Fossil SCM

Merge trunk

andygoth 2016-05-23 15:45 andygoth-brackets-outside-link merge
Commit 83bd4f37b1d19b40685a1e200755f964f9e2ac6e
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,5 +1,6 @@
11
compat/openssl*
22
compat/tcl*
33
fossil
44
fossil.exe
55
win/fossil.exe
6
+*sqlite3-see.*
67
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,5 +1,6 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
5 win/fossil.exe
 
6
--- .fossil-settings/ignore-glob
+++ .fossil-settings/ignore-glob
@@ -1,5 +1,6 @@
1 compat/openssl*
2 compat/tcl*
3 fossil
4 fossil.exe
5 win/fossil.exe
6 *sqlite3-see.*
7
--- Makefile.in
+++ Makefile.in
@@ -41,10 +41,11 @@
4141
LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
4242
TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
4343
INSTALLDIR = $(DESTDIR)@prefix@/bin
4444
USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
4545
USE_LINENOISE = @USE_LINENOISE@
46
+USE_SEE = @USE_SEE@
4647
FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
4748
4849
include $(SRCDIR)/main.mk
4950
5051
distclean: clean
5152
--- Makefile.in
+++ Makefile.in
@@ -41,10 +41,11 @@
41 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
43 INSTALLDIR = $(DESTDIR)@prefix@/bin
44 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
45 USE_LINENOISE = @USE_LINENOISE@
 
46 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
47
48 include $(SRCDIR)/main.mk
49
50 distclean: clean
51
--- Makefile.in
+++ Makefile.in
@@ -41,10 +41,11 @@
41 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42 TCCFLAGS = @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
43 INSTALLDIR = $(DESTDIR)@prefix@/bin
44 USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
45 USE_LINENOISE = @USE_LINENOISE@
46 USE_SEE = @USE_SEE@
47 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
48
49 include $(SRCDIR)/main.mk
50
51 distclean: clean
52
+8
--- auto.def
+++ auto.def
@@ -15,10 +15,11 @@
1515
with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
1616
with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
1717
with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
1818
with-tcl-private-stubs=0
1919
=> {Enable Tcl integration via private stubs mechanism}
20
+ with-see=0 => {Enable the SQLite Encryption Extension (SEE)}
2021
internal-sqlite=1 => {Don't use the internal SQLite, use the system one}
2122
static=0 => {Link a static executable}
2223
fusefs=1 => {Disable the Fuse Filesystem}
2324
fossil-debug=0 => {Build with fossil debugging enabled}
2425
json=0 => {Build with fossil JSON API enabled}
@@ -38,10 +39,11 @@
3839
define EXTRA_CFLAGS ""
3940
define EXTRA_LDFLAGS ""
4041
define USE_SYSTEM_SQLITE 0
4142
define USE_LINENOISE 0
4243
define FOSSIL_ENABLE_MINIZ 0
44
+define USE_SEE 0
4345
4446
# This procedure is a customized version of "cc-check-function-in-lib",
4547
# that does not modify the LIBS variable. Its use prevents prematurely
4648
# pulling in libraries that will be added later anyhow (e.g. "-ldl").
4749
proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -132,10 +134,16 @@
132134
133135
if {[opt-bool fossil-debug]} {
134136
define-append EXTRA_CFLAGS -DFOSSIL_DEBUG
135137
msg-result "Debugging support enabled"
136138
}
139
+
140
+if {[opt-bool with-see]} {
141
+ define-append EXTRA_CFLAGS -DUSE_SEE
142
+ define USE_SEE 1
143
+ msg-result "Enabling encryption support"
144
+}
137145
138146
if {[opt-bool json]} {
139147
# Reminder/FIXME (stephan): FOSSIL_ENABLE_JSON
140148
# is required in the CFLAGS because json*.c
141149
# have #ifdef guards around the whole file without
142150
--- auto.def
+++ auto.def
@@ -15,10 +15,11 @@
15 with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
16 with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
17 with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
18 with-tcl-private-stubs=0
19 => {Enable Tcl integration via private stubs mechanism}
 
20 internal-sqlite=1 => {Don't use the internal SQLite, use the system one}
21 static=0 => {Link a static executable}
22 fusefs=1 => {Disable the Fuse Filesystem}
23 fossil-debug=0 => {Build with fossil debugging enabled}
24 json=0 => {Build with fossil JSON API enabled}
@@ -38,10 +39,11 @@
38 define EXTRA_CFLAGS ""
39 define EXTRA_LDFLAGS ""
40 define USE_SYSTEM_SQLITE 0
41 define USE_LINENOISE 0
42 define FOSSIL_ENABLE_MINIZ 0
 
43
44 # This procedure is a customized version of "cc-check-function-in-lib",
45 # that does not modify the LIBS variable. Its use prevents prematurely
46 # pulling in libraries that will be added later anyhow (e.g. "-ldl").
47 proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -132,10 +134,16 @@
132
133 if {[opt-bool fossil-debug]} {
134 define-append EXTRA_CFLAGS -DFOSSIL_DEBUG
135 msg-result "Debugging support enabled"
136 }
 
 
 
 
 
 
137
138 if {[opt-bool json]} {
139 # Reminder/FIXME (stephan): FOSSIL_ENABLE_JSON
140 # is required in the CFLAGS because json*.c
141 # have #ifdef guards around the whole file without
142
--- auto.def
+++ auto.def
@@ -15,10 +15,11 @@
15 with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
16 with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
17 with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
18 with-tcl-private-stubs=0
19 => {Enable Tcl integration via private stubs mechanism}
20 with-see=0 => {Enable the SQLite Encryption Extension (SEE)}
21 internal-sqlite=1 => {Don't use the internal SQLite, use the system one}
22 static=0 => {Link a static executable}
23 fusefs=1 => {Disable the Fuse Filesystem}
24 fossil-debug=0 => {Build with fossil debugging enabled}
25 json=0 => {Build with fossil JSON API enabled}
@@ -38,10 +39,11 @@
39 define EXTRA_CFLAGS ""
40 define EXTRA_LDFLAGS ""
41 define USE_SYSTEM_SQLITE 0
42 define USE_LINENOISE 0
43 define FOSSIL_ENABLE_MINIZ 0
44 define USE_SEE 0
45
46 # This procedure is a customized version of "cc-check-function-in-lib",
47 # that does not modify the LIBS variable. Its use prevents prematurely
48 # pulling in libraries that will be added later anyhow (e.g. "-ldl").
49 proc check-function-in-lib {function libs {otherlibs {}}} {
@@ -132,10 +134,16 @@
134
135 if {[opt-bool fossil-debug]} {
136 define-append EXTRA_CFLAGS -DFOSSIL_DEBUG
137 msg-result "Debugging support enabled"
138 }
139
140 if {[opt-bool with-see]} {
141 define-append EXTRA_CFLAGS -DUSE_SEE
142 define USE_SEE 1
143 msg-result "Enabling encryption support"
144 }
145
146 if {[opt-bool json]} {
147 # Reminder/FIXME (stephan): FOSSIL_ENABLE_JSON
148 # is required in the CFLAGS because json*.c
149 # have #ifdef guards around the whole file without
150
--- src/allrepo.c
+++ src/allrepo.c
@@ -377,10 +377,13 @@
377377
}
378378
db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
379379
db_prepare(&q, "SELECT name, tag FROM repolist ORDER BY 1");
380380
while( db_step(&q)==SQLITE_ROW ){
381381
const char *zFilename = db_column_text(&q, 0);
382
+#if !USE_SEE
383
+ if( sqlite3_strglob("*.efossil", zFilename)==0 ) continue;
384
+#endif
382385
if( file_access(zFilename, F_OK)
383386
|| !file_is_canonical(zFilename)
384387
|| (useCheckouts && file_isdir(zFilename)!=1)
385388
){
386389
db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
387390
--- src/allrepo.c
+++ src/allrepo.c
@@ -377,10 +377,13 @@
377 }
378 db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
379 db_prepare(&q, "SELECT name, tag FROM repolist ORDER BY 1");
380 while( db_step(&q)==SQLITE_ROW ){
381 const char *zFilename = db_column_text(&q, 0);
 
 
 
382 if( file_access(zFilename, F_OK)
383 || !file_is_canonical(zFilename)
384 || (useCheckouts && file_isdir(zFilename)!=1)
385 ){
386 db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
387
--- src/allrepo.c
+++ src/allrepo.c
@@ -377,10 +377,13 @@
377 }
378 db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
379 db_prepare(&q, "SELECT name, tag FROM repolist ORDER BY 1");
380 while( db_step(&q)==SQLITE_ROW ){
381 const char *zFilename = db_column_text(&q, 0);
382 #if !USE_SEE
383 if( sqlite3_strglob("*.efossil", zFilename)==0 ) continue;
384 #endif
385 if( file_access(zFilename, F_OK)
386 || !file_is_canonical(zFilename)
387 || (useCheckouts && file_isdir(zFilename)!=1)
388 ){
389 db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
390
+162 -50
--- src/attach.c
+++ src/attach.c
@@ -246,10 +246,66 @@
246246
db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
247247
}
248248
manifest_crosslink(rid, pAttach, MC_NONE);
249249
}
250250
251
+
252
+/*
253
+** Commit a new attachment into the repository
254
+*/
255
+void attach_commit(
256
+ const char *zName, /* The filename of the attachment */
257
+ const char *zTarget, /* The artifact uuid to attach to */
258
+ const char *aContent, /* The content of the attachment */
259
+ int szContent, /* The length of the attachment */
260
+ int needModerator, /* Moderate the attachment? */
261
+ const char *zComment /* The comment for the attachment */
262
+){
263
+ Blob content;
264
+ Blob manifest;
265
+ Blob cksum;
266
+ char *zUUID;
267
+ char *zDate;
268
+ int rid;
269
+ int i, n;
270
+ int addCompress = 0;
271
+ Manifest *pManifest;
272
+
273
+ db_begin_transaction();
274
+ blob_init(&content, aContent, szContent);
275
+ pManifest = manifest_parse(&content, 0, 0);
276
+ manifest_destroy(pManifest);
277
+ blob_init(&content, aContent, szContent);
278
+ if( pManifest ){
279
+ blob_compress(&content, &content);
280
+ addCompress = 1;
281
+ }
282
+ rid = content_put_ex(&content, 0, 0, 0, needModerator);
283
+ zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
284
+ blob_zero(&manifest);
285
+ for(i=n=0; zName[i]; i++){
286
+ if( zName[i]=='/' || zName[i]=='\\' ) n = i+1;
287
+ }
288
+ zName += n;
289
+ if( zName[0]==0 ) zName = "unknown";
290
+ blob_appendf(&manifest, "A %F%s %F %s\n",
291
+ zName, addCompress ? ".gz" : "", zTarget, zUUID);
292
+ while( fossil_isspace(zComment[0]) ) zComment++;
293
+ n = strlen(zComment);
294
+ while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
295
+ if( n>0 ){
296
+ blob_appendf(&manifest, "C %#F\n", n, zComment);
297
+ }
298
+ zDate = date_in_standard_format("now");
299
+ blob_appendf(&manifest, "D %s\n", zDate);
300
+ blob_appendf(&manifest, "U %F\n", login_name());
301
+ md5sum_blob(&manifest, &cksum);
302
+ blob_appendf(&manifest, "Z %b\n", &cksum);
303
+ attach_put(&manifest, rid, needModerator);
304
+ assert( blob_is_reset(&manifest) );
305
+ db_end_transaction(0);
306
+}
251307
252308
/*
253309
** WEBPAGE: attachadd
254310
** Add a new attachment.
255311
**
@@ -300,11 +356,11 @@
300356
zTechNote = db_text(0, "SELECT substr(tagname,7) FROM tag"
301357
" WHERE tagname GLOB 'event-%q*'", zTechNote);
302358
if( zTechNote==0) fossil_redirect_home();
303359
}
304360
zTarget = zTechNote;
305
- zTargetType = mprintf("Tech Note <a href=\"%R/technote/%h\">%h</a>",
361
+ zTargetType = mprintf("Tech Note <a href=\"%R/technote/%s\">%S</a>",
306362
zTechNote, zTechNote);
307363
308364
}else{
309365
if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){
310366
login_needed(g.anon.ApndTkt && g.anon.Attach);
@@ -322,59 +378,14 @@
322378
if( zFrom==0 ) zFrom = mprintf("%s/home", g.zTop);
323379
if( P("cancel") ){
324380
cgi_redirect(zFrom);
325381
}
326382
if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct()) ){
327
- Blob content;
328
- Blob manifest;
329
- Blob cksum;
330
- char *zUUID;
331
- const char *zComment;
332
- char *zDate;
333
- int rid;
334
- int i, n;
335
- int addCompress = 0;
336
- Manifest *pManifest;
337
- int needModerator;
338
-
339
- db_begin_transaction();
340
- blob_init(&content, aContent, szContent);
341
- pManifest = manifest_parse(&content, 0, 0);
342
- manifest_destroy(pManifest);
343
- blob_init(&content, aContent, szContent);
344
- if( pManifest ){
345
- blob_compress(&content, &content);
346
- addCompress = 1;
347
- }
348
- needModerator =
349
- (zTkt!=0 && ticket_need_moderation(0)) ||
350
- (zPage!=0 && wiki_need_moderation(0));
351
- rid = content_put_ex(&content, 0, 0, 0, needModerator);
352
- zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
353
- blob_zero(&manifest);
354
- for(i=n=0; zName[i]; i++){
355
- if( zName[i]=='/' || zName[i]=='\\' ) n = i;
356
- }
357
- zName += n;
358
- if( zName[0]==0 ) zName = "unknown";
359
- blob_appendf(&manifest, "A %F%s %F %s\n",
360
- zName, addCompress ? ".gz" : "", zTarget, zUUID);
361
- zComment = PD("comment", "");
362
- while( fossil_isspace(zComment[0]) ) zComment++;
363
- n = strlen(zComment);
364
- while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
365
- if( n>0 ){
366
- blob_appendf(&manifest, "C %#F\n", n, zComment);
367
- }
368
- zDate = date_in_standard_format("now");
369
- blob_appendf(&manifest, "D %s\n", zDate);
370
- blob_appendf(&manifest, "U %F\n", login_name());
371
- md5sum_blob(&manifest, &cksum);
372
- blob_appendf(&manifest, "Z %b\n", &cksum);
373
- attach_put(&manifest, rid, needModerator);
374
- assert( blob_is_reset(&manifest) );
375
- db_end_transaction(0);
383
+ int needModerator = (zTkt!=0 && ticket_need_moderation(0)) ||
384
+ (zPage!=0 && wiki_need_moderation(0));
385
+ const char *zComment = PD("comment", "");
386
+ attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment);
376387
cgi_redirect(zFrom);
377388
}
378389
style_header("Add Attachment");
379390
if( !goodCaptcha ){
380391
@ <p class="generalError">Error: Incorrect security code.</p>
@@ -670,5 +681,106 @@
670681
@ </ul>
671682
}
672683
db_finalize(&q);
673684
674685
}
686
+
687
+/*
688
+** COMMAND: attachment*
689
+**
690
+** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS?
691
+**
692
+** Add an attachment to an existing wiki page or tech note.
693
+**
694
+** Options:
695
+** -t|--technote DATETIME Specifies the timestamp of
696
+** the technote to which the attachment
697
+** is to be made. The attachment will be
698
+** to the most recently modified tech note
699
+** with the specified timestamp.
700
+** -t|--technote TECHNOTE-ID Specifies the technote to be
701
+** updated by its technote id.
702
+**
703
+** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
704
+*/
705
+void attachment_cmd(void){
706
+ int n;
707
+ db_find_and_open_repository(0, 0);
708
+ if( g.argc<3 ){
709
+ goto attachment_cmd_usage;
710
+ }
711
+ n = strlen(g.argv[2]);
712
+ if( n==0 ){
713
+ goto attachment_cmd_usage;
714
+ }
715
+
716
+ if( strncmp(g.argv[2],"add",n)==0 ){
717
+ const char *zPageName; /* Name of the wiki page to attach to */
718
+ const char *zFile; /* Name of the file to be attached */
719
+ const char *zETime; /* The name of the technote to attach to */
720
+ Manifest *pWiki = 0; /* Parsed wiki page content */
721
+ char *zBody = 0; /* Wiki page content */
722
+ int rid;
723
+ const char *zTarget; /* Target of the attachment */
724
+ Blob content; /* The content of the attachment */
725
+ zETime = find_option("technote","t",1);
726
+ if( !zETime ){
727
+ if( g.argc!=5 ){
728
+ usage("add PAGENAME FILENAME");
729
+ }
730
+ zPageName = g.argv[3];
731
+ rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
732
+ " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
733
+ " ORDER BY x.mtime DESC LIMIT 1",
734
+ zPageName
735
+ );
736
+ if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
737
+ zBody = pWiki->zWiki;
738
+ }
739
+ if( zBody==0 ){
740
+ fossil_fatal("wiki page [%s] not found",zPageName);
741
+ }
742
+ zTarget = zPageName;
743
+ zFile = g.argv[4];
744
+ }else{
745
+ if( g.argc!=4 ){
746
+ usage("add FILENAME --technote DATETIME|TECHNOTE-ID");
747
+ }
748
+ rid = wiki_technote_to_rid(zETime);
749
+ if( rid<0 ){
750
+ fossil_fatal("ambiguous tech note id: %s", zETime);
751
+ }
752
+ if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
753
+ zBody = pWiki->zWiki;
754
+ }
755
+ if( zBody==0 ){
756
+ fossil_fatal("technote [%s] not found",zETime);
757
+ }
758
+ zTarget = db_text(0,
759
+ "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
760
+ rid
761
+ );
762
+ zFile = g.argv[3];
763
+ }
764
+ blob_read_from_file(&content, zFile);
765
+ user_select();
766
+ attach_commit(
767
+ zFile, /* The filename of the attachment */
768
+ zTarget, /* The artifact uuid to attach to */
769
+ blob_buffer(&content), /* The content of the attachment */
770
+ blob_size(&content), /* The length of the attachment */
771
+ 0, /* No need to moderate the attachment */
772
+ "" /* Empty attachment comment */
773
+ );
774
+ if( !zETime ){
775
+ fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
776
+ }else{
777
+ fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
778
+ }
779
+ }else{
780
+ goto attachment_cmd_usage;
781
+ }
782
+ return;
783
+
784
+attachment_cmd_usage:
785
+ usage("add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
786
+}
675787
--- src/attach.c
+++ src/attach.c
@@ -246,10 +246,66 @@
246 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
247 }
248 manifest_crosslink(rid, pAttach, MC_NONE);
249 }
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
252 /*
253 ** WEBPAGE: attachadd
254 ** Add a new attachment.
255 **
@@ -300,11 +356,11 @@
300 zTechNote = db_text(0, "SELECT substr(tagname,7) FROM tag"
301 " WHERE tagname GLOB 'event-%q*'", zTechNote);
302 if( zTechNote==0) fossil_redirect_home();
303 }
304 zTarget = zTechNote;
305 zTargetType = mprintf("Tech Note <a href=\"%R/technote/%h\">%h</a>",
306 zTechNote, zTechNote);
307
308 }else{
309 if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){
310 login_needed(g.anon.ApndTkt && g.anon.Attach);
@@ -322,59 +378,14 @@
322 if( zFrom==0 ) zFrom = mprintf("%s/home", g.zTop);
323 if( P("cancel") ){
324 cgi_redirect(zFrom);
325 }
326 if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct()) ){
327 Blob content;
328 Blob manifest;
329 Blob cksum;
330 char *zUUID;
331 const char *zComment;
332 char *zDate;
333 int rid;
334 int i, n;
335 int addCompress = 0;
336 Manifest *pManifest;
337 int needModerator;
338
339 db_begin_transaction();
340 blob_init(&content, aContent, szContent);
341 pManifest = manifest_parse(&content, 0, 0);
342 manifest_destroy(pManifest);
343 blob_init(&content, aContent, szContent);
344 if( pManifest ){
345 blob_compress(&content, &content);
346 addCompress = 1;
347 }
348 needModerator =
349 (zTkt!=0 && ticket_need_moderation(0)) ||
350 (zPage!=0 && wiki_need_moderation(0));
351 rid = content_put_ex(&content, 0, 0, 0, needModerator);
352 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
353 blob_zero(&manifest);
354 for(i=n=0; zName[i]; i++){
355 if( zName[i]=='/' || zName[i]=='\\' ) n = i;
356 }
357 zName += n;
358 if( zName[0]==0 ) zName = "unknown";
359 blob_appendf(&manifest, "A %F%s %F %s\n",
360 zName, addCompress ? ".gz" : "", zTarget, zUUID);
361 zComment = PD("comment", "");
362 while( fossil_isspace(zComment[0]) ) zComment++;
363 n = strlen(zComment);
364 while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
365 if( n>0 ){
366 blob_appendf(&manifest, "C %#F\n", n, zComment);
367 }
368 zDate = date_in_standard_format("now");
369 blob_appendf(&manifest, "D %s\n", zDate);
370 blob_appendf(&manifest, "U %F\n", login_name());
371 md5sum_blob(&manifest, &cksum);
372 blob_appendf(&manifest, "Z %b\n", &cksum);
373 attach_put(&manifest, rid, needModerator);
374 assert( blob_is_reset(&manifest) );
375 db_end_transaction(0);
376 cgi_redirect(zFrom);
377 }
378 style_header("Add Attachment");
379 if( !goodCaptcha ){
380 @ <p class="generalError">Error: Incorrect security code.</p>
@@ -670,5 +681,106 @@
670 @ </ul>
671 }
672 db_finalize(&q);
673
674 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
--- src/attach.c
+++ src/attach.c
@@ -246,10 +246,66 @@
246 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", rid);
247 }
248 manifest_crosslink(rid, pAttach, MC_NONE);
249 }
250
251
252 /*
253 ** Commit a new attachment into the repository
254 */
255 void attach_commit(
256 const char *zName, /* The filename of the attachment */
257 const char *zTarget, /* The artifact uuid to attach to */
258 const char *aContent, /* The content of the attachment */
259 int szContent, /* The length of the attachment */
260 int needModerator, /* Moderate the attachment? */
261 const char *zComment /* The comment for the attachment */
262 ){
263 Blob content;
264 Blob manifest;
265 Blob cksum;
266 char *zUUID;
267 char *zDate;
268 int rid;
269 int i, n;
270 int addCompress = 0;
271 Manifest *pManifest;
272
273 db_begin_transaction();
274 blob_init(&content, aContent, szContent);
275 pManifest = manifest_parse(&content, 0, 0);
276 manifest_destroy(pManifest);
277 blob_init(&content, aContent, szContent);
278 if( pManifest ){
279 blob_compress(&content, &content);
280 addCompress = 1;
281 }
282 rid = content_put_ex(&content, 0, 0, 0, needModerator);
283 zUUID = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
284 blob_zero(&manifest);
285 for(i=n=0; zName[i]; i++){
286 if( zName[i]=='/' || zName[i]=='\\' ) n = i+1;
287 }
288 zName += n;
289 if( zName[0]==0 ) zName = "unknown";
290 blob_appendf(&manifest, "A %F%s %F %s\n",
291 zName, addCompress ? ".gz" : "", zTarget, zUUID);
292 while( fossil_isspace(zComment[0]) ) zComment++;
293 n = strlen(zComment);
294 while( n>0 && fossil_isspace(zComment[n-1]) ){ n--; }
295 if( n>0 ){
296 blob_appendf(&manifest, "C %#F\n", n, zComment);
297 }
298 zDate = date_in_standard_format("now");
299 blob_appendf(&manifest, "D %s\n", zDate);
300 blob_appendf(&manifest, "U %F\n", login_name());
301 md5sum_blob(&manifest, &cksum);
302 blob_appendf(&manifest, "Z %b\n", &cksum);
303 attach_put(&manifest, rid, needModerator);
304 assert( blob_is_reset(&manifest) );
305 db_end_transaction(0);
306 }
307
308 /*
309 ** WEBPAGE: attachadd
310 ** Add a new attachment.
311 **
@@ -300,11 +356,11 @@
356 zTechNote = db_text(0, "SELECT substr(tagname,7) FROM tag"
357 " WHERE tagname GLOB 'event-%q*'", zTechNote);
358 if( zTechNote==0) fossil_redirect_home();
359 }
360 zTarget = zTechNote;
361 zTargetType = mprintf("Tech Note <a href=\"%R/technote/%s\">%S</a>",
362 zTechNote, zTechNote);
363
364 }else{
365 if( g.perm.ApndTkt==0 || g.perm.Attach==0 ){
366 login_needed(g.anon.ApndTkt && g.anon.Attach);
@@ -322,59 +378,14 @@
378 if( zFrom==0 ) zFrom = mprintf("%s/home", g.zTop);
379 if( P("cancel") ){
380 cgi_redirect(zFrom);
381 }
382 if( P("ok") && szContent>0 && (goodCaptcha = captcha_is_correct()) ){
383 int needModerator = (zTkt!=0 && ticket_need_moderation(0)) ||
384 (zPage!=0 && wiki_need_moderation(0));
385 const char *zComment = PD("comment", "");
386 attach_commit(zName, zTarget, aContent, szContent, needModerator, zComment);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387 cgi_redirect(zFrom);
388 }
389 style_header("Add Attachment");
390 if( !goodCaptcha ){
391 @ <p class="generalError">Error: Incorrect security code.</p>
@@ -670,5 +681,106 @@
681 @ </ul>
682 }
683 db_finalize(&q);
684
685 }
686
687 /*
688 ** COMMAND: attachment*
689 **
690 ** Usage: %fossil attachment add ?PAGENAME? FILENAME ?OPTIONS?
691 **
692 ** Add an attachment to an existing wiki page or tech note.
693 **
694 ** Options:
695 ** -t|--technote DATETIME Specifies the timestamp of
696 ** the technote to which the attachment
697 ** is to be made. The attachment will be
698 ** to the most recently modified tech note
699 ** with the specified timestamp.
700 ** -t|--technote TECHNOTE-ID Specifies the technote to be
701 ** updated by its technote id.
702 **
703 ** One of PAGENAME, DATETIME or TECHNOTE-ID must be specified.
704 */
705 void attachment_cmd(void){
706 int n;
707 db_find_and_open_repository(0, 0);
708 if( g.argc<3 ){
709 goto attachment_cmd_usage;
710 }
711 n = strlen(g.argv[2]);
712 if( n==0 ){
713 goto attachment_cmd_usage;
714 }
715
716 if( strncmp(g.argv[2],"add",n)==0 ){
717 const char *zPageName; /* Name of the wiki page to attach to */
718 const char *zFile; /* Name of the file to be attached */
719 const char *zETime; /* The name of the technote to attach to */
720 Manifest *pWiki = 0; /* Parsed wiki page content */
721 char *zBody = 0; /* Wiki page content */
722 int rid;
723 const char *zTarget; /* Target of the attachment */
724 Blob content; /* The content of the attachment */
725 zETime = find_option("technote","t",1);
726 if( !zETime ){
727 if( g.argc!=5 ){
728 usage("add PAGENAME FILENAME");
729 }
730 zPageName = g.argv[3];
731 rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
732 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
733 " ORDER BY x.mtime DESC LIMIT 1",
734 zPageName
735 );
736 if( (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0 ){
737 zBody = pWiki->zWiki;
738 }
739 if( zBody==0 ){
740 fossil_fatal("wiki page [%s] not found",zPageName);
741 }
742 zTarget = zPageName;
743 zFile = g.argv[4];
744 }else{
745 if( g.argc!=4 ){
746 usage("add FILENAME --technote DATETIME|TECHNOTE-ID");
747 }
748 rid = wiki_technote_to_rid(zETime);
749 if( rid<0 ){
750 fossil_fatal("ambiguous tech note id: %s", zETime);
751 }
752 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
753 zBody = pWiki->zWiki;
754 }
755 if( zBody==0 ){
756 fossil_fatal("technote [%s] not found",zETime);
757 }
758 zTarget = db_text(0,
759 "SELECT substr(tagname,7) FROM tag WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
760 rid
761 );
762 zFile = g.argv[3];
763 }
764 blob_read_from_file(&content, zFile);
765 user_select();
766 attach_commit(
767 zFile, /* The filename of the attachment */
768 zTarget, /* The artifact uuid to attach to */
769 blob_buffer(&content), /* The content of the attachment */
770 blob_size(&content), /* The length of the attachment */
771 0, /* No need to moderate the attachment */
772 "" /* Empty attachment comment */
773 );
774 if( !zETime ){
775 fossil_print("Attached %s to wiki page %s.\n", zFile, zPageName);
776 }else{
777 fossil_print("Attached %s to tech note %s.\n", zFile, zETime);
778 }
779 }else{
780 goto attachment_cmd_usage;
781 }
782 return;
783
784 attachment_cmd_usage:
785 usage("add ?PAGENAME? FILENAME [-t|--technote DATETIME ]");
786 }
787
+36 -26
--- src/checkin.c
+++ src/checkin.c
@@ -549,20 +549,20 @@
549549
/*
550550
** COMMAND: extras
551551
**
552552
** Usage: %fossil extras ?OPTIONS? ?PATH1 ...?
553553
**
554
-** Print a list of all files in the source tree that are not part of
555
-** the current checkout. See also the "clean" command. If paths are
556
-** specified, only files in the given directories will be listed.
554
+** Print a list of all files in the source tree that are not part of the
555
+** current checkout. See also the "clean" command. If paths are specified,
556
+** only files in the given directories will be listed.
557557
**
558558
** Files and subdirectories whose names begin with "." are normally
559559
** ignored but can be included by adding the --dotfiles option.
560560
**
561
-** The GLOBPATTERN is a comma-separated list of GLOB expressions for
562
-** files that are ignored. The GLOBPATTERN specified by the "ignore-glob"
563
-** is used if the --ignore option is omitted.
561
+** Files whose names match any of the glob patterns in the "ignore-glob"
562
+** setting are ignored. This setting can be overridden by the --ignore
563
+** option, whose CSG argument is a comma-separated list of glob patterns.
564564
**
565565
** Pathnames are displayed according to the "relative-paths" setting,
566566
** unless overridden by the --abs-paths or --rel-paths options.
567567
**
568568
** Options:
@@ -635,29 +635,38 @@
635635
/*
636636
** COMMAND: clean
637637
**
638638
** Usage: %fossil clean ?OPTIONS? ?PATH ...?
639639
**
640
-** Delete all "extra" files in the source tree. "Extra" files are
641
-** files that are not officially part of the checkout. This operation
642
-** cannot be undone. If one or more PATH arguments appear, then only
643
-** the files named, or files contained with directories named, will be
644
-** removed.
645
-**
646
-** Prompted are issued to confirm the removal of each file, unless
647
-** the --force flag is used or unless the file matches glob pattern
648
-** specified by the --clean option. No file that matches glob patterns
649
-** specified by --ignore or --keep will ever be deleted. The default
650
-** values for --clean, --ignore, and --keep are determined by the
651
-** (versionable) clean-glob, ignore-glob, and keep-glob settings.
652
-** Files and subdirectories whose names begin with "." are automatically
653
-** ignored unless the --dotfiles option is used.
654
-**
655
-** The --verily option ignores the keep-glob and ignore-glob settings
656
-** and turns on --force, --dotfiles, and --emptydirs. Use the --verily
657
-** option when you really want to clean up everything. Extreme care
658
-** should be exercised when using the --verily option.
640
+** Delete all "extra" files in the source tree. "Extra" files are files
641
+** that are not officially part of the checkout. If one or more PATH
642
+** arguments appear, then only the files named, or files contained with
643
+** directories named, will be removed.
644
+**
645
+** If the --prompt option is used, prompts are issued to confirm the
646
+** permanent removal of each file. Otherwise, files are backed up to the
647
+** undo buffer prior to removal, and prompts are issued only for files
648
+** whose removal cannot be undone due to their large size or due to
649
+** --disable-undo being used.
650
+**
651
+** The --force option treats all prompts as having been answered yes,
652
+** whereas --no-prompt treats them as having been answered no.
653
+**
654
+** Files matching any glob pattern specified by the --clean option are
655
+** deleted without prompting, and the removal cannot be undone.
656
+**
657
+** No file that matches glob patterns specified by --ignore or --keep will
658
+** ever be deleted. Files and subdirectories whose names begin with "."
659
+** are automatically ignored unless the --dotfiles option is used.
660
+**
661
+** The default values for --clean, --ignore, and --keep are determined by
662
+** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
663
+**
664
+** The --verily option ignores the keep-glob and ignore-glob settings and
665
+** turns on --force, --emptydirs, --dotfiles, and --disable-undo. Use the
666
+** --verily option when you really want to clean up everything. Extreme
667
+** care should be exercised when using the --verily option.
659668
**
660669
** Options:
661670
** --allckouts Check for empty directories within any checkouts
662671
** that may be nested within the current one. This
663672
** option should be used with great care because the
@@ -678,11 +687,12 @@
678687
** argument. Matching files, if any, are removed
679688
** prior to checking for any empty directories;
680689
** therefore, directories that contain only files
681690
** that were removed will be removed as well.
682691
** -f|--force Remove files without prompting.
683
-** -i|--prompt Prompt before removing each file.
692
+** -i|--prompt Prompt before removing each file. This option
693
+** implies the --disable-undo option.
684694
** -x|--verily WARNING: Removes everything that is not a managed
685695
** file or the repository itself. This option
686696
** implies the --force, --emptydirs, --dotfiles, and
687697
** --disable-undo options. Furthermore, it completely
688698
** disregards the keep-glob and ignore-glob settings.
689699
--- src/checkin.c
+++ src/checkin.c
@@ -549,20 +549,20 @@
549 /*
550 ** COMMAND: extras
551 **
552 ** Usage: %fossil extras ?OPTIONS? ?PATH1 ...?
553 **
554 ** Print a list of all files in the source tree that are not part of
555 ** the current checkout. See also the "clean" command. If paths are
556 ** specified, only files in the given directories will be listed.
557 **
558 ** Files and subdirectories whose names begin with "." are normally
559 ** ignored but can be included by adding the --dotfiles option.
560 **
561 ** The GLOBPATTERN is a comma-separated list of GLOB expressions for
562 ** files that are ignored. The GLOBPATTERN specified by the "ignore-glob"
563 ** is used if the --ignore option is omitted.
564 **
565 ** Pathnames are displayed according to the "relative-paths" setting,
566 ** unless overridden by the --abs-paths or --rel-paths options.
567 **
568 ** Options:
@@ -635,29 +635,38 @@
635 /*
636 ** COMMAND: clean
637 **
638 ** Usage: %fossil clean ?OPTIONS? ?PATH ...?
639 **
640 ** Delete all "extra" files in the source tree. "Extra" files are
641 ** files that are not officially part of the checkout. This operation
642 ** cannot be undone. If one or more PATH arguments appear, then only
643 ** the files named, or files contained with directories named, will be
644 ** removed.
645 **
646 ** Prompted are issued to confirm the removal of each file, unless
647 ** the --force flag is used or unless the file matches glob pattern
648 ** specified by the --clean option. No file that matches glob patterns
649 ** specified by --ignore or --keep will ever be deleted. The default
650 ** values for --clean, --ignore, and --keep are determined by the
651 ** (versionable) clean-glob, ignore-glob, and keep-glob settings.
652 ** Files and subdirectories whose names begin with "." are automatically
653 ** ignored unless the --dotfiles option is used.
654 **
655 ** The --verily option ignores the keep-glob and ignore-glob settings
656 ** and turns on --force, --dotfiles, and --emptydirs. Use the --verily
657 ** option when you really want to clean up everything. Extreme care
658 ** should be exercised when using the --verily option.
 
 
 
 
 
 
 
 
 
659 **
660 ** Options:
661 ** --allckouts Check for empty directories within any checkouts
662 ** that may be nested within the current one. This
663 ** option should be used with great care because the
@@ -678,11 +687,12 @@
678 ** argument. Matching files, if any, are removed
679 ** prior to checking for any empty directories;
680 ** therefore, directories that contain only files
681 ** that were removed will be removed as well.
682 ** -f|--force Remove files without prompting.
683 ** -i|--prompt Prompt before removing each file.
 
684 ** -x|--verily WARNING: Removes everything that is not a managed
685 ** file or the repository itself. This option
686 ** implies the --force, --emptydirs, --dotfiles, and
687 ** --disable-undo options. Furthermore, it completely
688 ** disregards the keep-glob and ignore-glob settings.
689
--- src/checkin.c
+++ src/checkin.c
@@ -549,20 +549,20 @@
549 /*
550 ** COMMAND: extras
551 **
552 ** Usage: %fossil extras ?OPTIONS? ?PATH1 ...?
553 **
554 ** Print a list of all files in the source tree that are not part of the
555 ** current checkout. See also the "clean" command. If paths are specified,
556 ** only files in the given directories will be listed.
557 **
558 ** Files and subdirectories whose names begin with "." are normally
559 ** ignored but can be included by adding the --dotfiles option.
560 **
561 ** Files whose names match any of the glob patterns in the "ignore-glob"
562 ** setting are ignored. This setting can be overridden by the --ignore
563 ** option, whose CSG argument is a comma-separated list of glob patterns.
564 **
565 ** Pathnames are displayed according to the "relative-paths" setting,
566 ** unless overridden by the --abs-paths or --rel-paths options.
567 **
568 ** Options:
@@ -635,29 +635,38 @@
635 /*
636 ** COMMAND: clean
637 **
638 ** Usage: %fossil clean ?OPTIONS? ?PATH ...?
639 **
640 ** Delete all "extra" files in the source tree. "Extra" files are files
641 ** that are not officially part of the checkout. If one or more PATH
642 ** arguments appear, then only the files named, or files contained with
643 ** directories named, will be removed.
644 **
645 ** If the --prompt option is used, prompts are issued to confirm the
646 ** permanent removal of each file. Otherwise, files are backed up to the
647 ** undo buffer prior to removal, and prompts are issued only for files
648 ** whose removal cannot be undone due to their large size or due to
649 ** --disable-undo being used.
650 **
651 ** The --force option treats all prompts as having been answered yes,
652 ** whereas --no-prompt treats them as having been answered no.
653 **
654 ** Files matching any glob pattern specified by the --clean option are
655 ** deleted without prompting, and the removal cannot be undone.
656 **
657 ** No file that matches glob patterns specified by --ignore or --keep will
658 ** ever be deleted. Files and subdirectories whose names begin with "."
659 ** are automatically ignored unless the --dotfiles option is used.
660 **
661 ** The default values for --clean, --ignore, and --keep are determined by
662 ** the (versionable) clean-glob, ignore-glob, and keep-glob settings.
663 **
664 ** The --verily option ignores the keep-glob and ignore-glob settings and
665 ** turns on --force, --emptydirs, --dotfiles, and --disable-undo. Use the
666 ** --verily option when you really want to clean up everything. Extreme
667 ** care should be exercised when using the --verily option.
668 **
669 ** Options:
670 ** --allckouts Check for empty directories within any checkouts
671 ** that may be nested within the current one. This
672 ** option should be used with great care because the
@@ -678,11 +687,12 @@
687 ** argument. Matching files, if any, are removed
688 ** prior to checking for any empty directories;
689 ** therefore, directories that contain only files
690 ** that were removed will be removed as well.
691 ** -f|--force Remove files without prompting.
692 ** -i|--prompt Prompt before removing each file. This option
693 ** implies the --disable-undo option.
694 ** -x|--verily WARNING: Removes everything that is not a managed
695 ** file or the repository itself. This option
696 ** implies the --force, --emptydirs, --dotfiles, and
697 ** --disable-undo options. Furthermore, it completely
698 ** disregards the keep-glob and ignore-glob settings.
699
+9 -6
--- src/content.c
+++ src/content.c
@@ -282,18 +282,21 @@
282282
rc = content_get(a[n], pBlob);
283283
n--;
284284
while( rc && n>=0 ){
285285
rc = content_of_blob(a[n], &delta);
286286
if( rc ){
287
- blob_delta_apply(pBlob, &delta, &next);
288
- blob_reset(&delta);
289
- if( (mx-n)%8==0 ){
290
- content_cache_insert(a[n+1], pBlob);
287
+ if( blob_delta_apply(pBlob, &delta, &next)<0 ){
288
+ rc = 1;
291289
}else{
292
- blob_reset(pBlob);
290
+ blob_reset(&delta);
291
+ if( (mx-n)%8==0 ){
292
+ content_cache_insert(a[n+1], pBlob);
293
+ }else{
294
+ blob_reset(pBlob);
295
+ }
296
+ *pBlob = next;
293297
}
294
- *pBlob = next;
295298
}
296299
n--;
297300
}
298301
free(a);
299302
if( !rc ) blob_reset(pBlob);
300303
--- src/content.c
+++ src/content.c
@@ -282,18 +282,21 @@
282 rc = content_get(a[n], pBlob);
283 n--;
284 while( rc && n>=0 ){
285 rc = content_of_blob(a[n], &delta);
286 if( rc ){
287 blob_delta_apply(pBlob, &delta, &next);
288 blob_reset(&delta);
289 if( (mx-n)%8==0 ){
290 content_cache_insert(a[n+1], pBlob);
291 }else{
292 blob_reset(pBlob);
 
 
 
 
 
 
293 }
294 *pBlob = next;
295 }
296 n--;
297 }
298 free(a);
299 if( !rc ) blob_reset(pBlob);
300
--- src/content.c
+++ src/content.c
@@ -282,18 +282,21 @@
282 rc = content_get(a[n], pBlob);
283 n--;
284 while( rc && n>=0 ){
285 rc = content_of_blob(a[n], &delta);
286 if( rc ){
287 if( blob_delta_apply(pBlob, &delta, &next)<0 ){
288 rc = 1;
 
 
289 }else{
290 blob_reset(&delta);
291 if( (mx-n)%8==0 ){
292 content_cache_insert(a[n+1], pBlob);
293 }else{
294 blob_reset(pBlob);
295 }
296 *pBlob = next;
297 }
 
298 }
299 n--;
300 }
301 free(a);
302 if( !rc ) blob_reset(pBlob);
303
+41 -3
--- src/db.c
+++ src/db.c
@@ -870,18 +870,45 @@
870870
db_tolocal_function, 0, 0);
871871
sqlite3_create_function(db, "fromLocal", 0, SQLITE_UTF8, 0,
872872
db_fromlocal_function, 0, 0);
873873
}
874874
875
+/*
876
+** If the database file zDbFile has a name that suggests that it is
877
+** encrypted, then prompt for the encryption key and return it in the
878
+** blob *pKey. Or, if the encryption key has previously been requested,
879
+** just return a copy of the previous result.
880
+*/
881
+static void db_encryption_key(
882
+ const char *zDbFile, /* Name of the database file */
883
+ Blob *pKey /* Put the encryption key here */
884
+){
885
+ blob_init(pKey, 0, 0);
886
+#if USE_SEE
887
+ if( sqlite3_strglob("*.efossil", zDbFile)==0 ){
888
+ static char *zSavedKey = 0;
889
+ if( zSavedKey ){
890
+ blob_set(pKey, zSavedKey);
891
+ }else{
892
+ char *zPrompt = mprintf("\rencryption key for '%s': ", zDbFile);
893
+ prompt_for_password(zPrompt, pKey, 0);
894
+ fossil_free(zPrompt);
895
+ zSavedKey = fossil_strdup(blob_str(pKey));
896
+ }
897
+ }
898
+#endif
899
+}
900
+
875901
876902
/*
877903
** Open a database file. Return a pointer to the new database
878904
** connection. An error results in process abort.
879905
*/
880906
LOCAL sqlite3 *db_open(const char *zDbName){
881907
int rc;
882908
sqlite3 *db;
909
+ Blob key;
883910
884911
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
885912
rc = sqlite3_open_v2(
886913
zDbName, &db,
887914
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
@@ -888,10 +915,17 @@
888915
g.zVfsName
889916
);
890917
if( rc!=SQLITE_OK ){
891918
db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
892919
}
920
+ db_encryption_key(zDbName, &key);
921
+ if( blob_size(&key)>0 ){
922
+ char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
923
+ sqlite3_exec(db, zCmd, 0, 0, 0);
924
+ sqlite3_free(zCmd);
925
+ }
926
+ blob_reset(&key);
893927
sqlite3_busy_timeout(db, 5000);
894928
sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
895929
sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
896930
sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
897931
sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
@@ -921,11 +955,15 @@
921955
/*
922956
** zDbName is the name of a database file. Attach zDbName using
923957
** the name zLabel.
924958
*/
925959
void db_attach(const char *zDbName, const char *zLabel){
926
- db_multi_exec("ATTACH DATABASE %Q AS %Q", zDbName, zLabel);
960
+ Blob key;
961
+ db_encryption_key(zDbName, &key);
962
+ db_multi_exec("ATTACH DATABASE %Q AS %Q KEY %Q",
963
+ zDbName, zLabel, blob_str(&key));
964
+ blob_reset(&key);
927965
}
928966
929967
/*
930968
** zDbName is the name of a database file. If no other database
931969
** file is open, then open this one. If another database file is
@@ -2639,12 +2677,12 @@
26392677
** differ only in case are the same file. Defaults to
26402678
** TRUE for unix and FALSE for Cygwin, Mac and Windows.
26412679
**
26422680
** clean-glob The VALUE is a comma or newline-separated list of GLOB
26432681
** (versionable) patterns specifying files that the "clean" command will
2644
-** delete without prompting even when the -force flag has
2645
-** not been used. Example: *.a *.lib *.o
2682
+** delete without prompting or allowing undo.
2683
+** Example: *.a,*.lib,*.o
26462684
**
26472685
** clearsign When enabled, fossil will attempt to sign all commits
26482686
** with gpg. When disabled (the default), commits will
26492687
** be unsigned. Default: off
26502688
**
26512689
--- src/db.c
+++ src/db.c
@@ -870,18 +870,45 @@
870 db_tolocal_function, 0, 0);
871 sqlite3_create_function(db, "fromLocal", 0, SQLITE_UTF8, 0,
872 db_fromlocal_function, 0, 0);
873 }
874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
876 /*
877 ** Open a database file. Return a pointer to the new database
878 ** connection. An error results in process abort.
879 */
880 LOCAL sqlite3 *db_open(const char *zDbName){
881 int rc;
882 sqlite3 *db;
 
883
884 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
885 rc = sqlite3_open_v2(
886 zDbName, &db,
887 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
@@ -888,10 +915,17 @@
888 g.zVfsName
889 );
890 if( rc!=SQLITE_OK ){
891 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
892 }
 
 
 
 
 
 
 
893 sqlite3_busy_timeout(db, 5000);
894 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
895 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
896 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
897 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
@@ -921,11 +955,15 @@
921 /*
922 ** zDbName is the name of a database file. Attach zDbName using
923 ** the name zLabel.
924 */
925 void db_attach(const char *zDbName, const char *zLabel){
926 db_multi_exec("ATTACH DATABASE %Q AS %Q", zDbName, zLabel);
 
 
 
 
927 }
928
929 /*
930 ** zDbName is the name of a database file. If no other database
931 ** file is open, then open this one. If another database file is
@@ -2639,12 +2677,12 @@
2639 ** differ only in case are the same file. Defaults to
2640 ** TRUE for unix and FALSE for Cygwin, Mac and Windows.
2641 **
2642 ** clean-glob The VALUE is a comma or newline-separated list of GLOB
2643 ** (versionable) patterns specifying files that the "clean" command will
2644 ** delete without prompting even when the -force flag has
2645 ** not been used. Example: *.a *.lib *.o
2646 **
2647 ** clearsign When enabled, fossil will attempt to sign all commits
2648 ** with gpg. When disabled (the default), commits will
2649 ** be unsigned. Default: off
2650 **
2651
--- src/db.c
+++ src/db.c
@@ -870,18 +870,45 @@
870 db_tolocal_function, 0, 0);
871 sqlite3_create_function(db, "fromLocal", 0, SQLITE_UTF8, 0,
872 db_fromlocal_function, 0, 0);
873 }
874
875 /*
876 ** If the database file zDbFile has a name that suggests that it is
877 ** encrypted, then prompt for the encryption key and return it in the
878 ** blob *pKey. Or, if the encryption key has previously been requested,
879 ** just return a copy of the previous result.
880 */
881 static void db_encryption_key(
882 const char *zDbFile, /* Name of the database file */
883 Blob *pKey /* Put the encryption key here */
884 ){
885 blob_init(pKey, 0, 0);
886 #if USE_SEE
887 if( sqlite3_strglob("*.efossil", zDbFile)==0 ){
888 static char *zSavedKey = 0;
889 if( zSavedKey ){
890 blob_set(pKey, zSavedKey);
891 }else{
892 char *zPrompt = mprintf("\rencryption key for '%s': ", zDbFile);
893 prompt_for_password(zPrompt, pKey, 0);
894 fossil_free(zPrompt);
895 zSavedKey = fossil_strdup(blob_str(pKey));
896 }
897 }
898 #endif
899 }
900
901
902 /*
903 ** Open a database file. Return a pointer to the new database
904 ** connection. An error results in process abort.
905 */
906 LOCAL sqlite3 *db_open(const char *zDbName){
907 int rc;
908 sqlite3 *db;
909 Blob key;
910
911 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
912 rc = sqlite3_open_v2(
913 zDbName, &db,
914 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
@@ -888,10 +915,17 @@
915 g.zVfsName
916 );
917 if( rc!=SQLITE_OK ){
918 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
919 }
920 db_encryption_key(zDbName, &key);
921 if( blob_size(&key)>0 ){
922 char *zCmd = sqlite3_mprintf("PRAGMA key(%Q)", blob_str(&key));
923 sqlite3_exec(db, zCmd, 0, 0, 0);
924 sqlite3_free(zCmd);
925 }
926 blob_reset(&key);
927 sqlite3_busy_timeout(db, 5000);
928 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
929 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
930 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
931 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
@@ -921,11 +955,15 @@
955 /*
956 ** zDbName is the name of a database file. Attach zDbName using
957 ** the name zLabel.
958 */
959 void db_attach(const char *zDbName, const char *zLabel){
960 Blob key;
961 db_encryption_key(zDbName, &key);
962 db_multi_exec("ATTACH DATABASE %Q AS %Q KEY %Q",
963 zDbName, zLabel, blob_str(&key));
964 blob_reset(&key);
965 }
966
967 /*
968 ** zDbName is the name of a database file. If no other database
969 ** file is open, then open this one. If another database file is
@@ -2639,12 +2677,12 @@
2677 ** differ only in case are the same file. Defaults to
2678 ** TRUE for unix and FALSE for Cygwin, Mac and Windows.
2679 **
2680 ** clean-glob The VALUE is a comma or newline-separated list of GLOB
2681 ** (versionable) patterns specifying files that the "clean" command will
2682 ** delete without prompting or allowing undo.
2683 ** Example: *.a,*.lib,*.o
2684 **
2685 ** clearsign When enabled, fossil will attempt to sign all commits
2686 ** with gpg. When disabled (the default), commits will
2687 ** be unsigned. Default: off
2688 **
2689
+4 -22
--- src/event.c
+++ src/event.c
@@ -540,44 +540,26 @@
540540
style_footer();
541541
}
542542
543543
/*
544544
** Add a new tech note to the repository. The timestamp is
545
-** given by the zETime parameter. isNew must be true to create
545
+** given by the zETime parameter. rid must be zero to create
546546
** a new page. If no previous page with the name zPageName exists
547547
** and isNew is false, then this routine throws an error.
548548
*/
549549
void event_cmd_commit(
550550
char *zETime, /* timestamp */
551
- int isNew, /* true to create a new page */
551
+ int rid, /* Artifact id of the tech note */
552552
Blob *pContent, /* content of the new page */
553553
const char *zMimeType, /* mimetype of the content */
554554
const char *zComment, /* comment to go on the timeline */
555555
const char *zTags, /* tags */
556556
const char *zClr /* background color */
557557
){
558
- int rid; /* Artifact id of the tech note */
559558
const char *zId; /* id of the tech note */
560
- rid = db_int(0, "SELECT objid FROM event"
561
- " WHERE datetime(mtime)=datetime('%q') AND type = 'e'"
562
- " LIMIT 1",
563
- zETime
564
- );
565
- if( rid==0 && !isNew ){
566
-#ifdef FOSSIL_ENABLE_JSON
567
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
568
-#endif
569
- fossil_fatal("no such tech note: %s", zETime);
570
- }
571
- if( rid!=0 && isNew ){
572
-#ifdef FOSSIL_ENABLE_JSON
573
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
574
-#endif
575
- fossil_fatal("tech note %s already exists", zETime);
576
- }
577
-
578
- if ( isNew ){
559
+
560
+ if ( rid==0 ){
579561
zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
580562
}else{
581563
zId = db_text(0,
582564
"SELECT substr(tagname,7) FROM tag"
583565
" WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
584566
--- src/event.c
+++ src/event.c
@@ -540,44 +540,26 @@
540 style_footer();
541 }
542
543 /*
544 ** Add a new tech note to the repository. The timestamp is
545 ** given by the zETime parameter. isNew must be true to create
546 ** a new page. If no previous page with the name zPageName exists
547 ** and isNew is false, then this routine throws an error.
548 */
549 void event_cmd_commit(
550 char *zETime, /* timestamp */
551 int isNew, /* true to create a new page */
552 Blob *pContent, /* content of the new page */
553 const char *zMimeType, /* mimetype of the content */
554 const char *zComment, /* comment to go on the timeline */
555 const char *zTags, /* tags */
556 const char *zClr /* background color */
557 ){
558 int rid; /* Artifact id of the tech note */
559 const char *zId; /* id of the tech note */
560 rid = db_int(0, "SELECT objid FROM event"
561 " WHERE datetime(mtime)=datetime('%q') AND type = 'e'"
562 " LIMIT 1",
563 zETime
564 );
565 if( rid==0 && !isNew ){
566 #ifdef FOSSIL_ENABLE_JSON
567 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
568 #endif
569 fossil_fatal("no such tech note: %s", zETime);
570 }
571 if( rid!=0 && isNew ){
572 #ifdef FOSSIL_ENABLE_JSON
573 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
574 #endif
575 fossil_fatal("tech note %s already exists", zETime);
576 }
577
578 if ( isNew ){
579 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
580 }else{
581 zId = db_text(0,
582 "SELECT substr(tagname,7) FROM tag"
583 " WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
584
--- src/event.c
+++ src/event.c
@@ -540,44 +540,26 @@
540 style_footer();
541 }
542
543 /*
544 ** Add a new tech note to the repository. The timestamp is
545 ** given by the zETime parameter. rid must be zero to create
546 ** a new page. If no previous page with the name zPageName exists
547 ** and isNew is false, then this routine throws an error.
548 */
549 void event_cmd_commit(
550 char *zETime, /* timestamp */
551 int rid, /* Artifact id of the tech note */
552 Blob *pContent, /* content of the new page */
553 const char *zMimeType, /* mimetype of the content */
554 const char *zComment, /* comment to go on the timeline */
555 const char *zTags, /* tags */
556 const char *zClr /* background color */
557 ){
 
558 const char *zId; /* id of the tech note */
559
560 if ( rid==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561 zId = db_text(0, "SELECT lower(hex(randomblob(20)))");
562 }else{
563 zId = db_text(0,
564 "SELECT substr(tagname,7) FROM tag"
565 " WHERE tagid=(SELECT tagid FROM event WHERE objid='%d')",
566
+236 -27
--- src/export.c
+++ src/export.c
@@ -19,10 +19,28 @@
1919
*/
2020
#include "config.h"
2121
#include "export.h"
2222
#include <assert.h>
2323
24
+#if INTERFACE
25
+/*
26
+** struct mark_t
27
+** holds information for translating between git commits
28
+** and fossil commits.
29
+** -git_name: This is the mark name that identifies the commit to git.
30
+** It will always begin with a ':'.
31
+** -rid: The unique object ID that identifies this commit within the
32
+** repository database.
33
+** -uuid: The SHA-1 of artifact corresponding to rid.
34
+*/
35
+struct mark_t{
36
+ char *name;
37
+ int rid;
38
+ char uuid[41];
39
+};
40
+#endif
41
+
2442
/*
2543
** Output a "committer" record for the given user.
2644
*/
2745
static void print_person(const char *zUser){
2846
static Stmt q;
@@ -96,10 +114,197 @@
96114
db_reset(&q);
97115
}
98116
99117
#define BLOBMARK(rid) ((rid) * 2)
100118
#define COMMITMARK(rid) ((rid) * 2 + 1)
119
+
120
+/*
121
+** insert_commit_xref()
122
+** Insert a new (mark,rid,uuid) entry into the 'xmark' table.
123
+** zName and zUuid must be non-null and must point to NULL-terminated strings.
124
+*/
125
+void insert_commit_xref(int rid, const char *zName, const char *zUuid){
126
+ db_multi_exec(
127
+ "INSERT OR IGNORE INTO xmark(tname, trid, tuuid)"
128
+ "VALUES(%Q,%d,%Q)",
129
+ zName, rid, zUuid
130
+ );
131
+}
132
+
133
+/*
134
+** create_mark()
135
+** Create a new (mark,rid,uuid) entry for the given rid in the 'xmark' table,
136
+** and return that information as a struct mark_t in *mark.
137
+** This function returns -1 in the case where 'rid' does not exist, otherwise
138
+** it returns 0.
139
+** mark->name is dynamically allocated and is owned by the caller upon return.
140
+*/
141
+int create_mark(int rid, struct mark_t *mark){
142
+ char sid[13];
143
+ char *zUuid = rid_to_uuid(rid);
144
+ if(!zUuid){
145
+ fossil_trace("Undefined rid=%d\n", rid);
146
+ return -1;
147
+ }
148
+ mark->rid = rid;
149
+ sprintf(sid, ":%d", COMMITMARK(rid));
150
+ mark->name = fossil_strdup(sid);
151
+ strcpy(mark->uuid, zUuid);
152
+ free(zUuid);
153
+ insert_commit_xref(mark->rid, mark->name, mark->uuid);
154
+ return 0;
155
+}
156
+
157
+/*
158
+** mark_name_from_rid()
159
+** Find the mark associated with the given rid. Mark names always start
160
+** with ':', and are pulled from the 'xmark' temporary table.
161
+** This function returns NULL if the rid does not exist in the 'xmark' table.
162
+** Otherwise, it returns the name of the mark, which is dynamically allocated
163
+** and is owned by the caller of this function.
164
+*/
165
+char * mark_name_from_rid(int rid){
166
+ char *zMark = db_text(0, "SELECT tname FROM xmark WHERE trid=%d", rid);
167
+ if(zMark==NULL){
168
+ struct mark_t mark;
169
+ if(create_mark(rid, &mark)==0){
170
+ zMark = mark.name;
171
+ }else{
172
+ return NULL;
173
+ }
174
+ }
175
+ return zMark;
176
+}
177
+
178
+/*
179
+** parse_mark()
180
+** Create a new (mark,rid,uuid) entry in the 'xmark' table given a line
181
+** from a marks file. Return the cross-ref information as a struct mark_t
182
+** in *mark.
183
+** This function returns -1 in the case that the line is blank, malformed, or
184
+** the rid/uuid named in 'line' does not match what is in the repository
185
+** database. Otherwise, 0 is returned.
186
+** mark->name is dynamically allocated, and owned by the caller.
187
+*/
188
+int parse_mark(char *line, struct mark_t *mark){
189
+ char *cur_tok;
190
+ cur_tok = strtok(line, " \t");
191
+ if(!cur_tok||strlen(cur_tok)<2){
192
+ return -1;
193
+ }
194
+ mark->rid = atoi(&cur_tok[1]);
195
+ if(cur_tok[0]!='c'){
196
+ /* This is probably a blob mark */
197
+ mark->name = NULL;
198
+ return 0;
199
+ }
200
+
201
+ cur_tok = strtok(NULL, " \t");
202
+ if(!cur_tok){
203
+ /* This mark was generated by an older version of Fossil and doesn't
204
+ ** include the mark name and uuid. create_mark() will name the new mark
205
+ ** exactly as it was when exported to git, so that we should have a
206
+ ** valid mapping from git sha1<->mark name<->fossil sha1. */
207
+ return create_mark(mark->rid, mark);
208
+ }else{
209
+ mark->name = fossil_strdup(cur_tok);
210
+ }
211
+
212
+ cur_tok = strtok(NULL, "\n");
213
+ if(!cur_tok||strlen(cur_tok)!=40){
214
+ free(mark->name);
215
+ fossil_trace("Invalid SHA-1 in marks file: %s\n", cur_tok);
216
+ return -1;
217
+ }else{
218
+ strcpy(mark->uuid, cur_tok);
219
+ }
220
+
221
+ /* make sure that rid corresponds to UUID */
222
+ if(fast_uuid_to_rid(mark->uuid)!=mark->rid){
223
+ free(mark->name);
224
+ fossil_trace("Non-existent SHA-1 in marks file: %s\n", mark->uuid);
225
+ return -1;
226
+ }
227
+
228
+ /* insert a cross-ref into the 'xmark' table */
229
+ insert_commit_xref(mark->rid, mark->name, mark->uuid);
230
+ return 0;
231
+}
232
+
233
+/*
234
+** import_marks()
235
+** Import the marks specified in file 'f' into the 'xmark' table.
236
+** If 'blobs' is non-null, insert all blob marks into it.
237
+** If 'vers' is non-null, insert all commit marks into it.
238
+** Each line in the file must be at most 100 characters in length. This
239
+** seems like a reasonable maximum for a 40-character uuid, and 1-13
240
+** character rid.
241
+** The function returns -1 if any of the lines in file 'f' are malformed,
242
+** or the rid/uuid information doesn't match what is in the repository
243
+** database. Otherwise, 0 is returned.
244
+*/
245
+int import_marks(FILE* f, Bag *blobs, Bag *vers){
246
+ char line[101];
247
+ while(fgets(line, sizeof(line), f)){
248
+ struct mark_t mark;
249
+ if(strlen(line)==100&&line[99]!='\n'){
250
+ /* line too long */
251
+ return -1;
252
+ }
253
+ if( parse_mark(line, &mark)<0 ){
254
+ return -1;
255
+ }else if( line[0]=='b' ){
256
+ /* Don't import blob marks into 'xmark' table--git doesn't use them,
257
+ ** so they need to be left free for git to reuse. */
258
+ if(blobs!=NULL){
259
+ bag_insert(blobs, mark.rid);
260
+ }
261
+ }else if( vers!=NULL ){
262
+ bag_insert(vers, mark.rid);
263
+ }
264
+ free(mark.name);
265
+ }
266
+ return 0;
267
+}
268
+
269
+/*
270
+** If 'blobs' is non-null, it must point to a Bag of blob rids to be
271
+** written to disk. Blob rids are written as 'b<rid>'.
272
+** If 'vers' is non-null, it must point to a Bag of commit rids to be
273
+** written to disk. Commit rids are written as 'c<rid> :<mark> <uuid>'.
274
+** All commit (mark,rid,uuid) tuples are stored in 'xmark' table.
275
+** This function does not fail, but may produce errors if a uuid cannot
276
+** be found for an rid in 'vers'.
277
+*/
278
+void export_marks(FILE* f, Bag *blobs, Bag *vers){
279
+ int rid;
280
+ if( blobs!=NULL ){
281
+ rid = bag_first(blobs);
282
+ if(rid!=0){
283
+ do{
284
+ fprintf(f, "b%d\n", rid);
285
+ }while((rid = bag_next(blobs, rid))!=0);
286
+ }
287
+ }
288
+ if( vers!=NULL ){
289
+ rid = bag_first(vers);
290
+ if( rid!=0 ){
291
+ do{
292
+ char *zUuid = rid_to_uuid(rid);
293
+ char *zMark;
294
+ if(zUuid==NULL){
295
+ fossil_trace("No uuid matching rid=%d when exporting marks\n", rid);
296
+ continue;
297
+ }
298
+ zMark = mark_name_from_rid(rid);
299
+ fprintf(f, "c%d %s %s\n", rid, zMark, zUuid);
300
+ free(zMark);
301
+ free(zUuid);
302
+ }while( (rid = bag_next(vers, rid))!=0 );
303
+ }
304
+ }
305
+}
101306
102307
/*
103308
** COMMAND: export
104309
**
105310
** Usage: %fossil export --git ?OPTIONS? ?REPOSITORY?
@@ -112,11 +317,11 @@
112317
**
113318
** Run this command within a checkout. Or use the -R or --repository
114319
** option to specify a Fossil repository to be exported.
115320
**
116321
** Only check-ins are exported using --git. Git does not support tickets
117
-** or wiki or events or attachments, so none of those are exported.
322
+** or wiki or tech notes or attachments, so none of those are exported.
118323
**
119324
** If the "--import-marks FILE" option is used, it contains a list of
120325
** rids to skip.
121326
**
122327
** If the "--export-marks FILE" option is used, the rid of all commits and
@@ -147,35 +352,40 @@
147352
verify_all_options();
148353
if( g.argc!=2 && g.argc!=3 ){ usage("--git ?REPOSITORY?"); }
149354
150355
db_multi_exec("CREATE TEMPORARY TABLE oldblob(rid INTEGER PRIMARY KEY)");
151356
db_multi_exec("CREATE TEMPORARY TABLE oldcommit(rid INTEGER PRIMARY KEY)");
357
+ db_multi_exec("CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT)");
152358
if( markfile_in!=0 ){
153359
Stmt qb,qc;
154
- char line[100];
155360
FILE *f;
361
+ int rid;
156362
157363
f = fossil_fopen(markfile_in, "r");
158364
if( f==0 ){
159365
fossil_fatal("cannot open %s for reading", markfile_in);
160366
}
367
+ if(import_marks(f, &blobs, &vers)<0){
368
+ fossil_fatal("error importing marks from file: %s\n", markfile_in);
369
+ }
161370
db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
162371
db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
163
- while( fgets(line, sizeof(line), f)!=0 ){
164
- if( *line == 'b' ){
165
- db_bind_text(&qb, ":rid", line + 1);
372
+ rid = bag_first(&blobs);
373
+ if(rid!=0){
374
+ do{
375
+ db_bind_int(&qb, ":rid", rid);
166376
db_step(&qb);
167377
db_reset(&qb);
168
- bag_insert(&blobs, atoi(line + 1));
169
- }else if( *line == 'c' ){
170
- db_bind_text(&qc, ":rid", line + 1);
378
+ }while((rid = bag_next(&blobs, rid))!=0);
379
+ }
380
+ rid = bag_first(&vers);
381
+ if(rid!=0){
382
+ do{
383
+ db_bind_int(&qc, ":rid", rid);
171384
db_step(&qc);
172385
db_reset(&qc);
173
- bag_insert(&vers, atoi(line + 1));
174
- }else{
175
- fossil_fatal("bad input from %s: %s", markfile_in, line);
176
- }
386
+ }while((rid = bag_next(&vers, rid))!=0);
177387
}
178388
db_finalize(&qb);
179389
db_finalize(&qc);
180390
fclose(f);
181391
}
@@ -249,10 +459,11 @@
249459
int ckinId = db_column_int(&q, 1);
250460
const char *zComment = db_column_text(&q, 2);
251461
const char *zUser = db_column_text(&q, 3);
252462
const char *zBranch = db_column_text(&q, 4);
253463
char *zBr;
464
+ char *zMark;
254465
255466
bag_insert(&vers, ckinId);
256467
db_bind_int(&q2, ":rid", ckinId);
257468
db_step(&q2);
258469
db_reset(&q2);
@@ -259,11 +470,13 @@
259470
if( zBranch==0 ) zBranch = "trunk";
260471
zBr = mprintf("%s", zBranch);
261472
for(i=0; zBr[i]; i++){
262473
if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
263474
}
264
- printf("commit refs/heads/%s\nmark :%d\n", zBr, COMMITMARK(ckinId));
475
+ zMark = mark_name_from_rid(ckinId);
476
+ printf("commit refs/heads/%s\nmark %s\n", zBr, zMark);
477
+ free(zMark);
265478
free(zBr);
266479
printf("committer");
267480
print_person(zUser);
268481
printf(" %s +0000\n", zSecondsSince1970);
269482
if( zComment==0 ) zComment = "null comment";
@@ -273,19 +486,24 @@
273486
" WHERE cid=%d AND isprim"
274487
" AND pid IN (SELECT objid FROM event)",
275488
ckinId
276489
);
277490
if( db_step(&q3) == SQLITE_ROW ){
278
- printf("from :%d\n", COMMITMARK(db_column_int(&q3, 0)));
491
+ int pid = db_column_int(&q3, 0);
492
+ zMark = mark_name_from_rid(pid);
493
+ printf("from %s\n", zMark);
494
+ free(zMark);
279495
db_prepare(&q4,
280496
"SELECT pid FROM plink"
281497
" WHERE cid=%d AND NOT isprim"
282498
" AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
283499
" ORDER BY pid",
284500
ckinId);
285501
while( db_step(&q4)==SQLITE_ROW ){
286
- printf("merge :%d\n", COMMITMARK(db_column_int(&q4,0)));
502
+ zMark = mark_name_from_rid(db_column_int(&q4, 0));
503
+ printf("merge %s\n", zMark);
504
+ free(zMark);
287505
}
288506
db_finalize(&q4);
289507
}else{
290508
printf("deleteall\n");
291509
}
@@ -316,11 +534,10 @@
316534
db_finalize(&q3);
317535
printf("\n");
318536
}
319537
db_finalize(&q2);
320538
db_finalize(&q);
321
- bag_clear(&blobs);
322539
manifest_cache_clear();
323540
324541
325542
/* Output tags */
326543
db_prepare(&q,
@@ -345,28 +562,20 @@
345562
printf("tagger <tagger> %s +0000\n", zSecSince1970);
346563
printf("data 0\n");
347564
fossil_free(zEncoded);
348565
}
349566
db_finalize(&q);
350
- bag_clear(&vers);
351567
352568
if( markfile_out!=0 ){
353569
FILE *f;
354570
f = fossil_fopen(markfile_out, "w");
355571
if( f == 0 ){
356572
fossil_fatal("cannot open %s for writing", markfile_out);
357573
}
358
- db_prepare(&q, "SELECT rid FROM oldblob");
359
- while( db_step(&q)==SQLITE_ROW ){
360
- fprintf(f, "b%d\n", db_column_int(&q, 0));
361
- }
362
- db_finalize(&q);
363
- db_prepare(&q, "SELECT rid FROM oldcommit");
364
- while( db_step(&q)==SQLITE_ROW ){
365
- fprintf(f, "c%d\n", db_column_int(&q, 0));
366
- }
367
- db_finalize(&q);
574
+ export_marks(f, &blobs, &vers);
368575
if( ferror(f)!=0 || fclose(f)!=0 ) {
369576
fossil_fatal("error while writing %s", markfile_out);
370577
}
371578
}
579
+ bag_clear(&blobs);
580
+ bag_clear(&vers);
372581
}
373582
--- src/export.c
+++ src/export.c
@@ -19,10 +19,28 @@
19 */
20 #include "config.h"
21 #include "export.h"
22 #include <assert.h>
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24 /*
25 ** Output a "committer" record for the given user.
26 */
27 static void print_person(const char *zUser){
28 static Stmt q;
@@ -96,10 +114,197 @@
96 db_reset(&q);
97 }
98
99 #define BLOBMARK(rid) ((rid) * 2)
100 #define COMMITMARK(rid) ((rid) * 2 + 1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
102 /*
103 ** COMMAND: export
104 **
105 ** Usage: %fossil export --git ?OPTIONS? ?REPOSITORY?
@@ -112,11 +317,11 @@
112 **
113 ** Run this command within a checkout. Or use the -R or --repository
114 ** option to specify a Fossil repository to be exported.
115 **
116 ** Only check-ins are exported using --git. Git does not support tickets
117 ** or wiki or events or attachments, so none of those are exported.
118 **
119 ** If the "--import-marks FILE" option is used, it contains a list of
120 ** rids to skip.
121 **
122 ** If the "--export-marks FILE" option is used, the rid of all commits and
@@ -147,35 +352,40 @@
147 verify_all_options();
148 if( g.argc!=2 && g.argc!=3 ){ usage("--git ?REPOSITORY?"); }
149
150 db_multi_exec("CREATE TEMPORARY TABLE oldblob(rid INTEGER PRIMARY KEY)");
151 db_multi_exec("CREATE TEMPORARY TABLE oldcommit(rid INTEGER PRIMARY KEY)");
 
152 if( markfile_in!=0 ){
153 Stmt qb,qc;
154 char line[100];
155 FILE *f;
 
156
157 f = fossil_fopen(markfile_in, "r");
158 if( f==0 ){
159 fossil_fatal("cannot open %s for reading", markfile_in);
160 }
 
 
 
161 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
162 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
163 while( fgets(line, sizeof(line), f)!=0 ){
164 if( *line == 'b' ){
165 db_bind_text(&qb, ":rid", line + 1);
 
166 db_step(&qb);
167 db_reset(&qb);
168 bag_insert(&blobs, atoi(line + 1));
169 }else if( *line == 'c' ){
170 db_bind_text(&qc, ":rid", line + 1);
 
 
 
171 db_step(&qc);
172 db_reset(&qc);
173 bag_insert(&vers, atoi(line + 1));
174 }else{
175 fossil_fatal("bad input from %s: %s", markfile_in, line);
176 }
177 }
178 db_finalize(&qb);
179 db_finalize(&qc);
180 fclose(f);
181 }
@@ -249,10 +459,11 @@
249 int ckinId = db_column_int(&q, 1);
250 const char *zComment = db_column_text(&q, 2);
251 const char *zUser = db_column_text(&q, 3);
252 const char *zBranch = db_column_text(&q, 4);
253 char *zBr;
 
254
255 bag_insert(&vers, ckinId);
256 db_bind_int(&q2, ":rid", ckinId);
257 db_step(&q2);
258 db_reset(&q2);
@@ -259,11 +470,13 @@
259 if( zBranch==0 ) zBranch = "trunk";
260 zBr = mprintf("%s", zBranch);
261 for(i=0; zBr[i]; i++){
262 if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
263 }
264 printf("commit refs/heads/%s\nmark :%d\n", zBr, COMMITMARK(ckinId));
 
 
265 free(zBr);
266 printf("committer");
267 print_person(zUser);
268 printf(" %s +0000\n", zSecondsSince1970);
269 if( zComment==0 ) zComment = "null comment";
@@ -273,19 +486,24 @@
273 " WHERE cid=%d AND isprim"
274 " AND pid IN (SELECT objid FROM event)",
275 ckinId
276 );
277 if( db_step(&q3) == SQLITE_ROW ){
278 printf("from :%d\n", COMMITMARK(db_column_int(&q3, 0)));
 
 
 
279 db_prepare(&q4,
280 "SELECT pid FROM plink"
281 " WHERE cid=%d AND NOT isprim"
282 " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
283 " ORDER BY pid",
284 ckinId);
285 while( db_step(&q4)==SQLITE_ROW ){
286 printf("merge :%d\n", COMMITMARK(db_column_int(&q4,0)));
 
 
287 }
288 db_finalize(&q4);
289 }else{
290 printf("deleteall\n");
291 }
@@ -316,11 +534,10 @@
316 db_finalize(&q3);
317 printf("\n");
318 }
319 db_finalize(&q2);
320 db_finalize(&q);
321 bag_clear(&blobs);
322 manifest_cache_clear();
323
324
325 /* Output tags */
326 db_prepare(&q,
@@ -345,28 +562,20 @@
345 printf("tagger <tagger> %s +0000\n", zSecSince1970);
346 printf("data 0\n");
347 fossil_free(zEncoded);
348 }
349 db_finalize(&q);
350 bag_clear(&vers);
351
352 if( markfile_out!=0 ){
353 FILE *f;
354 f = fossil_fopen(markfile_out, "w");
355 if( f == 0 ){
356 fossil_fatal("cannot open %s for writing", markfile_out);
357 }
358 db_prepare(&q, "SELECT rid FROM oldblob");
359 while( db_step(&q)==SQLITE_ROW ){
360 fprintf(f, "b%d\n", db_column_int(&q, 0));
361 }
362 db_finalize(&q);
363 db_prepare(&q, "SELECT rid FROM oldcommit");
364 while( db_step(&q)==SQLITE_ROW ){
365 fprintf(f, "c%d\n", db_column_int(&q, 0));
366 }
367 db_finalize(&q);
368 if( ferror(f)!=0 || fclose(f)!=0 ) {
369 fossil_fatal("error while writing %s", markfile_out);
370 }
371 }
 
 
372 }
373
--- src/export.c
+++ src/export.c
@@ -19,10 +19,28 @@
19 */
20 #include "config.h"
21 #include "export.h"
22 #include <assert.h>
23
24 #if INTERFACE
25 /*
26 ** struct mark_t
27 ** holds information for translating between git commits
28 ** and fossil commits.
29 ** -git_name: This is the mark name that identifies the commit to git.
30 ** It will always begin with a ':'.
31 ** -rid: The unique object ID that identifies this commit within the
32 ** repository database.
33 ** -uuid: The SHA-1 of artifact corresponding to rid.
34 */
35 struct mark_t{
36 char *name;
37 int rid;
38 char uuid[41];
39 };
40 #endif
41
42 /*
43 ** Output a "committer" record for the given user.
44 */
45 static void print_person(const char *zUser){
46 static Stmt q;
@@ -96,10 +114,197 @@
114 db_reset(&q);
115 }
116
117 #define BLOBMARK(rid) ((rid) * 2)
118 #define COMMITMARK(rid) ((rid) * 2 + 1)
119
120 /*
121 ** insert_commit_xref()
122 ** Insert a new (mark,rid,uuid) entry into the 'xmark' table.
123 ** zName and zUuid must be non-null and must point to NULL-terminated strings.
124 */
125 void insert_commit_xref(int rid, const char *zName, const char *zUuid){
126 db_multi_exec(
127 "INSERT OR IGNORE INTO xmark(tname, trid, tuuid)"
128 "VALUES(%Q,%d,%Q)",
129 zName, rid, zUuid
130 );
131 }
132
133 /*
134 ** create_mark()
135 ** Create a new (mark,rid,uuid) entry for the given rid in the 'xmark' table,
136 ** and return that information as a struct mark_t in *mark.
137 ** This function returns -1 in the case where 'rid' does not exist, otherwise
138 ** it returns 0.
139 ** mark->name is dynamically allocated and is owned by the caller upon return.
140 */
141 int create_mark(int rid, struct mark_t *mark){
142 char sid[13];
143 char *zUuid = rid_to_uuid(rid);
144 if(!zUuid){
145 fossil_trace("Undefined rid=%d\n", rid);
146 return -1;
147 }
148 mark->rid = rid;
149 sprintf(sid, ":%d", COMMITMARK(rid));
150 mark->name = fossil_strdup(sid);
151 strcpy(mark->uuid, zUuid);
152 free(zUuid);
153 insert_commit_xref(mark->rid, mark->name, mark->uuid);
154 return 0;
155 }
156
157 /*
158 ** mark_name_from_rid()
159 ** Find the mark associated with the given rid. Mark names always start
160 ** with ':', and are pulled from the 'xmark' temporary table.
161 ** This function returns NULL if the rid does not exist in the 'xmark' table.
162 ** Otherwise, it returns the name of the mark, which is dynamically allocated
163 ** and is owned by the caller of this function.
164 */
165 char * mark_name_from_rid(int rid){
166 char *zMark = db_text(0, "SELECT tname FROM xmark WHERE trid=%d", rid);
167 if(zMark==NULL){
168 struct mark_t mark;
169 if(create_mark(rid, &mark)==0){
170 zMark = mark.name;
171 }else{
172 return NULL;
173 }
174 }
175 return zMark;
176 }
177
178 /*
179 ** parse_mark()
180 ** Create a new (mark,rid,uuid) entry in the 'xmark' table given a line
181 ** from a marks file. Return the cross-ref information as a struct mark_t
182 ** in *mark.
183 ** This function returns -1 in the case that the line is blank, malformed, or
184 ** the rid/uuid named in 'line' does not match what is in the repository
185 ** database. Otherwise, 0 is returned.
186 ** mark->name is dynamically allocated, and owned by the caller.
187 */
188 int parse_mark(char *line, struct mark_t *mark){
189 char *cur_tok;
190 cur_tok = strtok(line, " \t");
191 if(!cur_tok||strlen(cur_tok)<2){
192 return -1;
193 }
194 mark->rid = atoi(&cur_tok[1]);
195 if(cur_tok[0]!='c'){
196 /* This is probably a blob mark */
197 mark->name = NULL;
198 return 0;
199 }
200
201 cur_tok = strtok(NULL, " \t");
202 if(!cur_tok){
203 /* This mark was generated by an older version of Fossil and doesn't
204 ** include the mark name and uuid. create_mark() will name the new mark
205 ** exactly as it was when exported to git, so that we should have a
206 ** valid mapping from git sha1<->mark name<->fossil sha1. */
207 return create_mark(mark->rid, mark);
208 }else{
209 mark->name = fossil_strdup(cur_tok);
210 }
211
212 cur_tok = strtok(NULL, "\n");
213 if(!cur_tok||strlen(cur_tok)!=40){
214 free(mark->name);
215 fossil_trace("Invalid SHA-1 in marks file: %s\n", cur_tok);
216 return -1;
217 }else{
218 strcpy(mark->uuid, cur_tok);
219 }
220
221 /* make sure that rid corresponds to UUID */
222 if(fast_uuid_to_rid(mark->uuid)!=mark->rid){
223 free(mark->name);
224 fossil_trace("Non-existent SHA-1 in marks file: %s\n", mark->uuid);
225 return -1;
226 }
227
228 /* insert a cross-ref into the 'xmark' table */
229 insert_commit_xref(mark->rid, mark->name, mark->uuid);
230 return 0;
231 }
232
233 /*
234 ** import_marks()
235 ** Import the marks specified in file 'f' into the 'xmark' table.
236 ** If 'blobs' is non-null, insert all blob marks into it.
237 ** If 'vers' is non-null, insert all commit marks into it.
238 ** Each line in the file must be at most 100 characters in length. This
239 ** seems like a reasonable maximum for a 40-character uuid, and 1-13
240 ** character rid.
241 ** The function returns -1 if any of the lines in file 'f' are malformed,
242 ** or the rid/uuid information doesn't match what is in the repository
243 ** database. Otherwise, 0 is returned.
244 */
245 int import_marks(FILE* f, Bag *blobs, Bag *vers){
246 char line[101];
247 while(fgets(line, sizeof(line), f)){
248 struct mark_t mark;
249 if(strlen(line)==100&&line[99]!='\n'){
250 /* line too long */
251 return -1;
252 }
253 if( parse_mark(line, &mark)<0 ){
254 return -1;
255 }else if( line[0]=='b' ){
256 /* Don't import blob marks into 'xmark' table--git doesn't use them,
257 ** so they need to be left free for git to reuse. */
258 if(blobs!=NULL){
259 bag_insert(blobs, mark.rid);
260 }
261 }else if( vers!=NULL ){
262 bag_insert(vers, mark.rid);
263 }
264 free(mark.name);
265 }
266 return 0;
267 }
268
269 /*
270 ** If 'blobs' is non-null, it must point to a Bag of blob rids to be
271 ** written to disk. Blob rids are written as 'b<rid>'.
272 ** If 'vers' is non-null, it must point to a Bag of commit rids to be
273 ** written to disk. Commit rids are written as 'c<rid> :<mark> <uuid>'.
274 ** All commit (mark,rid,uuid) tuples are stored in 'xmark' table.
275 ** This function does not fail, but may produce errors if a uuid cannot
276 ** be found for an rid in 'vers'.
277 */
278 void export_marks(FILE* f, Bag *blobs, Bag *vers){
279 int rid;
280 if( blobs!=NULL ){
281 rid = bag_first(blobs);
282 if(rid!=0){
283 do{
284 fprintf(f, "b%d\n", rid);
285 }while((rid = bag_next(blobs, rid))!=0);
286 }
287 }
288 if( vers!=NULL ){
289 rid = bag_first(vers);
290 if( rid!=0 ){
291 do{
292 char *zUuid = rid_to_uuid(rid);
293 char *zMark;
294 if(zUuid==NULL){
295 fossil_trace("No uuid matching rid=%d when exporting marks\n", rid);
296 continue;
297 }
298 zMark = mark_name_from_rid(rid);
299 fprintf(f, "c%d %s %s\n", rid, zMark, zUuid);
300 free(zMark);
301 free(zUuid);
302 }while( (rid = bag_next(vers, rid))!=0 );
303 }
304 }
305 }
306
307 /*
308 ** COMMAND: export
309 **
310 ** Usage: %fossil export --git ?OPTIONS? ?REPOSITORY?
@@ -112,11 +317,11 @@
317 **
318 ** Run this command within a checkout. Or use the -R or --repository
319 ** option to specify a Fossil repository to be exported.
320 **
321 ** Only check-ins are exported using --git. Git does not support tickets
322 ** or wiki or tech notes or attachments, so none of those are exported.
323 **
324 ** If the "--import-marks FILE" option is used, it contains a list of
325 ** rids to skip.
326 **
327 ** If the "--export-marks FILE" option is used, the rid of all commits and
@@ -147,35 +352,40 @@
352 verify_all_options();
353 if( g.argc!=2 && g.argc!=3 ){ usage("--git ?REPOSITORY?"); }
354
355 db_multi_exec("CREATE TEMPORARY TABLE oldblob(rid INTEGER PRIMARY KEY)");
356 db_multi_exec("CREATE TEMPORARY TABLE oldcommit(rid INTEGER PRIMARY KEY)");
357 db_multi_exec("CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT)");
358 if( markfile_in!=0 ){
359 Stmt qb,qc;
 
360 FILE *f;
361 int rid;
362
363 f = fossil_fopen(markfile_in, "r");
364 if( f==0 ){
365 fossil_fatal("cannot open %s for reading", markfile_in);
366 }
367 if(import_marks(f, &blobs, &vers)<0){
368 fossil_fatal("error importing marks from file: %s\n", markfile_in);
369 }
370 db_prepare(&qb, "INSERT OR IGNORE INTO oldblob VALUES (:rid)");
371 db_prepare(&qc, "INSERT OR IGNORE INTO oldcommit VALUES (:rid)");
372 rid = bag_first(&blobs);
373 if(rid!=0){
374 do{
375 db_bind_int(&qb, ":rid", rid);
376 db_step(&qb);
377 db_reset(&qb);
378 }while((rid = bag_next(&blobs, rid))!=0);
379 }
380 rid = bag_first(&vers);
381 if(rid!=0){
382 do{
383 db_bind_int(&qc, ":rid", rid);
384 db_step(&qc);
385 db_reset(&qc);
386 }while((rid = bag_next(&vers, rid))!=0);
 
 
 
387 }
388 db_finalize(&qb);
389 db_finalize(&qc);
390 fclose(f);
391 }
@@ -249,10 +459,11 @@
459 int ckinId = db_column_int(&q, 1);
460 const char *zComment = db_column_text(&q, 2);
461 const char *zUser = db_column_text(&q, 3);
462 const char *zBranch = db_column_text(&q, 4);
463 char *zBr;
464 char *zMark;
465
466 bag_insert(&vers, ckinId);
467 db_bind_int(&q2, ":rid", ckinId);
468 db_step(&q2);
469 db_reset(&q2);
@@ -259,11 +470,13 @@
470 if( zBranch==0 ) zBranch = "trunk";
471 zBr = mprintf("%s", zBranch);
472 for(i=0; zBr[i]; i++){
473 if( !fossil_isalnum(zBr[i]) ) zBr[i] = '_';
474 }
475 zMark = mark_name_from_rid(ckinId);
476 printf("commit refs/heads/%s\nmark %s\n", zBr, zMark);
477 free(zMark);
478 free(zBr);
479 printf("committer");
480 print_person(zUser);
481 printf(" %s +0000\n", zSecondsSince1970);
482 if( zComment==0 ) zComment = "null comment";
@@ -273,19 +486,24 @@
486 " WHERE cid=%d AND isprim"
487 " AND pid IN (SELECT objid FROM event)",
488 ckinId
489 );
490 if( db_step(&q3) == SQLITE_ROW ){
491 int pid = db_column_int(&q3, 0);
492 zMark = mark_name_from_rid(pid);
493 printf("from %s\n", zMark);
494 free(zMark);
495 db_prepare(&q4,
496 "SELECT pid FROM plink"
497 " WHERE cid=%d AND NOT isprim"
498 " AND NOT EXISTS(SELECT 1 FROM phantom WHERE rid=pid)"
499 " ORDER BY pid",
500 ckinId);
501 while( db_step(&q4)==SQLITE_ROW ){
502 zMark = mark_name_from_rid(db_column_int(&q4, 0));
503 printf("merge %s\n", zMark);
504 free(zMark);
505 }
506 db_finalize(&q4);
507 }else{
508 printf("deleteall\n");
509 }
@@ -316,11 +534,10 @@
534 db_finalize(&q3);
535 printf("\n");
536 }
537 db_finalize(&q2);
538 db_finalize(&q);
 
539 manifest_cache_clear();
540
541
542 /* Output tags */
543 db_prepare(&q,
@@ -345,28 +562,20 @@
562 printf("tagger <tagger> %s +0000\n", zSecSince1970);
563 printf("data 0\n");
564 fossil_free(zEncoded);
565 }
566 db_finalize(&q);
 
567
568 if( markfile_out!=0 ){
569 FILE *f;
570 f = fossil_fopen(markfile_out, "w");
571 if( f == 0 ){
572 fossil_fatal("cannot open %s for writing", markfile_out);
573 }
574 export_marks(f, &blobs, &vers);
 
 
 
 
 
 
 
 
 
575 if( ferror(f)!=0 || fclose(f)!=0 ) {
576 fossil_fatal("error while writing %s", markfile_out);
577 }
578 }
579 bag_clear(&blobs);
580 bag_clear(&vers);
581 }
582
+6 -7
--- src/foci.c
+++ src/foci.c
@@ -13,23 +13,22 @@
1313
** [email protected]
1414
** http://www.hwaci.com/drh/
1515
**
1616
*******************************************************************************
1717
**
18
-** This routine implements an SQLite virtual table that gives all of the
19
-** files associated with a single check-in.
18
+** This routine implements eponymous virtual table for SQLite that gives
19
+** all of the files associated with a single check-in.
2020
**
21
-** The filename "foci" is short for "Files of Check-in".
21
+** The source code filename "foci" is short for "Files of Check-in".
2222
**
2323
** Usage example:
2424
**
25
-** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
26
-** -- ^^^^--- important!
27
-** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
25
+** SELECT * FROM files_of_checkin
26
+** WHERE checkinID=symbolic_name_to_rid('trunk');
2827
**
2928
** The symbolic_name_to_rid('trunk') function finds the BLOB.RID value
30
-** corresponding to the 'trunk' tag. Then the files_of_checkin virtual table
29
+** corresponding to the 'trunk' tag. Then the foci virtual table
3130
** decodes the manifest defined by that BLOB and returns all files described
3231
** by that manifest. The "schema" for the temp.foci table is:
3332
**
3433
** CREATE TABLE files_of_checkin(
3534
** checkinID INTEGER, -- RID for the check-in manifest
3635
--- src/foci.c
+++ src/foci.c
@@ -13,23 +13,22 @@
13 ** [email protected]
14 ** http://www.hwaci.com/drh/
15 **
16 *******************************************************************************
17 **
18 ** This routine implements an SQLite virtual table that gives all of the
19 ** files associated with a single check-in.
20 **
21 ** The filename "foci" is short for "Files of Check-in".
22 **
23 ** Usage example:
24 **
25 ** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
26 ** -- ^^^^--- important!
27 ** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
28 **
29 ** The symbolic_name_to_rid('trunk') function finds the BLOB.RID value
30 ** corresponding to the 'trunk' tag. Then the files_of_checkin virtual table
31 ** decodes the manifest defined by that BLOB and returns all files described
32 ** by that manifest. The "schema" for the temp.foci table is:
33 **
34 ** CREATE TABLE files_of_checkin(
35 ** checkinID INTEGER, -- RID for the check-in manifest
36
--- src/foci.c
+++ src/foci.c
@@ -13,23 +13,22 @@
13 ** [email protected]
14 ** http://www.hwaci.com/drh/
15 **
16 *******************************************************************************
17 **
18 ** This routine implements eponymous virtual table for SQLite that gives
19 ** all of the files associated with a single check-in.
20 **
21 ** The source code filename "foci" is short for "Files of Check-in".
22 **
23 ** Usage example:
24 **
25 ** SELECT * FROM files_of_checkin
26 ** WHERE checkinID=symbolic_name_to_rid('trunk');
 
27 **
28 ** The symbolic_name_to_rid('trunk') function finds the BLOB.RID value
29 ** corresponding to the 'trunk' tag. Then the foci virtual table
30 ** decodes the manifest defined by that BLOB and returns all files described
31 ** by that manifest. The "schema" for the temp.foci table is:
32 **
33 ** CREATE TABLE files_of_checkin(
34 ** checkinID INTEGER, -- RID for the check-in manifest
35
+14 -6
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -452,15 +452,19 @@
452452
453453
/*
454454
** Send content out over the SSL connection.
455455
*/
456456
size_t ssl_send(void *NotUsed, void *pContent, size_t N){
457
- size_t sent;
458457
size_t total = 0;
459458
while( N>0 ){
460
- sent = BIO_write(iBio, pContent, N);
461
- if( sent<=0 ) break;
459
+ int sent = BIO_write(iBio, pContent, N);
460
+ if( sent<=0 ){
461
+ if( BIO_should_retry(iBio) ){
462
+ continue;
463
+ }
464
+ break;
465
+ }
462466
total += sent;
463467
N -= sent;
464468
pContent = (void*)&((char*)pContent)[sent];
465469
}
466470
return total;
@@ -468,18 +472,22 @@
468472
469473
/*
470474
** Receive content back from the SSL connection.
471475
*/
472476
size_t ssl_receive(void *NotUsed, void *pContent, size_t N){
473
- size_t got;
474477
size_t total = 0;
475478
while( N>0 ){
476
- got = BIO_read(iBio, pContent, N);
477
- if( got<=0 ) break;
479
+ int got = BIO_read(iBio, pContent, N);
480
+ if( got<=0 ){
481
+ if( BIO_should_retry(iBio) ){
482
+ continue;
483
+ }
484
+ break;
485
+ }
478486
total += got;
479487
N -= got;
480488
pContent = (void*)&((char*)pContent)[got];
481489
}
482490
return total;
483491
}
484492
485493
#endif /* FOSSIL_ENABLE_SSL */
486494
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -452,15 +452,19 @@
452
453 /*
454 ** Send content out over the SSL connection.
455 */
456 size_t ssl_send(void *NotUsed, void *pContent, size_t N){
457 size_t sent;
458 size_t total = 0;
459 while( N>0 ){
460 sent = BIO_write(iBio, pContent, N);
461 if( sent<=0 ) break;
 
 
 
 
 
462 total += sent;
463 N -= sent;
464 pContent = (void*)&((char*)pContent)[sent];
465 }
466 return total;
@@ -468,18 +472,22 @@
468
469 /*
470 ** Receive content back from the SSL connection.
471 */
472 size_t ssl_receive(void *NotUsed, void *pContent, size_t N){
473 size_t got;
474 size_t total = 0;
475 while( N>0 ){
476 got = BIO_read(iBio, pContent, N);
477 if( got<=0 ) break;
 
 
 
 
 
478 total += got;
479 N -= got;
480 pContent = (void*)&((char*)pContent)[got];
481 }
482 return total;
483 }
484
485 #endif /* FOSSIL_ENABLE_SSL */
486
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -452,15 +452,19 @@
452
453 /*
454 ** Send content out over the SSL connection.
455 */
456 size_t ssl_send(void *NotUsed, void *pContent, size_t N){
 
457 size_t total = 0;
458 while( N>0 ){
459 int sent = BIO_write(iBio, pContent, N);
460 if( sent<=0 ){
461 if( BIO_should_retry(iBio) ){
462 continue;
463 }
464 break;
465 }
466 total += sent;
467 N -= sent;
468 pContent = (void*)&((char*)pContent)[sent];
469 }
470 return total;
@@ -468,18 +472,22 @@
472
473 /*
474 ** Receive content back from the SSL connection.
475 */
476 size_t ssl_receive(void *NotUsed, void *pContent, size_t N){
 
477 size_t total = 0;
478 while( N>0 ){
479 int got = BIO_read(iBio, pContent, N);
480 if( got<=0 ){
481 if( BIO_should_retry(iBio) ){
482 continue;
483 }
484 break;
485 }
486 total += got;
487 N -= got;
488 pContent = (void*)&((char*)pContent)[got];
489 }
490 return total;
491 }
492
493 #endif /* FOSSIL_ENABLE_SSL */
494
+50 -2
--- src/import.c
+++ src/import.c
@@ -1494,10 +1494,13 @@
14941494
** data is read from standard input.
14951495
**
14961496
** The following formats are currently understood by this command
14971497
**
14981498
** --git Import from the git-fast-export file format (default)
1499
+** Options:
1500
+** --import-marks FILE Restore marks table from FILE
1501
+** --export-marks FILE Save marks table to FILE
14991502
**
15001503
** --svn Import from the svnadmin-dump file format. The default
15011504
** behaviour (unless overridden by --flat) is to treat 3
15021505
** folders in the SVN root as special, following the
15031506
** common layout of SVN repositories. These are (by
@@ -1525,19 +1528,24 @@
15251528
char *zPassword;
15261529
FILE *pIn;
15271530
Stmt q;
15281531
int forceFlag = find_option("force", "f", 0)!=0;
15291532
int svnFlag = find_option("svn", 0, 0)!=0;
1533
+ int gitFlag = find_option("git", 0, 0)!=0;
15301534
int omitRebuild = find_option("no-rebuild",0,0)!=0;
15311535
int omitVacuum = find_option("no-vacuum",0,0)!=0;
15321536
15331537
/* Options common to all input formats */
15341538
int incrFlag = find_option("incremental", "i", 0)!=0;
15351539
15361540
/* Options for --svn only */
15371541
const char *zBase="";
15381542
int flatFlag=0;
1543
+
1544
+ /* Options for --git only */
1545
+ const char *markfile_in;
1546
+ const char *markfile_out;
15391547
15401548
if( svnFlag ){
15411549
/* Get --svn related options here, so verify_all_options() fail when svn
15421550
* only option are specify with --git
15431551
*/
@@ -1545,12 +1553,13 @@
15451553
flatFlag = find_option("flat", 0, 0)!=0;
15461554
gsvn.zTrunk = find_option("trunk", 0, 1);
15471555
gsvn.zBranches = find_option("branches", 0, 1);
15481556
gsvn.zTags = find_option("tags", 0, 1);
15491557
gsvn.incrFlag = incrFlag;
1550
- }else{
1551
- find_option("git",0,0); /* Skip the --git option for now */
1558
+ }else if( gitFlag ){
1559
+ markfile_in = find_option("import-marks", 0, 1);
1560
+ markfile_out = find_option("export-marks", 0, 1);
15521561
}
15531562
verify_all_options();
15541563
15551564
if( g.argc!=3 && g.argc!=4 ){
15561565
usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?");
@@ -1624,10 +1633,13 @@
16241633
gsvn.lenTags++;
16251634
}
16261635
}
16271636
svn_dump_import(pIn);
16281637
}else{
1638
+ Bag blobs, vers;
1639
+ bag_init(&blobs);
1640
+ bag_init(&vers);
16291641
/* The following temp-tables are used to hold information needed for
16301642
** the import.
16311643
**
16321644
** The XMARK table provides a mapping from fast-import "marks" and symbols
16331645
** into artifact ids (UUIDs - the 40-byte hex SHA1 hash of artifacts).
@@ -1648,10 +1660,21 @@
16481660
db_multi_exec(
16491661
"CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT);"
16501662
"CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
16511663
"CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
16521664
);
1665
+
1666
+ if(markfile_in){
1667
+ FILE *f = fossil_fopen(markfile_in, "r");
1668
+ if(!f){
1669
+ fossil_fatal("cannot open %s for reading\n", markfile_in);
1670
+ }
1671
+ if(import_marks(f, &blobs, NULL)<0){
1672
+ fossil_fatal("error importing marks from file: %s\n", markfile_in);
1673
+ }
1674
+ fclose(f);
1675
+ }
16531676
16541677
manifest_crosslink_begin();
16551678
git_fast_import(pIn);
16561679
db_prepare(&q, "SELECT tcontent FROM xtag");
16571680
while( db_step(&q)==SQLITE_ROW ){
@@ -1659,10 +1682,35 @@
16591682
db_ephemeral_blob(&q, 0, &record);
16601683
fast_insert_content(&record, 0, 0, 1);
16611684
import_reset(0);
16621685
}
16631686
db_finalize(&q);
1687
+ if(markfile_out){
1688
+ int rid;
1689
+ Stmt q_marks;
1690
+ FILE *f;
1691
+ db_prepare(&q_marks, "SELECT DISTINCT trid FROM xmark");
1692
+ while( db_step(&q_marks)==SQLITE_ROW){
1693
+ rid = db_column_int(&q_marks, 0);
1694
+ if(db_int(0, "SELECT count(objid) FROM event WHERE objid=%d AND type='ci'", rid)==0){
1695
+ if(bag_find(&blobs, rid)==0){
1696
+ bag_insert(&blobs, rid);
1697
+ }
1698
+ }else{
1699
+ bag_insert(&vers, rid);
1700
+ }
1701
+ }
1702
+ db_finalize(&q_marks);
1703
+ f = fossil_fopen(markfile_out, "w");
1704
+ if(!f){
1705
+ fossil_fatal("cannot open %s for writing\n", markfile_out);
1706
+ }
1707
+ export_marks(f, &blobs, &vers);
1708
+ fclose(f);
1709
+ bag_clear(&blobs);
1710
+ bag_clear(&vers);
1711
+ }
16641712
manifest_crosslink_end(MC_NONE);
16651713
}
16661714
16671715
verify_cancel();
16681716
db_end_transaction(0);
16691717
--- src/import.c
+++ src/import.c
@@ -1494,10 +1494,13 @@
1494 ** data is read from standard input.
1495 **
1496 ** The following formats are currently understood by this command
1497 **
1498 ** --git Import from the git-fast-export file format (default)
 
 
 
1499 **
1500 ** --svn Import from the svnadmin-dump file format. The default
1501 ** behaviour (unless overridden by --flat) is to treat 3
1502 ** folders in the SVN root as special, following the
1503 ** common layout of SVN repositories. These are (by
@@ -1525,19 +1528,24 @@
1525 char *zPassword;
1526 FILE *pIn;
1527 Stmt q;
1528 int forceFlag = find_option("force", "f", 0)!=0;
1529 int svnFlag = find_option("svn", 0, 0)!=0;
 
1530 int omitRebuild = find_option("no-rebuild",0,0)!=0;
1531 int omitVacuum = find_option("no-vacuum",0,0)!=0;
1532
1533 /* Options common to all input formats */
1534 int incrFlag = find_option("incremental", "i", 0)!=0;
1535
1536 /* Options for --svn only */
1537 const char *zBase="";
1538 int flatFlag=0;
 
 
 
 
1539
1540 if( svnFlag ){
1541 /* Get --svn related options here, so verify_all_options() fail when svn
1542 * only option are specify with --git
1543 */
@@ -1545,12 +1553,13 @@
1545 flatFlag = find_option("flat", 0, 0)!=0;
1546 gsvn.zTrunk = find_option("trunk", 0, 1);
1547 gsvn.zBranches = find_option("branches", 0, 1);
1548 gsvn.zTags = find_option("tags", 0, 1);
1549 gsvn.incrFlag = incrFlag;
1550 }else{
1551 find_option("git",0,0); /* Skip the --git option for now */
 
1552 }
1553 verify_all_options();
1554
1555 if( g.argc!=3 && g.argc!=4 ){
1556 usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?");
@@ -1624,10 +1633,13 @@
1624 gsvn.lenTags++;
1625 }
1626 }
1627 svn_dump_import(pIn);
1628 }else{
 
 
 
1629 /* The following temp-tables are used to hold information needed for
1630 ** the import.
1631 **
1632 ** The XMARK table provides a mapping from fast-import "marks" and symbols
1633 ** into artifact ids (UUIDs - the 40-byte hex SHA1 hash of artifacts).
@@ -1648,10 +1660,21 @@
1648 db_multi_exec(
1649 "CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT);"
1650 "CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
1651 "CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
1652 );
 
 
 
 
 
 
 
 
 
 
 
1653
1654 manifest_crosslink_begin();
1655 git_fast_import(pIn);
1656 db_prepare(&q, "SELECT tcontent FROM xtag");
1657 while( db_step(&q)==SQLITE_ROW ){
@@ -1659,10 +1682,35 @@
1659 db_ephemeral_blob(&q, 0, &record);
1660 fast_insert_content(&record, 0, 0, 1);
1661 import_reset(0);
1662 }
1663 db_finalize(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1664 manifest_crosslink_end(MC_NONE);
1665 }
1666
1667 verify_cancel();
1668 db_end_transaction(0);
1669
--- src/import.c
+++ src/import.c
@@ -1494,10 +1494,13 @@
1494 ** data is read from standard input.
1495 **
1496 ** The following formats are currently understood by this command
1497 **
1498 ** --git Import from the git-fast-export file format (default)
1499 ** Options:
1500 ** --import-marks FILE Restore marks table from FILE
1501 ** --export-marks FILE Save marks table to FILE
1502 **
1503 ** --svn Import from the svnadmin-dump file format. The default
1504 ** behaviour (unless overridden by --flat) is to treat 3
1505 ** folders in the SVN root as special, following the
1506 ** common layout of SVN repositories. These are (by
@@ -1525,19 +1528,24 @@
1528 char *zPassword;
1529 FILE *pIn;
1530 Stmt q;
1531 int forceFlag = find_option("force", "f", 0)!=0;
1532 int svnFlag = find_option("svn", 0, 0)!=0;
1533 int gitFlag = find_option("git", 0, 0)!=0;
1534 int omitRebuild = find_option("no-rebuild",0,0)!=0;
1535 int omitVacuum = find_option("no-vacuum",0,0)!=0;
1536
1537 /* Options common to all input formats */
1538 int incrFlag = find_option("incremental", "i", 0)!=0;
1539
1540 /* Options for --svn only */
1541 const char *zBase="";
1542 int flatFlag=0;
1543
1544 /* Options for --git only */
1545 const char *markfile_in;
1546 const char *markfile_out;
1547
1548 if( svnFlag ){
1549 /* Get --svn related options here, so verify_all_options() fail when svn
1550 * only option are specify with --git
1551 */
@@ -1545,12 +1553,13 @@
1553 flatFlag = find_option("flat", 0, 0)!=0;
1554 gsvn.zTrunk = find_option("trunk", 0, 1);
1555 gsvn.zBranches = find_option("branches", 0, 1);
1556 gsvn.zTags = find_option("tags", 0, 1);
1557 gsvn.incrFlag = incrFlag;
1558 }else if( gitFlag ){
1559 markfile_in = find_option("import-marks", 0, 1);
1560 markfile_out = find_option("export-marks", 0, 1);
1561 }
1562 verify_all_options();
1563
1564 if( g.argc!=3 && g.argc!=4 ){
1565 usage("--git|--svn ?OPTIONS? NEW-REPOSITORY ?INPUT-FILE?");
@@ -1624,10 +1633,13 @@
1633 gsvn.lenTags++;
1634 }
1635 }
1636 svn_dump_import(pIn);
1637 }else{
1638 Bag blobs, vers;
1639 bag_init(&blobs);
1640 bag_init(&vers);
1641 /* The following temp-tables are used to hold information needed for
1642 ** the import.
1643 **
1644 ** The XMARK table provides a mapping from fast-import "marks" and symbols
1645 ** into artifact ids (UUIDs - the 40-byte hex SHA1 hash of artifacts).
@@ -1648,10 +1660,21 @@
1660 db_multi_exec(
1661 "CREATE TEMP TABLE xmark(tname TEXT UNIQUE, trid INT, tuuid TEXT);"
1662 "CREATE TEMP TABLE xbranch(tname TEXT UNIQUE, brnm TEXT);"
1663 "CREATE TEMP TABLE xtag(tname TEXT UNIQUE, tcontent TEXT);"
1664 );
1665
1666 if(markfile_in){
1667 FILE *f = fossil_fopen(markfile_in, "r");
1668 if(!f){
1669 fossil_fatal("cannot open %s for reading\n", markfile_in);
1670 }
1671 if(import_marks(f, &blobs, NULL)<0){
1672 fossil_fatal("error importing marks from file: %s\n", markfile_in);
1673 }
1674 fclose(f);
1675 }
1676
1677 manifest_crosslink_begin();
1678 git_fast_import(pIn);
1679 db_prepare(&q, "SELECT tcontent FROM xtag");
1680 while( db_step(&q)==SQLITE_ROW ){
@@ -1659,10 +1682,35 @@
1682 db_ephemeral_blob(&q, 0, &record);
1683 fast_insert_content(&record, 0, 0, 1);
1684 import_reset(0);
1685 }
1686 db_finalize(&q);
1687 if(markfile_out){
1688 int rid;
1689 Stmt q_marks;
1690 FILE *f;
1691 db_prepare(&q_marks, "SELECT DISTINCT trid FROM xmark");
1692 while( db_step(&q_marks)==SQLITE_ROW){
1693 rid = db_column_int(&q_marks, 0);
1694 if(db_int(0, "SELECT count(objid) FROM event WHERE objid=%d AND type='ci'", rid)==0){
1695 if(bag_find(&blobs, rid)==0){
1696 bag_insert(&blobs, rid);
1697 }
1698 }else{
1699 bag_insert(&vers, rid);
1700 }
1701 }
1702 db_finalize(&q_marks);
1703 f = fossil_fopen(markfile_out, "w");
1704 if(!f){
1705 fossil_fatal("cannot open %s for writing\n", markfile_out);
1706 }
1707 export_marks(f, &blobs, &vers);
1708 fclose(f);
1709 bag_clear(&blobs);
1710 bag_clear(&vers);
1711 }
1712 manifest_crosslink_end(MC_NONE);
1713 }
1714
1715 verify_cancel();
1716 db_end_transaction(0);
1717
+30 -7
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
13291329
const char *zDate = db_column_text(&q, 0);
13301330
const char *zUser = db_column_text(&q, 1);
13311331
const char *zCom = db_column_text(&q, 2);
13321332
const char *zType = db_column_text(&q, 3);
13331333
const char *zUuid = db_column_text(&q, 4);
1334
+ int eventTagId = db_column_int(&q, 5);
13341335
if( cnt>0 ){
13351336
@ Also
13361337
}
13371338
if( zType[0]=='w' ){
13381339
@ Wiki edit
@@ -1342,17 +1343,21 @@
13421343
objType |= OBJTYPE_TICKET;
13431344
}else if( zType[0]=='c' ){
13441345
@ Manifest of check-in
13451346
objType |= OBJTYPE_CHECKIN;
13461347
}else if( zType[0]=='e' ){
1347
- @ Instance of technote
1348
- objType |= OBJTYPE_EVENT;
1349
- hyperlink_to_event_tagid(db_column_int(&q, 5));
1348
+ if( eventTagId != 0) {
1349
+ @ Instance of technote
1350
+ objType |= OBJTYPE_EVENT;
1351
+ hyperlink_to_event_tagid(db_column_int(&q, 5));
1352
+ }else{
1353
+ @ Attachment to technote
1354
+ }
13501355
}else{
13511356
@ Tag referencing
13521357
}
1353
- if( zType[0]!='e' ){
1358
+ if( zType[0]!='e' || eventTagId == 0){
13541359
hyperlink_to_uuid(zUuid);
13551360
}
13561361
@ - %!W(zCom) by
13571362
hyperlink_to_user(zUser,zDate," on");
13581363
hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
13821387
}else{
13831388
@ Attachment "%h(zFilename)" to
13841389
}
13851390
objType |= OBJTYPE_ATTACHMENT;
13861391
if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1387
- if( g.perm.Hyperlink && g.anon.RdTkt ){
1388
- @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1392
+ if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1393
+ zTarget)
1394
+ ){
1395
+ if( g.perm.Hyperlink && g.anon.RdTkt ){
1396
+ @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1397
+ }else{
1398
+ @ ticket [%S(zTarget)]
1399
+ }
1400
+ }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",
1401
+ zTarget)
1402
+ ){
1403
+ if( g.perm.Hyperlink && g.anon.RdWiki ){
1404
+ @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>]
1405
+ }else{
1406
+ @ tech note [%S(zTarget)]
1407
+ }
13891408
}else{
1390
- @ ticket [%S(zTarget)]
1409
+ if( g.perm.Hyperlink && g.anon.RdWiki ){
1410
+ @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1411
+ }else{
1412
+ @ wiki page [%h(zTarget)]
1413
+ }
13911414
}
13921415
}else{
13931416
if( g.perm.Hyperlink && g.anon.RdWiki ){
13941417
@ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
13951418
}else{
13961419
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
1329 const char *zDate = db_column_text(&q, 0);
1330 const char *zUser = db_column_text(&q, 1);
1331 const char *zCom = db_column_text(&q, 2);
1332 const char *zType = db_column_text(&q, 3);
1333 const char *zUuid = db_column_text(&q, 4);
 
1334 if( cnt>0 ){
1335 @ Also
1336 }
1337 if( zType[0]=='w' ){
1338 @ Wiki edit
@@ -1342,17 +1343,21 @@
1342 objType |= OBJTYPE_TICKET;
1343 }else if( zType[0]=='c' ){
1344 @ Manifest of check-in
1345 objType |= OBJTYPE_CHECKIN;
1346 }else if( zType[0]=='e' ){
1347 @ Instance of technote
1348 objType |= OBJTYPE_EVENT;
1349 hyperlink_to_event_tagid(db_column_int(&q, 5));
 
 
 
 
1350 }else{
1351 @ Tag referencing
1352 }
1353 if( zType[0]!='e' ){
1354 hyperlink_to_uuid(zUuid);
1355 }
1356 @ - %!W(zCom) by
1357 hyperlink_to_user(zUser,zDate," on");
1358 hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
1382 }else{
1383 @ Attachment "%h(zFilename)" to
1384 }
1385 objType |= OBJTYPE_ATTACHMENT;
1386 if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1387 if( g.perm.Hyperlink && g.anon.RdTkt ){
1388 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1389 }else{
1390 @ ticket [%S(zTarget)]
 
 
 
 
1391 }
1392 }else{
1393 if( g.perm.Hyperlink && g.anon.RdWiki ){
1394 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1395 }else{
1396
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
1329 const char *zDate = db_column_text(&q, 0);
1330 const char *zUser = db_column_text(&q, 1);
1331 const char *zCom = db_column_text(&q, 2);
1332 const char *zType = db_column_text(&q, 3);
1333 const char *zUuid = db_column_text(&q, 4);
1334 int eventTagId = db_column_int(&q, 5);
1335 if( cnt>0 ){
1336 @ Also
1337 }
1338 if( zType[0]=='w' ){
1339 @ Wiki edit
@@ -1342,17 +1343,21 @@
1343 objType |= OBJTYPE_TICKET;
1344 }else if( zType[0]=='c' ){
1345 @ Manifest of check-in
1346 objType |= OBJTYPE_CHECKIN;
1347 }else if( zType[0]=='e' ){
1348 if( eventTagId != 0) {
1349 @ Instance of technote
1350 objType |= OBJTYPE_EVENT;
1351 hyperlink_to_event_tagid(db_column_int(&q, 5));
1352 }else{
1353 @ Attachment to technote
1354 }
1355 }else{
1356 @ Tag referencing
1357 }
1358 if( zType[0]!='e' || eventTagId == 0){
1359 hyperlink_to_uuid(zUuid);
1360 }
1361 @ - %!W(zCom) by
1362 hyperlink_to_user(zUser,zDate," on");
1363 hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
1387 }else{
1388 @ Attachment "%h(zFilename)" to
1389 }
1390 objType |= OBJTYPE_ATTACHMENT;
1391 if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1392 if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1393 zTarget)
1394 ){
1395 if( g.perm.Hyperlink && g.anon.RdTkt ){
1396 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1397 }else{
1398 @ ticket [%S(zTarget)]
1399 }
1400 }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",
1401 zTarget)
1402 ){
1403 if( g.perm.Hyperlink && g.anon.RdWiki ){
1404 @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>]
1405 }else{
1406 @ tech note [%S(zTarget)]
1407 }
1408 }else{
1409 if( g.perm.Hyperlink && g.anon.RdWiki ){
1410 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1411 }else{
1412 @ wiki page [%h(zTarget)]
1413 }
1414 }
1415 }else{
1416 if( g.perm.Hyperlink && g.anon.RdWiki ){
1417 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1418 }else{
1419
+30 -7
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
13291329
const char *zDate = db_column_text(&q, 0);
13301330
const char *zUser = db_column_text(&q, 1);
13311331
const char *zCom = db_column_text(&q, 2);
13321332
const char *zType = db_column_text(&q, 3);
13331333
const char *zUuid = db_column_text(&q, 4);
1334
+ int eventTagId = db_column_int(&q, 5);
13341335
if( cnt>0 ){
13351336
@ Also
13361337
}
13371338
if( zType[0]=='w' ){
13381339
@ Wiki edit
@@ -1342,17 +1343,21 @@
13421343
objType |= OBJTYPE_TICKET;
13431344
}else if( zType[0]=='c' ){
13441345
@ Manifest of check-in
13451346
objType |= OBJTYPE_CHECKIN;
13461347
}else if( zType[0]=='e' ){
1347
- @ Instance of technote
1348
- objType |= OBJTYPE_EVENT;
1349
- hyperlink_to_event_tagid(db_column_int(&q, 5));
1348
+ if( eventTagId != 0) {
1349
+ @ Instance of technote
1350
+ objType |= OBJTYPE_EVENT;
1351
+ hyperlink_to_event_tagid(db_column_int(&q, 5));
1352
+ }else{
1353
+ @ Attachment to technote
1354
+ }
13501355
}else{
13511356
@ Tag referencing
13521357
}
1353
- if( zType[0]!='e' ){
1358
+ if( zType[0]!='e' || eventTagId == 0){
13541359
hyperlink_to_uuid(zUuid);
13551360
}
13561361
@ - %!W(zCom) by
13571362
hyperlink_to_user(zUser,zDate," on");
13581363
hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
13821387
}else{
13831388
@ Attachment "%h(zFilename)" to
13841389
}
13851390
objType |= OBJTYPE_ATTACHMENT;
13861391
if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1387
- if( g.perm.Hyperlink && g.anon.RdTkt ){
1388
- @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1392
+ if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1393
+ zTarget)
1394
+ ){
1395
+ if( g.perm.Hyperlink && g.anon.RdTkt ){
1396
+ @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1397
+ }else{
1398
+ @ ticket [%S(zTarget)]
1399
+ }
1400
+ }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",
1401
+ zTarget)
1402
+ ){
1403
+ if( g.perm.Hyperlink && g.anon.RdWiki ){
1404
+ @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>]
1405
+ }else{
1406
+ @ tech note [%S(zTarget)]
1407
+ }
13891408
}else{
1390
- @ ticket [%S(zTarget)]
1409
+ if( g.perm.Hyperlink && g.anon.RdWiki ){
1410
+ @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1411
+ }else{
1412
+ @ wiki page [%h(zTarget)]
1413
+ }
13911414
}
13921415
}else{
13931416
if( g.perm.Hyperlink && g.anon.RdWiki ){
13941417
@ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
13951418
}else{
13961419
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
1329 const char *zDate = db_column_text(&q, 0);
1330 const char *zUser = db_column_text(&q, 1);
1331 const char *zCom = db_column_text(&q, 2);
1332 const char *zType = db_column_text(&q, 3);
1333 const char *zUuid = db_column_text(&q, 4);
 
1334 if( cnt>0 ){
1335 @ Also
1336 }
1337 if( zType[0]=='w' ){
1338 @ Wiki edit
@@ -1342,17 +1343,21 @@
1342 objType |= OBJTYPE_TICKET;
1343 }else if( zType[0]=='c' ){
1344 @ Manifest of check-in
1345 objType |= OBJTYPE_CHECKIN;
1346 }else if( zType[0]=='e' ){
1347 @ Instance of technote
1348 objType |= OBJTYPE_EVENT;
1349 hyperlink_to_event_tagid(db_column_int(&q, 5));
 
 
 
 
1350 }else{
1351 @ Tag referencing
1352 }
1353 if( zType[0]!='e' ){
1354 hyperlink_to_uuid(zUuid);
1355 }
1356 @ - %!W(zCom) by
1357 hyperlink_to_user(zUser,zDate," on");
1358 hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
1382 }else{
1383 @ Attachment "%h(zFilename)" to
1384 }
1385 objType |= OBJTYPE_ATTACHMENT;
1386 if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1387 if( g.perm.Hyperlink && g.anon.RdTkt ){
1388 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1389 }else{
1390 @ ticket [%S(zTarget)]
 
 
 
 
1391 }
1392 }else{
1393 if( g.perm.Hyperlink && g.anon.RdWiki ){
1394 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1395 }else{
1396
--- src/info.c
+++ src/info.c
@@ -1329,10 +1329,11 @@
1329 const char *zDate = db_column_text(&q, 0);
1330 const char *zUser = db_column_text(&q, 1);
1331 const char *zCom = db_column_text(&q, 2);
1332 const char *zType = db_column_text(&q, 3);
1333 const char *zUuid = db_column_text(&q, 4);
1334 int eventTagId = db_column_int(&q, 5);
1335 if( cnt>0 ){
1336 @ Also
1337 }
1338 if( zType[0]=='w' ){
1339 @ Wiki edit
@@ -1342,17 +1343,21 @@
1343 objType |= OBJTYPE_TICKET;
1344 }else if( zType[0]=='c' ){
1345 @ Manifest of check-in
1346 objType |= OBJTYPE_CHECKIN;
1347 }else if( zType[0]=='e' ){
1348 if( eventTagId != 0) {
1349 @ Instance of technote
1350 objType |= OBJTYPE_EVENT;
1351 hyperlink_to_event_tagid(db_column_int(&q, 5));
1352 }else{
1353 @ Attachment to technote
1354 }
1355 }else{
1356 @ Tag referencing
1357 }
1358 if( zType[0]!='e' || eventTagId == 0){
1359 hyperlink_to_uuid(zUuid);
1360 }
1361 @ - %!W(zCom) by
1362 hyperlink_to_user(zUser,zDate," on");
1363 hyperlink_to_date(zDate, ".");
@@ -1382,14 +1387,32 @@
1387 }else{
1388 @ Attachment "%h(zFilename)" to
1389 }
1390 objType |= OBJTYPE_ATTACHMENT;
1391 if( strlen(zTarget)==UUID_SIZE && validate16(zTarget,UUID_SIZE) ){
1392 if ( db_exists("SELECT 1 FROM tag WHERE tagname='tkt-%q'",
1393 zTarget)
1394 ){
1395 if( g.perm.Hyperlink && g.anon.RdTkt ){
1396 @ ticket [%z(href("%R/tktview?name=%!S",zTarget))%S(zTarget)</a>]
1397 }else{
1398 @ ticket [%S(zTarget)]
1399 }
1400 }else if( db_exists("SELECT 1 FROM tag WHERE tagname='event-%q'",
1401 zTarget)
1402 ){
1403 if( g.perm.Hyperlink && g.anon.RdWiki ){
1404 @ tech note [%z(href("%R/technote/%h",zTarget))%S(zTarget)</a>]
1405 }else{
1406 @ tech note [%S(zTarget)]
1407 }
1408 }else{
1409 if( g.perm.Hyperlink && g.anon.RdWiki ){
1410 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1411 }else{
1412 @ wiki page [%h(zTarget)]
1413 }
1414 }
1415 }else{
1416 if( g.perm.Hyperlink && g.anon.RdWiki ){
1417 @ wiki page [%z(href("%R/wiki?name=%t",zTarget))%h(zTarget)</a>]
1418 }else{
1419
+2 -1
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -374,12 +374,13 @@
374374
if(contentLen){
375375
blob_append(&content, cson_string_cstr(jstr),contentLen);
376376
}
377377
378378
zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379
+ zMimeType = wiki_filter_mimetypes(zMimeType);
379380
380
- wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
381
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0);
381382
blob_reset(&content);
382383
/*
383384
Our return value here has a race condition: if this operation
384385
is called concurrently for the same wiki page via two requests,
385386
payV could reflect the results of the other save operation.
386387
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -374,12 +374,13 @@
374 if(contentLen){
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
 
379
380 wiki_cmd_commit(zPageName, 0==rid, &content, zMimeType, 0);
381 blob_reset(&content);
382 /*
383 Our return value here has a race condition: if this operation
384 is called concurrently for the same wiki page via two requests,
385 payV could reflect the results of the other save operation.
386
--- src/json_wiki.c
+++ src/json_wiki.c
@@ -374,12 +374,13 @@
374 if(contentLen){
375 blob_append(&content, cson_string_cstr(jstr),contentLen);
376 }
377
378 zMimeType = json_find_option_cstr("mimetype","mimetype","M");
379 zMimeType = wiki_filter_mimetypes(zMimeType);
380
381 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 0);
382 blob_reset(&content);
383 /*
384 Our return value here has a race condition: if this operation
385 is called concurrently for the same wiki page via two requests,
386 payV could reflect the results of the other save operation.
387
+8 -4
--- src/main.c
+++ src/main.c
@@ -1081,10 +1081,13 @@
10811081
#if defined(FOSSIL_DYNAMIC_BUILD)
10821082
blob_append(pOut, "DYNAMIC_BUILD\n", -1);
10831083
#else
10841084
blob_append(pOut, "STATIC_BUILD\n", -1);
10851085
#endif
1086
+#if defined(USE_SEE)
1087
+ blob_append(pOut, "USE_SEE\n", -1);
1088
+#endif
10861089
}
10871090
10881091
/*
10891092
** This function returns the user-agent string for Fossil, for
10901093
** use in HTTP(S) requests.
@@ -1585,10 +1588,11 @@
15851588
n = db_int(0, "SELECT count(*) FROM sfile");
15861589
if( n>0 ){
15871590
Stmt q;
15881591
@ <html>
15891592
@ <head>
1593
+ @ <base href="%s(g.zBaseURL)/" />
15901594
@ <title>Repository List</title>
15911595
@ </head>
15921596
@ <body>
15931597
@ <h1>Available Repositories:</h1>
15941598
@ <ol>
@@ -1595,11 +1599,11 @@
15951599
db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
15961600
" FROM sfile ORDER BY x COLLATE nocase;");
15971601
while( db_step(&q)==SQLITE_ROW ){
15981602
const char *zName = db_column_text(&q, 0);
15991603
const char *zUrl = db_column_text(&q, 1);
1600
- @ <li><a href="%h(zUrl)" target="_blank">%h(zName)</a></li>
1604
+ @ <li><a href="%R/%h(zUrl)" target="_blank">%h(zName)</a></li>
16011605
}
16021606
@ </ol>
16031607
@ </body>
16041608
@ </html>
16051609
cgi_reply();
@@ -2659,13 +2663,13 @@
26592663
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
26602664
db_close(1);
26612665
if( allowRepoList ){
26622666
flags |= HTTP_SERVER_REPOLIST;
26632667
}
2664
- if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2665
- win32_http_server(iPort, mxPort, zBrowserCmd,
2666
- zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2668
+ if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
2669
+ win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2670
+ zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
26672671
}
26682672
#endif
26692673
}
26702674
26712675
/*
26722676
--- src/main.c
+++ src/main.c
@@ -1081,10 +1081,13 @@
1081 #if defined(FOSSIL_DYNAMIC_BUILD)
1082 blob_append(pOut, "DYNAMIC_BUILD\n", -1);
1083 #else
1084 blob_append(pOut, "STATIC_BUILD\n", -1);
1085 #endif
 
 
 
1086 }
1087
1088 /*
1089 ** This function returns the user-agent string for Fossil, for
1090 ** use in HTTP(S) requests.
@@ -1585,10 +1588,11 @@
1585 n = db_int(0, "SELECT count(*) FROM sfile");
1586 if( n>0 ){
1587 Stmt q;
1588 @ <html>
1589 @ <head>
 
1590 @ <title>Repository List</title>
1591 @ </head>
1592 @ <body>
1593 @ <h1>Available Repositories:</h1>
1594 @ <ol>
@@ -1595,11 +1599,11 @@
1595 db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
1596 " FROM sfile ORDER BY x COLLATE nocase;");
1597 while( db_step(&q)==SQLITE_ROW ){
1598 const char *zName = db_column_text(&q, 0);
1599 const char *zUrl = db_column_text(&q, 1);
1600 @ <li><a href="%h(zUrl)" target="_blank">%h(zName)</a></li>
1601 }
1602 @ </ol>
1603 @ </body>
1604 @ </html>
1605 cgi_reply();
@@ -2659,13 +2663,13 @@
2659 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2660 db_close(1);
2661 if( allowRepoList ){
2662 flags |= HTTP_SERVER_REPOLIST;
2663 }
2664 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2665 win32_http_server(iPort, mxPort, zBrowserCmd,
2666 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2667 }
2668 #endif
2669 }
2670
2671 /*
2672
--- src/main.c
+++ src/main.c
@@ -1081,10 +1081,13 @@
1081 #if defined(FOSSIL_DYNAMIC_BUILD)
1082 blob_append(pOut, "DYNAMIC_BUILD\n", -1);
1083 #else
1084 blob_append(pOut, "STATIC_BUILD\n", -1);
1085 #endif
1086 #if defined(USE_SEE)
1087 blob_append(pOut, "USE_SEE\n", -1);
1088 #endif
1089 }
1090
1091 /*
1092 ** This function returns the user-agent string for Fossil, for
1093 ** use in HTTP(S) requests.
@@ -1585,10 +1588,11 @@
1588 n = db_int(0, "SELECT count(*) FROM sfile");
1589 if( n>0 ){
1590 Stmt q;
1591 @ <html>
1592 @ <head>
1593 @ <base href="%s(g.zBaseURL)/" />
1594 @ <title>Repository List</title>
1595 @ </head>
1596 @ <body>
1597 @ <h1>Available Repositories:</h1>
1598 @ <ol>
@@ -1595,11 +1599,11 @@
1599 db_prepare(&q, "SELECT x, substr(x,-7,-100000)||'/home'"
1600 " FROM sfile ORDER BY x COLLATE nocase;");
1601 while( db_step(&q)==SQLITE_ROW ){
1602 const char *zName = db_column_text(&q, 0);
1603 const char *zUrl = db_column_text(&q, 1);
1604 @ <li><a href="%R/%h(zUrl)" target="_blank">%h(zName)</a></li>
1605 }
1606 @ </ol>
1607 @ </body>
1608 @ </html>
1609 cgi_reply();
@@ -2659,13 +2663,13 @@
2663 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2664 db_close(1);
2665 if( allowRepoList ){
2666 flags |= HTTP_SERVER_REPOLIST;
2667 }
2668 if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
2669 win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2670 zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
2671 }
2672 #endif
2673 }
2674
2675 /*
2676
+18 -5
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459459
$(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460460
461461
$(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462462
$(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463463
464
-# Run the test suite.
464
+# Run the test suite.
465465
# Other flags that can be included in TESTFLAGS are:
466466
#
467467
# -halt Stop testing after the first failed test
468468
# -keep Keep the temporary workspace for debugging
469469
# -prot Write a detailed log of the tests to the file ./prot
@@ -508,12 +508,12 @@
508508
509509
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
510510
# to 1. If it is set to 1, then there is no need to build or link
511511
# the sqlite3.o object. Instead, the system SQLite will be linked
512512
# using -lsqlite3.
513
-SQLITE3_OBJ.1 =
514513
SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
514
+SQLITE3_OBJ.1 =
515515
SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
516516
517517
# The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
518518
# set to 1. If it is set to 1, the miniz library included in the
519519
# source tree should be used; otherwise, it should not.
@@ -528,10 +528,23 @@
528528
LINENOISE_DEF.1 = -DHAVE_LINENOISE
529529
LINENOISE_DEF. = $(LINENOISE_DEF.0)
530530
LINENOISE_OBJ.0 =
531531
LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
532532
LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
533
+
534
+# The USE_SEE variable may be undefined, 0 or 1. If undefined or
535
+# 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
536
+# the source tree) is used and extra flags are provided to enable
537
+# the SQLite Encryption Extension.
538
+SQLITE3_SRC.0 = sqlite3.c
539
+SQLITE3_SRC.1 = sqlite3-see.c
540
+SQLITE3_SRC. = sqlite3.c
541
+SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
542
+SEE_FLAGS.0 =
543
+SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
544
+SEE_FLAGS. =
545
+SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
533546
534547
535548
EXTRAOBJ = \
536549
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
537550
$(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -1640,13 +1653,13 @@
16401653
$(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
16411654
$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
16421655
16431656
$(OBJDIR)/zip.h: $(OBJDIR)/headers
16441657
1645
-$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1646
- $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
1647
-
1658
+$(OBJDIR)/sqlite3.o: $(SQLITE3_SRC)
1659
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
1660
+ -c $(SQLITE3_SRC) -o $@
16481661
$(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
16491662
$(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SRCDIR)/shell.c -o $@
16501663
16511664
$(OBJDIR)/linenoise.o: $(SRCDIR)/linenoise.c $(SRCDIR)/linenoise.h
16521665
$(XTCC) -c $(SRCDIR)/linenoise.c -o $@
16531666
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460
461 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463
464 # Run the test suite.
465 # Other flags that can be included in TESTFLAGS are:
466 #
467 # -halt Stop testing after the first failed test
468 # -keep Keep the temporary workspace for debugging
469 # -prot Write a detailed log of the tests to the file ./prot
@@ -508,12 +508,12 @@
508
509 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
510 # to 1. If it is set to 1, then there is no need to build or link
511 # the sqlite3.o object. Instead, the system SQLite will be linked
512 # using -lsqlite3.
513 SQLITE3_OBJ.1 =
514 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
 
515 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
516
517 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
518 # set to 1. If it is set to 1, the miniz library included in the
519 # source tree should be used; otherwise, it should not.
@@ -528,10 +528,23 @@
528 LINENOISE_DEF.1 = -DHAVE_LINENOISE
529 LINENOISE_DEF. = $(LINENOISE_DEF.0)
530 LINENOISE_OBJ.0 =
531 LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
532 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
533
534
535 EXTRAOBJ = \
536 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
537 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -1640,13 +1653,13 @@
1640 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1641 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1642
1643 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1644
1645 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c
1646 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
1647
1648 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1649 $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SRCDIR)/shell.c -o $@
1650
1651 $(OBJDIR)/linenoise.o: $(SRCDIR)/linenoise.c $(SRCDIR)/linenoise.h
1652 $(XTCC) -c $(SRCDIR)/linenoise.c -o $@
1653
--- src/main.mk
+++ src/main.mk
@@ -459,11 +459,11 @@
459 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
460
461 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
462 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
463
464 # Run the test suite.
465 # Other flags that can be included in TESTFLAGS are:
466 #
467 # -halt Stop testing after the first failed test
468 # -keep Keep the temporary workspace for debugging
469 # -prot Write a detailed log of the tests to the file ./prot
@@ -508,12 +508,12 @@
508
509 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
510 # to 1. If it is set to 1, then there is no need to build or link
511 # the sqlite3.o object. Instead, the system SQLite will be linked
512 # using -lsqlite3.
 
513 SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
514 SQLITE3_OBJ.1 =
515 SQLITE3_OBJ. = $(SQLITE3_OBJ.0)
516
517 # The FOSSIL_ENABLE_MINIZ variable may be undefined, set to 0, or
518 # set to 1. If it is set to 1, the miniz library included in the
519 # source tree should be used; otherwise, it should not.
@@ -528,10 +528,23 @@
528 LINENOISE_DEF.1 = -DHAVE_LINENOISE
529 LINENOISE_DEF. = $(LINENOISE_DEF.0)
530 LINENOISE_OBJ.0 =
531 LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
532 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
533
534 # The USE_SEE variable may be undefined, 0 or 1. If undefined or
535 # 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
536 # the source tree) is used and extra flags are provided to enable
537 # the SQLite Encryption Extension.
538 SQLITE3_SRC.0 = sqlite3.c
539 SQLITE3_SRC.1 = sqlite3-see.c
540 SQLITE3_SRC. = sqlite3.c
541 SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
542 SEE_FLAGS.0 =
543 SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
544 SEE_FLAGS. =
545 SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
546
547
548 EXTRAOBJ = \
549 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
550 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -1640,13 +1653,13 @@
1653 $(OBJDIR)/zip.o: $(OBJDIR)/zip_.c $(OBJDIR)/zip.h $(SRCDIR)/config.h
1654 $(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
1655
1656 $(OBJDIR)/zip.h: $(OBJDIR)/headers
1657
1658 $(OBJDIR)/sqlite3.o: $(SQLITE3_SRC)
1659 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
1660 -c $(SQLITE3_SRC) -o $@
1661 $(OBJDIR)/shell.o: $(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
1662 $(XTCC) $(SHELL_OPTIONS) $(SHELL_CFLAGS) $(LINENOISE_DEF.$(USE_LINENOISE)) -c $(SRCDIR)/shell.c -o $@
1663
1664 $(OBJDIR)/linenoise.o: $(SRCDIR)/linenoise.c $(SRCDIR)/linenoise.h
1665 $(XTCC) -c $(SRCDIR)/linenoise.c -o $@
1666
+63 -9
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -304,11 +304,11 @@
304304
$(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
305305
306306
$(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
307307
$(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
308308
309
-# Run the test suite.
309
+# Run the test suite.
310310
# Other flags that can be included in TESTFLAGS are:
311311
#
312312
# -halt Stop testing after the first failed test
313313
# -keep Keep the temporary workspace for debugging
314314
# -prot Write a detailed log of the tests to the file ./prot
@@ -358,10 +358,23 @@
358358
LINENOISE_DEF.1 = -DHAVE_LINENOISE
359359
LINENOISE_DEF. = $(LINENOISE_DEF.0)
360360
LINENOISE_OBJ.0 =
361361
LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
362362
LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
363
+
364
+# The USE_SEE variable may be undefined, 0 or 1. If undefined or
365
+# 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
366
+# the source tree) is used and extra flags are provided to enable
367
+# the SQLite Encryption Extension.
368
+SQLITE3_SRC.0 = sqlite3.c
369
+SQLITE3_SRC.1 = sqlite3-see.c
370
+SQLITE3_SRC. = sqlite3.c
371
+SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
372
+SEE_FLAGS.0 =
373
+SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
374
+SEE_FLAGS. =
375
+SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
363376
}]
364377
365378
writeln [string map [list <<<NEXT_LINE>>> \\] {
366379
EXTRAOBJ = <<<NEXT_LINE>>>
367380
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -421,12 +434,13 @@
421434
writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h$extra_h($s)\$(SRCDIR)/config.h"
422435
writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
423436
writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n"
424437
}
425438
426
-writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
427
-writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
439
+writeln "\$(OBJDIR)/sqlite3.o:\t\$(SQLITE3_SRC)"
440
+writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\"
441
+writeln "\t\t-c \$(SQLITE3_SRC) -o \$@"
428442
429443
writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
430444
writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SRCDIR)/shell.c -o \$@\n"
431445
432446
writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR)/linenoise.c \$(SRCDIR)/linenoise.h"
@@ -558,10 +572,14 @@
558572
# FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
559573
560574
#### Use 'system' SQLite
561575
#
562576
# USE_SYSTEM_SQLITE = 1
577
+
578
+#### Use the SQLite Encryption Extension
579
+#
580
+# USE_SEE = 1
563581
564582
#### Use the miniz compression library
565583
#
566584
# FOSSIL_ENABLE_MINIZ = 1
567585
@@ -628,11 +646,11 @@
628646
#### The directories where the OpenSSL include and library files are located.
629647
# The recommended usage here is to use the Sysinternals junction tool
630648
# to create a hard link between an "openssl-1.x" sub-directory of the
631649
# Fossil source code directory and the target OpenSSL source directory.
632650
#
633
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
651
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
634652
OPENSSLINCDIR = $(OPENSSLDIR)/include
635653
OPENSSLLIBDIR = $(OPENSSLDIR)
636654
637655
#### Either the directory where the Tcl library is installed or the Tcl
638656
# source code directory resides (depending on the value of the macro
@@ -783,10 +801,16 @@
783801
# With JSON support
784802
ifdef FOSSIL_ENABLE_JSON
785803
TCC += -DFOSSIL_ENABLE_JSON=1
786804
RCC += -DFOSSIL_ENABLE_JSON=1
787805
endif
806
+
807
+# With SQLite Encryption Extension support
808
+ifdef USE_SEE
809
+TCC += -DUSE_SEE=1
810
+RCC += -DUSE_SEE=1
811
+endif
788812
789813
#### The option -static has no effect on MinGW(-w64), only dynamic
790814
# executables can be built when linking with MSVCRT. OpenSSL
791815
# (optional) and zlib (required) however are always linked in
792816
# statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -998,10 +1022,23 @@
9981022
# set to 1. If it is set to 1, the miniz library included in the
9991023
# source tree should be used; otherwise, it should not.
10001024
MINIZ_OBJ.0 =
10011025
MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
10021026
MINIZ_OBJ. = $(MINIZ_OBJ.0)
1027
+
1028
+# The USE_SEE variable may be undefined, 0 or 1. If undefined or
1029
+# 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
1030
+# the source tree) is used and extra flags are provided to enable
1031
+# the SQLite Encryption Extension.
1032
+SQLITE3_SRC.0 = sqlite3.c
1033
+SQLITE3_SRC.1 = sqlite3-see.c
1034
+SQLITE3_SRC. = sqlite3.c
1035
+SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
1036
+SEE_FLAGS.0 =
1037
+SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
1038
+SEE_FLAGS. =
1039
+SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
10031040
}
10041041
10051042
writeln [string map [list <<<NEXT_LINE>>> \\] {
10061043
EXTRAOBJ = <<<NEXT_LINE>>>
10071044
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -1123,12 +1160,13 @@
11231160
set j " \\\n "
11241161
writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
11251162
set j " \\\n "
11261163
writeln "MINIZ_OPTIONS = [join $MINIZ_WIN32_OPTIONS $j]\n"
11271164
1128
-writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c \$(SRCDIR)/../win/Makefile.mingw"
1129
-writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
1165
+writeln "\$(OBJDIR)/sqlite3.o:\t\$(SQLITE3_SRC) \$(SRCDIR)/../win/Makefile.mingw"
1166
+writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\"
1167
+writeln "\t\t-c \$(SQLITE3_SRC) -o \$@\n"
11301168
11311169
writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
11321170
writeln "\t\$(XTCC) -c \$(SRCDIR)/cson_amalgamation.c -o \$@\n"
11331171
writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_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 : \$(SRCDIR)/json_detail.h\n"
11341172
@@ -1415,13 +1453,18 @@
14151453
14161454
# Enable support for Windows XP with Visual Studio 201x?
14171455
!ifndef FOSSIL_ENABLE_WINXP
14181456
FOSSIL_ENABLE_WINXP = 0
14191457
!endif
1458
+
1459
+# Enable support for the SQLite Encryption Extension?
1460
+!ifndef USE_SEE
1461
+USE_SEE = 0
1462
+!endif
14201463
14211464
!if $(FOSSIL_ENABLE_SSL)!=0
1422
-SSLDIR = $(B)\compat\openssl-1.0.2g
1465
+SSLDIR = $(B)\compat\openssl-1.0.2h
14231466
SSLINCDIR = $(SSLDIR)\inc32
14241467
!if $(FOSSIL_DYNAMIC_BUILD)!=0
14251468
SSLLIBDIR = $(SSLDIR)\out32dll
14261469
!else
14271470
SSLLIBDIR = $(SSLDIR)\out32
@@ -1624,10 +1667,15 @@
16241667
TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
16251668
RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
16261669
TCC = $(TCC) /DUSE_TCL_STUBS=1
16271670
RCC = $(RCC) /DUSE_TCL_STUBS=1
16281671
!endif
1672
+
1673
+!if $(USE_SEE)!=0
1674
+TCC = $(TCC) /DUSE_SEE=1
1675
+RCC = $(RCC) /DUSE_SEE=1
1676
+!endif
16291677
}
16301678
regsub -all {[-]D} [join $SQLITE_WIN32_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
16311679
set j " \\\n "
16321680
writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
16331681
@@ -1760,12 +1808,18 @@
17601808
$(BCC) $**
17611809
17621810
$(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
17631811
$(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
17641812
1765
-$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c $B\win\Makefile.msc
1766
- $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SRCDIR)\sqlite3.c
1813
+!if $(USE_SEE)!=0
1814
+SQLITE3_SRC = $(SRCDIR)\sqlite3-see.c
1815
+!else
1816
+SQLITE3_SRC = $(SRCDIR)\sqlite3.c
1817
+!endif
1818
+
1819
+$(OX)\sqlite3$O : $(SQLITE3_SRC) $B\win\Makefile.msc
1820
+ $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) $(SQLITE3_SRC)
17671821
17681822
$(OX)\th$O : $(SRCDIR)\th.c
17691823
$(TCC) /Fo$@ -c $**
17701824
17711825
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
17721826
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -304,11 +304,11 @@
304 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
305
306 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
307 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
308
309 # Run the test suite.
310 # Other flags that can be included in TESTFLAGS are:
311 #
312 # -halt Stop testing after the first failed test
313 # -keep Keep the temporary workspace for debugging
314 # -prot Write a detailed log of the tests to the file ./prot
@@ -358,10 +358,23 @@
358 LINENOISE_DEF.1 = -DHAVE_LINENOISE
359 LINENOISE_DEF. = $(LINENOISE_DEF.0)
360 LINENOISE_OBJ.0 =
361 LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
362 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
363 }]
364
365 writeln [string map [list <<<NEXT_LINE>>> \\] {
366 EXTRAOBJ = <<<NEXT_LINE>>>
367 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -421,12 +434,13 @@
421 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h$extra_h($s)\$(SRCDIR)/config.h"
422 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
423 writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n"
424 }
425
426 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
427 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
 
428
429 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
430 writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SRCDIR)/shell.c -o \$@\n"
431
432 writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR)/linenoise.c \$(SRCDIR)/linenoise.h"
@@ -558,10 +572,14 @@
558 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
559
560 #### Use 'system' SQLite
561 #
562 # USE_SYSTEM_SQLITE = 1
 
 
 
 
563
564 #### Use the miniz compression library
565 #
566 # FOSSIL_ENABLE_MINIZ = 1
567
@@ -628,11 +646,11 @@
628 #### The directories where the OpenSSL include and library files are located.
629 # The recommended usage here is to use the Sysinternals junction tool
630 # to create a hard link between an "openssl-1.x" sub-directory of the
631 # Fossil source code directory and the target OpenSSL source directory.
632 #
633 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
634 OPENSSLINCDIR = $(OPENSSLDIR)/include
635 OPENSSLLIBDIR = $(OPENSSLDIR)
636
637 #### Either the directory where the Tcl library is installed or the Tcl
638 # source code directory resides (depending on the value of the macro
@@ -783,10 +801,16 @@
783 # With JSON support
784 ifdef FOSSIL_ENABLE_JSON
785 TCC += -DFOSSIL_ENABLE_JSON=1
786 RCC += -DFOSSIL_ENABLE_JSON=1
787 endif
 
 
 
 
 
 
788
789 #### The option -static has no effect on MinGW(-w64), only dynamic
790 # executables can be built when linking with MSVCRT. OpenSSL
791 # (optional) and zlib (required) however are always linked in
792 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -998,10 +1022,23 @@
998 # set to 1. If it is set to 1, the miniz library included in the
999 # source tree should be used; otherwise, it should not.
1000 MINIZ_OBJ.0 =
1001 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
1002 MINIZ_OBJ. = $(MINIZ_OBJ.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
1003 }
1004
1005 writeln [string map [list <<<NEXT_LINE>>> \\] {
1006 EXTRAOBJ = <<<NEXT_LINE>>>
1007 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -1123,12 +1160,13 @@
1123 set j " \\\n "
1124 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
1125 set j " \\\n "
1126 writeln "MINIZ_OPTIONS = [join $MINIZ_WIN32_OPTIONS $j]\n"
1127
1128 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c \$(SRCDIR)/../win/Makefile.mingw"
1129 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) -c \$(SRCDIR)/sqlite3.c -o \$@\n"
 
1130
1131 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
1132 writeln "\t\$(XTCC) -c \$(SRCDIR)/cson_amalgamation.c -o \$@\n"
1133 writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_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 : \$(SRCDIR)/json_detail.h\n"
1134
@@ -1415,13 +1453,18 @@
1415
1416 # Enable support for Windows XP with Visual Studio 201x?
1417 !ifndef FOSSIL_ENABLE_WINXP
1418 FOSSIL_ENABLE_WINXP = 0
1419 !endif
 
 
 
 
 
1420
1421 !if $(FOSSIL_ENABLE_SSL)!=0
1422 SSLDIR = $(B)\compat\openssl-1.0.2g
1423 SSLINCDIR = $(SSLDIR)\inc32
1424 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1425 SSLLIBDIR = $(SSLDIR)\out32dll
1426 !else
1427 SSLLIBDIR = $(SSLDIR)\out32
@@ -1624,10 +1667,15 @@
1624 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1625 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1626 TCC = $(TCC) /DUSE_TCL_STUBS=1
1627 RCC = $(RCC) /DUSE_TCL_STUBS=1
1628 !endif
 
 
 
 
 
1629 }
1630 regsub -all {[-]D} [join $SQLITE_WIN32_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
1631 set j " \\\n "
1632 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
1633
@@ -1760,12 +1808,18 @@
1760 $(BCC) $**
1761
1762 $(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
1763 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
1764
1765 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c $B\win\Makefile.msc
1766 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SRCDIR)\sqlite3.c
 
 
 
 
 
 
1767
1768 $(OX)\th$O : $(SRCDIR)\th.c
1769 $(TCC) /Fo$@ -c $**
1770
1771 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
1772
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -304,11 +304,11 @@
304 $(BCC) -o $(OBJDIR)/mkversion $(SRCDIR)/mkversion.c
305
306 $(OBJDIR)/codecheck1: $(SRCDIR)/codecheck1.c
307 $(BCC) -o $(OBJDIR)/codecheck1 $(SRCDIR)/codecheck1.c
308
309 # Run the test suite.
310 # Other flags that can be included in TESTFLAGS are:
311 #
312 # -halt Stop testing after the first failed test
313 # -keep Keep the temporary workspace for debugging
314 # -prot Write a detailed log of the tests to the file ./prot
@@ -358,10 +358,23 @@
358 LINENOISE_DEF.1 = -DHAVE_LINENOISE
359 LINENOISE_DEF. = $(LINENOISE_DEF.0)
360 LINENOISE_OBJ.0 =
361 LINENOISE_OBJ.1 = $(OBJDIR)/linenoise.o
362 LINENOISE_OBJ. = $(LINENOISE_OBJ.0)
363
364 # The USE_SEE variable may be undefined, 0 or 1. If undefined or
365 # 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
366 # the source tree) is used and extra flags are provided to enable
367 # the SQLite Encryption Extension.
368 SQLITE3_SRC.0 = sqlite3.c
369 SQLITE3_SRC.1 = sqlite3-see.c
370 SQLITE3_SRC. = sqlite3.c
371 SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
372 SEE_FLAGS.0 =
373 SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
374 SEE_FLAGS. =
375 SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
376 }]
377
378 writeln [string map [list <<<NEXT_LINE>>> \\] {
379 EXTRAOBJ = <<<NEXT_LINE>>>
380 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -421,12 +434,13 @@
434 writeln "\$(OBJDIR)/$s.o:\t\$(OBJDIR)/${s}_.c \$(OBJDIR)/$s.h$extra_h($s)\$(SRCDIR)/config.h"
435 writeln "\t\$(XTCC) -o \$(OBJDIR)/$s.o -c \$(OBJDIR)/${s}_.c\n"
436 writeln "\$(OBJDIR)/$s.h:\t\$(OBJDIR)/headers\n"
437 }
438
439 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SQLITE3_SRC)"
440 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\"
441 writeln "\t\t-c \$(SQLITE3_SRC) -o \$@"
442
443 writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
444 writeln "\t\$(XTCC) \$(SHELL_OPTIONS) \$(SHELL_CFLAGS) \$(LINENOISE_DEF.\$(USE_LINENOISE)) -c \$(SRCDIR)/shell.c -o \$@\n"
445
446 writeln "\$(OBJDIR)/linenoise.o:\t\$(SRCDIR)/linenoise.c \$(SRCDIR)/linenoise.h"
@@ -558,10 +572,14 @@
572 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
573
574 #### Use 'system' SQLite
575 #
576 # USE_SYSTEM_SQLITE = 1
577
578 #### Use the SQLite Encryption Extension
579 #
580 # USE_SEE = 1
581
582 #### Use the miniz compression library
583 #
584 # FOSSIL_ENABLE_MINIZ = 1
585
@@ -628,11 +646,11 @@
646 #### The directories where the OpenSSL include and library files are located.
647 # The recommended usage here is to use the Sysinternals junction tool
648 # to create a hard link between an "openssl-1.x" sub-directory of the
649 # Fossil source code directory and the target OpenSSL source directory.
650 #
651 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
652 OPENSSLINCDIR = $(OPENSSLDIR)/include
653 OPENSSLLIBDIR = $(OPENSSLDIR)
654
655 #### Either the directory where the Tcl library is installed or the Tcl
656 # source code directory resides (depending on the value of the macro
@@ -783,10 +801,16 @@
801 # With JSON support
802 ifdef FOSSIL_ENABLE_JSON
803 TCC += -DFOSSIL_ENABLE_JSON=1
804 RCC += -DFOSSIL_ENABLE_JSON=1
805 endif
806
807 # With SQLite Encryption Extension support
808 ifdef USE_SEE
809 TCC += -DUSE_SEE=1
810 RCC += -DUSE_SEE=1
811 endif
812
813 #### The option -static has no effect on MinGW(-w64), only dynamic
814 # executables can be built when linking with MSVCRT. OpenSSL
815 # (optional) and zlib (required) however are always linked in
816 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -998,10 +1022,23 @@
1022 # set to 1. If it is set to 1, the miniz library included in the
1023 # source tree should be used; otherwise, it should not.
1024 MINIZ_OBJ.0 =
1025 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
1026 MINIZ_OBJ. = $(MINIZ_OBJ.0)
1027
1028 # The USE_SEE variable may be undefined, 0 or 1. If undefined or
1029 # 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
1030 # the source tree) is used and extra flags are provided to enable
1031 # the SQLite Encryption Extension.
1032 SQLITE3_SRC.0 = sqlite3.c
1033 SQLITE3_SRC.1 = sqlite3-see.c
1034 SQLITE3_SRC. = sqlite3.c
1035 SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
1036 SEE_FLAGS.0 =
1037 SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
1038 SEE_FLAGS. =
1039 SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
1040 }
1041
1042 writeln [string map [list <<<NEXT_LINE>>> \\] {
1043 EXTRAOBJ = <<<NEXT_LINE>>>
1044 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) <<<NEXT_LINE>>>
@@ -1123,12 +1160,13 @@
1160 set j " \\\n "
1161 writeln "SHELL_OPTIONS = [join $SHELL_WIN32_OPTIONS $j]\n"
1162 set j " \\\n "
1163 writeln "MINIZ_OPTIONS = [join $MINIZ_WIN32_OPTIONS $j]\n"
1164
1165 writeln "\$(OBJDIR)/sqlite3.o:\t\$(SQLITE3_SRC) \$(SRCDIR)/../win/Makefile.mingw"
1166 writeln "\t\$(XTCC) \$(SQLITE_OPTIONS) \$(SQLITE_CFLAGS) \$(SEE_FLAGS) \\"
1167 writeln "\t\t-c \$(SQLITE3_SRC) -o \$@\n"
1168
1169 writeln "\$(OBJDIR)/cson_amalgamation.o:\t\$(SRCDIR)/cson_amalgamation.c"
1170 writeln "\t\$(XTCC) -c \$(SRCDIR)/cson_amalgamation.c -o \$@\n"
1171 writeln "\$(OBJDIR)/json.o \$(OBJDIR)/json_artifact.o \$(OBJDIR)/json_branch.o \$(OBJDIR)/json_config.o \$(OBJDIR)/json_diff.o \$(OBJDIR)/json_dir.o \$(OBJDIR)/jsos_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 : \$(SRCDIR)/json_detail.h\n"
1172
@@ -1415,13 +1453,18 @@
1453
1454 # Enable support for Windows XP with Visual Studio 201x?
1455 !ifndef FOSSIL_ENABLE_WINXP
1456 FOSSIL_ENABLE_WINXP = 0
1457 !endif
1458
1459 # Enable support for the SQLite Encryption Extension?
1460 !ifndef USE_SEE
1461 USE_SEE = 0
1462 !endif
1463
1464 !if $(FOSSIL_ENABLE_SSL)!=0
1465 SSLDIR = $(B)\compat\openssl-1.0.2h
1466 SSLINCDIR = $(SSLDIR)\inc32
1467 !if $(FOSSIL_DYNAMIC_BUILD)!=0
1468 SSLLIBDIR = $(SSLDIR)\out32dll
1469 !else
1470 SSLLIBDIR = $(SSLDIR)\out32
@@ -1624,10 +1667,15 @@
1667 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1668 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
1669 TCC = $(TCC) /DUSE_TCL_STUBS=1
1670 RCC = $(RCC) /DUSE_TCL_STUBS=1
1671 !endif
1672
1673 !if $(USE_SEE)!=0
1674 TCC = $(TCC) /DUSE_SEE=1
1675 RCC = $(RCC) /DUSE_SEE=1
1676 !endif
1677 }
1678 regsub -all {[-]D} [join $SQLITE_WIN32_OPTIONS { }] {/D} MSC_SQLITE_OPTIONS
1679 set j " \\\n "
1680 writeln "SQLITE_OPTIONS = [join $MSC_SQLITE_OPTIONS $j]\n"
1681
@@ -1760,12 +1808,18 @@
1808 $(BCC) $**
1809
1810 $(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
1811 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
1812
1813 !if $(USE_SEE)!=0
1814 SQLITE3_SRC = $(SRCDIR)\sqlite3-see.c
1815 !else
1816 SQLITE3_SRC = $(SRCDIR)\sqlite3.c
1817 !endif
1818
1819 $(OX)\sqlite3$O : $(SQLITE3_SRC) $B\win\Makefile.msc
1820 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) $(SQLITE3_SRC)
1821
1822 $(OX)\th$O : $(SRCDIR)\th.c
1823 $(TCC) /Fo$@ -c $**
1824
1825 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
1826
+11 -6
--- src/manifest.c
+++ src/manifest.c
@@ -2066,15 +2066,17 @@
20662066
const char isAdd = (zSrc && zSrc[0]) ? 1 : 0;
20672067
char *zComment;
20682068
if( isAdd ){
20692069
zComment = mprintf(
20702070
"Add attachment [/artifact/%!S|%h] to"
2071
- " tech note [/technote/%h|%.10h]",
2071
+ " tech note [/technote/%!S|%S]",
20722072
zSrc, zName, zTarget, zTarget);
20732073
}else{
2074
- zComment = mprintf("Delete attachment \"%h\" from tech note [%.10h]",
2075
- zName, zTarget);
2074
+ zComment = mprintf(
2075
+ "Delete attachment \"%h\" from"
2076
+ " tech note [/technote/%!S|%S]",
2077
+ zName, zTarget, zTarget);
20762078
}
20772079
db_multi_exec("UPDATE event SET comment=%Q, type='e'"
20782080
" WHERE objid=%Q",
20792081
zComment, zAttachId);
20802082
fossil_free(zComment);
@@ -2162,15 +2164,18 @@
21622164
p->zAttachName, p->zAttachTarget);
21632165
}
21642166
}else if( 'e' == attachToType ){
21652167
if( isAdd ){
21662168
zComment = mprintf(
2167
- "Add attachment [/artifact/%!S|%h] to tech note [/technote/%h|%.10h]",
2169
+ "Add attachment [/artifact/%!S|%h] to tech note [/technote/%!S|%S]",
21682170
p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
21692171
}else{
2170
- zComment = mprintf("Delete attachment \"%h\" from tech note [%.10h]",
2171
- p->zAttachName, p->zAttachTarget);
2172
+ zComment = mprintf(
2173
+ "Delete attachment \"/artifact/%!S|%h\" from"
2174
+ " tech note [/technote/%!S|%S]",
2175
+ p->zAttachName, p->zAttachName,
2176
+ p->zAttachTarget,p->zAttachTarget);
21722177
}
21732178
}else{
21742179
if( isAdd ){
21752180
zComment = mprintf(
21762181
"Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]",
21772182
--- src/manifest.c
+++ src/manifest.c
@@ -2066,15 +2066,17 @@
2066 const char isAdd = (zSrc && zSrc[0]) ? 1 : 0;
2067 char *zComment;
2068 if( isAdd ){
2069 zComment = mprintf(
2070 "Add attachment [/artifact/%!S|%h] to"
2071 " tech note [/technote/%h|%.10h]",
2072 zSrc, zName, zTarget, zTarget);
2073 }else{
2074 zComment = mprintf("Delete attachment \"%h\" from tech note [%.10h]",
2075 zName, zTarget);
 
 
2076 }
2077 db_multi_exec("UPDATE event SET comment=%Q, type='e'"
2078 " WHERE objid=%Q",
2079 zComment, zAttachId);
2080 fossil_free(zComment);
@@ -2162,15 +2164,18 @@
2162 p->zAttachName, p->zAttachTarget);
2163 }
2164 }else if( 'e' == attachToType ){
2165 if( isAdd ){
2166 zComment = mprintf(
2167 "Add attachment [/artifact/%!S|%h] to tech note [/technote/%h|%.10h]",
2168 p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
2169 }else{
2170 zComment = mprintf("Delete attachment \"%h\" from tech note [%.10h]",
2171 p->zAttachName, p->zAttachTarget);
 
 
 
2172 }
2173 }else{
2174 if( isAdd ){
2175 zComment = mprintf(
2176 "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]",
2177
--- src/manifest.c
+++ src/manifest.c
@@ -2066,15 +2066,17 @@
2066 const char isAdd = (zSrc && zSrc[0]) ? 1 : 0;
2067 char *zComment;
2068 if( isAdd ){
2069 zComment = mprintf(
2070 "Add attachment [/artifact/%!S|%h] to"
2071 " tech note [/technote/%!S|%S]",
2072 zSrc, zName, zTarget, zTarget);
2073 }else{
2074 zComment = mprintf(
2075 "Delete attachment \"%h\" from"
2076 " tech note [/technote/%!S|%S]",
2077 zName, zTarget, zTarget);
2078 }
2079 db_multi_exec("UPDATE event SET comment=%Q, type='e'"
2080 " WHERE objid=%Q",
2081 zComment, zAttachId);
2082 fossil_free(zComment);
@@ -2162,15 +2164,18 @@
2164 p->zAttachName, p->zAttachTarget);
2165 }
2166 }else if( 'e' == attachToType ){
2167 if( isAdd ){
2168 zComment = mprintf(
2169 "Add attachment [/artifact/%!S|%h] to tech note [/technote/%!S|%S]",
2170 p->zAttachSrc, p->zAttachName, p->zAttachTarget, p->zAttachTarget);
2171 }else{
2172 zComment = mprintf(
2173 "Delete attachment \"/artifact/%!S|%h\" from"
2174 " tech note [/technote/%!S|%S]",
2175 p->zAttachName, p->zAttachName,
2176 p->zAttachTarget,p->zAttachTarget);
2177 }
2178 }else{
2179 if( isAdd ){
2180 zComment = mprintf(
2181 "Add attachment [/artifact/%!S|%h] to ticket [%!S|%S]",
2182
+251 -145
--- src/merge.c
+++ src/merge.c
@@ -128,10 +128,46 @@
128128
}
129129
}
130130
db_finalize(&q);
131131
return fForkSeen;
132132
}
133
+
134
+/*
135
+** Add an entry to the FV table for all files renamed between
136
+** version N and the version specified by vid.
137
+*/
138
+static void add_renames(
139
+ const char *zFnCol, /* The FV column for the filename in vid */
140
+ int vid, /* The desired version's RID */
141
+ int nid, /* Version N's RID */
142
+ int revOk, /* Ok to move backwards (child->parent) if true */
143
+ const char *zDebug /* Generate trace output if not NULL */
144
+){
145
+ int nChng; /* Number of file name changes */
146
+ int *aChng; /* An array of file name changes */
147
+ int i; /* Loop counter */
148
+ find_filename_changes(nid, vid, revOk, &nChng, &aChng, zDebug);
149
+ if( nChng==0 ) return;
150
+ for(i=0; i<nChng; i++){
151
+ char *zN, *zV;
152
+ zN = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
153
+ zV = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
154
+ db_multi_exec(
155
+ "INSERT OR IGNORE INTO fv(%s,fnn) VALUES(%Q,%Q)",
156
+ zFnCol /*safe-for-%s*/, zV, zN
157
+ );
158
+ if( db_changes()==0 ){
159
+ db_multi_exec(
160
+ "UPDATE fv SET %s=%Q WHERE fnn=%Q",
161
+ zFnCol /*safe-for-%s*/, zV, zN
162
+ );
163
+ }
164
+ free(zN);
165
+ free(zV);
166
+ }
167
+ free(aChng);
168
+}
133169
134170
/*
135171
** COMMAND: merge
136172
**
137173
** Usage: %fossil merge ?OPTIONS? ?VERSION?
@@ -178,10 +214,11 @@
178214
*/
179215
void merge_cmd(void){
180216
int vid; /* Current version "V" */
181217
int mid; /* Version we are merging from "M" */
182218
int pid; /* The pivot version - most recent common ancestor P */
219
+ int nid = 0; /* The name pivot version "N" */
183220
int verboseFlag; /* True if the -v|--verbose option is present */
184221
int integrateFlag; /* True if the --integrate option is present */
185222
int pickFlag; /* True if the --cherrypick option is present */
186223
int backoutFlag; /* True if the --backout option is present */
187224
int dryRunFlag; /* True if the --dry-run or -n option is present */
@@ -188,23 +225,22 @@
188225
int forceFlag; /* True if the --force or -f option is present */
189226
int forceMissingFlag; /* True if the --force-missing option is present */
190227
const char *zBinGlob; /* The value of --binary */
191228
const char *zPivot; /* The value of --baseline */
192229
int debugFlag; /* True if --debug is present */
193
- int nChng; /* Number of file name changes */
194
- int *aChng; /* An array of file name changes */
195
- int i; /* Loop counter */
196230
int nConflict = 0; /* Number of conflicts seen */
197231
int nOverwrite = 0; /* Number of unmanaged files overwritten */
232
+ char vAncestor = 'p'; /* If P is an ancestor of V then 'p', else 'n' */
198233
Stmt q;
199234
200235
201236
/* Notation:
202237
**
203238
** V The current checkout
204239
** M The version being merged in
205240
** P The "pivot" - the most recent common ancestor of V and M.
241
+ ** N The "name pivot" - for detecting renames
206242
*/
207243
208244
undo_capture_command_line();
209245
verboseFlag = find_option("verbose","v",0)!=0;
210246
forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -291,37 +327,49 @@
291327
fossil_fatal("not a version: %s", zPivot);
292328
}
293329
if( pickFlag ){
294330
fossil_fatal("incompatible options: --cherrypick & --baseline");
295331
}
296
- }else if( pickFlag || backoutFlag ){
332
+ }
333
+ if( pickFlag || backoutFlag ){
297334
if( integrateFlag ){
298335
fossil_fatal("incompatible options: --integrate & --cherrypick or --backout");
299336
}
300337
pid = db_int(0, "SELECT pid FROM plink WHERE cid=%d AND isprim", mid);
301338
if( pid<=0 ){
302339
fossil_fatal("cannot find an ancestor for %s", g.argv[2]);
303340
}
304341
}else{
342
+ if( !zPivot ){
343
+ pivot_set_primary(mid);
344
+ pivot_set_secondary(vid);
345
+ db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0");
346
+ while( db_step(&q)==SQLITE_ROW ){
347
+ pivot_set_secondary(db_column_int(&q,0));
348
+ }
349
+ db_finalize(&q);
350
+ pid = pivot_find(0);
351
+ if( pid<=0 ){
352
+ fossil_fatal("cannot find a common ancestor between the current "
353
+ "checkout and %s", g.argv[2]);
354
+ }
355
+ }
305356
pivot_set_primary(mid);
306357
pivot_set_secondary(vid);
307
- db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0");
308
- while( db_step(&q)==SQLITE_ROW ){
309
- pivot_set_secondary(db_column_int(&q,0));
310
- }
311
- db_finalize(&q);
312
- pid = pivot_find();
313
- if( pid<=0 ){
314
- fossil_fatal("cannot find a common ancestor between the current "
315
- "checkout and %s", g.argv[2]);
358
+ nid = pivot_find(1);
359
+ if( nid!=pid ){
360
+ pivot_set_primary(nid);
361
+ pivot_set_secondary(pid);
362
+ nid = pivot_find(1);
316363
}
317364
}
318365
if( backoutFlag ){
319366
int t = pid;
320367
pid = mid;
321368
mid = t;
322369
}
370
+ if( nid==0 ) nid = pid;
323371
if( !is_a_version(pid) ){
324372
fossil_fatal("not a version: record #%d", pid);
325373
}
326374
if( !forceFlag && mid==pid ){
327375
fossil_print("Merge skipped because it is a no-op. "
@@ -343,12 +391,25 @@
343391
fossil_fatal("missing content, unable to merge");
344392
}
345393
if( load_vfile_from_rid(pid) && !forceMissingFlag ){
346394
fossil_fatal("missing content, unable to merge");
347395
}
396
+ if( zPivot ){
397
+ vAncestor = db_exists(
398
+ "WITH RECURSIVE ancestor(id) AS ("
399
+ " VALUES(%d)"
400
+ " UNION ALL"
401
+ " SELECT pid FROM plink, ancestor"
402
+ " WHERE cid=ancestor.id AND pid!=%d AND cid!=%d)"
403
+ "SELECT 1 FROM ancestor WHERE id=%d LIMIT 1",
404
+ vid, nid, pid, pid
405
+ ) ? 'p' : 'n';
406
+ }
348407
if( debugFlag ){
349408
char *z;
409
+ z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nid);
410
+ fossil_print("N=%d %z\n", nid, z);
350411
z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pid);
351412
fossil_print("P=%d %z\n", pid, z);
352413
z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
353414
fossil_print("M=%d %z\n", mid, z);
354415
z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -361,115 +422,102 @@
361422
** in the current checkout, the pivot, and the version being merged.
362423
*/
363424
db_multi_exec(
364425
"DROP TABLE IF EXISTS fv;"
365426
"CREATE TEMP TABLE fv("
366
- " fn TEXT PRIMARY KEY %s," /* The filename */
367
- " idv INTEGER," /* VFILE entry for current version */
368
- " idp INTEGER," /* VFILE entry for the pivot */
369
- " idm INTEGER," /* VFILE entry for version merging in */
427
+ " fn TEXT UNIQUE %s," /* The filename */
428
+ " idv INTEGER DEFAULT 0," /* VFILE entry for current version */
429
+ " idp INTEGER DEFAULT 0," /* VFILE entry for the pivot */
430
+ " idm INTEGER DEFAULT 0," /* VFILE entry for version merging in */
370431
" chnged BOOLEAN," /* True if current version has been edited */
371
- " ridv INTEGER," /* Record ID for current version */
372
- " ridp INTEGER," /* Record ID for pivot */
373
- " ridm INTEGER," /* Record ID for merge */
432
+ " ridv INTEGER DEFAULT 0," /* Record ID for current version */
433
+ " ridp INTEGER DEFAULT 0," /* Record ID for pivot */
434
+ " ridm INTEGER DEFAULT 0," /* Record ID for merge */
374435
" isexe BOOLEAN," /* Execute permission enabled */
375
- " fnp TEXT %s," /* The filename in the pivot */
376
- " fnm TEXT %s," /* the filename in the merged version */
436
+ " fnp TEXT UNIQUE %s," /* The filename in the pivot */
437
+ " fnm TEXT UNIQUE %s," /* The filename in the merged version */
438
+ " fnn TEXT UNIQUE %s," /* The filename in the name pivot */
377439
" islinkv BOOLEAN," /* True if current version is a symlink */
378440
" islinkm BOOLEAN" /* True if merged version in is a symlink */
379441
");",
380
- filename_collation(), filename_collation(), filename_collation()
381
- );
382
-
383
- /* Add files found in V
384
- */
385
- db_multi_exec(
386
- "INSERT OR IGNORE"
387
- " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
388
- " SELECT pathname, pathname, pathname, id, 0, 0, rid, 0, 0, isexe, chnged "
389
- " FROM vfile WHERE vid=%d",
390
- vid
391
- );
392
-
393
- /*
394
- ** Compute name changes from P->V
395
- */
396
- find_filename_changes(pid, vid, 0, &nChng, &aChng, debugFlag ? "P->V" : 0);
397
- if( nChng ){
398
- for(i=0; i<nChng; i++){
399
- char *z;
400
- z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
401
- db_multi_exec(
402
- "UPDATE fv SET fnp=%Q, fnm=%Q"
403
- " WHERE fn=(SELECT name FROM filename WHERE fnid=%d)",
404
- z, z, aChng[i*2+1]
405
- );
406
- free(z);
407
- }
408
- fossil_free(aChng);
409
- db_multi_exec("UPDATE fv SET fnm=fnp WHERE fnp!=fn");
410
- }
411
-
412
- /* Add files found in P but not in V
413
- */
414
- db_multi_exec(
415
- "INSERT OR IGNORE"
416
- " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
417
- " SELECT pathname, pathname, pathname, 0, 0, 0, 0, 0, 0, isexe, 0 "
418
- " FROM vfile"
419
- " WHERE vid=%d AND pathname %s NOT IN (SELECT fnp FROM fv)",
420
- pid, filename_collation()
421
- );
422
-
423
- /*
424
- ** Compute name changes from P->M
425
- */
426
- find_filename_changes(pid, mid, 0, &nChng, &aChng, debugFlag ? "P->M" : 0);
427
- if( nChng ){
428
- if( nChng>4 ) db_multi_exec("CREATE INDEX fv_fnp ON fv(fnp)");
429
- for(i=0; i<nChng; i++){
430
- db_multi_exec(
431
- "UPDATE fv SET fnm=(SELECT name FROM filename WHERE fnid=%d)"
432
- " WHERE fnp=(SELECT name FROM filename WHERE fnid=%d)",
433
- aChng[i*2+1], aChng[i*2]
434
- );
435
- }
436
- fossil_free(aChng);
437
- }
438
-
439
- /* Add files found in M but not in P or V.
440
- */
441
- db_multi_exec(
442
- "INSERT OR IGNORE"
443
- " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
444
- " SELECT pathname, pathname, pathname, 0, 0, 0, 0, 0, 0, isexe, 0 "
445
- " FROM vfile"
446
- " WHERE vid=%d"
447
- " AND pathname %s NOT IN (SELECT fnp FROM fv UNION SELECT fnm FROM fv)",
448
- mid, filename_collation()
449
- );
450
-
451
- /*
452
- ** Compute the file version ids for P and M.
453
- */
442
+ filename_collation(), filename_collation(), filename_collation(),
443
+ filename_collation()
444
+ );
445
+
446
+ /*
447
+ ** Compute name changes from N to V, P, and M
448
+ */
449
+ add_renames("fn", vid, nid, 0, debugFlag ? "N->V" : 0);
450
+ add_renames("fnp", pid, nid, 0, debugFlag ? "N->P" : 0);
451
+ add_renames("fnm", mid, nid, backoutFlag, debugFlag ? "N->M" : 0);
452
+
453
+ /*
454
+ ** Add files found in V
455
+ */
456
+ db_multi_exec(
457
+ "UPDATE OR IGNORE fv SET fn=coalesce(fn%c,fnn) WHERE fn IS NULL;"
458
+ "REPLACE INTO fv(fn,fnp,fnm,fnn,idv,ridv,islinkv,isexe,chnged)"
459
+ " SELECT pathname, fnp, fnm, fnn, id, rid, islink, vf.isexe, vf.chnged"
460
+ " FROM vfile vf"
461
+ " LEFT JOIN fv ON fn=coalesce(origname,pathname)"
462
+ " AND rid>0 AND vf.chnged NOT IN (3,5)"
463
+ " WHERE vid=%d;",
464
+ vAncestor, vid
465
+ );
466
+
467
+ /*
468
+ ** Add files found in P
469
+ */
470
+ db_multi_exec(
471
+ "UPDATE OR IGNORE fv SET fnp=coalesce(fnn,"
472
+ " (SELECT coalesce(origname,pathname) FROM vfile WHERE id=idv))"
473
+ " WHERE fnp IS NULL;"
474
+ "INSERT OR IGNORE INTO fv(fnp)"
475
+ " SELECT coalesce(origname,pathname) FROM vfile WHERE vid=%d;",
476
+ pid
477
+ );
478
+
479
+ /*
480
+ ** Add files found in M
481
+ */
482
+ db_multi_exec(
483
+ "UPDATE OR IGNORE fv SET fnm=fnp WHERE fnm IS NULL;"
484
+ "INSERT OR IGNORE INTO fv(fnm)"
485
+ " SELECT pathname FROM vfile WHERE vid=%d;",
486
+ mid
487
+ );
488
+
489
+ /*
490
+ ** Compute the file version ids for P and M
491
+ */
492
+ if( pid==vid ){
493
+ db_multi_exec(
494
+ "UPDATE fv SET idp=idv, ridp=ridv WHERE ridv>0 AND chnged NOT IN (3,5)"
495
+ );
496
+ }else{
497
+ db_multi_exec(
498
+ "UPDATE fv SET"
499
+ " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnp=pathname),0),"
500
+ " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnp=pathname),0)",
501
+ pid, pid
502
+ );
503
+ }
454504
db_multi_exec(
455505
"UPDATE fv SET"
456
- " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnp=pathname),0),"
457
- " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnp=pathname),0),"
458506
" idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnm=pathname),0),"
459507
" ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnm=pathname),0),"
460
- " islinkv=coalesce((SELECT islink FROM vfile"
508
+ " islinkm=coalesce((SELECT islink FROM vfile"
461509
" WHERE vid=%d AND fnm=pathname),0),"
462
- " islinkm=coalesce((SELECT islink FROM vfile"
463
- " WHERE vid=%d AND fnm=pathname),0)",
464
- pid, pid, mid, mid, vid, mid
510
+ " isexe=coalesce((SELECT isexe FROM vfile WHERE vid=%d AND fnm=pathname),"
511
+ " isexe)",
512
+ mid, mid, mid, mid
465513
);
466514
467515
if( debugFlag ){
468516
db_prepare(&q,
469517
"SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
470
- " isexe, islinkv, islinkm FROM fv"
518
+ " isexe, islinkv, islinkm, fnn FROM fv"
471519
);
472520
while( db_step(&q)==SQLITE_ROW ){
473521
fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
474522
" islinkv=%d islinkm=%d\n",
475523
db_column_int(&q, 0),
@@ -481,14 +529,36 @@
481529
db_column_int(&q, 9),
482530
db_column_int(&q, 10));
483531
fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
484532
fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
485533
fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
534
+ fossil_print(" fnn = [%s]\n", db_column_text(&q, 11));
486535
}
487536
db_finalize(&q);
488537
}
489538
539
+ /*
540
+ ** Update the execute bit on files where it's changed from P->M but not P->V
541
+ */
542
+ db_prepare(&q,
543
+ "SELECT idv, fn, fv.isexe FROM fv, vfile p, vfile v"
544
+ " WHERE p.id=idp AND v.id=idv AND fv.isexe!=p.isexe AND v.isexe=p.isexe"
545
+ );
546
+ while( db_step(&q)==SQLITE_ROW ){
547
+ int idv = db_column_int(&q, 0);
548
+ const char *zName = db_column_text(&q, 1);
549
+ int isExe = db_column_int(&q, 2);
550
+ fossil_print("%s %s\n", isExe ? "EXECUTABLE" : "UNEXEC", zName);
551
+ if( !dryRunFlag ){
552
+ char *zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
553
+ file_wd_setexe(zFullPath, isExe);
554
+ free(zFullPath);
555
+ db_multi_exec("UPDATE vfile SET isexe=%d WHERE id=%d", isExe, idv);
556
+ }
557
+ }
558
+ db_finalize(&q);
559
+
490560
/*
491561
** Find files in M and V but not in P and report conflicts.
492562
** The file in M will be ignored. It will be treated as if it
493563
** does not exist.
494564
*/
@@ -496,50 +566,14 @@
496566
"SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0"
497567
);
498568
while( db_step(&q)==SQLITE_ROW ){
499569
int idm = db_column_int(&q, 0);
500570
char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idm);
501
- fossil_warning("WARNING - no common ancestor: %s", zName);
571
+ fossil_warning("WARNING: no common ancestor for %s", zName);
502572
free(zName);
503573
db_multi_exec("UPDATE fv SET idm=0 WHERE idm=%d", idm);
504574
}
505
- db_finalize(&q);
506
-
507
- /*
508
- ** Add to V files that are not in V or P but are in M
509
- */
510
- db_prepare(&q,
511
- "SELECT idm, rowid, fnm FROM fv AS x"
512
- " WHERE idp=0 AND idv=0 AND idm>0"
513
- );
514
- while( db_step(&q)==SQLITE_ROW ){
515
- int idm = db_column_int(&q, 0);
516
- int rowid = db_column_int(&q, 1);
517
- int idv;
518
- const char *zName;
519
- char *zFullName;
520
- db_multi_exec(
521
- "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
522
- " SELECT %d,%d,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
523
- vid, integrateFlag?5:3, idm
524
- );
525
- idv = db_last_insert_rowid();
526
- db_multi_exec("UPDATE fv SET idv=%d WHERE rowid=%d", idv, rowid);
527
- zName = db_column_text(&q, 2);
528
- zFullName = mprintf("%s%s", g.zLocalRoot, zName);
529
- if( file_wd_isfile_or_link(zFullName) ){
530
- fossil_print("ADDED %s (overwrites an unmanaged file)\n", zName);
531
- nOverwrite++;
532
- }else{
533
- fossil_print("ADDED %s\n", zName);
534
- }
535
- fossil_free(zFullName);
536
- if( !dryRunFlag ){
537
- undo_save(zName);
538
- vfile_to_disk(0, idm, 0, 0);
539
- }
540
- }
541575
db_finalize(&q);
542576
543577
/*
544578
** Find files that have changed from P->M but not P->V.
545579
** Copy the M content over into V.
@@ -646,11 +680,11 @@
646680
const char *zName = db_column_text(&q, 1);
647681
int chnged = db_column_int(&q, 2);
648682
/* Delete the file idv */
649683
fossil_print("DELETE %s\n", zName);
650684
if( chnged ){
651
- fossil_warning("WARNING: local edits lost for %s\n", zName);
685
+ fossil_warning("WARNING: local edits lost for %s", zName);
652686
nConflict++;
653687
}
654688
if( !dryRunFlag ) undo_save(zName);
655689
db_multi_exec(
656690
"UPDATE vfile SET deleted=1 WHERE id=%d", idv
@@ -661,45 +695,117 @@
661695
free(zFullPath);
662696
}
663697
}
664698
db_finalize(&q);
665699
700
+ /* For certain sets of renames (e.g. A -> B and B -> A), a file that is
701
+ ** being renamed must first be moved to a temporary location to avoid
702
+ ** being overwritten by another rename operation. A row is added to the
703
+ ** TMPRN table for each of these temporary renames.
704
+ */
705
+ db_multi_exec(
706
+ "DROP TABLE IF EXISTS tmprn;"
707
+ "CREATE TEMP TABLE tmprn(fn UNIQUE, tmpfn);"
708
+ );
709
+
666710
/*
667711
** Rename files that have taken a rename on P->M but which keep the same
668712
** name on P->V. If a file is renamed on P->V only or on both P->V and
669713
** P->M then we retain the V name of the file.
670714
*/
671715
db_prepare(&q,
672
- "SELECT idv, fnp, fnm FROM fv"
716
+ "SELECT idv, fnp, fnm, isexe FROM fv"
673717
" WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp"
674718
);
675719
while( db_step(&q)==SQLITE_ROW ){
676720
int idv = db_column_int(&q, 0);
677721
const char *zOldName = db_column_text(&q, 1);
678722
const char *zNewName = db_column_text(&q, 2);
723
+ int isExe = db_column_int(&q, 3);
679724
fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
680725
if( !dryRunFlag ) undo_save(zOldName);
681726
if( !dryRunFlag ) undo_save(zNewName);
682727
db_multi_exec(
728
+ "UPDATE vfile SET pathname=NULL, origname=pathname"
729
+ " WHERE vid=%d AND pathname=%Q;"
683730
"UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
684
- " WHERE id=%d AND vid=%d", zNewName, idv, vid
731
+ " WHERE id=%d;",
732
+ vid, zNewName, zNewName, idv
685733
);
686734
if( !dryRunFlag ){
687
- char *zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
688
- char *zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
735
+ char *zFullOldPath, *zFullNewPath;
736
+ zFullOldPath = db_text(0,"SELECT tmpfn FROM tmprn WHERE fn=%Q", zOldName);
737
+ if( !zFullOldPath ){
738
+ zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
739
+ }
740
+ zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
741
+ if( file_wd_size(zFullNewPath)>=0 ){
742
+ char zTmpPath[300];
743
+ file_tempname(sizeof(zTmpPath), zTmpPath);
744
+ db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
745
+ zNewName, zTmpPath);
746
+ if( file_wd_islink(zFullNewPath) ){
747
+ symlink_copy(zFullNewPath, zTmpPath);
748
+ }else{
749
+ file_copy(zFullNewPath, zTmpPath);
750
+ }
751
+ }
689752
if( file_wd_islink(zFullOldPath) ){
690753
symlink_copy(zFullOldPath, zFullNewPath);
691754
}else{
692755
file_copy(zFullOldPath, zFullNewPath);
693756
}
757
+ file_wd_setexe(zFullNewPath, isExe);
694758
file_delete(zFullOldPath);
695759
free(zFullNewPath);
696760
free(zFullOldPath);
697761
}
698762
}
699763
db_finalize(&q);
700764
765
+ /* A file that has been deleted and replaced by a renamed file will have a
766
+ ** NULL pathname. Change it to something that makes the output of "status"
767
+ ** and similar commands make sense for such files and that will (most likely)
768
+ ** not be an actual existing pathname.
769
+ */
770
+ db_multi_exec(
771
+ "UPDATE vfile SET pathname=origname || ' (overwritten by rename)'"
772
+ " WHERE pathname IS NULL"
773
+ );
774
+
775
+ /*
776
+ ** Add to V files that are not in V or P but are in M
777
+ */
778
+ db_prepare(&q,
779
+ "SELECT idm, fnm FROM fv"
780
+ " WHERE idp=0 AND idv=0 AND idm>0"
781
+ );
782
+ while( db_step(&q)==SQLITE_ROW ){
783
+ int idm = db_column_int(&q, 0);
784
+ const char *zName;
785
+ char *zFullName;
786
+ db_multi_exec(
787
+ "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
788
+ " SELECT %d,%d,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
789
+ vid, integrateFlag?5:3, idm
790
+ );
791
+ zName = db_column_text(&q, 1);
792
+ zFullName = mprintf("%s%s", g.zLocalRoot, zName);
793
+ if( file_wd_isfile_or_link(zFullName)
794
+ && !db_exists("SELECT 1 FROM fv WHERE fn=%Q", zName) ){
795
+ fossil_print("ADDED %s (overwrites an unmanaged file)\n", zName);
796
+ nOverwrite++;
797
+ }else{
798
+ fossil_print("ADDED %s\n", zName);
799
+ }
800
+ fossil_free(zFullName);
801
+ if( !dryRunFlag ){
802
+ undo_save(zName);
803
+ vfile_to_disk(0, idm, 0, 0);
804
+ }
805
+ }
806
+ db_finalize(&q);
701807
702808
/* Report on conflicts
703809
*/
704810
if( nConflict ){
705811
fossil_warning("WARNING: %d merge conflicts", nConflict);
706812
--- src/merge.c
+++ src/merge.c
@@ -128,10 +128,46 @@
128 }
129 }
130 db_finalize(&q);
131 return fForkSeen;
132 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134 /*
135 ** COMMAND: merge
136 **
137 ** Usage: %fossil merge ?OPTIONS? ?VERSION?
@@ -178,10 +214,11 @@
178 */
179 void merge_cmd(void){
180 int vid; /* Current version "V" */
181 int mid; /* Version we are merging from "M" */
182 int pid; /* The pivot version - most recent common ancestor P */
 
183 int verboseFlag; /* True if the -v|--verbose option is present */
184 int integrateFlag; /* True if the --integrate option is present */
185 int pickFlag; /* True if the --cherrypick option is present */
186 int backoutFlag; /* True if the --backout option is present */
187 int dryRunFlag; /* True if the --dry-run or -n option is present */
@@ -188,23 +225,22 @@
188 int forceFlag; /* True if the --force or -f option is present */
189 int forceMissingFlag; /* True if the --force-missing option is present */
190 const char *zBinGlob; /* The value of --binary */
191 const char *zPivot; /* The value of --baseline */
192 int debugFlag; /* True if --debug is present */
193 int nChng; /* Number of file name changes */
194 int *aChng; /* An array of file name changes */
195 int i; /* Loop counter */
196 int nConflict = 0; /* Number of conflicts seen */
197 int nOverwrite = 0; /* Number of unmanaged files overwritten */
 
198 Stmt q;
199
200
201 /* Notation:
202 **
203 ** V The current checkout
204 ** M The version being merged in
205 ** P The "pivot" - the most recent common ancestor of V and M.
 
206 */
207
208 undo_capture_command_line();
209 verboseFlag = find_option("verbose","v",0)!=0;
210 forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -291,37 +327,49 @@
291 fossil_fatal("not a version: %s", zPivot);
292 }
293 if( pickFlag ){
294 fossil_fatal("incompatible options: --cherrypick & --baseline");
295 }
296 }else if( pickFlag || backoutFlag ){
 
297 if( integrateFlag ){
298 fossil_fatal("incompatible options: --integrate & --cherrypick or --backout");
299 }
300 pid = db_int(0, "SELECT pid FROM plink WHERE cid=%d AND isprim", mid);
301 if( pid<=0 ){
302 fossil_fatal("cannot find an ancestor for %s", g.argv[2]);
303 }
304 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305 pivot_set_primary(mid);
306 pivot_set_secondary(vid);
307 db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0");
308 while( db_step(&q)==SQLITE_ROW ){
309 pivot_set_secondary(db_column_int(&q,0));
310 }
311 db_finalize(&q);
312 pid = pivot_find();
313 if( pid<=0 ){
314 fossil_fatal("cannot find a common ancestor between the current "
315 "checkout and %s", g.argv[2]);
316 }
317 }
318 if( backoutFlag ){
319 int t = pid;
320 pid = mid;
321 mid = t;
322 }
 
323 if( !is_a_version(pid) ){
324 fossil_fatal("not a version: record #%d", pid);
325 }
326 if( !forceFlag && mid==pid ){
327 fossil_print("Merge skipped because it is a no-op. "
@@ -343,12 +391,25 @@
343 fossil_fatal("missing content, unable to merge");
344 }
345 if( load_vfile_from_rid(pid) && !forceMissingFlag ){
346 fossil_fatal("missing content, unable to merge");
347 }
 
 
 
 
 
 
 
 
 
 
 
348 if( debugFlag ){
349 char *z;
 
 
350 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pid);
351 fossil_print("P=%d %z\n", pid, z);
352 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
353 fossil_print("M=%d %z\n", mid, z);
354 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -361,115 +422,102 @@
361 ** in the current checkout, the pivot, and the version being merged.
362 */
363 db_multi_exec(
364 "DROP TABLE IF EXISTS fv;"
365 "CREATE TEMP TABLE fv("
366 " fn TEXT PRIMARY KEY %s," /* The filename */
367 " idv INTEGER," /* VFILE entry for current version */
368 " idp INTEGER," /* VFILE entry for the pivot */
369 " idm INTEGER," /* VFILE entry for version merging in */
370 " chnged BOOLEAN," /* True if current version has been edited */
371 " ridv INTEGER," /* Record ID for current version */
372 " ridp INTEGER," /* Record ID for pivot */
373 " ridm INTEGER," /* Record ID for merge */
374 " isexe BOOLEAN," /* Execute permission enabled */
375 " fnp TEXT %s," /* The filename in the pivot */
376 " fnm TEXT %s," /* the filename in the merged version */
 
377 " islinkv BOOLEAN," /* True if current version is a symlink */
378 " islinkm BOOLEAN" /* True if merged version in is a symlink */
379 ");",
380 filename_collation(), filename_collation(), filename_collation()
381 );
382
383 /* Add files found in V
384 */
385 db_multi_exec(
386 "INSERT OR IGNORE"
387 " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
388 " SELECT pathname, pathname, pathname, id, 0, 0, rid, 0, 0, isexe, chnged "
389 " FROM vfile WHERE vid=%d",
390 vid
391 );
392
393 /*
394 ** Compute name changes from P->V
395 */
396 find_filename_changes(pid, vid, 0, &nChng, &aChng, debugFlag ? "P->V" : 0);
397 if( nChng ){
398 for(i=0; i<nChng; i++){
399 char *z;
400 z = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
401 db_multi_exec(
402 "UPDATE fv SET fnp=%Q, fnm=%Q"
403 " WHERE fn=(SELECT name FROM filename WHERE fnid=%d)",
404 z, z, aChng[i*2+1]
405 );
406 free(z);
407 }
408 fossil_free(aChng);
409 db_multi_exec("UPDATE fv SET fnm=fnp WHERE fnp!=fn");
410 }
411
412 /* Add files found in P but not in V
413 */
414 db_multi_exec(
415 "INSERT OR IGNORE"
416 " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
417 " SELECT pathname, pathname, pathname, 0, 0, 0, 0, 0, 0, isexe, 0 "
418 " FROM vfile"
419 " WHERE vid=%d AND pathname %s NOT IN (SELECT fnp FROM fv)",
420 pid, filename_collation()
421 );
422
423 /*
424 ** Compute name changes from P->M
425 */
426 find_filename_changes(pid, mid, 0, &nChng, &aChng, debugFlag ? "P->M" : 0);
427 if( nChng ){
428 if( nChng>4 ) db_multi_exec("CREATE INDEX fv_fnp ON fv(fnp)");
429 for(i=0; i<nChng; i++){
430 db_multi_exec(
431 "UPDATE fv SET fnm=(SELECT name FROM filename WHERE fnid=%d)"
432 " WHERE fnp=(SELECT name FROM filename WHERE fnid=%d)",
433 aChng[i*2+1], aChng[i*2]
434 );
435 }
436 fossil_free(aChng);
437 }
438
439 /* Add files found in M but not in P or V.
440 */
441 db_multi_exec(
442 "INSERT OR IGNORE"
443 " INTO fv(fn,fnp,fnm,idv,idp,idm,ridv,ridp,ridm,isexe,chnged)"
444 " SELECT pathname, pathname, pathname, 0, 0, 0, 0, 0, 0, isexe, 0 "
445 " FROM vfile"
446 " WHERE vid=%d"
447 " AND pathname %s NOT IN (SELECT fnp FROM fv UNION SELECT fnm FROM fv)",
448 mid, filename_collation()
449 );
450
451 /*
452 ** Compute the file version ids for P and M.
453 */
454 db_multi_exec(
455 "UPDATE fv SET"
456 " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnp=pathname),0),"
457 " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnp=pathname),0),"
458 " idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnm=pathname),0),"
459 " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnm=pathname),0),"
460 " islinkv=coalesce((SELECT islink FROM vfile"
461 " WHERE vid=%d AND fnm=pathname),0),"
462 " islinkm=coalesce((SELECT islink FROM vfile"
463 " WHERE vid=%d AND fnm=pathname),0)",
464 pid, pid, mid, mid, vid, mid
465 );
466
467 if( debugFlag ){
468 db_prepare(&q,
469 "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
470 " isexe, islinkv, islinkm FROM fv"
471 );
472 while( db_step(&q)==SQLITE_ROW ){
473 fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
474 " islinkv=%d islinkm=%d\n",
475 db_column_int(&q, 0),
@@ -481,14 +529,36 @@
481 db_column_int(&q, 9),
482 db_column_int(&q, 10));
483 fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
484 fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
485 fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
 
486 }
487 db_finalize(&q);
488 }
489
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490 /*
491 ** Find files in M and V but not in P and report conflicts.
492 ** The file in M will be ignored. It will be treated as if it
493 ** does not exist.
494 */
@@ -496,50 +566,14 @@
496 "SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0"
497 );
498 while( db_step(&q)==SQLITE_ROW ){
499 int idm = db_column_int(&q, 0);
500 char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idm);
501 fossil_warning("WARNING - no common ancestor: %s", zName);
502 free(zName);
503 db_multi_exec("UPDATE fv SET idm=0 WHERE idm=%d", idm);
504 }
505 db_finalize(&q);
506
507 /*
508 ** Add to V files that are not in V or P but are in M
509 */
510 db_prepare(&q,
511 "SELECT idm, rowid, fnm FROM fv AS x"
512 " WHERE idp=0 AND idv=0 AND idm>0"
513 );
514 while( db_step(&q)==SQLITE_ROW ){
515 int idm = db_column_int(&q, 0);
516 int rowid = db_column_int(&q, 1);
517 int idv;
518 const char *zName;
519 char *zFullName;
520 db_multi_exec(
521 "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
522 " SELECT %d,%d,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
523 vid, integrateFlag?5:3, idm
524 );
525 idv = db_last_insert_rowid();
526 db_multi_exec("UPDATE fv SET idv=%d WHERE rowid=%d", idv, rowid);
527 zName = db_column_text(&q, 2);
528 zFullName = mprintf("%s%s", g.zLocalRoot, zName);
529 if( file_wd_isfile_or_link(zFullName) ){
530 fossil_print("ADDED %s (overwrites an unmanaged file)\n", zName);
531 nOverwrite++;
532 }else{
533 fossil_print("ADDED %s\n", zName);
534 }
535 fossil_free(zFullName);
536 if( !dryRunFlag ){
537 undo_save(zName);
538 vfile_to_disk(0, idm, 0, 0);
539 }
540 }
541 db_finalize(&q);
542
543 /*
544 ** Find files that have changed from P->M but not P->V.
545 ** Copy the M content over into V.
@@ -646,11 +680,11 @@
646 const char *zName = db_column_text(&q, 1);
647 int chnged = db_column_int(&q, 2);
648 /* Delete the file idv */
649 fossil_print("DELETE %s\n", zName);
650 if( chnged ){
651 fossil_warning("WARNING: local edits lost for %s\n", zName);
652 nConflict++;
653 }
654 if( !dryRunFlag ) undo_save(zName);
655 db_multi_exec(
656 "UPDATE vfile SET deleted=1 WHERE id=%d", idv
@@ -661,45 +695,117 @@
661 free(zFullPath);
662 }
663 }
664 db_finalize(&q);
665
 
 
 
 
 
 
 
 
 
 
666 /*
667 ** Rename files that have taken a rename on P->M but which keep the same
668 ** name on P->V. If a file is renamed on P->V only or on both P->V and
669 ** P->M then we retain the V name of the file.
670 */
671 db_prepare(&q,
672 "SELECT idv, fnp, fnm FROM fv"
673 " WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp"
674 );
675 while( db_step(&q)==SQLITE_ROW ){
676 int idv = db_column_int(&q, 0);
677 const char *zOldName = db_column_text(&q, 1);
678 const char *zNewName = db_column_text(&q, 2);
 
679 fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
680 if( !dryRunFlag ) undo_save(zOldName);
681 if( !dryRunFlag ) undo_save(zNewName);
682 db_multi_exec(
 
 
683 "UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
684 " WHERE id=%d AND vid=%d", zNewName, idv, vid
 
685 );
686 if( !dryRunFlag ){
687 char *zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
688 char *zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689 if( file_wd_islink(zFullOldPath) ){
690 symlink_copy(zFullOldPath, zFullNewPath);
691 }else{
692 file_copy(zFullOldPath, zFullNewPath);
693 }
 
694 file_delete(zFullOldPath);
695 free(zFullNewPath);
696 free(zFullOldPath);
697 }
698 }
699 db_finalize(&q);
700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
702 /* Report on conflicts
703 */
704 if( nConflict ){
705 fossil_warning("WARNING: %d merge conflicts", nConflict);
706
--- src/merge.c
+++ src/merge.c
@@ -128,10 +128,46 @@
128 }
129 }
130 db_finalize(&q);
131 return fForkSeen;
132 }
133
134 /*
135 ** Add an entry to the FV table for all files renamed between
136 ** version N and the version specified by vid.
137 */
138 static void add_renames(
139 const char *zFnCol, /* The FV column for the filename in vid */
140 int vid, /* The desired version's RID */
141 int nid, /* Version N's RID */
142 int revOk, /* Ok to move backwards (child->parent) if true */
143 const char *zDebug /* Generate trace output if not NULL */
144 ){
145 int nChng; /* Number of file name changes */
146 int *aChng; /* An array of file name changes */
147 int i; /* Loop counter */
148 find_filename_changes(nid, vid, revOk, &nChng, &aChng, zDebug);
149 if( nChng==0 ) return;
150 for(i=0; i<nChng; i++){
151 char *zN, *zV;
152 zN = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2]);
153 zV = db_text(0, "SELECT name FROM filename WHERE fnid=%d", aChng[i*2+1]);
154 db_multi_exec(
155 "INSERT OR IGNORE INTO fv(%s,fnn) VALUES(%Q,%Q)",
156 zFnCol /*safe-for-%s*/, zV, zN
157 );
158 if( db_changes()==0 ){
159 db_multi_exec(
160 "UPDATE fv SET %s=%Q WHERE fnn=%Q",
161 zFnCol /*safe-for-%s*/, zV, zN
162 );
163 }
164 free(zN);
165 free(zV);
166 }
167 free(aChng);
168 }
169
170 /*
171 ** COMMAND: merge
172 **
173 ** Usage: %fossil merge ?OPTIONS? ?VERSION?
@@ -178,10 +214,11 @@
214 */
215 void merge_cmd(void){
216 int vid; /* Current version "V" */
217 int mid; /* Version we are merging from "M" */
218 int pid; /* The pivot version - most recent common ancestor P */
219 int nid = 0; /* The name pivot version "N" */
220 int verboseFlag; /* True if the -v|--verbose option is present */
221 int integrateFlag; /* True if the --integrate option is present */
222 int pickFlag; /* True if the --cherrypick option is present */
223 int backoutFlag; /* True if the --backout option is present */
224 int dryRunFlag; /* True if the --dry-run or -n option is present */
@@ -188,23 +225,22 @@
225 int forceFlag; /* True if the --force or -f option is present */
226 int forceMissingFlag; /* True if the --force-missing option is present */
227 const char *zBinGlob; /* The value of --binary */
228 const char *zPivot; /* The value of --baseline */
229 int debugFlag; /* True if --debug is present */
 
 
 
230 int nConflict = 0; /* Number of conflicts seen */
231 int nOverwrite = 0; /* Number of unmanaged files overwritten */
232 char vAncestor = 'p'; /* If P is an ancestor of V then 'p', else 'n' */
233 Stmt q;
234
235
236 /* Notation:
237 **
238 ** V The current checkout
239 ** M The version being merged in
240 ** P The "pivot" - the most recent common ancestor of V and M.
241 ** N The "name pivot" - for detecting renames
242 */
243
244 undo_capture_command_line();
245 verboseFlag = find_option("verbose","v",0)!=0;
246 forceMissingFlag = find_option("force-missing",0,0)!=0;
@@ -291,37 +327,49 @@
327 fossil_fatal("not a version: %s", zPivot);
328 }
329 if( pickFlag ){
330 fossil_fatal("incompatible options: --cherrypick & --baseline");
331 }
332 }
333 if( pickFlag || backoutFlag ){
334 if( integrateFlag ){
335 fossil_fatal("incompatible options: --integrate & --cherrypick or --backout");
336 }
337 pid = db_int(0, "SELECT pid FROM plink WHERE cid=%d AND isprim", mid);
338 if( pid<=0 ){
339 fossil_fatal("cannot find an ancestor for %s", g.argv[2]);
340 }
341 }else{
342 if( !zPivot ){
343 pivot_set_primary(mid);
344 pivot_set_secondary(vid);
345 db_prepare(&q, "SELECT merge FROM vmerge WHERE id=0");
346 while( db_step(&q)==SQLITE_ROW ){
347 pivot_set_secondary(db_column_int(&q,0));
348 }
349 db_finalize(&q);
350 pid = pivot_find(0);
351 if( pid<=0 ){
352 fossil_fatal("cannot find a common ancestor between the current "
353 "checkout and %s", g.argv[2]);
354 }
355 }
356 pivot_set_primary(mid);
357 pivot_set_secondary(vid);
358 nid = pivot_find(1);
359 if( nid!=pid ){
360 pivot_set_primary(nid);
361 pivot_set_secondary(pid);
362 nid = pivot_find(1);
 
 
 
 
363 }
364 }
365 if( backoutFlag ){
366 int t = pid;
367 pid = mid;
368 mid = t;
369 }
370 if( nid==0 ) nid = pid;
371 if( !is_a_version(pid) ){
372 fossil_fatal("not a version: record #%d", pid);
373 }
374 if( !forceFlag && mid==pid ){
375 fossil_print("Merge skipped because it is a no-op. "
@@ -343,12 +391,25 @@
391 fossil_fatal("missing content, unable to merge");
392 }
393 if( load_vfile_from_rid(pid) && !forceMissingFlag ){
394 fossil_fatal("missing content, unable to merge");
395 }
396 if( zPivot ){
397 vAncestor = db_exists(
398 "WITH RECURSIVE ancestor(id) AS ("
399 " VALUES(%d)"
400 " UNION ALL"
401 " SELECT pid FROM plink, ancestor"
402 " WHERE cid=ancestor.id AND pid!=%d AND cid!=%d)"
403 "SELECT 1 FROM ancestor WHERE id=%d LIMIT 1",
404 vid, nid, pid, pid
405 ) ? 'p' : 'n';
406 }
407 if( debugFlag ){
408 char *z;
409 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", nid);
410 fossil_print("N=%d %z\n", nid, z);
411 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", pid);
412 fossil_print("P=%d %z\n", pid, z);
413 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", mid);
414 fossil_print("M=%d %z\n", mid, z);
415 z = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", vid);
@@ -361,115 +422,102 @@
422 ** in the current checkout, the pivot, and the version being merged.
423 */
424 db_multi_exec(
425 "DROP TABLE IF EXISTS fv;"
426 "CREATE TEMP TABLE fv("
427 " fn TEXT UNIQUE %s," /* The filename */
428 " idv INTEGER DEFAULT 0," /* VFILE entry for current version */
429 " idp INTEGER DEFAULT 0," /* VFILE entry for the pivot */
430 " idm INTEGER DEFAULT 0," /* VFILE entry for version merging in */
431 " chnged BOOLEAN," /* True if current version has been edited */
432 " ridv INTEGER DEFAULT 0," /* Record ID for current version */
433 " ridp INTEGER DEFAULT 0," /* Record ID for pivot */
434 " ridm INTEGER DEFAULT 0," /* Record ID for merge */
435 " isexe BOOLEAN," /* Execute permission enabled */
436 " fnp TEXT UNIQUE %s," /* The filename in the pivot */
437 " fnm TEXT UNIQUE %s," /* The filename in the merged version */
438 " fnn TEXT UNIQUE %s," /* The filename in the name pivot */
439 " islinkv BOOLEAN," /* True if current version is a symlink */
440 " islinkm BOOLEAN" /* True if merged version in is a symlink */
441 ");",
442 filename_collation(), filename_collation(), filename_collation(),
443 filename_collation()
444 );
445
446 /*
447 ** Compute name changes from N to V, P, and M
448 */
449 add_renames("fn", vid, nid, 0, debugFlag ? "N->V" : 0);
450 add_renames("fnp", pid, nid, 0, debugFlag ? "N->P" : 0);
451 add_renames("fnm", mid, nid, backoutFlag, debugFlag ? "N->M" : 0);
452
453 /*
454 ** Add files found in V
455 */
456 db_multi_exec(
457 "UPDATE OR IGNORE fv SET fn=coalesce(fn%c,fnn) WHERE fn IS NULL;"
458 "REPLACE INTO fv(fn,fnp,fnm,fnn,idv,ridv,islinkv,isexe,chnged)"
459 " SELECT pathname, fnp, fnm, fnn, id, rid, islink, vf.isexe, vf.chnged"
460 " FROM vfile vf"
461 " LEFT JOIN fv ON fn=coalesce(origname,pathname)"
462 " AND rid>0 AND vf.chnged NOT IN (3,5)"
463 " WHERE vid=%d;",
464 vAncestor, vid
465 );
466
467 /*
468 ** Add files found in P
469 */
470 db_multi_exec(
471 "UPDATE OR IGNORE fv SET fnp=coalesce(fnn,"
472 " (SELECT coalesce(origname,pathname) FROM vfile WHERE id=idv))"
473 " WHERE fnp IS NULL;"
474 "INSERT OR IGNORE INTO fv(fnp)"
475 " SELECT coalesce(origname,pathname) FROM vfile WHERE vid=%d;",
476 pid
477 );
478
479 /*
480 ** Add files found in M
481 */
482 db_multi_exec(
483 "UPDATE OR IGNORE fv SET fnm=fnp WHERE fnm IS NULL;"
484 "INSERT OR IGNORE INTO fv(fnm)"
485 " SELECT pathname FROM vfile WHERE vid=%d;",
486 mid
487 );
488
489 /*
490 ** Compute the file version ids for P and M
491 */
492 if( pid==vid ){
493 db_multi_exec(
494 "UPDATE fv SET idp=idv, ridp=ridv WHERE ridv>0 AND chnged NOT IN (3,5)"
495 );
496 }else{
497 db_multi_exec(
498 "UPDATE fv SET"
499 " idp=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnp=pathname),0),"
500 " ridp=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnp=pathname),0)",
501 pid, pid
502 );
503 }
 
 
 
 
 
 
 
 
 
 
 
 
504 db_multi_exec(
505 "UPDATE fv SET"
 
 
506 " idm=coalesce((SELECT id FROM vfile WHERE vid=%d AND fnm=pathname),0),"
507 " ridm=coalesce((SELECT rid FROM vfile WHERE vid=%d AND fnm=pathname),0),"
508 " islinkm=coalesce((SELECT islink FROM vfile"
509 " WHERE vid=%d AND fnm=pathname),0),"
510 " isexe=coalesce((SELECT isexe FROM vfile WHERE vid=%d AND fnm=pathname),"
511 " isexe)",
512 mid, mid, mid, mid
513 );
514
515 if( debugFlag ){
516 db_prepare(&q,
517 "SELECT rowid, fn, fnp, fnm, chnged, ridv, ridp, ridm, "
518 " isexe, islinkv, islinkm, fnn FROM fv"
519 );
520 while( db_step(&q)==SQLITE_ROW ){
521 fossil_print("%3d: ridv=%-4d ridp=%-4d ridm=%-4d chnged=%d isexe=%d "
522 " islinkv=%d islinkm=%d\n",
523 db_column_int(&q, 0),
@@ -481,14 +529,36 @@
529 db_column_int(&q, 9),
530 db_column_int(&q, 10));
531 fossil_print(" fn = [%s]\n", db_column_text(&q, 1));
532 fossil_print(" fnp = [%s]\n", db_column_text(&q, 2));
533 fossil_print(" fnm = [%s]\n", db_column_text(&q, 3));
534 fossil_print(" fnn = [%s]\n", db_column_text(&q, 11));
535 }
536 db_finalize(&q);
537 }
538
539 /*
540 ** Update the execute bit on files where it's changed from P->M but not P->V
541 */
542 db_prepare(&q,
543 "SELECT idv, fn, fv.isexe FROM fv, vfile p, vfile v"
544 " WHERE p.id=idp AND v.id=idv AND fv.isexe!=p.isexe AND v.isexe=p.isexe"
545 );
546 while( db_step(&q)==SQLITE_ROW ){
547 int idv = db_column_int(&q, 0);
548 const char *zName = db_column_text(&q, 1);
549 int isExe = db_column_int(&q, 2);
550 fossil_print("%s %s\n", isExe ? "EXECUTABLE" : "UNEXEC", zName);
551 if( !dryRunFlag ){
552 char *zFullPath = mprintf("%s/%s", g.zLocalRoot, zName);
553 file_wd_setexe(zFullPath, isExe);
554 free(zFullPath);
555 db_multi_exec("UPDATE vfile SET isexe=%d WHERE id=%d", isExe, idv);
556 }
557 }
558 db_finalize(&q);
559
560 /*
561 ** Find files in M and V but not in P and report conflicts.
562 ** The file in M will be ignored. It will be treated as if it
563 ** does not exist.
564 */
@@ -496,50 +566,14 @@
566 "SELECT idm FROM fv WHERE idp=0 AND idv>0 AND idm>0"
567 );
568 while( db_step(&q)==SQLITE_ROW ){
569 int idm = db_column_int(&q, 0);
570 char *zName = db_text(0, "SELECT pathname FROM vfile WHERE id=%d", idm);
571 fossil_warning("WARNING: no common ancestor for %s", zName);
572 free(zName);
573 db_multi_exec("UPDATE fv SET idm=0 WHERE idm=%d", idm);
574 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575 db_finalize(&q);
576
577 /*
578 ** Find files that have changed from P->M but not P->V.
579 ** Copy the M content over into V.
@@ -646,11 +680,11 @@
680 const char *zName = db_column_text(&q, 1);
681 int chnged = db_column_int(&q, 2);
682 /* Delete the file idv */
683 fossil_print("DELETE %s\n", zName);
684 if( chnged ){
685 fossil_warning("WARNING: local edits lost for %s", zName);
686 nConflict++;
687 }
688 if( !dryRunFlag ) undo_save(zName);
689 db_multi_exec(
690 "UPDATE vfile SET deleted=1 WHERE id=%d", idv
@@ -661,45 +695,117 @@
695 free(zFullPath);
696 }
697 }
698 db_finalize(&q);
699
700 /* For certain sets of renames (e.g. A -> B and B -> A), a file that is
701 ** being renamed must first be moved to a temporary location to avoid
702 ** being overwritten by another rename operation. A row is added to the
703 ** TMPRN table for each of these temporary renames.
704 */
705 db_multi_exec(
706 "DROP TABLE IF EXISTS tmprn;"
707 "CREATE TEMP TABLE tmprn(fn UNIQUE, tmpfn);"
708 );
709
710 /*
711 ** Rename files that have taken a rename on P->M but which keep the same
712 ** name on P->V. If a file is renamed on P->V only or on both P->V and
713 ** P->M then we retain the V name of the file.
714 */
715 db_prepare(&q,
716 "SELECT idv, fnp, fnm, isexe FROM fv"
717 " WHERE idv>0 AND idp>0 AND idm>0 AND fnp=fn AND fnm!=fnp"
718 );
719 while( db_step(&q)==SQLITE_ROW ){
720 int idv = db_column_int(&q, 0);
721 const char *zOldName = db_column_text(&q, 1);
722 const char *zNewName = db_column_text(&q, 2);
723 int isExe = db_column_int(&q, 3);
724 fossil_print("RENAME %s -> %s\n", zOldName, zNewName);
725 if( !dryRunFlag ) undo_save(zOldName);
726 if( !dryRunFlag ) undo_save(zNewName);
727 db_multi_exec(
728 "UPDATE vfile SET pathname=NULL, origname=pathname"
729 " WHERE vid=%d AND pathname=%Q;"
730 "UPDATE vfile SET pathname=%Q, origname=coalesce(origname,pathname)"
731 " WHERE id=%d;",
732 vid, zNewName, zNewName, idv
733 );
734 if( !dryRunFlag ){
735 char *zFullOldPath, *zFullNewPath;
736 zFullOldPath = db_text(0,"SELECT tmpfn FROM tmprn WHERE fn=%Q", zOldName);
737 if( !zFullOldPath ){
738 zFullOldPath = mprintf("%s%s", g.zLocalRoot, zOldName);
739 }
740 zFullNewPath = mprintf("%s%s", g.zLocalRoot, zNewName);
741 if( file_wd_size(zFullNewPath)>=0 ){
742 char zTmpPath[300];
743 file_tempname(sizeof(zTmpPath), zTmpPath);
744 db_multi_exec("INSERT INTO tmprn(fn,tmpfn) VALUES(%Q,%Q)",
745 zNewName, zTmpPath);
746 if( file_wd_islink(zFullNewPath) ){
747 symlink_copy(zFullNewPath, zTmpPath);
748 }else{
749 file_copy(zFullNewPath, zTmpPath);
750 }
751 }
752 if( file_wd_islink(zFullOldPath) ){
753 symlink_copy(zFullOldPath, zFullNewPath);
754 }else{
755 file_copy(zFullOldPath, zFullNewPath);
756 }
757 file_wd_setexe(zFullNewPath, isExe);
758 file_delete(zFullOldPath);
759 free(zFullNewPath);
760 free(zFullOldPath);
761 }
762 }
763 db_finalize(&q);
764
765 /* A file that has been deleted and replaced by a renamed file will have a
766 ** NULL pathname. Change it to something that makes the output of "status"
767 ** and similar commands make sense for such files and that will (most likely)
768 ** not be an actual existing pathname.
769 */
770 db_multi_exec(
771 "UPDATE vfile SET pathname=origname || ' (overwritten by rename)'"
772 " WHERE pathname IS NULL"
773 );
774
775 /*
776 ** Add to V files that are not in V or P but are in M
777 */
778 db_prepare(&q,
779 "SELECT idm, fnm FROM fv"
780 " WHERE idp=0 AND idv=0 AND idm>0"
781 );
782 while( db_step(&q)==SQLITE_ROW ){
783 int idm = db_column_int(&q, 0);
784 const char *zName;
785 char *zFullName;
786 db_multi_exec(
787 "INSERT INTO vfile(vid,chnged,deleted,rid,mrid,isexe,islink,pathname)"
788 " SELECT %d,%d,0,rid,mrid,isexe,islink,pathname FROM vfile WHERE id=%d",
789 vid, integrateFlag?5:3, idm
790 );
791 zName = db_column_text(&q, 1);
792 zFullName = mprintf("%s%s", g.zLocalRoot, zName);
793 if( file_wd_isfile_or_link(zFullName)
794 && !db_exists("SELECT 1 FROM fv WHERE fn=%Q", zName) ){
795 fossil_print("ADDED %s (overwrites an unmanaged file)\n", zName);
796 nOverwrite++;
797 }else{
798 fossil_print("ADDED %s\n", zName);
799 }
800 fossil_free(zFullName);
801 if( !dryRunFlag ){
802 undo_save(zName);
803 vfile_to_disk(0, idm, 0, 0);
804 }
805 }
806 db_finalize(&q);
807
808 /* Report on conflicts
809 */
810 if( nConflict ){
811 fossil_warning("WARNING: %d merge conflicts", nConflict);
812
-1
--- src/path.c
+++ src/path.c
@@ -452,11 +452,10 @@
452452
if( nChng ){
453453
aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
454454
for(pChng=pAll, i=0; pChng; pChng=pChng->pNext){
455455
if( pChng->newName==0 ) continue;
456456
if( pChng->origName==0 ) continue;
457
- if( pChng->newName==pChng->origName ) continue;
458457
aChng[i] = pChng->origName;
459458
aChng[i+1] = pChng->newName;
460459
if( zDebug ){
461460
fossil_print("%s summary %d[%z] -> %d[%z]\n",
462461
zDebug,
463462
--- src/path.c
+++ src/path.c
@@ -452,11 +452,10 @@
452 if( nChng ){
453 aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
454 for(pChng=pAll, i=0; pChng; pChng=pChng->pNext){
455 if( pChng->newName==0 ) continue;
456 if( pChng->origName==0 ) continue;
457 if( pChng->newName==pChng->origName ) continue;
458 aChng[i] = pChng->origName;
459 aChng[i+1] = pChng->newName;
460 if( zDebug ){
461 fossil_print("%s summary %d[%z] -> %d[%z]\n",
462 zDebug,
463
--- src/path.c
+++ src/path.c
@@ -452,11 +452,10 @@
452 if( nChng ){
453 aChng = *aiChng = fossil_malloc( nChng*2*sizeof(int) );
454 for(pChng=pAll, i=0; pChng; pChng=pChng->pNext){
455 if( pChng->newName==0 ) continue;
456 if( pChng->origName==0 ) continue;
 
457 aChng[i] = pChng->origName;
458 aChng[i+1] = pChng->newName;
459 if( zDebug ){
460 fossil_print("%s summary %d[%z] -> %d[%z]\n",
461 zDebug,
462
+8 -4
--- src/pivot.c
+++ src/pivot.c
@@ -73,12 +73,14 @@
7373
7474
/*
7575
** Find the most recent common ancestor of the primary and one of
7676
** the secondaries. Return its rid. Return 0 if no common ancestor
7777
** can be found.
78
+**
79
+** If ignoreMerges is true, follow only "primary" parent links.
7880
*/
79
-int pivot_find(void){
81
+int pivot_find(int ignoreMerges){
8082
Stmt q1, q2, u1, i1;
8183
int rid = 0;
8284
8385
/* aqueue must contain at least one primary and one other. Otherwise
8486
** we abort early
@@ -102,11 +104,12 @@
102104
db_prepare(&q2,
103105
"SELECT 1 FROM aqueue A, plink, aqueue B"
104106
" WHERE plink.pid=:rid"
105107
" AND plink.cid=B.rid"
106108
" AND A.rid=:rid"
107
- " AND A.src!=B.src"
109
+ " AND A.src!=B.src %s",
110
+ ignoreMerges ? "AND plink.isprim" : ""
108111
);
109112
110113
/* Mark the :rid record has having been checked. It is not the
111114
** common ancestor.
112115
*/
@@ -122,11 +125,12 @@
122125
" coalesce((SELECT mtime FROM plink X WHERE X.cid=plink.pid), 0.0),"
123126
" 1,"
124127
" aqueue.src "
125128
" FROM plink, aqueue"
126129
" WHERE plink.cid=:rid"
127
- " AND aqueue.rid=:rid"
130
+ " AND aqueue.rid=:rid %s",
131
+ ignoreMerges ? "AND plink.isprim" : ""
128132
);
129133
130134
while( db_step(&q1)==SQLITE_ROW ){
131135
rid = db_column_int(&q1, 0);
132136
db_reset(&q1);
@@ -161,10 +165,10 @@
161165
db_must_be_within_tree();
162166
pivot_set_primary(name_to_rid(g.argv[2]));
163167
for(i=3; i<g.argc; i++){
164168
pivot_set_secondary(name_to_rid(g.argv[i]));
165169
}
166
- rid = pivot_find();
170
+ rid = pivot_find(0);
167171
printf("pivot=%s\n",
168172
db_text("?","SELECT uuid FROM blob WHERE rid=%d",rid)
169173
);
170174
}
171175
--- src/pivot.c
+++ src/pivot.c
@@ -73,12 +73,14 @@
73
74 /*
75 ** Find the most recent common ancestor of the primary and one of
76 ** the secondaries. Return its rid. Return 0 if no common ancestor
77 ** can be found.
 
 
78 */
79 int pivot_find(void){
80 Stmt q1, q2, u1, i1;
81 int rid = 0;
82
83 /* aqueue must contain at least one primary and one other. Otherwise
84 ** we abort early
@@ -102,11 +104,12 @@
102 db_prepare(&q2,
103 "SELECT 1 FROM aqueue A, plink, aqueue B"
104 " WHERE plink.pid=:rid"
105 " AND plink.cid=B.rid"
106 " AND A.rid=:rid"
107 " AND A.src!=B.src"
 
108 );
109
110 /* Mark the :rid record has having been checked. It is not the
111 ** common ancestor.
112 */
@@ -122,11 +125,12 @@
122 " coalesce((SELECT mtime FROM plink X WHERE X.cid=plink.pid), 0.0),"
123 " 1,"
124 " aqueue.src "
125 " FROM plink, aqueue"
126 " WHERE plink.cid=:rid"
127 " AND aqueue.rid=:rid"
 
128 );
129
130 while( db_step(&q1)==SQLITE_ROW ){
131 rid = db_column_int(&q1, 0);
132 db_reset(&q1);
@@ -161,10 +165,10 @@
161 db_must_be_within_tree();
162 pivot_set_primary(name_to_rid(g.argv[2]));
163 for(i=3; i<g.argc; i++){
164 pivot_set_secondary(name_to_rid(g.argv[i]));
165 }
166 rid = pivot_find();
167 printf("pivot=%s\n",
168 db_text("?","SELECT uuid FROM blob WHERE rid=%d",rid)
169 );
170 }
171
--- src/pivot.c
+++ src/pivot.c
@@ -73,12 +73,14 @@
73
74 /*
75 ** Find the most recent common ancestor of the primary and one of
76 ** the secondaries. Return its rid. Return 0 if no common ancestor
77 ** can be found.
78 **
79 ** If ignoreMerges is true, follow only "primary" parent links.
80 */
81 int pivot_find(int ignoreMerges){
82 Stmt q1, q2, u1, i1;
83 int rid = 0;
84
85 /* aqueue must contain at least one primary and one other. Otherwise
86 ** we abort early
@@ -102,11 +104,12 @@
104 db_prepare(&q2,
105 "SELECT 1 FROM aqueue A, plink, aqueue B"
106 " WHERE plink.pid=:rid"
107 " AND plink.cid=B.rid"
108 " AND A.rid=:rid"
109 " AND A.src!=B.src %s",
110 ignoreMerges ? "AND plink.isprim" : ""
111 );
112
113 /* Mark the :rid record has having been checked. It is not the
114 ** common ancestor.
115 */
@@ -122,11 +125,12 @@
125 " coalesce((SELECT mtime FROM plink X WHERE X.cid=plink.pid), 0.0),"
126 " 1,"
127 " aqueue.src "
128 " FROM plink, aqueue"
129 " WHERE plink.cid=:rid"
130 " AND aqueue.rid=:rid %s",
131 ignoreMerges ? "AND plink.isprim" : ""
132 );
133
134 while( db_step(&q1)==SQLITE_ROW ){
135 rid = db_column_int(&q1, 0);
136 db_reset(&q1);
@@ -161,10 +165,10 @@
165 db_must_be_within_tree();
166 pivot_set_primary(name_to_rid(g.argv[2]));
167 for(i=3; i<g.argc; i++){
168 pivot_set_secondary(name_to_rid(g.argv[i]));
169 }
170 rid = pivot_find(0);
171 printf("pivot=%s\n",
172 db_text("?","SELECT uuid FROM blob WHERE rid=%d",rid)
173 );
174 }
175
+233 -87
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667667
#define MODE_Insert 5 /* Generate SQL "insert" statements */
668668
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669669
#define MODE_Csv 7 /* Quote strings, numbers are plain */
670670
#define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671671
#define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
672
+#define MODE_Pretty 10 /* Pretty-print schemas */
672673
673674
static const char *modeDescr[] = {
674675
"line",
675676
"column",
676677
"list",
@@ -679,10 +680,11 @@
679680
"insert",
680681
"tcl",
681682
"csv",
682683
"explain",
683684
"ascii",
685
+ "prettyprint",
684686
};
685687
686688
/*
687689
** These are the column/row/line separators used by the various
688690
** import/export modes.
@@ -1052,11 +1054,74 @@
10521054
i==nArg-1 ? rowSep : " ");
10531055
}
10541056
}
10551057
break;
10561058
}
1057
- case MODE_Semi:
1059
+ case MODE_Semi: { /* .schema and .fullschema output */
1060
+ utf8_printf(p->out, "%s;\n", azArg[0]);
1061
+ break;
1062
+ }
1063
+ case MODE_Pretty: { /* .schema and .fullschema with --indent */
1064
+ char *z;
1065
+ int j;
1066
+ int nParen = 0;
1067
+ char cEnd = 0;
1068
+ char c;
1069
+ int nLine = 0;
1070
+ assert( nArg==1 );
1071
+ if( azArg[0]==0 ) break;
1072
+ if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
1073
+ || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
1074
+ ){
1075
+ utf8_printf(p->out, "%s;\n", azArg[0]);
1076
+ break;
1077
+ }
1078
+ z = sqlite3_mprintf("%s", azArg[0]);
1079
+ j = 0;
1080
+ for(i=0; IsSpace(z[i]); i++){}
1081
+ for(; (c = z[i])!=0; i++){
1082
+ if( IsSpace(c) ){
1083
+ if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
1084
+ }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
1085
+ j--;
1086
+ }
1087
+ z[j++] = c;
1088
+ }
1089
+ while( j>0 && IsSpace(z[j-1]) ){ j--; }
1090
+ z[j] = 0;
1091
+ if( strlen30(z)>=79 ){
1092
+ for(i=j=0; (c = z[i])!=0; i++){
1093
+ if( c==cEnd ){
1094
+ cEnd = 0;
1095
+ }else if( c=='"' || c=='\'' || c=='`' ){
1096
+ cEnd = c;
1097
+ }else if( c=='[' ){
1098
+ cEnd = ']';
1099
+ }else if( c=='(' ){
1100
+ nParen++;
1101
+ }else if( c==')' ){
1102
+ nParen--;
1103
+ if( nLine>0 && nParen==0 && j>0 ){
1104
+ utf8_printf(p->out, "%.*s\n", j, z);
1105
+ j = 0;
1106
+ }
1107
+ }
1108
+ z[j++] = c;
1109
+ if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1110
+ if( c=='\n' ) j--;
1111
+ utf8_printf(p->out, "%.*s\n ", j, z);
1112
+ j = 0;
1113
+ nLine++;
1114
+ while( IsSpace(z[i+1]) ){ i++; }
1115
+ }
1116
+ }
1117
+ z[j] = 0;
1118
+ }
1119
+ utf8_printf(p->out, "%s;\n", z);
1120
+ sqlite3_free(z);
1121
+ break;
1122
+ }
10581123
case MODE_List: {
10591124
if( p->cnt++==0 && p->showHeader ){
10601125
for(i=0; i<nArg; i++){
10611126
utf8_printf(p->out,"%s%s",azCol[i],
10621127
i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
10671132
char *z = azArg[i];
10681133
if( z==0 ) z = p->nullValue;
10691134
utf8_printf(p->out, "%s", z);
10701135
if( i<nArg-1 ){
10711136
utf8_printf(p->out, "%s", p->colSeparator);
1072
- }else if( p->cMode==MODE_Semi ){
1073
- utf8_printf(p->out, ";%s", p->rowSeparator);
10741137
}else{
10751138
utf8_printf(p->out, "%s", p->rowSeparator);
10761139
}
10771140
}
10781141
break;
@@ -1668,11 +1731,11 @@
16681731
for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
16691732
}
16701733
if( str_in_array(zOp, azGoto) && p2op<p->nIndent
16711734
&& (abYield[p2op] || sqlite3_column_int(pSql, 2))
16721735
){
1673
- for(i=p2op+1; i<iOp; i++) p->aiIndent[i] += 2;
1736
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
16741737
}
16751738
}
16761739
16771740
p->iIndent = 0;
16781741
sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
16861749
sqlite3_free(p->aiIndent);
16871750
p->aiIndent = 0;
16881751
p->nIndent = 0;
16891752
p->iIndent = 0;
16901753
}
1754
+
1755
+/*
1756
+** Disable and restore .wheretrace and .selecttrace settings.
1757
+*/
1758
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1759
+extern int sqlite3SelectTrace;
1760
+static int savedSelectTrace;
1761
+#endif
1762
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1763
+extern int sqlite3WhereTrace;
1764
+static int savedWhereTrace;
1765
+#endif
1766
+static void disable_debug_trace_modes(void){
1767
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1768
+ savedSelectTrace = sqlite3SelectTrace;
1769
+ sqlite3SelectTrace = 0;
1770
+#endif
1771
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1772
+ savedWhereTrace = sqlite3WhereTrace;
1773
+ sqlite3WhereTrace = 0;
1774
+#endif
1775
+}
1776
+static void restore_debug_trace_modes(void){
1777
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1778
+ sqlite3SelectTrace = savedSelectTrace;
1779
+#endif
1780
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1781
+ sqlite3WhereTrace = savedWhereTrace;
1782
+#endif
1783
+}
1784
+
1785
+/*
1786
+** Run a prepared statement
1787
+*/
1788
+static void exec_prepared_stmt(
1789
+ ShellState *pArg, /* Pointer to ShellState */
1790
+ sqlite3_stmt *pStmt, /* Statment to run */
1791
+ int (*xCallback)(void*,int,char**,char**,int*) /* Callback function */
1792
+){
1793
+ int rc;
1794
+
1795
+ /* perform the first step. this will tell us if we
1796
+ ** have a result set or not and how wide it is.
1797
+ */
1798
+ rc = sqlite3_step(pStmt);
1799
+ /* if we have a result set... */
1800
+ if( SQLITE_ROW == rc ){
1801
+ /* if we have a callback... */
1802
+ if( xCallback ){
1803
+ /* allocate space for col name ptr, value ptr, and type */
1804
+ int nCol = sqlite3_column_count(pStmt);
1805
+ void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1806
+ if( !pData ){
1807
+ rc = SQLITE_NOMEM;
1808
+ }else{
1809
+ char **azCols = (char **)pData; /* Names of result columns */
1810
+ char **azVals = &azCols[nCol]; /* Results */
1811
+ int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1812
+ int i, x;
1813
+ assert(sizeof(int) <= sizeof(char *));
1814
+ /* save off ptrs to column names */
1815
+ for(i=0; i<nCol; i++){
1816
+ azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1817
+ }
1818
+ do{
1819
+ /* extract the data and data types */
1820
+ for(i=0; i<nCol; i++){
1821
+ aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1822
+ if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1823
+ azVals[i] = "";
1824
+ }else{
1825
+ azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1826
+ }
1827
+ if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1828
+ rc = SQLITE_NOMEM;
1829
+ break; /* from for */
1830
+ }
1831
+ } /* end for */
1832
+
1833
+ /* if data and types extracted successfully... */
1834
+ if( SQLITE_ROW == rc ){
1835
+ /* call the supplied callback with the result row data */
1836
+ if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1837
+ rc = SQLITE_ABORT;
1838
+ }else{
1839
+ rc = sqlite3_step(pStmt);
1840
+ }
1841
+ }
1842
+ } while( SQLITE_ROW == rc );
1843
+ sqlite3_free(pData);
1844
+ }
1845
+ }else{
1846
+ do{
1847
+ rc = sqlite3_step(pStmt);
1848
+ } while( rc == SQLITE_ROW );
1849
+ }
1850
+ }
1851
+}
16911852
16921853
/*
16931854
** Execute a statement or set of statements. Print
16941855
** any result rows/columns depending on the current mode
16951856
** set via the supplied callback.
@@ -1714,10 +1875,11 @@
17141875
if( pzErrMsg ){
17151876
*pzErrMsg = NULL;
17161877
}
17171878
17181879
while( zSql[0] && (SQLITE_OK == rc) ){
1880
+ static const char *zStmtSql;
17191881
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
17201882
if( SQLITE_OK != rc ){
17211883
if( pzErrMsg ){
17221884
*pzErrMsg = save_err_msg(db);
17231885
}
@@ -1726,28 +1888,30 @@
17261888
/* this happens for a comment or white-space */
17271889
zSql = zLeftover;
17281890
while( IsSpace(zSql[0]) ) zSql++;
17291891
continue;
17301892
}
1893
+ zStmtSql = sqlite3_sql(pStmt);
1894
+ while( IsSpace(zStmtSql[0]) ) zStmtSql++;
17311895
17321896
/* save off the prepared statment handle and reset row count */
17331897
if( pArg ){
17341898
pArg->pStmt = pStmt;
17351899
pArg->cnt = 0;
17361900
}
17371901
17381902
/* echo the sql statement if echo on */
17391903
if( pArg && pArg->echoOn ){
1740
- const char *zStmtSql = sqlite3_sql(pStmt);
17411904
utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
17421905
}
17431906
17441907
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
1745
- if( pArg && pArg->autoEQP ){
1908
+ if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
17461909
sqlite3_stmt *pExplain;
1747
- char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1748
- sqlite3_sql(pStmt));
1910
+ char *zEQP;
1911
+ disable_debug_trace_modes();
1912
+ zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
17491913
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
17501914
if( rc==SQLITE_OK ){
17511915
while( sqlite3_step(pExplain)==SQLITE_ROW ){
17521916
raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
17531917
raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
17551919
utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
17561920
}
17571921
}
17581922
sqlite3_finalize(pExplain);
17591923
sqlite3_free(zEQP);
1924
+ if( pArg->autoEQP>=2 ){
1925
+ /* Also do an EXPLAIN for ".eqp full" mode */
1926
+ zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
1927
+ rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1928
+ if( rc==SQLITE_OK ){
1929
+ pArg->cMode = MODE_Explain;
1930
+ explain_data_prepare(pArg, pExplain);
1931
+ exec_prepared_stmt(pArg, pExplain, xCallback);
1932
+ explain_data_delete(pArg);
1933
+ }
1934
+ sqlite3_finalize(pExplain);
1935
+ sqlite3_free(zEQP);
1936
+ }
1937
+ restore_debug_trace_modes();
17601938
}
17611939
17621940
if( pArg ){
17631941
pArg->cMode = pArg->mode;
17641942
if( pArg->autoExplain
17651943
&& sqlite3_column_count(pStmt)==8
1766
- && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1944
+ && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
17671945
){
17681946
pArg->cMode = MODE_Explain;
17691947
}
17701948
17711949
/* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
17731951
if( pArg->cMode==MODE_Explain ){
17741952
explain_data_prepare(pArg, pStmt);
17751953
}
17761954
}
17771955
1778
- /* perform the first step. this will tell us if we
1779
- ** have a result set or not and how wide it is.
1780
- */
1781
- rc = sqlite3_step(pStmt);
1782
- /* if we have a result set... */
1783
- if( SQLITE_ROW == rc ){
1784
- /* if we have a callback... */
1785
- if( xCallback ){
1786
- /* allocate space for col name ptr, value ptr, and type */
1787
- int nCol = sqlite3_column_count(pStmt);
1788
- void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1789
- if( !pData ){
1790
- rc = SQLITE_NOMEM;
1791
- }else{
1792
- char **azCols = (char **)pData; /* Names of result columns */
1793
- char **azVals = &azCols[nCol]; /* Results */
1794
- int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1795
- int i, x;
1796
- assert(sizeof(int) <= sizeof(char *));
1797
- /* save off ptrs to column names */
1798
- for(i=0; i<nCol; i++){
1799
- azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1800
- }
1801
- do{
1802
- /* extract the data and data types */
1803
- for(i=0; i<nCol; i++){
1804
- aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1805
- if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1806
- azVals[i] = "";
1807
- }else{
1808
- azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1809
- }
1810
- if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1811
- rc = SQLITE_NOMEM;
1812
- break; /* from for */
1813
- }
1814
- } /* end for */
1815
-
1816
- /* if data and types extracted successfully... */
1817
- if( SQLITE_ROW == rc ){
1818
- /* call the supplied callback with the result row data */
1819
- if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1820
- rc = SQLITE_ABORT;
1821
- }else{
1822
- rc = sqlite3_step(pStmt);
1823
- }
1824
- }
1825
- } while( SQLITE_ROW == rc );
1826
- sqlite3_free(pData);
1827
- }
1828
- }else{
1829
- do{
1830
- rc = sqlite3_step(pStmt);
1831
- } while( rc == SQLITE_ROW );
1832
- }
1833
- }
1834
-
1956
+ exec_prepared_stmt(pArg, pStmt, xCallback);
18351957
explain_data_delete(pArg);
18361958
18371959
/* print usage stats if stats on */
18381960
if( pArg && pArg->statsOn ){
18391961
display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
20192141
".dbinfo ?DB? Show status information about the database\n"
20202142
".dump ?TABLE? ... Dump the database in an SQL text format\n"
20212143
" If TABLE specified, only dump tables matching\n"
20222144
" LIKE pattern TABLE.\n"
20232145
".echo on|off Turn command echo on or off\n"
2024
- ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
2146
+ ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
20252147
".exit Exit this program\n"
20262148
".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2027
- ".fullschema Show schema and the content of sqlite_stat tables\n"
2149
+ ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
20282150
".headers on|off Turn display of headers on or off\n"
20292151
".help Show this message\n"
20302152
".import FILE TABLE Import data from FILE into TABLE\n"
20312153
".indexes ?TABLE? Show names of all indexes\n"
20322154
" If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
20582180
".quit Exit this program\n"
20592181
".read FILENAME Execute SQL in FILENAME\n"
20602182
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
20612183
".save FILE Write in-memory database into FILE\n"
20622184
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2063
- ".schema ?TABLE? Show the CREATE statements\n"
2064
- " If TABLE specified, only show tables matching\n"
2065
- " LIKE pattern TABLE.\n"
2185
+ ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n"
2186
+ " Add --indent for pretty-printing\n"
20662187
".separator COL ?ROW? Change the column separator and optionally the row\n"
20672188
" separator for both the output mode and .import\n"
20682189
#if defined(SQLITE_ENABLE_SESSION)
20692190
".session CMD ... Create or control sessions\n"
20702191
#endif
@@ -2930,10 +3051,21 @@
29303051
*/
29313052
static int shellNomemError(void){
29323053
raw_printf(stderr, "Error: out of memory\n");
29333054
return 1;
29343055
}
3056
+
3057
+/*
3058
+** Compare the string as a command-line option with either one or two
3059
+** initial "-" characters.
3060
+*/
3061
+static int optionMatch(const char *zStr, const char *zOpt){
3062
+ if( zStr[0]!='-' ) return 0;
3063
+ zStr++;
3064
+ if( zStr[0]=='-' ) zStr++;
3065
+ return strcmp(zStr, zOpt)==0;
3066
+}
29353067
29363068
/*
29373069
** If an input line begins with "." then invoke this routine to
29383070
** process that line.
29393071
**
@@ -3179,13 +3311,17 @@
31793311
}
31803312
}else
31813313
31823314
if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
31833315
if( nArg==2 ){
3184
- p->autoEQP = booleanValue(azArg[1]);
3316
+ if( strcmp(azArg[1],"full")==0 ){
3317
+ p->autoEQP = 2;
3318
+ }else{
3319
+ p->autoEQP = booleanValue(azArg[1]);
3320
+ }
31853321
}else{
3186
- raw_printf(stderr, "Usage: .eqp on|off\n");
3322
+ raw_printf(stderr, "Usage: .eqp on|off|full\n");
31873323
rc = 1;
31883324
}
31893325
}else
31903326
31913327
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
32173353
32183354
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
32193355
ShellState data;
32203356
char *zErrMsg = 0;
32213357
int doStats = 0;
3222
- if( nArg!=1 ){
3223
- raw_printf(stderr, "Usage: .fullschema\n");
3224
- rc = 1;
3225
- goto meta_command_exit;
3226
- }
3227
- open_db(p, 0);
32283358
memcpy(&data, p, sizeof(data));
32293359
data.showHeader = 0;
32303360
data.cMode = data.mode = MODE_Semi;
3361
+ if( nArg==2 && optionMatch(azArg[1], "indent") ){
3362
+ data.cMode = data.mode = MODE_Pretty;
3363
+ nArg = 1;
3364
+ }
3365
+ if( nArg!=1 ){
3366
+ raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
3367
+ rc = 1;
3368
+ goto meta_command_exit;
3369
+ }
3370
+ open_db(p, 0);
32313371
rc = sqlite3_exec(p->db,
32323372
"SELECT sql FROM"
32333373
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
32343374
" FROM sqlite_master UNION ALL"
32353375
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
38604000
char *zErrMsg = 0;
38614001
open_db(p, 0);
38624002
memcpy(&data, p, sizeof(data));
38634003
data.showHeader = 0;
38644004
data.cMode = data.mode = MODE_Semi;
3865
- if( nArg==2 ){
4005
+ if( nArg>=2 && optionMatch(azArg[1], "indent") ){
4006
+ data.cMode = data.mode = MODE_Pretty;
4007
+ nArg--;
4008
+ if( nArg==2 ) azArg[1] = azArg[2];
4009
+ }
4010
+ if( nArg==2 && azArg[1][0]!='-' ){
38664011
int i;
38674012
for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
38684013
if( strcmp(azArg[1],"sqlite_master")==0 ){
38694014
char *new_argv[2], *new_colv[2];
38704015
new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
39154060
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
39164061
"ORDER BY rowid",
39174062
callback, &data, &zErrMsg
39184063
);
39194064
}else{
3920
- raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
4065
+ raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
39214066
rc = 1;
39224067
goto meta_command_exit;
39234068
}
39244069
if( zErrMsg ){
39254070
utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
39334078
}
39344079
}else
39354080
39364081
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
39374082
if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3938
- extern int sqlite3SelectTrace;
39394083
sqlite3SelectTrace = integerValue(azArg[1]);
39404084
}else
39414085
#endif
39424086
39434087
#if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
41934337
sqlite3_free(zCmd);
41944338
if( x ) raw_printf(stderr, "System command returns %d\n", x);
41954339
}else
41964340
41974341
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
4342
+ static const char *azBool[] = { "off", "on", "full", "unk" };
41984343
int i;
41994344
if( nArg!=1 ){
42004345
raw_printf(stderr, "Usage: .show\n");
42014346
rc = 1;
42024347
goto meta_command_exit;
42034348
}
4204
- utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
4205
- utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
4349
+ utf8_printf(p->out, "%12.12s: %s\n","echo", azBool[p->echoOn!=0]);
4350
+ utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
42064351
utf8_printf(p->out, "%12.12s: %s\n","explain",
42074352
p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4208
- utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
4353
+ utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
42094354
utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
42104355
utf8_printf(p->out, "%12.12s: ", "nullvalue");
42114356
output_c_string(p->out, p->nullValue);
42124357
raw_printf(p->out, "\n");
42134358
utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
42164361
output_c_string(p->out, p->colSeparator);
42174362
raw_printf(p->out, "\n");
42184363
utf8_printf(p->out,"%12.12s: ", "rowseparator");
42194364
output_c_string(p->out, p->rowSeparator);
42204365
raw_printf(p->out, "\n");
4221
- utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
4366
+ utf8_printf(p->out, "%12.12s: %s\n","stats", azBool[p->statsOn!=0]);
42224367
utf8_printf(p->out, "%12.12s: ", "width");
42234368
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
42244369
raw_printf(p->out, "%d ", p->colWidth[i]);
42254370
}
42264371
raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
46314776
}
46324777
}else
46334778
46344779
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
46354780
if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
4636
- extern int sqlite3WhereTrace;
46374781
sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
46384782
}else
46394783
#endif
46404784
46414785
if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
52995443
data.showHeader = 0;
53005444
}else if( strcmp(z,"-echo")==0 ){
53015445
data.echoOn = 1;
53025446
}else if( strcmp(z,"-eqp")==0 ){
53035447
data.autoEQP = 1;
5448
+ }else if( strcmp(z,"-eqpfull")==0 ){
5449
+ data.autoEQP = 2;
53045450
}else if( strcmp(z,"-stats")==0 ){
53055451
data.statsOn = 1;
53065452
}else if( strcmp(z,"-scanstats")==0 ){
53075453
data.scanstatsOn = 1;
53085454
}else if( strcmp(z,"-backslash")==0 ){
53095455
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667 #define MODE_Insert 5 /* Generate SQL "insert" statements */
668 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669 #define MODE_Csv 7 /* Quote strings, numbers are plain */
670 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
 
672
673 static const char *modeDescr[] = {
674 "line",
675 "column",
676 "list",
@@ -679,10 +680,11 @@
679 "insert",
680 "tcl",
681 "csv",
682 "explain",
683 "ascii",
 
684 };
685
686 /*
687 ** These are the column/row/line separators used by the various
688 ** import/export modes.
@@ -1052,11 +1054,74 @@
1052 i==nArg-1 ? rowSep : " ");
1053 }
1054 }
1055 break;
1056 }
1057 case MODE_Semi:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1058 case MODE_List: {
1059 if( p->cnt++==0 && p->showHeader ){
1060 for(i=0; i<nArg; i++){
1061 utf8_printf(p->out,"%s%s",azCol[i],
1062 i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
1067 char *z = azArg[i];
1068 if( z==0 ) z = p->nullValue;
1069 utf8_printf(p->out, "%s", z);
1070 if( i<nArg-1 ){
1071 utf8_printf(p->out, "%s", p->colSeparator);
1072 }else if( p->cMode==MODE_Semi ){
1073 utf8_printf(p->out, ";%s", p->rowSeparator);
1074 }else{
1075 utf8_printf(p->out, "%s", p->rowSeparator);
1076 }
1077 }
1078 break;
@@ -1668,11 +1731,11 @@
1668 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1669 }
1670 if( str_in_array(zOp, azGoto) && p2op<p->nIndent
1671 && (abYield[p2op] || sqlite3_column_int(pSql, 2))
1672 ){
1673 for(i=p2op+1; i<iOp; i++) p->aiIndent[i] += 2;
1674 }
1675 }
1676
1677 p->iIndent = 0;
1678 sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
1686 sqlite3_free(p->aiIndent);
1687 p->aiIndent = 0;
1688 p->nIndent = 0;
1689 p->iIndent = 0;
1690 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1691
1692 /*
1693 ** Execute a statement or set of statements. Print
1694 ** any result rows/columns depending on the current mode
1695 ** set via the supplied callback.
@@ -1714,10 +1875,11 @@
1714 if( pzErrMsg ){
1715 *pzErrMsg = NULL;
1716 }
1717
1718 while( zSql[0] && (SQLITE_OK == rc) ){
 
1719 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1720 if( SQLITE_OK != rc ){
1721 if( pzErrMsg ){
1722 *pzErrMsg = save_err_msg(db);
1723 }
@@ -1726,28 +1888,30 @@
1726 /* this happens for a comment or white-space */
1727 zSql = zLeftover;
1728 while( IsSpace(zSql[0]) ) zSql++;
1729 continue;
1730 }
 
 
1731
1732 /* save off the prepared statment handle and reset row count */
1733 if( pArg ){
1734 pArg->pStmt = pStmt;
1735 pArg->cnt = 0;
1736 }
1737
1738 /* echo the sql statement if echo on */
1739 if( pArg && pArg->echoOn ){
1740 const char *zStmtSql = sqlite3_sql(pStmt);
1741 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1742 }
1743
1744 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1745 if( pArg && pArg->autoEQP ){
1746 sqlite3_stmt *pExplain;
1747 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1748 sqlite3_sql(pStmt));
 
1749 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1750 if( rc==SQLITE_OK ){
1751 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1752 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1753 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
1755 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1756 }
1757 }
1758 sqlite3_finalize(pExplain);
1759 sqlite3_free(zEQP);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1760 }
1761
1762 if( pArg ){
1763 pArg->cMode = pArg->mode;
1764 if( pArg->autoExplain
1765 && sqlite3_column_count(pStmt)==8
1766 && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1767 ){
1768 pArg->cMode = MODE_Explain;
1769 }
1770
1771 /* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
1773 if( pArg->cMode==MODE_Explain ){
1774 explain_data_prepare(pArg, pStmt);
1775 }
1776 }
1777
1778 /* perform the first step. this will tell us if we
1779 ** have a result set or not and how wide it is.
1780 */
1781 rc = sqlite3_step(pStmt);
1782 /* if we have a result set... */
1783 if( SQLITE_ROW == rc ){
1784 /* if we have a callback... */
1785 if( xCallback ){
1786 /* allocate space for col name ptr, value ptr, and type */
1787 int nCol = sqlite3_column_count(pStmt);
1788 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1789 if( !pData ){
1790 rc = SQLITE_NOMEM;
1791 }else{
1792 char **azCols = (char **)pData; /* Names of result columns */
1793 char **azVals = &azCols[nCol]; /* Results */
1794 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1795 int i, x;
1796 assert(sizeof(int) <= sizeof(char *));
1797 /* save off ptrs to column names */
1798 for(i=0; i<nCol; i++){
1799 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1800 }
1801 do{
1802 /* extract the data and data types */
1803 for(i=0; i<nCol; i++){
1804 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1805 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1806 azVals[i] = "";
1807 }else{
1808 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1809 }
1810 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1811 rc = SQLITE_NOMEM;
1812 break; /* from for */
1813 }
1814 } /* end for */
1815
1816 /* if data and types extracted successfully... */
1817 if( SQLITE_ROW == rc ){
1818 /* call the supplied callback with the result row data */
1819 if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1820 rc = SQLITE_ABORT;
1821 }else{
1822 rc = sqlite3_step(pStmt);
1823 }
1824 }
1825 } while( SQLITE_ROW == rc );
1826 sqlite3_free(pData);
1827 }
1828 }else{
1829 do{
1830 rc = sqlite3_step(pStmt);
1831 } while( rc == SQLITE_ROW );
1832 }
1833 }
1834
1835 explain_data_delete(pArg);
1836
1837 /* print usage stats if stats on */
1838 if( pArg && pArg->statsOn ){
1839 display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
2019 ".dbinfo ?DB? Show status information about the database\n"
2020 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
2021 " If TABLE specified, only dump tables matching\n"
2022 " LIKE pattern TABLE.\n"
2023 ".echo on|off Turn command echo on or off\n"
2024 ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
2025 ".exit Exit this program\n"
2026 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2027 ".fullschema Show schema and the content of sqlite_stat tables\n"
2028 ".headers on|off Turn display of headers on or off\n"
2029 ".help Show this message\n"
2030 ".import FILE TABLE Import data from FILE into TABLE\n"
2031 ".indexes ?TABLE? Show names of all indexes\n"
2032 " If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
2058 ".quit Exit this program\n"
2059 ".read FILENAME Execute SQL in FILENAME\n"
2060 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
2061 ".save FILE Write in-memory database into FILE\n"
2062 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2063 ".schema ?TABLE? Show the CREATE statements\n"
2064 " If TABLE specified, only show tables matching\n"
2065 " LIKE pattern TABLE.\n"
2066 ".separator COL ?ROW? Change the column separator and optionally the row\n"
2067 " separator for both the output mode and .import\n"
2068 #if defined(SQLITE_ENABLE_SESSION)
2069 ".session CMD ... Create or control sessions\n"
2070 #endif
@@ -2930,10 +3051,21 @@
2930 */
2931 static int shellNomemError(void){
2932 raw_printf(stderr, "Error: out of memory\n");
2933 return 1;
2934 }
 
 
 
 
 
 
 
 
 
 
 
2935
2936 /*
2937 ** If an input line begins with "." then invoke this routine to
2938 ** process that line.
2939 **
@@ -3179,13 +3311,17 @@
3179 }
3180 }else
3181
3182 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
3183 if( nArg==2 ){
3184 p->autoEQP = booleanValue(azArg[1]);
 
 
 
 
3185 }else{
3186 raw_printf(stderr, "Usage: .eqp on|off\n");
3187 rc = 1;
3188 }
3189 }else
3190
3191 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
3217
3218 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
3219 ShellState data;
3220 char *zErrMsg = 0;
3221 int doStats = 0;
3222 if( nArg!=1 ){
3223 raw_printf(stderr, "Usage: .fullschema\n");
3224 rc = 1;
3225 goto meta_command_exit;
3226 }
3227 open_db(p, 0);
3228 memcpy(&data, p, sizeof(data));
3229 data.showHeader = 0;
3230 data.cMode = data.mode = MODE_Semi;
 
 
 
 
 
 
 
 
 
 
3231 rc = sqlite3_exec(p->db,
3232 "SELECT sql FROM"
3233 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3234 " FROM sqlite_master UNION ALL"
3235 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
3860 char *zErrMsg = 0;
3861 open_db(p, 0);
3862 memcpy(&data, p, sizeof(data));
3863 data.showHeader = 0;
3864 data.cMode = data.mode = MODE_Semi;
3865 if( nArg==2 ){
 
 
 
 
 
3866 int i;
3867 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
3868 if( strcmp(azArg[1],"sqlite_master")==0 ){
3869 char *new_argv[2], *new_colv[2];
3870 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
3915 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
3916 "ORDER BY rowid",
3917 callback, &data, &zErrMsg
3918 );
3919 }else{
3920 raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
3921 rc = 1;
3922 goto meta_command_exit;
3923 }
3924 if( zErrMsg ){
3925 utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
3933 }
3934 }else
3935
3936 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
3937 if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3938 extern int sqlite3SelectTrace;
3939 sqlite3SelectTrace = integerValue(azArg[1]);
3940 }else
3941 #endif
3942
3943 #if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
4193 sqlite3_free(zCmd);
4194 if( x ) raw_printf(stderr, "System command returns %d\n", x);
4195 }else
4196
4197 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
 
4198 int i;
4199 if( nArg!=1 ){
4200 raw_printf(stderr, "Usage: .show\n");
4201 rc = 1;
4202 goto meta_command_exit;
4203 }
4204 utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
4205 utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
4206 utf8_printf(p->out, "%12.12s: %s\n","explain",
4207 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4208 utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
4209 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
4210 utf8_printf(p->out, "%12.12s: ", "nullvalue");
4211 output_c_string(p->out, p->nullValue);
4212 raw_printf(p->out, "\n");
4213 utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
4216 output_c_string(p->out, p->colSeparator);
4217 raw_printf(p->out, "\n");
4218 utf8_printf(p->out,"%12.12s: ", "rowseparator");
4219 output_c_string(p->out, p->rowSeparator);
4220 raw_printf(p->out, "\n");
4221 utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
4222 utf8_printf(p->out, "%12.12s: ", "width");
4223 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
4224 raw_printf(p->out, "%d ", p->colWidth[i]);
4225 }
4226 raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
4631 }
4632 }else
4633
4634 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
4635 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
4636 extern int sqlite3WhereTrace;
4637 sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
4638 }else
4639 #endif
4640
4641 if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
5299 data.showHeader = 0;
5300 }else if( strcmp(z,"-echo")==0 ){
5301 data.echoOn = 1;
5302 }else if( strcmp(z,"-eqp")==0 ){
5303 data.autoEQP = 1;
 
 
5304 }else if( strcmp(z,"-stats")==0 ){
5305 data.statsOn = 1;
5306 }else if( strcmp(z,"-scanstats")==0 ){
5307 data.scanstatsOn = 1;
5308 }else if( strcmp(z,"-backslash")==0 ){
5309
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667 #define MODE_Insert 5 /* Generate SQL "insert" statements */
668 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669 #define MODE_Csv 7 /* Quote strings, numbers are plain */
670 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
672 #define MODE_Pretty 10 /* Pretty-print schemas */
673
674 static const char *modeDescr[] = {
675 "line",
676 "column",
677 "list",
@@ -679,10 +680,11 @@
680 "insert",
681 "tcl",
682 "csv",
683 "explain",
684 "ascii",
685 "prettyprint",
686 };
687
688 /*
689 ** These are the column/row/line separators used by the various
690 ** import/export modes.
@@ -1052,11 +1054,74 @@
1054 i==nArg-1 ? rowSep : " ");
1055 }
1056 }
1057 break;
1058 }
1059 case MODE_Semi: { /* .schema and .fullschema output */
1060 utf8_printf(p->out, "%s;\n", azArg[0]);
1061 break;
1062 }
1063 case MODE_Pretty: { /* .schema and .fullschema with --indent */
1064 char *z;
1065 int j;
1066 int nParen = 0;
1067 char cEnd = 0;
1068 char c;
1069 int nLine = 0;
1070 assert( nArg==1 );
1071 if( azArg[0]==0 ) break;
1072 if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
1073 || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
1074 ){
1075 utf8_printf(p->out, "%s;\n", azArg[0]);
1076 break;
1077 }
1078 z = sqlite3_mprintf("%s", azArg[0]);
1079 j = 0;
1080 for(i=0; IsSpace(z[i]); i++){}
1081 for(; (c = z[i])!=0; i++){
1082 if( IsSpace(c) ){
1083 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
1084 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
1085 j--;
1086 }
1087 z[j++] = c;
1088 }
1089 while( j>0 && IsSpace(z[j-1]) ){ j--; }
1090 z[j] = 0;
1091 if( strlen30(z)>=79 ){
1092 for(i=j=0; (c = z[i])!=0; i++){
1093 if( c==cEnd ){
1094 cEnd = 0;
1095 }else if( c=='"' || c=='\'' || c=='`' ){
1096 cEnd = c;
1097 }else if( c=='[' ){
1098 cEnd = ']';
1099 }else if( c=='(' ){
1100 nParen++;
1101 }else if( c==')' ){
1102 nParen--;
1103 if( nLine>0 && nParen==0 && j>0 ){
1104 utf8_printf(p->out, "%.*s\n", j, z);
1105 j = 0;
1106 }
1107 }
1108 z[j++] = c;
1109 if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1110 if( c=='\n' ) j--;
1111 utf8_printf(p->out, "%.*s\n ", j, z);
1112 j = 0;
1113 nLine++;
1114 while( IsSpace(z[i+1]) ){ i++; }
1115 }
1116 }
1117 z[j] = 0;
1118 }
1119 utf8_printf(p->out, "%s;\n", z);
1120 sqlite3_free(z);
1121 break;
1122 }
1123 case MODE_List: {
1124 if( p->cnt++==0 && p->showHeader ){
1125 for(i=0; i<nArg; i++){
1126 utf8_printf(p->out,"%s%s",azCol[i],
1127 i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
1132 char *z = azArg[i];
1133 if( z==0 ) z = p->nullValue;
1134 utf8_printf(p->out, "%s", z);
1135 if( i<nArg-1 ){
1136 utf8_printf(p->out, "%s", p->colSeparator);
 
 
1137 }else{
1138 utf8_printf(p->out, "%s", p->rowSeparator);
1139 }
1140 }
1141 break;
@@ -1668,11 +1731,11 @@
1731 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1732 }
1733 if( str_in_array(zOp, azGoto) && p2op<p->nIndent
1734 && (abYield[p2op] || sqlite3_column_int(pSql, 2))
1735 ){
1736 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1737 }
1738 }
1739
1740 p->iIndent = 0;
1741 sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
1749 sqlite3_free(p->aiIndent);
1750 p->aiIndent = 0;
1751 p->nIndent = 0;
1752 p->iIndent = 0;
1753 }
1754
1755 /*
1756 ** Disable and restore .wheretrace and .selecttrace settings.
1757 */
1758 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1759 extern int sqlite3SelectTrace;
1760 static int savedSelectTrace;
1761 #endif
1762 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1763 extern int sqlite3WhereTrace;
1764 static int savedWhereTrace;
1765 #endif
1766 static void disable_debug_trace_modes(void){
1767 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1768 savedSelectTrace = sqlite3SelectTrace;
1769 sqlite3SelectTrace = 0;
1770 #endif
1771 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1772 savedWhereTrace = sqlite3WhereTrace;
1773 sqlite3WhereTrace = 0;
1774 #endif
1775 }
1776 static void restore_debug_trace_modes(void){
1777 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1778 sqlite3SelectTrace = savedSelectTrace;
1779 #endif
1780 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1781 sqlite3WhereTrace = savedWhereTrace;
1782 #endif
1783 }
1784
1785 /*
1786 ** Run a prepared statement
1787 */
1788 static void exec_prepared_stmt(
1789 ShellState *pArg, /* Pointer to ShellState */
1790 sqlite3_stmt *pStmt, /* Statment to run */
1791 int (*xCallback)(void*,int,char**,char**,int*) /* Callback function */
1792 ){
1793 int rc;
1794
1795 /* perform the first step. this will tell us if we
1796 ** have a result set or not and how wide it is.
1797 */
1798 rc = sqlite3_step(pStmt);
1799 /* if we have a result set... */
1800 if( SQLITE_ROW == rc ){
1801 /* if we have a callback... */
1802 if( xCallback ){
1803 /* allocate space for col name ptr, value ptr, and type */
1804 int nCol = sqlite3_column_count(pStmt);
1805 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1806 if( !pData ){
1807 rc = SQLITE_NOMEM;
1808 }else{
1809 char **azCols = (char **)pData; /* Names of result columns */
1810 char **azVals = &azCols[nCol]; /* Results */
1811 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1812 int i, x;
1813 assert(sizeof(int) <= sizeof(char *));
1814 /* save off ptrs to column names */
1815 for(i=0; i<nCol; i++){
1816 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1817 }
1818 do{
1819 /* extract the data and data types */
1820 for(i=0; i<nCol; i++){
1821 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1822 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1823 azVals[i] = "";
1824 }else{
1825 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1826 }
1827 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1828 rc = SQLITE_NOMEM;
1829 break; /* from for */
1830 }
1831 } /* end for */
1832
1833 /* if data and types extracted successfully... */
1834 if( SQLITE_ROW == rc ){
1835 /* call the supplied callback with the result row data */
1836 if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1837 rc = SQLITE_ABORT;
1838 }else{
1839 rc = sqlite3_step(pStmt);
1840 }
1841 }
1842 } while( SQLITE_ROW == rc );
1843 sqlite3_free(pData);
1844 }
1845 }else{
1846 do{
1847 rc = sqlite3_step(pStmt);
1848 } while( rc == SQLITE_ROW );
1849 }
1850 }
1851 }
1852
1853 /*
1854 ** Execute a statement or set of statements. Print
1855 ** any result rows/columns depending on the current mode
1856 ** set via the supplied callback.
@@ -1714,10 +1875,11 @@
1875 if( pzErrMsg ){
1876 *pzErrMsg = NULL;
1877 }
1878
1879 while( zSql[0] && (SQLITE_OK == rc) ){
1880 static const char *zStmtSql;
1881 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1882 if( SQLITE_OK != rc ){
1883 if( pzErrMsg ){
1884 *pzErrMsg = save_err_msg(db);
1885 }
@@ -1726,28 +1888,30 @@
1888 /* this happens for a comment or white-space */
1889 zSql = zLeftover;
1890 while( IsSpace(zSql[0]) ) zSql++;
1891 continue;
1892 }
1893 zStmtSql = sqlite3_sql(pStmt);
1894 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
1895
1896 /* save off the prepared statment handle and reset row count */
1897 if( pArg ){
1898 pArg->pStmt = pStmt;
1899 pArg->cnt = 0;
1900 }
1901
1902 /* echo the sql statement if echo on */
1903 if( pArg && pArg->echoOn ){
 
1904 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1905 }
1906
1907 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1908 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
1909 sqlite3_stmt *pExplain;
1910 char *zEQP;
1911 disable_debug_trace_modes();
1912 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
1913 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1914 if( rc==SQLITE_OK ){
1915 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1916 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1917 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
1919 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1920 }
1921 }
1922 sqlite3_finalize(pExplain);
1923 sqlite3_free(zEQP);
1924 if( pArg->autoEQP>=2 ){
1925 /* Also do an EXPLAIN for ".eqp full" mode */
1926 zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
1927 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1928 if( rc==SQLITE_OK ){
1929 pArg->cMode = MODE_Explain;
1930 explain_data_prepare(pArg, pExplain);
1931 exec_prepared_stmt(pArg, pExplain, xCallback);
1932 explain_data_delete(pArg);
1933 }
1934 sqlite3_finalize(pExplain);
1935 sqlite3_free(zEQP);
1936 }
1937 restore_debug_trace_modes();
1938 }
1939
1940 if( pArg ){
1941 pArg->cMode = pArg->mode;
1942 if( pArg->autoExplain
1943 && sqlite3_column_count(pStmt)==8
1944 && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
1945 ){
1946 pArg->cMode = MODE_Explain;
1947 }
1948
1949 /* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
1951 if( pArg->cMode==MODE_Explain ){
1952 explain_data_prepare(pArg, pStmt);
1953 }
1954 }
1955
1956 exec_prepared_stmt(pArg, pStmt, xCallback);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1957 explain_data_delete(pArg);
1958
1959 /* print usage stats if stats on */
1960 if( pArg && pArg->statsOn ){
1961 display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
2141 ".dbinfo ?DB? Show status information about the database\n"
2142 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
2143 " If TABLE specified, only dump tables matching\n"
2144 " LIKE pattern TABLE.\n"
2145 ".echo on|off Turn command echo on or off\n"
2146 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
2147 ".exit Exit this program\n"
2148 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2149 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
2150 ".headers on|off Turn display of headers on or off\n"
2151 ".help Show this message\n"
2152 ".import FILE TABLE Import data from FILE into TABLE\n"
2153 ".indexes ?TABLE? Show names of all indexes\n"
2154 " If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
2180 ".quit Exit this program\n"
2181 ".read FILENAME Execute SQL in FILENAME\n"
2182 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
2183 ".save FILE Write in-memory database into FILE\n"
2184 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2185 ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n"
2186 " Add --indent for pretty-printing\n"
 
2187 ".separator COL ?ROW? Change the column separator and optionally the row\n"
2188 " separator for both the output mode and .import\n"
2189 #if defined(SQLITE_ENABLE_SESSION)
2190 ".session CMD ... Create or control sessions\n"
2191 #endif
@@ -2930,10 +3051,21 @@
3051 */
3052 static int shellNomemError(void){
3053 raw_printf(stderr, "Error: out of memory\n");
3054 return 1;
3055 }
3056
3057 /*
3058 ** Compare the string as a command-line option with either one or two
3059 ** initial "-" characters.
3060 */
3061 static int optionMatch(const char *zStr, const char *zOpt){
3062 if( zStr[0]!='-' ) return 0;
3063 zStr++;
3064 if( zStr[0]=='-' ) zStr++;
3065 return strcmp(zStr, zOpt)==0;
3066 }
3067
3068 /*
3069 ** If an input line begins with "." then invoke this routine to
3070 ** process that line.
3071 **
@@ -3179,13 +3311,17 @@
3311 }
3312 }else
3313
3314 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
3315 if( nArg==2 ){
3316 if( strcmp(azArg[1],"full")==0 ){
3317 p->autoEQP = 2;
3318 }else{
3319 p->autoEQP = booleanValue(azArg[1]);
3320 }
3321 }else{
3322 raw_printf(stderr, "Usage: .eqp on|off|full\n");
3323 rc = 1;
3324 }
3325 }else
3326
3327 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
3353
3354 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
3355 ShellState data;
3356 char *zErrMsg = 0;
3357 int doStats = 0;
 
 
 
 
 
 
3358 memcpy(&data, p, sizeof(data));
3359 data.showHeader = 0;
3360 data.cMode = data.mode = MODE_Semi;
3361 if( nArg==2 && optionMatch(azArg[1], "indent") ){
3362 data.cMode = data.mode = MODE_Pretty;
3363 nArg = 1;
3364 }
3365 if( nArg!=1 ){
3366 raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
3367 rc = 1;
3368 goto meta_command_exit;
3369 }
3370 open_db(p, 0);
3371 rc = sqlite3_exec(p->db,
3372 "SELECT sql FROM"
3373 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3374 " FROM sqlite_master UNION ALL"
3375 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
4000 char *zErrMsg = 0;
4001 open_db(p, 0);
4002 memcpy(&data, p, sizeof(data));
4003 data.showHeader = 0;
4004 data.cMode = data.mode = MODE_Semi;
4005 if( nArg>=2 && optionMatch(azArg[1], "indent") ){
4006 data.cMode = data.mode = MODE_Pretty;
4007 nArg--;
4008 if( nArg==2 ) azArg[1] = azArg[2];
4009 }
4010 if( nArg==2 && azArg[1][0]!='-' ){
4011 int i;
4012 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
4013 if( strcmp(azArg[1],"sqlite_master")==0 ){
4014 char *new_argv[2], *new_colv[2];
4015 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
4060 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
4061 "ORDER BY rowid",
4062 callback, &data, &zErrMsg
4063 );
4064 }else{
4065 raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
4066 rc = 1;
4067 goto meta_command_exit;
4068 }
4069 if( zErrMsg ){
4070 utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
4078 }
4079 }else
4080
4081 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
4082 if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
 
4083 sqlite3SelectTrace = integerValue(azArg[1]);
4084 }else
4085 #endif
4086
4087 #if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
4337 sqlite3_free(zCmd);
4338 if( x ) raw_printf(stderr, "System command returns %d\n", x);
4339 }else
4340
4341 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
4342 static const char *azBool[] = { "off", "on", "full", "unk" };
4343 int i;
4344 if( nArg!=1 ){
4345 raw_printf(stderr, "Usage: .show\n");
4346 rc = 1;
4347 goto meta_command_exit;
4348 }
4349 utf8_printf(p->out, "%12.12s: %s\n","echo", azBool[p->echoOn!=0]);
4350 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
4351 utf8_printf(p->out, "%12.12s: %s\n","explain",
4352 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4353 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
4354 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
4355 utf8_printf(p->out, "%12.12s: ", "nullvalue");
4356 output_c_string(p->out, p->nullValue);
4357 raw_printf(p->out, "\n");
4358 utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
4361 output_c_string(p->out, p->colSeparator);
4362 raw_printf(p->out, "\n");
4363 utf8_printf(p->out,"%12.12s: ", "rowseparator");
4364 output_c_string(p->out, p->rowSeparator);
4365 raw_printf(p->out, "\n");
4366 utf8_printf(p->out, "%12.12s: %s\n","stats", azBool[p->statsOn!=0]);
4367 utf8_printf(p->out, "%12.12s: ", "width");
4368 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
4369 raw_printf(p->out, "%d ", p->colWidth[i]);
4370 }
4371 raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
4776 }
4777 }else
4778
4779 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
4780 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
 
4781 sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
4782 }else
4783 #endif
4784
4785 if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
5443 data.showHeader = 0;
5444 }else if( strcmp(z,"-echo")==0 ){
5445 data.echoOn = 1;
5446 }else if( strcmp(z,"-eqp")==0 ){
5447 data.autoEQP = 1;
5448 }else if( strcmp(z,"-eqpfull")==0 ){
5449 data.autoEQP = 2;
5450 }else if( strcmp(z,"-stats")==0 ){
5451 data.statsOn = 1;
5452 }else if( strcmp(z,"-scanstats")==0 ){
5453 data.scanstatsOn = 1;
5454 }else if( strcmp(z,"-backslash")==0 ){
5455
+2734 -1777
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
3838
**
3939
*/
4040
#ifndef _SQLITEINT_H_
4141
#define _SQLITEINT_H_
4242
43
+/* Special Comments:
44
+**
45
+** Some comments have special meaning to the tools that measure test
46
+** coverage:
47
+**
48
+** NO_TEST - The branches on this line are not
49
+** measured by branch coverage. This is
50
+** used on lines of code that actually
51
+** implement parts of coverage testing.
52
+**
53
+** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54
+** and the correct answer is still obtained,
55
+** though perhaps more slowly.
56
+**
57
+** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58
+** and the correct answer is still obtained,
59
+** though perhaps more slowly.
60
+**
61
+** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62
+** that would be harmless and undetectable
63
+** if it did occur.
64
+**
65
+** In all cases, the special comment must be enclosed in the usual
66
+** slash-asterisk...asterisk-slash comment marks, with no spaces between the
67
+** asterisks and the comment text.
68
+*/
69
+
4370
/*
4471
** Make sure that rand_s() is available on Windows systems with MSVC 2005
4572
** or higher.
4673
*/
4774
#if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
336363
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337364
** [sqlite_version()] and [sqlite_source_id()].
338365
*/
339366
#define SQLITE_VERSION "3.13.0"
340367
#define SQLITE_VERSION_NUMBER 3013000
341
-#define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
368
+#define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
342369
343370
/*
344371
** CAPI3REF: Run-Time Library Version Numbers
345372
** KEYWORDS: sqlite3_version, sqlite3_sourceid
346373
**
@@ -2155,16 +2182,34 @@
21552182
** The second parameter is a pointer to an integer into which
21562183
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
21572184
** following this call. The second parameter may be a NULL pointer, in
21582185
** which case the new setting is not reported back. </dd>
21592186
**
2187
+** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2188
+** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2189
+** interface independently of the [load_extension()] SQL function.
2190
+** The [sqlite3_enable_load_extension()] API enables or disables both the
2191
+** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2192
+** There should be two additional arguments.
2193
+** When the first argument to this interface is 1, then only the C-API is
2194
+** enabled and the SQL function remains disabled. If the first argment to
2195
+** this interface is 0, then both the C-API and the SQL function are disabled.
2196
+** If the first argument is -1, then no changes are made to state of either the
2197
+** C-API or the SQL function.
2198
+** The second parameter is a pointer to an integer into which
2199
+** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2200
+** is disabled or enabled following this call. The second parameter may
2201
+** be a NULL pointer, in which case the new setting is not reported back.
2202
+** </dd>
2203
+**
21602204
** </dl>
21612205
*/
21622206
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
21632207
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
21642208
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
21652209
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2210
+#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
21662211
21672212
21682213
/*
21692214
** CAPI3REF: Enable Or Disable Extended Result Codes
21702215
** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
56975742
** fill *pzErrMsg with error message text stored in memory
56985743
** obtained from [sqlite3_malloc()]. The calling function
56995744
** should free this memory by calling [sqlite3_free()].
57005745
**
57015746
** ^Extension loading must be enabled using
5702
-** [sqlite3_enable_load_extension()] prior to calling this API,
5747
+** [sqlite3_enable_load_extension()] or
5748
+** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5749
+** prior to calling this API,
57035750
** otherwise an error will be returned.
5751
+**
5752
+** <b>Security warning:</b> It is recommended that the
5753
+** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5754
+** interface. The use of the [sqlite3_enable_load_extension()] interface
5755
+** should be avoided. This will keep the SQL function [load_extension()]
5756
+** disabled and prevent SQL injections from giving attackers
5757
+** access to extension loading capabilities.
57045758
**
57055759
** See also the [load_extension() SQL function].
57065760
*/
57075761
SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
57085762
sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
57225776
**
57235777
** ^Extension loading is off by default.
57245778
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
57255779
** to turn extension loading on and call it with onoff==0 to turn
57265780
** it back off again.
5781
+**
5782
+** ^This interface enables or disables both the C-API
5783
+** [sqlite3_load_extension()] and the SQL function [load_extension()].
5784
+** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5785
+** to enable or disable only the C-API.
5786
+**
5787
+** <b>Security warning:</b> It is recommended that extension loading
5788
+** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5789
+** rather than this interface, so the [load_extension()] SQL function
5790
+** remains disabled. This will prevent SQL injections from giving attackers
5791
+** access to extension loading capabilities.
57275792
*/
57285793
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
57295794
57305795
/*
57315796
** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
83048369
83058370
/*
83068371
** CAPI3REF: Start a read transaction on an historical snapshot
83078372
** EXPERIMENTAL
83088373
**
8309
-** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8310
-** read transaction that is currently open on schema S of
8311
-** [database connection] D so that it refers to historical [snapshot] P.
8374
+** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8375
+** read transaction for schema S of
8376
+** [database connection] D such that the read transaction
8377
+** refers to historical [snapshot] P, rather than the most
8378
+** recent change to the database.
83128379
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
83138380
** or an appropriate [error code] if it fails.
83148381
**
83158382
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8316
-** the first operation, apart from other sqlite3_snapshot_open() calls,
8317
-** following the [BEGIN] that starts a new read transaction.
8318
-** ^A [snapshot] will fail to open if it has been overwritten by a
8383
+** the first operation following the [BEGIN] that takes the schema S
8384
+** out of [autocommit mode].
8385
+** ^In other words, schema S must not currently be in
8386
+** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8387
+** database connection D must be out of [autocommit mode].
8388
+** ^A [snapshot] will fail to open if it has been overwritten by a
83198389
** [checkpoint].
8320
-** ^A [snapshot] will fail to open if the database connection D has not
8321
-** previously completed at least one read operation against the database
8322
-** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
8390
+** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8391
+** database connection D does not know that the database file for
8392
+** schema S is in [WAL mode]. A database connection might not know
8393
+** that the database file is in [WAL mode] if there has been no prior
8394
+** I/O on that database connection, or if the database entered [WAL mode]
8395
+** after the most recent I/O on the database connection.)^
8396
+** (Hint: Run "[PRAGMA application_id]" against a newly opened
83238397
** database connection in order to make it ready to use snapshots.)
83248398
**
83258399
** The [sqlite3_snapshot_open()] interface is only available when the
83268400
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
83278401
*/
@@ -8341,10 +8415,37 @@
83418415
**
83428416
** The [sqlite3_snapshot_free()] interface is only available when the
83438417
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
83448418
*/
83458419
SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8420
+
8421
+/*
8422
+** CAPI3REF: Compare the ages of two snapshot handles.
8423
+** EXPERIMENTAL
8424
+**
8425
+** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8426
+** of two valid snapshot handles.
8427
+**
8428
+** If the two snapshot handles are not associated with the same database
8429
+** file, the result of the comparison is undefined.
8430
+**
8431
+** Additionally, the result of the comparison is only valid if both of the
8432
+** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8433
+** last time the wal file was deleted. The wal file is deleted when the
8434
+** database is changed back to rollback mode or when the number of database
8435
+** clients drops to zero. If either snapshot handle was obtained before the
8436
+** wal file was last deleted, the value returned by this function
8437
+** is undefined.
8438
+**
8439
+** Otherwise, this API returns a negative value if P1 refers to an older
8440
+** snapshot than P2, zero if the two handles refer to the same database
8441
+** snapshot, and a positive value if P1 is a newer snapshot than P2.
8442
+*/
8443
+SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8444
+ sqlite3_snapshot *p1,
8445
+ sqlite3_snapshot *p2
8446
+);
83468447
83478448
/*
83488449
** Undo the hack that converts floating point types to integer for
83498450
** builds on processors without floating point support.
83508451
*/
@@ -8476,11 +8577,11 @@
84768577
#endif /* ifndef _SQLITE3RTREE_H_ */
84778578
84788579
/******** End of sqlite3rtree.h *********/
84798580
/******** Begin file sqlite3session.h *********/
84808581
8481
-#ifndef __SQLITESESSION_H_
8582
+#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
84828583
#define __SQLITESESSION_H_ 1
84838584
84848585
/*
84858586
** Make sure we can call this stuff from C++.
84868587
*/
@@ -9750,11 +9851,11 @@
97509851
*/
97519852
#if 0
97529853
}
97539854
#endif
97549855
9755
-#endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
9856
+#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
97569857
97579858
/******** End of sqlite3session.h *********/
97589859
/******** Begin file fts5.h *********/
97599860
/*
97609861
** 2014 May 31
@@ -9898,15 +9999,17 @@
98989999
** of the current query. Specifically, a query equivalent to:
989910000
**
990010001
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
990110002
**
990210003
** with $p set to a phrase equivalent to the phrase iPhrase of the
9903
-** current query is executed. For each row visited, the callback function
9904
-** passed as the fourth argument is invoked. The context and API objects
9905
-** passed to the callback function may be used to access the properties of
9906
-** each matched row. Invoking Api.xUserData() returns a copy of the pointer
9907
-** passed as the third argument to pUserData.
10004
+** current query is executed. Any column filter that applies to
10005
+** phrase iPhrase of the current query is included in $p. For each
10006
+** row visited, the callback function passed as the fourth argument
10007
+** is invoked. The context and API objects passed to the callback
10008
+** function may be used to access the properties of each matched row.
10009
+** Invoking Api.xUserData() returns a copy of the pointer passed as
10010
+** the third argument to pUserData.
990810011
**
990910012
** If the callback function returns any value other than SQLITE_OK, the
991010013
** query is abandoned and the xQueryPhrase function returns immediately.
991110014
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
991210015
** Otherwise, the error code is propagated upwards.
@@ -10814,11 +10917,11 @@
1081410917
**
1081510918
** When doing coverage testing ALWAYS and NEVER are hard-coded to
1081610919
** be true and false so that the unreachable code they specify will
1081710920
** not be counted as untested code.
1081810921
*/
10819
-#if defined(SQLITE_COVERAGE_TEST)
10922
+#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
1082010923
# define ALWAYS(X) (1)
1082110924
# define NEVER(X) (0)
1082210925
#elif !defined(NDEBUG)
1082310926
# define ALWAYS(X) ((X)?1:(assert(0),0))
1082410927
# define NEVER(X) ((X)?(assert(0),1):0)
@@ -11019,80 +11122,80 @@
1101911122
#define TK_LP 22
1102011123
#define TK_RP 23
1102111124
#define TK_AS 24
1102211125
#define TK_WITHOUT 25
1102311126
#define TK_COMMA 26
11024
-#define TK_ID 27
11025
-#define TK_INDEXED 28
11026
-#define TK_ABORT 29
11027
-#define TK_ACTION 30
11028
-#define TK_AFTER 31
11029
-#define TK_ANALYZE 32
11030
-#define TK_ASC 33
11031
-#define TK_ATTACH 34
11032
-#define TK_BEFORE 35
11033
-#define TK_BY 36
11034
-#define TK_CASCADE 37
11035
-#define TK_CAST 38
11036
-#define TK_COLUMNKW 39
11037
-#define TK_CONFLICT 40
11038
-#define TK_DATABASE 41
11039
-#define TK_DESC 42
11040
-#define TK_DETACH 43
11041
-#define TK_EACH 44
11042
-#define TK_FAIL 45
11043
-#define TK_FOR 46
11044
-#define TK_IGNORE 47
11045
-#define TK_INITIALLY 48
11046
-#define TK_INSTEAD 49
11047
-#define TK_LIKE_KW 50
11048
-#define TK_MATCH 51
11049
-#define TK_NO 52
11050
-#define TK_KEY 53
11051
-#define TK_OF 54
11052
-#define TK_OFFSET 55
11053
-#define TK_PRAGMA 56
11054
-#define TK_RAISE 57
11055
-#define TK_RECURSIVE 58
11056
-#define TK_REPLACE 59
11057
-#define TK_RESTRICT 60
11058
-#define TK_ROW 61
11059
-#define TK_TRIGGER 62
11060
-#define TK_VACUUM 63
11061
-#define TK_VIEW 64
11062
-#define TK_VIRTUAL 65
11063
-#define TK_WITH 66
11064
-#define TK_REINDEX 67
11065
-#define TK_RENAME 68
11066
-#define TK_CTIME_KW 69
11067
-#define TK_ANY 70
11068
-#define TK_OR 71
11069
-#define TK_AND 72
11070
-#define TK_IS 73
11071
-#define TK_BETWEEN 74
11072
-#define TK_IN 75
11073
-#define TK_ISNULL 76
11074
-#define TK_NOTNULL 77
11075
-#define TK_NE 78
11076
-#define TK_EQ 79
11077
-#define TK_GT 80
11078
-#define TK_LE 81
11079
-#define TK_LT 82
11080
-#define TK_GE 83
11081
-#define TK_ESCAPE 84
11082
-#define TK_BITAND 85
11083
-#define TK_BITOR 86
11084
-#define TK_LSHIFT 87
11085
-#define TK_RSHIFT 88
11086
-#define TK_PLUS 89
11087
-#define TK_MINUS 90
11088
-#define TK_STAR 91
11089
-#define TK_SLASH 92
11090
-#define TK_REM 93
11091
-#define TK_CONCAT 94
11092
-#define TK_COLLATE 95
11093
-#define TK_BITNOT 96
11127
+#define TK_OR 27
11128
+#define TK_AND 28
11129
+#define TK_IS 29
11130
+#define TK_MATCH 30
11131
+#define TK_LIKE_KW 31
11132
+#define TK_BETWEEN 32
11133
+#define TK_IN 33
11134
+#define TK_ISNULL 34
11135
+#define TK_NOTNULL 35
11136
+#define TK_NE 36
11137
+#define TK_EQ 37
11138
+#define TK_GT 38
11139
+#define TK_LE 39
11140
+#define TK_LT 40
11141
+#define TK_GE 41
11142
+#define TK_ESCAPE 42
11143
+#define TK_BITAND 43
11144
+#define TK_BITOR 44
11145
+#define TK_LSHIFT 45
11146
+#define TK_RSHIFT 46
11147
+#define TK_PLUS 47
11148
+#define TK_MINUS 48
11149
+#define TK_STAR 49
11150
+#define TK_SLASH 50
11151
+#define TK_REM 51
11152
+#define TK_CONCAT 52
11153
+#define TK_COLLATE 53
11154
+#define TK_BITNOT 54
11155
+#define TK_ID 55
11156
+#define TK_INDEXED 56
11157
+#define TK_ABORT 57
11158
+#define TK_ACTION 58
11159
+#define TK_AFTER 59
11160
+#define TK_ANALYZE 60
11161
+#define TK_ASC 61
11162
+#define TK_ATTACH 62
11163
+#define TK_BEFORE 63
11164
+#define TK_BY 64
11165
+#define TK_CASCADE 65
11166
+#define TK_CAST 66
11167
+#define TK_COLUMNKW 67
11168
+#define TK_CONFLICT 68
11169
+#define TK_DATABASE 69
11170
+#define TK_DESC 70
11171
+#define TK_DETACH 71
11172
+#define TK_EACH 72
11173
+#define TK_FAIL 73
11174
+#define TK_FOR 74
11175
+#define TK_IGNORE 75
11176
+#define TK_INITIALLY 76
11177
+#define TK_INSTEAD 77
11178
+#define TK_NO 78
11179
+#define TK_KEY 79
11180
+#define TK_OF 80
11181
+#define TK_OFFSET 81
11182
+#define TK_PRAGMA 82
11183
+#define TK_RAISE 83
11184
+#define TK_RECURSIVE 84
11185
+#define TK_REPLACE 85
11186
+#define TK_RESTRICT 86
11187
+#define TK_ROW 87
11188
+#define TK_TRIGGER 88
11189
+#define TK_VACUUM 89
11190
+#define TK_VIEW 90
11191
+#define TK_VIRTUAL 91
11192
+#define TK_WITH 92
11193
+#define TK_REINDEX 93
11194
+#define TK_RENAME 94
11195
+#define TK_CTIME_KW 95
11196
+#define TK_ANY 96
1109411197
#define TK_STRING 97
1109511198
#define TK_JOIN_KW 98
1109611199
#define TK_CONSTRAINT 99
1109711200
#define TK_DEFAULT 100
1109811201
#define TK_NULL 101
@@ -12103,11 +12206,11 @@
1210312206
** as an instance of the following structure:
1210412207
*/
1210512208
struct VdbeOp {
1210612209
u8 opcode; /* What operation to perform */
1210712210
signed char p4type; /* One of the P4_xxx constants for p4 */
12108
- u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
12211
+ u8 notUsed1;
1210912212
u8 p5; /* Fifth parameter is an unsigned character */
1211012213
int p1; /* First operand */
1211112214
int p2; /* Second parameter (often the jump destination) */
1211212215
int p3; /* The third parameter */
1211312216
union p4union { /* fourth parameter */
@@ -12246,157 +12349,156 @@
1224612349
#define OP_Vacuum 10
1224712350
#define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
1224812351
#define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
1224912352
#define OP_Goto 13
1225012353
#define OP_Gosub 14
12251
-#define OP_Return 15
12252
-#define OP_InitCoroutine 16
12253
-#define OP_EndCoroutine 17
12254
-#define OP_Yield 18
12354
+#define OP_InitCoroutine 15
12355
+#define OP_Yield 16
12356
+#define OP_MustBeInt 17
12357
+#define OP_Jump 18
1225512358
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12256
-#define OP_HaltIfNull 20 /* synopsis: if r[P3]=null halt */
12257
-#define OP_Halt 21
12258
-#define OP_Integer 22 /* synopsis: r[P2]=P1 */
12259
-#define OP_Int64 23 /* synopsis: r[P2]=P4 */
12260
-#define OP_String 24 /* synopsis: r[P2]='P4' (len=P1) */
12261
-#define OP_Null 25 /* synopsis: r[P2..P3]=NULL */
12262
-#define OP_SoftNull 26 /* synopsis: r[P1]=NULL */
12263
-#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
12264
-#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
12265
-#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
12266
-#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12267
-#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
12268
-#define OP_IntCopy 32 /* synopsis: r[P2]=r[P1] */
12269
-#define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */
12270
-#define OP_CollSeq 34
12271
-#define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */
12272
-#define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */
12273
-#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
12274
-#define OP_MustBeInt 38
12275
-#define OP_RealAffinity 39
12276
-#define OP_Cast 40 /* synopsis: affinity(r[P1]) */
12277
-#define OP_Permutation 41
12278
-#define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12279
-#define OP_Jump 43
12280
-#define OP_Once 44
12281
-#define OP_If 45
12282
-#define OP_IfNot 46
12283
-#define OP_Column 47 /* synopsis: r[P3]=PX */
12284
-#define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */
12285
-#define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12286
-#define OP_Count 50 /* synopsis: r[P2]=count() */
12287
-#define OP_ReadCookie 51
12288
-#define OP_SetCookie 52
12289
-#define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */
12290
-#define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */
12291
-#define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */
12292
-#define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */
12293
-#define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */
12294
-#define OP_SorterOpen 58
12295
-#define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12296
-#define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */
12297
-#define OP_Close 61
12298
-#define OP_ColumnsUsed 62
12299
-#define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */
12300
-#define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */
12301
-#define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */
12302
-#define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */
12303
-#define OP_NoConflict 67 /* synopsis: key=r[P3@P4] */
12304
-#define OP_NotFound 68 /* synopsis: key=r[P3@P4] */
12305
-#define OP_Found 69 /* synopsis: key=r[P3@P4] */
12306
-#define OP_NotExists 70 /* synopsis: intkey=r[P3] */
12307
-#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12308
-#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12309
-#define OP_Sequence 73 /* synopsis: r[P2]=cursor[P1].ctr++ */
12310
-#define OP_NewRowid 74 /* synopsis: r[P2]=rowid */
12311
-#define OP_Insert 75 /* synopsis: intkey=r[P3] data=r[P2] */
12312
-#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12313
-#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12314
-#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12315
-#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12316
-#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12317
-#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12318
-#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12319
-#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12320
-#define OP_InsertInt 84 /* synopsis: intkey=P3 data=r[P2] */
12321
-#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12322
-#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12323
-#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12324
-#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12325
-#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12326
-#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12327
-#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12328
-#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12329
-#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12330
-#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12331
-#define OP_Delete 95
12332
-#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12359
+#define OP_Once 20
12360
+#define OP_If 21
12361
+#define OP_IfNot 22
12362
+#define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12363
+#define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12364
+#define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12365
+#define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12366
+#define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12367
+#define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12368
+#define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12369
+#define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12370
+#define OP_Found 31 /* synopsis: key=r[P3@P4] */
12371
+#define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12372
+#define OP_Last 33
12373
+#define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12374
+#define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12375
+#define OP_Ne 36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12376
+#define OP_Eq 37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12377
+#define OP_Gt 38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12378
+#define OP_Le 39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12379
+#define OP_Lt 40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12380
+#define OP_Ge 41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12381
+#define OP_SorterSort 42
12382
+#define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12383
+#define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12384
+#define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12385
+#define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12386
+#define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12387
+#define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12388
+#define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12389
+#define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12390
+#define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12391
+#define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12392
+#define OP_Sort 53
12393
+#define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12394
+#define OP_Rewind 55
12395
+#define OP_IdxLE 56 /* synopsis: key=r[P3@P4] */
12396
+#define OP_IdxGT 57 /* synopsis: key=r[P3@P4] */
12397
+#define OP_IdxLT 58 /* synopsis: key=r[P3@P4] */
12398
+#define OP_IdxGE 59 /* synopsis: key=r[P3@P4] */
12399
+#define OP_RowSetRead 60 /* synopsis: r[P3]=rowset(P1) */
12400
+#define OP_RowSetTest 61 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12401
+#define OP_Program 62
12402
+#define OP_FkIfZero 63 /* synopsis: if fkctr[P1]==0 goto P2 */
12403
+#define OP_IfPos 64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12404
+#define OP_IfNotZero 65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12405
+#define OP_DecrJumpZero 66 /* synopsis: if (--r[P1])==0 goto P2 */
12406
+#define OP_IncrVacuum 67
12407
+#define OP_VNext 68
12408
+#define OP_Init 69 /* synopsis: Start at P2 */
12409
+#define OP_Return 70
12410
+#define OP_EndCoroutine 71
12411
+#define OP_HaltIfNull 72 /* synopsis: if r[P3]=null halt */
12412
+#define OP_Halt 73
12413
+#define OP_Integer 74 /* synopsis: r[P2]=P1 */
12414
+#define OP_Int64 75 /* synopsis: r[P2]=P4 */
12415
+#define OP_String 76 /* synopsis: r[P2]='P4' (len=P1) */
12416
+#define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
12417
+#define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
12418
+#define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
12419
+#define OP_Variable 80 /* synopsis: r[P2]=parameter(P1,P4) */
12420
+#define OP_Move 81 /* synopsis: r[P2@P3]=r[P1@P3] */
12421
+#define OP_Copy 82 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12422
+#define OP_SCopy 83 /* synopsis: r[P2]=r[P1] */
12423
+#define OP_IntCopy 84 /* synopsis: r[P2]=r[P1] */
12424
+#define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */
12425
+#define OP_CollSeq 86
12426
+#define OP_Function0 87 /* synopsis: r[P3]=func(r[P2@P5]) */
12427
+#define OP_Function 88 /* synopsis: r[P3]=func(r[P2@P5]) */
12428
+#define OP_AddImm 89 /* synopsis: r[P1]=r[P1]+P2 */
12429
+#define OP_RealAffinity 90
12430
+#define OP_Cast 91 /* synopsis: affinity(r[P1]) */
12431
+#define OP_Permutation 92
12432
+#define OP_Compare 93 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12433
+#define OP_Column 94 /* synopsis: r[P3]=PX */
12434
+#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */
12435
+#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
1233312436
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12334
-#define OP_ResetCount 98
12335
-#define OP_SorterCompare 99 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12336
-#define OP_SorterData 100 /* synopsis: r[P2]=data */
12337
-#define OP_RowKey 101 /* synopsis: r[P2]=key */
12338
-#define OP_RowData 102 /* synopsis: r[P2]=data */
12339
-#define OP_Rowid 103 /* synopsis: r[P2]=rowid */
12340
-#define OP_NullRow 104
12341
-#define OP_Last 105
12342
-#define OP_SorterSort 106
12343
-#define OP_Sort 107
12344
-#define OP_Rewind 108
12345
-#define OP_SorterInsert 109
12346
-#define OP_IdxInsert 110 /* synopsis: key=r[P2] */
12347
-#define OP_IdxDelete 111 /* synopsis: key=r[P2@P3] */
12348
-#define OP_Seek 112 /* synopsis: Move P3 to P1.rowid */
12349
-#define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */
12350
-#define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */
12351
-#define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */
12352
-#define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */
12353
-#define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */
12354
-#define OP_Destroy 118
12355
-#define OP_Clear 119
12356
-#define OP_ResetSorter 120
12357
-#define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */
12358
-#define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */
12359
-#define OP_ParseSchema 123
12360
-#define OP_LoadAnalysis 124
12361
-#define OP_DropTable 125
12362
-#define OP_DropIndex 126
12363
-#define OP_DropTrigger 127
12364
-#define OP_IntegrityCk 128
12365
-#define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */
12366
-#define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */
12367
-#define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12368
-#define OP_Program 132
12437
+#define OP_Count 98 /* synopsis: r[P2]=count() */
12438
+#define OP_ReadCookie 99
12439
+#define OP_SetCookie 100
12440
+#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
12441
+#define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
12442
+#define OP_OpenWrite 103 /* synopsis: root=P2 iDb=P3 */
12443
+#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2 */
12444
+#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2 */
12445
+#define OP_SorterOpen 106
12446
+#define OP_SequenceTest 107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12447
+#define OP_OpenPseudo 108 /* synopsis: P3 columns in r[P2] */
12448
+#define OP_Close 109
12449
+#define OP_ColumnsUsed 110
12450
+#define OP_Sequence 111 /* synopsis: r[P2]=cursor[P1].ctr++ */
12451
+#define OP_NewRowid 112 /* synopsis: r[P2]=rowid */
12452
+#define OP_Insert 113 /* synopsis: intkey=r[P3] data=r[P2] */
12453
+#define OP_InsertInt 114 /* synopsis: intkey=P3 data=r[P2] */
12454
+#define OP_Delete 115
12455
+#define OP_ResetCount 116
12456
+#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12457
+#define OP_SorterData 118 /* synopsis: r[P2]=data */
12458
+#define OP_RowKey 119 /* synopsis: r[P2]=key */
12459
+#define OP_RowData 120 /* synopsis: r[P2]=data */
12460
+#define OP_Rowid 121 /* synopsis: r[P2]=rowid */
12461
+#define OP_NullRow 122
12462
+#define OP_SorterInsert 123
12463
+#define OP_IdxInsert 124 /* synopsis: key=r[P2] */
12464
+#define OP_IdxDelete 125 /* synopsis: key=r[P2@P3] */
12465
+#define OP_Seek 126 /* synopsis: Move P3 to P1.rowid */
12466
+#define OP_IdxRowid 127 /* synopsis: r[P2]=rowid */
12467
+#define OP_Destroy 128
12468
+#define OP_Clear 129
12469
+#define OP_ResetSorter 130
12470
+#define OP_CreateIndex 131 /* synopsis: r[P2]=root iDb=P1 */
12471
+#define OP_CreateTable 132 /* synopsis: r[P2]=root iDb=P1 */
1236912472
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12370
-#define OP_Param 134
12371
-#define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
12372
-#define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
12373
-#define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12374
-#define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12375
-#define OP_OffsetLimit 139 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12376
-#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12377
-#define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
12378
-#define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
12379
-#define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12380
-#define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12381
-#define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
12382
-#define OP_IncrVacuum 146
12383
-#define OP_Expire 147
12384
-#define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */
12385
-#define OP_VBegin 149
12386
-#define OP_VCreate 150
12387
-#define OP_VDestroy 151
12388
-#define OP_VOpen 152
12389
-#define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */
12390
-#define OP_VNext 154
12473
+#define OP_ParseSchema 134
12474
+#define OP_LoadAnalysis 135
12475
+#define OP_DropTable 136
12476
+#define OP_DropIndex 137
12477
+#define OP_DropTrigger 138
12478
+#define OP_IntegrityCk 139
12479
+#define OP_RowSetAdd 140 /* synopsis: rowset(P1)=r[P2] */
12480
+#define OP_Param 141
12481
+#define OP_FkCounter 142 /* synopsis: fkctr[P1]+=P2 */
12482
+#define OP_MemMax 143 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12483
+#define OP_OffsetLimit 144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12484
+#define OP_AggStep0 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12485
+#define OP_AggStep 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12486
+#define OP_AggFinal 147 /* synopsis: accum=r[P1] N=P2 */
12487
+#define OP_Expire 148
12488
+#define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */
12489
+#define OP_VBegin 150
12490
+#define OP_VCreate 151
12491
+#define OP_VDestroy 152
12492
+#define OP_VOpen 153
12493
+#define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */
1239112494
#define OP_VRename 155
1239212495
#define OP_Pagecount 156
1239312496
#define OP_MaxPgcnt 157
12394
-#define OP_Init 158 /* synopsis: Start at P2 */
12395
-#define OP_CursorHint 159
12396
-#define OP_Noop 160
12397
-#define OP_Explain 161
12497
+#define OP_CursorHint 158
12498
+#define OP_Noop 159
12499
+#define OP_Explain 160
1239812500
1239912501
/* Properties such as "out2" or "jump" that are specified in
1240012502
** comments following the "case" for each opcode in the vdbe.c
1240112503
** are encoded into bitvectors as follows:
1240212504
*/
@@ -12406,30 +12508,38 @@
1240612508
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
1240712509
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1240812510
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1240912511
#define OPFLG_INITIALIZER {\
1241012512
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12411
-/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02,\
12412
-/* 16 */ 0x01, 0x02, 0x03, 0x12, 0x08, 0x00, 0x10, 0x10,\
12413
-/* 24 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
12414
-/* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\
12415
-/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
12416
-/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12417
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\
12418
-/* 64 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26,\
12419
-/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
12420
-/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
12421
-/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
12422
-/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12423
-/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
12424
-/* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
12425
-/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12426
-/* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
12427
-/* 136 */ 0x01, 0x04, 0x03, 0x1a, 0x03, 0x03, 0x03, 0x00,\
12428
-/* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
12429
-/* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
12430
-/* 160 */ 0x00, 0x00,}
12513
+/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12514
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12515
+/* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12516
+/* 32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12517
+/* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12518
+/* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12519
+/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
12520
+/* 64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
12521
+/* 72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
12522
+/* 80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
12523
+/* 88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
12524
+/* 96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12525
+/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12526
+/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12527
+/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
12528
+/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12529
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
12530
+/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12531
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12532
+/* 160 */ 0x00,}
12533
+
12534
+/* The sqlite3P2Values() routine is able to run faster if it knows
12535
+** the value of the largest JUMP opcode. The smaller the maximum
12536
+** JUMP opcode the better, so the mkopcodeh.tcl script that
12537
+** generated this include file strives to group all JUMP opcodes
12538
+** together near the beginning of the list.
12539
+*/
12540
+#define SQLITE_MX_JUMP_OPCODE 69 /* Maximum JUMP opcode */
1243112541
1243212542
/************** End of opcodes.h *********************************************/
1243312543
/************** Continuing where we left off in vdbe.h ***********************/
1243412544
1243512545
/*
@@ -12648,11 +12758,15 @@
1264812758
#define PAGER_LOCKINGMODE_QUERY -1
1264912759
#define PAGER_LOCKINGMODE_NORMAL 0
1265012760
#define PAGER_LOCKINGMODE_EXCLUSIVE 1
1265112761
1265212762
/*
12653
-** Numeric constants that encode the journalmode.
12763
+** Numeric constants that encode the journalmode.
12764
+**
12765
+** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
12766
+** are exposed in the API via the "PRAGMA journal_mode" command and
12767
+** therefore cannot be changed without a compatibility break.
1265412768
*/
1265512769
#define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
1265612770
#define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
1265712771
#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
1265812772
#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12780,15 @@
1266612780
#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
1266712781
#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
1266812782
1266912783
/*
1267012784
** Flags for sqlite3PagerSetFlags()
12785
+**
12786
+** Value constraints (enforced via assert()):
12787
+** PAGER_FULLFSYNC == SQLITE_FullFSync
12788
+** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
12789
+** PAGER_CACHE_SPILL == SQLITE_CacheSpill
1267112790
*/
1267212791
#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
1267312792
#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
1267412793
#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
1267512794
#define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12835,11 +12954,11 @@
1283512954
*/
1283612955
struct PgHdr {
1283712956
sqlite3_pcache_page *pPage; /* Pcache object page handle */
1283812957
void *pData; /* Page data */
1283912958
void *pExtra; /* Extra content */
12840
- PgHdr *pDirty; /* Transient list of dirty pages */
12959
+ PgHdr *pDirty; /* Transient list of dirty sorted by pgno */
1284112960
Pager *pPager; /* The pager this page is part of */
1284212961
Pgno pgno; /* Page number for this page */
1284312962
#ifdef SQLITE_CHECK_PAGES
1284412963
u32 pageHash; /* Hash of page content */
1284512964
#endif
@@ -12860,15 +12979,14 @@
1286012979
#define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
1286112980
#define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
1286212981
#define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
1286312982
#define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
1286412983
** writing this page to the database */
12865
-#define PGHDR_NEED_READ 0x010 /* Content is unread */
12866
-#define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
12867
-#define PGHDR_MMAP 0x040 /* This is an mmap page object */
12984
+#define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
12985
+#define PGHDR_MMAP 0x020 /* This is an mmap page object */
1286812986
12869
-#define PGHDR_WAL_APPEND 0x080 /* Appended to wal file */
12987
+#define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
1287012988
1287112989
/* Initialize and shutdown the page cache subsystem */
1287212990
SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
1287312991
SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
1287412992
@@ -12908,10 +13026,11 @@
1290813026
1290913027
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
1291013028
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
1291113029
SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
1291213030
SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
13031
+SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*);
1291313032
1291413033
/* Change a page number. Used by incr-vacuum. */
1291513034
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
1291613035
1291713036
/* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12945,10 +13064,15 @@
1294513064
** interface is only available if SQLITE_CHECK_PAGES is defined when the
1294613065
** library is built.
1294713066
*/
1294813067
SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
1294913068
#endif
13069
+
13070
+#if defined(SQLITE_DEBUG)
13071
+/* Check invariants on a PgHdr object */
13072
+SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*);
13073
+#endif
1295013074
1295113075
/* Set and get the suggested cache-size for the specified pager-cache.
1295213076
**
1295313077
** If no global maximum is configured, then the system attempts to limit
1295413078
** the total number of pages cached by purgeable pager-caches to the sum
@@ -12981,10 +13105,13 @@
1298113105
SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
1298213106
1298313107
/* Return the header size */
1298413108
SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
1298513109
SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
13110
+
13111
+/* Number of dirty pages as a percentage of the configured cache size */
13112
+SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*);
1298613113
1298713114
#endif /* _PCACHE_H_ */
1298813115
1298913116
/************** End of pcache.h **********************************************/
1299013117
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13338,11 @@
1321113338
SQLITE_PRIVATE int sqlite3OsInit(void);
1321213339
1321313340
/*
1321413341
** Functions for accessing sqlite3_file methods
1321513342
*/
13216
-SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
13343
+SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
1321713344
SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
1321813345
SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
1321913346
SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
1322013347
SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
1322113348
SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13383,11 @@
1325613383
/*
1325713384
** Convenience functions for opening and closing files using
1325813385
** sqlite3_malloc() to obtain space for the file-handle structure.
1325913386
*/
1326013387
SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13261
-SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
13388
+SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
1326213389
1326313390
#endif /* _SQLITE_OS_H_ */
1326413391
1326513392
/************** End of os.h **************************************************/
1326613393
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13792,15 @@
1366513792
#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
1366613793
#define ENC(db) ((db)->enc)
1366713794
1366813795
/*
1366913796
** Possible values for the sqlite3.flags.
13797
+**
13798
+** Value constraints (enforced via assert()):
13799
+** SQLITE_FullFSync == PAGER_FULLFSYNC
13800
+** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
13801
+** SQLITE_CacheSpill == PAGER_CACHE_SPILL
1367013802
*/
1367113803
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
1367213804
#define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
1367313805
#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1367413806
#define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13824,18 @@
1369213824
#define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
1369313825
#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
1369413826
#define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
1369513827
#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
1369613828
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13697
-#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
13698
-#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
13699
-#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
13700
-#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
13701
-#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
13702
-#define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */
13703
-#define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */
13829
+#define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */
13830
+#define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */
13831
+#define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */
13832
+#define SQLITE_QueryOnly 0x04000000 /* Disable database changes */
13833
+#define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */
13834
+#define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
13835
+#define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */
13836
+#define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */
1370413837
1370513838
1370613839
/*
1370713840
** Bits of the sqlite3.dbOptFlags field that are used by the
1370813841
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13932,17 @@
1379913932
/*
1380013933
** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
1380113934
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
1380213935
** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
1380313936
** are assert() statements in the code to verify this.
13937
+**
13938
+** Value constraints (enforced via assert()):
13939
+** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
13940
+** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
13941
+** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
13942
+** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
13943
+** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1380413944
*/
1380513945
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1380613946
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1380713947
#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
1380813948
#define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14938,13 @@
1479814938
1479914939
1480014940
/*
1480114941
** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
1480214942
** and the WhereInfo.wctrlFlags member.
14943
+**
14944
+** Value constraints (enforced via assert()):
14945
+** WHERE_USE_LIMIT == SF_FixedLimit
1480314946
*/
1480414947
#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
1480514948
#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
1480614949
#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
1480714950
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14815,10 +14958,11 @@
1481514958
#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1481614959
#define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
1481714960
#define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
1481814961
#define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
1481914962
#define WHERE_USE_LIMIT 0x4000 /* There is a constant LIMIT clause */
14963
+#define WHERE_SEEK_TABLE 0x8000 /* Do not defer seeks on main table */
1482014964
1482114965
/* Allowed return values from sqlite3WhereIsDistinct()
1482214966
*/
1482314967
#define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
1482414968
#define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -14858,20 +15002,22 @@
1485815002
};
1485915003
1486015004
/*
1486115005
** Allowed values for the NameContext, ncFlags field.
1486215006
**
14863
-** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
14864
-** SQLITE_FUNC_MINMAX.
15007
+** Value constraints (all checked via assert()):
15008
+** NC_HasAgg == SF_HasAgg
15009
+** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
1486515010
**
1486615011
*/
1486715012
#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
14868
-#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
15013
+#define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
1486915014
#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
1487015015
#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
14871
-#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
15016
+#define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
1487215017
#define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
15018
+#define NC_VarSelect 0x0040 /* A correlated subquery has been seen */
1487315019
#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
1487415020
1487515021
/*
1487615022
** An instance of the following structure contains all information
1487715023
** needed to generate code for a single SELECT statement.
@@ -14915,28 +15061,34 @@
1491515061
};
1491615062
1491715063
/*
1491815064
** Allowed values for Select.selFlags. The "SF" prefix stands for
1491915065
** "Select Flag".
15066
+**
15067
+** Value constraints (all checked via assert())
15068
+** SF_HasAgg == NC_HasAgg
15069
+** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
15070
+** SF_FixedLimit == WHERE_USE_LIMIT
1492015071
*/
1492115072
#define SF_Distinct 0x00001 /* Output should be DISTINCT */
1492215073
#define SF_All 0x00002 /* Includes the ALL keyword */
1492315074
#define SF_Resolved 0x00004 /* Identifiers have been resolved */
14924
-#define SF_Aggregate 0x00008 /* Contains aggregate functions */
14925
-#define SF_UsesEphemeral 0x00010 /* Uses the OpenEphemeral opcode */
14926
-#define SF_Expanded 0x00020 /* sqlite3SelectExpand() called on this */
14927
-#define SF_HasTypeInfo 0x00040 /* FROM subqueries have Table metadata */
14928
-#define SF_Compound 0x00080 /* Part of a compound query */
14929
-#define SF_Values 0x00100 /* Synthesized from VALUES clause */
14930
-#define SF_MultiValue 0x00200 /* Single VALUES term with multiple rows */
14931
-#define SF_NestedFrom 0x00400 /* Part of a parenthesized FROM clause */
14932
-#define SF_MaybeConvert 0x00800 /* Need convertCompoundSelectToSubquery() */
15075
+#define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
15076
+#define SF_HasAgg 0x00010 /* Contains aggregate functions */
15077
+#define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
15078
+#define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
15079
+#define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
15080
+#define SF_Compound 0x00100 /* Part of a compound query */
15081
+#define SF_Values 0x00200 /* Synthesized from VALUES clause */
15082
+#define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
15083
+#define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
1493315084
#define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
1493415085
#define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
1493515086
#define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
14936
-#define SF_Converted 0x08000 /* By convertCompoundSelectToSubquery() */
14937
-#define SF_IncludeHidden 0x10000 /* Include hidden columns in output */
15087
+#define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
15088
+#define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
15089
+#define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
1493815090
1493915091
1494015092
/*
1494115093
** The results of a SELECT can be distributed in several ways, as defined
1494215094
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15281,11 @@
1512915281
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
1513015282
u8 mayAbort; /* True if statement may throw an ABORT exception */
1513115283
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
1513215284
u8 okConstFactor; /* OK to factor out constants */
1513315285
u8 disableLookaside; /* Number of times lookaside has been disabled */
15286
+ u8 nColCache; /* Number of entries in aColCache[] */
1513415287
int aTempReg[8]; /* Holding area for temporary registers */
1513515288
int nRangeReg; /* Size of the temporary register block */
1513615289
int iRangeReg; /* First register in temporary register block */
1513715290
int nErr; /* Number of errors seen */
1513815291
int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15395,19 @@
1524215395
Parse *pParse; /* The Parse structure */
1524315396
};
1524415397
1524515398
/*
1524615399
** Bitfield flags for P5 value in various opcodes.
15400
+**
15401
+** Value constraints (enforced via assert()):
15402
+** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
15403
+** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
15404
+** OPFLAG_BULKCSR == BTREE_BULKLOAD
15405
+** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
15406
+** OPFLAG_FORDELETE == BTREE_FORDELETE
15407
+** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
15408
+** OPFLAG_AUXDELETE == BTREE_AUXDELETE
1524715409
*/
1524815410
#define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
1524915411
/* Also used in P2 (not P5) of OP_Delete */
1525015412
#define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
1525115413
#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15778,20 @@
1561615778
# define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
1561715779
# define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
1561815780
# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
1561915781
# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
1562015782
# define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
15783
+# define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
1562115784
#else
1562215785
# define sqlite3Toupper(x) toupper((unsigned char)(x))
1562315786
# define sqlite3Isspace(x) isspace((unsigned char)(x))
1562415787
# define sqlite3Isalnum(x) isalnum((unsigned char)(x))
1562515788
# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
1562615789
# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
1562715790
# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
1562815791
# define sqlite3Tolower(x) tolower((unsigned char)(x))
15792
+# define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
1562915793
#endif
1563015794
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
1563115795
SQLITE_PRIVATE int sqlite3IsIdChar(u8);
1563215796
#endif
1563315797
@@ -15747,11 +15911,11 @@
1574715911
#endif
1574815912
1574915913
1575015914
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
1575115915
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15752
-SQLITE_PRIVATE int sqlite3Dequote(char*);
15916
+SQLITE_PRIVATE void sqlite3Dequote(char*);
1575315917
SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
1575415918
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
1575515919
SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
1575615920
SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
1575715921
SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15928,11 @@
1576415928
#endif
1576515929
SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
1576615930
SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
1576715931
SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
1576815932
SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
15933
+SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
1576915934
SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
1577015935
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
1577115936
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
1577215937
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1577315938
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16724,11 @@
1655916724
** isdigit() 0x04
1656016725
** isalnum() 0x06
1656116726
** isxdigit() 0x08
1656216727
** toupper() 0x20
1656316728
** SQLite identifier character 0x40
16729
+** Quote character 0x80
1656416730
**
1656516731
** Bit 0x20 is set if the mapped character requires translation to upper
1656616732
** case. i.e. if the character is a lower-case ASCII character.
1656716733
** If x is a lower-case ASCII character, then its upper-case equivalent
1656816734
** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16750,20 @@
1658416750
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
1658516751
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
1658616752
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
1658716753
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
1658816754
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16589
- 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */
16755
+ 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
1659016756
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
1659116757
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
1659216758
0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
1659316759
1659416760
0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
1659516761
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
1659616762
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16597
- 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16598
- 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16763
+ 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16764
+ 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
1659916765
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
1660016766
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
1660116767
0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
1660216768
1660316769
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18347,19 @@
1818118347
/* #include <assert.h> */
1818218348
#include <time.h>
1818318349
1818418350
#ifndef SQLITE_OMIT_DATETIME_FUNCS
1818518351
18352
+/*
18353
+** The MSVC CRT on Windows CE may not have a localtime() function.
18354
+** So declare a substitute. The substitute function itself is
18355
+** defined in "os_win.c".
18356
+*/
18357
+#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
18358
+ (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
18359
+struct tm *__cdecl localtime(const time_t *);
18360
+#endif
1818618361
1818718362
/*
1818818363
** A structure for holding a single date and time.
1818918364
*/
1819018365
typedef struct DateTime DateTime;
@@ -18549,10 +18724,11 @@
1854918724
p->validYMD = 0;
1855018725
p->validHMS = 0;
1855118726
p->validTZ = 0;
1855218727
}
1855318728
18729
+#ifndef SQLITE_OMIT_LOCALTIME
1855418730
/*
1855518731
** On recent Windows platforms, the localtime_s() function is available
1855618732
** as part of the "Secure CRT". It is essentially equivalent to
1855718733
** localtime_r() available under most POSIX platforms, except that the
1855818734
** order of the parameters is reversed.
@@ -18567,11 +18743,10 @@
1856718743
&& defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
1856818744
#undef HAVE_LOCALTIME_S
1856918745
#define HAVE_LOCALTIME_S 1
1857018746
#endif
1857118747
18572
-#ifndef SQLITE_OMIT_LOCALTIME
1857318748
/*
1857418749
** The following routine implements the rough equivalent of localtime_r()
1857518750
** using whatever operating-system specific localtime facility that
1857618751
** is available. This routine returns 0 on success and
1857718752
** non-zero on any kind of error.
@@ -19371,17 +19546,15 @@
1937119546
** The following routines are convenience wrappers around methods
1937219547
** of the sqlite3_file object. This is mostly just syntactic sugar. All
1937319548
** of this would be completely automatic if SQLite were coded using
1937419549
** C++ instead of plain old C.
1937519550
*/
19376
-SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file *pId){
19377
- int rc = SQLITE_OK;
19551
+SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *pId){
1937819552
if( pId->pMethods ){
19379
- rc = pId->pMethods->xClose(pId);
19553
+ pId->pMethods->xClose(pId);
1938019554
pId->pMethods = 0;
1938119555
}
19382
- return rc;
1938319556
}
1938419557
SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
1938519558
DO_OS_MALLOC_TEST(id);
1938619559
return id->pMethods->xRead(id, pBuf, amt, offset);
1938719560
}
@@ -19595,16 +19768,14 @@
1959519768
}else{
1959619769
rc = SQLITE_NOMEM_BKPT;
1959719770
}
1959819771
return rc;
1959919772
}
19600
-SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){
19601
- int rc = SQLITE_OK;
19773
+SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
1960219774
assert( pFile );
19603
- rc = sqlite3OsClose(pFile);
19775
+ sqlite3OsClose(pFile);
1960419776
sqlite3_free(pFile);
19605
- return rc;
1960619777
}
1960719778
1960819779
/*
1960919780
** This function is a wrapper around the OS specific implementation of
1961019781
** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -24280,30 +24451,30 @@
2428024451
2428124452
/*
2428224453
** Conversion types fall into various categories as defined by the
2428324454
** following enumeration.
2428424455
*/
24285
-#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
24286
-#define etFLOAT 2 /* Floating point. %f */
24287
-#define etEXP 3 /* Exponentional notation. %e and %E */
24288
-#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
24289
-#define etSIZE 5 /* Return number of characters processed so far. %n */
24290
-#define etSTRING 6 /* Strings. %s */
24291
-#define etDYNSTRING 7 /* Dynamically allocated strings. %z */
24292
-#define etPERCENT 8 /* Percent symbol. %% */
24293
-#define etCHARX 9 /* Characters. %c */
24456
+#define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */
24457
+#define etFLOAT 1 /* Floating point. %f */
24458
+#define etEXP 2 /* Exponentional notation. %e and %E */
24459
+#define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */
24460
+#define etSIZE 4 /* Return number of characters processed so far. %n */
24461
+#define etSTRING 5 /* Strings. %s */
24462
+#define etDYNSTRING 6 /* Dynamically allocated strings. %z */
24463
+#define etPERCENT 7 /* Percent symbol. %% */
24464
+#define etCHARX 8 /* Characters. %c */
2429424465
/* The rest are extensions, not normally found in printf() */
24295
-#define etSQLESCAPE 10 /* Strings with '\'' doubled. %q */
24296
-#define etSQLESCAPE2 11 /* Strings with '\'' doubled and enclosed in '',
24466
+#define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */
24467
+#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
2429724468
NULL pointers replaced by SQL NULL. %Q */
24298
-#define etTOKEN 12 /* a pointer to a Token structure */
24299
-#define etSRCLIST 13 /* a pointer to a SrcList */
24300
-#define etPOINTER 14 /* The %p conversion */
24301
-#define etSQLESCAPE3 15 /* %w -> Strings with '\"' doubled */
24302
-#define etORDINAL 16 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
24469
+#define etTOKEN 11 /* a pointer to a Token structure */
24470
+#define etSRCLIST 12 /* a pointer to a SrcList */
24471
+#define etPOINTER 13 /* The %p conversion */
24472
+#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
24473
+#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
2430324474
24304
-#define etINVALID 0 /* Any unrecognized conversion type */
24475
+#define etINVALID 16 /* Any unrecognized conversion type */
2430524476
2430624477
2430724478
/*
2430824479
** An "etByte" is an 8-bit unsigned value.
2430924480
*/
@@ -24454,11 +24625,11 @@
2445424625
etByte flag_altform2; /* True if "!" flag is present */
2445524626
etByte flag_zeropad; /* True if field width constant starts with zero */
2445624627
etByte flag_long; /* True if "l" flag is present */
2445724628
etByte flag_longlong; /* True if the "ll" flag is present */
2445824629
etByte done; /* Loop termination flag */
24459
- etByte xtype = 0; /* Conversion paradigm */
24630
+ etByte xtype = etINVALID; /* Conversion paradigm */
2446024631
u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
2446124632
u8 useIntern; /* Ok to use internal conversions (ex: %T) */
2446224633
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
2446324634
sqlite_uint64 longvalue; /* Value for integer types */
2446424635
LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -27045,22 +27216,17 @@
2704527216
**
2704627217
** 2002-Feb-14: This routine is extended to remove MS-Access style
2704727218
** brackets from around identifiers. For example: "[a-b-c]" becomes
2704827219
** "a-b-c".
2704927220
*/
27050
-SQLITE_PRIVATE int sqlite3Dequote(char *z){
27221
+SQLITE_PRIVATE void sqlite3Dequote(char *z){
2705127222
char quote;
2705227223
int i, j;
27053
- if( z==0 ) return -1;
27224
+ if( z==0 ) return;
2705427225
quote = z[0];
27055
- switch( quote ){
27056
- case '\'': break;
27057
- case '"': break;
27058
- case '`': break; /* For MySQL compatibility */
27059
- case '[': quote = ']'; break; /* For MS SqlServer compatibility */
27060
- default: return -1;
27061
- }
27226
+ if( !sqlite3Isquote(quote) ) return;
27227
+ if( quote=='[' ) quote = ']';
2706227228
for(i=1, j=0;; i++){
2706327229
assert( z[i] );
2706427230
if( z[i]==quote ){
2706527231
if( z[i+1]==quote ){
2706627232
z[j++] = quote;
@@ -27071,11 +27237,10 @@
2707127237
}else{
2707227238
z[j++] = z[i];
2707327239
}
2707427240
}
2707527241
z[j] = 0;
27076
- return j;
2707727242
}
2707827243
2707927244
/*
2708027245
** Generate a Token object from a string
2708127246
*/
@@ -27164,11 +27329,11 @@
2716427329
int esign = 1; /* sign of exponent */
2716527330
int e = 0; /* exponent */
2716627331
int eValid = 1; /* True exponent is either not used or is well-formed */
2716727332
double result;
2716827333
int nDigits = 0;
27169
- int nonNum = 0;
27334
+ int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
2717027335
2717127336
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2717227337
*pResult = 0.0; /* Default return value, in case of an error */
2717327338
2717427339
if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27342,11 @@
2717727342
int i;
2717827343
incr = 2;
2717927344
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
2718027345
for(i=3-enc; i<length && z[i]==0; i+=2){}
2718127346
nonNum = i<length;
27182
- zEnd = z+i+enc-3;
27347
+ zEnd = &z[i^1];
2718327348
z += (enc&1);
2718427349
}
2718527350
2718627351
/* skip leading spaces */
2718727352
while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27358,10 @@
2719327358
z+=incr;
2719427359
}else if( *z=='+' ){
2719527360
z+=incr;
2719627361
}
2719727362
27198
- /* skip leading zeroes */
27199
- while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
27200
-
2720127363
/* copy max significant digits to significand */
2720227364
while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
2720327365
s = s*10 + (*z - '0');
2720427366
z+=incr, nDigits++;
2720527367
}
@@ -27212,24 +27374,30 @@
2721227374
/* if decimal point is present */
2721327375
if( *z=='.' ){
2721427376
z+=incr;
2721527377
/* copy digits from after decimal to significand
2721627378
** (decrease exponent by d to shift decimal right) */
27217
- while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27218
- s = s*10 + (*z - '0');
27219
- z+=incr, nDigits++, d--;
27379
+ while( z<zEnd && sqlite3Isdigit(*z) ){
27380
+ if( s<((LARGEST_INT64-9)/10) ){
27381
+ s = s*10 + (*z - '0');
27382
+ d--;
27383
+ }
27384
+ z+=incr, nDigits++;
2722027385
}
27221
- /* skip non-significant digits */
27222
- while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
2722327386
}
2722427387
if( z>=zEnd ) goto do_atof_calc;
2722527388
2722627389
/* if exponent is present */
2722727390
if( *z=='e' || *z=='E' ){
2722827391
z+=incr;
2722927392
eValid = 0;
27230
- if( z>=zEnd ) goto do_atof_calc;
27393
+
27394
+ /* This branch is needed to avoid a (harmless) buffer overread. The
27395
+ ** special comment alerts the mutation tester that the correct answer
27396
+ ** is obtained even if the branch is omitted */
27397
+ if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
27398
+
2723127399
/* get sign of exponent */
2723227400
if( *z=='-' ){
2723327401
esign = -1;
2723427402
z+=incr;
2723527403
}else if( *z=='+' ){
@@ -27242,13 +27410,11 @@
2724227410
eValid = 1;
2724327411
}
2724427412
}
2724527413
2724627414
/* skip trailing spaces */
27247
- if( nDigits && eValid ){
27248
- while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
27249
- }
27415
+ while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
2725027416
2725127417
do_atof_calc:
2725227418
/* adjust exponent by d, and update sign */
2725327419
e = (e*esign) + d;
2725427420
if( e<0 ) {
@@ -27256,45 +27422,55 @@
2725627422
e *= -1;
2725727423
} else {
2725827424
esign = 1;
2725927425
}
2726027426
27261
- /* if 0 significand */
27262
- if( !s ) {
27263
- /* In the IEEE 754 standard, zero is signed.
27264
- ** Add the sign if we've seen at least one digit */
27265
- result = (sign<0 && nDigits) ? -(double)0 : (double)0;
27427
+ if( s==0 ) {
27428
+ /* In the IEEE 754 standard, zero is signed. */
27429
+ result = sign<0 ? -(double)0 : (double)0;
2726627430
} else {
27267
- /* attempt to reduce exponent */
27268
- if( esign>0 ){
27269
- while( s<(LARGEST_INT64/10) && e>0 ) e--,s*=10;
27270
- }else{
27271
- while( !(s%10) && e>0 ) e--,s/=10;
27431
+ /* Attempt to reduce exponent.
27432
+ **
27433
+ ** Branches that are not required for the correct answer but which only
27434
+ ** help to obtain the correct answer faster are marked with special
27435
+ ** comments, as a hint to the mutation tester.
27436
+ */
27437
+ while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/
27438
+ if( esign>0 ){
27439
+ if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/
27440
+ s *= 10;
27441
+ }else{
27442
+ if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/
27443
+ s /= 10;
27444
+ }
27445
+ e--;
2727227446
}
2727327447
2727427448
/* adjust the sign of significand */
2727527449
s = sign<0 ? -s : s;
2727627450
27277
- /* if exponent, scale significand as appropriate
27278
- ** and store in result. */
27279
- if( e ){
27451
+ if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
27452
+ result = (double)s;
27453
+ }else{
2728027454
LONGDOUBLE_TYPE scale = 1.0;
2728127455
/* attempt to handle extremely small/large numbers better */
27282
- if( e>307 && e<342 ){
27283
- while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27284
- if( esign<0 ){
27285
- result = s / scale;
27286
- result /= 1.0e+308;
27287
- }else{
27288
- result = s * scale;
27289
- result *= 1.0e+308;
27290
- }
27291
- }else if( e>=342 ){
27292
- if( esign<0 ){
27293
- result = 0.0*s;
27294
- }else{
27295
- result = 1e308*1e308*s; /* Infinity */
27456
+ if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
27457
+ if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
27458
+ while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27459
+ if( esign<0 ){
27460
+ result = s / scale;
27461
+ result /= 1.0e+308;
27462
+ }else{
27463
+ result = s * scale;
27464
+ result *= 1.0e+308;
27465
+ }
27466
+ }else{ assert( e>=342 );
27467
+ if( esign<0 ){
27468
+ result = 0.0*s;
27469
+ }else{
27470
+ result = 1e308*1e308*s; /* Infinity */
27471
+ }
2729627472
}
2729727473
}else{
2729827474
/* 1.0e+22 is the largest power of 10 than can be
2729927475
** represented exactly. */
2730027476
while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27479,18 @@
2730327479
result = s / scale;
2730427480
}else{
2730527481
result = s * scale;
2730627482
}
2730727483
}
27308
- } else {
27309
- result = (double)s;
2731027484
}
2731127485
}
2731227486
2731327487
/* store the result */
2731427488
*pResult = result;
2731527489
2731627490
/* return true if number and no extra non-whitespace chracters after */
27317
- return z>=zEnd && nDigits>0 && eValid && nonNum==0;
27491
+ return z==zEnd && nDigits>0 && eValid && nonNum==0;
2731827492
#else
2731927493
return !sqlite3Atoi64(z, pResult, length, enc);
2732027494
#endif /* SQLITE_OMIT_FLOATING_POINT */
2732127495
}
2732227496
@@ -27374,11 +27548,11 @@
2737427548
int incr;
2737527549
u64 u = 0;
2737627550
int neg = 0; /* assume positive */
2737727551
int i;
2737827552
int c = 0;
27379
- int nonNum = 0;
27553
+ int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
2738027554
const char *zStart;
2738127555
const char *zEnd = zNum + length;
2738227556
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2738327557
if( enc==SQLITE_UTF8 ){
2738427558
incr = 1;
@@ -27385,11 +27559,11 @@
2738527559
}else{
2738627560
incr = 2;
2738727561
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
2738827562
for(i=3-enc; i<length && zNum[i]==0; i+=2){}
2738927563
nonNum = i<length;
27390
- zEnd = zNum+i+enc-3;
27564
+ zEnd = &zNum[i^1];
2739127565
zNum += (enc&1);
2739227566
}
2739327567
while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
2739427568
if( zNum<zEnd ){
2739527569
if( *zNum=='-' ){
@@ -27412,12 +27586,15 @@
2741227586
*pNum = (i64)u;
2741327587
}
2741427588
testcase( i==18 );
2741527589
testcase( i==19 );
2741627590
testcase( i==20 );
27417
- if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum)
27418
- || i>19*incr || nonNum ){
27591
+ if( &zNum[i]<zEnd /* Extra bytes at the end */
27592
+ || (i==0 && zStart==zNum) /* No digits */
27593
+ || i>19*incr /* Too many digits */
27594
+ || nonNum /* UTF16 with high-order bytes non-zero */
27595
+ ){
2741927596
/* zNum is empty or contains non-numeric text or is longer
2742027597
** than 19 digits (thus guaranteeing that it is too large) */
2742127598
return 1;
2742227599
}else if( i<19*incr ){
2742327600
/* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27632,10 @@
2745527632
*/
2745627633
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
2745727634
#ifndef SQLITE_OMIT_HEX_INTEGER
2745827635
if( z[0]=='0'
2745927636
&& (z[1]=='x' || z[1]=='X')
27460
- && sqlite3Isxdigit(z[2])
2746127637
){
2746227638
u64 u = 0;
2746327639
int i, k;
2746427640
for(i=2; z[i]=='0'; i++){}
2746527641
for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28393,11 @@
2821728393
LogEst y = 40;
2821828394
if( x<8 ){
2821928395
if( x<2 ) return 0;
2822028396
while( x<8 ){ y -= 10; x <<= 1; }
2822128397
}else{
28222
- while( x>255 ){ y += 40; x >>= 4; }
28398
+ while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
2822328399
while( x>15 ){ y += 10; x >>= 1; }
2822428400
}
2822528401
return a[x&7] + y - 10;
2822628402
}
2822728403
@@ -28326,11 +28502,11 @@
2832628502
** The hashing function.
2832728503
*/
2832828504
static unsigned int strHash(const char *z){
2832928505
unsigned int h = 0;
2833028506
unsigned char c;
28331
- while( (c = (unsigned char)*z++)!=0 ){
28507
+ while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
2833228508
h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
2833328509
}
2833428510
return h;
2833528511
}
2833628512
@@ -28419,11 +28595,11 @@
2841928595
){
2842028596
HashElem *elem; /* Used to loop thru the element list */
2842128597
int count; /* Number of elements left to test */
2842228598
unsigned int h; /* The computed hash */
2842328599
28424
- if( pH->ht ){
28600
+ if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
2842528601
struct _ht *pEntry;
2842628602
h = strHash(pKey) % pH->htsize;
2842728603
pEntry = &pH->ht[h];
2842828604
elem = pEntry->chain;
2842928605
count = pEntry->count;
@@ -28566,157 +28742,156 @@
2856628742
/* 10 */ "Vacuum" OpHelp(""),
2856728743
/* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
2856828744
/* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
2856928745
/* 13 */ "Goto" OpHelp(""),
2857028746
/* 14 */ "Gosub" OpHelp(""),
28571
- /* 15 */ "Return" OpHelp(""),
28572
- /* 16 */ "InitCoroutine" OpHelp(""),
28573
- /* 17 */ "EndCoroutine" OpHelp(""),
28574
- /* 18 */ "Yield" OpHelp(""),
28747
+ /* 15 */ "InitCoroutine" OpHelp(""),
28748
+ /* 16 */ "Yield" OpHelp(""),
28749
+ /* 17 */ "MustBeInt" OpHelp(""),
28750
+ /* 18 */ "Jump" OpHelp(""),
2857528751
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28576
- /* 20 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28577
- /* 21 */ "Halt" OpHelp(""),
28578
- /* 22 */ "Integer" OpHelp("r[P2]=P1"),
28579
- /* 23 */ "Int64" OpHelp("r[P2]=P4"),
28580
- /* 24 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28581
- /* 25 */ "Null" OpHelp("r[P2..P3]=NULL"),
28582
- /* 26 */ "SoftNull" OpHelp("r[P1]=NULL"),
28583
- /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28584
- /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28585
- /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28586
- /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28587
- /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28588
- /* 32 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28589
- /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28590
- /* 34 */ "CollSeq" OpHelp(""),
28591
- /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28592
- /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28593
- /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28594
- /* 38 */ "MustBeInt" OpHelp(""),
28595
- /* 39 */ "RealAffinity" OpHelp(""),
28596
- /* 40 */ "Cast" OpHelp("affinity(r[P1])"),
28597
- /* 41 */ "Permutation" OpHelp(""),
28598
- /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28599
- /* 43 */ "Jump" OpHelp(""),
28600
- /* 44 */ "Once" OpHelp(""),
28601
- /* 45 */ "If" OpHelp(""),
28602
- /* 46 */ "IfNot" OpHelp(""),
28603
- /* 47 */ "Column" OpHelp("r[P3]=PX"),
28604
- /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28605
- /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28606
- /* 50 */ "Count" OpHelp("r[P2]=count()"),
28607
- /* 51 */ "ReadCookie" OpHelp(""),
28608
- /* 52 */ "SetCookie" OpHelp(""),
28609
- /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28610
- /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28611
- /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28612
- /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28613
- /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28614
- /* 58 */ "SorterOpen" OpHelp(""),
28615
- /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28616
- /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28617
- /* 61 */ "Close" OpHelp(""),
28618
- /* 62 */ "ColumnsUsed" OpHelp(""),
28619
- /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28620
- /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28621
- /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28622
- /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28623
- /* 67 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28624
- /* 68 */ "NotFound" OpHelp("key=r[P3@P4]"),
28625
- /* 69 */ "Found" OpHelp("key=r[P3@P4]"),
28626
- /* 70 */ "NotExists" OpHelp("intkey=r[P3]"),
28627
- /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28628
- /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28629
- /* 73 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28630
- /* 74 */ "NewRowid" OpHelp("r[P2]=rowid"),
28631
- /* 75 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28632
- /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28633
- /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28634
- /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28635
- /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28636
- /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28637
- /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28638
- /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28639
- /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28640
- /* 84 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28641
- /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28642
- /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28643
- /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28644
- /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28645
- /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28646
- /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28647
- /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28648
- /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28649
- /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28650
- /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28651
- /* 95 */ "Delete" OpHelp(""),
28652
- /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28752
+ /* 20 */ "Once" OpHelp(""),
28753
+ /* 21 */ "If" OpHelp(""),
28754
+ /* 22 */ "IfNot" OpHelp(""),
28755
+ /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28756
+ /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28757
+ /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28758
+ /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28759
+ /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28760
+ /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28761
+ /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28762
+ /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
28763
+ /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
28764
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
28765
+ /* 33 */ "Last" OpHelp(""),
28766
+ /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28767
+ /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28768
+ /* 36 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28769
+ /* 37 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28770
+ /* 38 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28771
+ /* 39 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28772
+ /* 40 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28773
+ /* 41 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28774
+ /* 42 */ "SorterSort" OpHelp(""),
28775
+ /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28776
+ /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28777
+ /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28778
+ /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28779
+ /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28780
+ /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28781
+ /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28782
+ /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28783
+ /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28784
+ /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28785
+ /* 53 */ "Sort" OpHelp(""),
28786
+ /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28787
+ /* 55 */ "Rewind" OpHelp(""),
28788
+ /* 56 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28789
+ /* 57 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28790
+ /* 58 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28791
+ /* 59 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28792
+ /* 60 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28793
+ /* 61 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28794
+ /* 62 */ "Program" OpHelp(""),
28795
+ /* 63 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28796
+ /* 64 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28797
+ /* 65 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28798
+ /* 66 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28799
+ /* 67 */ "IncrVacuum" OpHelp(""),
28800
+ /* 68 */ "VNext" OpHelp(""),
28801
+ /* 69 */ "Init" OpHelp("Start at P2"),
28802
+ /* 70 */ "Return" OpHelp(""),
28803
+ /* 71 */ "EndCoroutine" OpHelp(""),
28804
+ /* 72 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28805
+ /* 73 */ "Halt" OpHelp(""),
28806
+ /* 74 */ "Integer" OpHelp("r[P2]=P1"),
28807
+ /* 75 */ "Int64" OpHelp("r[P2]=P4"),
28808
+ /* 76 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28809
+ /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
28810
+ /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
28811
+ /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28812
+ /* 80 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28813
+ /* 81 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28814
+ /* 82 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28815
+ /* 83 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28816
+ /* 84 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28817
+ /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28818
+ /* 86 */ "CollSeq" OpHelp(""),
28819
+ /* 87 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28820
+ /* 88 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28821
+ /* 89 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28822
+ /* 90 */ "RealAffinity" OpHelp(""),
28823
+ /* 91 */ "Cast" OpHelp("affinity(r[P1])"),
28824
+ /* 92 */ "Permutation" OpHelp(""),
28825
+ /* 93 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28826
+ /* 94 */ "Column" OpHelp("r[P3]=PX"),
28827
+ /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28828
+ /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
2865328829
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
28654
- /* 98 */ "ResetCount" OpHelp(""),
28655
- /* 99 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28656
- /* 100 */ "SorterData" OpHelp("r[P2]=data"),
28657
- /* 101 */ "RowKey" OpHelp("r[P2]=key"),
28658
- /* 102 */ "RowData" OpHelp("r[P2]=data"),
28659
- /* 103 */ "Rowid" OpHelp("r[P2]=rowid"),
28660
- /* 104 */ "NullRow" OpHelp(""),
28661
- /* 105 */ "Last" OpHelp(""),
28662
- /* 106 */ "SorterSort" OpHelp(""),
28663
- /* 107 */ "Sort" OpHelp(""),
28664
- /* 108 */ "Rewind" OpHelp(""),
28665
- /* 109 */ "SorterInsert" OpHelp(""),
28666
- /* 110 */ "IdxInsert" OpHelp("key=r[P2]"),
28667
- /* 111 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28668
- /* 112 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28669
- /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28670
- /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28671
- /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28672
- /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28673
- /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28674
- /* 118 */ "Destroy" OpHelp(""),
28675
- /* 119 */ "Clear" OpHelp(""),
28676
- /* 120 */ "ResetSorter" OpHelp(""),
28677
- /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28678
- /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28679
- /* 123 */ "ParseSchema" OpHelp(""),
28680
- /* 124 */ "LoadAnalysis" OpHelp(""),
28681
- /* 125 */ "DropTable" OpHelp(""),
28682
- /* 126 */ "DropIndex" OpHelp(""),
28683
- /* 127 */ "DropTrigger" OpHelp(""),
28684
- /* 128 */ "IntegrityCk" OpHelp(""),
28685
- /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28686
- /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28687
- /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28688
- /* 132 */ "Program" OpHelp(""),
28830
+ /* 98 */ "Count" OpHelp("r[P2]=count()"),
28831
+ /* 99 */ "ReadCookie" OpHelp(""),
28832
+ /* 100 */ "SetCookie" OpHelp(""),
28833
+ /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28834
+ /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28835
+ /* 103 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28836
+ /* 104 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28837
+ /* 105 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28838
+ /* 106 */ "SorterOpen" OpHelp(""),
28839
+ /* 107 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28840
+ /* 108 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28841
+ /* 109 */ "Close" OpHelp(""),
28842
+ /* 110 */ "ColumnsUsed" OpHelp(""),
28843
+ /* 111 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28844
+ /* 112 */ "NewRowid" OpHelp("r[P2]=rowid"),
28845
+ /* 113 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28846
+ /* 114 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28847
+ /* 115 */ "Delete" OpHelp(""),
28848
+ /* 116 */ "ResetCount" OpHelp(""),
28849
+ /* 117 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28850
+ /* 118 */ "SorterData" OpHelp("r[P2]=data"),
28851
+ /* 119 */ "RowKey" OpHelp("r[P2]=key"),
28852
+ /* 120 */ "RowData" OpHelp("r[P2]=data"),
28853
+ /* 121 */ "Rowid" OpHelp("r[P2]=rowid"),
28854
+ /* 122 */ "NullRow" OpHelp(""),
28855
+ /* 123 */ "SorterInsert" OpHelp(""),
28856
+ /* 124 */ "IdxInsert" OpHelp("key=r[P2]"),
28857
+ /* 125 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28858
+ /* 126 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28859
+ /* 127 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28860
+ /* 128 */ "Destroy" OpHelp(""),
28861
+ /* 129 */ "Clear" OpHelp(""),
28862
+ /* 130 */ "ResetSorter" OpHelp(""),
28863
+ /* 131 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28864
+ /* 132 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
2868928865
/* 133 */ "Real" OpHelp("r[P2]=P4"),
28690
- /* 134 */ "Param" OpHelp(""),
28691
- /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28692
- /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28693
- /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28694
- /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28695
- /* 139 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28696
- /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28697
- /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28698
- /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
28699
- /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28700
- /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28701
- /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28702
- /* 146 */ "IncrVacuum" OpHelp(""),
28703
- /* 147 */ "Expire" OpHelp(""),
28704
- /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28705
- /* 149 */ "VBegin" OpHelp(""),
28706
- /* 150 */ "VCreate" OpHelp(""),
28707
- /* 151 */ "VDestroy" OpHelp(""),
28708
- /* 152 */ "VOpen" OpHelp(""),
28709
- /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28710
- /* 154 */ "VNext" OpHelp(""),
28866
+ /* 134 */ "ParseSchema" OpHelp(""),
28867
+ /* 135 */ "LoadAnalysis" OpHelp(""),
28868
+ /* 136 */ "DropTable" OpHelp(""),
28869
+ /* 137 */ "DropIndex" OpHelp(""),
28870
+ /* 138 */ "DropTrigger" OpHelp(""),
28871
+ /* 139 */ "IntegrityCk" OpHelp(""),
28872
+ /* 140 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28873
+ /* 141 */ "Param" OpHelp(""),
28874
+ /* 142 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28875
+ /* 143 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28876
+ /* 144 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28877
+ /* 145 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28878
+ /* 146 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28879
+ /* 147 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28880
+ /* 148 */ "Expire" OpHelp(""),
28881
+ /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28882
+ /* 150 */ "VBegin" OpHelp(""),
28883
+ /* 151 */ "VCreate" OpHelp(""),
28884
+ /* 152 */ "VDestroy" OpHelp(""),
28885
+ /* 153 */ "VOpen" OpHelp(""),
28886
+ /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
2871128887
/* 155 */ "VRename" OpHelp(""),
2871228888
/* 156 */ "Pagecount" OpHelp(""),
2871328889
/* 157 */ "MaxPgcnt" OpHelp(""),
28714
- /* 158 */ "Init" OpHelp("Start at P2"),
28715
- /* 159 */ "CursorHint" OpHelp(""),
28716
- /* 160 */ "Noop" OpHelp(""),
28717
- /* 161 */ "Explain" OpHelp(""),
28890
+ /* 158 */ "CursorHint" OpHelp(""),
28891
+ /* 159 */ "Noop" OpHelp(""),
28892
+ /* 160 */ "Explain" OpHelp(""),
2871828893
};
2871928894
return azName[i];
2872028895
}
2872128896
#endif
2872228897
@@ -29325,11 +29500,11 @@
2932529500
#if defined(USE_PREAD64)
2932629501
{ "pread64", (sqlite3_syscall_ptr)pread64, 0 },
2932729502
#else
2932829503
{ "pread64", (sqlite3_syscall_ptr)0, 0 },
2932929504
#endif
29330
-#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
29505
+#define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
2933129506
2933229507
{ "write", (sqlite3_syscall_ptr)write, 0 },
2933329508
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
2933429509
2933529510
#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29518,11 @@
2934329518
#if defined(USE_PREAD64)
2934429519
{ "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
2934529520
#else
2934629521
{ "pwrite64", (sqlite3_syscall_ptr)0, 0 },
2934729522
#endif
29348
-#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
29523
+#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
2934929524
aSyscall[13].pCurrent)
2935029525
2935129526
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
2935229527
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
2935329528
@@ -33208,14 +33383,16 @@
3320833383
sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
3320933384
#endif
3321033385
pShmNode->h = -1;
3321133386
pDbFd->pInode->pShmNode = pShmNode;
3321233387
pShmNode->pInode = pDbFd->pInode;
33213
- pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33214
- if( pShmNode->mutex==0 ){
33215
- rc = SQLITE_NOMEM_BKPT;
33216
- goto shm_open_err;
33388
+ if( sqlite3GlobalConfig.bCoreMutex ){
33389
+ pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33390
+ if( pShmNode->mutex==0 ){
33391
+ rc = SQLITE_NOMEM_BKPT;
33392
+ goto shm_open_err;
33393
+ }
3321733394
}
3321833395
3321933396
if( pInode->bProcessLock==0 ){
3322033397
int openFlags = O_RDWR | O_CREAT;
3322133398
if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34507,28 @@
3433034507
"/var/tmp",
3433134508
"/usr/tmp",
3433234509
"/tmp",
3433334510
"."
3433434511
};
34335
- unsigned int i;
34512
+ unsigned int i = 0;
3433634513
struct stat buf;
3433734514
const char *zDir = sqlite3_temp_directory;
3433834515
3433934516
if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
3434034517
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34341
- for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34342
- if( zDir==0 ) continue;
34343
- if( osStat(zDir, &buf) ) continue;
34344
- if( !S_ISDIR(buf.st_mode) ) continue;
34345
- if( osAccess(zDir, 07) ) continue;
34346
- break;
34347
- }
34348
- return zDir;
34518
+ while(1){
34519
+ if( zDir!=0
34520
+ && osStat(zDir, &buf)==0
34521
+ && S_ISDIR(buf.st_mode)
34522
+ && osAccess(zDir, 03)==0
34523
+ ){
34524
+ return zDir;
34525
+ }
34526
+ if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
34527
+ zDir = azDirs[i++];
34528
+ }
34529
+ return 0;
3434934530
}
3435034531
3435134532
/*
3435234533
** Create a temporary file name in zBuf. zBuf must be allocated
3435334534
** by the calling process and must be big enough to hold at least
@@ -34359,13 +34540,15 @@
3435934540
3436034541
/* It's odd to simulate an io-error here, but really this is just
3436134542
** using the io-error infrastructure to test that SQLite handles this
3436234543
** function failing.
3436334544
*/
34545
+ zBuf[0] = 0;
3436434546
SimulateIOError( return SQLITE_IOERR );
3436534547
3436634548
zDir = unixTempFileDir();
34549
+ if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
3436734550
do{
3436834551
u64 r;
3436934552
sqlite3_randomness(sizeof(r), &r);
3437034553
assert( nBuf>2 );
3437134554
zBuf[nBuf-2] = 0;
@@ -37963,12 +38146,12 @@
3796338146
*/
3796438147
SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
3796538148
int rc;
3796638149
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
3796738150
MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
37968
- MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
37969
- MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
38151
+ MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
38152
+ MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
3797038153
sqlite3_mutex_enter(pMaster);
3797138154
sqlite3_mutex_enter(pMem);
3797238155
winMemAssertMagic();
3797338156
if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
3797438157
/*
@@ -38821,20 +39004,21 @@
3882139004
winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
3882239005
);
3882339006
}
3882439007
}
3882539008
38826
-#if SQLITE_OS_WINCE
38827
-/*************************************************************************
38828
-** This section contains code for WinCE only.
38829
-*/
38830
-#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API
38831
-/*
38832
-** The MSVC CRT on Windows CE may not have a localtime() function. So
38833
-** create a substitute.
38834
-*/
38835
-/* #include <time.h> */
39009
+/*
39010
+** This #if does not rely on the SQLITE_OS_WINCE define because the
39011
+** corresponding section in "date.c" cannot use it.
39012
+*/
39013
+#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
39014
+ (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
39015
+/*
39016
+** The MSVC CRT on Windows CE may not have a localtime() function.
39017
+** So define a substitute.
39018
+*/
39019
+/* # include <time.h> */
3883639020
struct tm *__cdecl localtime(const time_t *t)
3883739021
{
3883839022
static struct tm y;
3883939023
FILETIME uTm, lTm;
3884039024
SYSTEMTIME pTm;
@@ -38854,10 +39038,14 @@
3885439038
y.tm_sec = pTm.wSecond;
3885539039
return &y;
3885639040
}
3885739041
#endif
3885839042
39043
+#if SQLITE_OS_WINCE
39044
+/*************************************************************************
39045
+** This section contains code for WinCE only.
39046
+*/
3885939047
#define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
3886039048
3886139049
/*
3886239050
** Acquire a lock on the handle h
3886339051
*/
@@ -39867,13 +40055,12 @@
3986740055
/* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
3986840056
** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
3986940057
** the PENDING_LOCK byte is temporary.
3987040058
*/
3987140059
newLocktype = pFile->locktype;
39872
- if( (pFile->locktype==NO_LOCK)
39873
- || ( (locktype==EXCLUSIVE_LOCK)
39874
- && (pFile->locktype==RESERVED_LOCK))
40060
+ if( pFile->locktype==NO_LOCK
40061
+ || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
3987540062
){
3987640063
int cnt = 3;
3987740064
while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
3987840065
PENDING_BYTE, 0, 1, 0))==0 ){
3987940066
/* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40650,16 @@
4046340650
pNew = 0;
4046440651
((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
4046540652
pShmNode->pNext = winShmNodeList;
4046640653
winShmNodeList = pShmNode;
4046740654
40468
- pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40469
- if( pShmNode->mutex==0 ){
40470
- rc = SQLITE_IOERR_NOMEM_BKPT;
40471
- goto shm_open_err;
40655
+ if( sqlite3GlobalConfig.bCoreMutex ){
40656
+ pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40657
+ if( pShmNode->mutex==0 ){
40658
+ rc = SQLITE_IOERR_NOMEM_BKPT;
40659
+ goto shm_open_err;
40660
+ }
4047240661
}
4047340662
4047440663
rc = winOpen(pDbFd->pVfs,
4047540664
pShmNode->zFilename, /* Name of the file (UTF-8) */
4047640665
(sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -42930,11 +43119,33 @@
4293043119
** This file implements that page cache.
4293143120
*/
4293243121
/* #include "sqliteInt.h" */
4293343122
4293443123
/*
42935
-** A complete page cache is an instance of this structure.
43124
+** A complete page cache is an instance of this structure. Every
43125
+** entry in the cache holds a single page of the database file. The
43126
+** btree layer only operates on the cached copy of the database pages.
43127
+**
43128
+** A page cache entry is "clean" if it exactly matches what is currently
43129
+** on disk. A page is "dirty" if it has been modified and needs to be
43130
+** persisted to disk.
43131
+**
43132
+** pDirty, pDirtyTail, pSynced:
43133
+** All dirty pages are linked into the doubly linked list using
43134
+** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
43135
+** such that p was added to the list more recently than p->pDirtyNext.
43136
+** PCache.pDirty points to the first (newest) element in the list and
43137
+** pDirtyTail to the last (oldest).
43138
+**
43139
+** The PCache.pSynced variable is used to optimize searching for a dirty
43140
+** page to eject from the cache mid-transaction. It is better to eject
43141
+** a page that does not require a journal sync than one that does.
43142
+** Therefore, pSynced is maintained to that it *almost* always points
43143
+** to either the oldest page in the pDirty/pDirtyTail list that has a
43144
+** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
43145
+** (so that the right page to eject can be found by following pDirtyPrev
43146
+** pointers).
4293643147
*/
4293743148
struct PCache {
4293843149
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
4293943150
PgHdr *pSynced; /* Last synced page in dirty page list */
4294043151
int nRefSum; /* Sum of ref counts over all pages */
@@ -42946,10 +43157,99 @@
4294643157
u8 eCreate; /* eCreate value for for xFetch() */
4294743158
int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
4294843159
void *pStress; /* Argument to xStress */
4294943160
sqlite3_pcache *pCache; /* Pluggable cache module */
4295043161
};
43162
+
43163
+/********************************** Test and Debug Logic **********************/
43164
+/*
43165
+** Debug tracing macros. Enable by by changing the "0" to "1" and
43166
+** recompiling.
43167
+**
43168
+** When sqlite3PcacheTrace is 1, single line trace messages are issued.
43169
+** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
43170
+** is displayed for many operations, resulting in a lot of output.
43171
+*/
43172
+#if defined(SQLITE_DEBUG) && 0
43173
+ int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
43174
+ int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
43175
+# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
43176
+ void pcacheDump(PCache *pCache){
43177
+ int N;
43178
+ int i, j;
43179
+ sqlite3_pcache_page *pLower;
43180
+ PgHdr *pPg;
43181
+ unsigned char *a;
43182
+
43183
+ if( sqlite3PcacheTrace<2 ) return;
43184
+ if( pCache->pCache==0 ) return;
43185
+ N = sqlite3PcachePagecount(pCache);
43186
+ if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
43187
+ for(i=1; i<=N; i++){
43188
+ pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
43189
+ if( pLower==0 ) continue;
43190
+ pPg = (PgHdr*)pLower->pExtra;
43191
+ printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
43192
+ a = (unsigned char *)pLower->pBuf;
43193
+ for(j=0; j<12; j++) printf("%02x", a[j]);
43194
+ printf("\n");
43195
+ if( pPg->pPage==0 ){
43196
+ sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
43197
+ }
43198
+ }
43199
+ }
43200
+ #else
43201
+# define pcacheTrace(X)
43202
+# define pcacheDump(X)
43203
+#endif
43204
+
43205
+/*
43206
+** Check invariants on a PgHdr entry. Return true if everything is OK.
43207
+** Return false if any invariant is violated.
43208
+**
43209
+** This routine is for use inside of assert() statements only. For
43210
+** example:
43211
+**
43212
+** assert( sqlite3PcachePageSanity(pPg) );
43213
+*/
43214
+#if SQLITE_DEBUG
43215
+SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43216
+ PCache *pCache;
43217
+ assert( pPg!=0 );
43218
+ assert( pPg->pgno>0 ); /* Page number is 1 or more */
43219
+ pCache = pPg->pCache;
43220
+ assert( pCache!=0 ); /* Every page has an associated PCache */
43221
+ if( pPg->flags & PGHDR_CLEAN ){
43222
+ assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43223
+ assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
43224
+ assert( pCache->pDirtyTail!=pPg );
43225
+ }
43226
+ /* WRITEABLE pages must also be DIRTY */
43227
+ if( pPg->flags & PGHDR_WRITEABLE ){
43228
+ assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
43229
+ }
43230
+ /* NEED_SYNC can be set independently of WRITEABLE. This can happen,
43231
+ ** for example, when using the sqlite3PagerDontWrite() optimization:
43232
+ ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
43233
+ ** (2) Page X moved to freelist, WRITEABLE is cleared
43234
+ ** (3) Page X reused, WRITEABLE is set again
43235
+ ** If NEED_SYNC had been cleared in step 2, then it would not be reset
43236
+ ** in step 3, and page might be written into the database without first
43237
+ ** syncing the rollback journal, which might cause corruption on a power
43238
+ ** loss.
43239
+ **
43240
+ ** Another example is when the database page size is smaller than the
43241
+ ** disk sector size. When any page of a sector is journalled, all pages
43242
+ ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
43243
+ ** in case they are later modified, since all pages in the same sector
43244
+ ** must be journalled and synced before any of those pages can be safely
43245
+ ** written.
43246
+ */
43247
+ return 1;
43248
+}
43249
+#endif /* SQLITE_DEBUG */
43250
+
4295143251
4295243252
/********************************** Linked List Management ********************/
4295343253
4295443254
/* Allowed values for second argument to pcacheManageDirtyList() */
4295543255
#define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -42963,21 +43263,20 @@
4296343263
** the dirty list. Doing both moves pPage to the front of the dirty list.
4296443264
*/
4296543265
static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
4296643266
PCache *p = pPage->pCache;
4296743267
43268
+ pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
43269
+ addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
43270
+ pPage->pgno));
4296843271
if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
4296943272
assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
4297043273
assert( pPage->pDirtyPrev || pPage==p->pDirty );
4297143274
4297243275
/* Update the PCache1.pSynced variable if necessary. */
4297343276
if( p->pSynced==pPage ){
42974
- PgHdr *pSynced = pPage->pDirtyPrev;
42975
- while( pSynced && (pSynced->flags&PGHDR_NEED_SYNC) ){
42976
- pSynced = pSynced->pDirtyPrev;
42977
- }
42978
- p->pSynced = pSynced;
43277
+ p->pSynced = pPage->pDirtyPrev;
4297943278
}
4298043279
4298143280
if( pPage->pDirtyNext ){
4298243281
pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
4298343282
}else{
@@ -42985,14 +43284,19 @@
4298543284
p->pDirtyTail = pPage->pDirtyPrev;
4298643285
}
4298743286
if( pPage->pDirtyPrev ){
4298843287
pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
4298943288
}else{
43289
+ /* If there are now no dirty pages in the cache, set eCreate to 2.
43290
+ ** This is an optimization that allows sqlite3PcacheFetch() to skip
43291
+ ** searching for a dirty page to eject from the cache when it might
43292
+ ** otherwise have to. */
4299043293
assert( pPage==p->pDirty );
4299143294
p->pDirty = pPage->pDirtyNext;
42992
- if( p->pDirty==0 && p->bPurgeable ){
42993
- assert( p->eCreate==1 );
43295
+ assert( p->bPurgeable || p->eCreate==2 );
43296
+ if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
43297
+ assert( p->bPurgeable==0 || p->eCreate==1 );
4299443298
p->eCreate = 2;
4299543299
}
4299643300
}
4299743301
pPage->pDirtyNext = 0;
4299843302
pPage->pDirtyPrev = 0;
@@ -43010,23 +43314,34 @@
4301043314
assert( p->eCreate==2 );
4301143315
p->eCreate = 1;
4301243316
}
4301343317
}
4301443318
p->pDirty = pPage;
43015
- if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
43319
+
43320
+ /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
43321
+ ** pSynced to point to it. Checking the NEED_SYNC flag is an
43322
+ ** optimization, as if pSynced points to a page with the NEED_SYNC
43323
+ ** flag set sqlite3PcacheFetchStress() searches through all newer
43324
+ ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
43325
+ if( !p->pSynced
43326
+ && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
43327
+ ){
4301643328
p->pSynced = pPage;
4301743329
}
4301843330
}
43331
+ pcacheDump(p);
4301943332
}
4302043333
4302143334
/*
4302243335
** Wrapper around the pluggable caches xUnpin method. If the cache is
4302343336
** being used for an in-memory database, this function is a no-op.
4302443337
*/
4302543338
static void pcacheUnpin(PgHdr *p){
4302643339
if( p->pCache->bPurgeable ){
43340
+ pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
4302743341
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
43342
+ pcacheDump(p->pCache);
4302843343
}
4302943344
}
4303043345
4303143346
/*
4303243347
** Compute the number of pages of cache requested. p->szCache is the
@@ -43092,10 +43407,11 @@
4309243407
p->eCreate = 2;
4309343408
p->xStress = xStress;
4309443409
p->pStress = pStress;
4309543410
p->szCache = 100;
4309643411
p->szSpill = 1;
43412
+ pcacheTrace(("%p.OPEN szPage %d bPurgeable %d\n",p,szPage,bPurgeable));
4309743413
return sqlite3PcacheSetPageSize(p, szPage);
4309843414
}
4309943415
4310043416
/*
4310143417
** Change the page size for PCache object. The caller must ensure that there
@@ -43114,10 +43430,11 @@
4311443430
if( pCache->pCache ){
4311543431
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
4311643432
}
4311743433
pCache->pCache = pNew;
4311843434
pCache->szPage = szPage;
43435
+ pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
4311943436
}
4312043437
return SQLITE_OK;
4312143438
}
4312243439
4312343440
/*
@@ -43148,15 +43465,17 @@
4314843465
PCache *pCache, /* Obtain the page from this cache */
4314943466
Pgno pgno, /* Page number to obtain */
4315043467
int createFlag /* If true, create page if it does not exist already */
4315143468
){
4315243469
int eCreate;
43470
+ sqlite3_pcache_page *pRes;
4315343471
4315443472
assert( pCache!=0 );
4315543473
assert( pCache->pCache!=0 );
4315643474
assert( createFlag==3 || createFlag==0 );
4315743475
assert( pgno>0 );
43476
+ assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
4315843477
4315943478
/* eCreate defines what to do if the page does not exist.
4316043479
** 0 Do not allocate a new page. (createFlag==0)
4316143480
** 1 Allocate a new page if doing so is inexpensive.
4316243481
** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43165,16 +43484,19 @@
4316543484
*/
4316643485
eCreate = createFlag & pCache->eCreate;
4316743486
assert( eCreate==0 || eCreate==1 || eCreate==2 );
4316843487
assert( createFlag==0 || pCache->eCreate==eCreate );
4316943488
assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43170
- return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43489
+ pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43490
+ pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
43491
+ createFlag?" create":"",pRes));
43492
+ return pRes;
4317143493
}
4317243494
4317343495
/*
4317443496
** If the sqlite3PcacheFetch() routine is unable to allocate a new
43175
-** page because new clean pages are available for reuse and the cache
43497
+** page because no clean pages are available for reuse and the cache
4317643498
** size limit has been reached, then this routine can be invoked to
4317743499
** try harder to allocate a page. This routine might invoke the stress
4317843500
** callback to spill dirty pages to the journal. It will then try to
4317943501
** allocate the new page and will only fail to allocate a new page on
4318043502
** an OOM error.
@@ -43192,11 +43514,15 @@
4319243514
if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
4319343515
/* Find a dirty page to write-out and recycle. First try to find a
4319443516
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
4319543517
** cleared), but if that is not possible settle for any other
4319643518
** unreferenced dirty page.
43197
- */
43519
+ **
43520
+ ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
43521
+ ** flag is currently referenced, then the following may leave pSynced
43522
+ ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
43523
+ ** cleared). This is Ok, as pSynced is just an optimization. */
4319843524
for(pPg=pCache->pSynced;
4319943525
pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
4320043526
pPg=pPg->pDirtyPrev
4320143527
);
4320243528
pCache->pSynced = pPg;
@@ -43210,11 +43536,13 @@
4321043536
"spill page %d making room for %d - cache used: %d/%d",
4321143537
pPg->pgno, pgno,
4321243538
sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
4321343539
numberOfCachePages(pCache));
4321443540
#endif
43541
+ pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
4321543542
rc = pCache->xStress(pCache->pStress, pPg);
43543
+ pcacheDump(pCache);
4321643544
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
4321743545
return rc;
4321843546
}
4321943547
}
4322043548
}
@@ -43270,10 +43598,11 @@
4327043598
if( !pPgHdr->pPage ){
4327143599
return pcacheFetchFinishWithInit(pCache, pgno, pPage);
4327243600
}
4327343601
pCache->nRefSum++;
4327443602
pPgHdr->nRef++;
43603
+ assert( sqlite3PcachePageSanity(pPgHdr) );
4327543604
return pPgHdr;
4327643605
}
4327743606
4327843607
/*
4327943608
** Decrement the reference count on a page. If the page is clean and the
@@ -43283,12 +43612,15 @@
4328343612
assert( p->nRef>0 );
4328443613
p->pCache->nRefSum--;
4328543614
if( (--p->nRef)==0 ){
4328643615
if( p->flags&PGHDR_CLEAN ){
4328743616
pcacheUnpin(p);
43288
- }else if( p->pDirtyPrev!=0 ){
43289
- /* Move the page to the head of the dirty list. */
43617
+ }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
43618
+ /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
43619
+ ** then page p is already at the head of the dirty list and the
43620
+ ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
43621
+ ** tag above. */
4329043622
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
4329143623
}
4329243624
}
4329343625
}
4329443626
@@ -43295,10 +43627,11 @@
4329543627
/*
4329643628
** Increase the reference count of a supplied page by 1.
4329743629
*/
4329843630
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
4329943631
assert(p->nRef>0);
43632
+ assert( sqlite3PcachePageSanity(p) );
4330043633
p->nRef++;
4330143634
p->pCache->nRefSum++;
4330243635
}
4330343636
4330443637
/*
@@ -43306,10 +43639,11 @@
4330643639
** page. This function deletes that reference, so after it returns the
4330743640
** page pointed to by p is invalid.
4330843641
*/
4330943642
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
4331043643
assert( p->nRef==1 );
43644
+ assert( sqlite3PcachePageSanity(p) );
4331143645
if( p->flags&PGHDR_DIRTY ){
4331243646
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
4331343647
}
4331443648
p->pCache->nRefSum--;
4331543649
sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43319,30 +43653,36 @@
4331943653
** Make sure the page is marked as dirty. If it isn't dirty already,
4332043654
** make it so.
4332143655
*/
4332243656
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
4332343657
assert( p->nRef>0 );
43324
- if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){
43658
+ assert( sqlite3PcachePageSanity(p) );
43659
+ if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
4332543660
p->flags &= ~PGHDR_DONT_WRITE;
4332643661
if( p->flags & PGHDR_CLEAN ){
4332743662
p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
43663
+ pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
4332843664
assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
4332943665
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
4333043666
}
43667
+ assert( sqlite3PcachePageSanity(p) );
4333143668
}
4333243669
}
4333343670
4333443671
/*
4333543672
** Make sure the page is marked as clean. If it isn't clean already,
4333643673
** make it so.
4333743674
*/
4333843675
SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43339
- if( (p->flags & PGHDR_DIRTY) ){
43676
+ assert( sqlite3PcachePageSanity(p) );
43677
+ if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){
4334043678
assert( (p->flags & PGHDR_CLEAN)==0 );
4334143679
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
4334243680
p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
4334343681
p->flags |= PGHDR_CLEAN;
43682
+ pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
43683
+ assert( sqlite3PcachePageSanity(p) );
4334443684
if( p->nRef==0 ){
4334543685
pcacheUnpin(p);
4334643686
}
4334743687
}
4334843688
}
@@ -43350,14 +43690,27 @@
4335043690
/*
4335143691
** Make every page in the cache clean.
4335243692
*/
4335343693
SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
4335443694
PgHdr *p;
43695
+ pcacheTrace(("%p.CLEAN-ALL\n",pCache));
4335543696
while( (p = pCache->pDirty)!=0 ){
4335643697
sqlite3PcacheMakeClean(p);
4335743698
}
4335843699
}
43700
+
43701
+/*
43702
+** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43703
+*/
43704
+SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43705
+ PgHdr *p;
43706
+ pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
43707
+ for(p=pCache->pDirty; p; p=p->pDirtyNext){
43708
+ p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43709
+ }
43710
+ pCache->pSynced = pCache->pDirtyTail;
43711
+}
4335943712
4336043713
/*
4336143714
** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
4336243715
*/
4336343716
SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43373,10 +43726,12 @@
4337343726
*/
4337443727
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
4337543728
PCache *pCache = p->pCache;
4337643729
assert( p->nRef>0 );
4337743730
assert( newPgno>0 );
43731
+ assert( sqlite3PcachePageSanity(p) );
43732
+ pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
4337843733
sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
4337943734
p->pgno = newPgno;
4338043735
if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
4338143736
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
4338243737
}
@@ -43393,18 +43748,19 @@
4339343748
*/
4339443749
SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
4339543750
if( pCache->pCache ){
4339643751
PgHdr *p;
4339743752
PgHdr *pNext;
43753
+ pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
4339843754
for(p=pCache->pDirty; p; p=pNext){
4339943755
pNext = p->pDirtyNext;
4340043756
/* This routine never gets call with a positive pgno except right
4340143757
** after sqlite3PcacheCleanAll(). So if there are dirty pages,
4340243758
** it must be that pgno==0.
4340343759
*/
4340443760
assert( p->pgno>0 );
43405
- if( ALWAYS(p->pgno>pgno) ){
43761
+ if( p->pgno>pgno ){
4340643762
assert( p->flags&PGHDR_DIRTY );
4340743763
sqlite3PcacheMakeClean(p);
4340843764
}
4340943765
}
4341043766
if( pgno==0 && pCache->nRefSum ){
@@ -43423,10 +43779,11 @@
4342343779
/*
4342443780
** Close a cache.
4342543781
*/
4342643782
SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
4342743783
assert( pCache->pCache!=0 );
43784
+ pcacheTrace(("%p.CLOSE\n",pCache));
4342843785
sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
4342943786
}
4343043787
4343143788
/*
4343243789
** Discard the contents of the cache.
@@ -43591,10 +43948,21 @@
4359143948
** Return the size of the header added by this middleware layer
4359243949
** in the page-cache hierarchy.
4359343950
*/
4359443951
SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
4359543952
43953
+/*
43954
+** Return the number of dirty pages currently in the cache, as a percentage
43955
+** of the configured cache size.
43956
+*/
43957
+SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
43958
+ PgHdr *pDirty;
43959
+ int nDirty = 0;
43960
+ int nCache = numberOfCachePages(pCache);
43961
+ for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
43962
+ return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
43963
+}
4359643964
4359743965
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
4359843966
/*
4359943967
** For all dirty pages currently in the cache, invoke the specified
4360043968
** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44668,12 @@
4430044668
pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
4430144669
#endif
4430244670
4430344671
#if SQLITE_THREADSAFE
4430444672
if( sqlite3GlobalConfig.bCoreMutex ){
44305
- pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
44306
- pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
44673
+ pcache1.grp.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU);
44674
+ pcache1.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PMEM);
4430744675
}
4430844676
#endif
4430944677
if( pcache1.separateCache
4431044678
&& sqlite3GlobalConfig.nPage!=0
4431144679
&& sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45275,13 @@
4490745275
** batch number is O(NlogN) where N is the number of elements in the RowSet.
4490845276
** The cost of a TEST using the same batch number is O(logN). The cost
4490945277
** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
4491045278
** primitives are constant time. The cost of DESTROY is O(N).
4491145279
**
44912
-** There is an added cost of O(N) when switching between TEST and
44913
-** SMALLEST primitives.
45280
+** TEST and SMALLEST may not be used by the same RowSet. This used to
45281
+** be possible, but the feature was not used, so it was removed in order
45282
+** to simplify the code.
4491445283
*/
4491545284
/* #include "sqliteInt.h" */
4491645285
4491745286
4491845287
/*
@@ -45029,11 +45398,13 @@
4502945398
** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
4503045399
** routine returns NULL.
4503145400
*/
4503245401
static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
4503345402
assert( p!=0 );
45034
- if( p->nFresh==0 ){
45403
+ if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
45404
+ /* We could allocate a fresh RowSetEntry each time one is needed, but it
45405
+ ** is more efficient to pull a preallocated entry from the pool */
4503545406
struct RowSetChunk *pNew;
4503645407
pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
4503745408
if( pNew==0 ){
4503845409
return 0;
4503945410
}
@@ -45063,11 +45434,13 @@
4506345434
if( pEntry==0 ) return;
4506445435
pEntry->v = rowid;
4506545436
pEntry->pRight = 0;
4506645437
pLast = p->pLast;
4506745438
if( pLast ){
45068
- if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){
45439
+ if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/
45440
+ /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
45441
+ ** where possible */
4506945442
p->rsFlags &= ~ROWSET_SORTED;
4507045443
}
4507145444
pLast->pRight = pEntry;
4507245445
}else{
4507345446
p->pEntry = pEntry;
@@ -45185,27 +45558,33 @@
4518545558
struct RowSetEntry **ppList,
4518645559
int iDepth
4518745560
){
4518845561
struct RowSetEntry *p; /* Root of the new tree */
4518945562
struct RowSetEntry *pLeft; /* Left subtree */
45190
- if( *ppList==0 ){
45191
- return 0;
45563
+ if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
45564
+ /* Prevent unnecessary deep recursion when we run out of entries */
45565
+ return 0;
4519245566
}
45193
- if( iDepth==1 ){
45567
+ if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
45568
+ /* This branch causes a *balanced* tree to be generated. A valid tree
45569
+ ** is still generated without this branch, but the tree is wildly
45570
+ ** unbalanced and inefficient. */
45571
+ pLeft = rowSetNDeepTree(ppList, iDepth-1);
45572
+ p = *ppList;
45573
+ if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
45574
+ /* It is safe to always return here, but the resulting tree
45575
+ ** would be unbalanced */
45576
+ return pLeft;
45577
+ }
45578
+ p->pLeft = pLeft;
45579
+ *ppList = p->pRight;
45580
+ p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45581
+ }else{
4519445582
p = *ppList;
4519545583
*ppList = p->pRight;
4519645584
p->pLeft = p->pRight = 0;
45197
- return p;
45198
- }
45199
- pLeft = rowSetNDeepTree(ppList, iDepth-1);
45200
- p = *ppList;
45201
- if( p==0 ){
45202
- return pLeft;
45203
- }
45204
- p->pLeft = pLeft;
45205
- *ppList = p->pRight;
45206
- p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45585
+ }
4520745586
return p;
4520845587
}
4520945588
4521045589
/*
4521145590
** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45607,41 @@
4522845607
p->pRight = rowSetNDeepTree(&pList, iDepth);
4522945608
}
4523045609
return p;
4523145610
}
4523245611
45233
-/*
45234
-** Take all the entries on p->pEntry and on the trees in p->pForest and
45235
-** sort them all together into one big ordered list on p->pEntry.
45236
-**
45237
-** This routine should only be called once in the life of a RowSet.
45238
-*/
45239
-static void rowSetToList(RowSet *p){
45240
-
45241
- /* This routine is called only once */
45242
- assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
45243
-
45244
- if( (p->rsFlags & ROWSET_SORTED)==0 ){
45245
- p->pEntry = rowSetEntrySort(p->pEntry);
45246
- }
45247
-
45248
- /* While this module could theoretically support it, sqlite3RowSetNext()
45249
- ** is never called after sqlite3RowSetText() for the same RowSet. So
45250
- ** there is never a forest to deal with. Should this change, simply
45251
- ** remove the assert() and the #if 0. */
45252
- assert( p->pForest==0 );
45253
-#if 0
45254
- while( p->pForest ){
45255
- struct RowSetEntry *pTree = p->pForest->pLeft;
45256
- if( pTree ){
45257
- struct RowSetEntry *pHead, *pTail;
45258
- rowSetTreeToList(pTree, &pHead, &pTail);
45259
- p->pEntry = rowSetEntryMerge(p->pEntry, pHead);
45260
- }
45261
- p->pForest = p->pForest->pRight;
45262
- }
45263
-#endif
45264
- p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */
45265
-}
45266
-
4526745612
/*
4526845613
** Extract the smallest element from the RowSet.
4526945614
** Write the element into *pRowid. Return 1 on success. Return
4527045615
** 0 if the RowSet is already empty.
4527145616
**
4527245617
** After this routine has been called, the sqlite3RowSetInsert()
45273
-** routine may not be called again.
45618
+** routine may not be called again.
45619
+**
45620
+** This routine may not be called after sqlite3RowSetTest() has
45621
+** been used. Older versions of RowSet allowed that, but as the
45622
+** capability was not used by the code generator, it was removed
45623
+** for code economy.
4527445624
*/
4527545625
SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
4527645626
assert( p!=0 );
45627
+ assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
4527745628
4527845629
/* Merge the forest into a single sorted list on first call */
45279
- if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p);
45630
+ if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45631
+ if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45632
+ p->pEntry = rowSetEntrySort(p->pEntry);
45633
+ }
45634
+ p->rsFlags |= ROWSET_SORTED|ROWSET_NEXT;
45635
+ }
4528045636
4528145637
/* Return the next entry on the list */
4528245638
if( p->pEntry ){
4528345639
*pRowid = p->pEntry->v;
4528445640
p->pEntry = p->pEntry->pRight;
45285
- if( p->pEntry==0 ){
45641
+ if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
45642
+ /* Free memory immediately, rather than waiting on sqlite3_finalize() */
4528645643
sqlite3RowSetClear(p);
4528745644
}
4528845645
return 1;
4528945646
}else{
4529045647
return 0;
@@ -45303,17 +45660,19 @@
4530345660
struct RowSetEntry *p, *pTree;
4530445661
4530545662
/* This routine is never called after sqlite3RowSetNext() */
4530645663
assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
4530745664
45308
- /* Sort entries into the forest on the first test of a new batch
45665
+ /* Sort entries into the forest on the first test of a new batch.
45666
+ ** To save unnecessary work, only do this when the batch number changes.
4530945667
*/
45310
- if( iBatch!=pRowSet->iBatch ){
45668
+ if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/
4531145669
p = pRowSet->pEntry;
4531245670
if( p ){
4531345671
struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45314
- if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){
45672
+ if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45673
+ /* Only sort the current set of entiries if they need it */
4531545674
p = rowSetEntrySort(p);
4531645675
}
4531745676
for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
4531845677
ppPrevTree = &pTree->pRight;
4531945678
if( pTree->pLeft==0 ){
@@ -46383,10 +46742,11 @@
4638346742
** return SQLITE_IOERR_NOMEM while the journal file is being written). It
4638446743
** is therefore not possible for an in-memory pager to enter the ERROR
4638546744
** state.
4638646745
*/
4638746746
if( MEMDB ){
46747
+ assert( !isOpen(p->fd) );
4638846748
assert( p->noSync );
4638946749
assert( p->journalMode==PAGER_JOURNALMODE_OFF
4639046750
|| p->journalMode==PAGER_JOURNALMODE_MEMORY
4639146751
);
4639246752
assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46829,11 @@
4646946829
/* There must be at least one outstanding reference to the pager if
4647046830
** in ERROR state. Otherwise the pager should have already dropped
4647146831
** back to OPEN state.
4647246832
*/
4647346833
assert( pPager->errCode!=SQLITE_OK );
46474
- assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
46834
+ assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
4647546835
break;
4647646836
}
4647746837
4647846838
return 1;
4647946839
}
@@ -46681,10 +47041,12 @@
4668147041
}
4668247042
}
4668347043
4668447044
return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
4668547045
}
47046
+#else
47047
+# define jrnlBufferSize(x) 0
4668647048
#endif
4668747049
4668847050
/*
4668947051
** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
4669047052
** on the cache using a hash function. This is used for testing
@@ -47329,17 +47691,21 @@
4732947691
/* If Pager.errCode is set, the contents of the pager cache cannot be
4733047692
** trusted. Now that there are no outstanding references to the pager,
4733147693
** it can safely move back to PAGER_OPEN state. This happens in both
4733247694
** normal and exclusive-locking mode.
4733347695
*/
47696
+ assert( pPager->errCode==SQLITE_OK || !MEMDB );
4733447697
if( pPager->errCode ){
47335
- assert( !MEMDB );
47336
- pager_reset(pPager);
47337
- pPager->changeCountDone = pPager->tempFile;
47338
- pPager->eState = PAGER_OPEN;
47339
- pPager->errCode = SQLITE_OK;
47698
+ if( pPager->tempFile==0 ){
47699
+ pager_reset(pPager);
47700
+ pPager->changeCountDone = 0;
47701
+ pPager->eState = PAGER_OPEN;
47702
+ }else{
47703
+ pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
47704
+ }
4734047705
if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
47706
+ pPager->errCode = SQLITE_OK;
4734147707
}
4734247708
4734347709
pPager->journalOff = 0;
4734447710
pPager->journalHdr = 0;
4734547711
pPager->setMaster = 0;
@@ -47378,10 +47744,33 @@
4737847744
}
4737947745
return rc;
4738047746
}
4738147747
4738247748
static int pager_truncate(Pager *pPager, Pgno nPage);
47749
+
47750
+/*
47751
+** The write transaction open on pPager is being committed (bCommit==1)
47752
+** or rolled back (bCommit==0).
47753
+**
47754
+** Return TRUE if and only if all dirty pages should be flushed to disk.
47755
+**
47756
+** Rules:
47757
+**
47758
+** * For non-TEMP databases, always sync to disk. This is necessary
47759
+** for transactions to be durable.
47760
+**
47761
+** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
47762
+** file has been created already (via a spill on pagerStress()) and
47763
+** when the number of dirty pages in memory exceeds 25% of the total
47764
+** cache size.
47765
+*/
47766
+static int pagerFlushOnCommit(Pager *pPager, int bCommit){
47767
+ if( pPager->tempFile==0 ) return 1;
47768
+ if( !bCommit ) return 0;
47769
+ if( !isOpen(pPager->fd) ) return 0;
47770
+ return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47771
+}
4738347772
4738447773
/*
4738547774
** This routine ends a transaction. A transaction is usually ended by
4738647775
** either a COMMIT or a ROLLBACK operation. This routine may be called
4738747776
** after rollback of a hot-journal, or if an error occurs while opening
@@ -47482,11 +47871,11 @@
4748247871
}
4748347872
pPager->journalOff = 0;
4748447873
}else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
4748547874
|| (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
4748647875
){
47487
- rc = zeroJournalHdr(pPager, hasMaster);
47876
+ rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
4748847877
pPager->journalOff = 0;
4748947878
}else{
4749047879
/* This branch may be executed with Pager.journalMode==MEMORY if
4749147880
** a hot-journal was just rolled back. In this case the journal
4749247881
** file should be closed and deleted. If this connection writes to
@@ -47517,12 +47906,18 @@
4751747906
#endif
4751847907
4751947908
sqlite3BitvecDestroy(pPager->pInJournal);
4752047909
pPager->pInJournal = 0;
4752147910
pPager->nRec = 0;
47522
- sqlite3PcacheCleanAll(pPager->pPCache);
47523
- sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47911
+ if( rc==SQLITE_OK ){
47912
+ if( pagerFlushOnCommit(pPager, bCommit) ){
47913
+ sqlite3PcacheCleanAll(pPager->pPCache);
47914
+ }else{
47915
+ sqlite3PcacheClearWritable(pPager->pPCache);
47916
+ }
47917
+ sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47918
+ }
4752447919
4752547920
if( pagerUseWal(pPager) ){
4752647921
/* Drop the WAL write-lock, if any. Also, if the connection was in
4752747922
** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
4752847923
** lock held on the database file.
@@ -47802,11 +48197,11 @@
4780248197
pPg = 0;
4780348198
}else{
4780448199
pPg = sqlite3PagerLookup(pPager, pgno);
4780548200
}
4780648201
assert( pPg || !MEMDB );
47807
- assert( pPager->eState!=PAGER_OPEN || pPg==0 );
48202
+ assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
4780848203
PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
4780948204
PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
4781048205
(isMainJrnl?"main-journal":"sub-journal")
4781148206
));
4781248207
if( isMainJrnl ){
@@ -47852,11 +48247,10 @@
4785248247
pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
4785348248
rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
4785448249
assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
4785548250
pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
4785648251
if( rc!=SQLITE_OK ) return rc;
47857
- pPg->flags &= ~PGHDR_NEED_READ;
4785848252
sqlite3PcacheMakeDirty(pPg);
4785948253
}
4786048254
if( pPg ){
4786148255
/* No page should ever be explicitly rolled back that is in use, except
4786248256
** for page 1 which is held in use in order to keep the lock on the
@@ -47866,33 +48260,14 @@
4786648260
*/
4786748261
void *pData;
4786848262
pData = pPg->pData;
4786948263
memcpy(pData, (u8*)aData, pPager->pageSize);
4787048264
pPager->xReiniter(pPg);
47871
- if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
47872
- /* If the contents of this page were just restored from the main
47873
- ** journal file, then its content must be as they were when the
47874
- ** transaction was first opened. In this case we can mark the page
47875
- ** as clean, since there will be no need to write it out to the
47876
- ** database.
47877
- **
47878
- ** There is one exception to this rule. If the page is being rolled
47879
- ** back as part of a savepoint (or statement) rollback from an
47880
- ** unsynced portion of the main journal file, then it is not safe
47881
- ** to mark the page as clean. This is because marking the page as
47882
- ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
47883
- ** already in the journal file (recorded in Pager.pInJournal) and
47884
- ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
47885
- ** again within this transaction, it will be marked as dirty but
47886
- ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
47887
- ** be written out into the database file before its journal file
47888
- ** segment is synced. If a crash occurs during or following this,
47889
- ** database corruption may ensue.
47890
- */
47891
- assert( !pagerUseWal(pPager) );
47892
- sqlite3PcacheMakeClean(pPg);
47893
- }
48265
+ /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
48266
+ ** that call was dangerous and had no detectable benefit since the cache
48267
+ ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
48268
+ ** has been removed. */
4789448269
pager_set_pagehash(pPg);
4789548270
4789648271
/* If this was page 1, then restore the value of Pager.dbFileVers.
4789748272
** Do this before any decoding. */
4789848273
if( pgno==1 ){
@@ -48679,25 +49054,24 @@
4867949054
** available from the WAL sub-system if the log file is empty or
4868049055
** contains no valid committed transactions.
4868149056
*/
4868249057
assert( pPager->eState==PAGER_OPEN );
4868349058
assert( pPager->eLock>=SHARED_LOCK );
49059
+ assert( isOpen(pPager->fd) );
49060
+ assert( pPager->tempFile==0 );
4868449061
nPage = sqlite3WalDbsize(pPager->pWal);
4868549062
4868649063
/* If the number of pages in the database is not available from the
4868749064
** WAL sub-system, determine the page counte based on the size of
4868849065
** the database file. If the size of the database file is not an
4868949066
** integer multiple of the page-size, round up the result.
4869049067
*/
48691
- if( nPage==0 ){
49068
+ if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
4869249069
i64 n = 0; /* Size of db file in bytes */
48693
- assert( isOpen(pPager->fd) || pPager->tempFile );
48694
- if( isOpen(pPager->fd) ){
48695
- int rc = sqlite3OsFileSize(pPager->fd, &n);
48696
- if( rc!=SQLITE_OK ){
48697
- return rc;
48698
- }
49070
+ int rc = sqlite3OsFileSize(pPager->fd, &n);
49071
+ if( rc!=SQLITE_OK ){
49072
+ return rc;
4869949073
}
4870049074
nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
4870149075
}
4870249076
4870349077
/* If the current number of pages in the file is greater than the
@@ -49769,12 +50143,13 @@
4976950143
static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
4977050144
int rc = SQLITE_OK; /* Return code */
4977150145
4977250146
/* This function is only called for rollback pagers in WRITER_DBMOD state. */
4977350147
assert( !pagerUseWal(pPager) );
49774
- assert( pPager->eState==PAGER_WRITER_DBMOD );
50148
+ assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD );
4977550149
assert( pPager->eLock==EXCLUSIVE_LOCK );
50150
+ assert( isOpen(pPager->fd) || pList->pDirty==0 );
4977650151
4977750152
/* If the file is a temp-file has not yet been opened, open it now. It
4977850153
** is not possible for rc to be other than SQLITE_OK if this branch
4977950154
** is taken, as pager_wait_on_lock() is a no-op for temp-files.
4978050155
*/
@@ -50438,10 +50813,11 @@
5043850813
*/
5043950814
rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
5044050815
if( rc==SQLITE_OK && !locked ){
5044150816
Pgno nPage; /* Number of pages in database file */
5044250817
50818
+ assert( pPager->tempFile==0 );
5044350819
rc = pagerPagecount(pPager, &nPage);
5044450820
if( rc==SQLITE_OK ){
5044550821
/* If the database is zero pages in size, that means that either (1) the
5044650822
** journal is a remnant from a prior database with the same name where
5044750823
** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50906,21 @@
5053050906
int rc = SQLITE_OK; /* Return code */
5053150907
5053250908
/* This routine is only called from b-tree and only when there are no
5053350909
** outstanding pages. This implies that the pager state should either
5053450910
** be OPEN or READER. READER is only possible if the pager is or was in
50535
- ** exclusive access mode.
50536
- */
50911
+ ** exclusive access mode. */
5053750912
assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
5053850913
assert( assert_pager_state(pPager) );
5053950914
assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50540
- if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; }
50915
+ assert( pPager->errCode==SQLITE_OK );
5054150916
5054250917
if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
5054350918
int bHotJournal = 1; /* True if there exists a hot journal-file */
5054450919
5054550920
assert( !MEMDB );
50921
+ assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
5054650922
5054750923
rc = pager_wait_on_lock(pPager, SHARED_LOCK);
5054850924
if( rc!=SQLITE_OK ){
5054950925
assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
5055050926
goto failed;
@@ -50626,11 +51002,11 @@
5062651002
*/
5062751003
if( isOpen(pPager->jfd) ){
5062851004
assert( rc==SQLITE_OK );
5062951005
rc = pagerSyncHotJournal(pPager);
5063051006
if( rc==SQLITE_OK ){
50631
- rc = pager_playback(pPager, 1);
51007
+ rc = pager_playback(pPager, !pPager->tempFile);
5063251008
pPager->eState = PAGER_OPEN;
5063351009
}
5063451010
}else if( !pPager->exclusiveMode ){
5063551011
pagerUnlockDb(pPager, SHARED_LOCK);
5063651012
}
@@ -50722,11 +51098,11 @@
5072251098
if( pagerUseWal(pPager) ){
5072351099
assert( rc==SQLITE_OK );
5072451100
rc = pagerBeginReadTransaction(pPager);
5072551101
}
5072651102
50727
- if( pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
51103
+ if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
5072851104
rc = pagerPagecount(pPager, &pPager->dbSize);
5072951105
}
5073051106
5073151107
failed:
5073251108
if( rc!=SQLITE_OK ){
@@ -50855,11 +51231,11 @@
5085551231
rc = sqlite3OsFetch(pPager->fd,
5085651232
(i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
5085751233
);
5085851234
5085951235
if( rc==SQLITE_OK && pData ){
50860
- if( pPager->eState>PAGER_READER ){
51236
+ if( pPager->eState>PAGER_READER || pPager->tempFile ){
5086151237
pPg = sqlite3PagerLookup(pPager, pgno);
5086251238
}
5086351239
if( pPg==0 ){
5086451240
rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
5086551241
}else{
@@ -50922,11 +51298,12 @@
5092251298
if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
5092351299
rc = SQLITE_CORRUPT_BKPT;
5092451300
goto pager_acquire_err;
5092551301
}
5092651302
50927
- if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){
51303
+ assert( !isOpen(pPager->fd) || !MEMDB );
51304
+ if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
5092851305
if( pgno>pPager->mxPgno ){
5092951306
rc = SQLITE_FULL;
5093051307
goto pager_acquire_err;
5093151308
}
5093251309
if( noContent ){
@@ -51064,28 +51441,28 @@
5106451441
/* Open the journal file if it is not already open. */
5106551442
if( !isOpen(pPager->jfd) ){
5106651443
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
5106751444
sqlite3MemJournalOpen(pPager->jfd);
5106851445
}else{
51069
- const int flags = /* VFS flags to open journal file */
51070
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
51071
- (pPager->tempFile ?
51072
- (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
51073
- (SQLITE_OPEN_MAIN_JOURNAL)
51074
- );
51446
+ int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
51447
+ int nSpill;
5107551448
51449
+ if( pPager->tempFile ){
51450
+ flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
51451
+ nSpill = sqlite3Config.nStmtSpill;
51452
+ }else{
51453
+ flags |= SQLITE_OPEN_MAIN_JOURNAL;
51454
+ nSpill = jrnlBufferSize(pPager);
51455
+ }
51456
+
5107651457
/* Verify that the database still has the same name as it did when
5107751458
** it was originally opened. */
5107851459
rc = databaseIsUnmoved(pPager);
5107951460
if( rc==SQLITE_OK ){
51080
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
51081
- rc = sqlite3JournalOpen(
51082
- pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
51461
+ rc = sqlite3JournalOpen (
51462
+ pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
5108351463
);
51084
-#else
51085
- rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
51086
-#endif
5108751464
}
5108851465
}
5108951466
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
5109051467
}
5109151468
@@ -51452,10 +51829,11 @@
5145251829
return pPager->errCode;
5145351830
}else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
5145451831
if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
5145551832
return SQLITE_OK;
5145651833
}else if( pPager->sectorSize > (u32)pPager->pageSize ){
51834
+ assert( pPager->tempFile==0 );
5145751835
return pagerWriteLargeSector(pPg);
5145851836
}else{
5145951837
return pager_write(pPg);
5146051838
}
5146151839
}
@@ -51482,18 +51860,25 @@
5148251860
** on the given page is unused. The pager marks the page as clean so
5148351861
** that it does not get written to disk.
5148451862
**
5148551863
** Tests show that this optimization can quadruple the speed of large
5148651864
** DELETE operations.
51865
+**
51866
+** This optimization cannot be used with a temp-file, as the page may
51867
+** have been dirty at the start of the transaction. In that case, if
51868
+** memory pressure forces page pPg out of the cache, the data does need
51869
+** to be written out to disk so that it may be read back in if the
51870
+** current transaction is rolled back.
5148751871
*/
5148851872
SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
5148951873
Pager *pPager = pPg->pPager;
51490
- if( (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
51874
+ if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
5149151875
PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
5149251876
IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
5149351877
pPg->flags |= PGHDR_DONT_WRITE;
5149451878
pPg->flags &= ~PGHDR_WRITEABLE;
51879
+ testcase( pPg->flags & PGHDR_NEED_SYNC );
5149551880
pager_set_pagehash(pPg);
5149651881
}
5149751882
}
5149851883
5149951884
/*
@@ -51683,22 +52068,26 @@
5168352068
);
5168452069
assert( assert_pager_state(pPager) );
5168552070
5168652071
/* If a prior error occurred, report that error again. */
5168752072
if( NEVER(pPager->errCode) ) return pPager->errCode;
52073
+
52074
+ /* Provide the ability to easily simulate an I/O error during testing */
52075
+ if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
5168852076
5168952077
PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
5169052078
pPager->zFilename, zMaster, pPager->dbSize));
5169152079
5169252080
/* If no database changes have been made, return early. */
5169352081
if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
5169452082
51695
- if( MEMDB ){
52083
+ assert( MEMDB==0 || pPager->tempFile );
52084
+ assert( isOpen(pPager->fd) || pPager->tempFile );
52085
+ if( 0==pagerFlushOnCommit(pPager, 1) ){
5169652086
/* If this is an in-memory db, or no pages have been written to, or this
5169752087
** function has already been called, it is mostly a no-op. However, any
51698
- ** backup in progress needs to be restarted.
51699
- */
52088
+ ** backup in progress needs to be restarted. */
5170052089
sqlite3BackupRestart(pPager->pBackup);
5170152090
}else{
5170252091
if( pagerUseWal(pPager) ){
5170352092
PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
5170452093
PgHdr *pPageOne = 0;
@@ -52033,14 +52422,14 @@
5203352422
pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
5203452423
}
5203552424
}
5203652425
5203752426
/*
52038
-** Return true if this is an in-memory pager.
52427
+** Return true if this is an in-memory or temp-file backed pager.
5203952428
*/
5204052429
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52041
- return MEMDB;
52430
+ return pPager->tempFile;
5204252431
}
5204352432
5204452433
/*
5204552434
** Check that there are at least nSavepoint savepoints open. If there are
5204652435
** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52705,12 @@
5231652705
assert( assert_pager_state(pPager) );
5231752706
5231852707
/* In order to be able to rollback, an in-memory database must journal
5231952708
** the page we are moving from.
5232052709
*/
52321
- if( MEMDB ){
52710
+ assert( pPager->tempFile || !MEMDB );
52711
+ if( pPager->tempFile ){
5232252712
rc = sqlite3PagerWrite(pPg);
5232352713
if( rc ) return rc;
5232452714
}
5232552715
5232652716
/* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52763,11 @@
5237352763
pPg->flags &= ~PGHDR_NEED_SYNC;
5237452764
pPgOld = sqlite3PagerLookup(pPager, pgno);
5237552765
assert( !pPgOld || pPgOld->nRef==1 );
5237652766
if( pPgOld ){
5237752767
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52378
- if( MEMDB ){
52768
+ if( pPager->tempFile ){
5237952769
/* Do not discard pages from an in-memory database since we might
5238052770
** need to rollback later. Just move the page out of the way. */
5238152771
sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
5238252772
}else{
5238352773
sqlite3PcacheDrop(pPgOld);
@@ -52390,12 +52780,11 @@
5239052780
5239152781
/* For an in-memory database, make sure the original page continues
5239252782
** to exist, in case the transaction needs to roll back. Use pPgOld
5239352783
** as the original page since it has already been allocated.
5239452784
*/
52395
- if( MEMDB ){
52396
- assert( pPgOld );
52785
+ if( pPager->tempFile && pPgOld ){
5239752786
sqlite3PcacheMove(pPgOld, origPgno);
5239852787
sqlite3PagerUnrefNotNull(pPgOld);
5239952788
}
5240052789
5240152790
if( needSyncPgno ){
@@ -52643,11 +53032,12 @@
5264353032
#ifndef SQLITE_OMIT_VACUUM
5264453033
/*
5264553034
** Unless this is an in-memory or temporary database, clear the pager cache.
5264653035
*/
5264753036
SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
52648
- if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
53037
+ assert( MEMDB==0 || pPager->tempFile );
53038
+ if( pPager->tempFile==0 ) pager_reset(pPager);
5264953039
}
5265053040
#endif
5265153041
5265253042
#ifndef SQLITE_OMIT_WAL
5265353043
/*
@@ -52822,10 +53212,11 @@
5282253212
if( rc==SQLITE_OK ){
5282353213
rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
5282453214
pPager->pageSize, (u8*)pPager->pTmpSpace);
5282553215
pPager->pWal = 0;
5282653216
pagerFixMaplimit(pPager);
53217
+ if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
5282753218
}
5282853219
}
5282953220
return rc;
5283053221
}
5283153222
@@ -56277,10 +56668,27 @@
5627756668
/* Try to open on pSnapshot when the next read-transaction starts
5627856669
*/
5627956670
SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
5628056671
pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
5628156672
}
56673
+
56674
+/*
56675
+** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
56676
+** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
56677
+*/
56678
+SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
56679
+ WalIndexHdr *pHdr1 = (WalIndexHdr*)p1;
56680
+ WalIndexHdr *pHdr2 = (WalIndexHdr*)p2;
56681
+
56682
+ /* aSalt[0] is a copy of the value stored in the wal file header. It
56683
+ ** is incremented each time the wal file is restarted. */
56684
+ if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
56685
+ if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
56686
+ if( pHdr1->mxFrame<pHdr2->mxFrame ) return -1;
56687
+ if( pHdr1->mxFrame>pHdr2->mxFrame ) return +1;
56688
+ return 0;
56689
+}
5628256690
#endif /* SQLITE_ENABLE_SNAPSHOT */
5628356691
5628456692
#ifdef SQLITE_ENABLE_ZIPVFS
5628556693
/*
5628656694
** If the argument is not NULL, it points to a Wal object that holds a
@@ -58992,15 +59400,15 @@
5899259400
flagByte &= ~PTF_LEAF;
5899359401
pPage->childPtrSize = 4-4*pPage->leaf;
5899459402
pPage->xCellSize = cellSizePtr;
5899559403
pBt = pPage->pBt;
5899659404
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
58997
- /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
58998
- ** table b-tree page. */
59405
+ /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
59406
+ ** interior table b-tree page. */
5899959407
assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59000
- /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
59001
- ** table b-tree page. */
59408
+ /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
59409
+ ** leaf table b-tree page. */
5900259410
assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
5900359411
pPage->intKey = 1;
5900459412
if( pPage->leaf ){
5900559413
pPage->intKeyLeaf = 1;
5900659414
pPage->xParseCell = btreeParseCellPtr;
@@ -59010,15 +59418,15 @@
5901059418
pPage->xParseCell = btreeParseCellPtrNoPayload;
5901159419
}
5901259420
pPage->maxLocal = pBt->maxLeaf;
5901359421
pPage->minLocal = pBt->minLeaf;
5901459422
}else if( flagByte==PTF_ZERODATA ){
59015
- /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
59016
- ** index b-tree page. */
59423
+ /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
59424
+ ** interior index b-tree page. */
5901759425
assert( (PTF_ZERODATA)==2 );
59018
- /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
59019
- ** index b-tree page. */
59426
+ /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
59427
+ ** leaf index b-tree page. */
5902059428
assert( (PTF_ZERODATA|PTF_LEAF)==10 );
5902159429
pPage->intKey = 0;
5902259430
pPage->intKeyLeaf = 0;
5902359431
pPage->xParseCell = btreeParseCellPtrIndex;
5902459432
pPage->maxLocal = pBt->maxLocal;
@@ -65455,10 +65863,32 @@
6545565863
6545665864
iCellDepth = pCur->iPage;
6545765865
iCellIdx = pCur->aiIdx[iCellDepth];
6545865866
pPage = pCur->apPage[iCellDepth];
6545965867
pCell = findCell(pPage, iCellIdx);
65868
+
65869
+ /* If the bPreserve flag is set to true, then the cursor position must
65870
+ ** be preserved following this delete operation. If the current delete
65871
+ ** will cause a b-tree rebalance, then this is done by saving the cursor
65872
+ ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65873
+ ** returning.
65874
+ **
65875
+ ** Or, if the current delete will not cause a rebalance, then the cursor
65876
+ ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65877
+ ** before or after the deleted entry. In this case set bSkipnext to true. */
65878
+ if( bPreserve ){
65879
+ if( !pPage->leaf
65880
+ || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65881
+ ){
65882
+ /* A b-tree rebalance will be required after deleting this entry.
65883
+ ** Save the cursor key. */
65884
+ rc = saveCursorKey(pCur);
65885
+ if( rc ) return rc;
65886
+ }else{
65887
+ bSkipnext = 1;
65888
+ }
65889
+ }
6546065890
6546165891
/* If the page containing the entry to delete is not a leaf page, move
6546265892
** the cursor to the largest entry in the tree that is smaller than
6546365893
** the entry being deleted. This cell will replace the cell being deleted
6546465894
** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65912,10 @@
6548265912
** invalidate any incrblob cursors open on the row being deleted. */
6548365913
if( pCur->pKeyInfo==0 ){
6548465914
invalidateIncrblobCursors(p, pCur->info.nKey, 0);
6548565915
}
6548665916
65487
- /* If the bPreserve flag is set to true, then the cursor position must
65488
- ** be preserved following this delete operation. If the current delete
65489
- ** will cause a b-tree rebalance, then this is done by saving the cursor
65490
- ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65491
- ** returning.
65492
- **
65493
- ** Or, if the current delete will not cause a rebalance, then the cursor
65494
- ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65495
- ** before or after the deleted entry. In this case set bSkipnext to true. */
65496
- if( bPreserve ){
65497
- if( !pPage->leaf
65498
- || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65499
- ){
65500
- /* A b-tree rebalance will be required after deleting this entry.
65501
- ** Save the cursor key. */
65502
- rc = saveCursorKey(pCur);
65503
- if( rc ) return rc;
65504
- }else{
65505
- bSkipnext = 1;
65506
- }
65507
- }
65508
-
6550965917
/* Make the page containing the entry to be deleted writable. Then free any
6551065918
** overflow pages associated with the entry and finally remove the cell
6551165919
** itself from within the page. */
6551265920
rc = sqlite3PagerWrite(pPage->pDbPage);
6551365921
if( rc ) return rc;
@@ -70082,77 +70490,88 @@
7008270490
** indicate what the prepared statement actually does.
7008370491
**
7008470492
** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
7008570493
**
7008670494
** (5) Reclaim the memory allocated for storing labels.
70495
+**
70496
+** This routine will only function correctly if the mkopcodeh.tcl generator
70497
+** script numbers the opcodes correctly. Changes to this routine must be
70498
+** coordinated with changes to mkopcodeh.tcl.
7008770499
*/
7008870500
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
70089
- int i;
7009070501
int nMaxArgs = *pMaxFuncArgs;
7009170502
Op *pOp;
7009270503
Parse *pParse = p->pParse;
7009370504
int *aLabel = pParse->aLabel;
7009470505
p->readOnly = 1;
7009570506
p->bIsReader = 0;
70096
- for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
70097
- u8 opcode = pOp->opcode;
70098
-
70099
- /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70100
- ** cases from this switch! */
70101
- switch( opcode ){
70102
- case OP_Transaction: {
70103
- if( pOp->p2!=0 ) p->readOnly = 0;
70104
- /* fall thru */
70105
- }
70106
- case OP_AutoCommit:
70107
- case OP_Savepoint: {
70108
- p->bIsReader = 1;
70109
- break;
70110
- }
70507
+ pOp = &p->aOp[p->nOp-1];
70508
+ while(1){
70509
+
70510
+ /* Only JUMP opcodes and the short list of special opcodes in the switch
70511
+ ** below need to be considered. The mkopcodeh.tcl generator script groups
70512
+ ** all these opcodes together near the front of the opcode list. Skip
70513
+ ** any opcode that does not need processing by virtual of the fact that
70514
+ ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
70515
+ */
70516
+ if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){
70517
+ /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70518
+ ** cases from this switch! */
70519
+ switch( pOp->opcode ){
70520
+ case OP_Transaction: {
70521
+ if( pOp->p2!=0 ) p->readOnly = 0;
70522
+ /* fall thru */
70523
+ }
70524
+ case OP_AutoCommit:
70525
+ case OP_Savepoint: {
70526
+ p->bIsReader = 1;
70527
+ break;
70528
+ }
7011170529
#ifndef SQLITE_OMIT_WAL
70112
- case OP_Checkpoint:
70530
+ case OP_Checkpoint:
7011370531
#endif
70114
- case OP_Vacuum:
70115
- case OP_JournalMode: {
70116
- p->readOnly = 0;
70117
- p->bIsReader = 1;
70118
- break;
70119
- }
70532
+ case OP_Vacuum:
70533
+ case OP_JournalMode: {
70534
+ p->readOnly = 0;
70535
+ p->bIsReader = 1;
70536
+ break;
70537
+ }
7012070538
#ifndef SQLITE_OMIT_VIRTUALTABLE
70121
- case OP_VUpdate: {
70122
- if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70123
- break;
70124
- }
70125
- case OP_VFilter: {
70126
- int n;
70127
- assert( p->nOp - i >= 3 );
70128
- assert( pOp[-1].opcode==OP_Integer );
70129
- n = pOp[-1].p1;
70130
- if( n>nMaxArgs ) nMaxArgs = n;
70131
- break;
70132
- }
70133
-#endif
70134
- case OP_Next:
70135
- case OP_NextIfOpen:
70136
- case OP_SorterNext: {
70137
- pOp->p4.xAdvance = sqlite3BtreeNext;
70138
- pOp->p4type = P4_ADVANCE;
70139
- break;
70140
- }
70141
- case OP_Prev:
70142
- case OP_PrevIfOpen: {
70143
- pOp->p4.xAdvance = sqlite3BtreePrevious;
70144
- pOp->p4type = P4_ADVANCE;
70145
- break;
70146
- }
70147
- }
70148
-
70149
- pOp->opflags = sqlite3OpcodeProperty[opcode];
70150
- if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70151
- assert( ADDR(pOp->p2)<pParse->nLabel );
70152
- pOp->p2 = aLabel[ADDR(pOp->p2)];
70153
- }
70539
+ case OP_VUpdate: {
70540
+ if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70541
+ break;
70542
+ }
70543
+ case OP_VFilter: {
70544
+ int n;
70545
+ assert( (pOp - p->aOp) >= 3 );
70546
+ assert( pOp[-1].opcode==OP_Integer );
70547
+ n = pOp[-1].p1;
70548
+ if( n>nMaxArgs ) nMaxArgs = n;
70549
+ break;
70550
+ }
70551
+#endif
70552
+ case OP_Next:
70553
+ case OP_NextIfOpen:
70554
+ case OP_SorterNext: {
70555
+ pOp->p4.xAdvance = sqlite3BtreeNext;
70556
+ pOp->p4type = P4_ADVANCE;
70557
+ break;
70558
+ }
70559
+ case OP_Prev:
70560
+ case OP_PrevIfOpen: {
70561
+ pOp->p4.xAdvance = sqlite3BtreePrevious;
70562
+ pOp->p4type = P4_ADVANCE;
70563
+ break;
70564
+ }
70565
+ }
70566
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70567
+ assert( ADDR(pOp->p2)<pParse->nLabel );
70568
+ pOp->p2 = aLabel[ADDR(pOp->p2)];
70569
+ }
70570
+ }
70571
+ if( pOp==p->aOp ) break;
70572
+ pOp--;
7015470573
}
7015570574
sqlite3DbFree(p->db, pParse->aLabel);
7015670575
pParse->aLabel = 0;
7015770576
pParse->nLabel = 0;
7015870577
*pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76799,11 @@
7638076799
nByte =
7638176800
ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
7638276801
(eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
7638376802
7638476803
assert( iCur>=0 && iCur<p->nCursor );
76385
- if( p->apCsr[iCur] ){
76804
+ if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
7638676805
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
7638776806
p->apCsr[iCur] = 0;
7638876807
}
7638976808
if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
7639076809
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76876,27 @@
7645776876
u8 enc /* Use this text encoding */
7645876877
){
7645976878
if( affinity>=SQLITE_AFF_NUMERIC ){
7646076879
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
7646176880
|| affinity==SQLITE_AFF_NUMERIC );
76462
- if( (pRec->flags & MEM_Int)==0 ){
76881
+ if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
7646376882
if( (pRec->flags & MEM_Real)==0 ){
7646476883
if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
7646576884
}else{
7646676885
sqlite3VdbeIntegerAffinity(pRec);
7646776886
}
7646876887
}
7646976888
}else if( affinity==SQLITE_AFF_TEXT ){
7647076889
/* Only attempt the conversion to TEXT if there is an integer or real
7647176890
** representation (blob and NULL do not get converted) but no string
76472
- ** representation.
76473
- */
76474
- if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
76475
- sqlite3VdbeMemStringify(pRec, enc, 1);
76891
+ ** representation. It would be harmless to repeat the conversion if
76892
+ ** there is already a string rep, but it is pointless to waste those
76893
+ ** CPU cycles. */
76894
+ if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
76895
+ if( (pRec->flags&(MEM_Real|MEM_Int)) ){
76896
+ sqlite3VdbeMemStringify(pRec, enc, 1);
76897
+ }
7647676898
}
7647776899
pRec->flags &= ~(MEM_Real|MEM_Int);
7647876900
}
7647976901
}
7648076902
@@ -76796,11 +77218,11 @@
7679677218
Mem *pOut;
7679777219
assert( pOp->p2>0 );
7679877220
assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
7679977221
pOut = &p->aMem[pOp->p2];
7680077222
memAboutToChange(p, pOut);
76801
- if( VdbeMemDynamic(pOut) ){
77223
+ if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/
7680277224
return out2PrereleaseWithClear(pOut);
7680377225
}else{
7680477226
pOut->flags = MEM_Int;
7680577227
return pOut;
7680677228
}
@@ -76928,41 +77350,43 @@
7692877350
}
7692977351
#endif
7693077352
7693177353
/* Sanity checking on other operands */
7693277354
#ifdef SQLITE_DEBUG
76933
- assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
76934
- if( (pOp->opflags & OPFLG_IN1)!=0 ){
76935
- assert( pOp->p1>0 );
76936
- assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
76937
- assert( memIsValid(&aMem[pOp->p1]) );
76938
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
76939
- REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
76940
- }
76941
- if( (pOp->opflags & OPFLG_IN2)!=0 ){
76942
- assert( pOp->p2>0 );
76943
- assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76944
- assert( memIsValid(&aMem[pOp->p2]) );
76945
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
76946
- REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
76947
- }
76948
- if( (pOp->opflags & OPFLG_IN3)!=0 ){
76949
- assert( pOp->p3>0 );
76950
- assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76951
- assert( memIsValid(&aMem[pOp->p3]) );
76952
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
76953
- REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
76954
- }
76955
- if( (pOp->opflags & OPFLG_OUT2)!=0 ){
76956
- assert( pOp->p2>0 );
76957
- assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76958
- memAboutToChange(p, &aMem[pOp->p2]);
76959
- }
76960
- if( (pOp->opflags & OPFLG_OUT3)!=0 ){
76961
- assert( pOp->p3>0 );
76962
- assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76963
- memAboutToChange(p, &aMem[pOp->p3]);
77355
+ {
77356
+ u8 opProperty = sqlite3OpcodeProperty[pOp->opcode];
77357
+ if( (opProperty & OPFLG_IN1)!=0 ){
77358
+ assert( pOp->p1>0 );
77359
+ assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
77360
+ assert( memIsValid(&aMem[pOp->p1]) );
77361
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
77362
+ REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
77363
+ }
77364
+ if( (opProperty & OPFLG_IN2)!=0 ){
77365
+ assert( pOp->p2>0 );
77366
+ assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77367
+ assert( memIsValid(&aMem[pOp->p2]) );
77368
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
77369
+ REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
77370
+ }
77371
+ if( (opProperty & OPFLG_IN3)!=0 ){
77372
+ assert( pOp->p3>0 );
77373
+ assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77374
+ assert( memIsValid(&aMem[pOp->p3]) );
77375
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
77376
+ REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
77377
+ }
77378
+ if( (opProperty & OPFLG_OUT2)!=0 ){
77379
+ assert( pOp->p2>0 );
77380
+ assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77381
+ memAboutToChange(p, &aMem[pOp->p2]);
77382
+ }
77383
+ if( (opProperty & OPFLG_OUT3)!=0 ){
77384
+ assert( pOp->p3>0 );
77385
+ assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77386
+ memAboutToChange(p, &aMem[pOp->p3]);
77387
+ }
7696477388
}
7696577389
#endif
7696677390
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
7696777391
pOrigOp = pOp;
7696877392
#endif
@@ -77198,12 +77622,10 @@
7719877622
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
7719977623
** every program. So a jump past the last instruction of the program
7720077624
** is the same as executing Halt.
7720177625
*/
7720277626
case OP_Halt: {
77203
- const char *zType;
77204
- const char *zLogFmt;
7720577627
VdbeFrame *pFrame;
7720677628
int pcx;
7720777629
7720877630
pcx = (int)(pOp - aOp);
7720977631
if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77650,32 @@
7722877650
break;
7722977651
}
7723077652
p->rc = pOp->p1;
7723177653
p->errorAction = (u8)pOp->p2;
7723277654
p->pc = pcx;
77655
+ assert( pOp->p5>=0 && pOp->p5<=4 );
7723377656
if( p->rc ){
7723477657
if( pOp->p5 ){
7723577658
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
7723677659
"FOREIGN KEY" };
77237
- assert( pOp->p5>=1 && pOp->p5<=4 );
7723877660
testcase( pOp->p5==1 );
7723977661
testcase( pOp->p5==2 );
7724077662
testcase( pOp->p5==3 );
7724177663
testcase( pOp->p5==4 );
77242
- zType = azType[pOp->p5-1];
77664
+ sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]);
77665
+ if( pOp->p4.z ){
77666
+ p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
77667
+ }
7724377668
}else{
77244
- zType = 0;
77245
- }
77246
- assert( zType!=0 || pOp->p4.z!=0 );
77247
- zLogFmt = "abort at %d in [%s]: %s";
77248
- if( zType && pOp->p4.z ){
77249
- sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z);
77250
- }else if( pOp->p4.z ){
7725177669
sqlite3VdbeError(p, "%s", pOp->p4.z);
77252
- }else{
77253
- sqlite3VdbeError(p, "%s constraint failed", zType);
7725477670
}
77255
- sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
77671
+ sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
7725677672
}
7725777673
rc = sqlite3VdbeHalt(p);
7725877674
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
7725977675
if( rc==SQLITE_BUSY ){
77260
- p->rc = rc = SQLITE_BUSY;
77676
+ p->rc = SQLITE_BUSY;
7726177677
}else{
7726277678
assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
7726377679
assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
7726477680
rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
7726577681
}
@@ -77321,14 +77737,11 @@
7732177737
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
7732277738
7732377739
#ifndef SQLITE_OMIT_UTF16
7732477740
if( encoding!=SQLITE_UTF8 ){
7732577741
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77326
- if( rc ){
77327
- assert( rc==SQLITE_TOOBIG ); /* This is the only possible error here */
77328
- goto too_big;
77329
- }
77742
+ assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
7733077743
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
7733177744
assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
7733277745
assert( VdbeMemDynamic(pOut)==0 );
7733377746
pOut->szMalloc = 0;
7733477747
pOut->flags |= MEM_Static;
@@ -77337,26 +77750,30 @@
7733777750
}
7733877751
pOp->p4type = P4_DYNAMIC;
7733977752
pOp->p4.z = pOut->z;
7734077753
pOp->p1 = pOut->n;
7734177754
}
77755
+ testcase( rc==SQLITE_TOOBIG );
7734277756
#endif
7734377757
if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7734477758
goto too_big;
7734577759
}
77760
+ assert( rc==SQLITE_OK );
7734677761
/* Fall through to the next case, OP_String */
7734777762
}
7734877763
7734977764
/* Opcode: String P1 P2 P3 P4 P5
7735077765
** Synopsis: r[P2]='P4' (len=P1)
7735177766
**
7735277767
** The string value P4 of length P1 (bytes) is stored in register P2.
7735377768
**
77354
-** If P5!=0 and the content of register P3 is greater than zero, then
77769
+** If P3 is not zero and the content of register P3 is equal to P5, then
7735577770
** the datatype of the register P2 is converted to BLOB. The content is
7735677771
** the same sequence of bytes, it is merely interpreted as a BLOB instead
77357
-** of a string, as if it had been CAST.
77772
+** of a string, as if it had been CAST. In other words:
77773
+**
77774
+** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
7735877775
*/
7735977776
case OP_String: { /* out2 */
7736077777
assert( pOp->p4.z!=0 );
7736177778
pOut = out2Prerelease(p, pOp);
7736277779
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77780,15 @@
7736377780
pOut->z = pOp->p4.z;
7736477781
pOut->n = pOp->p1;
7736577782
pOut->enc = encoding;
7736677783
UPDATE_MAX_BLOBSIZE(pOut);
7736777784
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77368
- if( pOp->p5 ){
77369
- assert( pOp->p3>0 );
77785
+ if( pOp->p3>0 ){
7737077786
assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
7737177787
pIn3 = &aMem[pOp->p3];
7737277788
assert( pIn3->flags & MEM_Int );
77373
- if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77789
+ if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
7737477790
}
7737577791
#endif
7737677792
break;
7737777793
}
7737877794
@@ -82224,25 +82640,10 @@
8222482640
if( pIn1->u.i==0 ) goto jump_to_p2;
8222582641
break;
8222682642
}
8222782643
8222882644
82229
-/* Opcode: JumpZeroIncr P1 P2 * * *
82230
-** Synopsis: if (r[P1]++)==0 ) goto P2
82231
-**
82232
-** The register P1 must contain an integer. If register P1 is initially
82233
-** zero, then jump to P2. Increment register P1 regardless of whether or
82234
-** not the jump is taken.
82235
-*/
82236
-case OP_JumpZeroIncr: { /* jump, in1 */
82237
- pIn1 = &aMem[pOp->p1];
82238
- assert( pIn1->flags&MEM_Int );
82239
- VdbeBranchTaken(pIn1->u.i==0, 2);
82240
- if( (pIn1->u.i++)==0 ) goto jump_to_p2;
82241
- break;
82242
-}
82243
-
8224482645
/* Opcode: AggStep0 * P2 P3 P4 P5
8224582646
** Synopsis: accum=r[P3] step(r[P2@P5])
8224682647
**
8224782648
** Execute the step function for an aggregate. The
8224882649
** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83532,16 @@
8313183532
#ifndef NDEBUG
8313283533
assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
8313383534
8313483535
#ifdef SQLITE_DEBUG
8313583536
if( db->flags & SQLITE_VdbeTrace ){
83537
+ u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode];
8313683538
if( rc!=0 ) printf("rc=%d\n",rc);
83137
- if( pOrigOp->opflags & (OPFLG_OUT2) ){
83539
+ if( opProperty & (OPFLG_OUT2) ){
8313883540
registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
8313983541
}
83140
- if( pOrigOp->opflags & OPFLG_OUT3 ){
83542
+ if( opProperty & OPFLG_OUT3 ){
8314183543
registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
8314283544
}
8314383545
}
8314483546
#endif /* SQLITE_DEBUG */
8314583547
#endif /* NDEBUG */
@@ -84648,11 +85050,10 @@
8464885050
int nField, /* Number of key fields in each record */
8464985051
VdbeCursor *pCsr /* Cursor that holds the new sorter */
8465085052
){
8465185053
int pgsz; /* Page size of main database */
8465285054
int i; /* Used to iterate through aTask[] */
84653
- int mxCache; /* Cache size */
8465485055
VdbeSorter *pSorter; /* The new sorter */
8465585056
KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
8465685057
int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
8465785058
int sz; /* Size of pSorter in bytes */
8465885059
int rc = SQLITE_OK;
@@ -84705,15 +85106,24 @@
8470585106
SortSubtask *pTask = &pSorter->aTask[i];
8470685107
pTask->pSorter = pSorter;
8470785108
}
8470885109
8470985110
if( !sqlite3TempInMemory(db) ){
85111
+ i64 mxCache; /* Cache size in bytes*/
8471085112
u32 szPma = sqlite3GlobalConfig.szPma;
8471185113
pSorter->mnPmaSize = szPma * pgsz;
85114
+
8471285115
mxCache = db->aDb[0].pSchema->cache_size;
84713
- if( mxCache<(int)szPma ) mxCache = (int)szPma;
84714
- pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
85116
+ if( mxCache<0 ){
85117
+ /* A negative cache-size value C indicates that the cache is abs(C)
85118
+ ** KiB in size. */
85119
+ mxCache = mxCache * -1024;
85120
+ }else{
85121
+ mxCache = mxCache * pgsz;
85122
+ }
85123
+ mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
85124
+ pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
8471585125
8471685126
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
8471785127
** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
8471885128
** large heap allocations.
8471985129
*/
@@ -86473,10 +86883,19 @@
8647386883
*************************************************************************
8647486884
**
8647586885
** This file contains code use to implement an in-memory rollback journal.
8647686886
** The in-memory rollback journal is used to journal transactions for
8647786887
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
86888
+**
86889
+** Update: The in-memory journal is also used to temporarily cache
86890
+** smaller journals that are not critical for power-loss recovery.
86891
+** For example, statement journals that are not too big will be held
86892
+** entirely in memory, thus reducing the number of file I/O calls, and
86893
+** more importantly, reducing temporary file creation events. If these
86894
+** journals become too large for memory, they are spilled to disk. But
86895
+** in the common case, they are usually small and no file I/O needs to
86896
+** occur.
8647886897
*/
8647986898
/* #include "sqliteInt.h" */
8648086899
8648186900
/* Forward references to internal structures */
8648286901
typedef struct MemJournal MemJournal;
@@ -87799,10 +88218,11 @@
8779988218
notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
8780088219
sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
8780188220
assert( pNC->nRef>=nRef );
8780288221
if( nRef!=pNC->nRef ){
8780388222
ExprSetProperty(pExpr, EP_VarSelect);
88223
+ pNC->ncFlags |= NC_VarSelect;
8780488224
}
8780588225
}
8780688226
break;
8780788227
}
8780888228
case TK_VARIABLE: {
@@ -89006,19 +89426,17 @@
8900689426
if( pToken ){
8900789427
if( nExtra==0 ){
8900889428
pNew->flags |= EP_IntValue;
8900989429
pNew->u.iValue = iValue;
8901089430
}else{
89011
- int c;
8901289431
pNew->u.zToken = (char*)&pNew[1];
8901389432
assert( pToken->z!=0 || pToken->n==0 );
8901489433
if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
8901589434
pNew->u.zToken[pToken->n] = 0;
89016
- if( dequote && nExtra>=3
89017
- && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
89435
+ if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
89436
+ if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted;
8901889437
sqlite3Dequote(pNew->u.zToken);
89019
- if( c=='"' ) pNew->flags |= EP_DblQuoted;
8902089438
}
8902189439
}
8902289440
}
8902389441
#if SQLITE_MAX_EXPR_DEPTH>0
8902489442
pNew->nHeight = 1;
@@ -89096,10 +89514,26 @@
8909689514
if( p ) {
8909789515
sqlite3ExprCheckHeight(pParse, p->nHeight);
8909889516
}
8909989517
return p;
8910089518
}
89519
+
89520
+/*
89521
+** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due
89522
+** do a memory allocation failure) then delete the pSelect object.
89523
+*/
89524
+SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){
89525
+ if( pExpr ){
89526
+ pExpr->x.pSelect = pSelect;
89527
+ ExprSetProperty(pExpr, EP_xIsSelect|EP_Subquery);
89528
+ sqlite3ExprSetHeightAndFlags(pParse, pExpr);
89529
+ }else{
89530
+ assert( pParse->db->mallocFailed );
89531
+ sqlite3SelectDelete(pParse->db, pSelect);
89532
+ }
89533
+}
89534
+
8910189535
8910289536
/*
8910389537
** If the expression is always either TRUE or FALSE (respectively),
8910489538
** then return 1. If one cannot determine the truth value of the
8910589539
** expression at compile-time return 0.
@@ -89257,12 +89691,12 @@
8925789691
}
8925889692
8925989693
/*
8926089694
** Recursively delete an expression tree.
8926189695
*/
89262
-SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89263
- if( p==0 ) return;
89696
+static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
89697
+ assert( p!=0 );
8926489698
/* Sanity check: Assert that the IntValue is non-negative if it exists */
8926589699
assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
8926689700
if( !ExprHasProperty(p, EP_TokenOnly) ){
8926789701
/* The Expr.x union is never used at the same time as Expr.pRight */
8926889702
assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89710,13 @@
8927689710
}
8927789711
}
8927889712
if( !ExprHasProperty(p, EP_Static) ){
8927989713
sqlite3DbFree(db, p);
8928089714
}
89715
+}
89716
+SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89717
+ if( p ) sqlite3ExprDeleteNN(db, p);
8928189718
}
8928289719
8928389720
/*
8928489721
** Return the number of bytes allocated for the expression structure
8928589722
** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89765,11 @@
8932889765
static int dupedExprStructSize(Expr *p, int flags){
8932989766
int nSize;
8933089767
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
8933189768
assert( EXPR_FULLSIZE<=0xfff );
8933289769
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89333
- if( 0==(flags&EXPRDUP_REDUCE) ){
89770
+ if( 0==flags ){
8933489771
nSize = EXPR_FULLSIZE;
8933589772
}else{
8933689773
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
8933789774
assert( !ExprHasProperty(p, EP_FromJoin) );
8933889775
assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89827,92 @@
8939089827
** to store the copy of expression p, the copies of p->u.zToken
8939189828
** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
8939289829
** if any. Before returning, *pzBuffer is set to the first byte past the
8939389830
** portion of the buffer copied into by this function.
8939489831
*/
89395
-static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
89396
- Expr *pNew = 0; /* Value to return */
89397
- assert( flags==0 || flags==EXPRDUP_REDUCE );
89832
+static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
89833
+ Expr *pNew; /* Value to return */
89834
+ u8 *zAlloc; /* Memory space from which to build Expr object */
89835
+ u32 staticFlag; /* EP_Static if space not obtained from malloc */
89836
+
8939889837
assert( db!=0 );
89399
- if( p ){
89400
- const int isReduced = (flags&EXPRDUP_REDUCE);
89401
- u8 *zAlloc;
89402
- u32 staticFlag = 0;
89403
-
89404
- assert( pzBuffer==0 || isReduced );
89405
-
89406
- /* Figure out where to write the new Expr structure. */
89407
- if( pzBuffer ){
89408
- zAlloc = *pzBuffer;
89409
- staticFlag = EP_Static;
89410
- }else{
89411
- zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags));
89412
- }
89413
- pNew = (Expr *)zAlloc;
89414
-
89415
- if( pNew ){
89416
- /* Set nNewSize to the size allocated for the structure pointed to
89417
- ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89418
- ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89419
- ** by the copy of the p->u.zToken string (if any).
89420
- */
89421
- const unsigned nStructSize = dupedExprStructSize(p, flags);
89422
- const int nNewSize = nStructSize & 0xfff;
89423
- int nToken;
89424
- if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89425
- nToken = sqlite3Strlen30(p->u.zToken) + 1;
89426
- }else{
89427
- nToken = 0;
89428
- }
89429
- if( isReduced ){
89430
- assert( ExprHasProperty(p, EP_Reduced)==0 );
89431
- memcpy(zAlloc, p, nNewSize);
89432
- }else{
89433
- u32 nSize = (u32)exprStructSize(p);
89434
- memcpy(zAlloc, p, nSize);
89435
- if( nSize<EXPR_FULLSIZE ){
89436
- memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89437
- }
89438
- }
89439
-
89440
- /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89441
- pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89442
- pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89443
- pNew->flags |= staticFlag;
89444
-
89445
- /* Copy the p->u.zToken string, if any. */
89446
- if( nToken ){
89447
- char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89448
- memcpy(zToken, p->u.zToken, nToken);
89449
- }
89450
-
89451
- if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89452
- /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89453
- if( ExprHasProperty(p, EP_xIsSelect) ){
89454
- pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
89455
- }else{
89456
- pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
89457
- }
89458
- }
89459
-
89460
- /* Fill in pNew->pLeft and pNew->pRight. */
89461
- if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89462
- zAlloc += dupedExprNodeSize(p, flags);
89463
- if( ExprHasProperty(pNew, EP_Reduced) ){
89464
- pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
89465
- pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
89466
- }
89467
- if( pzBuffer ){
89468
- *pzBuffer = zAlloc;
89469
- }
89470
- }else{
89471
- if( !ExprHasProperty(p, EP_TokenOnly) ){
89472
- pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89473
- pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89474
- }
89475
- }
89476
-
89838
+ assert( p );
89839
+ assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
89840
+ assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE );
89841
+
89842
+ /* Figure out where to write the new Expr structure. */
89843
+ if( pzBuffer ){
89844
+ zAlloc = *pzBuffer;
89845
+ staticFlag = EP_Static;
89846
+ }else{
89847
+ zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
89848
+ staticFlag = 0;
89849
+ }
89850
+ pNew = (Expr *)zAlloc;
89851
+
89852
+ if( pNew ){
89853
+ /* Set nNewSize to the size allocated for the structure pointed to
89854
+ ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89855
+ ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89856
+ ** by the copy of the p->u.zToken string (if any).
89857
+ */
89858
+ const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
89859
+ const int nNewSize = nStructSize & 0xfff;
89860
+ int nToken;
89861
+ if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89862
+ nToken = sqlite3Strlen30(p->u.zToken) + 1;
89863
+ }else{
89864
+ nToken = 0;
89865
+ }
89866
+ if( dupFlags ){
89867
+ assert( ExprHasProperty(p, EP_Reduced)==0 );
89868
+ memcpy(zAlloc, p, nNewSize);
89869
+ }else{
89870
+ u32 nSize = (u32)exprStructSize(p);
89871
+ memcpy(zAlloc, p, nSize);
89872
+ if( nSize<EXPR_FULLSIZE ){
89873
+ memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89874
+ }
89875
+ }
89876
+
89877
+ /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89878
+ pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89879
+ pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89880
+ pNew->flags |= staticFlag;
89881
+
89882
+ /* Copy the p->u.zToken string, if any. */
89883
+ if( nToken ){
89884
+ char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89885
+ memcpy(zToken, p->u.zToken, nToken);
89886
+ }
89887
+
89888
+ if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89889
+ /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89890
+ if( ExprHasProperty(p, EP_xIsSelect) ){
89891
+ pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
89892
+ }else{
89893
+ pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
89894
+ }
89895
+ }
89896
+
89897
+ /* Fill in pNew->pLeft and pNew->pRight. */
89898
+ if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89899
+ zAlloc += dupedExprNodeSize(p, dupFlags);
89900
+ if( ExprHasProperty(pNew, EP_Reduced) ){
89901
+ pNew->pLeft = p->pLeft ?
89902
+ exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0;
89903
+ pNew->pRight = p->pRight ?
89904
+ exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
89905
+ }
89906
+ if( pzBuffer ){
89907
+ *pzBuffer = zAlloc;
89908
+ }
89909
+ }else{
89910
+ if( !ExprHasProperty(p, EP_TokenOnly) ){
89911
+ pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89912
+ pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89913
+ }
8947789914
}
8947889915
}
8947989916
return pNew;
8948089917
}
8948189918
@@ -89523,11 +89960,11 @@
8952389960
** truncated version of the usual Expr structure that will be stored as
8952489961
** part of the in-memory representation of the database schema.
8952589962
*/
8952689963
SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
8952789964
assert( flags==0 || flags==EXPRDUP_REDUCE );
89528
- return exprDup(db, p, flags, 0);
89965
+ return p ? exprDup(db, p, flags, 0) : 0;
8952989966
}
8953089967
SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
8953189968
ExprList *pNew;
8953289969
struct ExprList_item *pItem, *pOldItem;
8953389970
int i;
@@ -89745,11 +90182,11 @@
8974590182
struct ExprList_item *pItem;
8974690183
assert( pList->nExpr>0 );
8974790184
pItem = &pList->a[pList->nExpr-1];
8974890185
assert( pItem->zName==0 );
8974990186
pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
89750
- if( dequote && pItem->zName ) sqlite3Dequote(pItem->zName);
90187
+ if( dequote ) sqlite3Dequote(pItem->zName);
8975190188
}
8975290189
}
8975390190
8975490191
/*
8975590192
** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90231,24 @@
8979490231
}
8979590232
8979690233
/*
8979790234
** Delete an entire expression list.
8979890235
*/
89799
-SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90236
+static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
8980090237
int i;
8980190238
struct ExprList_item *pItem;
89802
- if( pList==0 ) return;
8980390239
assert( pList->a!=0 || pList->nExpr==0 );
8980490240
for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
8980590241
sqlite3ExprDelete(db, pItem->pExpr);
8980690242
sqlite3DbFree(db, pItem->zName);
8980790243
sqlite3DbFree(db, pItem->zSpan);
8980890244
}
8980990245
sqlite3DbFree(db, pList->a);
8981090246
sqlite3DbFree(db, pList);
90247
+}
90248
+SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90249
+ if( pList ) exprListDeleteNN(db, pList);
8981190250
}
8981290251
8981390252
/*
8981490253
** Return the bitwise-OR of all Expr.flags fields in the given
8981590254
** ExprList.
@@ -90851,10 +91290,23 @@
9085191290
#endif
9085291291
}
9085391292
}
9085491293
}
9085591294
91295
+#if defined(SQLITE_DEBUG)
91296
+/*
91297
+** Verify the consistency of the column cache
91298
+*/
91299
+static int cacheIsValid(Parse *pParse){
91300
+ int i, n;
91301
+ for(i=n=0; i<SQLITE_N_COLCACHE; i++){
91302
+ if( pParse->aColCache[i].iReg>0 ) n++;
91303
+ }
91304
+ return n==pParse->nColCache;
91305
+}
91306
+#endif
91307
+
9085691308
/*
9085791309
** Clear a cache entry.
9085891310
*/
9085991311
static void cacheEntryClear(Parse *pParse, struct yColCache *p){
9086091312
if( p->tempReg ){
@@ -90861,10 +91313,13 @@
9086191313
if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
9086291314
pParse->aTempReg[pParse->nTempReg++] = p->iReg;
9086391315
}
9086491316
p->tempReg = 0;
9086591317
}
91318
+ p->iReg = 0;
91319
+ pParse->nColCache--;
91320
+ assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
9086691321
}
9086791322
9086891323
9086991324
/*
9087091325
** Record in the column cache that a particular column from a
@@ -90904,10 +91359,12 @@
9090491359
p->iTable = iTab;
9090591360
p->iColumn = iCol;
9090691361
p->iReg = iReg;
9090791362
p->tempReg = 0;
9090891363
p->lru = pParse->iCacheCnt++;
91364
+ pParse->nColCache++;
91365
+ assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
9090991366
return;
9091091367
}
9091191368
}
9091291369
9091391370
/* Replace the last recently used */
@@ -90925,28 +91382,27 @@
9092591382
p->iTable = iTab;
9092691383
p->iColumn = iCol;
9092791384
p->iReg = iReg;
9092891385
p->tempReg = 0;
9092991386
p->lru = pParse->iCacheCnt++;
91387
+ assert( cacheIsValid(pParse) );
9093091388
return;
9093191389
}
9093291390
}
9093391391
9093491392
/*
9093591393
** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
9093691394
** Purge the range of registers from the column cache.
9093791395
*/
9093891396
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
90939
- int i;
90940
- int iLast = iReg + nReg - 1;
9094191397
struct yColCache *p;
90942
- for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90943
- int r = p->iReg;
90944
- if( r>=iReg && r<=iLast ){
90945
- cacheEntryClear(pParse, p);
90946
- p->iReg = 0;
90947
- }
91398
+ if( iReg<=0 || pParse->nColCache==0 ) return;
91399
+ p = &pParse->aColCache[SQLITE_N_COLCACHE-1];
91400
+ while(1){
91401
+ if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p);
91402
+ if( p==pParse->aColCache ) break;
91403
+ p--;
9094891404
}
9094991405
}
9095091406
9095191407
/*
9095291408
** Remember the current column cache context. Any new entries added
@@ -90978,11 +91434,10 @@
9097891434
}
9097991435
#endif
9098091436
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
9098191437
if( p->iReg && p->iLevel>pParse->iCacheLevel ){
9098291438
cacheEntryClear(pParse, p);
90983
- p->iReg = 0;
9098491439
}
9098591440
}
9098691441
}
9098791442
9098891443
/*
@@ -91113,11 +91568,10 @@
9111391568
}
9111491569
#endif
9111591570
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
9111691571
if( p->iReg ){
9111791572
cacheEntryClear(pParse, p);
91118
- p->iReg = 0;
9111991573
}
9112091574
}
9112191575
}
9112291576
9112391577
/*
@@ -91154,10 +91608,11 @@
9115491608
if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
9115591609
}
9115691610
return 0;
9115791611
}
9115891612
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
91613
+
9115991614
9116091615
/*
9116191616
** Convert an expression node to a TK_REGISTER
9116291617
*/
9116391618
static void exprToRegister(Expr *p, int iReg){
@@ -96951,20 +97406,14 @@
9695197406
** contains lookaside memory. (Table objects in the schema do not use
9695297407
** lookaside memory, but some ephemeral Table objects do.) Or the
9695397408
** db parameter can be used with db->pnBytesFreed to measure the memory
9695497409
** used by the Table object.
9695597410
*/
96956
-SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
97411
+static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
9695797412
Index *pIndex, *pNext;
9695897413
TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
9695997414
96960
- assert( !pTable || pTable->nRef>0 );
96961
-
96962
- /* Do not delete the table until the reference count reaches zero. */
96963
- if( !pTable ) return;
96964
- if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
96965
-
9696697415
/* Record the number of outstanding lookaside allocations in schema Tables
9696797416
** prior to doing any free() operations. Since schema Tables do not use
9696897417
** lookaside, this number should not change. */
9696997418
TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
9697097419
db->lookaside.nOut : 0 );
@@ -97000,10 +97449,17 @@
9700097449
sqlite3DbFree(db, pTable);
9700197450
9700297451
/* Verify that no lookaside memory was used by schema tables */
9700397452
assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
9700497453
}
97454
+SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
97455
+ /* Do not delete the table until the reference count reaches zero. */
97456
+ if( !pTable ) return;
97457
+ if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
97458
+ deleteTable(db, pTable);
97459
+}
97460
+
9700597461
9700697462
/*
9700797463
** Unlink the given table from the hash tables and the delete the
9700897464
** table structure with all its indices and foreign keys.
9700997465
*/
@@ -97445,10 +97901,11 @@
9744597901
pCol->szEst = 1;
9744697902
}else{
9744797903
zType = z + sqlite3Strlen30(z) + 1;
9744897904
memcpy(zType, pType->z, pType->n);
9744997905
zType[pType->n] = 0;
97906
+ sqlite3Dequote(zType);
9745097907
pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
9745197908
pCol->colFlags |= COLFLAG_HASTYPE;
9745297909
}
9745397910
p->nCol++;
9745497911
pParse->constraintName.n = 0;
@@ -98579,11 +99036,11 @@
9857999036
assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
9858099037
}else{
9858199038
pTable->nCol = 0;
9858299039
nErr++;
9858399040
}
98584
- if( pSelTab ) sqlite3DeleteTable(db, pSelTab);
99041
+ sqlite3DeleteTable(db, pSelTab);
9858599042
sqlite3SelectDelete(db, pSel);
9858699043
db->lookaside.bDisable--;
9858799044
} else {
9858899045
nErr++;
9858999046
}
@@ -101410,11 +101867,11 @@
101410101867
101411101868
/* Check that there isn't an ORDER BY without a LIMIT clause.
101412101869
*/
101413101870
if( pOrderBy && (pLimit == 0) ) {
101414101871
sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101415
- goto limit_where_cleanup_2;
101872
+ goto limit_where_cleanup;
101416101873
}
101417101874
101418101875
/* We only need to generate a select expression if there
101419101876
** is a limit/offset term to enforce.
101420101877
*/
@@ -101432,44 +101889,34 @@
101432101889
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101433101890
** );
101434101891
*/
101435101892
101436101893
pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101437
- if( pSelectRowid == 0 ) goto limit_where_cleanup_2;
101894
+ if( pSelectRowid == 0 ) goto limit_where_cleanup;
101438101895
pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101439
- if( pEList == 0 ) goto limit_where_cleanup_2;
101896
+ if( pEList == 0 ) goto limit_where_cleanup;
101440101897
101441101898
/* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101442101899
** and the SELECT subtree. */
101443101900
pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101444101901
if( pSelectSrc == 0 ) {
101445101902
sqlite3ExprListDelete(pParse->db, pEList);
101446
- goto limit_where_cleanup_2;
101903
+ goto limit_where_cleanup;
101447101904
}
101448101905
101449101906
/* generate the SELECT expression tree. */
101450101907
pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101451101908
pOrderBy,0,pLimit,pOffset);
101452101909
if( pSelect == 0 ) return 0;
101453101910
101454101911
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101455101912
pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101456
- if( pWhereRowid == 0 ) goto limit_where_cleanup_1;
101457
- pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
101458
- if( pInClause == 0 ) goto limit_where_cleanup_1;
101459
-
101460
- pInClause->x.pSelect = pSelect;
101461
- pInClause->flags |= EP_xIsSelect;
101462
- sqlite3ExprSetHeightAndFlags(pParse, pInClause);
101913
+ pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
101914
+ sqlite3PExprAddSelect(pParse, pInClause, pSelect);
101463101915
return pInClause;
101464101916
101465
- /* something went wrong. clean up anything allocated. */
101466
-limit_where_cleanup_1:
101467
- sqlite3SelectDelete(pParse->db, pSelect);
101468
- return 0;
101469
-
101470
-limit_where_cleanup_2:
101917
+limit_where_cleanup:
101471101918
sqlite3ExprDelete(pParse->db, pWhere);
101472101919
sqlite3ExprListDelete(pParse->db, pOrderBy);
101473101920
sqlite3ExprDelete(pParse->db, pLimit);
101474101921
sqlite3ExprDelete(pParse->db, pOffset);
101475101922
return 0;
@@ -101516,15 +101963,16 @@
101516101963
int iEphCur = 0; /* Ephemeral table holding all primary key values */
101517101964
int iRowSet = 0; /* Register for rowset of rows to delete */
101518101965
int addrBypass = 0; /* Address of jump over the delete logic */
101519101966
int addrLoop = 0; /* Top of the delete loop */
101520101967
int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
101968
+ int bComplex; /* True if there are triggers or FKs or
101969
+ ** subqueries in the WHERE clause */
101521101970
101522101971
#ifndef SQLITE_OMIT_TRIGGER
101523101972
int isView; /* True if attempting to delete from a view */
101524101973
Trigger *pTrigger; /* List of table triggers, if required */
101525
- int bComplex; /* True if there are either triggers or FKs */
101526101974
#endif
101527101975
101528101976
memset(&sContext, 0, sizeof(sContext));
101529101977
db = pParse->db;
101530101978
if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101996,10 @@
101548101996
isView = pTab->pSelect!=0;
101549101997
bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101550101998
#else
101551101999
# define pTrigger 0
101552102000
# define isView 0
101553
-# define bComplex 0
101554102001
#endif
101555102002
#ifdef SQLITE_OMIT_VIEW
101556102003
# undef isView
101557102004
# define isView 0
101558102005
#endif
@@ -101650,11 +102097,12 @@
101650102097
sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
101651102098
}
101652102099
}else
101653102100
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
101654102101
{
101655
- u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
102102
+ u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;
102103
+ if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
101656102104
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
101657102105
if( HasRowid(pTab) ){
101658102106
/* For a rowid table, initialize the RowSet to an empty set */
101659102107
pPk = 0;
101660102108
nPk = 1;
@@ -103561,10 +104009,18 @@
103561104009
static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
103562104010
const char *zFile = (const char *)sqlite3_value_text(argv[0]);
103563104011
const char *zProc;
103564104012
sqlite3 *db = sqlite3_context_db_handle(context);
103565104013
char *zErrMsg = 0;
104014
+
104015
+ /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
104016
+ ** flag is set. See the sqlite3_enable_load_extension() API.
104017
+ */
104018
+ if( (db->flags & SQLITE_LoadExtFunc)==0 ){
104019
+ sqlite3_result_error(context, "not authorized", -1);
104020
+ return;
104021
+ }
103566104022
103567104023
if( argc==2 ){
103568104024
zProc = (const char *)sqlite3_value_text(argv[1]);
103569104025
}else{
103570104026
zProc = 0;
@@ -108756,12 +109212,13 @@
108756109212
if( pzErrMsg ) *pzErrMsg = 0;
108757109213
108758109214
/* Ticket #1863. To avoid a creating security problems for older
108759109215
** applications that relink against newer versions of SQLite, the
108760109216
** ability to run load_extension is turned off by default. One
108761
- ** must call sqlite3_enable_load_extension() to turn on extension
108762
- ** loading. Otherwise you get the following error.
109217
+ ** must call either sqlite3_enable_load_extension(db) or
109218
+ ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
109219
+ ** to turn on extension loading.
108763109220
*/
108764109221
if( (db->flags & SQLITE_LoadExtension)==0 ){
108765109222
if( pzErrMsg ){
108766109223
*pzErrMsg = sqlite3_mprintf("not authorized");
108767109224
}
@@ -108896,13 +109353,13 @@
108896109353
** default so as not to open security holes in older applications.
108897109354
*/
108898109355
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
108899109356
sqlite3_mutex_enter(db->mutex);
108900109357
if( onoff ){
108901
- db->flags |= SQLITE_LoadExtension;
109358
+ db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
108902109359
}else{
108903
- db->flags &= ~SQLITE_LoadExtension;
109360
+ db->flags &= ~(SQLITE_LoadExtension|SQLITE_LoadExtFunc);
108904109361
}
108905109362
sqlite3_mutex_leave(db->mutex);
108906109363
return SQLITE_OK;
108907109364
}
108908109365
@@ -112475,11 +112932,11 @@
112475112932
sqlite3ExprListDelete(db, p->pGroupBy);
112476112933
sqlite3ExprDelete(db, p->pHaving);
112477112934
sqlite3ExprListDelete(db, p->pOrderBy);
112478112935
sqlite3ExprDelete(db, p->pLimit);
112479112936
sqlite3ExprDelete(db, p->pOffset);
112480
- sqlite3WithDelete(db, p->pWith);
112937
+ if( p->pWith ) sqlite3WithDelete(db, p->pWith);
112481112938
if( bFree ) sqlite3DbFree(db, p);
112482112939
p = pPrior;
112483112940
bFree = 1;
112484112941
}
112485112942
}
@@ -112570,11 +113027,11 @@
112570113027
112571113028
/*
112572113029
** Delete the given Select structure and all of its substructures.
112573113030
*/
112574113031
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
112575
- clearSelect(db, p, 1);
113032
+ if( p ) clearSelect(db, p, 1);
112576113033
}
112577113034
112578113035
/*
112579113036
** Return a pointer to the right-most SELECT statement in a compound.
112580113037
*/
@@ -114190,23 +114647,23 @@
114190114647
114191114648
/*
114192114649
** Get a VDBE for the given parser context. Create a new one if necessary.
114193114650
** If an error occurs, return NULL and leave a message in pParse.
114194114651
*/
114195
-SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114196
- Vdbe *v = pParse->pVdbe;
114197
- if( v==0 ){
114198
- v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114199
- if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114200
- if( pParse->pToplevel==0
114201
- && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114202
- ){
114203
- pParse->okConstFactor = 1;
114204
- }
114205
-
114652
+static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
114653
+ Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114654
+ if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114655
+ if( pParse->pToplevel==0
114656
+ && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114657
+ ){
114658
+ pParse->okConstFactor = 1;
114206114659
}
114207114660
return v;
114661
+}
114662
+SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114663
+ Vdbe *v = pParse->pVdbe;
114664
+ return v ? v : allocVdbe(pParse);
114208114665
}
114209114666
114210114667
114211114668
/*
114212114669
** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116643,22 @@
116186116643
Expr *pWhere, /* The WHERE clause of the outer query */
116187116644
int iCursor /* Cursor number of the subquery */
116188116645
){
116189116646
Expr *pNew;
116190116647
int nChng = 0;
116648
+ Select *pX; /* For looping over compound SELECTs in pSubq */
116191116649
if( pWhere==0 ) return 0;
116192
- if( (pSubq->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116193
- return 0; /* restrictions (1) and (2) */
116650
+ for(pX=pSubq; pX; pX=pX->pPrior){
116651
+ if( (pX->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116652
+ testcase( pX->selFlags & SF_Aggregate );
116653
+ testcase( pX->selFlags & SF_Recursive );
116654
+ testcase( pX!=pSubq );
116655
+ return 0; /* restrictions (1) and (2) */
116656
+ }
116194116657
}
116195116658
if( pSubq->pLimit!=0 ){
116196
- return 0; /* restriction (3) */
116659
+ return 0; /* restriction (3) */
116197116660
}
116198116661
while( pWhere->op==TK_AND ){
116199116662
nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116200116663
pWhere = pWhere->pLeft;
116201116664
}
@@ -117493,10 +117956,17 @@
117493117956
pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117494117957
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117495117958
** the sDistinct.isTnct is still set. Hence, isTnct represents the
117496117959
** original setting of the SF_Distinct flag, not the current setting */
117497117960
assert( sDistinct.isTnct );
117961
+
117962
+#if SELECTTRACE_ENABLED
117963
+ if( sqlite3SelectTrace & 0x400 ){
117964
+ SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
117965
+ sqlite3TreeViewSelect(0, p, 0);
117966
+ }
117967
+#endif
117498117968
}
117499117969
117500117970
/* If there is an ORDER BY clause, then create an ephemeral index to
117501117971
** do the sorting. But this sorting ephemeral index might end up
117502117972
** being unused if the data can be extracted in pre-sorted order.
@@ -119731,11 +120201,12 @@
119731120201
/* Begin the database scan
119732120202
*/
119733120203
if( HasRowid(pTab) ){
119734120204
sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
119735120205
pWInfo = sqlite3WhereBegin(
119736
- pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur
120206
+ pParse, pTabList, pWhere, 0, 0,
120207
+ WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur
119737120208
);
119738120209
if( pWInfo==0 ) goto update_cleanup;
119739120210
okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
119740120211
119741120212
/* Remember the rowid of every item to be updated.
@@ -121888,11 +122359,11 @@
121888122359
int addrSkip; /* Jump here for next iteration of skip-scan */
121889122360
int addrCont; /* Jump here to continue with the next loop cycle */
121890122361
int addrFirst; /* First instruction of interior of the loop */
121891122362
int addrBody; /* Beginning of the body of this loop */
121892122363
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
121893
- int iLikeRepCntr; /* LIKE range processing counter register */
122364
+ u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */
121894122365
int addrLikeRep; /* LIKE range processing address */
121895122366
#endif
121896122367
u8 iFrom; /* Which entry in the FROM clause */
121897122368
u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
121898122369
int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122697,11 @@
122226122697
*/
122227122698
struct WhereInfo {
122228122699
Parse *pParse; /* Parsing and code generating context */
122229122700
SrcList *pTabList; /* List of tables in the join */
122230122701
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122231
- ExprList *pResultSet; /* Result set. DISTINCT operates on these */
122702
+ ExprList *pDistinctSet; /* DISTINCT over all these values */
122232122703
WhereLoop *pLoops; /* List of all WhereLoop objects */
122233122704
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122234122705
LogEst nRowOut; /* Estimated number of output rows */
122235122706
LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122236122707
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122781,18 @@
122310122781
/*
122311122782
** Bitmasks for the operators on WhereTerm objects. These are all
122312122783
** operators that are of interest to the query planner. An
122313122784
** OR-ed combination of these values can be used when searching for
122314122785
** particular WhereTerms within a WhereClause.
122786
+**
122787
+** Value constraints:
122788
+** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
122789
+** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
122790
+** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
122791
+** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
122792
+** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
122793
+** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
122315122794
*/
122316122795
#define WO_IN 0x0001
122317122796
#define WO_EQ 0x0002
122318122797
#define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122319122798
#define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123375,14 @@
122896123375
return regBase;
122897123376
}
122898123377
122899123378
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122900123379
/*
122901
-** If the most recently coded instruction is a constant range contraint
122902
-** that originated from the LIKE optimization, then change the P3 to be
122903
-** pLoop->iLikeRepCntr and set P5.
123380
+** If the most recently coded instruction is a constant range constraint
123381
+** (a string literal) that originated from the LIKE optimization, then
123382
+** set P3 and P5 on the OP_String opcode so that the string will be cast
123383
+** to a BLOB at appropriate times.
122904123384
**
122905123385
** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
122906123386
** expression: "x>='ABC' AND x<'abd'". But this requires that the range
122907123387
** scan loop run twice, once for strings and a second time for BLOBs.
122908123388
** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123403,12 @@
122923123403
assert( pLevel->iLikeRepCntr>0 );
122924123404
pOp = sqlite3VdbeGetOp(v, -1);
122925123405
assert( pOp!=0 );
122926123406
assert( pOp->opcode==OP_String8
122927123407
|| pTerm->pWC->pWInfo->pParse->db->mallocFailed );
122928
- pOp->p3 = pLevel->iLikeRepCntr;
122929
- pOp->p5 = 1;
123408
+ pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
123409
+ pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
122930123410
}
122931123411
}
122932123412
#else
122933123413
# define whereLikeOptimizationStringFixup(A,B,C)
122934123414
#endif
@@ -123277,11 +123757,17 @@
123277123757
pCompare->pLeft = 0;
123278123758
sqlite3ExprDelete(db, pCompare);
123279123759
}
123280123760
}
123281123761
}
123282
- sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123762
+ /* These registers need to be preserved in case there is an IN operator
123763
+ ** loop. So we could deallocate the registers here (and potentially
123764
+ ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
123765
+ ** simpler and safer to simply not reuse the registers.
123766
+ **
123767
+ ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123768
+ */
123283123769
sqlite3ExprCachePop(pParse);
123284123770
}else
123285123771
#endif /* SQLITE_OMIT_VIRTUALTABLE */
123286123772
123287123773
if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123991,21 @@
123505123991
nExtraReg = 1;
123506123992
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123507123993
if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123508123994
assert( pRangeStart!=0 ); /* LIKE opt constraints */
123509123995
assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123510
- pLevel->iLikeRepCntr = ++pParse->nMem;
123996
+ pLevel->iLikeRepCntr = (u32)++pParse->nMem;
123997
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
123998
+ VdbeComment((v, "LIKE loop counter"));
123999
+ pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
124000
+ /* iLikeRepCntr actually stores 2x the counter register number. The
124001
+ ** bottom bit indicates whether the search order is ASC or DESC. */
123511124002
testcase( bRev );
123512124003
testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
123513
- sqlite3VdbeAddOp2(v, OP_Integer,
123514
- bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
123515
- pLevel->iLikeRepCntr);
123516
- VdbeComment((v, "LIKE loop counter"));
123517
- pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
124004
+ assert( (bRev & ~1)==0 );
124005
+ pLevel->iLikeRepCntr <<=1;
124006
+ pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
123518124007
}
123519124008
#endif
123520124009
if( pRangeStart==0
123521124010
&& (j = pIdx->aiColumn[nEq])>=0
123522124011
&& pIdx->pTable->aCol[j].notNull==0
@@ -123650,11 +124139,11 @@
123650124139
disableTerm(pLevel, pRangeStart);
123651124140
disableTerm(pLevel, pRangeEnd);
123652124141
if( omitTable ){
123653124142
/* pIdx is a covering index. No need to access the main table. */
123654124143
}else if( HasRowid(pIdx->pTable) ){
123655
- if( pWInfo->eOnePass!=ONEPASS_OFF ){
124144
+ if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){
123656124145
iRowidReg = ++pParse->nMem;
123657124146
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
123658124147
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
123659124148
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
123660124149
VdbeCoverage(v);
@@ -123846,11 +124335,12 @@
123846124335
** sub-WHERE clause is to to invoke the main loop body as a subroutine.
123847124336
*/
123848124337
wctrlFlags = WHERE_OMIT_OPEN_CLOSE
123849124338
| WHERE_FORCE_TABLE
123850124339
| WHERE_ONETABLE_ONLY
123851
- | WHERE_NO_AUTOINDEX;
124340
+ | WHERE_NO_AUTOINDEX
124341
+ | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
123852124342
for(ii=0; ii<pOrWc->nTerm; ii++){
123853124343
WhereTerm *pOrTerm = &pOrWc->a[ii];
123854124344
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
123855124345
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
123856124346
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -124026,15 +124516,21 @@
124026124516
assert( pE!=0 );
124027124517
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124028124518
continue;
124029124519
}
124030124520
if( pTerm->wtFlags & TERM_LIKECOND ){
124521
+ /* If the TERM_LIKECOND flag is set, that means that the range search
124522
+ ** is sufficient to guarantee that the LIKE operator is true, so we
124523
+ ** can skip the call to the like(A,B) function. But this only works
124524
+ ** for strings. So do not skip the call to the function on the pass
124525
+ ** that compares BLOBs. */
124031124526
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124032124527
continue;
124033124528
#else
124034
- assert( pLevel->iLikeRepCntr>0 );
124035
- skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
124529
+ u32 x = pLevel->iLikeRepCntr;
124530
+ assert( x>0 );
124531
+ skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
124036124532
VdbeCoverage(v);
124037124533
#endif
124038124534
}
124039124535
sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124040124536
if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125882,14 @@
125386125882
if( p->op==TK_COLUMN ){
125387125883
mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125388125884
return mask;
125389125885
}
125390125886
mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125391
- mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125887
+ if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125392125888
if( ExprHasProperty(p, EP_xIsSelect) ){
125393125889
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125394
- }else{
125890
+ }else if( p->x.pList ){
125395125891
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125396125892
}
125397125893
return mask;
125398125894
}
125399125895
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -125729,11 +126225,14 @@
125729126225
** Initialize a WHERE clause scanner object. Return a pointer to the
125730126226
** first match. Return NULL if there are no matches.
125731126227
**
125732126228
** The scanner will be searching the WHERE clause pWC. It will look
125733126229
** for terms of the form "X <op> <expr>" where X is column iColumn of table
125734
-** iCur. The <op> must be one of the operators described by opMask.
126230
+** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
126231
+** must be one of the indexes of table iCur.
126232
+**
126233
+** The <op> must be one of the operators described by opMask.
125735126234
**
125736126235
** If the search is for X and the WHERE clause contains terms of the
125737126236
** form X=Y then this routine might also return terms of the form
125738126237
** "Y <op> <expr>". The number of levels of transitivity is limited,
125739126238
** but is enough to handle most commonly occurring SQL statements.
@@ -125777,15 +126276,16 @@
125777126276
return whereScanNext(pScan);
125778126277
}
125779126278
125780126279
/*
125781126280
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
125782
-** where X is a reference to the iColumn of table iCur and <op> is one of
125783
-** the WO_xx operator codes specified by the op parameter.
125784
-** Return a pointer to the term. Return 0 if not found.
126281
+** where X is a reference to the iColumn of table iCur or of index pIdx
126282
+** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
126283
+** the op parameter. Return a pointer to the term. Return 0 if not found.
125785126284
**
125786
-** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
126285
+** If pIdx!=0 then it must be one of the indexes of table iCur.
126286
+** Search for terms matching the iColumn-th column of pIdx
125787126287
** rather than the iColumn-th column of table iCur.
125788126288
**
125789126289
** The term returned might by Y=<expr> if there is another constraint in
125790126290
** the WHERE clause that specifies that X=Y. Any such constraints will be
125791126291
** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
@@ -127119,15 +127619,16 @@
127119127619
/*
127120127620
** Print a WhereLoop object for debugging purposes
127121127621
*/
127122127622
static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127123127623
WhereInfo *pWInfo = pWC->pWInfo;
127124
- int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
127624
+ int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
127125127625
struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127126127626
Table *pTab = pItem->pTab;
127627
+ Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
127127127628
sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127128
- p->iTab, nb, p->maskSelf, nb, p->prereq);
127629
+ p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
127129127630
sqlite3DebugPrintf(" %12s",
127130127631
pItem->zAlias ? pItem->zAlias : pTab->zName);
127131127632
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127132127633
const char *zName;
127133127634
if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129849,13 @@
129348129849
&& (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129349129850
&& pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129350129851
&& nRowEst
129351129852
){
129352129853
Bitmask notUsed;
129353
- int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
129854
+ int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
129354129855
WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129355
- if( rc==pWInfo->pResultSet->nExpr ){
129856
+ if( rc==pWInfo->pDistinctSet->nExpr ){
129356129857
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129357129858
}
129358129859
}
129359129860
if( pWInfo->pOrderBy ){
129360129861
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +130066,18 @@
129565130066
** the first cursor in an array of cursors for all indices. iIdxCur should
129566130067
** be used to compute the appropriate cursor depending on which index is
129567130068
** used.
129568130069
*/
129569130070
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
129570
- Parse *pParse, /* The parser context */
129571
- SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129572
- Expr *pWhere, /* The WHERE clause */
129573
- ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129574
- ExprList *pResultSet, /* Result set of the query */
129575
- u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
129576
- int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number,
129577
- ** If WHERE_USE_LIMIT, then the limit amount */
130071
+ Parse *pParse, /* The parser context */
130072
+ SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
130073
+ Expr *pWhere, /* The WHERE clause */
130074
+ ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
130075
+ ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
130076
+ u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
130077
+ int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number
130078
+ ** If WHERE_USE_LIMIT, then the limit amount */
129578130079
){
129579130080
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
129580130081
int nTabList; /* Number of elements in pTabList */
129581130082
WhereInfo *pWInfo; /* Will become the return value of this function */
129582130083
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +130148,11 @@
129647130148
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
129648130149
pWInfo->nLevel = nTabList;
129649130150
pWInfo->pParse = pParse;
129650130151
pWInfo->pTabList = pTabList;
129651130152
pWInfo->pOrderBy = pOrderBy;
129652
- pWInfo->pResultSet = pResultSet;
130153
+ pWInfo->pDistinctSet = pDistinctSet;
129653130154
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
129654130155
pWInfo->wctrlFlags = wctrlFlags;
129655130156
pWInfo->iLimit = iAuxArg;
129656130157
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
129657130158
assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130221,17 @@
129720130221
/* Analyze all of the subexpressions. */
129721130222
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
129722130223
if( db->mallocFailed ) goto whereBeginError;
129723130224
129724130225
if( wctrlFlags & WHERE_WANT_DISTINCT ){
129725
- if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
130226
+ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
129726130227
/* The DISTINCT marking is pointless. Ignore it. */
129727130228
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
129728130229
}else if( pOrderBy==0 ){
129729130230
/* Try to ORDER BY the result set to make distinct processing easier */
129730130231
pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
129731
- pWInfo->pOrderBy = pResultSet;
130232
+ pWInfo->pOrderBy = pDistinctSet;
129732130233
}
129733130234
}
129734130235
129735130236
/* Construct the WhereLoop objects */
129736130237
#if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130306,14 @@
129805130306
}
129806130307
}
129807130308
#endif
129808130309
/* Attempt to omit tables from the join that do not effect the result */
129809130310
if( pWInfo->nLevel>=2
129810
- && pResultSet!=0
130311
+ && pDistinctSet!=0
129811130312
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
129812130313
){
129813
- Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
130314
+ Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
129814130315
if( sWLB.pOrderBy ){
129815130316
tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
129816130317
}
129817130318
while( pWInfo->nLevel>=2 ){
129818130319
WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130575,12 @@
130074130575
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130075130576
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130076130577
}
130077130578
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130078130579
if( pLevel->addrLikeRep ){
130079
- int op;
130080
- if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
130081
- op = OP_DecrJumpZero;
130082
- }else{
130083
- op = OP_JumpZeroIncr;
130084
- }
130085
- sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
130580
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
130581
+ pLevel->addrLikeRep);
130086130582
VdbeCoverage(v);
130087130583
}
130088130584
#endif
130089130585
if( pLevel->iLeftJoin ){
130090130586
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130982,11 @@
130486130982
#endif
130487130983
/************* Begin control #defines *****************************************/
130488130984
#define YYCODETYPE unsigned char
130489130985
#define YYNOCODE 251
130490130986
#define YYACTIONTYPE unsigned short int
130491
-#define YYWILDCARD 70
130987
+#define YYWILDCARD 96
130492130988
#define sqlite3ParserTOKENTYPE Token
130493130989
typedef union {
130494130990
int yyinit;
130495130991
sqlite3ParserTOKENTYPE yy0;
130496130992
struct LimitVal yy64;
@@ -130590,402 +131086,404 @@
130590131086
** yy_reduce_ofst[] For each state, the offset into yy_action for
130591131087
** shifting non-terminals after a reduce.
130592131088
** yy_default[] Default action for each state.
130593131089
**
130594131090
*********** Begin parsing tables **********************************************/
130595
-#define YY_ACTTAB_COUNT (1499)
131091
+#define YY_ACTTAB_COUNT (1501)
130596131092
static const YYACTIONTYPE yy_action[] = {
130597
- /* 0 */ 315, 1302, 146, 921, 2, 194, 922, 342, 952, 91,
130598
- /* 10 */ 91, 91, 91, 84, 89, 89, 89, 89, 88, 88,
130599
- /* 20 */ 87, 87, 87, 86, 339, 87, 87, 87, 86, 339,
130600
- /* 30 */ 331, 819, 819, 91, 91, 91, 91, 339, 89, 89,
130601
- /* 40 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 319,
130602
- /* 50 */ 933, 933, 92, 93, 83, 831, 834, 823, 823, 90,
130603
- /* 60 */ 90, 91, 91, 91, 91, 123, 89, 89, 89, 89,
130604
- /* 70 */ 88, 88, 87, 87, 87, 86, 339, 315, 952, 89,
130605
- /* 80 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130606
- /* 90 */ 365, 772, 360, 24, 933, 933, 947, 694, 933, 933,
130607
- /* 100 */ 773, 937, 933, 933, 434, 715, 328, 434, 819, 819,
130608
- /* 110 */ 203, 160, 278, 391, 273, 390, 190, 933, 933, 370,
130609
- /* 120 */ 934, 935, 367, 271, 953, 48, 679, 953, 48, 92,
130610
- /* 130 */ 93, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130611
- /* 140 */ 91, 91, 123, 89, 89, 89, 89, 88, 88, 87,
130612
- /* 150 */ 87, 87, 86, 339, 315, 682, 337, 336, 218, 412,
130613
- /* 160 */ 398, 68, 412, 403, 934, 935, 743, 959, 934, 935,
130614
- /* 170 */ 810, 937, 934, 935, 957, 221, 958, 88, 88, 87,
130615
- /* 180 */ 87, 87, 86, 339, 291, 819, 819, 934, 935, 185,
130616
- /* 190 */ 94, 792, 388, 385, 384, 1240, 1240, 792, 804, 960,
130617
- /* 200 */ 960, 290, 798, 383, 123, 315, 92, 93, 83, 831,
130618
- /* 210 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130619
- /* 220 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130620
- /* 230 */ 339, 681, 741, 803, 803, 803, 819, 819, 944, 56,
130621
- /* 240 */ 253, 353, 242, 85, 82, 168, 253, 358, 252, 110,
130622
- /* 250 */ 96, 233, 397, 698, 677, 683, 683, 92, 93, 83,
130623
- /* 260 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130624
- /* 270 */ 433, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130625
- /* 280 */ 86, 339, 315, 434, 439, 651, 396, 57, 733, 733,
130626
- /* 290 */ 234, 291, 107, 287, 395, 86, 339, 810, 427, 728,
130627
- /* 300 */ 933, 933, 185, 953, 30, 388, 385, 384, 215, 949,
130628
- /* 310 */ 434, 933, 933, 819, 819, 697, 383, 162, 161, 407,
130629
- /* 320 */ 400, 85, 82, 168, 677, 804, 335, 113, 771, 798,
130630
- /* 330 */ 953, 48, 22, 351, 92, 93, 83, 831, 834, 823,
130631
- /* 340 */ 823, 90, 90, 91, 91, 91, 91, 870, 89, 89,
130632
- /* 350 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 315,
130633
- /* 360 */ 803, 803, 803, 268, 123, 412, 394, 1, 933, 933,
130634
- /* 370 */ 934, 935, 933, 933, 85, 82, 168, 232, 5, 343,
130635
- /* 380 */ 194, 934, 935, 952, 85, 82, 168, 54, 956, 434,
130636
- /* 390 */ 819, 819, 431, 938, 939, 792, 67, 759, 350, 144,
130637
- /* 400 */ 166, 770, 123, 896, 889, 955, 348, 288, 758, 953,
130638
- /* 410 */ 47, 92, 93, 83, 831, 834, 823, 823, 90, 90,
130639
- /* 420 */ 91, 91, 91, 91, 892, 89, 89, 89, 89, 88,
130640
- /* 430 */ 88, 87, 87, 87, 86, 339, 315, 113, 934, 935,
130641
- /* 440 */ 687, 893, 934, 935, 253, 358, 252, 85, 82, 168,
130642
- /* 450 */ 820, 820, 956, 952, 338, 938, 939, 894, 701, 721,
130643
- /* 460 */ 359, 289, 233, 397, 434, 349, 434, 819, 819, 955,
130644
- /* 470 */ 866, 722, 23, 389, 832, 835, 692, 357, 904, 667,
130645
- /* 480 */ 194, 702, 402, 952, 953, 48, 953, 48, 92, 93,
130646
- /* 490 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130647
- /* 500 */ 91, 824, 89, 89, 89, 89, 88, 88, 87, 87,
130648
- /* 510 */ 87, 86, 339, 315, 434, 113, 434, 680, 434, 332,
130649
- /* 520 */ 434, 408, 889, 356, 380, 940, 401, 720, 948, 864,
130650
- /* 530 */ 191, 165, 329, 689, 953, 9, 953, 9, 953, 9,
130651
- /* 540 */ 953, 9, 718, 948, 819, 819, 953, 8, 325, 111,
130652
- /* 550 */ 327, 153, 224, 952, 410, 113, 189, 337, 336, 913,
130653
- /* 560 */ 1295, 852, 75, 1295, 73, 92, 93, 83, 831, 834,
130654
- /* 570 */ 823, 823, 90, 90, 91, 91, 91, 91, 359, 89,
130655
- /* 580 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130656
- /* 590 */ 315, 730, 148, 236, 797, 366, 789, 892, 1179, 434,
130657
- /* 600 */ 960, 960, 400, 148, 314, 212, 873, 911, 757, 404,
130658
- /* 610 */ 872, 300, 320, 434, 893, 311, 237, 271, 405, 953,
130659
- /* 620 */ 34, 819, 819, 225, 371, 945, 360, 913, 1296, 113,
130660
- /* 630 */ 894, 1296, 417, 953, 35, 1245, 922, 342, 259, 247,
130661
- /* 640 */ 290, 315, 92, 93, 83, 831, 834, 823, 823, 90,
130662
- /* 650 */ 90, 91, 91, 91, 91, 148, 89, 89, 89, 89,
130663
- /* 660 */ 88, 88, 87, 87, 87, 86, 339, 310, 434, 796,
130664
- /* 670 */ 434, 240, 819, 819, 266, 911, 876, 876, 373, 346,
130665
- /* 680 */ 167, 654, 655, 656, 259, 244, 19, 246, 953, 11,
130666
- /* 690 */ 953, 26, 222, 92, 93, 83, 831, 834, 823, 823,
130667
- /* 700 */ 90, 90, 91, 91, 91, 91, 757, 89, 89, 89,
130668
- /* 710 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 434,
130669
- /* 720 */ 261, 434, 264, 696, 434, 241, 434, 344, 971, 308,
130670
- /* 730 */ 757, 434, 796, 434, 324, 434, 393, 423, 434, 953,
130671
- /* 740 */ 36, 953, 37, 20, 953, 38, 953, 27, 434, 819,
130672
- /* 750 */ 819, 953, 28, 953, 39, 953, 40, 738, 953, 41,
130673
- /* 760 */ 71, 738, 737, 245, 307, 973, 737, 259, 953, 10,
130674
- /* 770 */ 92, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130675
- /* 780 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130676
- /* 790 */ 87, 87, 87, 86, 339, 315, 434, 372, 434, 259,
130677
- /* 800 */ 149, 434, 167, 953, 42, 188, 187, 186, 219, 434,
130678
- /* 810 */ 748, 434, 974, 434, 796, 434, 953, 98, 953, 43,
130679
- /* 820 */ 862, 953, 44, 434, 920, 2, 819, 819, 757, 953,
130680
- /* 830 */ 31, 953, 45, 953, 46, 953, 32, 74, 307, 912,
130681
- /* 840 */ 220, 259, 259, 953, 115, 909, 315, 92, 93, 83,
130682
- /* 850 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130683
- /* 860 */ 434, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130684
- /* 870 */ 86, 339, 434, 248, 434, 215, 949, 819, 819, 333,
130685
- /* 880 */ 953, 116, 895, 860, 176, 259, 974, 400, 361, 259,
130686
- /* 890 */ 951, 887, 953, 117, 953, 52, 884, 315, 92, 93,
130687
- /* 900 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130688
- /* 910 */ 91, 434, 89, 89, 89, 89, 88, 88, 87, 87,
130689
- /* 920 */ 87, 86, 339, 434, 113, 434, 258, 883, 819, 819,
130690
- /* 930 */ 727, 953, 33, 363, 259, 673, 321, 189, 430, 321,
130691
- /* 940 */ 368, 365, 364, 953, 99, 953, 49, 365, 315, 92,
130692
- /* 950 */ 81, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130693
- /* 960 */ 91, 91, 434, 89, 89, 89, 89, 88, 88, 87,
130694
- /* 970 */ 87, 87, 86, 339, 434, 723, 434, 214, 165, 819,
130695
- /* 980 */ 819, 772, 953, 100, 322, 124, 1269, 158, 65, 710,
130696
- /* 990 */ 773, 700, 699, 320, 953, 101, 953, 97, 255, 315,
130697
- /* 1000 */ 216, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130698
- /* 1010 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130699
- /* 1020 */ 87, 87, 87, 86, 339, 434, 251, 434, 707, 708,
130700
- /* 1030 */ 819, 819, 223, 953, 114, 908, 794, 254, 309, 193,
130701
- /* 1040 */ 67, 381, 869, 869, 199, 953, 112, 953, 105, 269,
130702
- /* 1050 */ 726, 260, 67, 83, 831, 834, 823, 823, 90, 90,
130703
- /* 1060 */ 91, 91, 91, 91, 263, 89, 89, 89, 89, 88,
130704
- /* 1070 */ 88, 87, 87, 87, 86, 339, 79, 429, 690, 3,
130705
- /* 1080 */ 1174, 228, 434, 113, 340, 340, 868, 868, 265, 79,
130706
- /* 1090 */ 429, 735, 3, 859, 70, 432, 434, 340, 340, 434,
130707
- /* 1100 */ 1259, 434, 953, 104, 434, 670, 416, 766, 432, 434,
130708
- /* 1110 */ 193, 434, 413, 434, 418, 806, 953, 102, 420, 953,
130709
- /* 1120 */ 103, 953, 48, 123, 953, 51, 810, 418, 424, 953,
130710
- /* 1130 */ 53, 953, 50, 953, 25, 267, 123, 711, 113, 810,
130711
- /* 1140 */ 428, 277, 695, 272, 764, 113, 76, 77, 690, 434,
130712
- /* 1150 */ 795, 113, 276, 78, 436, 435, 412, 414, 798, 76,
130713
- /* 1160 */ 77, 113, 855, 859, 376, 199, 78, 436, 435, 953,
130714
- /* 1170 */ 29, 798, 744, 113, 755, 79, 429, 675, 3, 415,
130715
- /* 1180 */ 109, 292, 293, 340, 340, 806, 802, 678, 672, 803,
130716
- /* 1190 */ 803, 803, 805, 18, 432, 661, 660, 662, 927, 209,
130717
- /* 1200 */ 150, 352, 803, 803, 803, 805, 18, 6, 306, 280,
130718
- /* 1210 */ 282, 284, 786, 418, 250, 386, 243, 886, 694, 362,
130719
- /* 1220 */ 286, 163, 275, 79, 429, 810, 3, 857, 856, 159,
130720
- /* 1230 */ 419, 340, 340, 298, 930, 968, 126, 196, 965, 903,
130721
- /* 1240 */ 901, 323, 432, 136, 55, 76, 77, 742, 147, 58,
130722
- /* 1250 */ 121, 129, 78, 436, 435, 65, 783, 798, 354, 131,
130723
- /* 1260 */ 355, 418, 379, 132, 133, 134, 175, 139, 151, 369,
130724
- /* 1270 */ 888, 180, 791, 810, 61, 851, 871, 69, 429, 375,
130725
- /* 1280 */ 3, 756, 210, 257, 181, 340, 340, 145, 803, 803,
130726
- /* 1290 */ 803, 805, 18, 76, 77, 377, 432, 262, 182, 183,
130727
- /* 1300 */ 78, 436, 435, 663, 312, 798, 392, 714, 713, 712,
130728
- /* 1310 */ 330, 705, 692, 313, 704, 418, 686, 406, 752, 685,
130729
- /* 1320 */ 274, 684, 942, 64, 279, 195, 281, 810, 753, 839,
130730
- /* 1330 */ 751, 283, 72, 750, 285, 422, 803, 803, 803, 805,
130731
- /* 1340 */ 18, 334, 426, 95, 411, 229, 409, 76, 77, 230,
130732
- /* 1350 */ 734, 66, 231, 294, 78, 436, 435, 204, 295, 798,
130733
- /* 1360 */ 217, 296, 297, 669, 21, 305, 304, 303, 206, 301,
130734
- /* 1370 */ 437, 928, 664, 205, 208, 207, 438, 658, 657, 652,
130735
- /* 1380 */ 118, 108, 119, 226, 650, 341, 157, 170, 169, 239,
130736
- /* 1390 */ 803, 803, 803, 805, 18, 125, 120, 235, 238, 317,
130737
- /* 1400 */ 318, 345, 106, 790, 867, 127, 865, 128, 130, 724,
130738
- /* 1410 */ 249, 172, 174, 882, 135, 137, 59, 138, 173, 60,
130739
- /* 1420 */ 885, 123, 171, 177, 178, 881, 7, 12, 179, 256,
130740
- /* 1430 */ 874, 140, 193, 962, 374, 141, 666, 152, 378, 276,
130741
- /* 1440 */ 184, 382, 142, 122, 62, 13, 387, 703, 270, 14,
130742
- /* 1450 */ 63, 227, 809, 808, 837, 732, 15, 841, 736, 4,
130743
- /* 1460 */ 765, 211, 399, 164, 213, 143, 760, 201, 70, 316,
130744
- /* 1470 */ 67, 838, 836, 891, 198, 192, 16, 197, 890, 917,
130745
- /* 1480 */ 154, 17, 202, 421, 918, 155, 200, 156, 425, 840,
130746
- /* 1490 */ 807, 1261, 676, 80, 302, 299, 347, 1260, 923,
131093
+ /* 0 */ 315, 810, 339, 804, 5, 194, 194, 798, 92, 93,
131094
+ /* 10 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
131095
+ /* 20 */ 91, 91, 91, 290, 89, 89, 89, 89, 88, 88,
131096
+ /* 30 */ 87, 87, 87, 86, 339, 315, 952, 952, 803, 803,
131097
+ /* 40 */ 803, 922, 342, 92, 93, 83, 819, 819, 831, 834,
131098
+ /* 50 */ 823, 823, 90, 90, 91, 91, 91, 91, 123, 89,
131099
+ /* 60 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131100
+ /* 70 */ 88, 88, 87, 87, 87, 86, 339, 772, 952, 952,
131101
+ /* 80 */ 315, 87, 87, 87, 86, 339, 773, 68, 92, 93,
131102
+ /* 90 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
131103
+ /* 100 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
131104
+ /* 110 */ 87, 87, 87, 86, 339, 1302, 146, 921, 2, 315,
131105
+ /* 120 */ 427, 24, 679, 953, 48, 86, 339, 92, 93, 83,
131106
+ /* 130 */ 819, 819, 831, 834, 823, 823, 90, 90, 91, 91,
131107
+ /* 140 */ 91, 91, 94, 89, 89, 89, 89, 88, 88, 87,
131108
+ /* 150 */ 87, 87, 86, 339, 933, 933, 315, 259, 412, 398,
131109
+ /* 160 */ 396, 57, 733, 733, 92, 93, 83, 819, 819, 831,
131110
+ /* 170 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 56,
131111
+ /* 180 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131112
+ /* 190 */ 339, 315, 1245, 922, 342, 268, 934, 935, 241, 92,
131113
+ /* 200 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131114
+ /* 210 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
131115
+ /* 220 */ 88, 87, 87, 87, 86, 339, 315, 913, 1295, 682,
131116
+ /* 230 */ 687, 1295, 233, 397, 92, 93, 83, 819, 819, 831,
131117
+ /* 240 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
131118
+ /* 250 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131119
+ /* 260 */ 339, 315, 85, 82, 168, 680, 431, 938, 939, 92,
131120
+ /* 270 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131121
+ /* 280 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
131122
+ /* 290 */ 88, 87, 87, 87, 86, 339, 315, 319, 913, 1296,
131123
+ /* 300 */ 797, 911, 1296, 681, 92, 93, 83, 819, 819, 831,
131124
+ /* 310 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 335,
131125
+ /* 320 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131126
+ /* 330 */ 339, 315, 876, 876, 373, 85, 82, 168, 944, 92,
131127
+ /* 340 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131128
+ /* 350 */ 91, 91, 91, 91, 896, 89, 89, 89, 89, 88,
131129
+ /* 360 */ 88, 87, 87, 87, 86, 339, 315, 370, 307, 973,
131130
+ /* 370 */ 367, 1, 911, 433, 92, 93, 83, 819, 819, 831,
131131
+ /* 380 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 189,
131132
+ /* 390 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131133
+ /* 400 */ 339, 315, 720, 948, 933, 933, 149, 718, 948, 92,
131134
+ /* 410 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131135
+ /* 420 */ 91, 91, 91, 91, 434, 89, 89, 89, 89, 88,
131136
+ /* 430 */ 88, 87, 87, 87, 86, 339, 338, 938, 939, 947,
131137
+ /* 440 */ 694, 940, 974, 315, 953, 48, 934, 935, 715, 689,
131138
+ /* 450 */ 71, 92, 93, 83, 819, 819, 831, 834, 823, 823,
131139
+ /* 460 */ 90, 90, 91, 91, 91, 91, 320, 89, 89, 89,
131140
+ /* 470 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 412,
131141
+ /* 480 */ 403, 820, 820, 832, 835, 74, 92, 81, 83, 819,
131142
+ /* 490 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
131143
+ /* 500 */ 91, 698, 89, 89, 89, 89, 88, 88, 87, 87,
131144
+ /* 510 */ 87, 86, 339, 315, 259, 654, 655, 656, 393, 111,
131145
+ /* 520 */ 331, 153, 93, 83, 819, 819, 831, 834, 823, 823,
131146
+ /* 530 */ 90, 90, 91, 91, 91, 91, 434, 89, 89, 89,
131147
+ /* 540 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 188,
131148
+ /* 550 */ 187, 186, 824, 937, 328, 219, 953, 48, 83, 819,
131149
+ /* 560 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
131150
+ /* 570 */ 91, 956, 89, 89, 89, 89, 88, 88, 87, 87,
131151
+ /* 580 */ 87, 86, 339, 79, 429, 738, 3, 1174, 955, 348,
131152
+ /* 590 */ 737, 332, 792, 933, 933, 937, 79, 429, 730, 3,
131153
+ /* 600 */ 203, 160, 278, 391, 273, 390, 190, 892, 434, 400,
131154
+ /* 610 */ 741, 76, 77, 271, 287, 253, 353, 242, 78, 340,
131155
+ /* 620 */ 340, 85, 82, 168, 76, 77, 233, 397, 953, 48,
131156
+ /* 630 */ 432, 78, 340, 340, 277, 934, 935, 185, 439, 651,
131157
+ /* 640 */ 388, 385, 384, 432, 234, 276, 107, 418, 349, 337,
131158
+ /* 650 */ 336, 383, 893, 728, 215, 949, 123, 971, 308, 810,
131159
+ /* 660 */ 418, 436, 435, 412, 394, 798, 400, 873, 894, 123,
131160
+ /* 670 */ 721, 872, 810, 889, 436, 435, 215, 949, 798, 351,
131161
+ /* 680 */ 722, 697, 380, 434, 771, 371, 22, 434, 400, 79,
131162
+ /* 690 */ 429, 232, 3, 189, 413, 870, 803, 803, 803, 805,
131163
+ /* 700 */ 18, 54, 148, 953, 48, 956, 113, 953, 9, 803,
131164
+ /* 710 */ 803, 803, 805, 18, 310, 123, 748, 76, 77, 742,
131165
+ /* 720 */ 123, 325, 955, 866, 78, 340, 340, 113, 350, 359,
131166
+ /* 730 */ 85, 82, 168, 343, 960, 960, 432, 770, 412, 414,
131167
+ /* 740 */ 407, 23, 1240, 1240, 79, 429, 357, 3, 166, 91,
131168
+ /* 750 */ 91, 91, 91, 418, 89, 89, 89, 89, 88, 88,
131169
+ /* 760 */ 87, 87, 87, 86, 339, 810, 434, 436, 435, 792,
131170
+ /* 770 */ 320, 798, 76, 77, 789, 271, 123, 434, 360, 78,
131171
+ /* 780 */ 340, 340, 864, 85, 82, 168, 953, 9, 395, 743,
131172
+ /* 790 */ 360, 432, 253, 358, 252, 933, 933, 953, 30, 889,
131173
+ /* 800 */ 327, 216, 803, 803, 803, 805, 18, 113, 418, 89,
131174
+ /* 810 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131175
+ /* 820 */ 810, 113, 436, 435, 792, 185, 798, 288, 388, 385,
131176
+ /* 830 */ 384, 123, 113, 920, 2, 796, 696, 934, 935, 383,
131177
+ /* 840 */ 69, 429, 434, 3, 218, 110, 738, 253, 358, 252,
131178
+ /* 850 */ 434, 737, 933, 933, 892, 359, 222, 803, 803, 803,
131179
+ /* 860 */ 805, 18, 953, 47, 933, 933, 933, 933, 76, 77,
131180
+ /* 870 */ 953, 9, 366, 904, 217, 78, 340, 340, 677, 305,
131181
+ /* 880 */ 304, 303, 206, 301, 224, 259, 664, 432, 337, 336,
131182
+ /* 890 */ 434, 228, 247, 144, 934, 935, 933, 933, 667, 893,
131183
+ /* 900 */ 324, 1259, 96, 434, 418, 796, 934, 935, 934, 935,
131184
+ /* 910 */ 953, 48, 401, 148, 289, 894, 810, 417, 436, 435,
131185
+ /* 920 */ 677, 759, 798, 953, 9, 314, 220, 162, 161, 170,
131186
+ /* 930 */ 402, 239, 953, 8, 194, 683, 683, 410, 934, 935,
131187
+ /* 940 */ 238, 959, 933, 933, 225, 408, 945, 365, 957, 212,
131188
+ /* 950 */ 958, 172, 757, 803, 803, 803, 805, 18, 173, 365,
131189
+ /* 960 */ 176, 123, 171, 113, 244, 952, 246, 434, 356, 796,
131190
+ /* 970 */ 372, 365, 236, 960, 960, 810, 290, 804, 191, 165,
131191
+ /* 980 */ 852, 798, 259, 316, 934, 935, 237, 953, 34, 404,
131192
+ /* 990 */ 91, 91, 91, 91, 84, 89, 89, 89, 89, 88,
131193
+ /* 1000 */ 88, 87, 87, 87, 86, 339, 701, 952, 434, 240,
131194
+ /* 1010 */ 347, 758, 803, 803, 803, 434, 245, 1179, 434, 389,
131195
+ /* 1020 */ 434, 376, 434, 895, 167, 434, 405, 702, 953, 35,
131196
+ /* 1030 */ 673, 321, 221, 434, 333, 953, 11, 434, 953, 26,
131197
+ /* 1040 */ 953, 36, 953, 37, 251, 953, 38, 434, 259, 434,
131198
+ /* 1050 */ 757, 434, 329, 953, 27, 434, 223, 953, 28, 434,
131199
+ /* 1060 */ 690, 434, 67, 434, 65, 434, 862, 953, 39, 953,
131200
+ /* 1070 */ 40, 953, 41, 423, 434, 953, 10, 434, 772, 953,
131201
+ /* 1080 */ 42, 953, 98, 953, 43, 953, 44, 773, 434, 346,
131202
+ /* 1090 */ 434, 75, 434, 73, 953, 31, 434, 953, 45, 434,
131203
+ /* 1100 */ 259, 434, 690, 434, 757, 434, 887, 434, 953, 46,
131204
+ /* 1110 */ 953, 32, 953, 115, 434, 266, 953, 116, 951, 953,
131205
+ /* 1120 */ 117, 953, 52, 953, 33, 953, 99, 953, 49, 726,
131206
+ /* 1130 */ 434, 909, 434, 19, 953, 100, 434, 344, 434, 113,
131207
+ /* 1140 */ 434, 258, 692, 434, 259, 434, 670, 434, 20, 434,
131208
+ /* 1150 */ 953, 101, 953, 97, 434, 259, 953, 114, 953, 112,
131209
+ /* 1160 */ 953, 105, 113, 953, 104, 953, 102, 953, 103, 953,
131210
+ /* 1170 */ 51, 434, 148, 434, 953, 53, 167, 434, 259, 113,
131211
+ /* 1180 */ 300, 307, 912, 363, 311, 860, 248, 261, 209, 264,
131212
+ /* 1190 */ 416, 953, 50, 953, 25, 420, 727, 953, 29, 430,
131213
+ /* 1200 */ 321, 424, 757, 428, 322, 124, 1269, 214, 165, 710,
131214
+ /* 1210 */ 859, 908, 806, 794, 309, 158, 193, 361, 254, 723,
131215
+ /* 1220 */ 364, 67, 381, 269, 735, 199, 67, 70, 113, 700,
131216
+ /* 1230 */ 699, 707, 708, 884, 113, 766, 113, 855, 193, 883,
131217
+ /* 1240 */ 199, 869, 869, 675, 868, 868, 109, 368, 255, 260,
131218
+ /* 1250 */ 263, 280, 859, 265, 806, 974, 267, 711, 695, 272,
131219
+ /* 1260 */ 764, 282, 795, 284, 150, 744, 755, 415, 292, 293,
131220
+ /* 1270 */ 802, 678, 672, 661, 660, 662, 927, 6, 306, 386,
131221
+ /* 1280 */ 352, 786, 243, 250, 886, 362, 163, 286, 419, 298,
131222
+ /* 1290 */ 930, 159, 968, 196, 126, 903, 901, 965, 55, 58,
131223
+ /* 1300 */ 323, 275, 857, 136, 147, 694, 856, 121, 65, 354,
131224
+ /* 1310 */ 355, 379, 175, 61, 151, 369, 180, 871, 375, 129,
131225
+ /* 1320 */ 257, 756, 210, 181, 145, 131, 132, 377, 262, 663,
131226
+ /* 1330 */ 133, 134, 139, 783, 791, 182, 392, 183, 312, 330,
131227
+ /* 1340 */ 714, 888, 713, 851, 692, 195, 712, 406, 686, 705,
131228
+ /* 1350 */ 313, 685, 64, 839, 274, 72, 684, 334, 942, 95,
131229
+ /* 1360 */ 752, 279, 281, 704, 753, 751, 422, 283, 411, 750,
131230
+ /* 1370 */ 426, 66, 204, 409, 21, 285, 928, 669, 437, 205,
131231
+ /* 1380 */ 207, 208, 438, 658, 657, 652, 118, 108, 119, 226,
131232
+ /* 1390 */ 650, 341, 157, 235, 169, 345, 106, 734, 790, 296,
131233
+ /* 1400 */ 294, 295, 120, 297, 867, 865, 127, 128, 130, 724,
131234
+ /* 1410 */ 229, 174, 249, 882, 137, 230, 138, 135, 885, 231,
131235
+ /* 1420 */ 59, 60, 177, 881, 7, 178, 12, 179, 256, 874,
131236
+ /* 1430 */ 140, 193, 962, 374, 141, 152, 666, 378, 276, 184,
131237
+ /* 1440 */ 270, 122, 142, 382, 387, 62, 13, 14, 703, 63,
131238
+ /* 1450 */ 125, 317, 318, 227, 809, 808, 837, 732, 15, 164,
131239
+ /* 1460 */ 736, 4, 765, 211, 399, 213, 192, 143, 760, 70,
131240
+ /* 1470 */ 67, 16, 17, 838, 836, 891, 841, 890, 198, 197,
131241
+ /* 1480 */ 917, 154, 421, 923, 918, 155, 200, 977, 425, 840,
131242
+ /* 1490 */ 156, 201, 807, 676, 80, 302, 299, 977, 202, 1261,
131243
+ /* 1500 */ 1260,
130747131244
};
130748131245
static const YYCODETYPE yy_lookahead[] = {
130749
- /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
130750
- /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
130751
- /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
130752
- /* 30 */ 19, 50, 51, 80, 81, 82, 83, 95, 85, 86,
130753
- /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 157,
130754
- /* 50 */ 27, 28, 71, 72, 73, 74, 75, 76, 77, 78,
130755
- /* 60 */ 79, 80, 81, 82, 83, 66, 85, 86, 87, 88,
130756
- /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
130757
- /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130758
- /* 90 */ 152, 33, 152, 22, 27, 28, 179, 180, 27, 28,
130759
- /* 100 */ 42, 27, 27, 28, 152, 188, 95, 152, 50, 51,
130760
- /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 227,
130761
- /* 120 */ 97, 98, 230, 112, 172, 173, 172, 172, 173, 71,
130762
- /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130763
- /* 140 */ 82, 83, 66, 85, 86, 87, 88, 89, 90, 91,
130764
- /* 150 */ 92, 93, 94, 95, 19, 172, 89, 90, 218, 207,
130765
- /* 160 */ 208, 26, 207, 208, 97, 98, 91, 100, 97, 98,
130766
- /* 170 */ 69, 97, 97, 98, 107, 237, 109, 89, 90, 91,
130767
- /* 180 */ 92, 93, 94, 95, 152, 50, 51, 97, 98, 99,
130768
- /* 190 */ 55, 59, 102, 103, 104, 119, 120, 59, 97, 132,
130769
- /* 200 */ 133, 152, 101, 113, 66, 19, 71, 72, 73, 74,
130770
- /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 187,
130771
- /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
130772
- /* 230 */ 95, 172, 210, 132, 133, 134, 50, 51, 185, 53,
130773
- /* 240 */ 108, 109, 110, 221, 222, 223, 108, 109, 110, 22,
130774
- /* 250 */ 22, 119, 120, 181, 27, 27, 28, 71, 72, 73,
130775
- /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130776
- /* 270 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130777
- /* 280 */ 94, 95, 19, 152, 148, 149, 115, 24, 117, 118,
130778
- /* 290 */ 154, 152, 156, 152, 163, 94, 95, 69, 249, 163,
130779
- /* 300 */ 27, 28, 99, 172, 173, 102, 103, 104, 194, 195,
130780
- /* 310 */ 152, 27, 28, 50, 51, 181, 113, 89, 90, 152,
130781
- /* 320 */ 206, 221, 222, 223, 97, 97, 187, 196, 175, 101,
130782
- /* 330 */ 172, 173, 196, 219, 71, 72, 73, 74, 75, 76,
130783
- /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
130784
- /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
130785
- /* 360 */ 132, 133, 134, 23, 66, 207, 208, 22, 27, 28,
130786
- /* 370 */ 97, 98, 27, 28, 221, 222, 223, 199, 22, 243,
130787
- /* 380 */ 24, 97, 98, 27, 221, 222, 223, 209, 152, 152,
130788
- /* 390 */ 50, 51, 168, 169, 170, 59, 26, 124, 100, 58,
130789
- /* 400 */ 152, 175, 66, 240, 163, 169, 170, 152, 124, 172,
130790
- /* 410 */ 173, 71, 72, 73, 74, 75, 76, 77, 78, 79,
130791
- /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
130792
- /* 430 */ 90, 91, 92, 93, 94, 95, 19, 196, 97, 98,
130793
- /* 440 */ 23, 29, 97, 98, 108, 109, 110, 221, 222, 223,
130794
- /* 450 */ 50, 51, 152, 97, 168, 169, 170, 45, 37, 47,
130795
- /* 460 */ 219, 224, 119, 120, 152, 229, 152, 50, 51, 169,
130796
- /* 470 */ 170, 59, 231, 52, 74, 75, 106, 236, 152, 21,
130797
- /* 480 */ 24, 60, 163, 27, 172, 173, 172, 173, 71, 72,
130798
- /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130799
- /* 500 */ 83, 101, 85, 86, 87, 88, 89, 90, 91, 92,
130800
- /* 510 */ 93, 94, 95, 19, 152, 196, 152, 23, 152, 207,
130801
- /* 520 */ 152, 207, 163, 65, 19, 171, 152, 190, 191, 229,
130802
- /* 530 */ 211, 212, 111, 179, 172, 173, 172, 173, 172, 173,
130803
- /* 540 */ 172, 173, 190, 191, 50, 51, 172, 173, 186, 22,
130804
- /* 550 */ 186, 24, 186, 97, 186, 196, 51, 89, 90, 22,
130805
- /* 560 */ 23, 103, 137, 26, 139, 71, 72, 73, 74, 75,
130806
- /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 219, 85,
130807
- /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130808
- /* 590 */ 19, 195, 152, 152, 23, 236, 163, 12, 140, 152,
130809
- /* 600 */ 132, 133, 206, 152, 164, 23, 31, 70, 26, 19,
130810
- /* 610 */ 35, 160, 107, 152, 29, 164, 152, 112, 28, 172,
130811
- /* 620 */ 173, 50, 51, 183, 49, 185, 152, 22, 23, 196,
130812
- /* 630 */ 45, 26, 47, 172, 173, 0, 1, 2, 152, 16,
130813
- /* 640 */ 152, 19, 71, 72, 73, 74, 75, 76, 77, 78,
130814
- /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
130815
- /* 660 */ 89, 90, 91, 92, 93, 94, 95, 164, 152, 152,
130816
- /* 670 */ 152, 152, 50, 51, 16, 70, 108, 109, 110, 193,
130817
- /* 680 */ 98, 7, 8, 9, 152, 62, 22, 64, 172, 173,
130818
- /* 690 */ 172, 173, 218, 71, 72, 73, 74, 75, 76, 77,
130819
- /* 700 */ 78, 79, 80, 81, 82, 83, 124, 85, 86, 87,
130820
- /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
130821
- /* 720 */ 62, 152, 64, 181, 152, 193, 152, 241, 246, 247,
130822
- /* 730 */ 26, 152, 152, 152, 217, 152, 91, 249, 152, 172,
130823
- /* 740 */ 173, 172, 173, 79, 172, 173, 172, 173, 152, 50,
130824
- /* 750 */ 51, 172, 173, 172, 173, 172, 173, 116, 172, 173,
130825
- /* 760 */ 138, 116, 121, 140, 22, 23, 121, 152, 172, 173,
130826
- /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130827
- /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130828
- /* 790 */ 91, 92, 93, 94, 95, 19, 152, 217, 152, 152,
130829
- /* 800 */ 24, 152, 98, 172, 173, 108, 109, 110, 193, 152,
130830
- /* 810 */ 213, 152, 70, 152, 152, 152, 172, 173, 172, 173,
130831
- /* 820 */ 152, 172, 173, 152, 146, 147, 50, 51, 124, 172,
130832
- /* 830 */ 173, 172, 173, 172, 173, 172, 173, 138, 22, 23,
130833
- /* 840 */ 193, 152, 152, 172, 173, 152, 19, 71, 72, 73,
130834
- /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130835
- /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130836
- /* 870 */ 94, 95, 152, 152, 152, 194, 195, 50, 51, 217,
130837
- /* 880 */ 172, 173, 193, 193, 26, 152, 70, 206, 152, 152,
130838
- /* 890 */ 26, 163, 172, 173, 172, 173, 152, 19, 71, 72,
130839
- /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130840
- /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
130841
- /* 920 */ 93, 94, 95, 152, 196, 152, 193, 152, 50, 51,
130842
- /* 930 */ 193, 172, 173, 19, 152, 166, 167, 51, 166, 167,
130843
- /* 940 */ 152, 152, 28, 172, 173, 172, 173, 152, 19, 71,
130844
- /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130845
- /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
130846
- /* 970 */ 92, 93, 94, 95, 152, 193, 152, 211, 212, 50,
130847
- /* 980 */ 51, 33, 172, 173, 244, 245, 23, 123, 130, 26,
130848
- /* 990 */ 42, 100, 101, 107, 172, 173, 172, 173, 152, 19,
130849
- /* 1000 */ 22, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130850
- /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130851
- /* 1020 */ 91, 92, 93, 94, 95, 152, 237, 152, 7, 8,
130852
- /* 1030 */ 50, 51, 237, 172, 173, 23, 23, 23, 26, 26,
130853
- /* 1040 */ 26, 23, 132, 133, 26, 172, 173, 172, 173, 23,
130854
- /* 1050 */ 163, 152, 26, 73, 74, 75, 76, 77, 78, 79,
130855
- /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
130856
- /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 27, 22,
130857
- /* 1080 */ 23, 210, 152, 196, 27, 28, 132, 133, 152, 19,
130858
- /* 1090 */ 20, 23, 22, 27, 26, 38, 152, 27, 28, 152,
130859
- /* 1100 */ 122, 152, 172, 173, 152, 163, 191, 23, 38, 152,
130860
- /* 1110 */ 26, 152, 163, 152, 57, 27, 172, 173, 163, 172,
130861
- /* 1120 */ 173, 172, 173, 66, 172, 173, 69, 57, 163, 172,
130862
- /* 1130 */ 173, 172, 173, 172, 173, 152, 66, 152, 196, 69,
130863
- /* 1140 */ 163, 101, 152, 152, 152, 196, 89, 90, 97, 152,
130864
- /* 1150 */ 152, 196, 112, 96, 97, 98, 207, 208, 101, 89,
130865
- /* 1160 */ 90, 196, 23, 97, 233, 26, 96, 97, 98, 172,
130866
- /* 1170 */ 173, 101, 152, 196, 152, 19, 20, 23, 22, 152,
130867
- /* 1180 */ 26, 152, 152, 27, 28, 97, 152, 152, 152, 132,
130868
- /* 1190 */ 133, 134, 135, 136, 38, 152, 152, 152, 152, 232,
130869
- /* 1200 */ 197, 214, 132, 133, 134, 135, 136, 198, 150, 210,
130870
- /* 1210 */ 210, 210, 201, 57, 238, 176, 214, 201, 180, 238,
130871
- /* 1220 */ 214, 184, 175, 19, 20, 69, 22, 175, 175, 198,
130872
- /* 1230 */ 226, 27, 28, 200, 155, 39, 242, 122, 41, 159,
130873
- /* 1240 */ 159, 159, 38, 22, 239, 89, 90, 91, 220, 239,
130874
- /* 1250 */ 71, 189, 96, 97, 98, 130, 201, 101, 18, 192,
130875
- /* 1260 */ 159, 57, 18, 192, 192, 192, 158, 189, 220, 159,
130876
- /* 1270 */ 201, 158, 189, 69, 137, 201, 235, 19, 20, 46,
130877
- /* 1280 */ 22, 159, 159, 234, 158, 27, 28, 22, 132, 133,
130878
- /* 1290 */ 134, 135, 136, 89, 90, 177, 38, 159, 158, 158,
130879
- /* 1300 */ 96, 97, 98, 159, 177, 101, 107, 174, 174, 174,
130880
- /* 1310 */ 48, 182, 106, 177, 182, 57, 174, 125, 216, 176,
130881
- /* 1320 */ 174, 174, 174, 107, 215, 159, 215, 69, 216, 159,
130882
- /* 1330 */ 216, 215, 137, 216, 215, 177, 132, 133, 134, 135,
130883
- /* 1340 */ 136, 95, 177, 129, 126, 225, 127, 89, 90, 228,
130884
- /* 1350 */ 205, 128, 228, 204, 96, 97, 98, 25, 203, 101,
130885
- /* 1360 */ 5, 202, 201, 162, 26, 10, 11, 12, 13, 14,
130886
- /* 1370 */ 161, 13, 17, 153, 6, 153, 151, 151, 151, 151,
130887
- /* 1380 */ 165, 178, 165, 178, 4, 3, 22, 32, 15, 34,
130888
- /* 1390 */ 132, 133, 134, 135, 136, 245, 165, 142, 43, 248,
130889
- /* 1400 */ 248, 68, 16, 120, 23, 131, 23, 111, 123, 20,
130890
- /* 1410 */ 16, 56, 125, 1, 123, 131, 79, 111, 63, 79,
130891
- /* 1420 */ 28, 66, 67, 36, 122, 1, 5, 22, 107, 140,
130892
- /* 1430 */ 54, 54, 26, 61, 44, 107, 20, 24, 19, 112,
130893
- /* 1440 */ 105, 53, 22, 40, 22, 22, 53, 30, 23, 22,
130894
- /* 1450 */ 22, 53, 23, 23, 23, 116, 22, 11, 23, 22,
130895
- /* 1460 */ 28, 23, 26, 122, 23, 22, 124, 122, 26, 114,
130896
- /* 1470 */ 26, 23, 23, 23, 22, 36, 36, 26, 23, 23,
130897
- /* 1480 */ 22, 36, 122, 24, 23, 22, 26, 22, 24, 23,
130898
- /* 1490 */ 23, 122, 23, 22, 15, 23, 141, 122, 1,
130899
-};
130900
-#define YY_SHIFT_USE_DFLT (-72)
131246
+ /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
131247
+ /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131248
+ /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131249
+ /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
131250
+ /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
131251
+ /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 92, 43,
131252
+ /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131253
+ /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
131254
+ /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
131255
+ /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131256
+ /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131257
+ /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
131258
+ /* 120 */ 249, 22, 172, 172, 173, 52, 53, 27, 28, 29,
131259
+ /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
131260
+ /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
131261
+ /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
131262
+ /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
131263
+ /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
131264
+ /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131265
+ /* 190 */ 53, 19, 0, 1, 2, 23, 97, 98, 193, 27,
131266
+ /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131267
+ /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131268
+ /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
131269
+ /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
131270
+ /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131271
+ /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131272
+ /* 260 */ 53, 19, 221, 222, 223, 23, 168, 169, 170, 27,
131273
+ /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131274
+ /* 280 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131275
+ /* 290 */ 48, 49, 50, 51, 52, 53, 19, 157, 22, 23,
131276
+ /* 300 */ 23, 96, 26, 172, 27, 28, 29, 30, 31, 32,
131277
+ /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131278
+ /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131279
+ /* 330 */ 53, 19, 108, 109, 110, 221, 222, 223, 185, 27,
131280
+ /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131281
+ /* 350 */ 38, 39, 40, 41, 240, 43, 44, 45, 46, 47,
131282
+ /* 360 */ 48, 49, 50, 51, 52, 53, 19, 227, 22, 23,
131283
+ /* 370 */ 230, 22, 96, 152, 27, 28, 29, 30, 31, 32,
131284
+ /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 30,
131285
+ /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131286
+ /* 400 */ 53, 19, 190, 191, 55, 56, 24, 190, 191, 27,
131287
+ /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131288
+ /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131289
+ /* 430 */ 48, 49, 50, 51, 52, 53, 168, 169, 170, 179,
131290
+ /* 440 */ 180, 171, 96, 19, 172, 173, 97, 98, 188, 179,
131291
+ /* 450 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
131292
+ /* 460 */ 36, 37, 38, 39, 40, 41, 107, 43, 44, 45,
131293
+ /* 470 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 207,
131294
+ /* 480 */ 208, 30, 31, 32, 33, 138, 27, 28, 29, 30,
131295
+ /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131296
+ /* 500 */ 41, 181, 43, 44, 45, 46, 47, 48, 49, 50,
131297
+ /* 510 */ 51, 52, 53, 19, 152, 7, 8, 9, 49, 22,
131298
+ /* 520 */ 19, 24, 28, 29, 30, 31, 32, 33, 34, 35,
131299
+ /* 530 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
131300
+ /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 108,
131301
+ /* 550 */ 109, 110, 101, 55, 53, 193, 172, 173, 29, 30,
131302
+ /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131303
+ /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
131304
+ /* 580 */ 51, 52, 53, 19, 20, 116, 22, 23, 169, 170,
131305
+ /* 590 */ 121, 207, 85, 55, 56, 97, 19, 20, 195, 22,
131306
+ /* 600 */ 99, 100, 101, 102, 103, 104, 105, 12, 152, 206,
131307
+ /* 610 */ 210, 47, 48, 112, 152, 108, 109, 110, 54, 55,
131308
+ /* 620 */ 56, 221, 222, 223, 47, 48, 119, 120, 172, 173,
131309
+ /* 630 */ 66, 54, 55, 56, 101, 97, 98, 99, 148, 149,
131310
+ /* 640 */ 102, 103, 104, 66, 154, 112, 156, 83, 229, 47,
131311
+ /* 650 */ 48, 113, 57, 163, 194, 195, 92, 246, 247, 95,
131312
+ /* 660 */ 83, 97, 98, 207, 208, 101, 206, 59, 73, 92,
131313
+ /* 670 */ 75, 63, 95, 163, 97, 98, 194, 195, 101, 219,
131314
+ /* 680 */ 85, 181, 19, 152, 175, 77, 196, 152, 206, 19,
131315
+ /* 690 */ 20, 199, 22, 30, 163, 11, 132, 133, 134, 135,
131316
+ /* 700 */ 136, 209, 152, 172, 173, 152, 196, 172, 173, 132,
131317
+ /* 710 */ 133, 134, 135, 136, 164, 92, 213, 47, 48, 49,
131318
+ /* 720 */ 92, 186, 169, 170, 54, 55, 56, 196, 100, 219,
131319
+ /* 730 */ 221, 222, 223, 243, 132, 133, 66, 175, 207, 208,
131320
+ /* 740 */ 152, 231, 119, 120, 19, 20, 236, 22, 152, 38,
131321
+ /* 750 */ 39, 40, 41, 83, 43, 44, 45, 46, 47, 48,
131322
+ /* 760 */ 49, 50, 51, 52, 53, 95, 152, 97, 98, 85,
131323
+ /* 770 */ 107, 101, 47, 48, 163, 112, 92, 152, 152, 54,
131324
+ /* 780 */ 55, 56, 229, 221, 222, 223, 172, 173, 163, 49,
131325
+ /* 790 */ 152, 66, 108, 109, 110, 55, 56, 172, 173, 163,
131326
+ /* 800 */ 186, 22, 132, 133, 134, 135, 136, 196, 83, 43,
131327
+ /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131328
+ /* 820 */ 95, 196, 97, 98, 85, 99, 101, 152, 102, 103,
131329
+ /* 830 */ 104, 92, 196, 146, 147, 152, 181, 97, 98, 113,
131330
+ /* 840 */ 19, 20, 152, 22, 218, 22, 116, 108, 109, 110,
131331
+ /* 850 */ 152, 121, 55, 56, 12, 219, 218, 132, 133, 134,
131332
+ /* 860 */ 135, 136, 172, 173, 55, 56, 55, 56, 47, 48,
131333
+ /* 870 */ 172, 173, 236, 152, 5, 54, 55, 56, 55, 10,
131334
+ /* 880 */ 11, 12, 13, 14, 186, 152, 17, 66, 47, 48,
131335
+ /* 890 */ 152, 210, 16, 84, 97, 98, 55, 56, 21, 57,
131336
+ /* 900 */ 217, 122, 22, 152, 83, 152, 97, 98, 97, 98,
131337
+ /* 910 */ 172, 173, 152, 152, 224, 73, 95, 75, 97, 98,
131338
+ /* 920 */ 97, 124, 101, 172, 173, 164, 193, 47, 48, 60,
131339
+ /* 930 */ 163, 62, 172, 173, 24, 55, 56, 186, 97, 98,
131340
+ /* 940 */ 71, 100, 55, 56, 183, 207, 185, 152, 107, 23,
131341
+ /* 950 */ 109, 82, 26, 132, 133, 134, 135, 136, 89, 152,
131342
+ /* 960 */ 26, 92, 93, 196, 88, 55, 90, 152, 91, 152,
131343
+ /* 970 */ 217, 152, 152, 132, 133, 95, 152, 97, 211, 212,
131344
+ /* 980 */ 103, 101, 152, 114, 97, 98, 152, 172, 173, 19,
131345
+ /* 990 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
131346
+ /* 1000 */ 48, 49, 50, 51, 52, 53, 65, 97, 152, 152,
131347
+ /* 1010 */ 141, 124, 132, 133, 134, 152, 140, 140, 152, 78,
131348
+ /* 1020 */ 152, 233, 152, 193, 98, 152, 56, 86, 172, 173,
131349
+ /* 1030 */ 166, 167, 237, 152, 217, 172, 173, 152, 172, 173,
131350
+ /* 1040 */ 172, 173, 172, 173, 237, 172, 173, 152, 152, 152,
131351
+ /* 1050 */ 124, 152, 111, 172, 173, 152, 237, 172, 173, 152,
131352
+ /* 1060 */ 55, 152, 26, 152, 130, 152, 152, 172, 173, 172,
131353
+ /* 1070 */ 173, 172, 173, 249, 152, 172, 173, 152, 61, 172,
131354
+ /* 1080 */ 173, 172, 173, 172, 173, 172, 173, 70, 152, 193,
131355
+ /* 1090 */ 152, 137, 152, 139, 172, 173, 152, 172, 173, 152,
131356
+ /* 1100 */ 152, 152, 97, 152, 26, 152, 163, 152, 172, 173,
131357
+ /* 1110 */ 172, 173, 172, 173, 152, 16, 172, 173, 26, 172,
131358
+ /* 1120 */ 173, 172, 173, 172, 173, 172, 173, 172, 173, 163,
131359
+ /* 1130 */ 152, 152, 152, 22, 172, 173, 152, 241, 152, 196,
131360
+ /* 1140 */ 152, 193, 106, 152, 152, 152, 163, 152, 37, 152,
131361
+ /* 1150 */ 172, 173, 172, 173, 152, 152, 172, 173, 172, 173,
131362
+ /* 1160 */ 172, 173, 196, 172, 173, 172, 173, 172, 173, 172,
131363
+ /* 1170 */ 173, 152, 152, 152, 172, 173, 98, 152, 152, 196,
131364
+ /* 1180 */ 160, 22, 23, 19, 164, 193, 152, 88, 232, 90,
131365
+ /* 1190 */ 191, 172, 173, 172, 173, 163, 193, 172, 173, 166,
131366
+ /* 1200 */ 167, 163, 124, 163, 244, 245, 23, 211, 212, 26,
131367
+ /* 1210 */ 55, 23, 55, 23, 26, 123, 26, 152, 23, 193,
131368
+ /* 1220 */ 56, 26, 23, 23, 23, 26, 26, 26, 196, 100,
131369
+ /* 1230 */ 101, 7, 8, 152, 196, 23, 196, 23, 26, 152,
131370
+ /* 1240 */ 26, 132, 133, 23, 132, 133, 26, 152, 152, 152,
131371
+ /* 1250 */ 152, 210, 97, 152, 97, 96, 152, 152, 152, 152,
131372
+ /* 1260 */ 152, 210, 152, 210, 197, 152, 152, 152, 152, 152,
131373
+ /* 1270 */ 152, 152, 152, 152, 152, 152, 152, 198, 150, 176,
131374
+ /* 1280 */ 214, 201, 214, 238, 201, 238, 184, 214, 226, 200,
131375
+ /* 1290 */ 155, 198, 67, 122, 242, 159, 159, 69, 239, 239,
131376
+ /* 1300 */ 159, 175, 175, 22, 220, 180, 175, 27, 130, 18,
131377
+ /* 1310 */ 159, 18, 158, 137, 220, 159, 158, 235, 74, 189,
131378
+ /* 1320 */ 234, 159, 159, 158, 22, 192, 192, 177, 159, 159,
131379
+ /* 1330 */ 192, 192, 189, 201, 189, 158, 107, 158, 177, 76,
131380
+ /* 1340 */ 174, 201, 174, 201, 106, 159, 174, 125, 174, 182,
131381
+ /* 1350 */ 177, 176, 107, 159, 174, 137, 174, 53, 174, 129,
131382
+ /* 1360 */ 216, 215, 215, 182, 216, 216, 177, 215, 126, 216,
131383
+ /* 1370 */ 177, 128, 25, 127, 26, 215, 13, 162, 161, 153,
131384
+ /* 1380 */ 153, 6, 151, 151, 151, 151, 165, 178, 165, 178,
131385
+ /* 1390 */ 4, 3, 22, 142, 15, 94, 16, 205, 120, 202,
131386
+ /* 1400 */ 204, 203, 165, 201, 23, 23, 131, 111, 123, 20,
131387
+ /* 1410 */ 225, 125, 16, 1, 131, 228, 111, 123, 56, 228,
131388
+ /* 1420 */ 37, 37, 64, 1, 5, 122, 22, 107, 140, 80,
131389
+ /* 1430 */ 80, 26, 87, 72, 107, 24, 20, 19, 112, 105,
131390
+ /* 1440 */ 23, 68, 22, 79, 79, 22, 22, 22, 58, 22,
131391
+ /* 1450 */ 245, 248, 248, 79, 23, 23, 23, 116, 22, 122,
131392
+ /* 1460 */ 23, 22, 56, 23, 26, 23, 64, 22, 124, 26,
131393
+ /* 1470 */ 26, 64, 64, 23, 23, 23, 11, 23, 22, 26,
131394
+ /* 1480 */ 23, 22, 24, 1, 23, 22, 26, 250, 24, 23,
131395
+ /* 1490 */ 22, 122, 23, 23, 22, 15, 23, 250, 122, 122,
131396
+ /* 1500 */ 122,
131397
+};
131398
+#define YY_SHIFT_USE_DFLT (-95)
130901131399
#define YY_SHIFT_COUNT (439)
130902
-#define YY_SHIFT_MIN (-71)
130903
-#define YY_SHIFT_MAX (1497)
131400
+#define YY_SHIFT_MIN (-94)
131401
+#define YY_SHIFT_MAX (1482)
130904131402
static const short yy_shift_ofst[] = {
130905
- /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 138, -19, 58,
130906
- /* 10 */ 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 67,
130907
- /* 20 */ 67, 90, 132, 336, 76, 135, 263, 340, 417, 494,
130908
- /* 30 */ 571, 622, 699, 776, 827, 827, 827, 827, 827, 827,
130909
- /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 878,
130910
- /* 50 */ 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204, 1204,
130911
- /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130912
- /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130913
- /* 80 */ 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204, 1204,
130914
- /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47, -47,
130915
- /* 100 */ -47, -47, -47, -6, 88, -66, 23, 458, 505, 468,
130916
- /* 110 */ 468, 23, 201, 343, -58, -72, -72, -72, 11, 11,
130917
- /* 120 */ 11, 412, 412, 341, 537, 605, 23, 23, 23, 23,
130918
- /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130919
- /* 140 */ 23, 23, 23, 23, 23, 23, 635, 298, 74, 74,
130920
- /* 150 */ 343, -1, -1, -1, -1, -1, -1, -72, -72, -72,
130921
- /* 160 */ 228, 101, 101, 203, 75, 71, 273, 284, 345, 23,
130922
- /* 170 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130923
- /* 180 */ 23, 23, 23, 23, 23, 23, 421, 421, 421, 23,
130924
- /* 190 */ 23, 582, 23, 23, 23, 356, 23, 23, 585, 23,
130925
- /* 200 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 568,
130926
- /* 210 */ 575, 456, 456, 456, 704, 171, 645, 674, 858, 590,
130927
- /* 220 */ 590, 914, 858, 914, 370, 963, 886, 948, 590, 425,
130928
- /* 230 */ 948, 948, 864, 641, 527, 1196, 1115, 1115, 1197, 1197,
130929
- /* 240 */ 1115, 1221, 1179, 1125, 1240, 1240, 1240, 1240, 1115, 1244,
130930
- /* 250 */ 1125, 1221, 1179, 1179, 1125, 1115, 1244, 1137, 1233, 1115,
130931
- /* 260 */ 1115, 1244, 1265, 1115, 1244, 1115, 1244, 1265, 1199, 1199,
130932
- /* 270 */ 1199, 1262, 1265, 1199, 1206, 1199, 1262, 1199, 1199, 1192,
130933
- /* 280 */ 1216, 1192, 1216, 1192, 1216, 1192, 1216, 1115, 1115, 1195,
130934
- /* 290 */ 1265, 1246, 1246, 1265, 1214, 1218, 1223, 1219, 1125, 1332,
130935
- /* 300 */ 1338, 1358, 1358, 1368, 1368, 1368, 1368, -72, -72, -72,
130936
- /* 310 */ -72, -72, -72, -72, -72, 400, 623, 742, 816, 658,
130937
- /* 320 */ 697, 227, 1012, 664, 1013, 1014, 1018, 1026, 1051, 891,
130938
- /* 330 */ 1021, 1040, 1068, 1084, 1066, 1139, 910, 954, 1154, 1088,
130939
- /* 340 */ 978, 1380, 1382, 1364, 1255, 1373, 1333, 1386, 1381, 1383,
130940
- /* 350 */ 1283, 1274, 1296, 1285, 1389, 1287, 1394, 1412, 1291, 1284,
130941
- /* 360 */ 1337, 1340, 1306, 1392, 1387, 1302, 1424, 1421, 1405, 1321,
130942
- /* 370 */ 1289, 1376, 1406, 1377, 1372, 1390, 1328, 1413, 1416, 1419,
130943
- /* 380 */ 1327, 1335, 1420, 1388, 1422, 1423, 1425, 1427, 1393, 1417,
130944
- /* 390 */ 1428, 1398, 1403, 1429, 1430, 1431, 1339, 1434, 1435, 1437,
130945
- /* 400 */ 1436, 1341, 1438, 1441, 1432, 1439, 1443, 1342, 1442, 1440,
130946
- /* 410 */ 1444, 1445, 1442, 1448, 1449, 1450, 1451, 1455, 1452, 1446,
130947
- /* 420 */ 1456, 1458, 1459, 1460, 1461, 1463, 1464, 1460, 1466, 1465,
130948
- /* 430 */ 1467, 1469, 1471, 1345, 1360, 1369, 1375, 1472, 1479, 1497,
131403
+ /* 0 */ 40, 564, 869, 577, 725, 725, 725, 739, -19, 16,
131404
+ /* 10 */ 16, 100, 725, 725, 725, 725, 725, 725, 725, 841,
131405
+ /* 20 */ 841, 538, 507, 684, 623, 61, 137, 172, 207, 242,
131406
+ /* 30 */ 277, 312, 347, 382, 424, 424, 424, 424, 424, 424,
131407
+ /* 40 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 459,
131408
+ /* 50 */ 424, 494, 529, 529, 670, 725, 725, 725, 725, 725,
131409
+ /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131410
+ /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131411
+ /* 80 */ 725, 725, 725, 821, 725, 725, 725, 725, 725, 725,
131412
+ /* 90 */ 725, 725, 725, 725, 725, 725, 725, 952, 711, 711,
131413
+ /* 100 */ 711, 711, 711, 766, 23, 32, 811, 877, 663, 602,
131414
+ /* 110 */ 602, 811, 73, 113, -51, -95, -95, -95, 501, 501,
131415
+ /* 120 */ 501, 595, 595, 809, 205, 276, 811, 811, 811, 811,
131416
+ /* 130 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131417
+ /* 140 */ 811, 811, 811, 811, 811, 811, 192, 628, 498, 498,
131418
+ /* 150 */ 113, -34, -34, -34, -34, -34, -34, -95, -95, -95,
131419
+ /* 160 */ 880, -94, -94, 726, 740, 99, 797, 887, 349, 811,
131420
+ /* 170 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131421
+ /* 180 */ 811, 811, 811, 811, 811, 811, 941, 941, 941, 811,
131422
+ /* 190 */ 811, 926, 811, 811, 811, -18, 811, 811, 842, 811,
131423
+ /* 200 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 224,
131424
+ /* 210 */ 608, 910, 910, 910, 1078, 45, 469, 508, 934, 970,
131425
+ /* 220 */ 970, 1164, 934, 1164, 1036, 1183, 359, 1017, 970, 954,
131426
+ /* 230 */ 1017, 1017, 1092, 730, 497, 1225, 1171, 1171, 1228, 1228,
131427
+ /* 240 */ 1171, 1281, 1280, 1178, 1291, 1291, 1291, 1291, 1171, 1293,
131428
+ /* 250 */ 1178, 1281, 1280, 1280, 1178, 1171, 1293, 1176, 1244, 1171,
131429
+ /* 260 */ 1171, 1293, 1302, 1171, 1293, 1171, 1293, 1302, 1229, 1229,
131430
+ /* 270 */ 1229, 1263, 1302, 1229, 1238, 1229, 1263, 1229, 1229, 1222,
131431
+ /* 280 */ 1245, 1222, 1245, 1222, 1245, 1222, 1245, 1171, 1171, 1218,
131432
+ /* 290 */ 1302, 1304, 1304, 1302, 1230, 1242, 1243, 1246, 1178, 1347,
131433
+ /* 300 */ 1348, 1363, 1363, 1375, 1375, 1375, 1375, -95, -95, -95,
131434
+ /* 310 */ -95, -95, -95, -95, -95, 451, 876, 346, 1159, 1099,
131435
+ /* 320 */ 441, 823, 1188, 1111, 1190, 1195, 1199, 1200, 1005, 1129,
131436
+ /* 330 */ 1224, 533, 1201, 1212, 1155, 1214, 1109, 1112, 1220, 1157,
131437
+ /* 340 */ 779, 1386, 1388, 1370, 1251, 1379, 1301, 1380, 1381, 1382,
131438
+ /* 350 */ 1278, 1275, 1296, 1285, 1389, 1286, 1396, 1412, 1294, 1283,
131439
+ /* 360 */ 1383, 1384, 1305, 1362, 1358, 1303, 1422, 1419, 1404, 1320,
131440
+ /* 370 */ 1288, 1349, 1405, 1350, 1345, 1361, 1327, 1411, 1416, 1418,
131441
+ /* 380 */ 1326, 1334, 1420, 1364, 1423, 1424, 1417, 1425, 1365, 1390,
131442
+ /* 390 */ 1427, 1374, 1373, 1431, 1432, 1433, 1341, 1436, 1437, 1439,
131443
+ /* 400 */ 1438, 1337, 1440, 1442, 1406, 1402, 1445, 1344, 1443, 1407,
131444
+ /* 410 */ 1444, 1408, 1443, 1450, 1451, 1452, 1453, 1454, 1456, 1465,
131445
+ /* 420 */ 1457, 1459, 1458, 1460, 1461, 1463, 1464, 1460, 1466, 1468,
131446
+ /* 430 */ 1469, 1470, 1472, 1369, 1376, 1377, 1378, 1473, 1480, 1482,
130949131447
};
130950
-#define YY_REDUCE_USE_DFLT (-144)
131448
+#define YY_REDUCE_USE_DFLT (-130)
130951131449
#define YY_REDUCE_COUNT (314)
130952
-#define YY_REDUCE_MIN (-143)
130953
-#define YY_REDUCE_MAX (1231)
131450
+#define YY_REDUCE_MIN (-129)
131451
+#define YY_REDUCE_MAX (1237)
130954131452
static const short yy_reduce_ofst[] = {
130955
- /* 0 */ -143, 949, 136, 131, -48, -45, 158, 241, 22, 153,
130956
- /* 10 */ 226, 163, 362, 364, 366, 312, 314, 368, 237, 236,
130957
- /* 20 */ 300, 440, 114, 359, 319, 100, 100, 100, 100, 100,
130958
- /* 30 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130959
- /* 40 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130960
- /* 50 */ 100, 100, 100, 100, 374, 447, 461, 516, 518, 567,
130961
- /* 60 */ 569, 572, 574, 579, 581, 583, 586, 596, 631, 644,
130962
- /* 70 */ 646, 649, 657, 659, 661, 663, 671, 708, 720, 722,
130963
- /* 80 */ 759, 771, 773, 810, 822, 824, 861, 873, 875, 930,
130964
- /* 90 */ 944, 947, 952, 957, 959, 961, 997, 100, 100, 100,
130965
- /* 100 */ 100, 100, 100, 100, 100, 100, 486, -108, -83, 224,
130966
- /* 110 */ 286, 451, 100, 681, 100, 100, 100, 100, 354, 354,
130967
- /* 120 */ 354, 337, 352, 49, 482, 482, 503, 532, -60, 615,
130968
- /* 130 */ 647, 689, 690, 737, 782, -62, 517, 789, 474, 795,
130969
- /* 140 */ 580, 733, 32, 662, 488, 139, 678, 433, 769, 772,
130970
- /* 150 */ 396, 728, 887, 942, 955, 965, 977, 740, 766, 178,
130971
- /* 160 */ -46, -17, 59, 53, 118, 141, 167, 248, 255, 326,
130972
- /* 170 */ 441, 464, 519, 668, 693, 721, 736, 744, 775, 788,
130973
- /* 180 */ 846, 899, 912, 936, 983, 985, 72, 134, 542, 990,
130974
- /* 190 */ 991, 597, 992, 998, 1020, 871, 1022, 1027, 915, 1029,
130975
- /* 200 */ 1030, 1034, 118, 1035, 1036, 1043, 1044, 1045, 1046, 931,
130976
- /* 210 */ 967, 999, 1000, 1001, 597, 1003, 1009, 1058, 1011, 987,
130977
- /* 220 */ 1002, 976, 1016, 981, 1039, 1037, 1038, 1047, 1006, 1004,
130978
- /* 230 */ 1052, 1053, 1033, 1031, 1079, 994, 1080, 1081, 1005, 1010,
130979
- /* 240 */ 1082, 1028, 1062, 1055, 1067, 1071, 1072, 1073, 1101, 1108,
130980
- /* 250 */ 1069, 1048, 1078, 1083, 1074, 1110, 1113, 1041, 1049, 1122,
130981
- /* 260 */ 1123, 1126, 1118, 1138, 1140, 1144, 1141, 1127, 1133, 1134,
130982
- /* 270 */ 1135, 1129, 1136, 1142, 1143, 1146, 1132, 1147, 1148, 1102,
130983
- /* 280 */ 1109, 1112, 1111, 1114, 1116, 1117, 1119, 1166, 1170, 1120,
130984
- /* 290 */ 1158, 1121, 1124, 1165, 1145, 1149, 1155, 1159, 1161, 1201,
130985
- /* 300 */ 1209, 1220, 1222, 1225, 1226, 1227, 1228, 1151, 1152, 1150,
130986
- /* 310 */ 1215, 1217, 1203, 1205, 1231,
131453
+ /* 0 */ -29, 531, 490, 625, -49, 272, 456, 510, 400, 509,
131454
+ /* 10 */ 562, 114, 535, 614, 698, 384, 738, 751, 690, 419,
131455
+ /* 20 */ 553, 761, 460, 636, 767, 41, 41, 41, 41, 41,
131456
+ /* 30 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131457
+ /* 40 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131458
+ /* 50 */ 41, 41, 41, 41, 760, 815, 856, 863, 866, 868,
131459
+ /* 60 */ 870, 873, 881, 885, 895, 897, 899, 903, 907, 909,
131460
+ /* 70 */ 911, 913, 922, 925, 936, 938, 940, 944, 947, 949,
131461
+ /* 80 */ 951, 953, 955, 962, 978, 980, 984, 986, 988, 991,
131462
+ /* 90 */ 993, 995, 997, 1002, 1019, 1021, 1025, 41, 41, 41,
131463
+ /* 100 */ 41, 41, 41, 41, 41, 41, 896, 140, 260, 98,
131464
+ /* 110 */ 268, 1020, 41, 482, 41, 41, 41, 41, 270, 270,
131465
+ /* 120 */ 270, 212, 217, -129, 411, 411, 550, 5, 626, 362,
131466
+ /* 130 */ 733, 830, 992, 1003, 1026, 795, 683, 807, 638, 819,
131467
+ /* 140 */ 753, 948, 62, 817, 824, 132, 687, 611, 864, 1033,
131468
+ /* 150 */ 403, 943, 966, 983, 1032, 1038, 1040, 960, 996, 492,
131469
+ /* 160 */ -50, 57, 131, 153, 221, 462, 588, 596, 675, 721,
131470
+ /* 170 */ 820, 834, 857, 914, 979, 1034, 1065, 1081, 1087, 1095,
131471
+ /* 180 */ 1096, 1097, 1098, 1101, 1104, 1105, 320, 500, 655, 1106,
131472
+ /* 190 */ 1107, 503, 1108, 1110, 1113, 681, 1114, 1115, 999, 1116,
131473
+ /* 200 */ 1117, 1118, 221, 1119, 1120, 1121, 1122, 1123, 1124, 788,
131474
+ /* 210 */ 956, 1041, 1051, 1053, 503, 1067, 1079, 1128, 1080, 1066,
131475
+ /* 220 */ 1068, 1045, 1083, 1047, 1103, 1102, 1125, 1126, 1073, 1062,
131476
+ /* 230 */ 1127, 1131, 1089, 1093, 1135, 1052, 1136, 1137, 1059, 1060,
131477
+ /* 240 */ 1141, 1084, 1130, 1132, 1133, 1134, 1138, 1139, 1151, 1154,
131478
+ /* 250 */ 1140, 1094, 1143, 1145, 1142, 1156, 1158, 1082, 1086, 1162,
131479
+ /* 260 */ 1163, 1165, 1150, 1169, 1177, 1170, 1179, 1161, 1166, 1168,
131480
+ /* 270 */ 1172, 1167, 1173, 1174, 1175, 1180, 1181, 1182, 1184, 1144,
131481
+ /* 280 */ 1146, 1148, 1147, 1149, 1152, 1153, 1160, 1186, 1194, 1185,
131482
+ /* 290 */ 1189, 1187, 1191, 1193, 1192, 1196, 1198, 1197, 1202, 1215,
131483
+ /* 300 */ 1217, 1226, 1227, 1231, 1232, 1233, 1234, 1203, 1204, 1205,
131484
+ /* 310 */ 1221, 1223, 1209, 1211, 1237,
130987131485
};
130988131486
static const YYACTIONTYPE yy_default[] = {
130989131487
/* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
130990131488
/* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
130991131489
/* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131547,104 @@
131049131547
*/
131050131548
#ifdef YYFALLBACK
131051131549
static const YYCODETYPE yyFallback[] = {
131052131550
0, /* $ => nothing */
131053131551
0, /* SEMI => nothing */
131054
- 27, /* EXPLAIN => ID */
131055
- 27, /* QUERY => ID */
131056
- 27, /* PLAN => ID */
131057
- 27, /* BEGIN => ID */
131552
+ 55, /* EXPLAIN => ID */
131553
+ 55, /* QUERY => ID */
131554
+ 55, /* PLAN => ID */
131555
+ 55, /* BEGIN => ID */
131058131556
0, /* TRANSACTION => nothing */
131059
- 27, /* DEFERRED => ID */
131060
- 27, /* IMMEDIATE => ID */
131061
- 27, /* EXCLUSIVE => ID */
131557
+ 55, /* DEFERRED => ID */
131558
+ 55, /* IMMEDIATE => ID */
131559
+ 55, /* EXCLUSIVE => ID */
131062131560
0, /* COMMIT => nothing */
131063
- 27, /* END => ID */
131064
- 27, /* ROLLBACK => ID */
131065
- 27, /* SAVEPOINT => ID */
131066
- 27, /* RELEASE => ID */
131561
+ 55, /* END => ID */
131562
+ 55, /* ROLLBACK => ID */
131563
+ 55, /* SAVEPOINT => ID */
131564
+ 55, /* RELEASE => ID */
131067131565
0, /* TO => nothing */
131068131566
0, /* TABLE => nothing */
131069131567
0, /* CREATE => nothing */
131070
- 27, /* IF => ID */
131568
+ 55, /* IF => ID */
131071131569
0, /* NOT => nothing */
131072131570
0, /* EXISTS => nothing */
131073
- 27, /* TEMP => ID */
131571
+ 55, /* TEMP => ID */
131074131572
0, /* LP => nothing */
131075131573
0, /* RP => nothing */
131076131574
0, /* AS => nothing */
131077
- 27, /* WITHOUT => ID */
131575
+ 55, /* WITHOUT => ID */
131078131576
0, /* COMMA => nothing */
131577
+ 0, /* OR => nothing */
131578
+ 0, /* AND => nothing */
131579
+ 0, /* IS => nothing */
131580
+ 55, /* MATCH => ID */
131581
+ 55, /* LIKE_KW => ID */
131582
+ 0, /* BETWEEN => nothing */
131583
+ 0, /* IN => nothing */
131584
+ 0, /* ISNULL => nothing */
131585
+ 0, /* NOTNULL => nothing */
131586
+ 0, /* NE => nothing */
131587
+ 0, /* EQ => nothing */
131588
+ 0, /* GT => nothing */
131589
+ 0, /* LE => nothing */
131590
+ 0, /* LT => nothing */
131591
+ 0, /* GE => nothing */
131592
+ 0, /* ESCAPE => nothing */
131593
+ 0, /* BITAND => nothing */
131594
+ 0, /* BITOR => nothing */
131595
+ 0, /* LSHIFT => nothing */
131596
+ 0, /* RSHIFT => nothing */
131597
+ 0, /* PLUS => nothing */
131598
+ 0, /* MINUS => nothing */
131599
+ 0, /* STAR => nothing */
131600
+ 0, /* SLASH => nothing */
131601
+ 0, /* REM => nothing */
131602
+ 0, /* CONCAT => nothing */
131603
+ 0, /* COLLATE => nothing */
131604
+ 0, /* BITNOT => nothing */
131079131605
0, /* ID => nothing */
131080131606
0, /* INDEXED => nothing */
131081
- 27, /* ABORT => ID */
131082
- 27, /* ACTION => ID */
131083
- 27, /* AFTER => ID */
131084
- 27, /* ANALYZE => ID */
131085
- 27, /* ASC => ID */
131086
- 27, /* ATTACH => ID */
131087
- 27, /* BEFORE => ID */
131088
- 27, /* BY => ID */
131089
- 27, /* CASCADE => ID */
131090
- 27, /* CAST => ID */
131091
- 27, /* COLUMNKW => ID */
131092
- 27, /* CONFLICT => ID */
131093
- 27, /* DATABASE => ID */
131094
- 27, /* DESC => ID */
131095
- 27, /* DETACH => ID */
131096
- 27, /* EACH => ID */
131097
- 27, /* FAIL => ID */
131098
- 27, /* FOR => ID */
131099
- 27, /* IGNORE => ID */
131100
- 27, /* INITIALLY => ID */
131101
- 27, /* INSTEAD => ID */
131102
- 27, /* LIKE_KW => ID */
131103
- 27, /* MATCH => ID */
131104
- 27, /* NO => ID */
131105
- 27, /* KEY => ID */
131106
- 27, /* OF => ID */
131107
- 27, /* OFFSET => ID */
131108
- 27, /* PRAGMA => ID */
131109
- 27, /* RAISE => ID */
131110
- 27, /* RECURSIVE => ID */
131111
- 27, /* REPLACE => ID */
131112
- 27, /* RESTRICT => ID */
131113
- 27, /* ROW => ID */
131114
- 27, /* TRIGGER => ID */
131115
- 27, /* VACUUM => ID */
131116
- 27, /* VIEW => ID */
131117
- 27, /* VIRTUAL => ID */
131118
- 27, /* WITH => ID */
131119
- 27, /* REINDEX => ID */
131120
- 27, /* RENAME => ID */
131121
- 27, /* CTIME_KW => ID */
131607
+ 55, /* ABORT => ID */
131608
+ 55, /* ACTION => ID */
131609
+ 55, /* AFTER => ID */
131610
+ 55, /* ANALYZE => ID */
131611
+ 55, /* ASC => ID */
131612
+ 55, /* ATTACH => ID */
131613
+ 55, /* BEFORE => ID */
131614
+ 55, /* BY => ID */
131615
+ 55, /* CASCADE => ID */
131616
+ 55, /* CAST => ID */
131617
+ 55, /* COLUMNKW => ID */
131618
+ 55, /* CONFLICT => ID */
131619
+ 55, /* DATABASE => ID */
131620
+ 55, /* DESC => ID */
131621
+ 55, /* DETACH => ID */
131622
+ 55, /* EACH => ID */
131623
+ 55, /* FAIL => ID */
131624
+ 55, /* FOR => ID */
131625
+ 55, /* IGNORE => ID */
131626
+ 55, /* INITIALLY => ID */
131627
+ 55, /* INSTEAD => ID */
131628
+ 55, /* NO => ID */
131629
+ 55, /* KEY => ID */
131630
+ 55, /* OF => ID */
131631
+ 55, /* OFFSET => ID */
131632
+ 55, /* PRAGMA => ID */
131633
+ 55, /* RAISE => ID */
131634
+ 55, /* RECURSIVE => ID */
131635
+ 55, /* REPLACE => ID */
131636
+ 55, /* RESTRICT => ID */
131637
+ 55, /* ROW => ID */
131638
+ 55, /* TRIGGER => ID */
131639
+ 55, /* VACUUM => ID */
131640
+ 55, /* VIEW => ID */
131641
+ 55, /* VIRTUAL => ID */
131642
+ 55, /* WITH => ID */
131643
+ 55, /* REINDEX => ID */
131644
+ 55, /* RENAME => ID */
131645
+ 55, /* CTIME_KW => ID */
131122131646
};
131123131647
#endif /* YYFALLBACK */
131124131648
131125131649
/* The following structure represents a single element of the
131126131650
** parser's stack. Information stored includes:
@@ -131207,29 +131731,29 @@
131207131731
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131208131732
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131209131733
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131210131734
"TABLE", "CREATE", "IF", "NOT",
131211131735
"EXISTS", "TEMP", "LP", "RP",
131212
- "AS", "WITHOUT", "COMMA", "ID",
131736
+ "AS", "WITHOUT", "COMMA", "OR",
131737
+ "AND", "IS", "MATCH", "LIKE_KW",
131738
+ "BETWEEN", "IN", "ISNULL", "NOTNULL",
131739
+ "NE", "EQ", "GT", "LE",
131740
+ "LT", "GE", "ESCAPE", "BITAND",
131741
+ "BITOR", "LSHIFT", "RSHIFT", "PLUS",
131742
+ "MINUS", "STAR", "SLASH", "REM",
131743
+ "CONCAT", "COLLATE", "BITNOT", "ID",
131213131744
"INDEXED", "ABORT", "ACTION", "AFTER",
131214131745
"ANALYZE", "ASC", "ATTACH", "BEFORE",
131215131746
"BY", "CASCADE", "CAST", "COLUMNKW",
131216131747
"CONFLICT", "DATABASE", "DESC", "DETACH",
131217131748
"EACH", "FAIL", "FOR", "IGNORE",
131218
- "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
131219
- "NO", "KEY", "OF", "OFFSET",
131220
- "PRAGMA", "RAISE", "RECURSIVE", "REPLACE",
131221
- "RESTRICT", "ROW", "TRIGGER", "VACUUM",
131222
- "VIEW", "VIRTUAL", "WITH", "REINDEX",
131223
- "RENAME", "CTIME_KW", "ANY", "OR",
131224
- "AND", "IS", "BETWEEN", "IN",
131225
- "ISNULL", "NOTNULL", "NE", "EQ",
131226
- "GT", "LE", "LT", "GE",
131227
- "ESCAPE", "BITAND", "BITOR", "LSHIFT",
131228
- "RSHIFT", "PLUS", "MINUS", "STAR",
131229
- "SLASH", "REM", "CONCAT", "COLLATE",
131230
- "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT",
131749
+ "INITIALLY", "INSTEAD", "NO", "KEY",
131750
+ "OF", "OFFSET", "PRAGMA", "RAISE",
131751
+ "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
131752
+ "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
131753
+ "WITH", "REINDEX", "RENAME", "CTIME_KW",
131754
+ "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
131231131755
"DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131232131756
"CHECK", "REFERENCES", "AUTOINCR", "ON",
131233131757
"INSERT", "DELETE", "UPDATE", "SET",
131234131758
"DEFERRABLE", "FOREIGN", "DROP", "UNION",
131235131759
"ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133529,27 @@
133005133529
yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133006133530
}
133007133531
break;
133008133532
case 156: /* expr ::= VARIABLE */
133009133533
{
133010
- Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133011
- if( t.n>=2 && t.z[0]=='#' && sqlite3Isdigit(t.z[1]) ){
133534
+ if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
133535
+ spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
133536
+ sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133537
+ }else{
133012133538
/* When doing a nested parse, one can include terms in an expression
133013133539
** that look like this: #1 #2 ... These terms refer to registers
133014133540
** in the virtual machine. #N is the N-th register. */
133541
+ Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133542
+ assert( t.n>=2 );
133015133543
spanSet(&yymsp[0].minor.yy342, &t, &t);
133016133544
if( pParse->nested==0 ){
133017133545
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133018133546
yymsp[0].minor.yy342.pExpr = 0;
133019133547
}else{
133020133548
yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133021133549
if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133022133550
}
133023
- }else{
133024
- spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, t);
133025
- sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133026133551
}
133027133552
}
133028133553
break;
133029133554
case 157: /* expr ::= expr COLLATE ID|STRING */
133030133555
{
@@ -133205,60 +133730,37 @@
133205133730
break;
133206133731
case 188: /* expr ::= LP select RP */
133207133732
{
133208133733
spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133209133734
yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133210
- if( yymsp[-2].minor.yy342.pExpr ){
133211
- yymsp[-2].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133212
- ExprSetProperty(yymsp[-2].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133213
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-2].minor.yy342.pExpr);
133214
- }else{
133215
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133216
- }
133735
+ sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy342.pExpr, yymsp[-1].minor.yy159);
133217133736
}
133218133737
break;
133219133738
case 189: /* expr ::= expr in_op LP select RP */
133220133739
{
133221133740
yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133222
- if( yymsp[-4].minor.yy342.pExpr ){
133223
- yymsp[-4].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133224
- ExprSetProperty(yymsp[-4].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133225
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy342.pExpr);
133226
- }else{
133227
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133228
- }
133741
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy342.pExpr, yymsp[-1].minor.yy159);
133229133742
exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133230133743
yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133231133744
}
133232133745
break;
133233133746
case 190: /* expr ::= expr in_op nm dbnm */
133234133747
{
133235133748
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
133749
+ Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133236133750
yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133237
- if( yymsp[-3].minor.yy342.pExpr ){
133238
- yymsp[-3].minor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133239
- ExprSetProperty(yymsp[-3].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133240
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-3].minor.yy342.pExpr);
133241
- }else{
133242
- sqlite3SrcListDelete(pParse->db, pSrc);
133243
- }
133751
+ sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy342.pExpr, pSelect);
133244133752
exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133245133753
yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133246133754
}
133247133755
break;
133248133756
case 191: /* expr ::= EXISTS LP select RP */
133249133757
{
133250133758
Expr *p;
133251133759
spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133252133760
p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133253
- if( p ){
133254
- p->x.pSelect = yymsp[-1].minor.yy159;
133255
- ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
133256
- sqlite3ExprSetHeightAndFlags(pParse, p);
133257
- }else{
133258
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133259
- }
133761
+ sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy159);
133260133762
}
133261133763
break;
133262133764
case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133263133765
{
133264133766
spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135241,11 @@
134739135241
** will take responsibility for freeing the Table structure.
134740135242
*/
134741135243
sqlite3DeleteTable(db, pParse->pNewTable);
134742135244
}
134743135245
134744
- sqlite3WithDelete(db, pParse->pWithToFree);
135246
+ if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
134745135247
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
134746135248
for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
134747135249
sqlite3DbFree(db, pParse->azVar);
134748135250
while( pParse->pAinc ){
134749135251
AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136451,11 @@
135949136451
u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
135950136452
} aFlagOp[] = {
135951136453
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
135952136454
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
135953136455
{ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
136456
+ { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
135954136457
};
135955136458
unsigned int i;
135956136459
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
135957136460
for(i=0; i<ArraySize(aFlagOp); i++){
135958136461
if( aFlagOp[i].op==op ){
@@ -162447,19 +162950,21 @@
162447162950
** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162448162951
**
162449162952
** http://www.icu-project.org/userguide/posix.html#case_mappings
162450162953
*/
162451162954
static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162452
- const UChar *zInput;
162453
- UChar *zOutput = 0;
162454
- int nInput;
162455
- int nOut;
162955
+ const UChar *zInput; /* Pointer to input string */
162956
+ UChar *zOutput = 0; /* Pointer to output buffer */
162957
+ int nInput; /* Size of utf-16 input string in bytes */
162958
+ int nOut; /* Size of output buffer in bytes */
162456162959
int cnt;
162960
+ int bToUpper; /* True for toupper(), false for tolower() */
162457162961
UErrorCode status;
162458162962
const char *zLocale = 0;
162459162963
162460162964
assert(nArg==1 || nArg==2);
162965
+ bToUpper = (sqlite3_user_data(p)!=0);
162461162966
if( nArg==2 ){
162462162967
zLocale = (const char *)sqlite3_value_text(apArg[1]);
162463162968
}
162464162969
162465162970
zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162984,27 @@
162479162984
sqlite3_result_error_nomem(p);
162480162985
return;
162481162986
}
162482162987
zOutput = zNew;
162483162988
status = U_ZERO_ERROR;
162484
- if( sqlite3_user_data(p) ){
162989
+ if( bToUpper ){
162485162990
nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162486162991
}else{
162487162992
nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162488162993
}
162489
- if( !U_SUCCESS(status) ){
162490
- if( status==U_BUFFER_OVERFLOW_ERROR ) continue;
162491
- icuFunctionError(p,
162492
- sqlite3_user_data(p) ? "u_strToUpper" : "u_strToLower", status);
162493
- return;
162494
- }
162495
- }
162496
- sqlite3_result_text16(p, zOutput, nOut, xFree);
162994
+
162995
+ if( U_SUCCESS(status) ){
162996
+ sqlite3_result_text16(p, zOutput, nOut, xFree);
162997
+ }else if( status==U_BUFFER_OVERFLOW_ERROR ){
162998
+ assert( cnt==0 );
162999
+ continue;
163000
+ }else{
163001
+ icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status);
163002
+ }
163003
+ return;
163004
+ }
163005
+ assert( 0 ); /* Unreachable */
162497163006
}
162498163007
162499163008
/*
162500163009
** Collation sequence destructor function. The pCtx argument points to
162501163010
** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163817,42 @@
163308163817
const char *zTarget,
163309163818
const char *zRbu,
163310163819
const char *zState
163311163820
);
163312163821
163822
+/*
163823
+** Open an RBU handle to perform an RBU vacuum on database file zTarget.
163824
+** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
163825
+** that it can be suspended and resumed like an RBU update.
163826
+**
163827
+** The second argument to this function, which may not be NULL, identifies
163828
+** a database in which to store the state of the RBU vacuum operation if
163829
+** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
163830
+** an RBU vacuum operation, the state database should either not exist or
163831
+** be empty (contain no tables). If an RBU vacuum is suspended by calling
163832
+** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
163833
+** returned SQLITE_DONE, the vacuum state is stored in the state database.
163834
+** The vacuum can be resumed by calling this function to open a new RBU
163835
+** handle specifying the same target and state databases.
163836
+**
163837
+** This function does not delete the state database after an RBU vacuum
163838
+** is completed, even if it created it. However, if the call to
163839
+** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
163840
+** of the state tables within the state database are zeroed. This way,
163841
+** the next call to sqlite3rbu_vacuum() opens a handle that starts a
163842
+** new RBU vacuum operation.
163843
+**
163844
+** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
163845
+** describing the sqlite3rbu_create_vfs() API function below for
163846
+** a description of the complications associated with using RBU with
163847
+** zipvfs databases.
163848
+*/
163849
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
163850
+ const char *zTarget,
163851
+ const char *zState
163852
+);
163853
+
163313163854
/*
163314163855
** Internally, each RBU connection uses a separate SQLite database
163315163856
** connection to access the target and rbu update databases. This
163316163857
** API allows the application direct access to these database handles.
163317163858
**
@@ -163586,10 +164127,11 @@
163586164127
typedef struct rbu_file rbu_file;
163587164128
typedef struct RbuUpdateStmt RbuUpdateStmt;
163588164129
163589164130
#if !defined(SQLITE_AMALGAMATION)
163590164131
typedef unsigned int u32;
164132
+typedef unsigned short u16;
163591164133
typedef unsigned char u8;
163592164134
typedef sqlite3_int64 i64;
163593164135
#endif
163594164136
163595164137
/*
@@ -163598,10 +164140,12 @@
163598164140
** format.
163599164141
*/
163600164142
#define WAL_LOCK_WRITE 0
163601164143
#define WAL_LOCK_CKPT 1
163602164144
#define WAL_LOCK_READ0 3
164145
+
164146
+#define SQLITE_FCNTL_RBUCNT 5149216
163603164147
163604164148
/*
163605164149
** A structure to store values read from the rbu_state table in memory.
163606164150
*/
163607164151
struct RbuState {
@@ -163777,10 +164321,14 @@
163777164321
int nFrameAlloc; /* Allocated size of aFrame[] array */
163778164322
RbuFrame *aFrame;
163779164323
int pgsz;
163780164324
u8 *aBuf;
163781164325
i64 iWalCksum;
164326
+
164327
+ /* Used in RBU vacuum mode only */
164328
+ int nRbu; /* Number of RBU VFS in the stack */
164329
+ rbu_file *pRbuFd; /* Fd for main db of dbRbu */
163782164330
};
163783164331
163784164332
/*
163785164333
** An rbu VFS is implemented using an instance of this structure.
163786164334
*/
@@ -163802,10 +164350,11 @@
163802164350
sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
163803164351
163804164352
int openFlags; /* Flags this file was opened with */
163805164353
u32 iCookie; /* Cookie value for main db files */
163806164354
u8 iWriteVer; /* "write-version" value for main db files */
164355
+ u8 bNolock; /* True to fail EXCLUSIVE locks */
163807164356
163808164357
int nShm; /* Number of entries in apShm[] array */
163809164358
char **apShm; /* Array of mmap'd *-shm regions */
163810164359
char *zDel; /* Delete this when closing file */
163811164360
@@ -163812,10 +164361,15 @@
163812164361
const char *zWal; /* Wal filename for this main db file */
163813164362
rbu_file *pWalFd; /* Wal file descriptor for this main db */
163814164363
rbu_file *pMainNext; /* Next MAIN_DB file */
163815164364
};
163816164365
164366
+/*
164367
+** True for an RBU vacuum handle, or false otherwise.
164368
+*/
164369
+#define rbuIsVacuum(p) ((p)->zTarget==0)
164370
+
163817164371
163818164372
/*************************************************************************
163819164373
** The following three functions, found below:
163820164374
**
163821164375
** rbuDeltaGetInt()
@@ -164260,12 +164814,15 @@
164260164814
}
164261164815
164262164816
164263164817
/*
164264164818
** The implementation of the rbu_target_name() SQL function. This function
164265
-** accepts one argument - the name of a table in the RBU database. If the
164266
-** table name matches the pattern:
164819
+** accepts one or two arguments. The first argument is the name of a table -
164820
+** the name of a table in the RBU database. The second, if it is present, is 1
164821
+** for a view or 0 for a table.
164822
+**
164823
+** For a non-vacuum RBU handle, if the table name matches the pattern:
164267164824
**
164268164825
** data[0-9]_<name>
164269164826
**
164270164827
** where <name> is any sequence of 1 or more characters, <name> is returned.
164271164828
** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164829,37 @@
164272164829
** NULL is returned.
164273164830
**
164274164831
** "data_t1" -> "t1"
164275164832
** "data0123_t2" -> "t2"
164276164833
** "dataAB_t3" -> NULL
164834
+**
164835
+** For an rbu vacuum handle, a copy of the first argument is returned if
164836
+** the second argument is either missing or 0 (not a view).
164277164837
*/
164278164838
static void rbuTargetNameFunc(
164279
- sqlite3_context *context,
164839
+ sqlite3_context *pCtx,
164280164840
int argc,
164281164841
sqlite3_value **argv
164282164842
){
164843
+ sqlite3rbu *p = sqlite3_user_data(pCtx);
164283164844
const char *zIn;
164284
- assert( argc==1 );
164845
+ assert( argc==1 || argc==2 );
164285164846
164286164847
zIn = (const char*)sqlite3_value_text(argv[0]);
164287
- if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164288
- int i;
164289
- for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164290
- if( zIn[i]=='_' && zIn[i+1] ){
164291
- sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
164848
+ if( zIn ){
164849
+ if( rbuIsVacuum(p) ){
164850
+ if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
164851
+ sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC);
164852
+ }
164853
+ }else{
164854
+ if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164855
+ int i;
164856
+ for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164857
+ if( zIn[i]=='_' && zIn[i+1] ){
164858
+ sqlite3_result_text(pCtx, &zIn[i+1], -1, SQLITE_STATIC);
164859
+ }
164860
+ }
164292164861
}
164293164862
}
164294164863
}
164295164864
164296164865
/*
@@ -164304,11 +164873,12 @@
164304164873
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164305164874
int rc;
164306164875
memset(pIter, 0, sizeof(RbuObjIter));
164307164876
164308164877
rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164309
- "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
164878
+ "SELECT rbu_target_name(name, type='view') AS target, name "
164879
+ "FROM sqlite_master "
164310164880
"WHERE type IN ('table', 'view') AND target IS NOT NULL "
164311164881
"ORDER BY name"
164312164882
);
164313164883
164314164884
if( rc==SQLITE_OK ){
@@ -164680,10 +165250,11 @@
164680165250
}
164681165251
sqlite3_finalize(pStmt);
164682165252
pStmt = 0;
164683165253
164684165254
if( p->rc==SQLITE_OK
165255
+ && rbuIsVacuum(p)==0
164685165256
&& bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
164686165257
){
164687165258
p->rc = SQLITE_ERROR;
164688165259
p->zErrmsg = sqlite3_mprintf(
164689165260
"table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165390,12 @@
164819165390
if( pIter->eType==RBU_PK_IPK ){
164820165391
int i;
164821165392
for(i=0; pIter->abTblPk[i]==0; i++);
164822165393
assert( i<pIter->nTblCol );
164823165394
zCol = pIter->azTblCol[i];
165395
+ }else if( rbuIsVacuum(p) ){
165396
+ zCol = "_rowid_";
164824165397
}else{
164825165398
zCol = "rbu_rowid";
164826165399
}
164827165400
zType = "INTEGER";
164828165401
}else{
@@ -165359,20 +165932,29 @@
165359165932
sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165360165933
);
165361165934
}
165362165935
165363165936
/* And to delete index entries */
165364
- if( p->rc==SQLITE_OK ){
165937
+ if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165365165938
p->rc = prepareFreeAndCollectError(
165366165939
p->dbMain, &pIter->pDelete, &p->zErrmsg,
165367165940
sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165368165941
);
165369165942
}
165370165943
165371165944
/* Create the SELECT statement to read keys in sorted order */
165372165945
if( p->rc==SQLITE_OK ){
165373165946
char *zSql;
165947
+ if( rbuIsVacuum(p) ){
165948
+ zSql = sqlite3_mprintf(
165949
+ "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
165950
+ zCollist,
165951
+ pIter->zDataTbl,
165952
+ zCollist, zLimit
165953
+ );
165954
+ }else
165955
+
165374165956
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165375165957
zSql = sqlite3_mprintf(
165376165958
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165377165959
zCollist, p->zStateDb, pIter->zDataTbl,
165378165960
zCollist, zLimit
@@ -165395,11 +165977,13 @@
165395165977
sqlite3_free(zImposterCols);
165396165978
sqlite3_free(zImposterPK);
165397165979
sqlite3_free(zWhere);
165398165980
sqlite3_free(zBind);
165399165981
}else{
165400
- int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
165982
+ int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
165983
+ ||(pIter->eType==RBU_PK_NONE)
165984
+ ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
165401165985
const char *zTbl = pIter->zTbl; /* Table this step applies to */
165402165986
const char *zWrite; /* Imposter table name */
165403165987
165404165988
char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165405165989
char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +166006,22 @@
165422166006
zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
165423166007
)
165424166008
);
165425166009
}
165426166010
165427
- /* Create the DELETE statement to write to the target PK b-tree */
165428
- if( p->rc==SQLITE_OK ){
166011
+ /* Create the DELETE statement to write to the target PK b-tree.
166012
+ ** Because it only performs INSERT operations, this is not required for
166013
+ ** an rbu vacuum handle. */
166014
+ if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165429166015
p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
165430166016
sqlite3_mprintf(
165431166017
"DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
165432166018
)
165433166019
);
165434166020
}
165435166021
165436
- if( pIter->abIndexed ){
166022
+ if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
165437166023
const char *zRbuRowid = "";
165438166024
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165439166025
zRbuRowid = ", rbu_rowid";
165440166026
}
165441166027
@@ -165481,14 +166067,20 @@
165481166067
rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
165482166068
}
165483166069
165484166070
/* Create the SELECT statement to read keys from data_xxx */
165485166071
if( p->rc==SQLITE_OK ){
166072
+ const char *zRbuRowid = "";
166073
+ if( bRbuRowid ){
166074
+ zRbuRowid = rbuIsVacuum(p) ? ",_rowid_ " : ",rbu_rowid";
166075
+ }
165486166076
p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
165487166077
sqlite3_mprintf(
165488
- "SELECT %s, rbu_control%s FROM '%q'%s",
165489
- zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
166078
+ "SELECT %s,%s rbu_control%s FROM '%q'%s",
166079
+ zCollist,
166080
+ (rbuIsVacuum(p) ? "0 AS " : ""),
166081
+ zRbuRowid,
165490166082
pIter->zDataTbl, zLimit
165491166083
)
165492166084
);
165493166085
}
165494166086
@@ -165579,44 +166171,231 @@
165579166171
}
165580166172
165581166173
return p->rc;
165582166174
}
165583166175
165584
-static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
166176
+static sqlite3 *rbuOpenDbhandle(
166177
+ sqlite3rbu *p,
166178
+ const char *zName,
166179
+ int bUseVfs
166180
+){
165585166181
sqlite3 *db = 0;
165586166182
if( p->rc==SQLITE_OK ){
165587166183
const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
165588
- p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
166184
+ p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
165589166185
if( p->rc ){
165590166186
p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
165591166187
sqlite3_close(db);
165592166188
db = 0;
165593166189
}
165594166190
}
165595166191
return db;
165596166192
}
166193
+
166194
+/*
166195
+** Free an RbuState object allocated by rbuLoadState().
166196
+*/
166197
+static void rbuFreeState(RbuState *p){
166198
+ if( p ){
166199
+ sqlite3_free(p->zTbl);
166200
+ sqlite3_free(p->zIdx);
166201
+ sqlite3_free(p);
166202
+ }
166203
+}
166204
+
166205
+/*
166206
+** Allocate an RbuState object and load the contents of the rbu_state
166207
+** table into it. Return a pointer to the new object. It is the
166208
+** responsibility of the caller to eventually free the object using
166209
+** sqlite3_free().
166210
+**
166211
+** If an error occurs, leave an error code and message in the rbu handle
166212
+** and return NULL.
166213
+*/
166214
+static RbuState *rbuLoadState(sqlite3rbu *p){
166215
+ RbuState *pRet = 0;
166216
+ sqlite3_stmt *pStmt = 0;
166217
+ int rc;
166218
+ int rc2;
166219
+
166220
+ pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166221
+ if( pRet==0 ) return 0;
166222
+
166223
+ rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166224
+ sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166225
+ );
166226
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166227
+ switch( sqlite3_column_int(pStmt, 0) ){
166228
+ case RBU_STATE_STAGE:
166229
+ pRet->eStage = sqlite3_column_int(pStmt, 1);
166230
+ if( pRet->eStage!=RBU_STAGE_OAL
166231
+ && pRet->eStage!=RBU_STAGE_MOVE
166232
+ && pRet->eStage!=RBU_STAGE_CKPT
166233
+ ){
166234
+ p->rc = SQLITE_CORRUPT;
166235
+ }
166236
+ break;
166237
+
166238
+ case RBU_STATE_TBL:
166239
+ pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166240
+ break;
166241
+
166242
+ case RBU_STATE_IDX:
166243
+ pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166244
+ break;
166245
+
166246
+ case RBU_STATE_ROW:
166247
+ pRet->nRow = sqlite3_column_int(pStmt, 1);
166248
+ break;
166249
+
166250
+ case RBU_STATE_PROGRESS:
166251
+ pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166252
+ break;
166253
+
166254
+ case RBU_STATE_CKPT:
166255
+ pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166256
+ break;
166257
+
166258
+ case RBU_STATE_COOKIE:
166259
+ pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166260
+ break;
166261
+
166262
+ case RBU_STATE_OALSZ:
166263
+ pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166264
+ break;
166265
+
166266
+ case RBU_STATE_PHASEONESTEP:
166267
+ pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166268
+ break;
166269
+
166270
+ default:
166271
+ rc = SQLITE_CORRUPT;
166272
+ break;
166273
+ }
166274
+ }
166275
+ rc2 = sqlite3_finalize(pStmt);
166276
+ if( rc==SQLITE_OK ) rc = rc2;
166277
+
166278
+ p->rc = rc;
166279
+ return pRet;
166280
+}
166281
+
165597166282
165598166283
/*
165599166284
** Open the database handle and attach the RBU database as "rbu". If an
165600166285
** error occurs, leave an error code and message in the RBU handle.
165601166286
*/
165602166287
static void rbuOpenDatabase(sqlite3rbu *p){
165603166288
assert( p->rc==SQLITE_OK );
165604166289
assert( p->dbMain==0 && p->dbRbu==0 );
166290
+ assert( rbuIsVacuum(p) || p->zTarget!=0 );
165605166291
165606
- p->eStage = 0;
165607
- p->dbMain = rbuOpenDbhandle(p, p->zTarget);
165608
- p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
166292
+ /* Open the RBU database */
166293
+ p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
166294
+
166295
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166296
+ sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166297
+ }
165609166298
165610166299
/* If using separate RBU and state databases, attach the state database to
165611166300
** the RBU db handle now. */
165612166301
if( p->zState ){
165613166302
rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
165614166303
memcpy(p->zStateDb, "stat", 4);
165615166304
}else{
165616166305
memcpy(p->zStateDb, "main", 4);
165617166306
}
166307
+
166308
+#if 0
166309
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166310
+ p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
166311
+ }
166312
+#endif
166313
+
166314
+ /* If it has not already been created, create the rbu_state table */
166315
+ rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166316
+
166317
+#if 0
166318
+ if( rbuIsVacuum(p) ){
166319
+ if( p->rc==SQLITE_OK ){
166320
+ int rc2;
166321
+ int bOk = 0;
166322
+ sqlite3_stmt *pCnt = 0;
166323
+ p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
166324
+ "SELECT count(*) FROM stat.sqlite_master"
166325
+ );
166326
+ if( p->rc==SQLITE_OK
166327
+ && sqlite3_step(pCnt)==SQLITE_ROW
166328
+ && 1==sqlite3_column_int(pCnt, 0)
166329
+ ){
166330
+ bOk = 1;
166331
+ }
166332
+ rc2 = sqlite3_finalize(pCnt);
166333
+ if( p->rc==SQLITE_OK ) p->rc = rc2;
166334
+
166335
+ if( p->rc==SQLITE_OK && bOk==0 ){
166336
+ p->rc = SQLITE_ERROR;
166337
+ p->zErrmsg = sqlite3_mprintf("invalid state database");
166338
+ }
166339
+
166340
+ if( p->rc==SQLITE_OK ){
166341
+ p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
166342
+ }
166343
+ }
166344
+ }
166345
+#endif
166346
+
166347
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166348
+ int bOpen = 0;
166349
+ int rc;
166350
+ p->nRbu = 0;
166351
+ p->pRbuFd = 0;
166352
+ rc = sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166353
+ if( rc!=SQLITE_NOTFOUND ) p->rc = rc;
166354
+ if( p->eStage>=RBU_STAGE_MOVE ){
166355
+ bOpen = 1;
166356
+ }else{
166357
+ RbuState *pState = rbuLoadState(p);
166358
+ if( pState ){
166359
+ bOpen = (pState->eStage>RBU_STAGE_MOVE);
166360
+ rbuFreeState(pState);
166361
+ }
166362
+ }
166363
+ if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
166364
+ }
166365
+
166366
+ p->eStage = 0;
166367
+ if( p->rc==SQLITE_OK && p->dbMain==0 ){
166368
+ if( !rbuIsVacuum(p) ){
166369
+ p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
166370
+ }else if( p->pRbuFd->pWalFd ){
166371
+ p->rc = SQLITE_ERROR;
166372
+ p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
166373
+ }else{
166374
+ char *zTarget;
166375
+ char *zExtra = 0;
166376
+ if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
166377
+ zExtra = &p->zRbu[5];
166378
+ while( *zExtra ){
166379
+ if( *zExtra++=='?' ) break;
166380
+ }
166381
+ if( *zExtra=='\0' ) zExtra = 0;
166382
+ }
166383
+
166384
+ zTarget = sqlite3_mprintf("file:%s-vacuum?rbu_memory=1%s%s",
166385
+ sqlite3_db_filename(p->dbRbu, "main"),
166386
+ (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
166387
+ );
166388
+
166389
+ if( zTarget==0 ){
166390
+ p->rc = SQLITE_NOMEM;
166391
+ return;
166392
+ }
166393
+ p->dbMain = rbuOpenDbhandle(p, zTarget, p->nRbu<=1);
166394
+ sqlite3_free(zTarget);
166395
+ }
166396
+ }
165618166397
165619166398
if( p->rc==SQLITE_OK ){
165620166399
p->rc = sqlite3_create_function(p->dbMain,
165621166400
"rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
165622166401
);
@@ -165628,11 +166407,11 @@
165628166407
);
165629166408
}
165630166409
165631166410
if( p->rc==SQLITE_OK ){
165632166411
p->rc = sqlite3_create_function(p->dbRbu,
165633
- "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
166412
+ "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
165634166413
);
165635166414
}
165636166415
165637166416
if( p->rc==SQLITE_OK ){
165638166417
p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166666,19 @@
165887166666
** If an error occurs, leave an error code and error message in the rbu
165888166667
** handle.
165889166668
*/
165890166669
static void rbuMoveOalFile(sqlite3rbu *p){
165891166670
const char *zBase = sqlite3_db_filename(p->dbMain, "main");
166671
+ const char *zMove = zBase;
166672
+ char *zOal;
166673
+ char *zWal;
165892166674
165893
- char *zWal = sqlite3_mprintf("%s-wal", zBase);
165894
- char *zOal = sqlite3_mprintf("%s-oal", zBase);
166675
+ if( rbuIsVacuum(p) ){
166676
+ zMove = sqlite3_db_filename(p->dbRbu, "main");
166677
+ }
166678
+ zOal = sqlite3_mprintf("%s-oal", zMove);
166679
+ zWal = sqlite3_mprintf("%s-wal", zMove);
165895166680
165896166681
assert( p->eStage==RBU_STAGE_MOVE );
165897166682
assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
165898166683
if( zWal==0 || zOal==0 ){
165899166684
p->rc = SQLITE_NOMEM;
@@ -165910,12 +166695,12 @@
165910166695
rbuFileSuffix3(zBase, zWal);
165911166696
rbuFileSuffix3(zBase, zOal);
165912166697
165913166698
/* Re-open the databases. */
165914166699
rbuObjIterFinalize(&p->objiter);
165915
- sqlite3_close(p->dbMain);
165916166700
sqlite3_close(p->dbRbu);
166701
+ sqlite3_close(p->dbMain);
165917166702
p->dbMain = 0;
165918166703
p->dbRbu = 0;
165919166704
165920166705
#if defined(_WIN32_WCE)
165921166706
{
@@ -166073,23 +166858,28 @@
166073166858
166074166859
pVal = sqlite3_column_value(pIter->pSelect, i);
166075166860
p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166076166861
if( p->rc ) return;
166077166862
}
166078
- if( pIter->zIdx==0
166079
- && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
166080
- ){
166081
- /* For a virtual table, or a table with no primary key, the
166082
- ** SELECT statement is:
166083
- **
166084
- ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166085
- **
166086
- ** Hence column_value(pIter->nCol+1).
166087
- */
166088
- assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
166089
- pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166090
- p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166863
+ if( pIter->zIdx==0 ){
166864
+ if( pIter->eType==RBU_PK_VTAB
166865
+ || pIter->eType==RBU_PK_NONE
166866
+ || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p))
166867
+ ){
166868
+ /* For a virtual table, or a table with no primary key, the
166869
+ ** SELECT statement is:
166870
+ **
166871
+ ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166872
+ **
166873
+ ** Hence column_value(pIter->nCol+1).
166874
+ */
166875
+ assertColumnName(pIter->pSelect, pIter->nCol+1,
166876
+ rbuIsVacuum(p) ? "rowid" : "rbu_rowid"
166877
+ );
166878
+ pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166879
+ p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166880
+ }
166091166881
}
166092166882
if( p->rc==SQLITE_OK ){
166093166883
sqlite3_step(pWriter);
166094166884
p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166095166885
}
@@ -166164,17 +166954,22 @@
166164166954
return p->rc;
166165166955
}
166166166956
166167166957
/*
166168166958
** Increment the schema cookie of the main database opened by p->dbMain.
166959
+**
166960
+** Or, if this is an RBU vacuum, set the schema cookie of the main db
166961
+** opened by p->dbMain to one more than the schema cookie of the main
166962
+** db opened by p->dbRbu.
166169166963
*/
166170166964
static void rbuIncrSchemaCookie(sqlite3rbu *p){
166171166965
if( p->rc==SQLITE_OK ){
166966
+ sqlite3 *dbread = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
166172166967
int iCookie = 1000000;
166173166968
sqlite3_stmt *pStmt;
166174166969
166175
- p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
166970
+ p->rc = prepareAndCollectError(dbread, &pStmt, &p->zErrmsg,
166176166971
"PRAGMA schema_version"
166177166972
);
166178166973
if( p->rc==SQLITE_OK ){
166179166974
/* Coverage: it may be that this sqlite3_step() cannot fail. There
166180166975
** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166993,11 @@
166198166993
** are determined by inspecting the rbu handle passed as the first argument.
166199166994
*/
166200166995
static void rbuSaveState(sqlite3rbu *p, int eStage){
166201166996
if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166202166997
sqlite3_stmt *pInsert = 0;
166998
+ rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
166203166999
int rc;
166204167000
166205167001
assert( p->zErrmsg==0 );
166206167002
rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
166207167003
sqlite3_mprintf(
@@ -166220,11 +167016,11 @@
166220167016
RBU_STATE_TBL, p->objiter.zTbl,
166221167017
RBU_STATE_IDX, p->objiter.zIdx,
166222167018
RBU_STATE_ROW, p->nStep,
166223167019
RBU_STATE_PROGRESS, p->nProgress,
166224167020
RBU_STATE_CKPT, p->iWalCksum,
166225
- RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
167021
+ RBU_STATE_COOKIE, (i64)pFd->iCookie,
166226167022
RBU_STATE_OALSZ, p->iOalSz,
166227167023
RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
166228167024
)
166229167025
);
166230167026
assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +167031,121 @@
166235167031
}
166236167032
if( rc!=SQLITE_OK ) p->rc = rc;
166237167033
}
166238167034
}
166239167035
167036
+
167037
+/*
167038
+** The second argument passed to this function is the name of a PRAGMA
167039
+** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
167040
+** This function executes the following on sqlite3rbu.dbRbu:
167041
+**
167042
+** "PRAGMA main.$zPragma"
167043
+**
167044
+** where $zPragma is the string passed as the second argument, then
167045
+** on sqlite3rbu.dbMain:
167046
+**
167047
+** "PRAGMA main.$zPragma = $val"
167048
+**
167049
+** where $val is the value returned by the first PRAGMA invocation.
167050
+**
167051
+** In short, it copies the value of the specified PRAGMA setting from
167052
+** dbRbu to dbMain.
167053
+*/
167054
+static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){
167055
+ if( p->rc==SQLITE_OK ){
167056
+ sqlite3_stmt *pPragma = 0;
167057
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg,
167058
+ sqlite3_mprintf("PRAGMA main.%s", zPragma)
167059
+ );
167060
+ if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){
167061
+ p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d",
167062
+ zPragma, sqlite3_column_int(pPragma, 0)
167063
+ );
167064
+ }
167065
+ rbuFinalize(p, pPragma);
167066
+ }
167067
+}
167068
+
167069
+/*
167070
+** The RBU handle passed as the only argument has just been opened and
167071
+** the state database is empty. If this RBU handle was opened for an
167072
+** RBU vacuum operation, create the schema in the target db.
167073
+*/
167074
+static void rbuCreateTargetSchema(sqlite3rbu *p){
167075
+ sqlite3_stmt *pSql = 0;
167076
+ sqlite3_stmt *pInsert = 0;
167077
+
167078
+ assert( rbuIsVacuum(p) );
167079
+ p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
167080
+ if( p->rc==SQLITE_OK ){
167081
+ p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
167082
+ "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
167083
+ " AND name!='sqlite_sequence' "
167084
+ " ORDER BY type DESC"
167085
+ );
167086
+ }
167087
+
167088
+ while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
167089
+ const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
167090
+ p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
167091
+ }
167092
+ rbuFinalize(p, pSql);
167093
+ if( p->rc!=SQLITE_OK ) return;
167094
+
167095
+ if( p->rc==SQLITE_OK ){
167096
+ p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
167097
+ "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
167098
+ );
167099
+ }
167100
+
167101
+ if( p->rc==SQLITE_OK ){
167102
+ p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
167103
+ "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
167104
+ );
167105
+ }
167106
+
167107
+ while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
167108
+ int i;
167109
+ for(i=0; i<5; i++){
167110
+ sqlite3_bind_value(pInsert, i+1, sqlite3_column_value(pSql, i));
167111
+ }
167112
+ sqlite3_step(pInsert);
167113
+ p->rc = sqlite3_reset(pInsert);
167114
+ }
167115
+ if( p->rc==SQLITE_OK ){
167116
+ p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
167117
+ }
167118
+
167119
+ rbuFinalize(p, pSql);
167120
+ rbuFinalize(p, pInsert);
167121
+}
166240167122
166241167123
/*
166242167124
** Step the RBU object.
166243167125
*/
166244167126
SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
166245167127
if( p ){
166246167128
switch( p->eStage ){
166247167129
case RBU_STAGE_OAL: {
166248167130
RbuObjIter *pIter = &p->objiter;
167131
+
167132
+ /* If this is an RBU vacuum operation and the state table was empty
167133
+ ** when this handle was opened, create the target database schema. */
167134
+ if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
167135
+ rbuCreateTargetSchema(p);
167136
+ rbuCopyPragma(p, "user_version");
167137
+ rbuCopyPragma(p, "application_id");
167138
+ }
167139
+
166249167140
while( p->rc==SQLITE_OK && pIter->zTbl ){
166250167141
166251167142
if( pIter->bCleanup ){
166252167143
/* Clean up the rbu_tmp_xxx table for the previous table. It
166253167144
** cannot be dropped as there are currently active SQL statements.
166254167145
** But the contents can be deleted. */
166255
- if( pIter->abIndexed ){
167146
+ if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
166256167147
rbuMPrintfExec(p, p->dbRbu,
166257167148
"DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
166258167149
);
166259167150
}
166260167151
}else{
@@ -166337,98 +167228,10 @@
166337167228
}else{
166338167229
return SQLITE_NOMEM;
166339167230
}
166340167231
}
166341167232
166342
-/*
166343
-** Free an RbuState object allocated by rbuLoadState().
166344
-*/
166345
-static void rbuFreeState(RbuState *p){
166346
- if( p ){
166347
- sqlite3_free(p->zTbl);
166348
- sqlite3_free(p->zIdx);
166349
- sqlite3_free(p);
166350
- }
166351
-}
166352
-
166353
-/*
166354
-** Allocate an RbuState object and load the contents of the rbu_state
166355
-** table into it. Return a pointer to the new object. It is the
166356
-** responsibility of the caller to eventually free the object using
166357
-** sqlite3_free().
166358
-**
166359
-** If an error occurs, leave an error code and message in the rbu handle
166360
-** and return NULL.
166361
-*/
166362
-static RbuState *rbuLoadState(sqlite3rbu *p){
166363
- RbuState *pRet = 0;
166364
- sqlite3_stmt *pStmt = 0;
166365
- int rc;
166366
- int rc2;
166367
-
166368
- pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166369
- if( pRet==0 ) return 0;
166370
-
166371
- rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166372
- sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166373
- );
166374
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166375
- switch( sqlite3_column_int(pStmt, 0) ){
166376
- case RBU_STATE_STAGE:
166377
- pRet->eStage = sqlite3_column_int(pStmt, 1);
166378
- if( pRet->eStage!=RBU_STAGE_OAL
166379
- && pRet->eStage!=RBU_STAGE_MOVE
166380
- && pRet->eStage!=RBU_STAGE_CKPT
166381
- ){
166382
- p->rc = SQLITE_CORRUPT;
166383
- }
166384
- break;
166385
-
166386
- case RBU_STATE_TBL:
166387
- pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166388
- break;
166389
-
166390
- case RBU_STATE_IDX:
166391
- pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166392
- break;
166393
-
166394
- case RBU_STATE_ROW:
166395
- pRet->nRow = sqlite3_column_int(pStmt, 1);
166396
- break;
166397
-
166398
- case RBU_STATE_PROGRESS:
166399
- pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166400
- break;
166401
-
166402
- case RBU_STATE_CKPT:
166403
- pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166404
- break;
166405
-
166406
- case RBU_STATE_COOKIE:
166407
- pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166408
- break;
166409
-
166410
- case RBU_STATE_OALSZ:
166411
- pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166412
- break;
166413
-
166414
- case RBU_STATE_PHASEONESTEP:
166415
- pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166416
- break;
166417
-
166418
- default:
166419
- rc = SQLITE_CORRUPT;
166420
- break;
166421
- }
166422
- }
166423
- rc2 = sqlite3_finalize(pStmt);
166424
- if( rc==SQLITE_OK ) rc = rc2;
166425
-
166426
- p->rc = rc;
166427
- return pRet;
166428
-}
166429
-
166430167233
/*
166431167234
** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
166432167235
** otherwise. Either or both argument may be NULL. Two NULL values are
166433167236
** considered equal, and NULL is considered distinct from all other values.
166434167237
*/
@@ -166614,20 +167417,18 @@
166614167417
}
166615167418
}
166616167419
}
166617167420
}
166618167421
166619
-/*
166620
-** Open and return a new RBU handle.
166621
-*/
166622
-SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167422
+
167423
+static sqlite3rbu *openRbuHandle(
166623167424
const char *zTarget,
166624167425
const char *zRbu,
166625167426
const char *zState
166626167427
){
166627167428
sqlite3rbu *p;
166628
- size_t nTarget = strlen(zTarget);
167429
+ size_t nTarget = zTarget ? strlen(zTarget) : 0;
166629167430
size_t nRbu = strlen(zRbu);
166630167431
size_t nState = zState ? strlen(zState) : 0;
166631167432
size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
166632167433
166633167434
p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167437,28 @@
166636167437
166637167438
/* Create the custom VFS. */
166638167439
memset(p, 0, sizeof(sqlite3rbu));
166639167440
rbuCreateVfs(p);
166640167441
166641
- /* Open the target database */
167442
+ /* Open the target, RBU and state databases */
166642167443
if( p->rc==SQLITE_OK ){
166643
- p->zTarget = (char*)&p[1];
166644
- memcpy(p->zTarget, zTarget, nTarget+1);
166645
- p->zRbu = &p->zTarget[nTarget+1];
167444
+ char *pCsr = (char*)&p[1];
167445
+ if( zTarget ){
167446
+ p->zTarget = pCsr;
167447
+ memcpy(p->zTarget, zTarget, nTarget+1);
167448
+ pCsr += nTarget+1;
167449
+ }
167450
+ p->zRbu = pCsr;
166646167451
memcpy(p->zRbu, zRbu, nRbu+1);
167452
+ pCsr += nRbu+1;
166647167453
if( zState ){
166648
- p->zState = &p->zRbu[nRbu+1];
167454
+ p->zState = pCsr;
166649167455
memcpy(p->zState, zState, nState+1);
166650167456
}
166651167457
rbuOpenDatabase(p);
166652167458
}
166653167459
166654
- /* If it has not already been created, create the rbu_state table */
166655
- rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166656
-
166657167460
if( p->rc==SQLITE_OK ){
166658167461
pState = rbuLoadState(p);
166659167462
assert( pState || p->rc!=SQLITE_OK );
166660167463
if( p->rc==SQLITE_OK ){
166661167464
@@ -166681,31 +167484,43 @@
166681167484
p->eStage = RBU_STAGE_CKPT;
166682167485
p->nStep = 0;
166683167486
}
166684167487
}
166685167488
166686
- if( p->rc==SQLITE_OK
167489
+ if( p->rc==SQLITE_OK
166687167490
&& (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
166688
- && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
166689
- ){
166690
- /* At this point (pTargetFd->iCookie) contains the value of the
166691
- ** change-counter cookie (the thing that gets incremented when a
166692
- ** transaction is committed in rollback mode) currently stored on
166693
- ** page 1 of the database file. */
166694
- p->rc = SQLITE_BUSY;
166695
- p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
167491
+ && pState->eStage!=0
167492
+ ){
167493
+ rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
167494
+ if( pFd->iCookie!=pState->iCookie ){
167495
+ /* At this point (pTargetFd->iCookie) contains the value of the
167496
+ ** change-counter cookie (the thing that gets incremented when a
167497
+ ** transaction is committed in rollback mode) currently stored on
167498
+ ** page 1 of the database file. */
167499
+ p->rc = SQLITE_BUSY;
167500
+ p->zErrmsg = sqlite3_mprintf("database modified during rbu %s",
167501
+ (rbuIsVacuum(p) ? "vacuum" : "update")
167502
+ );
167503
+ }
166696167504
}
166697167505
166698167506
if( p->rc==SQLITE_OK ){
166699167507
if( p->eStage==RBU_STAGE_OAL ){
166700167508
sqlite3 *db = p->dbMain;
167509
+
167510
+ if( pState->eStage==0 && rbuIsVacuum(p) ){
167511
+ rbuCopyPragma(p, "page_size");
167512
+ rbuCopyPragma(p, "auto_vacuum");
167513
+ }
166701167514
166702167515
/* Open transactions both databases. The *-oal file is opened or
166703167516
** created at this point. */
166704
- p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167517
+ if( p->rc==SQLITE_OK ){
167518
+ p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167519
+ }
166705167520
if( p->rc==SQLITE_OK ){
166706
- p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167521
+ p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
166707167522
}
166708167523
166709167524
/* Check if the main database is a zipvfs db. If it is, set the upper
166710167525
** level pager to use "journal_mode=off". This prevents it from
166711167526
** generating a large journal using a temp file. */
@@ -166746,10 +167561,32 @@
166746167561
}
166747167562
166748167563
return p;
166749167564
}
166750167565
167566
+/*
167567
+** Open and return a new RBU handle.
167568
+*/
167569
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167570
+ const char *zTarget,
167571
+ const char *zRbu,
167572
+ const char *zState
167573
+){
167574
+ /* TODO: Check that zTarget and zRbu are non-NULL */
167575
+ return openRbuHandle(zTarget, zRbu, zState);
167576
+}
167577
+
167578
+/*
167579
+** Open a handle to begin or resume an RBU VACUUM operation.
167580
+*/
167581
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
167582
+ const char *zTarget,
167583
+ const char *zState
167584
+){
167585
+ /* TODO: Check that both arguments are non-NULL */
167586
+ return openRbuHandle(0, zTarget, zState);
167587
+}
166751167588
166752167589
/*
166753167590
** Return the database handle used by pRbu.
166754167591
*/
166755167592
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167603,11 @@
166766167603
** then edit any error message string so as to remove all occurrences of
166767167604
** the pattern "rbu_imp_[0-9]*".
166768167605
*/
166769167606
static void rbuEditErrmsg(sqlite3rbu *p){
166770167607
if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
166771
- int i;
167608
+ unsigned int i;
166772167609
size_t nErrmsg = strlen(p->zErrmsg);
166773167610
for(i=0; i<(nErrmsg-8); i++){
166774167611
if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
166775167612
int nDel = 8;
166776167613
while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167636,24 @@
166799167636
p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
166800167637
}
166801167638
166802167639
/* Close any open statement handles. */
166803167640
rbuObjIterFinalize(&p->objiter);
167641
+
167642
+ /* If this is an RBU vacuum handle and the vacuum has either finished
167643
+ ** successfully or encountered an error, delete the contents of the
167644
+ ** state table. This causes the next call to sqlite3rbu_vacuum()
167645
+ ** specifying the current target and state databases to start a new
167646
+ ** vacuum from scratch. */
167647
+ if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){
167648
+ int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
167649
+ if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2;
167650
+ }
166804167651
166805167652
/* Close the open database handle and VFS object. */
166806
- sqlite3_close(p->dbMain);
166807167653
sqlite3_close(p->dbRbu);
167654
+ sqlite3_close(p->dbMain);
166808167655
rbuDeleteVfs(p);
166809167656
sqlite3_free(p->aBuf);
166810167657
sqlite3_free(p->aFrame);
166811167658
166812167659
rbuEditErrmsg(p);
@@ -167003,10 +167850,26 @@
167003167850
return ((u32)aBuf[0] << 24)
167004167851
+ ((u32)aBuf[1] << 16)
167005167852
+ ((u32)aBuf[2] << 8)
167006167853
+ ((u32)aBuf[3]);
167007167854
}
167855
+
167856
+/*
167857
+** Write an unsigned 32-bit value in big-endian format to the supplied
167858
+** buffer.
167859
+*/
167860
+static void rbuPutU32(u8 *aBuf, u32 iVal){
167861
+ aBuf[0] = (iVal >> 24) & 0xFF;
167862
+ aBuf[1] = (iVal >> 16) & 0xFF;
167863
+ aBuf[2] = (iVal >> 8) & 0xFF;
167864
+ aBuf[3] = (iVal >> 0) & 0xFF;
167865
+}
167866
+
167867
+static void rbuPutU16(u8 *aBuf, u16 iVal){
167868
+ aBuf[0] = (iVal >> 8) & 0xFF;
167869
+ aBuf[1] = (iVal >> 0) & 0xFF;
167870
+}
167008167871
167009167872
/*
167010167873
** Read data from an rbuVfs-file.
167011167874
*/
167012167875
static int rbuVfsRead(
@@ -167029,10 +167892,39 @@
167029167892
){
167030167893
rc = SQLITE_OK;
167031167894
memset(zBuf, 0, iAmt);
167032167895
}else{
167033167896
rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
167897
+#if 1
167898
+ /* If this is being called to read the first page of the target
167899
+ ** database as part of an rbu vacuum operation, synthesize the
167900
+ ** contents of the first page if it does not yet exist. Otherwise,
167901
+ ** SQLite will not check for a *-wal file. */
167902
+ if( pRbu && rbuIsVacuum(pRbu)
167903
+ && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
167904
+ && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167905
+ && pRbu->rc==SQLITE_OK
167906
+ ){
167907
+ sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd;
167908
+ rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst);
167909
+ if( rc==SQLITE_OK ){
167910
+ u8 *aBuf = (u8*)zBuf;
167911
+ u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
167912
+ rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
167913
+ rbuPutU32(&aBuf[36], 0); /* number of free pages */
167914
+ rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
167915
+ rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
167916
+ rbuPutU32(&aBuf[24], pRbu->pRbuFd->iCookie+1); /* Change counter */
167917
+
167918
+ if( iAmt>100 ){
167919
+ memset(&aBuf[100], 0, iAmt-100);
167920
+ rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
167921
+ aBuf[100] = 0x0D;
167922
+ }
167923
+ }
167924
+ }
167925
+#endif
167034167926
}
167035167927
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167036167928
/* These look like magic numbers. But they are stable, as they are part
167037167929
** of the definition of the SQLite file format, which may not change. */
167038167930
u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167995,24 @@
167103167995
/*
167104167996
** Return the current file-size of an rbuVfs-file.
167105167997
*/
167106167998
static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167107167999
rbu_file *p = (rbu_file *)pFile;
167108
- return p->pReal->pMethods->xFileSize(p->pReal, pSize);
168000
+ int rc;
168001
+ rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
168002
+
168003
+ /* If this is an RBU vacuum operation and this is the target database,
168004
+ ** pretend that it has at least one page. Otherwise, SQLite will not
168005
+ ** check for the existance of a *-wal file. rbuVfsRead() contains
168006
+ ** similar logic. */
168007
+ if( rc==SQLITE_OK && *pSize==0
168008
+ && p->pRbu && rbuIsVacuum(p->pRbu)
168009
+ && (p->openFlags & SQLITE_OPEN_MAIN_DB)
168010
+ ){
168011
+ *pSize = 1024;
168012
+ }
168013
+ return rc;
167109168014
}
167110168015
167111168016
/*
167112168017
** Lock an rbuVfs-file.
167113168018
*/
@@ -167115,11 +168020,13 @@
167115168020
rbu_file *p = (rbu_file*)pFile;
167116168021
sqlite3rbu *pRbu = p->pRbu;
167117168022
int rc = SQLITE_OK;
167118168023
167119168024
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
167120
- if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
168025
+ if( eLock==SQLITE_LOCK_EXCLUSIVE
168026
+ && (p->bNolock || (pRbu && pRbu->eStage!=RBU_STAGE_DONE))
168027
+ ){
167121168028
/* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
167122168029
** prevents it from checkpointing the database from sqlite3_close(). */
167123168030
rc = SQLITE_BUSY;
167124168031
}else{
167125168032
rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +168084,16 @@
167177168084
if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
167178168085
rc = SQLITE_OK;
167179168086
}
167180168087
}
167181168088
return rc;
168089
+ }
168090
+ else if( op==SQLITE_FCNTL_RBUCNT ){
168091
+ sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
168092
+ pRbu->nRbu++;
168093
+ pRbu->pRbuFd = p;
168094
+ p->bNolock = 1;
167182168095
}
167183168096
167184168097
rc = xControl(p->pReal, op, pArg);
167185168098
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
167186168099
rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168253,37 @@
167340168253
sqlite3_mutex_enter(pRbuVfs->mutex);
167341168254
for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
167342168255
sqlite3_mutex_leave(pRbuVfs->mutex);
167343168256
return pDb;
167344168257
}
168258
+
168259
+/*
168260
+** A main database named zName has just been opened. The following
168261
+** function returns a pointer to a buffer owned by SQLite that contains
168262
+** the name of the *-wal file this db connection will use. SQLite
168263
+** happens to pass a pointer to this buffer when using xAccess()
168264
+** or xOpen() to operate on the *-wal file.
168265
+*/
168266
+static const char *rbuMainToWal(const char *zName, int flags){
168267
+ int n = (int)strlen(zName);
168268
+ const char *z = &zName[n];
168269
+ if( flags & SQLITE_OPEN_URI ){
168270
+ int odd = 0;
168271
+ while( 1 ){
168272
+ if( z[0]==0 ){
168273
+ odd = 1 - odd;
168274
+ if( odd && z[1]==0 ) break;
168275
+ }
168276
+ z++;
168277
+ }
168278
+ z += 2;
168279
+ }else{
168280
+ while( *z==0 ) z++;
168281
+ }
168282
+ z += (n + 8 + 1);
168283
+ return z;
168284
+}
167345168285
167346168286
/*
167347168287
** Open an rbu file handle.
167348168288
*/
167349168289
static int rbuVfsOpen(
@@ -167376,10 +168316,11 @@
167376168316
rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
167377168317
sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
167378168318
rbu_file *pFd = (rbu_file *)pFile;
167379168319
int rc = SQLITE_OK;
167380168320
const char *zOpen = zName;
168321
+ int oflags = flags;
167381168322
167382168323
memset(pFd, 0, sizeof(rbu_file));
167383168324
pFd->pReal = (sqlite3_file*)&pFd[1];
167384168325
pFd->pRbuVfs = pRbuVfs;
167385168326
pFd->openFlags = flags;
@@ -167388,40 +168329,31 @@
167388168329
/* A main database has just been opened. The following block sets
167389168330
** (pFd->zWal) to point to a buffer owned by SQLite that contains
167390168331
** the name of the *-wal file this db connection will use. SQLite
167391168332
** happens to pass a pointer to this buffer when using xAccess()
167392168333
** or xOpen() to operate on the *-wal file. */
167393
- int n = (int)strlen(zName);
167394
- const char *z = &zName[n];
167395
- if( flags & SQLITE_OPEN_URI ){
167396
- int odd = 0;
167397
- while( 1 ){
167398
- if( z[0]==0 ){
167399
- odd = 1 - odd;
167400
- if( odd && z[1]==0 ) break;
167401
- }
167402
- z++;
167403
- }
167404
- z += 2;
167405
- }else{
167406
- while( *z==0 ) z++;
167407
- }
167408
- z += (n + 8 + 1);
167409
- pFd->zWal = z;
168334
+ pFd->zWal = rbuMainToWal(zName, flags);
167410168335
}
167411168336
else if( flags & SQLITE_OPEN_WAL ){
167412168337
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
167413168338
if( pDb ){
167414168339
if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
167415168340
/* This call is to open a *-wal file. Intead, open the *-oal. This
167416168341
** code ensures that the string passed to xOpen() is terminated by a
167417168342
** pair of '\0' bytes in case the VFS attempts to extract a URI
167418168343
** parameter from it. */
167419
- size_t nCopy = strlen(zName);
167420
- char *zCopy = sqlite3_malloc64(nCopy+2);
168344
+ const char *zBase = zName;
168345
+ size_t nCopy;
168346
+ char *zCopy;
168347
+ if( rbuIsVacuum(pDb->pRbu) ){
168348
+ zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
168349
+ zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
168350
+ }
168351
+ nCopy = strlen(zBase);
168352
+ zCopy = sqlite3_malloc64(nCopy+2);
167421168353
if( zCopy ){
167422
- memcpy(zCopy, zName, nCopy);
168354
+ memcpy(zCopy, zBase, nCopy);
167423168355
zCopy[nCopy-3] = 'o';
167424168356
zCopy[nCopy] = '\0';
167425168357
zCopy[nCopy+1] = '\0';
167426168358
zOpen = (const char*)(pFd->zDel = zCopy);
167427168359
}else{
@@ -167431,13 +168363,22 @@
167431168363
}
167432168364
pDb->pWalFd = pFd;
167433168365
}
167434168366
}
167435168367
}
168368
+
168369
+ if( oflags & SQLITE_OPEN_MAIN_DB
168370
+ && sqlite3_uri_boolean(zName, "rbu_memory", 0)
168371
+ ){
168372
+ assert( oflags & SQLITE_OPEN_MAIN_DB );
168373
+ oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
168374
+ SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
168375
+ zOpen = 0;
168376
+ }
167436168377
167437168378
if( rc==SQLITE_OK ){
167438
- rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags);
168379
+ rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
167439168380
}
167440168381
if( pFd->pReal->pMethods ){
167441168382
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
167442168383
** pointer and, if the file is a main database file, link it into the
167443168384
** mutex protected linked list of all such files. */
@@ -168678,23 +169619,22 @@
168678169619
*/
168679169620
static int sessionVarintGet(u8 *aBuf, int *piVal){
168680169621
return getVarint32(aBuf, *piVal);
168681169622
}
168682169623
169624
+/* Load an unaligned and unsigned 32-bit integer */
169625
+#define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
169626
+
168683169627
/*
168684169628
** Read a 64-bit big-endian integer value from buffer aRec[]. Return
168685169629
** the value read.
168686169630
*/
168687169631
static sqlite3_int64 sessionGetI64(u8 *aRec){
168688
- return (((sqlite3_int64)aRec[0]) << 56)
168689
- + (((sqlite3_int64)aRec[1]) << 48)
168690
- + (((sqlite3_int64)aRec[2]) << 40)
168691
- + (((sqlite3_int64)aRec[3]) << 32)
168692
- + (((sqlite3_int64)aRec[4]) << 24)
168693
- + (((sqlite3_int64)aRec[5]) << 16)
168694
- + (((sqlite3_int64)aRec[6]) << 8)
168695
- + (((sqlite3_int64)aRec[7]) << 0);
169632
+ u64 x = SESSION_UINT32(aRec);
169633
+ u32 y = SESSION_UINT32(aRec+4);
169634
+ x = (x<<32) + y;
169635
+ return (sqlite3_int64)x;
168696169636
}
168697169637
168698169638
/*
168699169639
** Write a 64-bit big-endian integer value to the buffer aBuf[].
168700169640
*/
@@ -168992,18 +169932,23 @@
168992169932
u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
168993169933
u8 *a2 = aRight; /* Cursor to iterate through aRight */
168994169934
int iCol; /* Used to iterate through table columns */
168995169935
168996169936
for(iCol=0; iCol<pTab->nCol; iCol++){
168997
- int n1 = sessionSerialLen(a1);
168998
- int n2 = sessionSerialLen(a2);
168999
-
169000
- if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169001
- return 0;
169002
- }
169003
- if( pTab->abPK[iCol] || bLeftPkOnly==0 ) a1 += n1;
169004
- if( pTab->abPK[iCol] || bRightPkOnly==0 ) a2 += n2;
169937
+ if( pTab->abPK[iCol] ){
169938
+ int n1 = sessionSerialLen(a1);
169939
+ int n2 = sessionSerialLen(a2);
169940
+
169941
+ if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169942
+ return 0;
169943
+ }
169944
+ a1 += n1;
169945
+ a2 += n2;
169946
+ }else{
169947
+ if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
169948
+ if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
169949
+ }
169005169950
}
169006169951
169007169952
return 1;
169008169953
}
169009169954
@@ -169335,13 +170280,13 @@
169335170280
int rc;
169336170281
int nByte;
169337170282
int nDbCol = 0;
169338170283
int nThis;
169339170284
int i;
169340
- u8 *pAlloc;
170285
+ u8 *pAlloc = 0;
169341170286
char **azCol = 0;
169342
- u8 *abPK;
170287
+ u8 *abPK = 0;
169343170288
169344170289
assert( pazCol && pabPK );
169345170290
169346170291
nThis = sqlite3Strlen30(zThis);
169347170292
zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170938,13 @@
169993170938
for(pTab=pList; pTab; pTab=pNext){
169994170939
int i;
169995170940
pNext = pTab->pNext;
169996170941
for(i=0; i<pTab->nChange; i++){
169997170942
SessionChange *p;
169998
- SessionChange *pNext;
169999
- for(p=pTab->apChange[i]; p; p=pNext){
170000
- pNext = p->pNext;
170943
+ SessionChange *pNextChange;
170944
+ for(p=pTab->apChange[i]; p; p=pNextChange){
170945
+ pNextChange = p->pNext;
170001170946
sqlite3_free(p);
170002170947
}
170003170948
}
170004170949
sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170005170950
sqlite3_free(pTab->apChange);
@@ -171282,11 +172227,10 @@
171282172227
if( p->bPatchset && p->op==SQLITE_UPDATE ){
171283172228
/* If this is an UPDATE that is part of a patchset, then all PK and
171284172229
** modified fields are present in the new.* record. The old.* record
171285172230
** is currently completely empty. This block shifts the PK fields from
171286172231
** new.* to old.*, to accommodate the code that reads these arrays. */
171287
- int i;
171288172232
for(i=0; i<p->nCol; i++){
171289172233
assert( p->apValue[i]==0 );
171290172234
assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
171291172235
if( p->abPK[i] ){
171292172236
p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172999,11 @@
172055172999
sqlite3_changeset_iter *pIter, /* Changeset iterator */
172056173000
int(*xConflict)(void *, int, sqlite3_changeset_iter*),
172057173001
void *pCtx, /* First argument for conflict handler */
172058173002
int *pbReplace /* OUT: Set to true if PK row is found */
172059173003
){
172060
- int res; /* Value returned by conflict handler */
173004
+ int res = 0; /* Value returned by conflict handler */
172061173005
int rc;
172062173006
int nCol;
172063173007
int op;
172064173008
const char *zDummy;
172065173009
@@ -175390,15 +176334,17 @@
175390176334
** of the current query. Specifically, a query equivalent to:
175391176335
**
175392176336
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
175393176337
**
175394176338
** with $p set to a phrase equivalent to the phrase iPhrase of the
175395
-** current query is executed. For each row visited, the callback function
175396
-** passed as the fourth argument is invoked. The context and API objects
175397
-** passed to the callback function may be used to access the properties of
175398
-** each matched row. Invoking Api.xUserData() returns a copy of the pointer
175399
-** passed as the third argument to pUserData.
176339
+** current query is executed. Any column filter that applies to
176340
+** phrase iPhrase of the current query is included in $p. For each
176341
+** row visited, the callback function passed as the fourth argument
176342
+** is invoked. The context and API objects passed to the callback
176343
+** function may be used to access the properties of each matched row.
176344
+** Invoking Api.xUserData() returns a copy of the pointer passed as
176345
+** the third argument to pUserData.
175400176346
**
175401176347
** If the callback function returns any value other than SQLITE_OK, the
175402176348
** query is abandoned and the xQueryPhrase function returns immediately.
175403176349
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
175404176350
** Otherwise, the error code is propagated upwards.
@@ -181429,10 +182375,21 @@
181429182375
}
181430182376
if( rc==SQLITE_OK ){
181431182377
pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc,
181432182378
sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
181433182379
}
182380
+ if( rc==SQLITE_OK ){
182381
+ Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
182382
+ if( pColsetOrig ){
182383
+ int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
182384
+ Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
182385
+ if( pColset ){
182386
+ memcpy(pColset, pColsetOrig, nByte);
182387
+ }
182388
+ pNew->pRoot->pNear->pColset = pColset;
182389
+ }
182390
+ }
181434182391
181435182392
for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
181436182393
int tflags = 0;
181437182394
Fts5ExprTerm *p;
181438182395
for(p=&pOrig->aTerm[i]; p && rc==SQLITE_OK; p=p->pSynonym){
@@ -182777,15 +183734,15 @@
182777183734
assert( iCol>=p->iCol );
182778183735
if( iCol!=p->iCol ){
182779183736
if( pHash->eDetail==FTS5_DETAIL_FULL ){
182780183737
pPtr[p->nData++] = 0x01;
182781183738
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
182782
- p->iCol = iCol;
183739
+ p->iCol = (i16)iCol;
182783183740
p->iPos = 0;
182784183741
}else{
182785183742
bNew = 1;
182786
- p->iCol = iPos = iCol;
183743
+ p->iCol = (i16)(iPos = iCol);
182787183744
}
182788183745
}
182789183746
182790183747
/* Append the new position offset, if necessary */
182791183748
if( bNew ){
@@ -186204,11 +187161,11 @@
186204187161
while( *aiCol<iPrev ){
186205187162
aiCol++;
186206187163
if( aiCol==aiColEnd ) goto setoutputs_col_out;
186207187164
}
186208187165
if( *aiCol==iPrev ){
186209
- *aOut++ = (iPrev - iPrevOut) + 2;
187166
+ *aOut++ = (u8)((iPrev - iPrevOut) + 2);
186210187167
iPrevOut = iPrev;
186211187168
}
186212187169
}
186213187170
186214187171
setoutputs_col_out:
@@ -192037,11 +192994,11 @@
192037192994
int nArg, /* Number of args */
192038192995
sqlite3_value **apUnused /* Function arguments */
192039192996
){
192040192997
assert( nArg==0 );
192041192998
UNUSED_PARAM2(nArg, apUnused);
192042
- sqlite3_result_text(pCtx, "fts5: 2016-03-30 16:23:06 7cf0cab730e2d570c82dd789279ad6501ac598c8", -1, SQLITE_TRANSIENT);
192999
+ sqlite3_result_text(pCtx, "fts5: 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2", -1, SQLITE_TRANSIENT);
192043193000
}
192044193001
192045193002
static int fts5Init(sqlite3 *db){
192046193003
static const sqlite3_module fts5Mod = {
192047193004
/* iVersion */ 2,
192048193005
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
38 **
39 */
40 #ifndef _SQLITEINT_H_
41 #define _SQLITEINT_H_
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43 /*
44 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
45 ** or higher.
46 */
47 #if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
336 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337 ** [sqlite_version()] and [sqlite_source_id()].
338 */
339 #define SQLITE_VERSION "3.13.0"
340 #define SQLITE_VERSION_NUMBER 3013000
341 #define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
342
343 /*
344 ** CAPI3REF: Run-Time Library Version Numbers
345 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
346 **
@@ -2155,16 +2182,34 @@
2155 ** The second parameter is a pointer to an integer into which
2156 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2157 ** following this call. The second parameter may be a NULL pointer, in
2158 ** which case the new setting is not reported back. </dd>
2159 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2160 ** </dl>
2161 */
2162 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2163 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2164 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2165 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
 
2166
2167
2168 /*
2169 ** CAPI3REF: Enable Or Disable Extended Result Codes
2170 ** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
5697 ** fill *pzErrMsg with error message text stored in memory
5698 ** obtained from [sqlite3_malloc()]. The calling function
5699 ** should free this memory by calling [sqlite3_free()].
5700 **
5701 ** ^Extension loading must be enabled using
5702 ** [sqlite3_enable_load_extension()] prior to calling this API,
 
 
5703 ** otherwise an error will be returned.
 
 
 
 
 
 
 
5704 **
5705 ** See also the [load_extension() SQL function].
5706 */
5707 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5708 sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
5722 **
5723 ** ^Extension loading is off by default.
5724 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5725 ** to turn extension loading on and call it with onoff==0 to turn
5726 ** it back off again.
 
 
 
 
 
 
 
 
 
 
 
5727 */
5728 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5729
5730 /*
5731 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
8304
8305 /*
8306 ** CAPI3REF: Start a read transaction on an historical snapshot
8307 ** EXPERIMENTAL
8308 **
8309 ** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8310 ** read transaction that is currently open on schema S of
8311 ** [database connection] D so that it refers to historical [snapshot] P.
 
 
8312 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8313 ** or an appropriate [error code] if it fails.
8314 **
8315 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8316 ** the first operation, apart from other sqlite3_snapshot_open() calls,
8317 ** following the [BEGIN] that starts a new read transaction.
8318 ** ^A [snapshot] will fail to open if it has been overwritten by a
 
 
 
8319 ** [checkpoint].
8320 ** ^A [snapshot] will fail to open if the database connection D has not
8321 ** previously completed at least one read operation against the database
8322 ** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
 
 
 
 
8323 ** database connection in order to make it ready to use snapshots.)
8324 **
8325 ** The [sqlite3_snapshot_open()] interface is only available when the
8326 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8327 */
@@ -8341,10 +8415,37 @@
8341 **
8342 ** The [sqlite3_snapshot_free()] interface is only available when the
8343 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8344 */
8345 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8346
8347 /*
8348 ** Undo the hack that converts floating point types to integer for
8349 ** builds on processors without floating point support.
8350 */
@@ -8476,11 +8577,11 @@
8476 #endif /* ifndef _SQLITE3RTREE_H_ */
8477
8478 /******** End of sqlite3rtree.h *********/
8479 /******** Begin file sqlite3session.h *********/
8480
8481 #ifndef __SQLITESESSION_H_
8482 #define __SQLITESESSION_H_ 1
8483
8484 /*
8485 ** Make sure we can call this stuff from C++.
8486 */
@@ -9750,11 +9851,11 @@
9750 */
9751 #if 0
9752 }
9753 #endif
9754
9755 #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
9756
9757 /******** End of sqlite3session.h *********/
9758 /******** Begin file fts5.h *********/
9759 /*
9760 ** 2014 May 31
@@ -9898,15 +9999,17 @@
9898 ** of the current query. Specifically, a query equivalent to:
9899 **
9900 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
9901 **
9902 ** with $p set to a phrase equivalent to the phrase iPhrase of the
9903 ** current query is executed. For each row visited, the callback function
9904 ** passed as the fourth argument is invoked. The context and API objects
9905 ** passed to the callback function may be used to access the properties of
9906 ** each matched row. Invoking Api.xUserData() returns a copy of the pointer
9907 ** passed as the third argument to pUserData.
 
 
9908 **
9909 ** If the callback function returns any value other than SQLITE_OK, the
9910 ** query is abandoned and the xQueryPhrase function returns immediately.
9911 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
9912 ** Otherwise, the error code is propagated upwards.
@@ -10814,11 +10917,11 @@
10814 **
10815 ** When doing coverage testing ALWAYS and NEVER are hard-coded to
10816 ** be true and false so that the unreachable code they specify will
10817 ** not be counted as untested code.
10818 */
10819 #if defined(SQLITE_COVERAGE_TEST)
10820 # define ALWAYS(X) (1)
10821 # define NEVER(X) (0)
10822 #elif !defined(NDEBUG)
10823 # define ALWAYS(X) ((X)?1:(assert(0),0))
10824 # define NEVER(X) ((X)?(assert(0),1):0)
@@ -11019,80 +11122,80 @@
11019 #define TK_LP 22
11020 #define TK_RP 23
11021 #define TK_AS 24
11022 #define TK_WITHOUT 25
11023 #define TK_COMMA 26
11024 #define TK_ID 27
11025 #define TK_INDEXED 28
11026 #define TK_ABORT 29
11027 #define TK_ACTION 30
11028 #define TK_AFTER 31
11029 #define TK_ANALYZE 32
11030 #define TK_ASC 33
11031 #define TK_ATTACH 34
11032 #define TK_BEFORE 35
11033 #define TK_BY 36
11034 #define TK_CASCADE 37
11035 #define TK_CAST 38
11036 #define TK_COLUMNKW 39
11037 #define TK_CONFLICT 40
11038 #define TK_DATABASE 41
11039 #define TK_DESC 42
11040 #define TK_DETACH 43
11041 #define TK_EACH 44
11042 #define TK_FAIL 45
11043 #define TK_FOR 46
11044 #define TK_IGNORE 47
11045 #define TK_INITIALLY 48
11046 #define TK_INSTEAD 49
11047 #define TK_LIKE_KW 50
11048 #define TK_MATCH 51
11049 #define TK_NO 52
11050 #define TK_KEY 53
11051 #define TK_OF 54
11052 #define TK_OFFSET 55
11053 #define TK_PRAGMA 56
11054 #define TK_RAISE 57
11055 #define TK_RECURSIVE 58
11056 #define TK_REPLACE 59
11057 #define TK_RESTRICT 60
11058 #define TK_ROW 61
11059 #define TK_TRIGGER 62
11060 #define TK_VACUUM 63
11061 #define TK_VIEW 64
11062 #define TK_VIRTUAL 65
11063 #define TK_WITH 66
11064 #define TK_REINDEX 67
11065 #define TK_RENAME 68
11066 #define TK_CTIME_KW 69
11067 #define TK_ANY 70
11068 #define TK_OR 71
11069 #define TK_AND 72
11070 #define TK_IS 73
11071 #define TK_BETWEEN 74
11072 #define TK_IN 75
11073 #define TK_ISNULL 76
11074 #define TK_NOTNULL 77
11075 #define TK_NE 78
11076 #define TK_EQ 79
11077 #define TK_GT 80
11078 #define TK_LE 81
11079 #define TK_LT 82
11080 #define TK_GE 83
11081 #define TK_ESCAPE 84
11082 #define TK_BITAND 85
11083 #define TK_BITOR 86
11084 #define TK_LSHIFT 87
11085 #define TK_RSHIFT 88
11086 #define TK_PLUS 89
11087 #define TK_MINUS 90
11088 #define TK_STAR 91
11089 #define TK_SLASH 92
11090 #define TK_REM 93
11091 #define TK_CONCAT 94
11092 #define TK_COLLATE 95
11093 #define TK_BITNOT 96
11094 #define TK_STRING 97
11095 #define TK_JOIN_KW 98
11096 #define TK_CONSTRAINT 99
11097 #define TK_DEFAULT 100
11098 #define TK_NULL 101
@@ -12103,11 +12206,11 @@
12103 ** as an instance of the following structure:
12104 */
12105 struct VdbeOp {
12106 u8 opcode; /* What operation to perform */
12107 signed char p4type; /* One of the P4_xxx constants for p4 */
12108 u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
12109 u8 p5; /* Fifth parameter is an unsigned character */
12110 int p1; /* First operand */
12111 int p2; /* Second parameter (often the jump destination) */
12112 int p3; /* The third parameter */
12113 union p4union { /* fourth parameter */
@@ -12246,157 +12349,156 @@
12246 #define OP_Vacuum 10
12247 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
12248 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
12249 #define OP_Goto 13
12250 #define OP_Gosub 14
12251 #define OP_Return 15
12252 #define OP_InitCoroutine 16
12253 #define OP_EndCoroutine 17
12254 #define OP_Yield 18
12255 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12256 #define OP_HaltIfNull 20 /* synopsis: if r[P3]=null halt */
12257 #define OP_Halt 21
12258 #define OP_Integer 22 /* synopsis: r[P2]=P1 */
12259 #define OP_Int64 23 /* synopsis: r[P2]=P4 */
12260 #define OP_String 24 /* synopsis: r[P2]='P4' (len=P1) */
12261 #define OP_Null 25 /* synopsis: r[P2..P3]=NULL */
12262 #define OP_SoftNull 26 /* synopsis: r[P1]=NULL */
12263 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
12264 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
12265 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
12266 #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12267 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
12268 #define OP_IntCopy 32 /* synopsis: r[P2]=r[P1] */
12269 #define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */
12270 #define OP_CollSeq 34
12271 #define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */
12272 #define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */
12273 #define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
12274 #define OP_MustBeInt 38
12275 #define OP_RealAffinity 39
12276 #define OP_Cast 40 /* synopsis: affinity(r[P1]) */
12277 #define OP_Permutation 41
12278 #define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12279 #define OP_Jump 43
12280 #define OP_Once 44
12281 #define OP_If 45
12282 #define OP_IfNot 46
12283 #define OP_Column 47 /* synopsis: r[P3]=PX */
12284 #define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */
12285 #define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12286 #define OP_Count 50 /* synopsis: r[P2]=count() */
12287 #define OP_ReadCookie 51
12288 #define OP_SetCookie 52
12289 #define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */
12290 #define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */
12291 #define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */
12292 #define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */
12293 #define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */
12294 #define OP_SorterOpen 58
12295 #define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12296 #define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */
12297 #define OP_Close 61
12298 #define OP_ColumnsUsed 62
12299 #define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */
12300 #define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */
12301 #define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */
12302 #define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */
12303 #define OP_NoConflict 67 /* synopsis: key=r[P3@P4] */
12304 #define OP_NotFound 68 /* synopsis: key=r[P3@P4] */
12305 #define OP_Found 69 /* synopsis: key=r[P3@P4] */
12306 #define OP_NotExists 70 /* synopsis: intkey=r[P3] */
12307 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12308 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12309 #define OP_Sequence 73 /* synopsis: r[P2]=cursor[P1].ctr++ */
12310 #define OP_NewRowid 74 /* synopsis: r[P2]=rowid */
12311 #define OP_Insert 75 /* synopsis: intkey=r[P3] data=r[P2] */
12312 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12313 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12314 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12315 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12316 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12317 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12318 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12319 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12320 #define OP_InsertInt 84 /* synopsis: intkey=P3 data=r[P2] */
12321 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12322 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12323 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12324 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12325 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12326 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12327 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12328 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12329 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12330 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12331 #define OP_Delete 95
12332 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12333 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12334 #define OP_ResetCount 98
12335 #define OP_SorterCompare 99 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12336 #define OP_SorterData 100 /* synopsis: r[P2]=data */
12337 #define OP_RowKey 101 /* synopsis: r[P2]=key */
12338 #define OP_RowData 102 /* synopsis: r[P2]=data */
12339 #define OP_Rowid 103 /* synopsis: r[P2]=rowid */
12340 #define OP_NullRow 104
12341 #define OP_Last 105
12342 #define OP_SorterSort 106
12343 #define OP_Sort 107
12344 #define OP_Rewind 108
12345 #define OP_SorterInsert 109
12346 #define OP_IdxInsert 110 /* synopsis: key=r[P2] */
12347 #define OP_IdxDelete 111 /* synopsis: key=r[P2@P3] */
12348 #define OP_Seek 112 /* synopsis: Move P3 to P1.rowid */
12349 #define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */
12350 #define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */
12351 #define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */
12352 #define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */
12353 #define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */
12354 #define OP_Destroy 118
12355 #define OP_Clear 119
12356 #define OP_ResetSorter 120
12357 #define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */
12358 #define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */
12359 #define OP_ParseSchema 123
12360 #define OP_LoadAnalysis 124
12361 #define OP_DropTable 125
12362 #define OP_DropIndex 126
12363 #define OP_DropTrigger 127
12364 #define OP_IntegrityCk 128
12365 #define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */
12366 #define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */
12367 #define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12368 #define OP_Program 132
12369 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12370 #define OP_Param 134
12371 #define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
12372 #define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
12373 #define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12374 #define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12375 #define OP_OffsetLimit 139 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12376 #define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12377 #define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
12378 #define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
12379 #define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12380 #define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12381 #define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
12382 #define OP_IncrVacuum 146
12383 #define OP_Expire 147
12384 #define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */
12385 #define OP_VBegin 149
12386 #define OP_VCreate 150
12387 #define OP_VDestroy 151
12388 #define OP_VOpen 152
12389 #define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */
12390 #define OP_VNext 154
12391 #define OP_VRename 155
12392 #define OP_Pagecount 156
12393 #define OP_MaxPgcnt 157
12394 #define OP_Init 158 /* synopsis: Start at P2 */
12395 #define OP_CursorHint 159
12396 #define OP_Noop 160
12397 #define OP_Explain 161
12398
12399 /* Properties such as "out2" or "jump" that are specified in
12400 ** comments following the "case" for each opcode in the vdbe.c
12401 ** are encoded into bitvectors as follows:
12402 */
@@ -12406,30 +12508,38 @@
12406 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
12407 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12408 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12409 #define OPFLG_INITIALIZER {\
12410 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12411 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02,\
12412 /* 16 */ 0x01, 0x02, 0x03, 0x12, 0x08, 0x00, 0x10, 0x10,\
12413 /* 24 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
12414 /* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\
12415 /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
12416 /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12417 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\
12418 /* 64 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26,\
12419 /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
12420 /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
12421 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
12422 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12423 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
12424 /* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
12425 /* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12426 /* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
12427 /* 136 */ 0x01, 0x04, 0x03, 0x1a, 0x03, 0x03, 0x03, 0x00,\
12428 /* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
12429 /* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
12430 /* 160 */ 0x00, 0x00,}
 
 
 
 
 
 
 
 
12431
12432 /************** End of opcodes.h *********************************************/
12433 /************** Continuing where we left off in vdbe.h ***********************/
12434
12435 /*
@@ -12648,11 +12758,15 @@
12648 #define PAGER_LOCKINGMODE_QUERY -1
12649 #define PAGER_LOCKINGMODE_NORMAL 0
12650 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
12651
12652 /*
12653 ** Numeric constants that encode the journalmode.
 
 
 
 
12654 */
12655 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
12656 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
12657 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
12658 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12780,15 @@
12666 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
12667 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
12668
12669 /*
12670 ** Flags for sqlite3PagerSetFlags()
 
 
 
 
 
12671 */
12672 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
12673 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
12674 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
12675 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12835,11 +12954,11 @@
12835 */
12836 struct PgHdr {
12837 sqlite3_pcache_page *pPage; /* Pcache object page handle */
12838 void *pData; /* Page data */
12839 void *pExtra; /* Extra content */
12840 PgHdr *pDirty; /* Transient list of dirty pages */
12841 Pager *pPager; /* The pager this page is part of */
12842 Pgno pgno; /* Page number for this page */
12843 #ifdef SQLITE_CHECK_PAGES
12844 u32 pageHash; /* Hash of page content */
12845 #endif
@@ -12860,15 +12979,14 @@
12860 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
12861 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
12862 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
12863 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
12864 ** writing this page to the database */
12865 #define PGHDR_NEED_READ 0x010 /* Content is unread */
12866 #define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */
12867 #define PGHDR_MMAP 0x040 /* This is an mmap page object */
12868
12869 #define PGHDR_WAL_APPEND 0x080 /* Appended to wal file */
12870
12871 /* Initialize and shutdown the page cache subsystem */
12872 SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
12873 SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
12874
@@ -12908,10 +13026,11 @@
12908
12909 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
12910 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
12911 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
12912 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
 
12913
12914 /* Change a page number. Used by incr-vacuum. */
12915 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
12916
12917 /* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12945,10 +13064,15 @@
12945 ** interface is only available if SQLITE_CHECK_PAGES is defined when the
12946 ** library is built.
12947 */
12948 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
12949 #endif
 
 
 
 
 
12950
12951 /* Set and get the suggested cache-size for the specified pager-cache.
12952 **
12953 ** If no global maximum is configured, then the system attempts to limit
12954 ** the total number of pages cached by purgeable pager-caches to the sum
@@ -12981,10 +13105,13 @@
12981 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
12982
12983 /* Return the header size */
12984 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
12985 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
 
 
 
12986
12987 #endif /* _PCACHE_H_ */
12988
12989 /************** End of pcache.h **********************************************/
12990 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13338,11 @@
13211 SQLITE_PRIVATE int sqlite3OsInit(void);
13212
13213 /*
13214 ** Functions for accessing sqlite3_file methods
13215 */
13216 SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
13217 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
13218 SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
13219 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
13220 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
13221 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13383,11 @@
13256 /*
13257 ** Convenience functions for opening and closing files using
13258 ** sqlite3_malloc() to obtain space for the file-handle structure.
13259 */
13260 SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13261 SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
13262
13263 #endif /* _SQLITE_OS_H_ */
13264
13265 /************** End of os.h **************************************************/
13266 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13792,15 @@
13665 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
13666 #define ENC(db) ((db)->enc)
13667
13668 /*
13669 ** Possible values for the sqlite3.flags.
 
 
 
 
 
13670 */
13671 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
13672 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
13673 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
13674 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13824,18 @@
13692 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
13693 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
13694 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
13695 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
13696 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13697 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
13698 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
13699 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
13700 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
13701 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
13702 #define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */
13703 #define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */
 
13704
13705
13706 /*
13707 ** Bits of the sqlite3.dbOptFlags field that are used by the
13708 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13932,17 @@
13799 /*
13800 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
13801 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
13802 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
13803 ** are assert() statements in the code to verify this.
 
 
 
 
 
 
 
13804 */
13805 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
13806 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
13807 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
13808 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14938,13 @@
14798
14799
14800 /*
14801 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
14802 ** and the WhereInfo.wctrlFlags member.
 
 
 
14803 */
14804 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
14805 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
14806 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
14807 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14815,10 +14958,11 @@
14815 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
14816 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
14817 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
14818 #define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
14819 #define WHERE_USE_LIMIT 0x4000 /* There is a constant LIMIT clause */
 
14820
14821 /* Allowed return values from sqlite3WhereIsDistinct()
14822 */
14823 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
14824 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -14858,20 +15002,22 @@
14858 };
14859
14860 /*
14861 ** Allowed values for the NameContext, ncFlags field.
14862 **
14863 ** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
14864 ** SQLITE_FUNC_MINMAX.
 
14865 **
14866 */
14867 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
14868 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
14869 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
14870 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
14871 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
14872 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
 
14873 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
14874
14875 /*
14876 ** An instance of the following structure contains all information
14877 ** needed to generate code for a single SELECT statement.
@@ -14915,28 +15061,34 @@
14915 };
14916
14917 /*
14918 ** Allowed values for Select.selFlags. The "SF" prefix stands for
14919 ** "Select Flag".
 
 
 
 
 
14920 */
14921 #define SF_Distinct 0x00001 /* Output should be DISTINCT */
14922 #define SF_All 0x00002 /* Includes the ALL keyword */
14923 #define SF_Resolved 0x00004 /* Identifiers have been resolved */
14924 #define SF_Aggregate 0x00008 /* Contains aggregate functions */
14925 #define SF_UsesEphemeral 0x00010 /* Uses the OpenEphemeral opcode */
14926 #define SF_Expanded 0x00020 /* sqlite3SelectExpand() called on this */
14927 #define SF_HasTypeInfo 0x00040 /* FROM subqueries have Table metadata */
14928 #define SF_Compound 0x00080 /* Part of a compound query */
14929 #define SF_Values 0x00100 /* Synthesized from VALUES clause */
14930 #define SF_MultiValue 0x00200 /* Single VALUES term with multiple rows */
14931 #define SF_NestedFrom 0x00400 /* Part of a parenthesized FROM clause */
14932 #define SF_MaybeConvert 0x00800 /* Need convertCompoundSelectToSubquery() */
14933 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
14934 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
14935 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
14936 #define SF_Converted 0x08000 /* By convertCompoundSelectToSubquery() */
14937 #define SF_IncludeHidden 0x10000 /* Include hidden columns in output */
 
14938
14939
14940 /*
14941 ** The results of a SELECT can be distributed in several ways, as defined
14942 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15281,11 @@
15129 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
15130 u8 mayAbort; /* True if statement may throw an ABORT exception */
15131 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
15132 u8 okConstFactor; /* OK to factor out constants */
15133 u8 disableLookaside; /* Number of times lookaside has been disabled */
 
15134 int aTempReg[8]; /* Holding area for temporary registers */
15135 int nRangeReg; /* Size of the temporary register block */
15136 int iRangeReg; /* First register in temporary register block */
15137 int nErr; /* Number of errors seen */
15138 int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15395,19 @@
15242 Parse *pParse; /* The Parse structure */
15243 };
15244
15245 /*
15246 ** Bitfield flags for P5 value in various opcodes.
 
 
 
 
 
 
 
 
 
15247 */
15248 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15249 /* Also used in P2 (not P5) of OP_Delete */
15250 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15251 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15778,20 @@
15616 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
15617 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
15618 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
15619 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
15620 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
 
15621 #else
15622 # define sqlite3Toupper(x) toupper((unsigned char)(x))
15623 # define sqlite3Isspace(x) isspace((unsigned char)(x))
15624 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
15625 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
15626 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
15627 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
15628 # define sqlite3Tolower(x) tolower((unsigned char)(x))
 
15629 #endif
15630 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
15631 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
15632 #endif
15633
@@ -15747,11 +15911,11 @@
15747 #endif
15748
15749
15750 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
15751 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15752 SQLITE_PRIVATE int sqlite3Dequote(char*);
15753 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
15754 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
15755 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
15756 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
15757 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15928,11 @@
15764 #endif
15765 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
15766 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
15767 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
15768 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
 
15769 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
15770 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
15771 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
15772 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
15773 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16724,11 @@
16559 ** isdigit() 0x04
16560 ** isalnum() 0x06
16561 ** isxdigit() 0x08
16562 ** toupper() 0x20
16563 ** SQLite identifier character 0x40
 
16564 **
16565 ** Bit 0x20 is set if the mapped character requires translation to upper
16566 ** case. i.e. if the character is a lower-case ASCII character.
16567 ** If x is a lower-case ASCII character, then its upper-case equivalent
16568 ** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16750,20 @@
16584 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
16585 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
16586 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
16587 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
16588 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16589 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */
16590 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
16591 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
16592 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
16593
16594 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
16595 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
16596 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16597 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16598 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16599 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
16600 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
16601 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
16602
16603 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18347,19 @@
18181 /* #include <assert.h> */
18182 #include <time.h>
18183
18184 #ifndef SQLITE_OMIT_DATETIME_FUNCS
18185
 
 
 
 
 
 
 
 
 
18186
18187 /*
18188 ** A structure for holding a single date and time.
18189 */
18190 typedef struct DateTime DateTime;
@@ -18549,10 +18724,11 @@
18549 p->validYMD = 0;
18550 p->validHMS = 0;
18551 p->validTZ = 0;
18552 }
18553
 
18554 /*
18555 ** On recent Windows platforms, the localtime_s() function is available
18556 ** as part of the "Secure CRT". It is essentially equivalent to
18557 ** localtime_r() available under most POSIX platforms, except that the
18558 ** order of the parameters is reversed.
@@ -18567,11 +18743,10 @@
18567 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
18568 #undef HAVE_LOCALTIME_S
18569 #define HAVE_LOCALTIME_S 1
18570 #endif
18571
18572 #ifndef SQLITE_OMIT_LOCALTIME
18573 /*
18574 ** The following routine implements the rough equivalent of localtime_r()
18575 ** using whatever operating-system specific localtime facility that
18576 ** is available. This routine returns 0 on success and
18577 ** non-zero on any kind of error.
@@ -19371,17 +19546,15 @@
19371 ** The following routines are convenience wrappers around methods
19372 ** of the sqlite3_file object. This is mostly just syntactic sugar. All
19373 ** of this would be completely automatic if SQLite were coded using
19374 ** C++ instead of plain old C.
19375 */
19376 SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file *pId){
19377 int rc = SQLITE_OK;
19378 if( pId->pMethods ){
19379 rc = pId->pMethods->xClose(pId);
19380 pId->pMethods = 0;
19381 }
19382 return rc;
19383 }
19384 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
19385 DO_OS_MALLOC_TEST(id);
19386 return id->pMethods->xRead(id, pBuf, amt, offset);
19387 }
@@ -19595,16 +19768,14 @@
19595 }else{
19596 rc = SQLITE_NOMEM_BKPT;
19597 }
19598 return rc;
19599 }
19600 SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){
19601 int rc = SQLITE_OK;
19602 assert( pFile );
19603 rc = sqlite3OsClose(pFile);
19604 sqlite3_free(pFile);
19605 return rc;
19606 }
19607
19608 /*
19609 ** This function is a wrapper around the OS specific implementation of
19610 ** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -24280,30 +24451,30 @@
24280
24281 /*
24282 ** Conversion types fall into various categories as defined by the
24283 ** following enumeration.
24284 */
24285 #define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */
24286 #define etFLOAT 2 /* Floating point. %f */
24287 #define etEXP 3 /* Exponentional notation. %e and %E */
24288 #define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */
24289 #define etSIZE 5 /* Return number of characters processed so far. %n */
24290 #define etSTRING 6 /* Strings. %s */
24291 #define etDYNSTRING 7 /* Dynamically allocated strings. %z */
24292 #define etPERCENT 8 /* Percent symbol. %% */
24293 #define etCHARX 9 /* Characters. %c */
24294 /* The rest are extensions, not normally found in printf() */
24295 #define etSQLESCAPE 10 /* Strings with '\'' doubled. %q */
24296 #define etSQLESCAPE2 11 /* Strings with '\'' doubled and enclosed in '',
24297 NULL pointers replaced by SQL NULL. %Q */
24298 #define etTOKEN 12 /* a pointer to a Token structure */
24299 #define etSRCLIST 13 /* a pointer to a SrcList */
24300 #define etPOINTER 14 /* The %p conversion */
24301 #define etSQLESCAPE3 15 /* %w -> Strings with '\"' doubled */
24302 #define etORDINAL 16 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
24303
24304 #define etINVALID 0 /* Any unrecognized conversion type */
24305
24306
24307 /*
24308 ** An "etByte" is an 8-bit unsigned value.
24309 */
@@ -24454,11 +24625,11 @@
24454 etByte flag_altform2; /* True if "!" flag is present */
24455 etByte flag_zeropad; /* True if field width constant starts with zero */
24456 etByte flag_long; /* True if "l" flag is present */
24457 etByte flag_longlong; /* True if the "ll" flag is present */
24458 etByte done; /* Loop termination flag */
24459 etByte xtype = 0; /* Conversion paradigm */
24460 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
24461 u8 useIntern; /* Ok to use internal conversions (ex: %T) */
24462 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
24463 sqlite_uint64 longvalue; /* Value for integer types */
24464 LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -27045,22 +27216,17 @@
27045 **
27046 ** 2002-Feb-14: This routine is extended to remove MS-Access style
27047 ** brackets from around identifiers. For example: "[a-b-c]" becomes
27048 ** "a-b-c".
27049 */
27050 SQLITE_PRIVATE int sqlite3Dequote(char *z){
27051 char quote;
27052 int i, j;
27053 if( z==0 ) return -1;
27054 quote = z[0];
27055 switch( quote ){
27056 case '\'': break;
27057 case '"': break;
27058 case '`': break; /* For MySQL compatibility */
27059 case '[': quote = ']'; break; /* For MS SqlServer compatibility */
27060 default: return -1;
27061 }
27062 for(i=1, j=0;; i++){
27063 assert( z[i] );
27064 if( z[i]==quote ){
27065 if( z[i+1]==quote ){
27066 z[j++] = quote;
@@ -27071,11 +27237,10 @@
27071 }else{
27072 z[j++] = z[i];
27073 }
27074 }
27075 z[j] = 0;
27076 return j;
27077 }
27078
27079 /*
27080 ** Generate a Token object from a string
27081 */
@@ -27164,11 +27329,11 @@
27164 int esign = 1; /* sign of exponent */
27165 int e = 0; /* exponent */
27166 int eValid = 1; /* True exponent is either not used or is well-formed */
27167 double result;
27168 int nDigits = 0;
27169 int nonNum = 0;
27170
27171 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27172 *pResult = 0.0; /* Default return value, in case of an error */
27173
27174 if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27342,11 @@
27177 int i;
27178 incr = 2;
27179 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27180 for(i=3-enc; i<length && z[i]==0; i+=2){}
27181 nonNum = i<length;
27182 zEnd = z+i+enc-3;
27183 z += (enc&1);
27184 }
27185
27186 /* skip leading spaces */
27187 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27358,10 @@
27193 z+=incr;
27194 }else if( *z=='+' ){
27195 z+=incr;
27196 }
27197
27198 /* skip leading zeroes */
27199 while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
27200
27201 /* copy max significant digits to significand */
27202 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27203 s = s*10 + (*z - '0');
27204 z+=incr, nDigits++;
27205 }
@@ -27212,24 +27374,30 @@
27212 /* if decimal point is present */
27213 if( *z=='.' ){
27214 z+=incr;
27215 /* copy digits from after decimal to significand
27216 ** (decrease exponent by d to shift decimal right) */
27217 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27218 s = s*10 + (*z - '0');
27219 z+=incr, nDigits++, d--;
 
 
 
27220 }
27221 /* skip non-significant digits */
27222 while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
27223 }
27224 if( z>=zEnd ) goto do_atof_calc;
27225
27226 /* if exponent is present */
27227 if( *z=='e' || *z=='E' ){
27228 z+=incr;
27229 eValid = 0;
27230 if( z>=zEnd ) goto do_atof_calc;
 
 
 
 
 
27231 /* get sign of exponent */
27232 if( *z=='-' ){
27233 esign = -1;
27234 z+=incr;
27235 }else if( *z=='+' ){
@@ -27242,13 +27410,11 @@
27242 eValid = 1;
27243 }
27244 }
27245
27246 /* skip trailing spaces */
27247 if( nDigits && eValid ){
27248 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
27249 }
27250
27251 do_atof_calc:
27252 /* adjust exponent by d, and update sign */
27253 e = (e*esign) + d;
27254 if( e<0 ) {
@@ -27256,45 +27422,55 @@
27256 e *= -1;
27257 } else {
27258 esign = 1;
27259 }
27260
27261 /* if 0 significand */
27262 if( !s ) {
27263 /* In the IEEE 754 standard, zero is signed.
27264 ** Add the sign if we've seen at least one digit */
27265 result = (sign<0 && nDigits) ? -(double)0 : (double)0;
27266 } else {
27267 /* attempt to reduce exponent */
27268 if( esign>0 ){
27269 while( s<(LARGEST_INT64/10) && e>0 ) e--,s*=10;
27270 }else{
27271 while( !(s%10) && e>0 ) e--,s/=10;
 
 
 
 
 
 
 
 
 
 
27272 }
27273
27274 /* adjust the sign of significand */
27275 s = sign<0 ? -s : s;
27276
27277 /* if exponent, scale significand as appropriate
27278 ** and store in result. */
27279 if( e ){
27280 LONGDOUBLE_TYPE scale = 1.0;
27281 /* attempt to handle extremely small/large numbers better */
27282 if( e>307 && e<342 ){
27283 while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27284 if( esign<0 ){
27285 result = s / scale;
27286 result /= 1.0e+308;
27287 }else{
27288 result = s * scale;
27289 result *= 1.0e+308;
27290 }
27291 }else if( e>=342 ){
27292 if( esign<0 ){
27293 result = 0.0*s;
27294 }else{
27295 result = 1e308*1e308*s; /* Infinity */
 
 
27296 }
27297 }else{
27298 /* 1.0e+22 is the largest power of 10 than can be
27299 ** represented exactly. */
27300 while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27479,18 @@
27303 result = s / scale;
27304 }else{
27305 result = s * scale;
27306 }
27307 }
27308 } else {
27309 result = (double)s;
27310 }
27311 }
27312
27313 /* store the result */
27314 *pResult = result;
27315
27316 /* return true if number and no extra non-whitespace chracters after */
27317 return z>=zEnd && nDigits>0 && eValid && nonNum==0;
27318 #else
27319 return !sqlite3Atoi64(z, pResult, length, enc);
27320 #endif /* SQLITE_OMIT_FLOATING_POINT */
27321 }
27322
@@ -27374,11 +27548,11 @@
27374 int incr;
27375 u64 u = 0;
27376 int neg = 0; /* assume positive */
27377 int i;
27378 int c = 0;
27379 int nonNum = 0;
27380 const char *zStart;
27381 const char *zEnd = zNum + length;
27382 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27383 if( enc==SQLITE_UTF8 ){
27384 incr = 1;
@@ -27385,11 +27559,11 @@
27385 }else{
27386 incr = 2;
27387 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27388 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
27389 nonNum = i<length;
27390 zEnd = zNum+i+enc-3;
27391 zNum += (enc&1);
27392 }
27393 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
27394 if( zNum<zEnd ){
27395 if( *zNum=='-' ){
@@ -27412,12 +27586,15 @@
27412 *pNum = (i64)u;
27413 }
27414 testcase( i==18 );
27415 testcase( i==19 );
27416 testcase( i==20 );
27417 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum)
27418 || i>19*incr || nonNum ){
 
 
 
27419 /* zNum is empty or contains non-numeric text or is longer
27420 ** than 19 digits (thus guaranteeing that it is too large) */
27421 return 1;
27422 }else if( i<19*incr ){
27423 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27632,10 @@
27455 */
27456 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
27457 #ifndef SQLITE_OMIT_HEX_INTEGER
27458 if( z[0]=='0'
27459 && (z[1]=='x' || z[1]=='X')
27460 && sqlite3Isxdigit(z[2])
27461 ){
27462 u64 u = 0;
27463 int i, k;
27464 for(i=2; z[i]=='0'; i++){}
27465 for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28393,11 @@
28217 LogEst y = 40;
28218 if( x<8 ){
28219 if( x<2 ) return 0;
28220 while( x<8 ){ y -= 10; x <<= 1; }
28221 }else{
28222 while( x>255 ){ y += 40; x >>= 4; }
28223 while( x>15 ){ y += 10; x >>= 1; }
28224 }
28225 return a[x&7] + y - 10;
28226 }
28227
@@ -28326,11 +28502,11 @@
28326 ** The hashing function.
28327 */
28328 static unsigned int strHash(const char *z){
28329 unsigned int h = 0;
28330 unsigned char c;
28331 while( (c = (unsigned char)*z++)!=0 ){
28332 h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
28333 }
28334 return h;
28335 }
28336
@@ -28419,11 +28595,11 @@
28419 ){
28420 HashElem *elem; /* Used to loop thru the element list */
28421 int count; /* Number of elements left to test */
28422 unsigned int h; /* The computed hash */
28423
28424 if( pH->ht ){
28425 struct _ht *pEntry;
28426 h = strHash(pKey) % pH->htsize;
28427 pEntry = &pH->ht[h];
28428 elem = pEntry->chain;
28429 count = pEntry->count;
@@ -28566,157 +28742,156 @@
28566 /* 10 */ "Vacuum" OpHelp(""),
28567 /* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
28568 /* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
28569 /* 13 */ "Goto" OpHelp(""),
28570 /* 14 */ "Gosub" OpHelp(""),
28571 /* 15 */ "Return" OpHelp(""),
28572 /* 16 */ "InitCoroutine" OpHelp(""),
28573 /* 17 */ "EndCoroutine" OpHelp(""),
28574 /* 18 */ "Yield" OpHelp(""),
28575 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28576 /* 20 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28577 /* 21 */ "Halt" OpHelp(""),
28578 /* 22 */ "Integer" OpHelp("r[P2]=P1"),
28579 /* 23 */ "Int64" OpHelp("r[P2]=P4"),
28580 /* 24 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28581 /* 25 */ "Null" OpHelp("r[P2..P3]=NULL"),
28582 /* 26 */ "SoftNull" OpHelp("r[P1]=NULL"),
28583 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28584 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28585 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28586 /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28587 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28588 /* 32 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28589 /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28590 /* 34 */ "CollSeq" OpHelp(""),
28591 /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28592 /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28593 /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28594 /* 38 */ "MustBeInt" OpHelp(""),
28595 /* 39 */ "RealAffinity" OpHelp(""),
28596 /* 40 */ "Cast" OpHelp("affinity(r[P1])"),
28597 /* 41 */ "Permutation" OpHelp(""),
28598 /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28599 /* 43 */ "Jump" OpHelp(""),
28600 /* 44 */ "Once" OpHelp(""),
28601 /* 45 */ "If" OpHelp(""),
28602 /* 46 */ "IfNot" OpHelp(""),
28603 /* 47 */ "Column" OpHelp("r[P3]=PX"),
28604 /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28605 /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28606 /* 50 */ "Count" OpHelp("r[P2]=count()"),
28607 /* 51 */ "ReadCookie" OpHelp(""),
28608 /* 52 */ "SetCookie" OpHelp(""),
28609 /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28610 /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28611 /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28612 /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28613 /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28614 /* 58 */ "SorterOpen" OpHelp(""),
28615 /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28616 /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28617 /* 61 */ "Close" OpHelp(""),
28618 /* 62 */ "ColumnsUsed" OpHelp(""),
28619 /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28620 /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28621 /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28622 /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28623 /* 67 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28624 /* 68 */ "NotFound" OpHelp("key=r[P3@P4]"),
28625 /* 69 */ "Found" OpHelp("key=r[P3@P4]"),
28626 /* 70 */ "NotExists" OpHelp("intkey=r[P3]"),
28627 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28628 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28629 /* 73 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28630 /* 74 */ "NewRowid" OpHelp("r[P2]=rowid"),
28631 /* 75 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28632 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28633 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28634 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28635 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28636 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28637 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28638 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28639 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28640 /* 84 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28641 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28642 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28643 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28644 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28645 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28646 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28647 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28648 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28649 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28650 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28651 /* 95 */ "Delete" OpHelp(""),
28652 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28653 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
28654 /* 98 */ "ResetCount" OpHelp(""),
28655 /* 99 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28656 /* 100 */ "SorterData" OpHelp("r[P2]=data"),
28657 /* 101 */ "RowKey" OpHelp("r[P2]=key"),
28658 /* 102 */ "RowData" OpHelp("r[P2]=data"),
28659 /* 103 */ "Rowid" OpHelp("r[P2]=rowid"),
28660 /* 104 */ "NullRow" OpHelp(""),
28661 /* 105 */ "Last" OpHelp(""),
28662 /* 106 */ "SorterSort" OpHelp(""),
28663 /* 107 */ "Sort" OpHelp(""),
28664 /* 108 */ "Rewind" OpHelp(""),
28665 /* 109 */ "SorterInsert" OpHelp(""),
28666 /* 110 */ "IdxInsert" OpHelp("key=r[P2]"),
28667 /* 111 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28668 /* 112 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28669 /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28670 /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28671 /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28672 /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28673 /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28674 /* 118 */ "Destroy" OpHelp(""),
28675 /* 119 */ "Clear" OpHelp(""),
28676 /* 120 */ "ResetSorter" OpHelp(""),
28677 /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28678 /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28679 /* 123 */ "ParseSchema" OpHelp(""),
28680 /* 124 */ "LoadAnalysis" OpHelp(""),
28681 /* 125 */ "DropTable" OpHelp(""),
28682 /* 126 */ "DropIndex" OpHelp(""),
28683 /* 127 */ "DropTrigger" OpHelp(""),
28684 /* 128 */ "IntegrityCk" OpHelp(""),
28685 /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28686 /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28687 /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28688 /* 132 */ "Program" OpHelp(""),
28689 /* 133 */ "Real" OpHelp("r[P2]=P4"),
28690 /* 134 */ "Param" OpHelp(""),
28691 /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28692 /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28693 /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28694 /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28695 /* 139 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28696 /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28697 /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28698 /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
28699 /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28700 /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28701 /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28702 /* 146 */ "IncrVacuum" OpHelp(""),
28703 /* 147 */ "Expire" OpHelp(""),
28704 /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28705 /* 149 */ "VBegin" OpHelp(""),
28706 /* 150 */ "VCreate" OpHelp(""),
28707 /* 151 */ "VDestroy" OpHelp(""),
28708 /* 152 */ "VOpen" OpHelp(""),
28709 /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28710 /* 154 */ "VNext" OpHelp(""),
28711 /* 155 */ "VRename" OpHelp(""),
28712 /* 156 */ "Pagecount" OpHelp(""),
28713 /* 157 */ "MaxPgcnt" OpHelp(""),
28714 /* 158 */ "Init" OpHelp("Start at P2"),
28715 /* 159 */ "CursorHint" OpHelp(""),
28716 /* 160 */ "Noop" OpHelp(""),
28717 /* 161 */ "Explain" OpHelp(""),
28718 };
28719 return azName[i];
28720 }
28721 #endif
28722
@@ -29325,11 +29500,11 @@
29325 #if defined(USE_PREAD64)
29326 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
29327 #else
29328 { "pread64", (sqlite3_syscall_ptr)0, 0 },
29329 #endif
29330 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
29331
29332 { "write", (sqlite3_syscall_ptr)write, 0 },
29333 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
29334
29335 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29518,11 @@
29343 #if defined(USE_PREAD64)
29344 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
29345 #else
29346 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
29347 #endif
29348 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
29349 aSyscall[13].pCurrent)
29350
29351 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
29352 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
29353
@@ -33208,14 +33383,16 @@
33208 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
33209 #endif
33210 pShmNode->h = -1;
33211 pDbFd->pInode->pShmNode = pShmNode;
33212 pShmNode->pInode = pDbFd->pInode;
33213 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33214 if( pShmNode->mutex==0 ){
33215 rc = SQLITE_NOMEM_BKPT;
33216 goto shm_open_err;
 
 
33217 }
33218
33219 if( pInode->bProcessLock==0 ){
33220 int openFlags = O_RDWR | O_CREAT;
33221 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34507,28 @@
34330 "/var/tmp",
34331 "/usr/tmp",
34332 "/tmp",
34333 "."
34334 };
34335 unsigned int i;
34336 struct stat buf;
34337 const char *zDir = sqlite3_temp_directory;
34338
34339 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
34340 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34341 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34342 if( zDir==0 ) continue;
34343 if( osStat(zDir, &buf) ) continue;
34344 if( !S_ISDIR(buf.st_mode) ) continue;
34345 if( osAccess(zDir, 07) ) continue;
34346 break;
34347 }
34348 return zDir;
 
 
 
 
34349 }
34350
34351 /*
34352 ** Create a temporary file name in zBuf. zBuf must be allocated
34353 ** by the calling process and must be big enough to hold at least
@@ -34359,13 +34540,15 @@
34359
34360 /* It's odd to simulate an io-error here, but really this is just
34361 ** using the io-error infrastructure to test that SQLite handles this
34362 ** function failing.
34363 */
 
34364 SimulateIOError( return SQLITE_IOERR );
34365
34366 zDir = unixTempFileDir();
 
34367 do{
34368 u64 r;
34369 sqlite3_randomness(sizeof(r), &r);
34370 assert( nBuf>2 );
34371 zBuf[nBuf-2] = 0;
@@ -37963,12 +38146,12 @@
37963 */
37964 SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
37965 int rc;
37966 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
37967 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
37968 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
37969 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
37970 sqlite3_mutex_enter(pMaster);
37971 sqlite3_mutex_enter(pMem);
37972 winMemAssertMagic();
37973 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
37974 /*
@@ -38821,20 +39004,21 @@
38821 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
38822 );
38823 }
38824 }
38825
38826 #if SQLITE_OS_WINCE
38827 /*************************************************************************
38828 ** This section contains code for WinCE only.
38829 */
38830 #if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API
38831 /*
38832 ** The MSVC CRT on Windows CE may not have a localtime() function. So
38833 ** create a substitute.
38834 */
38835 /* #include <time.h> */
 
38836 struct tm *__cdecl localtime(const time_t *t)
38837 {
38838 static struct tm y;
38839 FILETIME uTm, lTm;
38840 SYSTEMTIME pTm;
@@ -38854,10 +39038,14 @@
38854 y.tm_sec = pTm.wSecond;
38855 return &y;
38856 }
38857 #endif
38858
 
 
 
 
38859 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
38860
38861 /*
38862 ** Acquire a lock on the handle h
38863 */
@@ -39867,13 +40055,12 @@
39867 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
39868 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
39869 ** the PENDING_LOCK byte is temporary.
39870 */
39871 newLocktype = pFile->locktype;
39872 if( (pFile->locktype==NO_LOCK)
39873 || ( (locktype==EXCLUSIVE_LOCK)
39874 && (pFile->locktype==RESERVED_LOCK))
39875 ){
39876 int cnt = 3;
39877 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
39878 PENDING_BYTE, 0, 1, 0))==0 ){
39879 /* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40650,16 @@
40463 pNew = 0;
40464 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
40465 pShmNode->pNext = winShmNodeList;
40466 winShmNodeList = pShmNode;
40467
40468 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40469 if( pShmNode->mutex==0 ){
40470 rc = SQLITE_IOERR_NOMEM_BKPT;
40471 goto shm_open_err;
 
 
40472 }
40473
40474 rc = winOpen(pDbFd->pVfs,
40475 pShmNode->zFilename, /* Name of the file (UTF-8) */
40476 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -42930,11 +43119,33 @@
42930 ** This file implements that page cache.
42931 */
42932 /* #include "sqliteInt.h" */
42933
42934 /*
42935 ** A complete page cache is an instance of this structure.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42936 */
42937 struct PCache {
42938 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
42939 PgHdr *pSynced; /* Last synced page in dirty page list */
42940 int nRefSum; /* Sum of ref counts over all pages */
@@ -42946,10 +43157,99 @@
42946 u8 eCreate; /* eCreate value for for xFetch() */
42947 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
42948 void *pStress; /* Argument to xStress */
42949 sqlite3_pcache *pCache; /* Pluggable cache module */
42950 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42951
42952 /********************************** Linked List Management ********************/
42953
42954 /* Allowed values for second argument to pcacheManageDirtyList() */
42955 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -42963,21 +43263,20 @@
42963 ** the dirty list. Doing both moves pPage to the front of the dirty list.
42964 */
42965 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
42966 PCache *p = pPage->pCache;
42967
 
 
 
42968 if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
42969 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
42970 assert( pPage->pDirtyPrev || pPage==p->pDirty );
42971
42972 /* Update the PCache1.pSynced variable if necessary. */
42973 if( p->pSynced==pPage ){
42974 PgHdr *pSynced = pPage->pDirtyPrev;
42975 while( pSynced && (pSynced->flags&PGHDR_NEED_SYNC) ){
42976 pSynced = pSynced->pDirtyPrev;
42977 }
42978 p->pSynced = pSynced;
42979 }
42980
42981 if( pPage->pDirtyNext ){
42982 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
42983 }else{
@@ -42985,14 +43284,19 @@
42985 p->pDirtyTail = pPage->pDirtyPrev;
42986 }
42987 if( pPage->pDirtyPrev ){
42988 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
42989 }else{
 
 
 
 
42990 assert( pPage==p->pDirty );
42991 p->pDirty = pPage->pDirtyNext;
42992 if( p->pDirty==0 && p->bPurgeable ){
42993 assert( p->eCreate==1 );
 
42994 p->eCreate = 2;
42995 }
42996 }
42997 pPage->pDirtyNext = 0;
42998 pPage->pDirtyPrev = 0;
@@ -43010,23 +43314,34 @@
43010 assert( p->eCreate==2 );
43011 p->eCreate = 1;
43012 }
43013 }
43014 p->pDirty = pPage;
43015 if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){
 
 
 
 
 
 
 
 
43016 p->pSynced = pPage;
43017 }
43018 }
 
43019 }
43020
43021 /*
43022 ** Wrapper around the pluggable caches xUnpin method. If the cache is
43023 ** being used for an in-memory database, this function is a no-op.
43024 */
43025 static void pcacheUnpin(PgHdr *p){
43026 if( p->pCache->bPurgeable ){
 
43027 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
 
43028 }
43029 }
43030
43031 /*
43032 ** Compute the number of pages of cache requested. p->szCache is the
@@ -43092,10 +43407,11 @@
43092 p->eCreate = 2;
43093 p->xStress = xStress;
43094 p->pStress = pStress;
43095 p->szCache = 100;
43096 p->szSpill = 1;
 
43097 return sqlite3PcacheSetPageSize(p, szPage);
43098 }
43099
43100 /*
43101 ** Change the page size for PCache object. The caller must ensure that there
@@ -43114,10 +43430,11 @@
43114 if( pCache->pCache ){
43115 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43116 }
43117 pCache->pCache = pNew;
43118 pCache->szPage = szPage;
 
43119 }
43120 return SQLITE_OK;
43121 }
43122
43123 /*
@@ -43148,15 +43465,17 @@
43148 PCache *pCache, /* Obtain the page from this cache */
43149 Pgno pgno, /* Page number to obtain */
43150 int createFlag /* If true, create page if it does not exist already */
43151 ){
43152 int eCreate;
 
43153
43154 assert( pCache!=0 );
43155 assert( pCache->pCache!=0 );
43156 assert( createFlag==3 || createFlag==0 );
43157 assert( pgno>0 );
 
43158
43159 /* eCreate defines what to do if the page does not exist.
43160 ** 0 Do not allocate a new page. (createFlag==0)
43161 ** 1 Allocate a new page if doing so is inexpensive.
43162 ** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43165,16 +43484,19 @@
43165 */
43166 eCreate = createFlag & pCache->eCreate;
43167 assert( eCreate==0 || eCreate==1 || eCreate==2 );
43168 assert( createFlag==0 || pCache->eCreate==eCreate );
43169 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43170 return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
 
 
 
43171 }
43172
43173 /*
43174 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43175 ** page because new clean pages are available for reuse and the cache
43176 ** size limit has been reached, then this routine can be invoked to
43177 ** try harder to allocate a page. This routine might invoke the stress
43178 ** callback to spill dirty pages to the journal. It will then try to
43179 ** allocate the new page and will only fail to allocate a new page on
43180 ** an OOM error.
@@ -43192,11 +43514,15 @@
43192 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
43193 /* Find a dirty page to write-out and recycle. First try to find a
43194 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
43195 ** cleared), but if that is not possible settle for any other
43196 ** unreferenced dirty page.
43197 */
 
 
 
 
43198 for(pPg=pCache->pSynced;
43199 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
43200 pPg=pPg->pDirtyPrev
43201 );
43202 pCache->pSynced = pPg;
@@ -43210,11 +43536,13 @@
43210 "spill page %d making room for %d - cache used: %d/%d",
43211 pPg->pgno, pgno,
43212 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
43213 numberOfCachePages(pCache));
43214 #endif
 
43215 rc = pCache->xStress(pCache->pStress, pPg);
 
43216 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
43217 return rc;
43218 }
43219 }
43220 }
@@ -43270,10 +43598,11 @@
43270 if( !pPgHdr->pPage ){
43271 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
43272 }
43273 pCache->nRefSum++;
43274 pPgHdr->nRef++;
 
43275 return pPgHdr;
43276 }
43277
43278 /*
43279 ** Decrement the reference count on a page. If the page is clean and the
@@ -43283,12 +43612,15 @@
43283 assert( p->nRef>0 );
43284 p->pCache->nRefSum--;
43285 if( (--p->nRef)==0 ){
43286 if( p->flags&PGHDR_CLEAN ){
43287 pcacheUnpin(p);
43288 }else if( p->pDirtyPrev!=0 ){
43289 /* Move the page to the head of the dirty list. */
 
 
 
43290 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43291 }
43292 }
43293 }
43294
@@ -43295,10 +43627,11 @@
43295 /*
43296 ** Increase the reference count of a supplied page by 1.
43297 */
43298 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
43299 assert(p->nRef>0);
 
43300 p->nRef++;
43301 p->pCache->nRefSum++;
43302 }
43303
43304 /*
@@ -43306,10 +43639,11 @@
43306 ** page. This function deletes that reference, so after it returns the
43307 ** page pointed to by p is invalid.
43308 */
43309 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
43310 assert( p->nRef==1 );
 
43311 if( p->flags&PGHDR_DIRTY ){
43312 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43313 }
43314 p->pCache->nRefSum--;
43315 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43319,30 +43653,36 @@
43319 ** Make sure the page is marked as dirty. If it isn't dirty already,
43320 ** make it so.
43321 */
43322 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
43323 assert( p->nRef>0 );
43324 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){
 
43325 p->flags &= ~PGHDR_DONT_WRITE;
43326 if( p->flags & PGHDR_CLEAN ){
43327 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
 
43328 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
43329 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
43330 }
 
43331 }
43332 }
43333
43334 /*
43335 ** Make sure the page is marked as clean. If it isn't clean already,
43336 ** make it so.
43337 */
43338 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43339 if( (p->flags & PGHDR_DIRTY) ){
 
43340 assert( (p->flags & PGHDR_CLEAN)==0 );
43341 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43342 p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43343 p->flags |= PGHDR_CLEAN;
 
 
43344 if( p->nRef==0 ){
43345 pcacheUnpin(p);
43346 }
43347 }
43348 }
@@ -43350,14 +43690,27 @@
43350 /*
43351 ** Make every page in the cache clean.
43352 */
43353 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
43354 PgHdr *p;
 
43355 while( (p = pCache->pDirty)!=0 ){
43356 sqlite3PcacheMakeClean(p);
43357 }
43358 }
 
 
 
 
 
 
 
 
 
 
 
 
43359
43360 /*
43361 ** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
43362 */
43363 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43373,10 +43726,12 @@
43373 */
43374 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
43375 PCache *pCache = p->pCache;
43376 assert( p->nRef>0 );
43377 assert( newPgno>0 );
 
 
43378 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
43379 p->pgno = newPgno;
43380 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
43381 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43382 }
@@ -43393,18 +43748,19 @@
43393 */
43394 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
43395 if( pCache->pCache ){
43396 PgHdr *p;
43397 PgHdr *pNext;
 
43398 for(p=pCache->pDirty; p; p=pNext){
43399 pNext = p->pDirtyNext;
43400 /* This routine never gets call with a positive pgno except right
43401 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43402 ** it must be that pgno==0.
43403 */
43404 assert( p->pgno>0 );
43405 if( ALWAYS(p->pgno>pgno) ){
43406 assert( p->flags&PGHDR_DIRTY );
43407 sqlite3PcacheMakeClean(p);
43408 }
43409 }
43410 if( pgno==0 && pCache->nRefSum ){
@@ -43423,10 +43779,11 @@
43423 /*
43424 ** Close a cache.
43425 */
43426 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
43427 assert( pCache->pCache!=0 );
 
43428 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43429 }
43430
43431 /*
43432 ** Discard the contents of the cache.
@@ -43591,10 +43948,21 @@
43591 ** Return the size of the header added by this middleware layer
43592 ** in the page-cache hierarchy.
43593 */
43594 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
43595
 
 
 
 
 
 
 
 
 
 
 
43596
43597 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
43598 /*
43599 ** For all dirty pages currently in the cache, invoke the specified
43600 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44668,12 @@
44300 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
44301 #endif
44302
44303 #if SQLITE_THREADSAFE
44304 if( sqlite3GlobalConfig.bCoreMutex ){
44305 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
44306 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
44307 }
44308 #endif
44309 if( pcache1.separateCache
44310 && sqlite3GlobalConfig.nPage!=0
44311 && sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45275,13 @@
44907 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
44908 ** The cost of a TEST using the same batch number is O(logN). The cost
44909 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
44910 ** primitives are constant time. The cost of DESTROY is O(N).
44911 **
44912 ** There is an added cost of O(N) when switching between TEST and
44913 ** SMALLEST primitives.
 
44914 */
44915 /* #include "sqliteInt.h" */
44916
44917
44918 /*
@@ -45029,11 +45398,13 @@
45029 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
45030 ** routine returns NULL.
45031 */
45032 static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
45033 assert( p!=0 );
45034 if( p->nFresh==0 ){
 
 
45035 struct RowSetChunk *pNew;
45036 pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
45037 if( pNew==0 ){
45038 return 0;
45039 }
@@ -45063,11 +45434,13 @@
45063 if( pEntry==0 ) return;
45064 pEntry->v = rowid;
45065 pEntry->pRight = 0;
45066 pLast = p->pLast;
45067 if( pLast ){
45068 if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){
 
 
45069 p->rsFlags &= ~ROWSET_SORTED;
45070 }
45071 pLast->pRight = pEntry;
45072 }else{
45073 p->pEntry = pEntry;
@@ -45185,27 +45558,33 @@
45185 struct RowSetEntry **ppList,
45186 int iDepth
45187 ){
45188 struct RowSetEntry *p; /* Root of the new tree */
45189 struct RowSetEntry *pLeft; /* Left subtree */
45190 if( *ppList==0 ){
45191 return 0;
 
45192 }
45193 if( iDepth==1 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45194 p = *ppList;
45195 *ppList = p->pRight;
45196 p->pLeft = p->pRight = 0;
45197 return p;
45198 }
45199 pLeft = rowSetNDeepTree(ppList, iDepth-1);
45200 p = *ppList;
45201 if( p==0 ){
45202 return pLeft;
45203 }
45204 p->pLeft = pLeft;
45205 *ppList = p->pRight;
45206 p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45207 return p;
45208 }
45209
45210 /*
45211 ** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45607,41 @@
45228 p->pRight = rowSetNDeepTree(&pList, iDepth);
45229 }
45230 return p;
45231 }
45232
45233 /*
45234 ** Take all the entries on p->pEntry and on the trees in p->pForest and
45235 ** sort them all together into one big ordered list on p->pEntry.
45236 **
45237 ** This routine should only be called once in the life of a RowSet.
45238 */
45239 static void rowSetToList(RowSet *p){
45240
45241 /* This routine is called only once */
45242 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
45243
45244 if( (p->rsFlags & ROWSET_SORTED)==0 ){
45245 p->pEntry = rowSetEntrySort(p->pEntry);
45246 }
45247
45248 /* While this module could theoretically support it, sqlite3RowSetNext()
45249 ** is never called after sqlite3RowSetText() for the same RowSet. So
45250 ** there is never a forest to deal with. Should this change, simply
45251 ** remove the assert() and the #if 0. */
45252 assert( p->pForest==0 );
45253 #if 0
45254 while( p->pForest ){
45255 struct RowSetEntry *pTree = p->pForest->pLeft;
45256 if( pTree ){
45257 struct RowSetEntry *pHead, *pTail;
45258 rowSetTreeToList(pTree, &pHead, &pTail);
45259 p->pEntry = rowSetEntryMerge(p->pEntry, pHead);
45260 }
45261 p->pForest = p->pForest->pRight;
45262 }
45263 #endif
45264 p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */
45265 }
45266
45267 /*
45268 ** Extract the smallest element from the RowSet.
45269 ** Write the element into *pRowid. Return 1 on success. Return
45270 ** 0 if the RowSet is already empty.
45271 **
45272 ** After this routine has been called, the sqlite3RowSetInsert()
45273 ** routine may not be called again.
 
 
 
 
 
45274 */
45275 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
45276 assert( p!=0 );
 
45277
45278 /* Merge the forest into a single sorted list on first call */
45279 if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p);
 
 
 
 
 
45280
45281 /* Return the next entry on the list */
45282 if( p->pEntry ){
45283 *pRowid = p->pEntry->v;
45284 p->pEntry = p->pEntry->pRight;
45285 if( p->pEntry==0 ){
 
45286 sqlite3RowSetClear(p);
45287 }
45288 return 1;
45289 }else{
45290 return 0;
@@ -45303,17 +45660,19 @@
45303 struct RowSetEntry *p, *pTree;
45304
45305 /* This routine is never called after sqlite3RowSetNext() */
45306 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
45307
45308 /* Sort entries into the forest on the first test of a new batch
 
45309 */
45310 if( iBatch!=pRowSet->iBatch ){
45311 p = pRowSet->pEntry;
45312 if( p ){
45313 struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45314 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){
 
45315 p = rowSetEntrySort(p);
45316 }
45317 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
45318 ppPrevTree = &pTree->pRight;
45319 if( pTree->pLeft==0 ){
@@ -46383,10 +46742,11 @@
46383 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
46384 ** is therefore not possible for an in-memory pager to enter the ERROR
46385 ** state.
46386 */
46387 if( MEMDB ){
 
46388 assert( p->noSync );
46389 assert( p->journalMode==PAGER_JOURNALMODE_OFF
46390 || p->journalMode==PAGER_JOURNALMODE_MEMORY
46391 );
46392 assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46829,11 @@
46469 /* There must be at least one outstanding reference to the pager if
46470 ** in ERROR state. Otherwise the pager should have already dropped
46471 ** back to OPEN state.
46472 */
46473 assert( pPager->errCode!=SQLITE_OK );
46474 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
46475 break;
46476 }
46477
46478 return 1;
46479 }
@@ -46681,10 +47041,12 @@
46681 }
46682 }
46683
46684 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
46685 }
 
 
46686 #endif
46687
46688 /*
46689 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
46690 ** on the cache using a hash function. This is used for testing
@@ -47329,17 +47691,21 @@
47329 /* If Pager.errCode is set, the contents of the pager cache cannot be
47330 ** trusted. Now that there are no outstanding references to the pager,
47331 ** it can safely move back to PAGER_OPEN state. This happens in both
47332 ** normal and exclusive-locking mode.
47333 */
 
47334 if( pPager->errCode ){
47335 assert( !MEMDB );
47336 pager_reset(pPager);
47337 pPager->changeCountDone = pPager->tempFile;
47338 pPager->eState = PAGER_OPEN;
47339 pPager->errCode = SQLITE_OK;
 
 
47340 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
 
47341 }
47342
47343 pPager->journalOff = 0;
47344 pPager->journalHdr = 0;
47345 pPager->setMaster = 0;
@@ -47378,10 +47744,33 @@
47378 }
47379 return rc;
47380 }
47381
47382 static int pager_truncate(Pager *pPager, Pgno nPage);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47383
47384 /*
47385 ** This routine ends a transaction. A transaction is usually ended by
47386 ** either a COMMIT or a ROLLBACK operation. This routine may be called
47387 ** after rollback of a hot-journal, or if an error occurs while opening
@@ -47482,11 +47871,11 @@
47482 }
47483 pPager->journalOff = 0;
47484 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
47485 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
47486 ){
47487 rc = zeroJournalHdr(pPager, hasMaster);
47488 pPager->journalOff = 0;
47489 }else{
47490 /* This branch may be executed with Pager.journalMode==MEMORY if
47491 ** a hot-journal was just rolled back. In this case the journal
47492 ** file should be closed and deleted. If this connection writes to
@@ -47517,12 +47906,18 @@
47517 #endif
47518
47519 sqlite3BitvecDestroy(pPager->pInJournal);
47520 pPager->pInJournal = 0;
47521 pPager->nRec = 0;
47522 sqlite3PcacheCleanAll(pPager->pPCache);
47523 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
 
 
 
 
 
 
47524
47525 if( pagerUseWal(pPager) ){
47526 /* Drop the WAL write-lock, if any. Also, if the connection was in
47527 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
47528 ** lock held on the database file.
@@ -47802,11 +48197,11 @@
47802 pPg = 0;
47803 }else{
47804 pPg = sqlite3PagerLookup(pPager, pgno);
47805 }
47806 assert( pPg || !MEMDB );
47807 assert( pPager->eState!=PAGER_OPEN || pPg==0 );
47808 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
47809 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
47810 (isMainJrnl?"main-journal":"sub-journal")
47811 ));
47812 if( isMainJrnl ){
@@ -47852,11 +48247,10 @@
47852 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
47853 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
47854 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
47855 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
47856 if( rc!=SQLITE_OK ) return rc;
47857 pPg->flags &= ~PGHDR_NEED_READ;
47858 sqlite3PcacheMakeDirty(pPg);
47859 }
47860 if( pPg ){
47861 /* No page should ever be explicitly rolled back that is in use, except
47862 ** for page 1 which is held in use in order to keep the lock on the
@@ -47866,33 +48260,14 @@
47866 */
47867 void *pData;
47868 pData = pPg->pData;
47869 memcpy(pData, (u8*)aData, pPager->pageSize);
47870 pPager->xReiniter(pPg);
47871 if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){
47872 /* If the contents of this page were just restored from the main
47873 ** journal file, then its content must be as they were when the
47874 ** transaction was first opened. In this case we can mark the page
47875 ** as clean, since there will be no need to write it out to the
47876 ** database.
47877 **
47878 ** There is one exception to this rule. If the page is being rolled
47879 ** back as part of a savepoint (or statement) rollback from an
47880 ** unsynced portion of the main journal file, then it is not safe
47881 ** to mark the page as clean. This is because marking the page as
47882 ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is
47883 ** already in the journal file (recorded in Pager.pInJournal) and
47884 ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to
47885 ** again within this transaction, it will be marked as dirty but
47886 ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
47887 ** be written out into the database file before its journal file
47888 ** segment is synced. If a crash occurs during or following this,
47889 ** database corruption may ensue.
47890 */
47891 assert( !pagerUseWal(pPager) );
47892 sqlite3PcacheMakeClean(pPg);
47893 }
47894 pager_set_pagehash(pPg);
47895
47896 /* If this was page 1, then restore the value of Pager.dbFileVers.
47897 ** Do this before any decoding. */
47898 if( pgno==1 ){
@@ -48679,25 +49054,24 @@
48679 ** available from the WAL sub-system if the log file is empty or
48680 ** contains no valid committed transactions.
48681 */
48682 assert( pPager->eState==PAGER_OPEN );
48683 assert( pPager->eLock>=SHARED_LOCK );
 
 
48684 nPage = sqlite3WalDbsize(pPager->pWal);
48685
48686 /* If the number of pages in the database is not available from the
48687 ** WAL sub-system, determine the page counte based on the size of
48688 ** the database file. If the size of the database file is not an
48689 ** integer multiple of the page-size, round up the result.
48690 */
48691 if( nPage==0 ){
48692 i64 n = 0; /* Size of db file in bytes */
48693 assert( isOpen(pPager->fd) || pPager->tempFile );
48694 if( isOpen(pPager->fd) ){
48695 int rc = sqlite3OsFileSize(pPager->fd, &n);
48696 if( rc!=SQLITE_OK ){
48697 return rc;
48698 }
48699 }
48700 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
48701 }
48702
48703 /* If the current number of pages in the file is greater than the
@@ -49769,12 +50143,13 @@
49769 static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
49770 int rc = SQLITE_OK; /* Return code */
49771
49772 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
49773 assert( !pagerUseWal(pPager) );
49774 assert( pPager->eState==PAGER_WRITER_DBMOD );
49775 assert( pPager->eLock==EXCLUSIVE_LOCK );
 
49776
49777 /* If the file is a temp-file has not yet been opened, open it now. It
49778 ** is not possible for rc to be other than SQLITE_OK if this branch
49779 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
49780 */
@@ -50438,10 +50813,11 @@
50438 */
50439 rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
50440 if( rc==SQLITE_OK && !locked ){
50441 Pgno nPage; /* Number of pages in database file */
50442
 
50443 rc = pagerPagecount(pPager, &nPage);
50444 if( rc==SQLITE_OK ){
50445 /* If the database is zero pages in size, that means that either (1) the
50446 ** journal is a remnant from a prior database with the same name where
50447 ** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50906,21 @@
50530 int rc = SQLITE_OK; /* Return code */
50531
50532 /* This routine is only called from b-tree and only when there are no
50533 ** outstanding pages. This implies that the pager state should either
50534 ** be OPEN or READER. READER is only possible if the pager is or was in
50535 ** exclusive access mode.
50536 */
50537 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
50538 assert( assert_pager_state(pPager) );
50539 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50540 if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; }
50541
50542 if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
50543 int bHotJournal = 1; /* True if there exists a hot journal-file */
50544
50545 assert( !MEMDB );
 
50546
50547 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
50548 if( rc!=SQLITE_OK ){
50549 assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
50550 goto failed;
@@ -50626,11 +51002,11 @@
50626 */
50627 if( isOpen(pPager->jfd) ){
50628 assert( rc==SQLITE_OK );
50629 rc = pagerSyncHotJournal(pPager);
50630 if( rc==SQLITE_OK ){
50631 rc = pager_playback(pPager, 1);
50632 pPager->eState = PAGER_OPEN;
50633 }
50634 }else if( !pPager->exclusiveMode ){
50635 pagerUnlockDb(pPager, SHARED_LOCK);
50636 }
@@ -50722,11 +51098,11 @@
50722 if( pagerUseWal(pPager) ){
50723 assert( rc==SQLITE_OK );
50724 rc = pagerBeginReadTransaction(pPager);
50725 }
50726
50727 if( pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
50728 rc = pagerPagecount(pPager, &pPager->dbSize);
50729 }
50730
50731 failed:
50732 if( rc!=SQLITE_OK ){
@@ -50855,11 +51231,11 @@
50855 rc = sqlite3OsFetch(pPager->fd,
50856 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
50857 );
50858
50859 if( rc==SQLITE_OK && pData ){
50860 if( pPager->eState>PAGER_READER ){
50861 pPg = sqlite3PagerLookup(pPager, pgno);
50862 }
50863 if( pPg==0 ){
50864 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
50865 }else{
@@ -50922,11 +51298,12 @@
50922 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
50923 rc = SQLITE_CORRUPT_BKPT;
50924 goto pager_acquire_err;
50925 }
50926
50927 if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){
 
50928 if( pgno>pPager->mxPgno ){
50929 rc = SQLITE_FULL;
50930 goto pager_acquire_err;
50931 }
50932 if( noContent ){
@@ -51064,28 +51441,28 @@
51064 /* Open the journal file if it is not already open. */
51065 if( !isOpen(pPager->jfd) ){
51066 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
51067 sqlite3MemJournalOpen(pPager->jfd);
51068 }else{
51069 const int flags = /* VFS flags to open journal file */
51070 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
51071 (pPager->tempFile ?
51072 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
51073 (SQLITE_OPEN_MAIN_JOURNAL)
51074 );
51075
 
 
 
 
 
 
 
 
51076 /* Verify that the database still has the same name as it did when
51077 ** it was originally opened. */
51078 rc = databaseIsUnmoved(pPager);
51079 if( rc==SQLITE_OK ){
51080 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
51081 rc = sqlite3JournalOpen(
51082 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
51083 );
51084 #else
51085 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
51086 #endif
51087 }
51088 }
51089 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
51090 }
51091
@@ -51452,10 +51829,11 @@
51452 return pPager->errCode;
51453 }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
51454 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
51455 return SQLITE_OK;
51456 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
 
51457 return pagerWriteLargeSector(pPg);
51458 }else{
51459 return pager_write(pPg);
51460 }
51461 }
@@ -51482,18 +51860,25 @@
51482 ** on the given page is unused. The pager marks the page as clean so
51483 ** that it does not get written to disk.
51484 **
51485 ** Tests show that this optimization can quadruple the speed of large
51486 ** DELETE operations.
 
 
 
 
 
 
51487 */
51488 SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
51489 Pager *pPager = pPg->pPager;
51490 if( (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
51491 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
51492 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
51493 pPg->flags |= PGHDR_DONT_WRITE;
51494 pPg->flags &= ~PGHDR_WRITEABLE;
 
51495 pager_set_pagehash(pPg);
51496 }
51497 }
51498
51499 /*
@@ -51683,22 +52068,26 @@
51683 );
51684 assert( assert_pager_state(pPager) );
51685
51686 /* If a prior error occurred, report that error again. */
51687 if( NEVER(pPager->errCode) ) return pPager->errCode;
 
 
 
51688
51689 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
51690 pPager->zFilename, zMaster, pPager->dbSize));
51691
51692 /* If no database changes have been made, return early. */
51693 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
51694
51695 if( MEMDB ){
 
 
51696 /* If this is an in-memory db, or no pages have been written to, or this
51697 ** function has already been called, it is mostly a no-op. However, any
51698 ** backup in progress needs to be restarted.
51699 */
51700 sqlite3BackupRestart(pPager->pBackup);
51701 }else{
51702 if( pagerUseWal(pPager) ){
51703 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
51704 PgHdr *pPageOne = 0;
@@ -52033,14 +52422,14 @@
52033 pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
52034 }
52035 }
52036
52037 /*
52038 ** Return true if this is an in-memory pager.
52039 */
52040 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52041 return MEMDB;
52042 }
52043
52044 /*
52045 ** Check that there are at least nSavepoint savepoints open. If there are
52046 ** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52705,12 @@
52316 assert( assert_pager_state(pPager) );
52317
52318 /* In order to be able to rollback, an in-memory database must journal
52319 ** the page we are moving from.
52320 */
52321 if( MEMDB ){
 
52322 rc = sqlite3PagerWrite(pPg);
52323 if( rc ) return rc;
52324 }
52325
52326 /* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52763,11 @@
52373 pPg->flags &= ~PGHDR_NEED_SYNC;
52374 pPgOld = sqlite3PagerLookup(pPager, pgno);
52375 assert( !pPgOld || pPgOld->nRef==1 );
52376 if( pPgOld ){
52377 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52378 if( MEMDB ){
52379 /* Do not discard pages from an in-memory database since we might
52380 ** need to rollback later. Just move the page out of the way. */
52381 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
52382 }else{
52383 sqlite3PcacheDrop(pPgOld);
@@ -52390,12 +52780,11 @@
52390
52391 /* For an in-memory database, make sure the original page continues
52392 ** to exist, in case the transaction needs to roll back. Use pPgOld
52393 ** as the original page since it has already been allocated.
52394 */
52395 if( MEMDB ){
52396 assert( pPgOld );
52397 sqlite3PcacheMove(pPgOld, origPgno);
52398 sqlite3PagerUnrefNotNull(pPgOld);
52399 }
52400
52401 if( needSyncPgno ){
@@ -52643,11 +53032,12 @@
52643 #ifndef SQLITE_OMIT_VACUUM
52644 /*
52645 ** Unless this is an in-memory or temporary database, clear the pager cache.
52646 */
52647 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
52648 if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
 
52649 }
52650 #endif
52651
52652 #ifndef SQLITE_OMIT_WAL
52653 /*
@@ -52822,10 +53212,11 @@
52822 if( rc==SQLITE_OK ){
52823 rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
52824 pPager->pageSize, (u8*)pPager->pTmpSpace);
52825 pPager->pWal = 0;
52826 pagerFixMaplimit(pPager);
 
52827 }
52828 }
52829 return rc;
52830 }
52831
@@ -56277,10 +56668,27 @@
56277 /* Try to open on pSnapshot when the next read-transaction starts
56278 */
56279 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
56280 pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
56281 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56282 #endif /* SQLITE_ENABLE_SNAPSHOT */
56283
56284 #ifdef SQLITE_ENABLE_ZIPVFS
56285 /*
56286 ** If the argument is not NULL, it points to a Wal object that holds a
@@ -58992,15 +59400,15 @@
58992 flagByte &= ~PTF_LEAF;
58993 pPage->childPtrSize = 4-4*pPage->leaf;
58994 pPage->xCellSize = cellSizePtr;
58995 pBt = pPage->pBt;
58996 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
58997 /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
58998 ** table b-tree page. */
58999 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59000 /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
59001 ** table b-tree page. */
59002 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
59003 pPage->intKey = 1;
59004 if( pPage->leaf ){
59005 pPage->intKeyLeaf = 1;
59006 pPage->xParseCell = btreeParseCellPtr;
@@ -59010,15 +59418,15 @@
59010 pPage->xParseCell = btreeParseCellPtrNoPayload;
59011 }
59012 pPage->maxLocal = pBt->maxLeaf;
59013 pPage->minLocal = pBt->minLeaf;
59014 }else if( flagByte==PTF_ZERODATA ){
59015 /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
59016 ** index b-tree page. */
59017 assert( (PTF_ZERODATA)==2 );
59018 /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
59019 ** index b-tree page. */
59020 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
59021 pPage->intKey = 0;
59022 pPage->intKeyLeaf = 0;
59023 pPage->xParseCell = btreeParseCellPtrIndex;
59024 pPage->maxLocal = pBt->maxLocal;
@@ -65455,10 +65863,32 @@
65455
65456 iCellDepth = pCur->iPage;
65457 iCellIdx = pCur->aiIdx[iCellDepth];
65458 pPage = pCur->apPage[iCellDepth];
65459 pCell = findCell(pPage, iCellIdx);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65460
65461 /* If the page containing the entry to delete is not a leaf page, move
65462 ** the cursor to the largest entry in the tree that is smaller than
65463 ** the entry being deleted. This cell will replace the cell being deleted
65464 ** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65912,10 @@
65482 ** invalidate any incrblob cursors open on the row being deleted. */
65483 if( pCur->pKeyInfo==0 ){
65484 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
65485 }
65486
65487 /* If the bPreserve flag is set to true, then the cursor position must
65488 ** be preserved following this delete operation. If the current delete
65489 ** will cause a b-tree rebalance, then this is done by saving the cursor
65490 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65491 ** returning.
65492 **
65493 ** Or, if the current delete will not cause a rebalance, then the cursor
65494 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65495 ** before or after the deleted entry. In this case set bSkipnext to true. */
65496 if( bPreserve ){
65497 if( !pPage->leaf
65498 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65499 ){
65500 /* A b-tree rebalance will be required after deleting this entry.
65501 ** Save the cursor key. */
65502 rc = saveCursorKey(pCur);
65503 if( rc ) return rc;
65504 }else{
65505 bSkipnext = 1;
65506 }
65507 }
65508
65509 /* Make the page containing the entry to be deleted writable. Then free any
65510 ** overflow pages associated with the entry and finally remove the cell
65511 ** itself from within the page. */
65512 rc = sqlite3PagerWrite(pPage->pDbPage);
65513 if( rc ) return rc;
@@ -70082,77 +70490,88 @@
70082 ** indicate what the prepared statement actually does.
70083 **
70084 ** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
70085 **
70086 ** (5) Reclaim the memory allocated for storing labels.
 
 
 
 
70087 */
70088 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
70089 int i;
70090 int nMaxArgs = *pMaxFuncArgs;
70091 Op *pOp;
70092 Parse *pParse = p->pParse;
70093 int *aLabel = pParse->aLabel;
70094 p->readOnly = 1;
70095 p->bIsReader = 0;
70096 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
70097 u8 opcode = pOp->opcode;
70098
70099 /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70100 ** cases from this switch! */
70101 switch( opcode ){
70102 case OP_Transaction: {
70103 if( pOp->p2!=0 ) p->readOnly = 0;
70104 /* fall thru */
70105 }
70106 case OP_AutoCommit:
70107 case OP_Savepoint: {
70108 p->bIsReader = 1;
70109 break;
70110 }
 
 
 
 
 
 
 
70111 #ifndef SQLITE_OMIT_WAL
70112 case OP_Checkpoint:
70113 #endif
70114 case OP_Vacuum:
70115 case OP_JournalMode: {
70116 p->readOnly = 0;
70117 p->bIsReader = 1;
70118 break;
70119 }
70120 #ifndef SQLITE_OMIT_VIRTUALTABLE
70121 case OP_VUpdate: {
70122 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70123 break;
70124 }
70125 case OP_VFilter: {
70126 int n;
70127 assert( p->nOp - i >= 3 );
70128 assert( pOp[-1].opcode==OP_Integer );
70129 n = pOp[-1].p1;
70130 if( n>nMaxArgs ) nMaxArgs = n;
70131 break;
70132 }
70133 #endif
70134 case OP_Next:
70135 case OP_NextIfOpen:
70136 case OP_SorterNext: {
70137 pOp->p4.xAdvance = sqlite3BtreeNext;
70138 pOp->p4type = P4_ADVANCE;
70139 break;
70140 }
70141 case OP_Prev:
70142 case OP_PrevIfOpen: {
70143 pOp->p4.xAdvance = sqlite3BtreePrevious;
70144 pOp->p4type = P4_ADVANCE;
70145 break;
70146 }
70147 }
70148
70149 pOp->opflags = sqlite3OpcodeProperty[opcode];
70150 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70151 assert( ADDR(pOp->p2)<pParse->nLabel );
70152 pOp->p2 = aLabel[ADDR(pOp->p2)];
70153 }
 
70154 }
70155 sqlite3DbFree(p->db, pParse->aLabel);
70156 pParse->aLabel = 0;
70157 pParse->nLabel = 0;
70158 *pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76799,11 @@
76380 nByte =
76381 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
76382 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
76383
76384 assert( iCur>=0 && iCur<p->nCursor );
76385 if( p->apCsr[iCur] ){
76386 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
76387 p->apCsr[iCur] = 0;
76388 }
76389 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
76390 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76876,27 @@
76457 u8 enc /* Use this text encoding */
76458 ){
76459 if( affinity>=SQLITE_AFF_NUMERIC ){
76460 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
76461 || affinity==SQLITE_AFF_NUMERIC );
76462 if( (pRec->flags & MEM_Int)==0 ){
76463 if( (pRec->flags & MEM_Real)==0 ){
76464 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
76465 }else{
76466 sqlite3VdbeIntegerAffinity(pRec);
76467 }
76468 }
76469 }else if( affinity==SQLITE_AFF_TEXT ){
76470 /* Only attempt the conversion to TEXT if there is an integer or real
76471 ** representation (blob and NULL do not get converted) but no string
76472 ** representation.
76473 */
76474 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
76475 sqlite3VdbeMemStringify(pRec, enc, 1);
 
 
 
76476 }
76477 pRec->flags &= ~(MEM_Real|MEM_Int);
76478 }
76479 }
76480
@@ -76796,11 +77218,11 @@
76796 Mem *pOut;
76797 assert( pOp->p2>0 );
76798 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76799 pOut = &p->aMem[pOp->p2];
76800 memAboutToChange(p, pOut);
76801 if( VdbeMemDynamic(pOut) ){
76802 return out2PrereleaseWithClear(pOut);
76803 }else{
76804 pOut->flags = MEM_Int;
76805 return pOut;
76806 }
@@ -76928,41 +77350,43 @@
76928 }
76929 #endif
76930
76931 /* Sanity checking on other operands */
76932 #ifdef SQLITE_DEBUG
76933 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
76934 if( (pOp->opflags & OPFLG_IN1)!=0 ){
76935 assert( pOp->p1>0 );
76936 assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
76937 assert( memIsValid(&aMem[pOp->p1]) );
76938 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
76939 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
76940 }
76941 if( (pOp->opflags & OPFLG_IN2)!=0 ){
76942 assert( pOp->p2>0 );
76943 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76944 assert( memIsValid(&aMem[pOp->p2]) );
76945 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
76946 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
76947 }
76948 if( (pOp->opflags & OPFLG_IN3)!=0 ){
76949 assert( pOp->p3>0 );
76950 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76951 assert( memIsValid(&aMem[pOp->p3]) );
76952 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
76953 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
76954 }
76955 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
76956 assert( pOp->p2>0 );
76957 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76958 memAboutToChange(p, &aMem[pOp->p2]);
76959 }
76960 if( (pOp->opflags & OPFLG_OUT3)!=0 ){
76961 assert( pOp->p3>0 );
76962 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76963 memAboutToChange(p, &aMem[pOp->p3]);
 
 
76964 }
76965 #endif
76966 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
76967 pOrigOp = pOp;
76968 #endif
@@ -77198,12 +77622,10 @@
77198 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
77199 ** every program. So a jump past the last instruction of the program
77200 ** is the same as executing Halt.
77201 */
77202 case OP_Halt: {
77203 const char *zType;
77204 const char *zLogFmt;
77205 VdbeFrame *pFrame;
77206 int pcx;
77207
77208 pcx = (int)(pOp - aOp);
77209 if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77650,32 @@
77228 break;
77229 }
77230 p->rc = pOp->p1;
77231 p->errorAction = (u8)pOp->p2;
77232 p->pc = pcx;
 
77233 if( p->rc ){
77234 if( pOp->p5 ){
77235 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
77236 "FOREIGN KEY" };
77237 assert( pOp->p5>=1 && pOp->p5<=4 );
77238 testcase( pOp->p5==1 );
77239 testcase( pOp->p5==2 );
77240 testcase( pOp->p5==3 );
77241 testcase( pOp->p5==4 );
77242 zType = azType[pOp->p5-1];
 
 
 
77243 }else{
77244 zType = 0;
77245 }
77246 assert( zType!=0 || pOp->p4.z!=0 );
77247 zLogFmt = "abort at %d in [%s]: %s";
77248 if( zType && pOp->p4.z ){
77249 sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z);
77250 }else if( pOp->p4.z ){
77251 sqlite3VdbeError(p, "%s", pOp->p4.z);
77252 }else{
77253 sqlite3VdbeError(p, "%s constraint failed", zType);
77254 }
77255 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
77256 }
77257 rc = sqlite3VdbeHalt(p);
77258 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
77259 if( rc==SQLITE_BUSY ){
77260 p->rc = rc = SQLITE_BUSY;
77261 }else{
77262 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
77263 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
77264 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
77265 }
@@ -77321,14 +77737,11 @@
77321 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
77322
77323 #ifndef SQLITE_OMIT_UTF16
77324 if( encoding!=SQLITE_UTF8 ){
77325 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77326 if( rc ){
77327 assert( rc==SQLITE_TOOBIG ); /* This is the only possible error here */
77328 goto too_big;
77329 }
77330 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
77331 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
77332 assert( VdbeMemDynamic(pOut)==0 );
77333 pOut->szMalloc = 0;
77334 pOut->flags |= MEM_Static;
@@ -77337,26 +77750,30 @@
77337 }
77338 pOp->p4type = P4_DYNAMIC;
77339 pOp->p4.z = pOut->z;
77340 pOp->p1 = pOut->n;
77341 }
 
77342 #endif
77343 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77344 goto too_big;
77345 }
 
77346 /* Fall through to the next case, OP_String */
77347 }
77348
77349 /* Opcode: String P1 P2 P3 P4 P5
77350 ** Synopsis: r[P2]='P4' (len=P1)
77351 **
77352 ** The string value P4 of length P1 (bytes) is stored in register P2.
77353 **
77354 ** If P5!=0 and the content of register P3 is greater than zero, then
77355 ** the datatype of the register P2 is converted to BLOB. The content is
77356 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
77357 ** of a string, as if it had been CAST.
 
 
77358 */
77359 case OP_String: { /* out2 */
77360 assert( pOp->p4.z!=0 );
77361 pOut = out2Prerelease(p, pOp);
77362 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77780,15 @@
77363 pOut->z = pOp->p4.z;
77364 pOut->n = pOp->p1;
77365 pOut->enc = encoding;
77366 UPDATE_MAX_BLOBSIZE(pOut);
77367 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77368 if( pOp->p5 ){
77369 assert( pOp->p3>0 );
77370 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77371 pIn3 = &aMem[pOp->p3];
77372 assert( pIn3->flags & MEM_Int );
77373 if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77374 }
77375 #endif
77376 break;
77377 }
77378
@@ -82224,25 +82640,10 @@
82224 if( pIn1->u.i==0 ) goto jump_to_p2;
82225 break;
82226 }
82227
82228
82229 /* Opcode: JumpZeroIncr P1 P2 * * *
82230 ** Synopsis: if (r[P1]++)==0 ) goto P2
82231 **
82232 ** The register P1 must contain an integer. If register P1 is initially
82233 ** zero, then jump to P2. Increment register P1 regardless of whether or
82234 ** not the jump is taken.
82235 */
82236 case OP_JumpZeroIncr: { /* jump, in1 */
82237 pIn1 = &aMem[pOp->p1];
82238 assert( pIn1->flags&MEM_Int );
82239 VdbeBranchTaken(pIn1->u.i==0, 2);
82240 if( (pIn1->u.i++)==0 ) goto jump_to_p2;
82241 break;
82242 }
82243
82244 /* Opcode: AggStep0 * P2 P3 P4 P5
82245 ** Synopsis: accum=r[P3] step(r[P2@P5])
82246 **
82247 ** Execute the step function for an aggregate. The
82248 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83532,16 @@
83131 #ifndef NDEBUG
83132 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
83133
83134 #ifdef SQLITE_DEBUG
83135 if( db->flags & SQLITE_VdbeTrace ){
 
83136 if( rc!=0 ) printf("rc=%d\n",rc);
83137 if( pOrigOp->opflags & (OPFLG_OUT2) ){
83138 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
83139 }
83140 if( pOrigOp->opflags & OPFLG_OUT3 ){
83141 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
83142 }
83143 }
83144 #endif /* SQLITE_DEBUG */
83145 #endif /* NDEBUG */
@@ -84648,11 +85050,10 @@
84648 int nField, /* Number of key fields in each record */
84649 VdbeCursor *pCsr /* Cursor that holds the new sorter */
84650 ){
84651 int pgsz; /* Page size of main database */
84652 int i; /* Used to iterate through aTask[] */
84653 int mxCache; /* Cache size */
84654 VdbeSorter *pSorter; /* The new sorter */
84655 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
84656 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
84657 int sz; /* Size of pSorter in bytes */
84658 int rc = SQLITE_OK;
@@ -84705,15 +85106,24 @@
84705 SortSubtask *pTask = &pSorter->aTask[i];
84706 pTask->pSorter = pSorter;
84707 }
84708
84709 if( !sqlite3TempInMemory(db) ){
 
84710 u32 szPma = sqlite3GlobalConfig.szPma;
84711 pSorter->mnPmaSize = szPma * pgsz;
 
84712 mxCache = db->aDb[0].pSchema->cache_size;
84713 if( mxCache<(int)szPma ) mxCache = (int)szPma;
84714 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
 
 
 
 
 
 
 
84715
84716 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
84717 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
84718 ** large heap allocations.
84719 */
@@ -86473,10 +86883,19 @@
86473 *************************************************************************
86474 **
86475 ** This file contains code use to implement an in-memory rollback journal.
86476 ** The in-memory rollback journal is used to journal transactions for
86477 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
 
 
 
 
 
 
 
 
 
86478 */
86479 /* #include "sqliteInt.h" */
86480
86481 /* Forward references to internal structures */
86482 typedef struct MemJournal MemJournal;
@@ -87799,10 +88218,11 @@
87799 notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
87800 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
87801 assert( pNC->nRef>=nRef );
87802 if( nRef!=pNC->nRef ){
87803 ExprSetProperty(pExpr, EP_VarSelect);
 
87804 }
87805 }
87806 break;
87807 }
87808 case TK_VARIABLE: {
@@ -89006,19 +89426,17 @@
89006 if( pToken ){
89007 if( nExtra==0 ){
89008 pNew->flags |= EP_IntValue;
89009 pNew->u.iValue = iValue;
89010 }else{
89011 int c;
89012 pNew->u.zToken = (char*)&pNew[1];
89013 assert( pToken->z!=0 || pToken->n==0 );
89014 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
89015 pNew->u.zToken[pToken->n] = 0;
89016 if( dequote && nExtra>=3
89017 && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
89018 sqlite3Dequote(pNew->u.zToken);
89019 if( c=='"' ) pNew->flags |= EP_DblQuoted;
89020 }
89021 }
89022 }
89023 #if SQLITE_MAX_EXPR_DEPTH>0
89024 pNew->nHeight = 1;
@@ -89096,10 +89514,26 @@
89096 if( p ) {
89097 sqlite3ExprCheckHeight(pParse, p->nHeight);
89098 }
89099 return p;
89100 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89101
89102 /*
89103 ** If the expression is always either TRUE or FALSE (respectively),
89104 ** then return 1. If one cannot determine the truth value of the
89105 ** expression at compile-time return 0.
@@ -89257,12 +89691,12 @@
89257 }
89258
89259 /*
89260 ** Recursively delete an expression tree.
89261 */
89262 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89263 if( p==0 ) return;
89264 /* Sanity check: Assert that the IntValue is non-negative if it exists */
89265 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
89266 if( !ExprHasProperty(p, EP_TokenOnly) ){
89267 /* The Expr.x union is never used at the same time as Expr.pRight */
89268 assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89710,13 @@
89276 }
89277 }
89278 if( !ExprHasProperty(p, EP_Static) ){
89279 sqlite3DbFree(db, p);
89280 }
 
 
 
89281 }
89282
89283 /*
89284 ** Return the number of bytes allocated for the expression structure
89285 ** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89765,11 @@
89328 static int dupedExprStructSize(Expr *p, int flags){
89329 int nSize;
89330 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
89331 assert( EXPR_FULLSIZE<=0xfff );
89332 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89333 if( 0==(flags&EXPRDUP_REDUCE) ){
89334 nSize = EXPR_FULLSIZE;
89335 }else{
89336 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
89337 assert( !ExprHasProperty(p, EP_FromJoin) );
89338 assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89827,92 @@
89390 ** to store the copy of expression p, the copies of p->u.zToken
89391 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
89392 ** if any. Before returning, *pzBuffer is set to the first byte past the
89393 ** portion of the buffer copied into by this function.
89394 */
89395 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
89396 Expr *pNew = 0; /* Value to return */
89397 assert( flags==0 || flags==EXPRDUP_REDUCE );
 
 
89398 assert( db!=0 );
89399 if( p ){
89400 const int isReduced = (flags&EXPRDUP_REDUCE);
89401 u8 *zAlloc;
89402 u32 staticFlag = 0;
89403
89404 assert( pzBuffer==0 || isReduced );
89405
89406 /* Figure out where to write the new Expr structure. */
89407 if( pzBuffer ){
89408 zAlloc = *pzBuffer;
89409 staticFlag = EP_Static;
89410 }else{
89411 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags));
89412 }
89413 pNew = (Expr *)zAlloc;
89414
89415 if( pNew ){
89416 /* Set nNewSize to the size allocated for the structure pointed to
89417 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89418 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89419 ** by the copy of the p->u.zToken string (if any).
89420 */
89421 const unsigned nStructSize = dupedExprStructSize(p, flags);
89422 const int nNewSize = nStructSize & 0xfff;
89423 int nToken;
89424 if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89425 nToken = sqlite3Strlen30(p->u.zToken) + 1;
89426 }else{
89427 nToken = 0;
89428 }
89429 if( isReduced ){
89430 assert( ExprHasProperty(p, EP_Reduced)==0 );
89431 memcpy(zAlloc, p, nNewSize);
89432 }else{
89433 u32 nSize = (u32)exprStructSize(p);
89434 memcpy(zAlloc, p, nSize);
89435 if( nSize<EXPR_FULLSIZE ){
89436 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89437 }
89438 }
89439
89440 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89441 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89442 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89443 pNew->flags |= staticFlag;
89444
89445 /* Copy the p->u.zToken string, if any. */
89446 if( nToken ){
89447 char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89448 memcpy(zToken, p->u.zToken, nToken);
89449 }
89450
89451 if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89452 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89453 if( ExprHasProperty(p, EP_xIsSelect) ){
89454 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
89455 }else{
89456 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
89457 }
89458 }
89459
89460 /* Fill in pNew->pLeft and pNew->pRight. */
89461 if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89462 zAlloc += dupedExprNodeSize(p, flags);
89463 if( ExprHasProperty(pNew, EP_Reduced) ){
89464 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
89465 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
89466 }
89467 if( pzBuffer ){
89468 *pzBuffer = zAlloc;
89469 }
89470 }else{
89471 if( !ExprHasProperty(p, EP_TokenOnly) ){
89472 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89473 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89474 }
89475 }
89476
89477 }
89478 }
89479 return pNew;
89480 }
89481
@@ -89523,11 +89960,11 @@
89523 ** truncated version of the usual Expr structure that will be stored as
89524 ** part of the in-memory representation of the database schema.
89525 */
89526 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
89527 assert( flags==0 || flags==EXPRDUP_REDUCE );
89528 return exprDup(db, p, flags, 0);
89529 }
89530 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
89531 ExprList *pNew;
89532 struct ExprList_item *pItem, *pOldItem;
89533 int i;
@@ -89745,11 +90182,11 @@
89745 struct ExprList_item *pItem;
89746 assert( pList->nExpr>0 );
89747 pItem = &pList->a[pList->nExpr-1];
89748 assert( pItem->zName==0 );
89749 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
89750 if( dequote && pItem->zName ) sqlite3Dequote(pItem->zName);
89751 }
89752 }
89753
89754 /*
89755 ** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90231,24 @@
89794 }
89795
89796 /*
89797 ** Delete an entire expression list.
89798 */
89799 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
89800 int i;
89801 struct ExprList_item *pItem;
89802 if( pList==0 ) return;
89803 assert( pList->a!=0 || pList->nExpr==0 );
89804 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
89805 sqlite3ExprDelete(db, pItem->pExpr);
89806 sqlite3DbFree(db, pItem->zName);
89807 sqlite3DbFree(db, pItem->zSpan);
89808 }
89809 sqlite3DbFree(db, pList->a);
89810 sqlite3DbFree(db, pList);
 
 
 
89811 }
89812
89813 /*
89814 ** Return the bitwise-OR of all Expr.flags fields in the given
89815 ** ExprList.
@@ -90851,10 +91290,23 @@
90851 #endif
90852 }
90853 }
90854 }
90855
 
 
 
 
 
 
 
 
 
 
 
 
 
90856 /*
90857 ** Clear a cache entry.
90858 */
90859 static void cacheEntryClear(Parse *pParse, struct yColCache *p){
90860 if( p->tempReg ){
@@ -90861,10 +91313,13 @@
90861 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
90862 pParse->aTempReg[pParse->nTempReg++] = p->iReg;
90863 }
90864 p->tempReg = 0;
90865 }
 
 
 
90866 }
90867
90868
90869 /*
90870 ** Record in the column cache that a particular column from a
@@ -90904,10 +91359,12 @@
90904 p->iTable = iTab;
90905 p->iColumn = iCol;
90906 p->iReg = iReg;
90907 p->tempReg = 0;
90908 p->lru = pParse->iCacheCnt++;
 
 
90909 return;
90910 }
90911 }
90912
90913 /* Replace the last recently used */
@@ -90925,28 +91382,27 @@
90925 p->iTable = iTab;
90926 p->iColumn = iCol;
90927 p->iReg = iReg;
90928 p->tempReg = 0;
90929 p->lru = pParse->iCacheCnt++;
 
90930 return;
90931 }
90932 }
90933
90934 /*
90935 ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
90936 ** Purge the range of registers from the column cache.
90937 */
90938 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
90939 int i;
90940 int iLast = iReg + nReg - 1;
90941 struct yColCache *p;
90942 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90943 int r = p->iReg;
90944 if( r>=iReg && r<=iLast ){
90945 cacheEntryClear(pParse, p);
90946 p->iReg = 0;
90947 }
90948 }
90949 }
90950
90951 /*
90952 ** Remember the current column cache context. Any new entries added
@@ -90978,11 +91434,10 @@
90978 }
90979 #endif
90980 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90981 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
90982 cacheEntryClear(pParse, p);
90983 p->iReg = 0;
90984 }
90985 }
90986 }
90987
90988 /*
@@ -91113,11 +91568,10 @@
91113 }
91114 #endif
91115 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91116 if( p->iReg ){
91117 cacheEntryClear(pParse, p);
91118 p->iReg = 0;
91119 }
91120 }
91121 }
91122
91123 /*
@@ -91154,10 +91608,11 @@
91154 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
91155 }
91156 return 0;
91157 }
91158 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
 
91159
91160 /*
91161 ** Convert an expression node to a TK_REGISTER
91162 */
91163 static void exprToRegister(Expr *p, int iReg){
@@ -96951,20 +97406,14 @@
96951 ** contains lookaside memory. (Table objects in the schema do not use
96952 ** lookaside memory, but some ephemeral Table objects do.) Or the
96953 ** db parameter can be used with db->pnBytesFreed to measure the memory
96954 ** used by the Table object.
96955 */
96956 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
96957 Index *pIndex, *pNext;
96958 TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
96959
96960 assert( !pTable || pTable->nRef>0 );
96961
96962 /* Do not delete the table until the reference count reaches zero. */
96963 if( !pTable ) return;
96964 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
96965
96966 /* Record the number of outstanding lookaside allocations in schema Tables
96967 ** prior to doing any free() operations. Since schema Tables do not use
96968 ** lookaside, this number should not change. */
96969 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
96970 db->lookaside.nOut : 0 );
@@ -97000,10 +97449,17 @@
97000 sqlite3DbFree(db, pTable);
97001
97002 /* Verify that no lookaside memory was used by schema tables */
97003 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
97004 }
 
 
 
 
 
 
 
97005
97006 /*
97007 ** Unlink the given table from the hash tables and the delete the
97008 ** table structure with all its indices and foreign keys.
97009 */
@@ -97445,10 +97901,11 @@
97445 pCol->szEst = 1;
97446 }else{
97447 zType = z + sqlite3Strlen30(z) + 1;
97448 memcpy(zType, pType->z, pType->n);
97449 zType[pType->n] = 0;
 
97450 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
97451 pCol->colFlags |= COLFLAG_HASTYPE;
97452 }
97453 p->nCol++;
97454 pParse->constraintName.n = 0;
@@ -98579,11 +99036,11 @@
98579 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
98580 }else{
98581 pTable->nCol = 0;
98582 nErr++;
98583 }
98584 if( pSelTab ) sqlite3DeleteTable(db, pSelTab);
98585 sqlite3SelectDelete(db, pSel);
98586 db->lookaside.bDisable--;
98587 } else {
98588 nErr++;
98589 }
@@ -101410,11 +101867,11 @@
101410
101411 /* Check that there isn't an ORDER BY without a LIMIT clause.
101412 */
101413 if( pOrderBy && (pLimit == 0) ) {
101414 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101415 goto limit_where_cleanup_2;
101416 }
101417
101418 /* We only need to generate a select expression if there
101419 ** is a limit/offset term to enforce.
101420 */
@@ -101432,44 +101889,34 @@
101432 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101433 ** );
101434 */
101435
101436 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101437 if( pSelectRowid == 0 ) goto limit_where_cleanup_2;
101438 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101439 if( pEList == 0 ) goto limit_where_cleanup_2;
101440
101441 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101442 ** and the SELECT subtree. */
101443 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101444 if( pSelectSrc == 0 ) {
101445 sqlite3ExprListDelete(pParse->db, pEList);
101446 goto limit_where_cleanup_2;
101447 }
101448
101449 /* generate the SELECT expression tree. */
101450 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101451 pOrderBy,0,pLimit,pOffset);
101452 if( pSelect == 0 ) return 0;
101453
101454 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101455 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101456 if( pWhereRowid == 0 ) goto limit_where_cleanup_1;
101457 pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
101458 if( pInClause == 0 ) goto limit_where_cleanup_1;
101459
101460 pInClause->x.pSelect = pSelect;
101461 pInClause->flags |= EP_xIsSelect;
101462 sqlite3ExprSetHeightAndFlags(pParse, pInClause);
101463 return pInClause;
101464
101465 /* something went wrong. clean up anything allocated. */
101466 limit_where_cleanup_1:
101467 sqlite3SelectDelete(pParse->db, pSelect);
101468 return 0;
101469
101470 limit_where_cleanup_2:
101471 sqlite3ExprDelete(pParse->db, pWhere);
101472 sqlite3ExprListDelete(pParse->db, pOrderBy);
101473 sqlite3ExprDelete(pParse->db, pLimit);
101474 sqlite3ExprDelete(pParse->db, pOffset);
101475 return 0;
@@ -101516,15 +101963,16 @@
101516 int iEphCur = 0; /* Ephemeral table holding all primary key values */
101517 int iRowSet = 0; /* Register for rowset of rows to delete */
101518 int addrBypass = 0; /* Address of jump over the delete logic */
101519 int addrLoop = 0; /* Top of the delete loop */
101520 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
 
 
101521
101522 #ifndef SQLITE_OMIT_TRIGGER
101523 int isView; /* True if attempting to delete from a view */
101524 Trigger *pTrigger; /* List of table triggers, if required */
101525 int bComplex; /* True if there are either triggers or FKs */
101526 #endif
101527
101528 memset(&sContext, 0, sizeof(sContext));
101529 db = pParse->db;
101530 if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101996,10 @@
101548 isView = pTab->pSelect!=0;
101549 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101550 #else
101551 # define pTrigger 0
101552 # define isView 0
101553 # define bComplex 0
101554 #endif
101555 #ifdef SQLITE_OMIT_VIEW
101556 # undef isView
101557 # define isView 0
101558 #endif
@@ -101650,11 +102097,12 @@
101650 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
101651 }
101652 }else
101653 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
101654 {
101655 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
 
101656 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
101657 if( HasRowid(pTab) ){
101658 /* For a rowid table, initialize the RowSet to an empty set */
101659 pPk = 0;
101660 nPk = 1;
@@ -103561,10 +104009,18 @@
103561 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
103562 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
103563 const char *zProc;
103564 sqlite3 *db = sqlite3_context_db_handle(context);
103565 char *zErrMsg = 0;
 
 
 
 
 
 
 
 
103566
103567 if( argc==2 ){
103568 zProc = (const char *)sqlite3_value_text(argv[1]);
103569 }else{
103570 zProc = 0;
@@ -108756,12 +109212,13 @@
108756 if( pzErrMsg ) *pzErrMsg = 0;
108757
108758 /* Ticket #1863. To avoid a creating security problems for older
108759 ** applications that relink against newer versions of SQLite, the
108760 ** ability to run load_extension is turned off by default. One
108761 ** must call sqlite3_enable_load_extension() to turn on extension
108762 ** loading. Otherwise you get the following error.
 
108763 */
108764 if( (db->flags & SQLITE_LoadExtension)==0 ){
108765 if( pzErrMsg ){
108766 *pzErrMsg = sqlite3_mprintf("not authorized");
108767 }
@@ -108896,13 +109353,13 @@
108896 ** default so as not to open security holes in older applications.
108897 */
108898 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
108899 sqlite3_mutex_enter(db->mutex);
108900 if( onoff ){
108901 db->flags |= SQLITE_LoadExtension;
108902 }else{
108903 db->flags &= ~SQLITE_LoadExtension;
108904 }
108905 sqlite3_mutex_leave(db->mutex);
108906 return SQLITE_OK;
108907 }
108908
@@ -112475,11 +112932,11 @@
112475 sqlite3ExprListDelete(db, p->pGroupBy);
112476 sqlite3ExprDelete(db, p->pHaving);
112477 sqlite3ExprListDelete(db, p->pOrderBy);
112478 sqlite3ExprDelete(db, p->pLimit);
112479 sqlite3ExprDelete(db, p->pOffset);
112480 sqlite3WithDelete(db, p->pWith);
112481 if( bFree ) sqlite3DbFree(db, p);
112482 p = pPrior;
112483 bFree = 1;
112484 }
112485 }
@@ -112570,11 +113027,11 @@
112570
112571 /*
112572 ** Delete the given Select structure and all of its substructures.
112573 */
112574 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
112575 clearSelect(db, p, 1);
112576 }
112577
112578 /*
112579 ** Return a pointer to the right-most SELECT statement in a compound.
112580 */
@@ -114190,23 +114647,23 @@
114190
114191 /*
114192 ** Get a VDBE for the given parser context. Create a new one if necessary.
114193 ** If an error occurs, return NULL and leave a message in pParse.
114194 */
114195 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114196 Vdbe *v = pParse->pVdbe;
114197 if( v==0 ){
114198 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114199 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114200 if( pParse->pToplevel==0
114201 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114202 ){
114203 pParse->okConstFactor = 1;
114204 }
114205
114206 }
114207 return v;
 
 
 
 
114208 }
114209
114210
114211 /*
114212 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116643,22 @@
116186 Expr *pWhere, /* The WHERE clause of the outer query */
116187 int iCursor /* Cursor number of the subquery */
116188 ){
116189 Expr *pNew;
116190 int nChng = 0;
 
116191 if( pWhere==0 ) return 0;
116192 if( (pSubq->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116193 return 0; /* restrictions (1) and (2) */
 
 
 
 
 
116194 }
116195 if( pSubq->pLimit!=0 ){
116196 return 0; /* restriction (3) */
116197 }
116198 while( pWhere->op==TK_AND ){
116199 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116200 pWhere = pWhere->pLeft;
116201 }
@@ -117493,10 +117956,17 @@
117493 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117494 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117495 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
117496 ** original setting of the SF_Distinct flag, not the current setting */
117497 assert( sDistinct.isTnct );
 
 
 
 
 
 
 
117498 }
117499
117500 /* If there is an ORDER BY clause, then create an ephemeral index to
117501 ** do the sorting. But this sorting ephemeral index might end up
117502 ** being unused if the data can be extracted in pre-sorted order.
@@ -119731,11 +120201,12 @@
119731 /* Begin the database scan
119732 */
119733 if( HasRowid(pTab) ){
119734 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
119735 pWInfo = sqlite3WhereBegin(
119736 pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur
 
119737 );
119738 if( pWInfo==0 ) goto update_cleanup;
119739 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
119740
119741 /* Remember the rowid of every item to be updated.
@@ -121888,11 +122359,11 @@
121888 int addrSkip; /* Jump here for next iteration of skip-scan */
121889 int addrCont; /* Jump here to continue with the next loop cycle */
121890 int addrFirst; /* First instruction of interior of the loop */
121891 int addrBody; /* Beginning of the body of this loop */
121892 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
121893 int iLikeRepCntr; /* LIKE range processing counter register */
121894 int addrLikeRep; /* LIKE range processing address */
121895 #endif
121896 u8 iFrom; /* Which entry in the FROM clause */
121897 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
121898 int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122697,11 @@
122226 */
122227 struct WhereInfo {
122228 Parse *pParse; /* Parsing and code generating context */
122229 SrcList *pTabList; /* List of tables in the join */
122230 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122231 ExprList *pResultSet; /* Result set. DISTINCT operates on these */
122232 WhereLoop *pLoops; /* List of all WhereLoop objects */
122233 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122234 LogEst nRowOut; /* Estimated number of output rows */
122235 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122236 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122781,18 @@
122310 /*
122311 ** Bitmasks for the operators on WhereTerm objects. These are all
122312 ** operators that are of interest to the query planner. An
122313 ** OR-ed combination of these values can be used when searching for
122314 ** particular WhereTerms within a WhereClause.
 
 
 
 
 
 
 
 
122315 */
122316 #define WO_IN 0x0001
122317 #define WO_EQ 0x0002
122318 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122319 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123375,14 @@
122896 return regBase;
122897 }
122898
122899 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122900 /*
122901 ** If the most recently coded instruction is a constant range contraint
122902 ** that originated from the LIKE optimization, then change the P3 to be
122903 ** pLoop->iLikeRepCntr and set P5.
 
122904 **
122905 ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
122906 ** expression: "x>='ABC' AND x<'abd'". But this requires that the range
122907 ** scan loop run twice, once for strings and a second time for BLOBs.
122908 ** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123403,12 @@
122923 assert( pLevel->iLikeRepCntr>0 );
122924 pOp = sqlite3VdbeGetOp(v, -1);
122925 assert( pOp!=0 );
122926 assert( pOp->opcode==OP_String8
122927 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
122928 pOp->p3 = pLevel->iLikeRepCntr;
122929 pOp->p5 = 1;
122930 }
122931 }
122932 #else
122933 # define whereLikeOptimizationStringFixup(A,B,C)
122934 #endif
@@ -123277,11 +123757,17 @@
123277 pCompare->pLeft = 0;
123278 sqlite3ExprDelete(db, pCompare);
123279 }
123280 }
123281 }
123282 sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
 
 
 
 
 
 
123283 sqlite3ExprCachePop(pParse);
123284 }else
123285 #endif /* SQLITE_OMIT_VIRTUALTABLE */
123286
123287 if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123991,21 @@
123505 nExtraReg = 1;
123506 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123507 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123508 assert( pRangeStart!=0 ); /* LIKE opt constraints */
123509 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123510 pLevel->iLikeRepCntr = ++pParse->nMem;
 
 
 
 
 
123511 testcase( bRev );
123512 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
123513 sqlite3VdbeAddOp2(v, OP_Integer,
123514 bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
123515 pLevel->iLikeRepCntr);
123516 VdbeComment((v, "LIKE loop counter"));
123517 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
123518 }
123519 #endif
123520 if( pRangeStart==0
123521 && (j = pIdx->aiColumn[nEq])>=0
123522 && pIdx->pTable->aCol[j].notNull==0
@@ -123650,11 +124139,11 @@
123650 disableTerm(pLevel, pRangeStart);
123651 disableTerm(pLevel, pRangeEnd);
123652 if( omitTable ){
123653 /* pIdx is a covering index. No need to access the main table. */
123654 }else if( HasRowid(pIdx->pTable) ){
123655 if( pWInfo->eOnePass!=ONEPASS_OFF ){
123656 iRowidReg = ++pParse->nMem;
123657 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
123658 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
123659 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
123660 VdbeCoverage(v);
@@ -123846,11 +124335,12 @@
123846 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
123847 */
123848 wctrlFlags = WHERE_OMIT_OPEN_CLOSE
123849 | WHERE_FORCE_TABLE
123850 | WHERE_ONETABLE_ONLY
123851 | WHERE_NO_AUTOINDEX;
 
123852 for(ii=0; ii<pOrWc->nTerm; ii++){
123853 WhereTerm *pOrTerm = &pOrWc->a[ii];
123854 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
123855 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
123856 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -124026,15 +124516,21 @@
124026 assert( pE!=0 );
124027 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124028 continue;
124029 }
124030 if( pTerm->wtFlags & TERM_LIKECOND ){
 
 
 
 
 
124031 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124032 continue;
124033 #else
124034 assert( pLevel->iLikeRepCntr>0 );
124035 skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
 
124036 VdbeCoverage(v);
124037 #endif
124038 }
124039 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124040 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125882,14 @@
125386 if( p->op==TK_COLUMN ){
125387 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125388 return mask;
125389 }
125390 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125391 mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125392 if( ExprHasProperty(p, EP_xIsSelect) ){
125393 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125394 }else{
125395 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125396 }
125397 return mask;
125398 }
125399 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -125729,11 +126225,14 @@
125729 ** Initialize a WHERE clause scanner object. Return a pointer to the
125730 ** first match. Return NULL if there are no matches.
125731 **
125732 ** The scanner will be searching the WHERE clause pWC. It will look
125733 ** for terms of the form "X <op> <expr>" where X is column iColumn of table
125734 ** iCur. The <op> must be one of the operators described by opMask.
 
 
 
125735 **
125736 ** If the search is for X and the WHERE clause contains terms of the
125737 ** form X=Y then this routine might also return terms of the form
125738 ** "Y <op> <expr>". The number of levels of transitivity is limited,
125739 ** but is enough to handle most commonly occurring SQL statements.
@@ -125777,15 +126276,16 @@
125777 return whereScanNext(pScan);
125778 }
125779
125780 /*
125781 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
125782 ** where X is a reference to the iColumn of table iCur and <op> is one of
125783 ** the WO_xx operator codes specified by the op parameter.
125784 ** Return a pointer to the term. Return 0 if not found.
125785 **
125786 ** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx
 
125787 ** rather than the iColumn-th column of table iCur.
125788 **
125789 ** The term returned might by Y=<expr> if there is another constraint in
125790 ** the WHERE clause that specifies that X=Y. Any such constraints will be
125791 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
@@ -127119,15 +127619,16 @@
127119 /*
127120 ** Print a WhereLoop object for debugging purposes
127121 */
127122 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127123 WhereInfo *pWInfo = pWC->pWInfo;
127124 int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
127125 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127126 Table *pTab = pItem->pTab;
 
127127 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127128 p->iTab, nb, p->maskSelf, nb, p->prereq);
127129 sqlite3DebugPrintf(" %12s",
127130 pItem->zAlias ? pItem->zAlias : pTab->zName);
127131 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127132 const char *zName;
127133 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129849,13 @@
129348 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129349 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129350 && nRowEst
129351 ){
129352 Bitmask notUsed;
129353 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
129354 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129355 if( rc==pWInfo->pResultSet->nExpr ){
129356 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129357 }
129358 }
129359 if( pWInfo->pOrderBy ){
129360 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +130066,18 @@
129565 ** the first cursor in an array of cursors for all indices. iIdxCur should
129566 ** be used to compute the appropriate cursor depending on which index is
129567 ** used.
129568 */
129569 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
129570 Parse *pParse, /* The parser context */
129571 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129572 Expr *pWhere, /* The WHERE clause */
129573 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129574 ExprList *pResultSet, /* Result set of the query */
129575 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
129576 int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number,
129577 ** If WHERE_USE_LIMIT, then the limit amount */
129578 ){
129579 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
129580 int nTabList; /* Number of elements in pTabList */
129581 WhereInfo *pWInfo; /* Will become the return value of this function */
129582 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +130148,11 @@
129647 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
129648 pWInfo->nLevel = nTabList;
129649 pWInfo->pParse = pParse;
129650 pWInfo->pTabList = pTabList;
129651 pWInfo->pOrderBy = pOrderBy;
129652 pWInfo->pResultSet = pResultSet;
129653 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
129654 pWInfo->wctrlFlags = wctrlFlags;
129655 pWInfo->iLimit = iAuxArg;
129656 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
129657 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130221,17 @@
129720 /* Analyze all of the subexpressions. */
129721 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
129722 if( db->mallocFailed ) goto whereBeginError;
129723
129724 if( wctrlFlags & WHERE_WANT_DISTINCT ){
129725 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
129726 /* The DISTINCT marking is pointless. Ignore it. */
129727 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
129728 }else if( pOrderBy==0 ){
129729 /* Try to ORDER BY the result set to make distinct processing easier */
129730 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
129731 pWInfo->pOrderBy = pResultSet;
129732 }
129733 }
129734
129735 /* Construct the WhereLoop objects */
129736 #if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130306,14 @@
129805 }
129806 }
129807 #endif
129808 /* Attempt to omit tables from the join that do not effect the result */
129809 if( pWInfo->nLevel>=2
129810 && pResultSet!=0
129811 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
129812 ){
129813 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
129814 if( sWLB.pOrderBy ){
129815 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
129816 }
129817 while( pWInfo->nLevel>=2 ){
129818 WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130575,12 @@
130074 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130075 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130076 }
130077 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130078 if( pLevel->addrLikeRep ){
130079 int op;
130080 if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
130081 op = OP_DecrJumpZero;
130082 }else{
130083 op = OP_JumpZeroIncr;
130084 }
130085 sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
130086 VdbeCoverage(v);
130087 }
130088 #endif
130089 if( pLevel->iLeftJoin ){
130090 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130982,11 @@
130486 #endif
130487 /************* Begin control #defines *****************************************/
130488 #define YYCODETYPE unsigned char
130489 #define YYNOCODE 251
130490 #define YYACTIONTYPE unsigned short int
130491 #define YYWILDCARD 70
130492 #define sqlite3ParserTOKENTYPE Token
130493 typedef union {
130494 int yyinit;
130495 sqlite3ParserTOKENTYPE yy0;
130496 struct LimitVal yy64;
@@ -130590,402 +131086,404 @@
130590 ** yy_reduce_ofst[] For each state, the offset into yy_action for
130591 ** shifting non-terminals after a reduce.
130592 ** yy_default[] Default action for each state.
130593 **
130594 *********** Begin parsing tables **********************************************/
130595 #define YY_ACTTAB_COUNT (1499)
130596 static const YYACTIONTYPE yy_action[] = {
130597 /* 0 */ 315, 1302, 146, 921, 2, 194, 922, 342, 952, 91,
130598 /* 10 */ 91, 91, 91, 84, 89, 89, 89, 89, 88, 88,
130599 /* 20 */ 87, 87, 87, 86, 339, 87, 87, 87, 86, 339,
130600 /* 30 */ 331, 819, 819, 91, 91, 91, 91, 339, 89, 89,
130601 /* 40 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 319,
130602 /* 50 */ 933, 933, 92, 93, 83, 831, 834, 823, 823, 90,
130603 /* 60 */ 90, 91, 91, 91, 91, 123, 89, 89, 89, 89,
130604 /* 70 */ 88, 88, 87, 87, 87, 86, 339, 315, 952, 89,
130605 /* 80 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130606 /* 90 */ 365, 772, 360, 24, 933, 933, 947, 694, 933, 933,
130607 /* 100 */ 773, 937, 933, 933, 434, 715, 328, 434, 819, 819,
130608 /* 110 */ 203, 160, 278, 391, 273, 390, 190, 933, 933, 370,
130609 /* 120 */ 934, 935, 367, 271, 953, 48, 679, 953, 48, 92,
130610 /* 130 */ 93, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130611 /* 140 */ 91, 91, 123, 89, 89, 89, 89, 88, 88, 87,
130612 /* 150 */ 87, 87, 86, 339, 315, 682, 337, 336, 218, 412,
130613 /* 160 */ 398, 68, 412, 403, 934, 935, 743, 959, 934, 935,
130614 /* 170 */ 810, 937, 934, 935, 957, 221, 958, 88, 88, 87,
130615 /* 180 */ 87, 87, 86, 339, 291, 819, 819, 934, 935, 185,
130616 /* 190 */ 94, 792, 388, 385, 384, 1240, 1240, 792, 804, 960,
130617 /* 200 */ 960, 290, 798, 383, 123, 315, 92, 93, 83, 831,
130618 /* 210 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130619 /* 220 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130620 /* 230 */ 339, 681, 741, 803, 803, 803, 819, 819, 944, 56,
130621 /* 240 */ 253, 353, 242, 85, 82, 168, 253, 358, 252, 110,
130622 /* 250 */ 96, 233, 397, 698, 677, 683, 683, 92, 93, 83,
130623 /* 260 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130624 /* 270 */ 433, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130625 /* 280 */ 86, 339, 315, 434, 439, 651, 396, 57, 733, 733,
130626 /* 290 */ 234, 291, 107, 287, 395, 86, 339, 810, 427, 728,
130627 /* 300 */ 933, 933, 185, 953, 30, 388, 385, 384, 215, 949,
130628 /* 310 */ 434, 933, 933, 819, 819, 697, 383, 162, 161, 407,
130629 /* 320 */ 400, 85, 82, 168, 677, 804, 335, 113, 771, 798,
130630 /* 330 */ 953, 48, 22, 351, 92, 93, 83, 831, 834, 823,
130631 /* 340 */ 823, 90, 90, 91, 91, 91, 91, 870, 89, 89,
130632 /* 350 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 315,
130633 /* 360 */ 803, 803, 803, 268, 123, 412, 394, 1, 933, 933,
130634 /* 370 */ 934, 935, 933, 933, 85, 82, 168, 232, 5, 343,
130635 /* 380 */ 194, 934, 935, 952, 85, 82, 168, 54, 956, 434,
130636 /* 390 */ 819, 819, 431, 938, 939, 792, 67, 759, 350, 144,
130637 /* 400 */ 166, 770, 123, 896, 889, 955, 348, 288, 758, 953,
130638 /* 410 */ 47, 92, 93, 83, 831, 834, 823, 823, 90, 90,
130639 /* 420 */ 91, 91, 91, 91, 892, 89, 89, 89, 89, 88,
130640 /* 430 */ 88, 87, 87, 87, 86, 339, 315, 113, 934, 935,
130641 /* 440 */ 687, 893, 934, 935, 253, 358, 252, 85, 82, 168,
130642 /* 450 */ 820, 820, 956, 952, 338, 938, 939, 894, 701, 721,
130643 /* 460 */ 359, 289, 233, 397, 434, 349, 434, 819, 819, 955,
130644 /* 470 */ 866, 722, 23, 389, 832, 835, 692, 357, 904, 667,
130645 /* 480 */ 194, 702, 402, 952, 953, 48, 953, 48, 92, 93,
130646 /* 490 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130647 /* 500 */ 91, 824, 89, 89, 89, 89, 88, 88, 87, 87,
130648 /* 510 */ 87, 86, 339, 315, 434, 113, 434, 680, 434, 332,
130649 /* 520 */ 434, 408, 889, 356, 380, 940, 401, 720, 948, 864,
130650 /* 530 */ 191, 165, 329, 689, 953, 9, 953, 9, 953, 9,
130651 /* 540 */ 953, 9, 718, 948, 819, 819, 953, 8, 325, 111,
130652 /* 550 */ 327, 153, 224, 952, 410, 113, 189, 337, 336, 913,
130653 /* 560 */ 1295, 852, 75, 1295, 73, 92, 93, 83, 831, 834,
130654 /* 570 */ 823, 823, 90, 90, 91, 91, 91, 91, 359, 89,
130655 /* 580 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130656 /* 590 */ 315, 730, 148, 236, 797, 366, 789, 892, 1179, 434,
130657 /* 600 */ 960, 960, 400, 148, 314, 212, 873, 911, 757, 404,
130658 /* 610 */ 872, 300, 320, 434, 893, 311, 237, 271, 405, 953,
130659 /* 620 */ 34, 819, 819, 225, 371, 945, 360, 913, 1296, 113,
130660 /* 630 */ 894, 1296, 417, 953, 35, 1245, 922, 342, 259, 247,
130661 /* 640 */ 290, 315, 92, 93, 83, 831, 834, 823, 823, 90,
130662 /* 650 */ 90, 91, 91, 91, 91, 148, 89, 89, 89, 89,
130663 /* 660 */ 88, 88, 87, 87, 87, 86, 339, 310, 434, 796,
130664 /* 670 */ 434, 240, 819, 819, 266, 911, 876, 876, 373, 346,
130665 /* 680 */ 167, 654, 655, 656, 259, 244, 19, 246, 953, 11,
130666 /* 690 */ 953, 26, 222, 92, 93, 83, 831, 834, 823, 823,
130667 /* 700 */ 90, 90, 91, 91, 91, 91, 757, 89, 89, 89,
130668 /* 710 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 434,
130669 /* 720 */ 261, 434, 264, 696, 434, 241, 434, 344, 971, 308,
130670 /* 730 */ 757, 434, 796, 434, 324, 434, 393, 423, 434, 953,
130671 /* 740 */ 36, 953, 37, 20, 953, 38, 953, 27, 434, 819,
130672 /* 750 */ 819, 953, 28, 953, 39, 953, 40, 738, 953, 41,
130673 /* 760 */ 71, 738, 737, 245, 307, 973, 737, 259, 953, 10,
130674 /* 770 */ 92, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130675 /* 780 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130676 /* 790 */ 87, 87, 87, 86, 339, 315, 434, 372, 434, 259,
130677 /* 800 */ 149, 434, 167, 953, 42, 188, 187, 186, 219, 434,
130678 /* 810 */ 748, 434, 974, 434, 796, 434, 953, 98, 953, 43,
130679 /* 820 */ 862, 953, 44, 434, 920, 2, 819, 819, 757, 953,
130680 /* 830 */ 31, 953, 45, 953, 46, 953, 32, 74, 307, 912,
130681 /* 840 */ 220, 259, 259, 953, 115, 909, 315, 92, 93, 83,
130682 /* 850 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130683 /* 860 */ 434, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130684 /* 870 */ 86, 339, 434, 248, 434, 215, 949, 819, 819, 333,
130685 /* 880 */ 953, 116, 895, 860, 176, 259, 974, 400, 361, 259,
130686 /* 890 */ 951, 887, 953, 117, 953, 52, 884, 315, 92, 93,
130687 /* 900 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130688 /* 910 */ 91, 434, 89, 89, 89, 89, 88, 88, 87, 87,
130689 /* 920 */ 87, 86, 339, 434, 113, 434, 258, 883, 819, 819,
130690 /* 930 */ 727, 953, 33, 363, 259, 673, 321, 189, 430, 321,
130691 /* 940 */ 368, 365, 364, 953, 99, 953, 49, 365, 315, 92,
130692 /* 950 */ 81, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130693 /* 960 */ 91, 91, 434, 89, 89, 89, 89, 88, 88, 87,
130694 /* 970 */ 87, 87, 86, 339, 434, 723, 434, 214, 165, 819,
130695 /* 980 */ 819, 772, 953, 100, 322, 124, 1269, 158, 65, 710,
130696 /* 990 */ 773, 700, 699, 320, 953, 101, 953, 97, 255, 315,
130697 /* 1000 */ 216, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130698 /* 1010 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130699 /* 1020 */ 87, 87, 87, 86, 339, 434, 251, 434, 707, 708,
130700 /* 1030 */ 819, 819, 223, 953, 114, 908, 794, 254, 309, 193,
130701 /* 1040 */ 67, 381, 869, 869, 199, 953, 112, 953, 105, 269,
130702 /* 1050 */ 726, 260, 67, 83, 831, 834, 823, 823, 90, 90,
130703 /* 1060 */ 91, 91, 91, 91, 263, 89, 89, 89, 89, 88,
130704 /* 1070 */ 88, 87, 87, 87, 86, 339, 79, 429, 690, 3,
130705 /* 1080 */ 1174, 228, 434, 113, 340, 340, 868, 868, 265, 79,
130706 /* 1090 */ 429, 735, 3, 859, 70, 432, 434, 340, 340, 434,
130707 /* 1100 */ 1259, 434, 953, 104, 434, 670, 416, 766, 432, 434,
130708 /* 1110 */ 193, 434, 413, 434, 418, 806, 953, 102, 420, 953,
130709 /* 1120 */ 103, 953, 48, 123, 953, 51, 810, 418, 424, 953,
130710 /* 1130 */ 53, 953, 50, 953, 25, 267, 123, 711, 113, 810,
130711 /* 1140 */ 428, 277, 695, 272, 764, 113, 76, 77, 690, 434,
130712 /* 1150 */ 795, 113, 276, 78, 436, 435, 412, 414, 798, 76,
130713 /* 1160 */ 77, 113, 855, 859, 376, 199, 78, 436, 435, 953,
130714 /* 1170 */ 29, 798, 744, 113, 755, 79, 429, 675, 3, 415,
130715 /* 1180 */ 109, 292, 293, 340, 340, 806, 802, 678, 672, 803,
130716 /* 1190 */ 803, 803, 805, 18, 432, 661, 660, 662, 927, 209,
130717 /* 1200 */ 150, 352, 803, 803, 803, 805, 18, 6, 306, 280,
130718 /* 1210 */ 282, 284, 786, 418, 250, 386, 243, 886, 694, 362,
130719 /* 1220 */ 286, 163, 275, 79, 429, 810, 3, 857, 856, 159,
130720 /* 1230 */ 419, 340, 340, 298, 930, 968, 126, 196, 965, 903,
130721 /* 1240 */ 901, 323, 432, 136, 55, 76, 77, 742, 147, 58,
130722 /* 1250 */ 121, 129, 78, 436, 435, 65, 783, 798, 354, 131,
130723 /* 1260 */ 355, 418, 379, 132, 133, 134, 175, 139, 151, 369,
130724 /* 1270 */ 888, 180, 791, 810, 61, 851, 871, 69, 429, 375,
130725 /* 1280 */ 3, 756, 210, 257, 181, 340, 340, 145, 803, 803,
130726 /* 1290 */ 803, 805, 18, 76, 77, 377, 432, 262, 182, 183,
130727 /* 1300 */ 78, 436, 435, 663, 312, 798, 392, 714, 713, 712,
130728 /* 1310 */ 330, 705, 692, 313, 704, 418, 686, 406, 752, 685,
130729 /* 1320 */ 274, 684, 942, 64, 279, 195, 281, 810, 753, 839,
130730 /* 1330 */ 751, 283, 72, 750, 285, 422, 803, 803, 803, 805,
130731 /* 1340 */ 18, 334, 426, 95, 411, 229, 409, 76, 77, 230,
130732 /* 1350 */ 734, 66, 231, 294, 78, 436, 435, 204, 295, 798,
130733 /* 1360 */ 217, 296, 297, 669, 21, 305, 304, 303, 206, 301,
130734 /* 1370 */ 437, 928, 664, 205, 208, 207, 438, 658, 657, 652,
130735 /* 1380 */ 118, 108, 119, 226, 650, 341, 157, 170, 169, 239,
130736 /* 1390 */ 803, 803, 803, 805, 18, 125, 120, 235, 238, 317,
130737 /* 1400 */ 318, 345, 106, 790, 867, 127, 865, 128, 130, 724,
130738 /* 1410 */ 249, 172, 174, 882, 135, 137, 59, 138, 173, 60,
130739 /* 1420 */ 885, 123, 171, 177, 178, 881, 7, 12, 179, 256,
130740 /* 1430 */ 874, 140, 193, 962, 374, 141, 666, 152, 378, 276,
130741 /* 1440 */ 184, 382, 142, 122, 62, 13, 387, 703, 270, 14,
130742 /* 1450 */ 63, 227, 809, 808, 837, 732, 15, 841, 736, 4,
130743 /* 1460 */ 765, 211, 399, 164, 213, 143, 760, 201, 70, 316,
130744 /* 1470 */ 67, 838, 836, 891, 198, 192, 16, 197, 890, 917,
130745 /* 1480 */ 154, 17, 202, 421, 918, 155, 200, 156, 425, 840,
130746 /* 1490 */ 807, 1261, 676, 80, 302, 299, 347, 1260, 923,
 
130747 };
130748 static const YYCODETYPE yy_lookahead[] = {
130749 /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
130750 /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
130751 /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
130752 /* 30 */ 19, 50, 51, 80, 81, 82, 83, 95, 85, 86,
130753 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 157,
130754 /* 50 */ 27, 28, 71, 72, 73, 74, 75, 76, 77, 78,
130755 /* 60 */ 79, 80, 81, 82, 83, 66, 85, 86, 87, 88,
130756 /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
130757 /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130758 /* 90 */ 152, 33, 152, 22, 27, 28, 179, 180, 27, 28,
130759 /* 100 */ 42, 27, 27, 28, 152, 188, 95, 152, 50, 51,
130760 /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 227,
130761 /* 120 */ 97, 98, 230, 112, 172, 173, 172, 172, 173, 71,
130762 /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130763 /* 140 */ 82, 83, 66, 85, 86, 87, 88, 89, 90, 91,
130764 /* 150 */ 92, 93, 94, 95, 19, 172, 89, 90, 218, 207,
130765 /* 160 */ 208, 26, 207, 208, 97, 98, 91, 100, 97, 98,
130766 /* 170 */ 69, 97, 97, 98, 107, 237, 109, 89, 90, 91,
130767 /* 180 */ 92, 93, 94, 95, 152, 50, 51, 97, 98, 99,
130768 /* 190 */ 55, 59, 102, 103, 104, 119, 120, 59, 97, 132,
130769 /* 200 */ 133, 152, 101, 113, 66, 19, 71, 72, 73, 74,
130770 /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 187,
130771 /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
130772 /* 230 */ 95, 172, 210, 132, 133, 134, 50, 51, 185, 53,
130773 /* 240 */ 108, 109, 110, 221, 222, 223, 108, 109, 110, 22,
130774 /* 250 */ 22, 119, 120, 181, 27, 27, 28, 71, 72, 73,
130775 /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130776 /* 270 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130777 /* 280 */ 94, 95, 19, 152, 148, 149, 115, 24, 117, 118,
130778 /* 290 */ 154, 152, 156, 152, 163, 94, 95, 69, 249, 163,
130779 /* 300 */ 27, 28, 99, 172, 173, 102, 103, 104, 194, 195,
130780 /* 310 */ 152, 27, 28, 50, 51, 181, 113, 89, 90, 152,
130781 /* 320 */ 206, 221, 222, 223, 97, 97, 187, 196, 175, 101,
130782 /* 330 */ 172, 173, 196, 219, 71, 72, 73, 74, 75, 76,
130783 /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
130784 /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
130785 /* 360 */ 132, 133, 134, 23, 66, 207, 208, 22, 27, 28,
130786 /* 370 */ 97, 98, 27, 28, 221, 222, 223, 199, 22, 243,
130787 /* 380 */ 24, 97, 98, 27, 221, 222, 223, 209, 152, 152,
130788 /* 390 */ 50, 51, 168, 169, 170, 59, 26, 124, 100, 58,
130789 /* 400 */ 152, 175, 66, 240, 163, 169, 170, 152, 124, 172,
130790 /* 410 */ 173, 71, 72, 73, 74, 75, 76, 77, 78, 79,
130791 /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
130792 /* 430 */ 90, 91, 92, 93, 94, 95, 19, 196, 97, 98,
130793 /* 440 */ 23, 29, 97, 98, 108, 109, 110, 221, 222, 223,
130794 /* 450 */ 50, 51, 152, 97, 168, 169, 170, 45, 37, 47,
130795 /* 460 */ 219, 224, 119, 120, 152, 229, 152, 50, 51, 169,
130796 /* 470 */ 170, 59, 231, 52, 74, 75, 106, 236, 152, 21,
130797 /* 480 */ 24, 60, 163, 27, 172, 173, 172, 173, 71, 72,
130798 /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130799 /* 500 */ 83, 101, 85, 86, 87, 88, 89, 90, 91, 92,
130800 /* 510 */ 93, 94, 95, 19, 152, 196, 152, 23, 152, 207,
130801 /* 520 */ 152, 207, 163, 65, 19, 171, 152, 190, 191, 229,
130802 /* 530 */ 211, 212, 111, 179, 172, 173, 172, 173, 172, 173,
130803 /* 540 */ 172, 173, 190, 191, 50, 51, 172, 173, 186, 22,
130804 /* 550 */ 186, 24, 186, 97, 186, 196, 51, 89, 90, 22,
130805 /* 560 */ 23, 103, 137, 26, 139, 71, 72, 73, 74, 75,
130806 /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 219, 85,
130807 /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130808 /* 590 */ 19, 195, 152, 152, 23, 236, 163, 12, 140, 152,
130809 /* 600 */ 132, 133, 206, 152, 164, 23, 31, 70, 26, 19,
130810 /* 610 */ 35, 160, 107, 152, 29, 164, 152, 112, 28, 172,
130811 /* 620 */ 173, 50, 51, 183, 49, 185, 152, 22, 23, 196,
130812 /* 630 */ 45, 26, 47, 172, 173, 0, 1, 2, 152, 16,
130813 /* 640 */ 152, 19, 71, 72, 73, 74, 75, 76, 77, 78,
130814 /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
130815 /* 660 */ 89, 90, 91, 92, 93, 94, 95, 164, 152, 152,
130816 /* 670 */ 152, 152, 50, 51, 16, 70, 108, 109, 110, 193,
130817 /* 680 */ 98, 7, 8, 9, 152, 62, 22, 64, 172, 173,
130818 /* 690 */ 172, 173, 218, 71, 72, 73, 74, 75, 76, 77,
130819 /* 700 */ 78, 79, 80, 81, 82, 83, 124, 85, 86, 87,
130820 /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
130821 /* 720 */ 62, 152, 64, 181, 152, 193, 152, 241, 246, 247,
130822 /* 730 */ 26, 152, 152, 152, 217, 152, 91, 249, 152, 172,
130823 /* 740 */ 173, 172, 173, 79, 172, 173, 172, 173, 152, 50,
130824 /* 750 */ 51, 172, 173, 172, 173, 172, 173, 116, 172, 173,
130825 /* 760 */ 138, 116, 121, 140, 22, 23, 121, 152, 172, 173,
130826 /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130827 /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130828 /* 790 */ 91, 92, 93, 94, 95, 19, 152, 217, 152, 152,
130829 /* 800 */ 24, 152, 98, 172, 173, 108, 109, 110, 193, 152,
130830 /* 810 */ 213, 152, 70, 152, 152, 152, 172, 173, 172, 173,
130831 /* 820 */ 152, 172, 173, 152, 146, 147, 50, 51, 124, 172,
130832 /* 830 */ 173, 172, 173, 172, 173, 172, 173, 138, 22, 23,
130833 /* 840 */ 193, 152, 152, 172, 173, 152, 19, 71, 72, 73,
130834 /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130835 /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130836 /* 870 */ 94, 95, 152, 152, 152, 194, 195, 50, 51, 217,
130837 /* 880 */ 172, 173, 193, 193, 26, 152, 70, 206, 152, 152,
130838 /* 890 */ 26, 163, 172, 173, 172, 173, 152, 19, 71, 72,
130839 /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130840 /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
130841 /* 920 */ 93, 94, 95, 152, 196, 152, 193, 152, 50, 51,
130842 /* 930 */ 193, 172, 173, 19, 152, 166, 167, 51, 166, 167,
130843 /* 940 */ 152, 152, 28, 172, 173, 172, 173, 152, 19, 71,
130844 /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130845 /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
130846 /* 970 */ 92, 93, 94, 95, 152, 193, 152, 211, 212, 50,
130847 /* 980 */ 51, 33, 172, 173, 244, 245, 23, 123, 130, 26,
130848 /* 990 */ 42, 100, 101, 107, 172, 173, 172, 173, 152, 19,
130849 /* 1000 */ 22, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130850 /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130851 /* 1020 */ 91, 92, 93, 94, 95, 152, 237, 152, 7, 8,
130852 /* 1030 */ 50, 51, 237, 172, 173, 23, 23, 23, 26, 26,
130853 /* 1040 */ 26, 23, 132, 133, 26, 172, 173, 172, 173, 23,
130854 /* 1050 */ 163, 152, 26, 73, 74, 75, 76, 77, 78, 79,
130855 /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
130856 /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 27, 22,
130857 /* 1080 */ 23, 210, 152, 196, 27, 28, 132, 133, 152, 19,
130858 /* 1090 */ 20, 23, 22, 27, 26, 38, 152, 27, 28, 152,
130859 /* 1100 */ 122, 152, 172, 173, 152, 163, 191, 23, 38, 152,
130860 /* 1110 */ 26, 152, 163, 152, 57, 27, 172, 173, 163, 172,
130861 /* 1120 */ 173, 172, 173, 66, 172, 173, 69, 57, 163, 172,
130862 /* 1130 */ 173, 172, 173, 172, 173, 152, 66, 152, 196, 69,
130863 /* 1140 */ 163, 101, 152, 152, 152, 196, 89, 90, 97, 152,
130864 /* 1150 */ 152, 196, 112, 96, 97, 98, 207, 208, 101, 89,
130865 /* 1160 */ 90, 196, 23, 97, 233, 26, 96, 97, 98, 172,
130866 /* 1170 */ 173, 101, 152, 196, 152, 19, 20, 23, 22, 152,
130867 /* 1180 */ 26, 152, 152, 27, 28, 97, 152, 152, 152, 132,
130868 /* 1190 */ 133, 134, 135, 136, 38, 152, 152, 152, 152, 232,
130869 /* 1200 */ 197, 214, 132, 133, 134, 135, 136, 198, 150, 210,
130870 /* 1210 */ 210, 210, 201, 57, 238, 176, 214, 201, 180, 238,
130871 /* 1220 */ 214, 184, 175, 19, 20, 69, 22, 175, 175, 198,
130872 /* 1230 */ 226, 27, 28, 200, 155, 39, 242, 122, 41, 159,
130873 /* 1240 */ 159, 159, 38, 22, 239, 89, 90, 91, 220, 239,
130874 /* 1250 */ 71, 189, 96, 97, 98, 130, 201, 101, 18, 192,
130875 /* 1260 */ 159, 57, 18, 192, 192, 192, 158, 189, 220, 159,
130876 /* 1270 */ 201, 158, 189, 69, 137, 201, 235, 19, 20, 46,
130877 /* 1280 */ 22, 159, 159, 234, 158, 27, 28, 22, 132, 133,
130878 /* 1290 */ 134, 135, 136, 89, 90, 177, 38, 159, 158, 158,
130879 /* 1300 */ 96, 97, 98, 159, 177, 101, 107, 174, 174, 174,
130880 /* 1310 */ 48, 182, 106, 177, 182, 57, 174, 125, 216, 176,
130881 /* 1320 */ 174, 174, 174, 107, 215, 159, 215, 69, 216, 159,
130882 /* 1330 */ 216, 215, 137, 216, 215, 177, 132, 133, 134, 135,
130883 /* 1340 */ 136, 95, 177, 129, 126, 225, 127, 89, 90, 228,
130884 /* 1350 */ 205, 128, 228, 204, 96, 97, 98, 25, 203, 101,
130885 /* 1360 */ 5, 202, 201, 162, 26, 10, 11, 12, 13, 14,
130886 /* 1370 */ 161, 13, 17, 153, 6, 153, 151, 151, 151, 151,
130887 /* 1380 */ 165, 178, 165, 178, 4, 3, 22, 32, 15, 34,
130888 /* 1390 */ 132, 133, 134, 135, 136, 245, 165, 142, 43, 248,
130889 /* 1400 */ 248, 68, 16, 120, 23, 131, 23, 111, 123, 20,
130890 /* 1410 */ 16, 56, 125, 1, 123, 131, 79, 111, 63, 79,
130891 /* 1420 */ 28, 66, 67, 36, 122, 1, 5, 22, 107, 140,
130892 /* 1430 */ 54, 54, 26, 61, 44, 107, 20, 24, 19, 112,
130893 /* 1440 */ 105, 53, 22, 40, 22, 22, 53, 30, 23, 22,
130894 /* 1450 */ 22, 53, 23, 23, 23, 116, 22, 11, 23, 22,
130895 /* 1460 */ 28, 23, 26, 122, 23, 22, 124, 122, 26, 114,
130896 /* 1470 */ 26, 23, 23, 23, 22, 36, 36, 26, 23, 23,
130897 /* 1480 */ 22, 36, 122, 24, 23, 22, 26, 22, 24, 23,
130898 /* 1490 */ 23, 122, 23, 22, 15, 23, 141, 122, 1,
130899 };
130900 #define YY_SHIFT_USE_DFLT (-72)
 
130901 #define YY_SHIFT_COUNT (439)
130902 #define YY_SHIFT_MIN (-71)
130903 #define YY_SHIFT_MAX (1497)
130904 static const short yy_shift_ofst[] = {
130905 /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 138, -19, 58,
130906 /* 10 */ 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 67,
130907 /* 20 */ 67, 90, 132, 336, 76, 135, 263, 340, 417, 494,
130908 /* 30 */ 571, 622, 699, 776, 827, 827, 827, 827, 827, 827,
130909 /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 878,
130910 /* 50 */ 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204, 1204,
130911 /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130912 /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130913 /* 80 */ 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204, 1204,
130914 /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47, -47,
130915 /* 100 */ -47, -47, -47, -6, 88, -66, 23, 458, 505, 468,
130916 /* 110 */ 468, 23, 201, 343, -58, -72, -72, -72, 11, 11,
130917 /* 120 */ 11, 412, 412, 341, 537, 605, 23, 23, 23, 23,
130918 /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130919 /* 140 */ 23, 23, 23, 23, 23, 23, 635, 298, 74, 74,
130920 /* 150 */ 343, -1, -1, -1, -1, -1, -1, -72, -72, -72,
130921 /* 160 */ 228, 101, 101, 203, 75, 71, 273, 284, 345, 23,
130922 /* 170 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130923 /* 180 */ 23, 23, 23, 23, 23, 23, 421, 421, 421, 23,
130924 /* 190 */ 23, 582, 23, 23, 23, 356, 23, 23, 585, 23,
130925 /* 200 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 568,
130926 /* 210 */ 575, 456, 456, 456, 704, 171, 645, 674, 858, 590,
130927 /* 220 */ 590, 914, 858, 914, 370, 963, 886, 948, 590, 425,
130928 /* 230 */ 948, 948, 864, 641, 527, 1196, 1115, 1115, 1197, 1197,
130929 /* 240 */ 1115, 1221, 1179, 1125, 1240, 1240, 1240, 1240, 1115, 1244,
130930 /* 250 */ 1125, 1221, 1179, 1179, 1125, 1115, 1244, 1137, 1233, 1115,
130931 /* 260 */ 1115, 1244, 1265, 1115, 1244, 1115, 1244, 1265, 1199, 1199,
130932 /* 270 */ 1199, 1262, 1265, 1199, 1206, 1199, 1262, 1199, 1199, 1192,
130933 /* 280 */ 1216, 1192, 1216, 1192, 1216, 1192, 1216, 1115, 1115, 1195,
130934 /* 290 */ 1265, 1246, 1246, 1265, 1214, 1218, 1223, 1219, 1125, 1332,
130935 /* 300 */ 1338, 1358, 1358, 1368, 1368, 1368, 1368, -72, -72, -72,
130936 /* 310 */ -72, -72, -72, -72, -72, 400, 623, 742, 816, 658,
130937 /* 320 */ 697, 227, 1012, 664, 1013, 1014, 1018, 1026, 1051, 891,
130938 /* 330 */ 1021, 1040, 1068, 1084, 1066, 1139, 910, 954, 1154, 1088,
130939 /* 340 */ 978, 1380, 1382, 1364, 1255, 1373, 1333, 1386, 1381, 1383,
130940 /* 350 */ 1283, 1274, 1296, 1285, 1389, 1287, 1394, 1412, 1291, 1284,
130941 /* 360 */ 1337, 1340, 1306, 1392, 1387, 1302, 1424, 1421, 1405, 1321,
130942 /* 370 */ 1289, 1376, 1406, 1377, 1372, 1390, 1328, 1413, 1416, 1419,
130943 /* 380 */ 1327, 1335, 1420, 1388, 1422, 1423, 1425, 1427, 1393, 1417,
130944 /* 390 */ 1428, 1398, 1403, 1429, 1430, 1431, 1339, 1434, 1435, 1437,
130945 /* 400 */ 1436, 1341, 1438, 1441, 1432, 1439, 1443, 1342, 1442, 1440,
130946 /* 410 */ 1444, 1445, 1442, 1448, 1449, 1450, 1451, 1455, 1452, 1446,
130947 /* 420 */ 1456, 1458, 1459, 1460, 1461, 1463, 1464, 1460, 1466, 1465,
130948 /* 430 */ 1467, 1469, 1471, 1345, 1360, 1369, 1375, 1472, 1479, 1497,
130949 };
130950 #define YY_REDUCE_USE_DFLT (-144)
130951 #define YY_REDUCE_COUNT (314)
130952 #define YY_REDUCE_MIN (-143)
130953 #define YY_REDUCE_MAX (1231)
130954 static const short yy_reduce_ofst[] = {
130955 /* 0 */ -143, 949, 136, 131, -48, -45, 158, 241, 22, 153,
130956 /* 10 */ 226, 163, 362, 364, 366, 312, 314, 368, 237, 236,
130957 /* 20 */ 300, 440, 114, 359, 319, 100, 100, 100, 100, 100,
130958 /* 30 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130959 /* 40 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130960 /* 50 */ 100, 100, 100, 100, 374, 447, 461, 516, 518, 567,
130961 /* 60 */ 569, 572, 574, 579, 581, 583, 586, 596, 631, 644,
130962 /* 70 */ 646, 649, 657, 659, 661, 663, 671, 708, 720, 722,
130963 /* 80 */ 759, 771, 773, 810, 822, 824, 861, 873, 875, 930,
130964 /* 90 */ 944, 947, 952, 957, 959, 961, 997, 100, 100, 100,
130965 /* 100 */ 100, 100, 100, 100, 100, 100, 486, -108, -83, 224,
130966 /* 110 */ 286, 451, 100, 681, 100, 100, 100, 100, 354, 354,
130967 /* 120 */ 354, 337, 352, 49, 482, 482, 503, 532, -60, 615,
130968 /* 130 */ 647, 689, 690, 737, 782, -62, 517, 789, 474, 795,
130969 /* 140 */ 580, 733, 32, 662, 488, 139, 678, 433, 769, 772,
130970 /* 150 */ 396, 728, 887, 942, 955, 965, 977, 740, 766, 178,
130971 /* 160 */ -46, -17, 59, 53, 118, 141, 167, 248, 255, 326,
130972 /* 170 */ 441, 464, 519, 668, 693, 721, 736, 744, 775, 788,
130973 /* 180 */ 846, 899, 912, 936, 983, 985, 72, 134, 542, 990,
130974 /* 190 */ 991, 597, 992, 998, 1020, 871, 1022, 1027, 915, 1029,
130975 /* 200 */ 1030, 1034, 118, 1035, 1036, 1043, 1044, 1045, 1046, 931,
130976 /* 210 */ 967, 999, 1000, 1001, 597, 1003, 1009, 1058, 1011, 987,
130977 /* 220 */ 1002, 976, 1016, 981, 1039, 1037, 1038, 1047, 1006, 1004,
130978 /* 230 */ 1052, 1053, 1033, 1031, 1079, 994, 1080, 1081, 1005, 1010,
130979 /* 240 */ 1082, 1028, 1062, 1055, 1067, 1071, 1072, 1073, 1101, 1108,
130980 /* 250 */ 1069, 1048, 1078, 1083, 1074, 1110, 1113, 1041, 1049, 1122,
130981 /* 260 */ 1123, 1126, 1118, 1138, 1140, 1144, 1141, 1127, 1133, 1134,
130982 /* 270 */ 1135, 1129, 1136, 1142, 1143, 1146, 1132, 1147, 1148, 1102,
130983 /* 280 */ 1109, 1112, 1111, 1114, 1116, 1117, 1119, 1166, 1170, 1120,
130984 /* 290 */ 1158, 1121, 1124, 1165, 1145, 1149, 1155, 1159, 1161, 1201,
130985 /* 300 */ 1209, 1220, 1222, 1225, 1226, 1227, 1228, 1151, 1152, 1150,
130986 /* 310 */ 1215, 1217, 1203, 1205, 1231,
130987 };
130988 static const YYACTIONTYPE yy_default[] = {
130989 /* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
130990 /* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
130991 /* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131547,104 @@
131049 */
131050 #ifdef YYFALLBACK
131051 static const YYCODETYPE yyFallback[] = {
131052 0, /* $ => nothing */
131053 0, /* SEMI => nothing */
131054 27, /* EXPLAIN => ID */
131055 27, /* QUERY => ID */
131056 27, /* PLAN => ID */
131057 27, /* BEGIN => ID */
131058 0, /* TRANSACTION => nothing */
131059 27, /* DEFERRED => ID */
131060 27, /* IMMEDIATE => ID */
131061 27, /* EXCLUSIVE => ID */
131062 0, /* COMMIT => nothing */
131063 27, /* END => ID */
131064 27, /* ROLLBACK => ID */
131065 27, /* SAVEPOINT => ID */
131066 27, /* RELEASE => ID */
131067 0, /* TO => nothing */
131068 0, /* TABLE => nothing */
131069 0, /* CREATE => nothing */
131070 27, /* IF => ID */
131071 0, /* NOT => nothing */
131072 0, /* EXISTS => nothing */
131073 27, /* TEMP => ID */
131074 0, /* LP => nothing */
131075 0, /* RP => nothing */
131076 0, /* AS => nothing */
131077 27, /* WITHOUT => ID */
131078 0, /* COMMA => nothing */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131079 0, /* ID => nothing */
131080 0, /* INDEXED => nothing */
131081 27, /* ABORT => ID */
131082 27, /* ACTION => ID */
131083 27, /* AFTER => ID */
131084 27, /* ANALYZE => ID */
131085 27, /* ASC => ID */
131086 27, /* ATTACH => ID */
131087 27, /* BEFORE => ID */
131088 27, /* BY => ID */
131089 27, /* CASCADE => ID */
131090 27, /* CAST => ID */
131091 27, /* COLUMNKW => ID */
131092 27, /* CONFLICT => ID */
131093 27, /* DATABASE => ID */
131094 27, /* DESC => ID */
131095 27, /* DETACH => ID */
131096 27, /* EACH => ID */
131097 27, /* FAIL => ID */
131098 27, /* FOR => ID */
131099 27, /* IGNORE => ID */
131100 27, /* INITIALLY => ID */
131101 27, /* INSTEAD => ID */
131102 27, /* LIKE_KW => ID */
131103 27, /* MATCH => ID */
131104 27, /* NO => ID */
131105 27, /* KEY => ID */
131106 27, /* OF => ID */
131107 27, /* OFFSET => ID */
131108 27, /* PRAGMA => ID */
131109 27, /* RAISE => ID */
131110 27, /* RECURSIVE => ID */
131111 27, /* REPLACE => ID */
131112 27, /* RESTRICT => ID */
131113 27, /* ROW => ID */
131114 27, /* TRIGGER => ID */
131115 27, /* VACUUM => ID */
131116 27, /* VIEW => ID */
131117 27, /* VIRTUAL => ID */
131118 27, /* WITH => ID */
131119 27, /* REINDEX => ID */
131120 27, /* RENAME => ID */
131121 27, /* CTIME_KW => ID */
131122 };
131123 #endif /* YYFALLBACK */
131124
131125 /* The following structure represents a single element of the
131126 ** parser's stack. Information stored includes:
@@ -131207,29 +131731,29 @@
131207 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131208 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131209 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131210 "TABLE", "CREATE", "IF", "NOT",
131211 "EXISTS", "TEMP", "LP", "RP",
131212 "AS", "WITHOUT", "COMMA", "ID",
 
 
 
 
 
 
 
131213 "INDEXED", "ABORT", "ACTION", "AFTER",
131214 "ANALYZE", "ASC", "ATTACH", "BEFORE",
131215 "BY", "CASCADE", "CAST", "COLUMNKW",
131216 "CONFLICT", "DATABASE", "DESC", "DETACH",
131217 "EACH", "FAIL", "FOR", "IGNORE",
131218 "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
131219 "NO", "KEY", "OF", "OFFSET",
131220 "PRAGMA", "RAISE", "RECURSIVE", "REPLACE",
131221 "RESTRICT", "ROW", "TRIGGER", "VACUUM",
131222 "VIEW", "VIRTUAL", "WITH", "REINDEX",
131223 "RENAME", "CTIME_KW", "ANY", "OR",
131224 "AND", "IS", "BETWEEN", "IN",
131225 "ISNULL", "NOTNULL", "NE", "EQ",
131226 "GT", "LE", "LT", "GE",
131227 "ESCAPE", "BITAND", "BITOR", "LSHIFT",
131228 "RSHIFT", "PLUS", "MINUS", "STAR",
131229 "SLASH", "REM", "CONCAT", "COLLATE",
131230 "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT",
131231 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131232 "CHECK", "REFERENCES", "AUTOINCR", "ON",
131233 "INSERT", "DELETE", "UPDATE", "SET",
131234 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
131235 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133529,27 @@
133005 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133006 }
133007 break;
133008 case 156: /* expr ::= VARIABLE */
133009 {
133010 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133011 if( t.n>=2 && t.z[0]=='#' && sqlite3Isdigit(t.z[1]) ){
 
 
133012 /* When doing a nested parse, one can include terms in an expression
133013 ** that look like this: #1 #2 ... These terms refer to registers
133014 ** in the virtual machine. #N is the N-th register. */
 
 
133015 spanSet(&yymsp[0].minor.yy342, &t, &t);
133016 if( pParse->nested==0 ){
133017 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133018 yymsp[0].minor.yy342.pExpr = 0;
133019 }else{
133020 yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133021 if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133022 }
133023 }else{
133024 spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, t);
133025 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133026 }
133027 }
133028 break;
133029 case 157: /* expr ::= expr COLLATE ID|STRING */
133030 {
@@ -133205,60 +133730,37 @@
133205 break;
133206 case 188: /* expr ::= LP select RP */
133207 {
133208 spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133209 yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133210 if( yymsp[-2].minor.yy342.pExpr ){
133211 yymsp[-2].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133212 ExprSetProperty(yymsp[-2].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133213 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-2].minor.yy342.pExpr);
133214 }else{
133215 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133216 }
133217 }
133218 break;
133219 case 189: /* expr ::= expr in_op LP select RP */
133220 {
133221 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133222 if( yymsp[-4].minor.yy342.pExpr ){
133223 yymsp[-4].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133224 ExprSetProperty(yymsp[-4].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133225 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy342.pExpr);
133226 }else{
133227 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133228 }
133229 exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133230 yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133231 }
133232 break;
133233 case 190: /* expr ::= expr in_op nm dbnm */
133234 {
133235 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
 
133236 yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133237 if( yymsp[-3].minor.yy342.pExpr ){
133238 yymsp[-3].minor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133239 ExprSetProperty(yymsp[-3].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133240 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-3].minor.yy342.pExpr);
133241 }else{
133242 sqlite3SrcListDelete(pParse->db, pSrc);
133243 }
133244 exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133245 yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133246 }
133247 break;
133248 case 191: /* expr ::= EXISTS LP select RP */
133249 {
133250 Expr *p;
133251 spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133252 p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133253 if( p ){
133254 p->x.pSelect = yymsp[-1].minor.yy159;
133255 ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
133256 sqlite3ExprSetHeightAndFlags(pParse, p);
133257 }else{
133258 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133259 }
133260 }
133261 break;
133262 case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133263 {
133264 spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135241,11 @@
134739 ** will take responsibility for freeing the Table structure.
134740 */
134741 sqlite3DeleteTable(db, pParse->pNewTable);
134742 }
134743
134744 sqlite3WithDelete(db, pParse->pWithToFree);
134745 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
134746 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
134747 sqlite3DbFree(db, pParse->azVar);
134748 while( pParse->pAinc ){
134749 AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136451,11 @@
135949 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
135950 } aFlagOp[] = {
135951 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
135952 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
135953 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
 
135954 };
135955 unsigned int i;
135956 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
135957 for(i=0; i<ArraySize(aFlagOp); i++){
135958 if( aFlagOp[i].op==op ){
@@ -162447,19 +162950,21 @@
162447 ** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162448 **
162449 ** http://www.icu-project.org/userguide/posix.html#case_mappings
162450 */
162451 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162452 const UChar *zInput;
162453 UChar *zOutput = 0;
162454 int nInput;
162455 int nOut;
162456 int cnt;
 
162457 UErrorCode status;
162458 const char *zLocale = 0;
162459
162460 assert(nArg==1 || nArg==2);
 
162461 if( nArg==2 ){
162462 zLocale = (const char *)sqlite3_value_text(apArg[1]);
162463 }
162464
162465 zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162984,27 @@
162479 sqlite3_result_error_nomem(p);
162480 return;
162481 }
162482 zOutput = zNew;
162483 status = U_ZERO_ERROR;
162484 if( sqlite3_user_data(p) ){
162485 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162486 }else{
162487 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162488 }
162489 if( !U_SUCCESS(status) ){
162490 if( status==U_BUFFER_OVERFLOW_ERROR ) continue;
162491 icuFunctionError(p,
162492 sqlite3_user_data(p) ? "u_strToUpper" : "u_strToLower", status);
162493 return;
162494 }
162495 }
162496 sqlite3_result_text16(p, zOutput, nOut, xFree);
 
 
 
 
162497 }
162498
162499 /*
162500 ** Collation sequence destructor function. The pCtx argument points to
162501 ** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163817,42 @@
163308 const char *zTarget,
163309 const char *zRbu,
163310 const char *zState
163311 );
163312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163313 /*
163314 ** Internally, each RBU connection uses a separate SQLite database
163315 ** connection to access the target and rbu update databases. This
163316 ** API allows the application direct access to these database handles.
163317 **
@@ -163586,10 +164127,11 @@
163586 typedef struct rbu_file rbu_file;
163587 typedef struct RbuUpdateStmt RbuUpdateStmt;
163588
163589 #if !defined(SQLITE_AMALGAMATION)
163590 typedef unsigned int u32;
 
163591 typedef unsigned char u8;
163592 typedef sqlite3_int64 i64;
163593 #endif
163594
163595 /*
@@ -163598,10 +164140,12 @@
163598 ** format.
163599 */
163600 #define WAL_LOCK_WRITE 0
163601 #define WAL_LOCK_CKPT 1
163602 #define WAL_LOCK_READ0 3
 
 
163603
163604 /*
163605 ** A structure to store values read from the rbu_state table in memory.
163606 */
163607 struct RbuState {
@@ -163777,10 +164321,14 @@
163777 int nFrameAlloc; /* Allocated size of aFrame[] array */
163778 RbuFrame *aFrame;
163779 int pgsz;
163780 u8 *aBuf;
163781 i64 iWalCksum;
 
 
 
 
163782 };
163783
163784 /*
163785 ** An rbu VFS is implemented using an instance of this structure.
163786 */
@@ -163802,10 +164350,11 @@
163802 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
163803
163804 int openFlags; /* Flags this file was opened with */
163805 u32 iCookie; /* Cookie value for main db files */
163806 u8 iWriteVer; /* "write-version" value for main db files */
 
163807
163808 int nShm; /* Number of entries in apShm[] array */
163809 char **apShm; /* Array of mmap'd *-shm regions */
163810 char *zDel; /* Delete this when closing file */
163811
@@ -163812,10 +164361,15 @@
163812 const char *zWal; /* Wal filename for this main db file */
163813 rbu_file *pWalFd; /* Wal file descriptor for this main db */
163814 rbu_file *pMainNext; /* Next MAIN_DB file */
163815 };
163816
 
 
 
 
 
163817
163818 /*************************************************************************
163819 ** The following three functions, found below:
163820 **
163821 ** rbuDeltaGetInt()
@@ -164260,12 +164814,15 @@
164260 }
164261
164262
164263 /*
164264 ** The implementation of the rbu_target_name() SQL function. This function
164265 ** accepts one argument - the name of a table in the RBU database. If the
164266 ** table name matches the pattern:
 
 
 
164267 **
164268 ** data[0-9]_<name>
164269 **
164270 ** where <name> is any sequence of 1 or more characters, <name> is returned.
164271 ** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164829,37 @@
164272 ** NULL is returned.
164273 **
164274 ** "data_t1" -> "t1"
164275 ** "data0123_t2" -> "t2"
164276 ** "dataAB_t3" -> NULL
 
 
 
164277 */
164278 static void rbuTargetNameFunc(
164279 sqlite3_context *context,
164280 int argc,
164281 sqlite3_value **argv
164282 ){
 
164283 const char *zIn;
164284 assert( argc==1 );
164285
164286 zIn = (const char*)sqlite3_value_text(argv[0]);
164287 if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164288 int i;
164289 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164290 if( zIn[i]=='_' && zIn[i+1] ){
164291 sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
 
 
 
 
 
 
 
 
164292 }
164293 }
164294 }
164295
164296 /*
@@ -164304,11 +164873,12 @@
164304 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164305 int rc;
164306 memset(pIter, 0, sizeof(RbuObjIter));
164307
164308 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164309 "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
 
164310 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
164311 "ORDER BY name"
164312 );
164313
164314 if( rc==SQLITE_OK ){
@@ -164680,10 +165250,11 @@
164680 }
164681 sqlite3_finalize(pStmt);
164682 pStmt = 0;
164683
164684 if( p->rc==SQLITE_OK
 
164685 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
164686 ){
164687 p->rc = SQLITE_ERROR;
164688 p->zErrmsg = sqlite3_mprintf(
164689 "table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165390,12 @@
164819 if( pIter->eType==RBU_PK_IPK ){
164820 int i;
164821 for(i=0; pIter->abTblPk[i]==0; i++);
164822 assert( i<pIter->nTblCol );
164823 zCol = pIter->azTblCol[i];
 
 
164824 }else{
164825 zCol = "rbu_rowid";
164826 }
164827 zType = "INTEGER";
164828 }else{
@@ -165359,20 +165932,29 @@
165359 sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165360 );
165361 }
165362
165363 /* And to delete index entries */
165364 if( p->rc==SQLITE_OK ){
165365 p->rc = prepareFreeAndCollectError(
165366 p->dbMain, &pIter->pDelete, &p->zErrmsg,
165367 sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165368 );
165369 }
165370
165371 /* Create the SELECT statement to read keys in sorted order */
165372 if( p->rc==SQLITE_OK ){
165373 char *zSql;
 
 
 
 
 
 
 
 
 
165374 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165375 zSql = sqlite3_mprintf(
165376 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165377 zCollist, p->zStateDb, pIter->zDataTbl,
165378 zCollist, zLimit
@@ -165395,11 +165977,13 @@
165395 sqlite3_free(zImposterCols);
165396 sqlite3_free(zImposterPK);
165397 sqlite3_free(zWhere);
165398 sqlite3_free(zBind);
165399 }else{
165400 int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
 
 
165401 const char *zTbl = pIter->zTbl; /* Table this step applies to */
165402 const char *zWrite; /* Imposter table name */
165403
165404 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165405 char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +166006,22 @@
165422 zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
165423 )
165424 );
165425 }
165426
165427 /* Create the DELETE statement to write to the target PK b-tree */
165428 if( p->rc==SQLITE_OK ){
 
 
165429 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
165430 sqlite3_mprintf(
165431 "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
165432 )
165433 );
165434 }
165435
165436 if( pIter->abIndexed ){
165437 const char *zRbuRowid = "";
165438 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165439 zRbuRowid = ", rbu_rowid";
165440 }
165441
@@ -165481,14 +166067,20 @@
165481 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
165482 }
165483
165484 /* Create the SELECT statement to read keys from data_xxx */
165485 if( p->rc==SQLITE_OK ){
 
 
 
 
165486 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
165487 sqlite3_mprintf(
165488 "SELECT %s, rbu_control%s FROM '%q'%s",
165489 zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
 
 
165490 pIter->zDataTbl, zLimit
165491 )
165492 );
165493 }
165494
@@ -165579,44 +166171,231 @@
165579 }
165580
165581 return p->rc;
165582 }
165583
165584 static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
 
 
 
 
165585 sqlite3 *db = 0;
165586 if( p->rc==SQLITE_OK ){
165587 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
165588 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
165589 if( p->rc ){
165590 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
165591 sqlite3_close(db);
165592 db = 0;
165593 }
165594 }
165595 return db;
165596 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165597
165598 /*
165599 ** Open the database handle and attach the RBU database as "rbu". If an
165600 ** error occurs, leave an error code and message in the RBU handle.
165601 */
165602 static void rbuOpenDatabase(sqlite3rbu *p){
165603 assert( p->rc==SQLITE_OK );
165604 assert( p->dbMain==0 && p->dbRbu==0 );
 
165605
165606 p->eStage = 0;
165607 p->dbMain = rbuOpenDbhandle(p, p->zTarget);
165608 p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
 
 
 
165609
165610 /* If using separate RBU and state databases, attach the state database to
165611 ** the RBU db handle now. */
165612 if( p->zState ){
165613 rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
165614 memcpy(p->zStateDb, "stat", 4);
165615 }else{
165616 memcpy(p->zStateDb, "main", 4);
165617 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165618
165619 if( p->rc==SQLITE_OK ){
165620 p->rc = sqlite3_create_function(p->dbMain,
165621 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
165622 );
@@ -165628,11 +166407,11 @@
165628 );
165629 }
165630
165631 if( p->rc==SQLITE_OK ){
165632 p->rc = sqlite3_create_function(p->dbRbu,
165633 "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
165634 );
165635 }
165636
165637 if( p->rc==SQLITE_OK ){
165638 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166666,19 @@
165887 ** If an error occurs, leave an error code and error message in the rbu
165888 ** handle.
165889 */
165890 static void rbuMoveOalFile(sqlite3rbu *p){
165891 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
 
 
 
165892
165893 char *zWal = sqlite3_mprintf("%s-wal", zBase);
165894 char *zOal = sqlite3_mprintf("%s-oal", zBase);
 
 
 
165895
165896 assert( p->eStage==RBU_STAGE_MOVE );
165897 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
165898 if( zWal==0 || zOal==0 ){
165899 p->rc = SQLITE_NOMEM;
@@ -165910,12 +166695,12 @@
165910 rbuFileSuffix3(zBase, zWal);
165911 rbuFileSuffix3(zBase, zOal);
165912
165913 /* Re-open the databases. */
165914 rbuObjIterFinalize(&p->objiter);
165915 sqlite3_close(p->dbMain);
165916 sqlite3_close(p->dbRbu);
 
165917 p->dbMain = 0;
165918 p->dbRbu = 0;
165919
165920 #if defined(_WIN32_WCE)
165921 {
@@ -166073,23 +166858,28 @@
166073
166074 pVal = sqlite3_column_value(pIter->pSelect, i);
166075 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166076 if( p->rc ) return;
166077 }
166078 if( pIter->zIdx==0
166079 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
166080 ){
166081 /* For a virtual table, or a table with no primary key, the
166082 ** SELECT statement is:
166083 **
166084 ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166085 **
166086 ** Hence column_value(pIter->nCol+1).
166087 */
166088 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
166089 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166090 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
 
 
 
 
 
166091 }
166092 if( p->rc==SQLITE_OK ){
166093 sqlite3_step(pWriter);
166094 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166095 }
@@ -166164,17 +166954,22 @@
166164 return p->rc;
166165 }
166166
166167 /*
166168 ** Increment the schema cookie of the main database opened by p->dbMain.
 
 
 
 
166169 */
166170 static void rbuIncrSchemaCookie(sqlite3rbu *p){
166171 if( p->rc==SQLITE_OK ){
 
166172 int iCookie = 1000000;
166173 sqlite3_stmt *pStmt;
166174
166175 p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
166176 "PRAGMA schema_version"
166177 );
166178 if( p->rc==SQLITE_OK ){
166179 /* Coverage: it may be that this sqlite3_step() cannot fail. There
166180 ** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166993,11 @@
166198 ** are determined by inspecting the rbu handle passed as the first argument.
166199 */
166200 static void rbuSaveState(sqlite3rbu *p, int eStage){
166201 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166202 sqlite3_stmt *pInsert = 0;
 
166203 int rc;
166204
166205 assert( p->zErrmsg==0 );
166206 rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
166207 sqlite3_mprintf(
@@ -166220,11 +167016,11 @@
166220 RBU_STATE_TBL, p->objiter.zTbl,
166221 RBU_STATE_IDX, p->objiter.zIdx,
166222 RBU_STATE_ROW, p->nStep,
166223 RBU_STATE_PROGRESS, p->nProgress,
166224 RBU_STATE_CKPT, p->iWalCksum,
166225 RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
166226 RBU_STATE_OALSZ, p->iOalSz,
166227 RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
166228 )
166229 );
166230 assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +167031,121 @@
166235 }
166236 if( rc!=SQLITE_OK ) p->rc = rc;
166237 }
166238 }
166239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166240
166241 /*
166242 ** Step the RBU object.
166243 */
166244 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
166245 if( p ){
166246 switch( p->eStage ){
166247 case RBU_STAGE_OAL: {
166248 RbuObjIter *pIter = &p->objiter;
 
 
 
 
 
 
 
 
 
166249 while( p->rc==SQLITE_OK && pIter->zTbl ){
166250
166251 if( pIter->bCleanup ){
166252 /* Clean up the rbu_tmp_xxx table for the previous table. It
166253 ** cannot be dropped as there are currently active SQL statements.
166254 ** But the contents can be deleted. */
166255 if( pIter->abIndexed ){
166256 rbuMPrintfExec(p, p->dbRbu,
166257 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
166258 );
166259 }
166260 }else{
@@ -166337,98 +167228,10 @@
166337 }else{
166338 return SQLITE_NOMEM;
166339 }
166340 }
166341
166342 /*
166343 ** Free an RbuState object allocated by rbuLoadState().
166344 */
166345 static void rbuFreeState(RbuState *p){
166346 if( p ){
166347 sqlite3_free(p->zTbl);
166348 sqlite3_free(p->zIdx);
166349 sqlite3_free(p);
166350 }
166351 }
166352
166353 /*
166354 ** Allocate an RbuState object and load the contents of the rbu_state
166355 ** table into it. Return a pointer to the new object. It is the
166356 ** responsibility of the caller to eventually free the object using
166357 ** sqlite3_free().
166358 **
166359 ** If an error occurs, leave an error code and message in the rbu handle
166360 ** and return NULL.
166361 */
166362 static RbuState *rbuLoadState(sqlite3rbu *p){
166363 RbuState *pRet = 0;
166364 sqlite3_stmt *pStmt = 0;
166365 int rc;
166366 int rc2;
166367
166368 pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166369 if( pRet==0 ) return 0;
166370
166371 rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166372 sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166373 );
166374 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166375 switch( sqlite3_column_int(pStmt, 0) ){
166376 case RBU_STATE_STAGE:
166377 pRet->eStage = sqlite3_column_int(pStmt, 1);
166378 if( pRet->eStage!=RBU_STAGE_OAL
166379 && pRet->eStage!=RBU_STAGE_MOVE
166380 && pRet->eStage!=RBU_STAGE_CKPT
166381 ){
166382 p->rc = SQLITE_CORRUPT;
166383 }
166384 break;
166385
166386 case RBU_STATE_TBL:
166387 pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166388 break;
166389
166390 case RBU_STATE_IDX:
166391 pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166392 break;
166393
166394 case RBU_STATE_ROW:
166395 pRet->nRow = sqlite3_column_int(pStmt, 1);
166396 break;
166397
166398 case RBU_STATE_PROGRESS:
166399 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166400 break;
166401
166402 case RBU_STATE_CKPT:
166403 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166404 break;
166405
166406 case RBU_STATE_COOKIE:
166407 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166408 break;
166409
166410 case RBU_STATE_OALSZ:
166411 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166412 break;
166413
166414 case RBU_STATE_PHASEONESTEP:
166415 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166416 break;
166417
166418 default:
166419 rc = SQLITE_CORRUPT;
166420 break;
166421 }
166422 }
166423 rc2 = sqlite3_finalize(pStmt);
166424 if( rc==SQLITE_OK ) rc = rc2;
166425
166426 p->rc = rc;
166427 return pRet;
166428 }
166429
166430 /*
166431 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
166432 ** otherwise. Either or both argument may be NULL. Two NULL values are
166433 ** considered equal, and NULL is considered distinct from all other values.
166434 */
@@ -166614,20 +167417,18 @@
166614 }
166615 }
166616 }
166617 }
166618
166619 /*
166620 ** Open and return a new RBU handle.
166621 */
166622 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
166623 const char *zTarget,
166624 const char *zRbu,
166625 const char *zState
166626 ){
166627 sqlite3rbu *p;
166628 size_t nTarget = strlen(zTarget);
166629 size_t nRbu = strlen(zRbu);
166630 size_t nState = zState ? strlen(zState) : 0;
166631 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
166632
166633 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167437,28 @@
166636
166637 /* Create the custom VFS. */
166638 memset(p, 0, sizeof(sqlite3rbu));
166639 rbuCreateVfs(p);
166640
166641 /* Open the target database */
166642 if( p->rc==SQLITE_OK ){
166643 p->zTarget = (char*)&p[1];
166644 memcpy(p->zTarget, zTarget, nTarget+1);
166645 p->zRbu = &p->zTarget[nTarget+1];
 
 
 
 
166646 memcpy(p->zRbu, zRbu, nRbu+1);
 
166647 if( zState ){
166648 p->zState = &p->zRbu[nRbu+1];
166649 memcpy(p->zState, zState, nState+1);
166650 }
166651 rbuOpenDatabase(p);
166652 }
166653
166654 /* If it has not already been created, create the rbu_state table */
166655 rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166656
166657 if( p->rc==SQLITE_OK ){
166658 pState = rbuLoadState(p);
166659 assert( pState || p->rc!=SQLITE_OK );
166660 if( p->rc==SQLITE_OK ){
166661
@@ -166681,31 +167484,43 @@
166681 p->eStage = RBU_STAGE_CKPT;
166682 p->nStep = 0;
166683 }
166684 }
166685
166686 if( p->rc==SQLITE_OK
166687 && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
166688 && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
166689 ){
166690 /* At this point (pTargetFd->iCookie) contains the value of the
166691 ** change-counter cookie (the thing that gets incremented when a
166692 ** transaction is committed in rollback mode) currently stored on
166693 ** page 1 of the database file. */
166694 p->rc = SQLITE_BUSY;
166695 p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
 
 
 
 
 
166696 }
166697
166698 if( p->rc==SQLITE_OK ){
166699 if( p->eStage==RBU_STAGE_OAL ){
166700 sqlite3 *db = p->dbMain;
 
 
 
 
 
166701
166702 /* Open transactions both databases. The *-oal file is opened or
166703 ** created at this point. */
166704 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
 
 
166705 if( p->rc==SQLITE_OK ){
166706 p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
166707 }
166708
166709 /* Check if the main database is a zipvfs db. If it is, set the upper
166710 ** level pager to use "journal_mode=off". This prevents it from
166711 ** generating a large journal using a temp file. */
@@ -166746,10 +167561,32 @@
166746 }
166747
166748 return p;
166749 }
166750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166751
166752 /*
166753 ** Return the database handle used by pRbu.
166754 */
166755 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167603,11 @@
166766 ** then edit any error message string so as to remove all occurrences of
166767 ** the pattern "rbu_imp_[0-9]*".
166768 */
166769 static void rbuEditErrmsg(sqlite3rbu *p){
166770 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
166771 int i;
166772 size_t nErrmsg = strlen(p->zErrmsg);
166773 for(i=0; i<(nErrmsg-8); i++){
166774 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
166775 int nDel = 8;
166776 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167636,24 @@
166799 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
166800 }
166801
166802 /* Close any open statement handles. */
166803 rbuObjIterFinalize(&p->objiter);
 
 
 
 
 
 
 
 
 
 
166804
166805 /* Close the open database handle and VFS object. */
166806 sqlite3_close(p->dbMain);
166807 sqlite3_close(p->dbRbu);
 
166808 rbuDeleteVfs(p);
166809 sqlite3_free(p->aBuf);
166810 sqlite3_free(p->aFrame);
166811
166812 rbuEditErrmsg(p);
@@ -167003,10 +167850,26 @@
167003 return ((u32)aBuf[0] << 24)
167004 + ((u32)aBuf[1] << 16)
167005 + ((u32)aBuf[2] << 8)
167006 + ((u32)aBuf[3]);
167007 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167008
167009 /*
167010 ** Read data from an rbuVfs-file.
167011 */
167012 static int rbuVfsRead(
@@ -167029,10 +167892,39 @@
167029 ){
167030 rc = SQLITE_OK;
167031 memset(zBuf, 0, iAmt);
167032 }else{
167033 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167034 }
167035 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167036 /* These look like magic numbers. But they are stable, as they are part
167037 ** of the definition of the SQLite file format, which may not change. */
167038 u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167995,24 @@
167103 /*
167104 ** Return the current file-size of an rbuVfs-file.
167105 */
167106 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167107 rbu_file *p = (rbu_file *)pFile;
167108 return p->pReal->pMethods->xFileSize(p->pReal, pSize);
 
 
 
 
 
 
 
 
 
 
 
 
 
167109 }
167110
167111 /*
167112 ** Lock an rbuVfs-file.
167113 */
@@ -167115,11 +168020,13 @@
167115 rbu_file *p = (rbu_file*)pFile;
167116 sqlite3rbu *pRbu = p->pRbu;
167117 int rc = SQLITE_OK;
167118
167119 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
167120 if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
 
 
167121 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
167122 ** prevents it from checkpointing the database from sqlite3_close(). */
167123 rc = SQLITE_BUSY;
167124 }else{
167125 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +168084,16 @@
167177 if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
167178 rc = SQLITE_OK;
167179 }
167180 }
167181 return rc;
 
 
 
 
 
 
167182 }
167183
167184 rc = xControl(p->pReal, op, pArg);
167185 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
167186 rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168253,37 @@
167340 sqlite3_mutex_enter(pRbuVfs->mutex);
167341 for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
167342 sqlite3_mutex_leave(pRbuVfs->mutex);
167343 return pDb;
167344 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167345
167346 /*
167347 ** Open an rbu file handle.
167348 */
167349 static int rbuVfsOpen(
@@ -167376,10 +168316,11 @@
167376 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
167377 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
167378 rbu_file *pFd = (rbu_file *)pFile;
167379 int rc = SQLITE_OK;
167380 const char *zOpen = zName;
 
167381
167382 memset(pFd, 0, sizeof(rbu_file));
167383 pFd->pReal = (sqlite3_file*)&pFd[1];
167384 pFd->pRbuVfs = pRbuVfs;
167385 pFd->openFlags = flags;
@@ -167388,40 +168329,31 @@
167388 /* A main database has just been opened. The following block sets
167389 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
167390 ** the name of the *-wal file this db connection will use. SQLite
167391 ** happens to pass a pointer to this buffer when using xAccess()
167392 ** or xOpen() to operate on the *-wal file. */
167393 int n = (int)strlen(zName);
167394 const char *z = &zName[n];
167395 if( flags & SQLITE_OPEN_URI ){
167396 int odd = 0;
167397 while( 1 ){
167398 if( z[0]==0 ){
167399 odd = 1 - odd;
167400 if( odd && z[1]==0 ) break;
167401 }
167402 z++;
167403 }
167404 z += 2;
167405 }else{
167406 while( *z==0 ) z++;
167407 }
167408 z += (n + 8 + 1);
167409 pFd->zWal = z;
167410 }
167411 else if( flags & SQLITE_OPEN_WAL ){
167412 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
167413 if( pDb ){
167414 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
167415 /* This call is to open a *-wal file. Intead, open the *-oal. This
167416 ** code ensures that the string passed to xOpen() is terminated by a
167417 ** pair of '\0' bytes in case the VFS attempts to extract a URI
167418 ** parameter from it. */
167419 size_t nCopy = strlen(zName);
167420 char *zCopy = sqlite3_malloc64(nCopy+2);
 
 
 
 
 
 
 
167421 if( zCopy ){
167422 memcpy(zCopy, zName, nCopy);
167423 zCopy[nCopy-3] = 'o';
167424 zCopy[nCopy] = '\0';
167425 zCopy[nCopy+1] = '\0';
167426 zOpen = (const char*)(pFd->zDel = zCopy);
167427 }else{
@@ -167431,13 +168363,22 @@
167431 }
167432 pDb->pWalFd = pFd;
167433 }
167434 }
167435 }
 
 
 
 
 
 
 
 
 
167436
167437 if( rc==SQLITE_OK ){
167438 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags);
167439 }
167440 if( pFd->pReal->pMethods ){
167441 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
167442 ** pointer and, if the file is a main database file, link it into the
167443 ** mutex protected linked list of all such files. */
@@ -168678,23 +169619,22 @@
168678 */
168679 static int sessionVarintGet(u8 *aBuf, int *piVal){
168680 return getVarint32(aBuf, *piVal);
168681 }
168682
 
 
 
168683 /*
168684 ** Read a 64-bit big-endian integer value from buffer aRec[]. Return
168685 ** the value read.
168686 */
168687 static sqlite3_int64 sessionGetI64(u8 *aRec){
168688 return (((sqlite3_int64)aRec[0]) << 56)
168689 + (((sqlite3_int64)aRec[1]) << 48)
168690 + (((sqlite3_int64)aRec[2]) << 40)
168691 + (((sqlite3_int64)aRec[3]) << 32)
168692 + (((sqlite3_int64)aRec[4]) << 24)
168693 + (((sqlite3_int64)aRec[5]) << 16)
168694 + (((sqlite3_int64)aRec[6]) << 8)
168695 + (((sqlite3_int64)aRec[7]) << 0);
168696 }
168697
168698 /*
168699 ** Write a 64-bit big-endian integer value to the buffer aBuf[].
168700 */
@@ -168992,18 +169932,23 @@
168992 u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
168993 u8 *a2 = aRight; /* Cursor to iterate through aRight */
168994 int iCol; /* Used to iterate through table columns */
168995
168996 for(iCol=0; iCol<pTab->nCol; iCol++){
168997 int n1 = sessionSerialLen(a1);
168998 int n2 = sessionSerialLen(a2);
168999
169000 if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169001 return 0;
169002 }
169003 if( pTab->abPK[iCol] || bLeftPkOnly==0 ) a1 += n1;
169004 if( pTab->abPK[iCol] || bRightPkOnly==0 ) a2 += n2;
 
 
 
 
 
169005 }
169006
169007 return 1;
169008 }
169009
@@ -169335,13 +170280,13 @@
169335 int rc;
169336 int nByte;
169337 int nDbCol = 0;
169338 int nThis;
169339 int i;
169340 u8 *pAlloc;
169341 char **azCol = 0;
169342 u8 *abPK;
169343
169344 assert( pazCol && pabPK );
169345
169346 nThis = sqlite3Strlen30(zThis);
169347 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170938,13 @@
169993 for(pTab=pList; pTab; pTab=pNext){
169994 int i;
169995 pNext = pTab->pNext;
169996 for(i=0; i<pTab->nChange; i++){
169997 SessionChange *p;
169998 SessionChange *pNext;
169999 for(p=pTab->apChange[i]; p; p=pNext){
170000 pNext = p->pNext;
170001 sqlite3_free(p);
170002 }
170003 }
170004 sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170005 sqlite3_free(pTab->apChange);
@@ -171282,11 +172227,10 @@
171282 if( p->bPatchset && p->op==SQLITE_UPDATE ){
171283 /* If this is an UPDATE that is part of a patchset, then all PK and
171284 ** modified fields are present in the new.* record. The old.* record
171285 ** is currently completely empty. This block shifts the PK fields from
171286 ** new.* to old.*, to accommodate the code that reads these arrays. */
171287 int i;
171288 for(i=0; i<p->nCol; i++){
171289 assert( p->apValue[i]==0 );
171290 assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
171291 if( p->abPK[i] ){
171292 p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172999,11 @@
172055 sqlite3_changeset_iter *pIter, /* Changeset iterator */
172056 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
172057 void *pCtx, /* First argument for conflict handler */
172058 int *pbReplace /* OUT: Set to true if PK row is found */
172059 ){
172060 int res; /* Value returned by conflict handler */
172061 int rc;
172062 int nCol;
172063 int op;
172064 const char *zDummy;
172065
@@ -175390,15 +176334,17 @@
175390 ** of the current query. Specifically, a query equivalent to:
175391 **
175392 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
175393 **
175394 ** with $p set to a phrase equivalent to the phrase iPhrase of the
175395 ** current query is executed. For each row visited, the callback function
175396 ** passed as the fourth argument is invoked. The context and API objects
175397 ** passed to the callback function may be used to access the properties of
175398 ** each matched row. Invoking Api.xUserData() returns a copy of the pointer
175399 ** passed as the third argument to pUserData.
 
 
175400 **
175401 ** If the callback function returns any value other than SQLITE_OK, the
175402 ** query is abandoned and the xQueryPhrase function returns immediately.
175403 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
175404 ** Otherwise, the error code is propagated upwards.
@@ -181429,10 +182375,21 @@
181429 }
181430 if( rc==SQLITE_OK ){
181431 pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc,
181432 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
181433 }
 
 
 
 
 
 
 
 
 
 
 
181434
181435 for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
181436 int tflags = 0;
181437 Fts5ExprTerm *p;
181438 for(p=&pOrig->aTerm[i]; p && rc==SQLITE_OK; p=p->pSynonym){
@@ -182777,15 +183734,15 @@
182777 assert( iCol>=p->iCol );
182778 if( iCol!=p->iCol ){
182779 if( pHash->eDetail==FTS5_DETAIL_FULL ){
182780 pPtr[p->nData++] = 0x01;
182781 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
182782 p->iCol = iCol;
182783 p->iPos = 0;
182784 }else{
182785 bNew = 1;
182786 p->iCol = iPos = iCol;
182787 }
182788 }
182789
182790 /* Append the new position offset, if necessary */
182791 if( bNew ){
@@ -186204,11 +187161,11 @@
186204 while( *aiCol<iPrev ){
186205 aiCol++;
186206 if( aiCol==aiColEnd ) goto setoutputs_col_out;
186207 }
186208 if( *aiCol==iPrev ){
186209 *aOut++ = (iPrev - iPrevOut) + 2;
186210 iPrevOut = iPrev;
186211 }
186212 }
186213
186214 setoutputs_col_out:
@@ -192037,11 +192994,11 @@
192037 int nArg, /* Number of args */
192038 sqlite3_value **apUnused /* Function arguments */
192039 ){
192040 assert( nArg==0 );
192041 UNUSED_PARAM2(nArg, apUnused);
192042 sqlite3_result_text(pCtx, "fts5: 2016-03-30 16:23:06 7cf0cab730e2d570c82dd789279ad6501ac598c8", -1, SQLITE_TRANSIENT);
192043 }
192044
192045 static int fts5Init(sqlite3 *db){
192046 static const sqlite3_module fts5Mod = {
192047 /* iVersion */ 2,
192048
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
38 **
39 */
40 #ifndef _SQLITEINT_H_
41 #define _SQLITEINT_H_
42
43 /* Special Comments:
44 **
45 ** Some comments have special meaning to the tools that measure test
46 ** coverage:
47 **
48 ** NO_TEST - The branches on this line are not
49 ** measured by branch coverage. This is
50 ** used on lines of code that actually
51 ** implement parts of coverage testing.
52 **
53 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54 ** and the correct answer is still obtained,
55 ** though perhaps more slowly.
56 **
57 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58 ** and the correct answer is still obtained,
59 ** though perhaps more slowly.
60 **
61 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62 ** that would be harmless and undetectable
63 ** if it did occur.
64 **
65 ** In all cases, the special comment must be enclosed in the usual
66 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the
67 ** asterisks and the comment text.
68 */
69
70 /*
71 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
72 ** or higher.
73 */
74 #if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
363 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364 ** [sqlite_version()] and [sqlite_source_id()].
365 */
366 #define SQLITE_VERSION "3.13.0"
367 #define SQLITE_VERSION_NUMBER 3013000
368 #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
369
370 /*
371 ** CAPI3REF: Run-Time Library Version Numbers
372 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
373 **
@@ -2155,16 +2182,34 @@
2182 ** The second parameter is a pointer to an integer into which
2183 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2184 ** following this call. The second parameter may be a NULL pointer, in
2185 ** which case the new setting is not reported back. </dd>
2186 **
2187 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2188 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2189 ** interface independently of the [load_extension()] SQL function.
2190 ** The [sqlite3_enable_load_extension()] API enables or disables both the
2191 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2192 ** There should be two additional arguments.
2193 ** When the first argument to this interface is 1, then only the C-API is
2194 ** enabled and the SQL function remains disabled. If the first argment to
2195 ** this interface is 0, then both the C-API and the SQL function are disabled.
2196 ** If the first argument is -1, then no changes are made to state of either the
2197 ** C-API or the SQL function.
2198 ** The second parameter is a pointer to an integer into which
2199 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2200 ** is disabled or enabled following this call. The second parameter may
2201 ** be a NULL pointer, in which case the new setting is not reported back.
2202 ** </dd>
2203 **
2204 ** </dl>
2205 */
2206 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2207 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2208 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2209 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2210 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2211
2212
2213 /*
2214 ** CAPI3REF: Enable Or Disable Extended Result Codes
2215 ** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
5742 ** fill *pzErrMsg with error message text stored in memory
5743 ** obtained from [sqlite3_malloc()]. The calling function
5744 ** should free this memory by calling [sqlite3_free()].
5745 **
5746 ** ^Extension loading must be enabled using
5747 ** [sqlite3_enable_load_extension()] or
5748 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5749 ** prior to calling this API,
5750 ** otherwise an error will be returned.
5751 **
5752 ** <b>Security warning:</b> It is recommended that the
5753 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5754 ** interface. The use of the [sqlite3_enable_load_extension()] interface
5755 ** should be avoided. This will keep the SQL function [load_extension()]
5756 ** disabled and prevent SQL injections from giving attackers
5757 ** access to extension loading capabilities.
5758 **
5759 ** See also the [load_extension() SQL function].
5760 */
5761 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5762 sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
5776 **
5777 ** ^Extension loading is off by default.
5778 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5779 ** to turn extension loading on and call it with onoff==0 to turn
5780 ** it back off again.
5781 **
5782 ** ^This interface enables or disables both the C-API
5783 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5784 ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5785 ** to enable or disable only the C-API.
5786 **
5787 ** <b>Security warning:</b> It is recommended that extension loading
5788 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5789 ** rather than this interface, so the [load_extension()] SQL function
5790 ** remains disabled. This will prevent SQL injections from giving attackers
5791 ** access to extension loading capabilities.
5792 */
5793 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5794
5795 /*
5796 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
8369
8370 /*
8371 ** CAPI3REF: Start a read transaction on an historical snapshot
8372 ** EXPERIMENTAL
8373 **
8374 ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8375 ** read transaction for schema S of
8376 ** [database connection] D such that the read transaction
8377 ** refers to historical [snapshot] P, rather than the most
8378 ** recent change to the database.
8379 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8380 ** or an appropriate [error code] if it fails.
8381 **
8382 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8383 ** the first operation following the [BEGIN] that takes the schema S
8384 ** out of [autocommit mode].
8385 ** ^In other words, schema S must not currently be in
8386 ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8387 ** database connection D must be out of [autocommit mode].
8388 ** ^A [snapshot] will fail to open if it has been overwritten by a
8389 ** [checkpoint].
8390 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8391 ** database connection D does not know that the database file for
8392 ** schema S is in [WAL mode]. A database connection might not know
8393 ** that the database file is in [WAL mode] if there has been no prior
8394 ** I/O on that database connection, or if the database entered [WAL mode]
8395 ** after the most recent I/O on the database connection.)^
8396 ** (Hint: Run "[PRAGMA application_id]" against a newly opened
8397 ** database connection in order to make it ready to use snapshots.)
8398 **
8399 ** The [sqlite3_snapshot_open()] interface is only available when the
8400 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8401 */
@@ -8341,10 +8415,37 @@
8415 **
8416 ** The [sqlite3_snapshot_free()] interface is only available when the
8417 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8418 */
8419 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8420
8421 /*
8422 ** CAPI3REF: Compare the ages of two snapshot handles.
8423 ** EXPERIMENTAL
8424 **
8425 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8426 ** of two valid snapshot handles.
8427 **
8428 ** If the two snapshot handles are not associated with the same database
8429 ** file, the result of the comparison is undefined.
8430 **
8431 ** Additionally, the result of the comparison is only valid if both of the
8432 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8433 ** last time the wal file was deleted. The wal file is deleted when the
8434 ** database is changed back to rollback mode or when the number of database
8435 ** clients drops to zero. If either snapshot handle was obtained before the
8436 ** wal file was last deleted, the value returned by this function
8437 ** is undefined.
8438 **
8439 ** Otherwise, this API returns a negative value if P1 refers to an older
8440 ** snapshot than P2, zero if the two handles refer to the same database
8441 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
8442 */
8443 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8444 sqlite3_snapshot *p1,
8445 sqlite3_snapshot *p2
8446 );
8447
8448 /*
8449 ** Undo the hack that converts floating point types to integer for
8450 ** builds on processors without floating point support.
8451 */
@@ -8476,11 +8577,11 @@
8577 #endif /* ifndef _SQLITE3RTREE_H_ */
8578
8579 /******** End of sqlite3rtree.h *********/
8580 /******** Begin file sqlite3session.h *********/
8581
8582 #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
8583 #define __SQLITESESSION_H_ 1
8584
8585 /*
8586 ** Make sure we can call this stuff from C++.
8587 */
@@ -9750,11 +9851,11 @@
9851 */
9852 #if 0
9853 }
9854 #endif
9855
9856 #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
9857
9858 /******** End of sqlite3session.h *********/
9859 /******** Begin file fts5.h *********/
9860 /*
9861 ** 2014 May 31
@@ -9898,15 +9999,17 @@
9999 ** of the current query. Specifically, a query equivalent to:
10000 **
10001 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
10002 **
10003 ** with $p set to a phrase equivalent to the phrase iPhrase of the
10004 ** current query is executed. Any column filter that applies to
10005 ** phrase iPhrase of the current query is included in $p. For each
10006 ** row visited, the callback function passed as the fourth argument
10007 ** is invoked. The context and API objects passed to the callback
10008 ** function may be used to access the properties of each matched row.
10009 ** Invoking Api.xUserData() returns a copy of the pointer passed as
10010 ** the third argument to pUserData.
10011 **
10012 ** If the callback function returns any value other than SQLITE_OK, the
10013 ** query is abandoned and the xQueryPhrase function returns immediately.
10014 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
10015 ** Otherwise, the error code is propagated upwards.
@@ -10814,11 +10917,11 @@
10917 **
10918 ** When doing coverage testing ALWAYS and NEVER are hard-coded to
10919 ** be true and false so that the unreachable code they specify will
10920 ** not be counted as untested code.
10921 */
10922 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST)
10923 # define ALWAYS(X) (1)
10924 # define NEVER(X) (0)
10925 #elif !defined(NDEBUG)
10926 # define ALWAYS(X) ((X)?1:(assert(0),0))
10927 # define NEVER(X) ((X)?(assert(0),1):0)
@@ -11019,80 +11122,80 @@
11122 #define TK_LP 22
11123 #define TK_RP 23
11124 #define TK_AS 24
11125 #define TK_WITHOUT 25
11126 #define TK_COMMA 26
11127 #define TK_OR 27
11128 #define TK_AND 28
11129 #define TK_IS 29
11130 #define TK_MATCH 30
11131 #define TK_LIKE_KW 31
11132 #define TK_BETWEEN 32
11133 #define TK_IN 33
11134 #define TK_ISNULL 34
11135 #define TK_NOTNULL 35
11136 #define TK_NE 36
11137 #define TK_EQ 37
11138 #define TK_GT 38
11139 #define TK_LE 39
11140 #define TK_LT 40
11141 #define TK_GE 41
11142 #define TK_ESCAPE 42
11143 #define TK_BITAND 43
11144 #define TK_BITOR 44
11145 #define TK_LSHIFT 45
11146 #define TK_RSHIFT 46
11147 #define TK_PLUS 47
11148 #define TK_MINUS 48
11149 #define TK_STAR 49
11150 #define TK_SLASH 50
11151 #define TK_REM 51
11152 #define TK_CONCAT 52
11153 #define TK_COLLATE 53
11154 #define TK_BITNOT 54
11155 #define TK_ID 55
11156 #define TK_INDEXED 56
11157 #define TK_ABORT 57
11158 #define TK_ACTION 58
11159 #define TK_AFTER 59
11160 #define TK_ANALYZE 60
11161 #define TK_ASC 61
11162 #define TK_ATTACH 62
11163 #define TK_BEFORE 63
11164 #define TK_BY 64
11165 #define TK_CASCADE 65
11166 #define TK_CAST 66
11167 #define TK_COLUMNKW 67
11168 #define TK_CONFLICT 68
11169 #define TK_DATABASE 69
11170 #define TK_DESC 70
11171 #define TK_DETACH 71
11172 #define TK_EACH 72
11173 #define TK_FAIL 73
11174 #define TK_FOR 74
11175 #define TK_IGNORE 75
11176 #define TK_INITIALLY 76
11177 #define TK_INSTEAD 77
11178 #define TK_NO 78
11179 #define TK_KEY 79
11180 #define TK_OF 80
11181 #define TK_OFFSET 81
11182 #define TK_PRAGMA 82
11183 #define TK_RAISE 83
11184 #define TK_RECURSIVE 84
11185 #define TK_REPLACE 85
11186 #define TK_RESTRICT 86
11187 #define TK_ROW 87
11188 #define TK_TRIGGER 88
11189 #define TK_VACUUM 89
11190 #define TK_VIEW 90
11191 #define TK_VIRTUAL 91
11192 #define TK_WITH 92
11193 #define TK_REINDEX 93
11194 #define TK_RENAME 94
11195 #define TK_CTIME_KW 95
11196 #define TK_ANY 96
11197 #define TK_STRING 97
11198 #define TK_JOIN_KW 98
11199 #define TK_CONSTRAINT 99
11200 #define TK_DEFAULT 100
11201 #define TK_NULL 101
@@ -12103,11 +12206,11 @@
12206 ** as an instance of the following structure:
12207 */
12208 struct VdbeOp {
12209 u8 opcode; /* What operation to perform */
12210 signed char p4type; /* One of the P4_xxx constants for p4 */
12211 u8 notUsed1;
12212 u8 p5; /* Fifth parameter is an unsigned character */
12213 int p1; /* First operand */
12214 int p2; /* Second parameter (often the jump destination) */
12215 int p3; /* The third parameter */
12216 union p4union { /* fourth parameter */
@@ -12246,157 +12349,156 @@
12349 #define OP_Vacuum 10
12350 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
12351 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
12352 #define OP_Goto 13
12353 #define OP_Gosub 14
12354 #define OP_InitCoroutine 15
12355 #define OP_Yield 16
12356 #define OP_MustBeInt 17
12357 #define OP_Jump 18
12358 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12359 #define OP_Once 20
12360 #define OP_If 21
12361 #define OP_IfNot 22
12362 #define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12363 #define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12364 #define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12365 #define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12366 #define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12367 #define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12368 #define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12369 #define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12370 #define OP_Found 31 /* synopsis: key=r[P3@P4] */
12371 #define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12372 #define OP_Last 33
12373 #define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12374 #define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12375 #define OP_Ne 36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12376 #define OP_Eq 37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12377 #define OP_Gt 38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12378 #define OP_Le 39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12379 #define OP_Lt 40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12380 #define OP_Ge 41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12381 #define OP_SorterSort 42
12382 #define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12383 #define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12384 #define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12385 #define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12386 #define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12387 #define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12388 #define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12389 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12390 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12391 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12392 #define OP_Sort 53
12393 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12394 #define OP_Rewind 55
12395 #define OP_IdxLE 56 /* synopsis: key=r[P3@P4] */
12396 #define OP_IdxGT 57 /* synopsis: key=r[P3@P4] */
12397 #define OP_IdxLT 58 /* synopsis: key=r[P3@P4] */
12398 #define OP_IdxGE 59 /* synopsis: key=r[P3@P4] */
12399 #define OP_RowSetRead 60 /* synopsis: r[P3]=rowset(P1) */
12400 #define OP_RowSetTest 61 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12401 #define OP_Program 62
12402 #define OP_FkIfZero 63 /* synopsis: if fkctr[P1]==0 goto P2 */
12403 #define OP_IfPos 64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12404 #define OP_IfNotZero 65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12405 #define OP_DecrJumpZero 66 /* synopsis: if (--r[P1])==0 goto P2 */
12406 #define OP_IncrVacuum 67
12407 #define OP_VNext 68
12408 #define OP_Init 69 /* synopsis: Start at P2 */
12409 #define OP_Return 70
12410 #define OP_EndCoroutine 71
12411 #define OP_HaltIfNull 72 /* synopsis: if r[P3]=null halt */
12412 #define OP_Halt 73
12413 #define OP_Integer 74 /* synopsis: r[P2]=P1 */
12414 #define OP_Int64 75 /* synopsis: r[P2]=P4 */
12415 #define OP_String 76 /* synopsis: r[P2]='P4' (len=P1) */
12416 #define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
12417 #define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
12418 #define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
12419 #define OP_Variable 80 /* synopsis: r[P2]=parameter(P1,P4) */
12420 #define OP_Move 81 /* synopsis: r[P2@P3]=r[P1@P3] */
12421 #define OP_Copy 82 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12422 #define OP_SCopy 83 /* synopsis: r[P2]=r[P1] */
12423 #define OP_IntCopy 84 /* synopsis: r[P2]=r[P1] */
12424 #define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */
12425 #define OP_CollSeq 86
12426 #define OP_Function0 87 /* synopsis: r[P3]=func(r[P2@P5]) */
12427 #define OP_Function 88 /* synopsis: r[P3]=func(r[P2@P5]) */
12428 #define OP_AddImm 89 /* synopsis: r[P1]=r[P1]+P2 */
12429 #define OP_RealAffinity 90
12430 #define OP_Cast 91 /* synopsis: affinity(r[P1]) */
12431 #define OP_Permutation 92
12432 #define OP_Compare 93 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12433 #define OP_Column 94 /* synopsis: r[P3]=PX */
12434 #define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */
12435 #define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12436 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12437 #define OP_Count 98 /* synopsis: r[P2]=count() */
12438 #define OP_ReadCookie 99
12439 #define OP_SetCookie 100
12440 #define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
12441 #define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
12442 #define OP_OpenWrite 103 /* synopsis: root=P2 iDb=P3 */
12443 #define OP_OpenAutoindex 104 /* synopsis: nColumn=P2 */
12444 #define OP_OpenEphemeral 105 /* synopsis: nColumn=P2 */
12445 #define OP_SorterOpen 106
12446 #define OP_SequenceTest 107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12447 #define OP_OpenPseudo 108 /* synopsis: P3 columns in r[P2] */
12448 #define OP_Close 109
12449 #define OP_ColumnsUsed 110
12450 #define OP_Sequence 111 /* synopsis: r[P2]=cursor[P1].ctr++ */
12451 #define OP_NewRowid 112 /* synopsis: r[P2]=rowid */
12452 #define OP_Insert 113 /* synopsis: intkey=r[P3] data=r[P2] */
12453 #define OP_InsertInt 114 /* synopsis: intkey=P3 data=r[P2] */
12454 #define OP_Delete 115
12455 #define OP_ResetCount 116
12456 #define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12457 #define OP_SorterData 118 /* synopsis: r[P2]=data */
12458 #define OP_RowKey 119 /* synopsis: r[P2]=key */
12459 #define OP_RowData 120 /* synopsis: r[P2]=data */
12460 #define OP_Rowid 121 /* synopsis: r[P2]=rowid */
12461 #define OP_NullRow 122
12462 #define OP_SorterInsert 123
12463 #define OP_IdxInsert 124 /* synopsis: key=r[P2] */
12464 #define OP_IdxDelete 125 /* synopsis: key=r[P2@P3] */
12465 #define OP_Seek 126 /* synopsis: Move P3 to P1.rowid */
12466 #define OP_IdxRowid 127 /* synopsis: r[P2]=rowid */
12467 #define OP_Destroy 128
12468 #define OP_Clear 129
12469 #define OP_ResetSorter 130
12470 #define OP_CreateIndex 131 /* synopsis: r[P2]=root iDb=P1 */
12471 #define OP_CreateTable 132 /* synopsis: r[P2]=root iDb=P1 */
12472 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12473 #define OP_ParseSchema 134
12474 #define OP_LoadAnalysis 135
12475 #define OP_DropTable 136
12476 #define OP_DropIndex 137
12477 #define OP_DropTrigger 138
12478 #define OP_IntegrityCk 139
12479 #define OP_RowSetAdd 140 /* synopsis: rowset(P1)=r[P2] */
12480 #define OP_Param 141
12481 #define OP_FkCounter 142 /* synopsis: fkctr[P1]+=P2 */
12482 #define OP_MemMax 143 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12483 #define OP_OffsetLimit 144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12484 #define OP_AggStep0 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12485 #define OP_AggStep 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12486 #define OP_AggFinal 147 /* synopsis: accum=r[P1] N=P2 */
12487 #define OP_Expire 148
12488 #define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */
12489 #define OP_VBegin 150
12490 #define OP_VCreate 151
12491 #define OP_VDestroy 152
12492 #define OP_VOpen 153
12493 #define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */
12494 #define OP_VRename 155
12495 #define OP_Pagecount 156
12496 #define OP_MaxPgcnt 157
12497 #define OP_CursorHint 158
12498 #define OP_Noop 159
12499 #define OP_Explain 160
 
12500
12501 /* Properties such as "out2" or "jump" that are specified in
12502 ** comments following the "case" for each opcode in the vdbe.c
12503 ** are encoded into bitvectors as follows:
12504 */
@@ -12406,30 +12508,38 @@
12508 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
12509 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12510 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12511 #define OPFLG_INITIALIZER {\
12512 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12513 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12514 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12515 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12516 /* 32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12517 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12518 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12519 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
12520 /* 64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
12521 /* 72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
12522 /* 80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
12523 /* 88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
12524 /* 96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12525 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12526 /* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12527 /* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
12528 /* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12529 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
12530 /* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12531 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12532 /* 160 */ 0x00,}
12533
12534 /* The sqlite3P2Values() routine is able to run faster if it knows
12535 ** the value of the largest JUMP opcode. The smaller the maximum
12536 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12537 ** generated this include file strives to group all JUMP opcodes
12538 ** together near the beginning of the list.
12539 */
12540 #define SQLITE_MX_JUMP_OPCODE 69 /* Maximum JUMP opcode */
12541
12542 /************** End of opcodes.h *********************************************/
12543 /************** Continuing where we left off in vdbe.h ***********************/
12544
12545 /*
@@ -12648,11 +12758,15 @@
12758 #define PAGER_LOCKINGMODE_QUERY -1
12759 #define PAGER_LOCKINGMODE_NORMAL 0
12760 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
12761
12762 /*
12763 ** Numeric constants that encode the journalmode.
12764 **
12765 ** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
12766 ** are exposed in the API via the "PRAGMA journal_mode" command and
12767 ** therefore cannot be changed without a compatibility break.
12768 */
12769 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
12770 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
12771 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
12772 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12780,15 @@
12780 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
12781 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
12782
12783 /*
12784 ** Flags for sqlite3PagerSetFlags()
12785 **
12786 ** Value constraints (enforced via assert()):
12787 ** PAGER_FULLFSYNC == SQLITE_FullFSync
12788 ** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
12789 ** PAGER_CACHE_SPILL == SQLITE_CacheSpill
12790 */
12791 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
12792 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
12793 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
12794 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12835,11 +12954,11 @@
12954 */
12955 struct PgHdr {
12956 sqlite3_pcache_page *pPage; /* Pcache object page handle */
12957 void *pData; /* Page data */
12958 void *pExtra; /* Extra content */
12959 PgHdr *pDirty; /* Transient list of dirty sorted by pgno */
12960 Pager *pPager; /* The pager this page is part of */
12961 Pgno pgno; /* Page number for this page */
12962 #ifdef SQLITE_CHECK_PAGES
12963 u32 pageHash; /* Hash of page content */
12964 #endif
@@ -12860,15 +12979,14 @@
12979 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
12980 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
12981 #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */
12982 #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before
12983 ** writing this page to the database */
12984 #define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */
12985 #define PGHDR_MMAP 0x020 /* This is an mmap page object */
 
12986
12987 #define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */
12988
12989 /* Initialize and shutdown the page cache subsystem */
12990 SQLITE_PRIVATE int sqlite3PcacheInitialize(void);
12991 SQLITE_PRIVATE void sqlite3PcacheShutdown(void);
12992
@@ -12908,10 +13026,11 @@
13026
13027 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
13028 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
13029 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
13030 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
13031 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*);
13032
13033 /* Change a page number. Used by incr-vacuum. */
13034 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
13035
13036 /* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12945,10 +13064,15 @@
13064 ** interface is only available if SQLITE_CHECK_PAGES is defined when the
13065 ** library is built.
13066 */
13067 SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *));
13068 #endif
13069
13070 #if defined(SQLITE_DEBUG)
13071 /* Check invariants on a PgHdr object */
13072 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*);
13073 #endif
13074
13075 /* Set and get the suggested cache-size for the specified pager-cache.
13076 **
13077 ** If no global maximum is configured, then the system attempts to limit
13078 ** the total number of pages cached by purgeable pager-caches to the sum
@@ -12981,10 +13105,13 @@
13105 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
13106
13107 /* Return the header size */
13108 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
13109 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
13110
13111 /* Number of dirty pages as a percentage of the configured cache size */
13112 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*);
13113
13114 #endif /* _PCACHE_H_ */
13115
13116 /************** End of pcache.h **********************************************/
13117 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13338,11 @@
13338 SQLITE_PRIVATE int sqlite3OsInit(void);
13339
13340 /*
13341 ** Functions for accessing sqlite3_file methods
13342 */
13343 SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
13344 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
13345 SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
13346 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
13347 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
13348 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13383,11 @@
13383 /*
13384 ** Convenience functions for opening and closing files using
13385 ** sqlite3_malloc() to obtain space for the file-handle structure.
13386 */
13387 SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13388 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
13389
13390 #endif /* _SQLITE_OS_H_ */
13391
13392 /************** End of os.h **************************************************/
13393 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13792,15 @@
13792 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
13793 #define ENC(db) ((db)->enc)
13794
13795 /*
13796 ** Possible values for the sqlite3.flags.
13797 **
13798 ** Value constraints (enforced via assert()):
13799 ** SQLITE_FullFSync == PAGER_FULLFSYNC
13800 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
13801 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL
13802 */
13803 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
13804 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
13805 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
13806 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13824,18 @@
13824 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
13825 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
13826 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
13827 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
13828 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13829 #define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */
13830 #define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */
13831 #define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */
13832 #define SQLITE_QueryOnly 0x04000000 /* Disable database changes */
13833 #define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */
13834 #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
13835 #define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */
13836 #define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */
13837
13838
13839 /*
13840 ** Bits of the sqlite3.dbOptFlags field that are used by the
13841 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13932,17 @@
13932 /*
13933 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
13934 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
13935 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
13936 ** are assert() statements in the code to verify this.
13937 **
13938 ** Value constraints (enforced via assert()):
13939 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
13940 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
13941 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
13942 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
13943 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
13944 */
13945 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
13946 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
13947 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
13948 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14938,13 @@
14938
14939
14940 /*
14941 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
14942 ** and the WhereInfo.wctrlFlags member.
14943 **
14944 ** Value constraints (enforced via assert()):
14945 ** WHERE_USE_LIMIT == SF_FixedLimit
14946 */
14947 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
14948 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
14949 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
14950 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14815,10 +14958,11 @@
14958 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
14959 #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */
14960 #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */
14961 #define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */
14962 #define WHERE_USE_LIMIT 0x4000 /* There is a constant LIMIT clause */
14963 #define WHERE_SEEK_TABLE 0x8000 /* Do not defer seeks on main table */
14964
14965 /* Allowed return values from sqlite3WhereIsDistinct()
14966 */
14967 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
14968 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -14858,20 +15002,22 @@
15002 };
15003
15004 /*
15005 ** Allowed values for the NameContext, ncFlags field.
15006 **
15007 ** Value constraints (all checked via assert()):
15008 ** NC_HasAgg == SF_HasAgg
15009 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
15010 **
15011 */
15012 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
15013 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
15014 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
15015 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
15016 #define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
15017 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
15018 #define NC_VarSelect 0x0040 /* A correlated subquery has been seen */
15019 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
15020
15021 /*
15022 ** An instance of the following structure contains all information
15023 ** needed to generate code for a single SELECT statement.
@@ -14915,28 +15061,34 @@
15061 };
15062
15063 /*
15064 ** Allowed values for Select.selFlags. The "SF" prefix stands for
15065 ** "Select Flag".
15066 **
15067 ** Value constraints (all checked via assert())
15068 ** SF_HasAgg == NC_HasAgg
15069 ** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
15070 ** SF_FixedLimit == WHERE_USE_LIMIT
15071 */
15072 #define SF_Distinct 0x00001 /* Output should be DISTINCT */
15073 #define SF_All 0x00002 /* Includes the ALL keyword */
15074 #define SF_Resolved 0x00004 /* Identifiers have been resolved */
15075 #define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
15076 #define SF_HasAgg 0x00010 /* Contains aggregate functions */
15077 #define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
15078 #define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
15079 #define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
15080 #define SF_Compound 0x00100 /* Part of a compound query */
15081 #define SF_Values 0x00200 /* Synthesized from VALUES clause */
15082 #define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
15083 #define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
15084 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
15085 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
15086 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
15087 #define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
15088 #define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
15089 #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
15090
15091
15092 /*
15093 ** The results of a SELECT can be distributed in several ways, as defined
15094 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15281,11 @@
15281 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
15282 u8 mayAbort; /* True if statement may throw an ABORT exception */
15283 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
15284 u8 okConstFactor; /* OK to factor out constants */
15285 u8 disableLookaside; /* Number of times lookaside has been disabled */
15286 u8 nColCache; /* Number of entries in aColCache[] */
15287 int aTempReg[8]; /* Holding area for temporary registers */
15288 int nRangeReg; /* Size of the temporary register block */
15289 int iRangeReg; /* First register in temporary register block */
15290 int nErr; /* Number of errors seen */
15291 int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15395,19 @@
15395 Parse *pParse; /* The Parse structure */
15396 };
15397
15398 /*
15399 ** Bitfield flags for P5 value in various opcodes.
15400 **
15401 ** Value constraints (enforced via assert()):
15402 ** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
15403 ** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
15404 ** OPFLAG_BULKCSR == BTREE_BULKLOAD
15405 ** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
15406 ** OPFLAG_FORDELETE == BTREE_FORDELETE
15407 ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
15408 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE
15409 */
15410 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15411 /* Also used in P2 (not P5) of OP_Delete */
15412 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15413 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15778,20 @@
15778 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
15779 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
15780 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
15781 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
15782 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
15783 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
15784 #else
15785 # define sqlite3Toupper(x) toupper((unsigned char)(x))
15786 # define sqlite3Isspace(x) isspace((unsigned char)(x))
15787 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
15788 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
15789 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
15790 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
15791 # define sqlite3Tolower(x) tolower((unsigned char)(x))
15792 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
15793 #endif
15794 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
15795 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
15796 #endif
15797
@@ -15747,11 +15911,11 @@
15911 #endif
15912
15913
15914 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
15915 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15916 SQLITE_PRIVATE void sqlite3Dequote(char*);
15917 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
15918 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
15919 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
15920 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
15921 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15928,11 @@
15928 #endif
15929 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
15930 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
15931 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
15932 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
15933 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
15934 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
15935 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
15936 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
15937 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
15938 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16724,11 @@
16724 ** isdigit() 0x04
16725 ** isalnum() 0x06
16726 ** isxdigit() 0x08
16727 ** toupper() 0x20
16728 ** SQLite identifier character 0x40
16729 ** Quote character 0x80
16730 **
16731 ** Bit 0x20 is set if the mapped character requires translation to upper
16732 ** case. i.e. if the character is a lower-case ASCII character.
16733 ** If x is a lower-case ASCII character, then its upper-case equivalent
16734 ** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16750,20 @@
16750 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
16751 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
16752 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
16753 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
16754 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16755 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
16756 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
16757 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
16758 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
16759
16760 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
16761 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
16762 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16763 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16764 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16765 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
16766 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
16767 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
16768
16769 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18347,19 @@
18347 /* #include <assert.h> */
18348 #include <time.h>
18349
18350 #ifndef SQLITE_OMIT_DATETIME_FUNCS
18351
18352 /*
18353 ** The MSVC CRT on Windows CE may not have a localtime() function.
18354 ** So declare a substitute. The substitute function itself is
18355 ** defined in "os_win.c".
18356 */
18357 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
18358 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
18359 struct tm *__cdecl localtime(const time_t *);
18360 #endif
18361
18362 /*
18363 ** A structure for holding a single date and time.
18364 */
18365 typedef struct DateTime DateTime;
@@ -18549,10 +18724,11 @@
18724 p->validYMD = 0;
18725 p->validHMS = 0;
18726 p->validTZ = 0;
18727 }
18728
18729 #ifndef SQLITE_OMIT_LOCALTIME
18730 /*
18731 ** On recent Windows platforms, the localtime_s() function is available
18732 ** as part of the "Secure CRT". It is essentially equivalent to
18733 ** localtime_r() available under most POSIX platforms, except that the
18734 ** order of the parameters is reversed.
@@ -18567,11 +18743,10 @@
18743 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
18744 #undef HAVE_LOCALTIME_S
18745 #define HAVE_LOCALTIME_S 1
18746 #endif
18747
 
18748 /*
18749 ** The following routine implements the rough equivalent of localtime_r()
18750 ** using whatever operating-system specific localtime facility that
18751 ** is available. This routine returns 0 on success and
18752 ** non-zero on any kind of error.
@@ -19371,17 +19546,15 @@
19546 ** The following routines are convenience wrappers around methods
19547 ** of the sqlite3_file object. This is mostly just syntactic sugar. All
19548 ** of this would be completely automatic if SQLite were coded using
19549 ** C++ instead of plain old C.
19550 */
19551 SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *pId){
 
19552 if( pId->pMethods ){
19553 pId->pMethods->xClose(pId);
19554 pId->pMethods = 0;
19555 }
 
19556 }
19557 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
19558 DO_OS_MALLOC_TEST(id);
19559 return id->pMethods->xRead(id, pBuf, amt, offset);
19560 }
@@ -19595,16 +19768,14 @@
19768 }else{
19769 rc = SQLITE_NOMEM_BKPT;
19770 }
19771 return rc;
19772 }
19773 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
 
19774 assert( pFile );
19775 sqlite3OsClose(pFile);
19776 sqlite3_free(pFile);
 
19777 }
19778
19779 /*
19780 ** This function is a wrapper around the OS specific implementation of
19781 ** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -24280,30 +24451,30 @@
24451
24452 /*
24453 ** Conversion types fall into various categories as defined by the
24454 ** following enumeration.
24455 */
24456 #define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */
24457 #define etFLOAT 1 /* Floating point. %f */
24458 #define etEXP 2 /* Exponentional notation. %e and %E */
24459 #define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */
24460 #define etSIZE 4 /* Return number of characters processed so far. %n */
24461 #define etSTRING 5 /* Strings. %s */
24462 #define etDYNSTRING 6 /* Dynamically allocated strings. %z */
24463 #define etPERCENT 7 /* Percent symbol. %% */
24464 #define etCHARX 8 /* Characters. %c */
24465 /* The rest are extensions, not normally found in printf() */
24466 #define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */
24467 #define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
24468 NULL pointers replaced by SQL NULL. %Q */
24469 #define etTOKEN 11 /* a pointer to a Token structure */
24470 #define etSRCLIST 12 /* a pointer to a SrcList */
24471 #define etPOINTER 13 /* The %p conversion */
24472 #define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
24473 #define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
24474
24475 #define etINVALID 16 /* Any unrecognized conversion type */
24476
24477
24478 /*
24479 ** An "etByte" is an 8-bit unsigned value.
24480 */
@@ -24454,11 +24625,11 @@
24625 etByte flag_altform2; /* True if "!" flag is present */
24626 etByte flag_zeropad; /* True if field width constant starts with zero */
24627 etByte flag_long; /* True if "l" flag is present */
24628 etByte flag_longlong; /* True if the "ll" flag is present */
24629 etByte done; /* Loop termination flag */
24630 etByte xtype = etINVALID; /* Conversion paradigm */
24631 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
24632 u8 useIntern; /* Ok to use internal conversions (ex: %T) */
24633 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
24634 sqlite_uint64 longvalue; /* Value for integer types */
24635 LONGDOUBLE_TYPE realvalue; /* Value for real types */
@@ -27045,22 +27216,17 @@
27216 **
27217 ** 2002-Feb-14: This routine is extended to remove MS-Access style
27218 ** brackets from around identifiers. For example: "[a-b-c]" becomes
27219 ** "a-b-c".
27220 */
27221 SQLITE_PRIVATE void sqlite3Dequote(char *z){
27222 char quote;
27223 int i, j;
27224 if( z==0 ) return;
27225 quote = z[0];
27226 if( !sqlite3Isquote(quote) ) return;
27227 if( quote=='[' ) quote = ']';
 
 
 
 
 
27228 for(i=1, j=0;; i++){
27229 assert( z[i] );
27230 if( z[i]==quote ){
27231 if( z[i+1]==quote ){
27232 z[j++] = quote;
@@ -27071,11 +27237,10 @@
27237 }else{
27238 z[j++] = z[i];
27239 }
27240 }
27241 z[j] = 0;
 
27242 }
27243
27244 /*
27245 ** Generate a Token object from a string
27246 */
@@ -27164,11 +27329,11 @@
27329 int esign = 1; /* sign of exponent */
27330 int e = 0; /* exponent */
27331 int eValid = 1; /* True exponent is either not used or is well-formed */
27332 double result;
27333 int nDigits = 0;
27334 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
27335
27336 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27337 *pResult = 0.0; /* Default return value, in case of an error */
27338
27339 if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27342,11 @@
27342 int i;
27343 incr = 2;
27344 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27345 for(i=3-enc; i<length && z[i]==0; i+=2){}
27346 nonNum = i<length;
27347 zEnd = &z[i^1];
27348 z += (enc&1);
27349 }
27350
27351 /* skip leading spaces */
27352 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27358,10 @@
27358 z+=incr;
27359 }else if( *z=='+' ){
27360 z+=incr;
27361 }
27362
 
 
 
27363 /* copy max significant digits to significand */
27364 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27365 s = s*10 + (*z - '0');
27366 z+=incr, nDigits++;
27367 }
@@ -27212,24 +27374,30 @@
27374 /* if decimal point is present */
27375 if( *z=='.' ){
27376 z+=incr;
27377 /* copy digits from after decimal to significand
27378 ** (decrease exponent by d to shift decimal right) */
27379 while( z<zEnd && sqlite3Isdigit(*z) ){
27380 if( s<((LARGEST_INT64-9)/10) ){
27381 s = s*10 + (*z - '0');
27382 d--;
27383 }
27384 z+=incr, nDigits++;
27385 }
 
 
27386 }
27387 if( z>=zEnd ) goto do_atof_calc;
27388
27389 /* if exponent is present */
27390 if( *z=='e' || *z=='E' ){
27391 z+=incr;
27392 eValid = 0;
27393
27394 /* This branch is needed to avoid a (harmless) buffer overread. The
27395 ** special comment alerts the mutation tester that the correct answer
27396 ** is obtained even if the branch is omitted */
27397 if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
27398
27399 /* get sign of exponent */
27400 if( *z=='-' ){
27401 esign = -1;
27402 z+=incr;
27403 }else if( *z=='+' ){
@@ -27242,13 +27410,11 @@
27410 eValid = 1;
27411 }
27412 }
27413
27414 /* skip trailing spaces */
27415 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
 
 
27416
27417 do_atof_calc:
27418 /* adjust exponent by d, and update sign */
27419 e = (e*esign) + d;
27420 if( e<0 ) {
@@ -27256,45 +27422,55 @@
27422 e *= -1;
27423 } else {
27424 esign = 1;
27425 }
27426
27427 if( s==0 ) {
27428 /* In the IEEE 754 standard, zero is signed. */
27429 result = sign<0 ? -(double)0 : (double)0;
 
 
27430 } else {
27431 /* Attempt to reduce exponent.
27432 **
27433 ** Branches that are not required for the correct answer but which only
27434 ** help to obtain the correct answer faster are marked with special
27435 ** comments, as a hint to the mutation tester.
27436 */
27437 while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/
27438 if( esign>0 ){
27439 if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/
27440 s *= 10;
27441 }else{
27442 if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/
27443 s /= 10;
27444 }
27445 e--;
27446 }
27447
27448 /* adjust the sign of significand */
27449 s = sign<0 ? -s : s;
27450
27451 if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
27452 result = (double)s;
27453 }else{
27454 LONGDOUBLE_TYPE scale = 1.0;
27455 /* attempt to handle extremely small/large numbers better */
27456 if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
27457 if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
27458 while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27459 if( esign<0 ){
27460 result = s / scale;
27461 result /= 1.0e+308;
27462 }else{
27463 result = s * scale;
27464 result *= 1.0e+308;
27465 }
27466 }else{ assert( e>=342 );
27467 if( esign<0 ){
27468 result = 0.0*s;
27469 }else{
27470 result = 1e308*1e308*s; /* Infinity */
27471 }
27472 }
27473 }else{
27474 /* 1.0e+22 is the largest power of 10 than can be
27475 ** represented exactly. */
27476 while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27479,18 @@
27479 result = s / scale;
27480 }else{
27481 result = s * scale;
27482 }
27483 }
 
 
27484 }
27485 }
27486
27487 /* store the result */
27488 *pResult = result;
27489
27490 /* return true if number and no extra non-whitespace chracters after */
27491 return z==zEnd && nDigits>0 && eValid && nonNum==0;
27492 #else
27493 return !sqlite3Atoi64(z, pResult, length, enc);
27494 #endif /* SQLITE_OMIT_FLOATING_POINT */
27495 }
27496
@@ -27374,11 +27548,11 @@
27548 int incr;
27549 u64 u = 0;
27550 int neg = 0; /* assume positive */
27551 int i;
27552 int c = 0;
27553 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
27554 const char *zStart;
27555 const char *zEnd = zNum + length;
27556 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27557 if( enc==SQLITE_UTF8 ){
27558 incr = 1;
@@ -27385,11 +27559,11 @@
27559 }else{
27560 incr = 2;
27561 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27562 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
27563 nonNum = i<length;
27564 zEnd = &zNum[i^1];
27565 zNum += (enc&1);
27566 }
27567 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
27568 if( zNum<zEnd ){
27569 if( *zNum=='-' ){
@@ -27412,12 +27586,15 @@
27586 *pNum = (i64)u;
27587 }
27588 testcase( i==18 );
27589 testcase( i==19 );
27590 testcase( i==20 );
27591 if( &zNum[i]<zEnd /* Extra bytes at the end */
27592 || (i==0 && zStart==zNum) /* No digits */
27593 || i>19*incr /* Too many digits */
27594 || nonNum /* UTF16 with high-order bytes non-zero */
27595 ){
27596 /* zNum is empty or contains non-numeric text or is longer
27597 ** than 19 digits (thus guaranteeing that it is too large) */
27598 return 1;
27599 }else if( i<19*incr ){
27600 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27632,10 @@
27632 */
27633 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
27634 #ifndef SQLITE_OMIT_HEX_INTEGER
27635 if( z[0]=='0'
27636 && (z[1]=='x' || z[1]=='X')
 
27637 ){
27638 u64 u = 0;
27639 int i, k;
27640 for(i=2; z[i]=='0'; i++){}
27641 for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28393,11 @@
28393 LogEst y = 40;
28394 if( x<8 ){
28395 if( x<2 ) return 0;
28396 while( x<8 ){ y -= 10; x <<= 1; }
28397 }else{
28398 while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
28399 while( x>15 ){ y += 10; x >>= 1; }
28400 }
28401 return a[x&7] + y - 10;
28402 }
28403
@@ -28326,11 +28502,11 @@
28502 ** The hashing function.
28503 */
28504 static unsigned int strHash(const char *z){
28505 unsigned int h = 0;
28506 unsigned char c;
28507 while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
28508 h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
28509 }
28510 return h;
28511 }
28512
@@ -28419,11 +28595,11 @@
28595 ){
28596 HashElem *elem; /* Used to loop thru the element list */
28597 int count; /* Number of elements left to test */
28598 unsigned int h; /* The computed hash */
28599
28600 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
28601 struct _ht *pEntry;
28602 h = strHash(pKey) % pH->htsize;
28603 pEntry = &pH->ht[h];
28604 elem = pEntry->chain;
28605 count = pEntry->count;
@@ -28566,157 +28742,156 @@
28742 /* 10 */ "Vacuum" OpHelp(""),
28743 /* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
28744 /* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
28745 /* 13 */ "Goto" OpHelp(""),
28746 /* 14 */ "Gosub" OpHelp(""),
28747 /* 15 */ "InitCoroutine" OpHelp(""),
28748 /* 16 */ "Yield" OpHelp(""),
28749 /* 17 */ "MustBeInt" OpHelp(""),
28750 /* 18 */ "Jump" OpHelp(""),
28751 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28752 /* 20 */ "Once" OpHelp(""),
28753 /* 21 */ "If" OpHelp(""),
28754 /* 22 */ "IfNot" OpHelp(""),
28755 /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28756 /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28757 /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28758 /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28759 /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28760 /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28761 /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28762 /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
28763 /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
28764 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
28765 /* 33 */ "Last" OpHelp(""),
28766 /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28767 /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28768 /* 36 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28769 /* 37 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28770 /* 38 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28771 /* 39 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28772 /* 40 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28773 /* 41 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28774 /* 42 */ "SorterSort" OpHelp(""),
28775 /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28776 /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28777 /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28778 /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28779 /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28780 /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28781 /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28782 /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28783 /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28784 /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28785 /* 53 */ "Sort" OpHelp(""),
28786 /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28787 /* 55 */ "Rewind" OpHelp(""),
28788 /* 56 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28789 /* 57 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28790 /* 58 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28791 /* 59 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28792 /* 60 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28793 /* 61 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28794 /* 62 */ "Program" OpHelp(""),
28795 /* 63 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28796 /* 64 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28797 /* 65 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28798 /* 66 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28799 /* 67 */ "IncrVacuum" OpHelp(""),
28800 /* 68 */ "VNext" OpHelp(""),
28801 /* 69 */ "Init" OpHelp("Start at P2"),
28802 /* 70 */ "Return" OpHelp(""),
28803 /* 71 */ "EndCoroutine" OpHelp(""),
28804 /* 72 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28805 /* 73 */ "Halt" OpHelp(""),
28806 /* 74 */ "Integer" OpHelp("r[P2]=P1"),
28807 /* 75 */ "Int64" OpHelp("r[P2]=P4"),
28808 /* 76 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28809 /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
28810 /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
28811 /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28812 /* 80 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28813 /* 81 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28814 /* 82 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28815 /* 83 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28816 /* 84 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28817 /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28818 /* 86 */ "CollSeq" OpHelp(""),
28819 /* 87 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28820 /* 88 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28821 /* 89 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28822 /* 90 */ "RealAffinity" OpHelp(""),
28823 /* 91 */ "Cast" OpHelp("affinity(r[P1])"),
28824 /* 92 */ "Permutation" OpHelp(""),
28825 /* 93 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28826 /* 94 */ "Column" OpHelp("r[P3]=PX"),
28827 /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28828 /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28829 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
28830 /* 98 */ "Count" OpHelp("r[P2]=count()"),
28831 /* 99 */ "ReadCookie" OpHelp(""),
28832 /* 100 */ "SetCookie" OpHelp(""),
28833 /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28834 /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28835 /* 103 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28836 /* 104 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28837 /* 105 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28838 /* 106 */ "SorterOpen" OpHelp(""),
28839 /* 107 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28840 /* 108 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28841 /* 109 */ "Close" OpHelp(""),
28842 /* 110 */ "ColumnsUsed" OpHelp(""),
28843 /* 111 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28844 /* 112 */ "NewRowid" OpHelp("r[P2]=rowid"),
28845 /* 113 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28846 /* 114 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28847 /* 115 */ "Delete" OpHelp(""),
28848 /* 116 */ "ResetCount" OpHelp(""),
28849 /* 117 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28850 /* 118 */ "SorterData" OpHelp("r[P2]=data"),
28851 /* 119 */ "RowKey" OpHelp("r[P2]=key"),
28852 /* 120 */ "RowData" OpHelp("r[P2]=data"),
28853 /* 121 */ "Rowid" OpHelp("r[P2]=rowid"),
28854 /* 122 */ "NullRow" OpHelp(""),
28855 /* 123 */ "SorterInsert" OpHelp(""),
28856 /* 124 */ "IdxInsert" OpHelp("key=r[P2]"),
28857 /* 125 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28858 /* 126 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28859 /* 127 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28860 /* 128 */ "Destroy" OpHelp(""),
28861 /* 129 */ "Clear" OpHelp(""),
28862 /* 130 */ "ResetSorter" OpHelp(""),
28863 /* 131 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28864 /* 132 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28865 /* 133 */ "Real" OpHelp("r[P2]=P4"),
28866 /* 134 */ "ParseSchema" OpHelp(""),
28867 /* 135 */ "LoadAnalysis" OpHelp(""),
28868 /* 136 */ "DropTable" OpHelp(""),
28869 /* 137 */ "DropIndex" OpHelp(""),
28870 /* 138 */ "DropTrigger" OpHelp(""),
28871 /* 139 */ "IntegrityCk" OpHelp(""),
28872 /* 140 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28873 /* 141 */ "Param" OpHelp(""),
28874 /* 142 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28875 /* 143 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28876 /* 144 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28877 /* 145 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28878 /* 146 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28879 /* 147 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28880 /* 148 */ "Expire" OpHelp(""),
28881 /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28882 /* 150 */ "VBegin" OpHelp(""),
28883 /* 151 */ "VCreate" OpHelp(""),
28884 /* 152 */ "VDestroy" OpHelp(""),
28885 /* 153 */ "VOpen" OpHelp(""),
28886 /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28887 /* 155 */ "VRename" OpHelp(""),
28888 /* 156 */ "Pagecount" OpHelp(""),
28889 /* 157 */ "MaxPgcnt" OpHelp(""),
28890 /* 158 */ "CursorHint" OpHelp(""),
28891 /* 159 */ "Noop" OpHelp(""),
28892 /* 160 */ "Explain" OpHelp(""),
 
28893 };
28894 return azName[i];
28895 }
28896 #endif
28897
@@ -29325,11 +29500,11 @@
29500 #if defined(USE_PREAD64)
29501 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
29502 #else
29503 { "pread64", (sqlite3_syscall_ptr)0, 0 },
29504 #endif
29505 #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
29506
29507 { "write", (sqlite3_syscall_ptr)write, 0 },
29508 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
29509
29510 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29518,11 @@
29518 #if defined(USE_PREAD64)
29519 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
29520 #else
29521 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
29522 #endif
29523 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
29524 aSyscall[13].pCurrent)
29525
29526 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
29527 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
29528
@@ -33208,14 +33383,16 @@
33383 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
33384 #endif
33385 pShmNode->h = -1;
33386 pDbFd->pInode->pShmNode = pShmNode;
33387 pShmNode->pInode = pDbFd->pInode;
33388 if( sqlite3GlobalConfig.bCoreMutex ){
33389 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33390 if( pShmNode->mutex==0 ){
33391 rc = SQLITE_NOMEM_BKPT;
33392 goto shm_open_err;
33393 }
33394 }
33395
33396 if( pInode->bProcessLock==0 ){
33397 int openFlags = O_RDWR | O_CREAT;
33398 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34507,28 @@
34507 "/var/tmp",
34508 "/usr/tmp",
34509 "/tmp",
34510 "."
34511 };
34512 unsigned int i = 0;
34513 struct stat buf;
34514 const char *zDir = sqlite3_temp_directory;
34515
34516 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
34517 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34518 while(1){
34519 if( zDir!=0
34520 && osStat(zDir, &buf)==0
34521 && S_ISDIR(buf.st_mode)
34522 && osAccess(zDir, 03)==0
34523 ){
34524 return zDir;
34525 }
34526 if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
34527 zDir = azDirs[i++];
34528 }
34529 return 0;
34530 }
34531
34532 /*
34533 ** Create a temporary file name in zBuf. zBuf must be allocated
34534 ** by the calling process and must be big enough to hold at least
@@ -34359,13 +34540,15 @@
34540
34541 /* It's odd to simulate an io-error here, but really this is just
34542 ** using the io-error infrastructure to test that SQLite handles this
34543 ** function failing.
34544 */
34545 zBuf[0] = 0;
34546 SimulateIOError( return SQLITE_IOERR );
34547
34548 zDir = unixTempFileDir();
34549 if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
34550 do{
34551 u64 r;
34552 sqlite3_randomness(sizeof(r), &r);
34553 assert( nBuf>2 );
34554 zBuf[nBuf-2] = 0;
@@ -37963,12 +38146,12 @@
38146 */
38147 SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
38148 int rc;
38149 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
38150 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
38151 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
38152 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
38153 sqlite3_mutex_enter(pMaster);
38154 sqlite3_mutex_enter(pMem);
38155 winMemAssertMagic();
38156 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
38157 /*
@@ -38821,20 +39004,21 @@
39004 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
39005 );
39006 }
39007 }
39008
39009 /*
39010 ** This #if does not rely on the SQLITE_OS_WINCE define because the
39011 ** corresponding section in "date.c" cannot use it.
39012 */
39013 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
39014 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
39015 /*
39016 ** The MSVC CRT on Windows CE may not have a localtime() function.
39017 ** So define a substitute.
39018 */
39019 /* # include <time.h> */
39020 struct tm *__cdecl localtime(const time_t *t)
39021 {
39022 static struct tm y;
39023 FILETIME uTm, lTm;
39024 SYSTEMTIME pTm;
@@ -38854,10 +39038,14 @@
39038 y.tm_sec = pTm.wSecond;
39039 return &y;
39040 }
39041 #endif
39042
39043 #if SQLITE_OS_WINCE
39044 /*************************************************************************
39045 ** This section contains code for WinCE only.
39046 */
39047 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
39048
39049 /*
39050 ** Acquire a lock on the handle h
39051 */
@@ -39867,13 +40055,12 @@
40055 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
40056 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
40057 ** the PENDING_LOCK byte is temporary.
40058 */
40059 newLocktype = pFile->locktype;
40060 if( pFile->locktype==NO_LOCK
40061 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
 
40062 ){
40063 int cnt = 3;
40064 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
40065 PENDING_BYTE, 0, 1, 0))==0 ){
40066 /* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40650,16 @@
40650 pNew = 0;
40651 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
40652 pShmNode->pNext = winShmNodeList;
40653 winShmNodeList = pShmNode;
40654
40655 if( sqlite3GlobalConfig.bCoreMutex ){
40656 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40657 if( pShmNode->mutex==0 ){
40658 rc = SQLITE_IOERR_NOMEM_BKPT;
40659 goto shm_open_err;
40660 }
40661 }
40662
40663 rc = winOpen(pDbFd->pVfs,
40664 pShmNode->zFilename, /* Name of the file (UTF-8) */
40665 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -42930,11 +43119,33 @@
43119 ** This file implements that page cache.
43120 */
43121 /* #include "sqliteInt.h" */
43122
43123 /*
43124 ** A complete page cache is an instance of this structure. Every
43125 ** entry in the cache holds a single page of the database file. The
43126 ** btree layer only operates on the cached copy of the database pages.
43127 **
43128 ** A page cache entry is "clean" if it exactly matches what is currently
43129 ** on disk. A page is "dirty" if it has been modified and needs to be
43130 ** persisted to disk.
43131 **
43132 ** pDirty, pDirtyTail, pSynced:
43133 ** All dirty pages are linked into the doubly linked list using
43134 ** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order
43135 ** such that p was added to the list more recently than p->pDirtyNext.
43136 ** PCache.pDirty points to the first (newest) element in the list and
43137 ** pDirtyTail to the last (oldest).
43138 **
43139 ** The PCache.pSynced variable is used to optimize searching for a dirty
43140 ** page to eject from the cache mid-transaction. It is better to eject
43141 ** a page that does not require a journal sync than one that does.
43142 ** Therefore, pSynced is maintained to that it *almost* always points
43143 ** to either the oldest page in the pDirty/pDirtyTail list that has a
43144 ** clear PGHDR_NEED_SYNC flag or to a page that is older than this one
43145 ** (so that the right page to eject can be found by following pDirtyPrev
43146 ** pointers).
43147 */
43148 struct PCache {
43149 PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
43150 PgHdr *pSynced; /* Last synced page in dirty page list */
43151 int nRefSum; /* Sum of ref counts over all pages */
@@ -42946,10 +43157,99 @@
43157 u8 eCreate; /* eCreate value for for xFetch() */
43158 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
43159 void *pStress; /* Argument to xStress */
43160 sqlite3_pcache *pCache; /* Pluggable cache module */
43161 };
43162
43163 /********************************** Test and Debug Logic **********************/
43164 /*
43165 ** Debug tracing macros. Enable by by changing the "0" to "1" and
43166 ** recompiling.
43167 **
43168 ** When sqlite3PcacheTrace is 1, single line trace messages are issued.
43169 ** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries
43170 ** is displayed for many operations, resulting in a lot of output.
43171 */
43172 #if defined(SQLITE_DEBUG) && 0
43173 int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */
43174 int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */
43175 # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
43176 void pcacheDump(PCache *pCache){
43177 int N;
43178 int i, j;
43179 sqlite3_pcache_page *pLower;
43180 PgHdr *pPg;
43181 unsigned char *a;
43182
43183 if( sqlite3PcacheTrace<2 ) return;
43184 if( pCache->pCache==0 ) return;
43185 N = sqlite3PcachePagecount(pCache);
43186 if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump;
43187 for(i=1; i<=N; i++){
43188 pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
43189 if( pLower==0 ) continue;
43190 pPg = (PgHdr*)pLower->pExtra;
43191 printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
43192 a = (unsigned char *)pLower->pBuf;
43193 for(j=0; j<12; j++) printf("%02x", a[j]);
43194 printf("\n");
43195 if( pPg->pPage==0 ){
43196 sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
43197 }
43198 }
43199 }
43200 #else
43201 # define pcacheTrace(X)
43202 # define pcacheDump(X)
43203 #endif
43204
43205 /*
43206 ** Check invariants on a PgHdr entry. Return true if everything is OK.
43207 ** Return false if any invariant is violated.
43208 **
43209 ** This routine is for use inside of assert() statements only. For
43210 ** example:
43211 **
43212 ** assert( sqlite3PcachePageSanity(pPg) );
43213 */
43214 #if SQLITE_DEBUG
43215 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43216 PCache *pCache;
43217 assert( pPg!=0 );
43218 assert( pPg->pgno>0 ); /* Page number is 1 or more */
43219 pCache = pPg->pCache;
43220 assert( pCache!=0 ); /* Every page has an associated PCache */
43221 if( pPg->flags & PGHDR_CLEAN ){
43222 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43223 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
43224 assert( pCache->pDirtyTail!=pPg );
43225 }
43226 /* WRITEABLE pages must also be DIRTY */
43227 if( pPg->flags & PGHDR_WRITEABLE ){
43228 assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */
43229 }
43230 /* NEED_SYNC can be set independently of WRITEABLE. This can happen,
43231 ** for example, when using the sqlite3PagerDontWrite() optimization:
43232 ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK.
43233 ** (2) Page X moved to freelist, WRITEABLE is cleared
43234 ** (3) Page X reused, WRITEABLE is set again
43235 ** If NEED_SYNC had been cleared in step 2, then it would not be reset
43236 ** in step 3, and page might be written into the database without first
43237 ** syncing the rollback journal, which might cause corruption on a power
43238 ** loss.
43239 **
43240 ** Another example is when the database page size is smaller than the
43241 ** disk sector size. When any page of a sector is journalled, all pages
43242 ** in that sector are marked NEED_SYNC even if they are still CLEAN, just
43243 ** in case they are later modified, since all pages in the same sector
43244 ** must be journalled and synced before any of those pages can be safely
43245 ** written.
43246 */
43247 return 1;
43248 }
43249 #endif /* SQLITE_DEBUG */
43250
43251
43252 /********************************** Linked List Management ********************/
43253
43254 /* Allowed values for second argument to pcacheManageDirtyList() */
43255 #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */
@@ -42963,21 +43263,20 @@
43263 ** the dirty list. Doing both moves pPage to the front of the dirty list.
43264 */
43265 static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){
43266 PCache *p = pPage->pCache;
43267
43268 pcacheTrace(("%p.DIRTYLIST.%s %d\n", p,
43269 addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT",
43270 pPage->pgno));
43271 if( addRemove & PCACHE_DIRTYLIST_REMOVE ){
43272 assert( pPage->pDirtyNext || pPage==p->pDirtyTail );
43273 assert( pPage->pDirtyPrev || pPage==p->pDirty );
43274
43275 /* Update the PCache1.pSynced variable if necessary. */
43276 if( p->pSynced==pPage ){
43277 p->pSynced = pPage->pDirtyPrev;
 
 
 
 
43278 }
43279
43280 if( pPage->pDirtyNext ){
43281 pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev;
43282 }else{
@@ -42985,14 +43284,19 @@
43284 p->pDirtyTail = pPage->pDirtyPrev;
43285 }
43286 if( pPage->pDirtyPrev ){
43287 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
43288 }else{
43289 /* If there are now no dirty pages in the cache, set eCreate to 2.
43290 ** This is an optimization that allows sqlite3PcacheFetch() to skip
43291 ** searching for a dirty page to eject from the cache when it might
43292 ** otherwise have to. */
43293 assert( pPage==p->pDirty );
43294 p->pDirty = pPage->pDirtyNext;
43295 assert( p->bPurgeable || p->eCreate==2 );
43296 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
43297 assert( p->bPurgeable==0 || p->eCreate==1 );
43298 p->eCreate = 2;
43299 }
43300 }
43301 pPage->pDirtyNext = 0;
43302 pPage->pDirtyPrev = 0;
@@ -43010,23 +43314,34 @@
43314 assert( p->eCreate==2 );
43315 p->eCreate = 1;
43316 }
43317 }
43318 p->pDirty = pPage;
43319
43320 /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set
43321 ** pSynced to point to it. Checking the NEED_SYNC flag is an
43322 ** optimization, as if pSynced points to a page with the NEED_SYNC
43323 ** flag set sqlite3PcacheFetchStress() searches through all newer
43324 ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */
43325 if( !p->pSynced
43326 && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/
43327 ){
43328 p->pSynced = pPage;
43329 }
43330 }
43331 pcacheDump(p);
43332 }
43333
43334 /*
43335 ** Wrapper around the pluggable caches xUnpin method. If the cache is
43336 ** being used for an in-memory database, this function is a no-op.
43337 */
43338 static void pcacheUnpin(PgHdr *p){
43339 if( p->pCache->bPurgeable ){
43340 pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
43341 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
43342 pcacheDump(p->pCache);
43343 }
43344 }
43345
43346 /*
43347 ** Compute the number of pages of cache requested. p->szCache is the
@@ -43092,10 +43407,11 @@
43407 p->eCreate = 2;
43408 p->xStress = xStress;
43409 p->pStress = pStress;
43410 p->szCache = 100;
43411 p->szSpill = 1;
43412 pcacheTrace(("%p.OPEN szPage %d bPurgeable %d\n",p,szPage,bPurgeable));
43413 return sqlite3PcacheSetPageSize(p, szPage);
43414 }
43415
43416 /*
43417 ** Change the page size for PCache object. The caller must ensure that there
@@ -43114,10 +43430,11 @@
43430 if( pCache->pCache ){
43431 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43432 }
43433 pCache->pCache = pNew;
43434 pCache->szPage = szPage;
43435 pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage));
43436 }
43437 return SQLITE_OK;
43438 }
43439
43440 /*
@@ -43148,15 +43465,17 @@
43465 PCache *pCache, /* Obtain the page from this cache */
43466 Pgno pgno, /* Page number to obtain */
43467 int createFlag /* If true, create page if it does not exist already */
43468 ){
43469 int eCreate;
43470 sqlite3_pcache_page *pRes;
43471
43472 assert( pCache!=0 );
43473 assert( pCache->pCache!=0 );
43474 assert( createFlag==3 || createFlag==0 );
43475 assert( pgno>0 );
43476 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
43477
43478 /* eCreate defines what to do if the page does not exist.
43479 ** 0 Do not allocate a new page. (createFlag==0)
43480 ** 1 Allocate a new page if doing so is inexpensive.
43481 ** (createFlag==1 AND bPurgeable AND pDirty)
@@ -43165,16 +43484,19 @@
43484 */
43485 eCreate = createFlag & pCache->eCreate;
43486 assert( eCreate==0 || eCreate==1 || eCreate==2 );
43487 assert( createFlag==0 || pCache->eCreate==eCreate );
43488 assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) );
43489 pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43490 pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno,
43491 createFlag?" create":"",pRes));
43492 return pRes;
43493 }
43494
43495 /*
43496 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43497 ** page because no clean pages are available for reuse and the cache
43498 ** size limit has been reached, then this routine can be invoked to
43499 ** try harder to allocate a page. This routine might invoke the stress
43500 ** callback to spill dirty pages to the journal. It will then try to
43501 ** allocate the new page and will only fail to allocate a new page on
43502 ** an OOM error.
@@ -43192,11 +43514,15 @@
43514 if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){
43515 /* Find a dirty page to write-out and recycle. First try to find a
43516 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
43517 ** cleared), but if that is not possible settle for any other
43518 ** unreferenced dirty page.
43519 **
43520 ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC
43521 ** flag is currently referenced, then the following may leave pSynced
43522 ** set incorrectly (pointing to other than the LRU page with NEED_SYNC
43523 ** cleared). This is Ok, as pSynced is just an optimization. */
43524 for(pPg=pCache->pSynced;
43525 pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC));
43526 pPg=pPg->pDirtyPrev
43527 );
43528 pCache->pSynced = pPg;
@@ -43210,11 +43536,13 @@
43536 "spill page %d making room for %d - cache used: %d/%d",
43537 pPg->pgno, pgno,
43538 sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
43539 numberOfCachePages(pCache));
43540 #endif
43541 pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
43542 rc = pCache->xStress(pCache->pStress, pPg);
43543 pcacheDump(pCache);
43544 if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
43545 return rc;
43546 }
43547 }
43548 }
@@ -43270,10 +43598,11 @@
43598 if( !pPgHdr->pPage ){
43599 return pcacheFetchFinishWithInit(pCache, pgno, pPage);
43600 }
43601 pCache->nRefSum++;
43602 pPgHdr->nRef++;
43603 assert( sqlite3PcachePageSanity(pPgHdr) );
43604 return pPgHdr;
43605 }
43606
43607 /*
43608 ** Decrement the reference count on a page. If the page is clean and the
@@ -43283,12 +43612,15 @@
43612 assert( p->nRef>0 );
43613 p->pCache->nRefSum--;
43614 if( (--p->nRef)==0 ){
43615 if( p->flags&PGHDR_CLEAN ){
43616 pcacheUnpin(p);
43617 }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
43618 /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
43619 ** then page p is already at the head of the dirty list and the
43620 ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
43621 ** tag above. */
43622 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43623 }
43624 }
43625 }
43626
@@ -43295,10 +43627,11 @@
43627 /*
43628 ** Increase the reference count of a supplied page by 1.
43629 */
43630 SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){
43631 assert(p->nRef>0);
43632 assert( sqlite3PcachePageSanity(p) );
43633 p->nRef++;
43634 p->pCache->nRefSum++;
43635 }
43636
43637 /*
@@ -43306,10 +43639,11 @@
43639 ** page. This function deletes that reference, so after it returns the
43640 ** page pointed to by p is invalid.
43641 */
43642 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){
43643 assert( p->nRef==1 );
43644 assert( sqlite3PcachePageSanity(p) );
43645 if( p->flags&PGHDR_DIRTY ){
43646 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43647 }
43648 p->pCache->nRefSum--;
43649 sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1);
@@ -43319,30 +43653,36 @@
43653 ** Make sure the page is marked as dirty. If it isn't dirty already,
43654 ** make it so.
43655 */
43656 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){
43657 assert( p->nRef>0 );
43658 assert( sqlite3PcachePageSanity(p) );
43659 if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/
43660 p->flags &= ~PGHDR_DONT_WRITE;
43661 if( p->flags & PGHDR_CLEAN ){
43662 p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN);
43663 pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno));
43664 assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY );
43665 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD);
43666 }
43667 assert( sqlite3PcachePageSanity(p) );
43668 }
43669 }
43670
43671 /*
43672 ** Make sure the page is marked as clean. If it isn't clean already,
43673 ** make it so.
43674 */
43675 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){
43676 assert( sqlite3PcachePageSanity(p) );
43677 if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){
43678 assert( (p->flags & PGHDR_CLEAN)==0 );
43679 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE);
43680 p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43681 p->flags |= PGHDR_CLEAN;
43682 pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno));
43683 assert( sqlite3PcachePageSanity(p) );
43684 if( p->nRef==0 ){
43685 pcacheUnpin(p);
43686 }
43687 }
43688 }
@@ -43350,14 +43690,27 @@
43690 /*
43691 ** Make every page in the cache clean.
43692 */
43693 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){
43694 PgHdr *p;
43695 pcacheTrace(("%p.CLEAN-ALL\n",pCache));
43696 while( (p = pCache->pDirty)!=0 ){
43697 sqlite3PcacheMakeClean(p);
43698 }
43699 }
43700
43701 /*
43702 ** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43703 */
43704 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43705 PgHdr *p;
43706 pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
43707 for(p=pCache->pDirty; p; p=p->pDirtyNext){
43708 p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43709 }
43710 pCache->pSynced = pCache->pDirtyTail;
43711 }
43712
43713 /*
43714 ** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
43715 */
43716 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43373,10 +43726,12 @@
43726 */
43727 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
43728 PCache *pCache = p->pCache;
43729 assert( p->nRef>0 );
43730 assert( newPgno>0 );
43731 assert( sqlite3PcachePageSanity(p) );
43732 pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
43733 sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
43734 p->pgno = newPgno;
43735 if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
43736 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
43737 }
@@ -43393,18 +43748,19 @@
43748 */
43749 SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){
43750 if( pCache->pCache ){
43751 PgHdr *p;
43752 PgHdr *pNext;
43753 pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno));
43754 for(p=pCache->pDirty; p; p=pNext){
43755 pNext = p->pDirtyNext;
43756 /* This routine never gets call with a positive pgno except right
43757 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43758 ** it must be that pgno==0.
43759 */
43760 assert( p->pgno>0 );
43761 if( p->pgno>pgno ){
43762 assert( p->flags&PGHDR_DIRTY );
43763 sqlite3PcacheMakeClean(p);
43764 }
43765 }
43766 if( pgno==0 && pCache->nRefSum ){
@@ -43423,10 +43779,11 @@
43779 /*
43780 ** Close a cache.
43781 */
43782 SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
43783 assert( pCache->pCache!=0 );
43784 pcacheTrace(("%p.CLOSE\n",pCache));
43785 sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
43786 }
43787
43788 /*
43789 ** Discard the contents of the cache.
@@ -43591,10 +43948,21 @@
43948 ** Return the size of the header added by this middleware layer
43949 ** in the page-cache hierarchy.
43950 */
43951 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
43952
43953 /*
43954 ** Return the number of dirty pages currently in the cache, as a percentage
43955 ** of the configured cache size.
43956 */
43957 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
43958 PgHdr *pDirty;
43959 int nDirty = 0;
43960 int nCache = numberOfCachePages(pCache);
43961 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
43962 return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
43963 }
43964
43965 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
43966 /*
43967 ** For all dirty pages currently in the cache, invoke the specified
43968 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44668,12 @@
44668 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
44669 #endif
44670
44671 #if SQLITE_THREADSAFE
44672 if( sqlite3GlobalConfig.bCoreMutex ){
44673 pcache1.grp.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU);
44674 pcache1.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PMEM);
44675 }
44676 #endif
44677 if( pcache1.separateCache
44678 && sqlite3GlobalConfig.nPage!=0
44679 && sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45275,13 @@
45275 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
45276 ** The cost of a TEST using the same batch number is O(logN). The cost
45277 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
45278 ** primitives are constant time. The cost of DESTROY is O(N).
45279 **
45280 ** TEST and SMALLEST may not be used by the same RowSet. This used to
45281 ** be possible, but the feature was not used, so it was removed in order
45282 ** to simplify the code.
45283 */
45284 /* #include "sqliteInt.h" */
45285
45286
45287 /*
@@ -45029,11 +45398,13 @@
45398 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
45399 ** routine returns NULL.
45400 */
45401 static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
45402 assert( p!=0 );
45403 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
45404 /* We could allocate a fresh RowSetEntry each time one is needed, but it
45405 ** is more efficient to pull a preallocated entry from the pool */
45406 struct RowSetChunk *pNew;
45407 pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
45408 if( pNew==0 ){
45409 return 0;
45410 }
@@ -45063,11 +45434,13 @@
45434 if( pEntry==0 ) return;
45435 pEntry->v = rowid;
45436 pEntry->pRight = 0;
45437 pLast = p->pLast;
45438 if( pLast ){
45439 if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/
45440 /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
45441 ** where possible */
45442 p->rsFlags &= ~ROWSET_SORTED;
45443 }
45444 pLast->pRight = pEntry;
45445 }else{
45446 p->pEntry = pEntry;
@@ -45185,27 +45558,33 @@
45558 struct RowSetEntry **ppList,
45559 int iDepth
45560 ){
45561 struct RowSetEntry *p; /* Root of the new tree */
45562 struct RowSetEntry *pLeft; /* Left subtree */
45563 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
45564 /* Prevent unnecessary deep recursion when we run out of entries */
45565 return 0;
45566 }
45567 if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
45568 /* This branch causes a *balanced* tree to be generated. A valid tree
45569 ** is still generated without this branch, but the tree is wildly
45570 ** unbalanced and inefficient. */
45571 pLeft = rowSetNDeepTree(ppList, iDepth-1);
45572 p = *ppList;
45573 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
45574 /* It is safe to always return here, but the resulting tree
45575 ** would be unbalanced */
45576 return pLeft;
45577 }
45578 p->pLeft = pLeft;
45579 *ppList = p->pRight;
45580 p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45581 }else{
45582 p = *ppList;
45583 *ppList = p->pRight;
45584 p->pLeft = p->pRight = 0;
45585 }
 
 
 
 
 
 
 
 
 
45586 return p;
45587 }
45588
45589 /*
45590 ** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45607,41 @@
45607 p->pRight = rowSetNDeepTree(&pList, iDepth);
45608 }
45609 return p;
45610 }
45611
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45612 /*
45613 ** Extract the smallest element from the RowSet.
45614 ** Write the element into *pRowid. Return 1 on success. Return
45615 ** 0 if the RowSet is already empty.
45616 **
45617 ** After this routine has been called, the sqlite3RowSetInsert()
45618 ** routine may not be called again.
45619 **
45620 ** This routine may not be called after sqlite3RowSetTest() has
45621 ** been used. Older versions of RowSet allowed that, but as the
45622 ** capability was not used by the code generator, it was removed
45623 ** for code economy.
45624 */
45625 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
45626 assert( p!=0 );
45627 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
45628
45629 /* Merge the forest into a single sorted list on first call */
45630 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45631 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45632 p->pEntry = rowSetEntrySort(p->pEntry);
45633 }
45634 p->rsFlags |= ROWSET_SORTED|ROWSET_NEXT;
45635 }
45636
45637 /* Return the next entry on the list */
45638 if( p->pEntry ){
45639 *pRowid = p->pEntry->v;
45640 p->pEntry = p->pEntry->pRight;
45641 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
45642 /* Free memory immediately, rather than waiting on sqlite3_finalize() */
45643 sqlite3RowSetClear(p);
45644 }
45645 return 1;
45646 }else{
45647 return 0;
@@ -45303,17 +45660,19 @@
45660 struct RowSetEntry *p, *pTree;
45661
45662 /* This routine is never called after sqlite3RowSetNext() */
45663 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
45664
45665 /* Sort entries into the forest on the first test of a new batch.
45666 ** To save unnecessary work, only do this when the batch number changes.
45667 */
45668 if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/
45669 p = pRowSet->pEntry;
45670 if( p ){
45671 struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45672 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45673 /* Only sort the current set of entiries if they need it */
45674 p = rowSetEntrySort(p);
45675 }
45676 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
45677 ppPrevTree = &pTree->pRight;
45678 if( pTree->pLeft==0 ){
@@ -46383,10 +46742,11 @@
46742 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
46743 ** is therefore not possible for an in-memory pager to enter the ERROR
46744 ** state.
46745 */
46746 if( MEMDB ){
46747 assert( !isOpen(p->fd) );
46748 assert( p->noSync );
46749 assert( p->journalMode==PAGER_JOURNALMODE_OFF
46750 || p->journalMode==PAGER_JOURNALMODE_MEMORY
46751 );
46752 assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46829,11 @@
46829 /* There must be at least one outstanding reference to the pager if
46830 ** in ERROR state. Otherwise the pager should have already dropped
46831 ** back to OPEN state.
46832 */
46833 assert( pPager->errCode!=SQLITE_OK );
46834 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
46835 break;
46836 }
46837
46838 return 1;
46839 }
@@ -46681,10 +47041,12 @@
47041 }
47042 }
47043
47044 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
47045 }
47046 #else
47047 # define jrnlBufferSize(x) 0
47048 #endif
47049
47050 /*
47051 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
47052 ** on the cache using a hash function. This is used for testing
@@ -47329,17 +47691,21 @@
47691 /* If Pager.errCode is set, the contents of the pager cache cannot be
47692 ** trusted. Now that there are no outstanding references to the pager,
47693 ** it can safely move back to PAGER_OPEN state. This happens in both
47694 ** normal and exclusive-locking mode.
47695 */
47696 assert( pPager->errCode==SQLITE_OK || !MEMDB );
47697 if( pPager->errCode ){
47698 if( pPager->tempFile==0 ){
47699 pager_reset(pPager);
47700 pPager->changeCountDone = 0;
47701 pPager->eState = PAGER_OPEN;
47702 }else{
47703 pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
47704 }
47705 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
47706 pPager->errCode = SQLITE_OK;
47707 }
47708
47709 pPager->journalOff = 0;
47710 pPager->journalHdr = 0;
47711 pPager->setMaster = 0;
@@ -47378,10 +47744,33 @@
47744 }
47745 return rc;
47746 }
47747
47748 static int pager_truncate(Pager *pPager, Pgno nPage);
47749
47750 /*
47751 ** The write transaction open on pPager is being committed (bCommit==1)
47752 ** or rolled back (bCommit==0).
47753 **
47754 ** Return TRUE if and only if all dirty pages should be flushed to disk.
47755 **
47756 ** Rules:
47757 **
47758 ** * For non-TEMP databases, always sync to disk. This is necessary
47759 ** for transactions to be durable.
47760 **
47761 ** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing
47762 ** file has been created already (via a spill on pagerStress()) and
47763 ** when the number of dirty pages in memory exceeds 25% of the total
47764 ** cache size.
47765 */
47766 static int pagerFlushOnCommit(Pager *pPager, int bCommit){
47767 if( pPager->tempFile==0 ) return 1;
47768 if( !bCommit ) return 0;
47769 if( !isOpen(pPager->fd) ) return 0;
47770 return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47771 }
47772
47773 /*
47774 ** This routine ends a transaction. A transaction is usually ended by
47775 ** either a COMMIT or a ROLLBACK operation. This routine may be called
47776 ** after rollback of a hot-journal, or if an error occurs while opening
@@ -47482,11 +47871,11 @@
47871 }
47872 pPager->journalOff = 0;
47873 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
47874 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
47875 ){
47876 rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
47877 pPager->journalOff = 0;
47878 }else{
47879 /* This branch may be executed with Pager.journalMode==MEMORY if
47880 ** a hot-journal was just rolled back. In this case the journal
47881 ** file should be closed and deleted. If this connection writes to
@@ -47517,12 +47906,18 @@
47906 #endif
47907
47908 sqlite3BitvecDestroy(pPager->pInJournal);
47909 pPager->pInJournal = 0;
47910 pPager->nRec = 0;
47911 if( rc==SQLITE_OK ){
47912 if( pagerFlushOnCommit(pPager, bCommit) ){
47913 sqlite3PcacheCleanAll(pPager->pPCache);
47914 }else{
47915 sqlite3PcacheClearWritable(pPager->pPCache);
47916 }
47917 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47918 }
47919
47920 if( pagerUseWal(pPager) ){
47921 /* Drop the WAL write-lock, if any. Also, if the connection was in
47922 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
47923 ** lock held on the database file.
@@ -47802,11 +48197,11 @@
48197 pPg = 0;
48198 }else{
48199 pPg = sqlite3PagerLookup(pPager, pgno);
48200 }
48201 assert( pPg || !MEMDB );
48202 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
48203 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
48204 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
48205 (isMainJrnl?"main-journal":"sub-journal")
48206 ));
48207 if( isMainJrnl ){
@@ -47852,11 +48247,10 @@
48247 pPager->doNotSpill |= SPILLFLAG_ROLLBACK;
48248 rc = sqlite3PagerGet(pPager, pgno, &pPg, 1);
48249 assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 );
48250 pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK;
48251 if( rc!=SQLITE_OK ) return rc;
 
48252 sqlite3PcacheMakeDirty(pPg);
48253 }
48254 if( pPg ){
48255 /* No page should ever be explicitly rolled back that is in use, except
48256 ** for page 1 which is held in use in order to keep the lock on the
@@ -47866,33 +48260,14 @@
48260 */
48261 void *pData;
48262 pData = pPg->pData;
48263 memcpy(pData, (u8*)aData, pPager->pageSize);
48264 pPager->xReiniter(pPg);
48265 /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But
48266 ** that call was dangerous and had no detectable benefit since the cache
48267 ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so
48268 ** has been removed. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48269 pager_set_pagehash(pPg);
48270
48271 /* If this was page 1, then restore the value of Pager.dbFileVers.
48272 ** Do this before any decoding. */
48273 if( pgno==1 ){
@@ -48679,25 +49054,24 @@
49054 ** available from the WAL sub-system if the log file is empty or
49055 ** contains no valid committed transactions.
49056 */
49057 assert( pPager->eState==PAGER_OPEN );
49058 assert( pPager->eLock>=SHARED_LOCK );
49059 assert( isOpen(pPager->fd) );
49060 assert( pPager->tempFile==0 );
49061 nPage = sqlite3WalDbsize(pPager->pWal);
49062
49063 /* If the number of pages in the database is not available from the
49064 ** WAL sub-system, determine the page counte based on the size of
49065 ** the database file. If the size of the database file is not an
49066 ** integer multiple of the page-size, round up the result.
49067 */
49068 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
49069 i64 n = 0; /* Size of db file in bytes */
49070 int rc = sqlite3OsFileSize(pPager->fd, &n);
49071 if( rc!=SQLITE_OK ){
49072 return rc;
 
 
 
49073 }
49074 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
49075 }
49076
49077 /* If the current number of pages in the file is greater than the
@@ -49769,12 +50143,13 @@
50143 static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
50144 int rc = SQLITE_OK; /* Return code */
50145
50146 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
50147 assert( !pagerUseWal(pPager) );
50148 assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD );
50149 assert( pPager->eLock==EXCLUSIVE_LOCK );
50150 assert( isOpen(pPager->fd) || pList->pDirty==0 );
50151
50152 /* If the file is a temp-file has not yet been opened, open it now. It
50153 ** is not possible for rc to be other than SQLITE_OK if this branch
50154 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
50155 */
@@ -50438,10 +50813,11 @@
50813 */
50814 rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
50815 if( rc==SQLITE_OK && !locked ){
50816 Pgno nPage; /* Number of pages in database file */
50817
50818 assert( pPager->tempFile==0 );
50819 rc = pagerPagecount(pPager, &nPage);
50820 if( rc==SQLITE_OK ){
50821 /* If the database is zero pages in size, that means that either (1) the
50822 ** journal is a remnant from a prior database with the same name where
50823 ** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50906,21 @@
50906 int rc = SQLITE_OK; /* Return code */
50907
50908 /* This routine is only called from b-tree and only when there are no
50909 ** outstanding pages. This implies that the pager state should either
50910 ** be OPEN or READER. READER is only possible if the pager is or was in
50911 ** exclusive access mode. */
 
50912 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
50913 assert( assert_pager_state(pPager) );
50914 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50915 assert( pPager->errCode==SQLITE_OK );
50916
50917 if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
50918 int bHotJournal = 1; /* True if there exists a hot journal-file */
50919
50920 assert( !MEMDB );
50921 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
50922
50923 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
50924 if( rc!=SQLITE_OK ){
50925 assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
50926 goto failed;
@@ -50626,11 +51002,11 @@
51002 */
51003 if( isOpen(pPager->jfd) ){
51004 assert( rc==SQLITE_OK );
51005 rc = pagerSyncHotJournal(pPager);
51006 if( rc==SQLITE_OK ){
51007 rc = pager_playback(pPager, !pPager->tempFile);
51008 pPager->eState = PAGER_OPEN;
51009 }
51010 }else if( !pPager->exclusiveMode ){
51011 pagerUnlockDb(pPager, SHARED_LOCK);
51012 }
@@ -50722,11 +51098,11 @@
51098 if( pagerUseWal(pPager) ){
51099 assert( rc==SQLITE_OK );
51100 rc = pagerBeginReadTransaction(pPager);
51101 }
51102
51103 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
51104 rc = pagerPagecount(pPager, &pPager->dbSize);
51105 }
51106
51107 failed:
51108 if( rc!=SQLITE_OK ){
@@ -50855,11 +51231,11 @@
51231 rc = sqlite3OsFetch(pPager->fd,
51232 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
51233 );
51234
51235 if( rc==SQLITE_OK && pData ){
51236 if( pPager->eState>PAGER_READER || pPager->tempFile ){
51237 pPg = sqlite3PagerLookup(pPager, pgno);
51238 }
51239 if( pPg==0 ){
51240 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
51241 }else{
@@ -50922,11 +51298,12 @@
51298 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
51299 rc = SQLITE_CORRUPT_BKPT;
51300 goto pager_acquire_err;
51301 }
51302
51303 assert( !isOpen(pPager->fd) || !MEMDB );
51304 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
51305 if( pgno>pPager->mxPgno ){
51306 rc = SQLITE_FULL;
51307 goto pager_acquire_err;
51308 }
51309 if( noContent ){
@@ -51064,28 +51441,28 @@
51441 /* Open the journal file if it is not already open. */
51442 if( !isOpen(pPager->jfd) ){
51443 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
51444 sqlite3MemJournalOpen(pPager->jfd);
51445 }else{
51446 int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
51447 int nSpill;
 
 
 
 
51448
51449 if( pPager->tempFile ){
51450 flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
51451 nSpill = sqlite3Config.nStmtSpill;
51452 }else{
51453 flags |= SQLITE_OPEN_MAIN_JOURNAL;
51454 nSpill = jrnlBufferSize(pPager);
51455 }
51456
51457 /* Verify that the database still has the same name as it did when
51458 ** it was originally opened. */
51459 rc = databaseIsUnmoved(pPager);
51460 if( rc==SQLITE_OK ){
51461 rc = sqlite3JournalOpen (
51462 pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
 
51463 );
 
 
 
51464 }
51465 }
51466 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
51467 }
51468
@@ -51452,10 +51829,11 @@
51829 return pPager->errCode;
51830 }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
51831 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
51832 return SQLITE_OK;
51833 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
51834 assert( pPager->tempFile==0 );
51835 return pagerWriteLargeSector(pPg);
51836 }else{
51837 return pager_write(pPg);
51838 }
51839 }
@@ -51482,18 +51860,25 @@
51860 ** on the given page is unused. The pager marks the page as clean so
51861 ** that it does not get written to disk.
51862 **
51863 ** Tests show that this optimization can quadruple the speed of large
51864 ** DELETE operations.
51865 **
51866 ** This optimization cannot be used with a temp-file, as the page may
51867 ** have been dirty at the start of the transaction. In that case, if
51868 ** memory pressure forces page pPg out of the cache, the data does need
51869 ** to be written out to disk so that it may be read back in if the
51870 ** current transaction is rolled back.
51871 */
51872 SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
51873 Pager *pPager = pPg->pPager;
51874 if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){
51875 PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager)));
51876 IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
51877 pPg->flags |= PGHDR_DONT_WRITE;
51878 pPg->flags &= ~PGHDR_WRITEABLE;
51879 testcase( pPg->flags & PGHDR_NEED_SYNC );
51880 pager_set_pagehash(pPg);
51881 }
51882 }
51883
51884 /*
@@ -51683,22 +52068,26 @@
52068 );
52069 assert( assert_pager_state(pPager) );
52070
52071 /* If a prior error occurred, report that error again. */
52072 if( NEVER(pPager->errCode) ) return pPager->errCode;
52073
52074 /* Provide the ability to easily simulate an I/O error during testing */
52075 if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
52076
52077 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
52078 pPager->zFilename, zMaster, pPager->dbSize));
52079
52080 /* If no database changes have been made, return early. */
52081 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
52082
52083 assert( MEMDB==0 || pPager->tempFile );
52084 assert( isOpen(pPager->fd) || pPager->tempFile );
52085 if( 0==pagerFlushOnCommit(pPager, 1) ){
52086 /* If this is an in-memory db, or no pages have been written to, or this
52087 ** function has already been called, it is mostly a no-op. However, any
52088 ** backup in progress needs to be restarted. */
 
52089 sqlite3BackupRestart(pPager->pBackup);
52090 }else{
52091 if( pagerUseWal(pPager) ){
52092 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
52093 PgHdr *pPageOne = 0;
@@ -52033,14 +52422,14 @@
52422 pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
52423 }
52424 }
52425
52426 /*
52427 ** Return true if this is an in-memory or temp-file backed pager.
52428 */
52429 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52430 return pPager->tempFile;
52431 }
52432
52433 /*
52434 ** Check that there are at least nSavepoint savepoints open. If there are
52435 ** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52705,12 @@
52705 assert( assert_pager_state(pPager) );
52706
52707 /* In order to be able to rollback, an in-memory database must journal
52708 ** the page we are moving from.
52709 */
52710 assert( pPager->tempFile || !MEMDB );
52711 if( pPager->tempFile ){
52712 rc = sqlite3PagerWrite(pPg);
52713 if( rc ) return rc;
52714 }
52715
52716 /* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52763,11 @@
52763 pPg->flags &= ~PGHDR_NEED_SYNC;
52764 pPgOld = sqlite3PagerLookup(pPager, pgno);
52765 assert( !pPgOld || pPgOld->nRef==1 );
52766 if( pPgOld ){
52767 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52768 if( pPager->tempFile ){
52769 /* Do not discard pages from an in-memory database since we might
52770 ** need to rollback later. Just move the page out of the way. */
52771 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
52772 }else{
52773 sqlite3PcacheDrop(pPgOld);
@@ -52390,12 +52780,11 @@
52780
52781 /* For an in-memory database, make sure the original page continues
52782 ** to exist, in case the transaction needs to roll back. Use pPgOld
52783 ** as the original page since it has already been allocated.
52784 */
52785 if( pPager->tempFile && pPgOld ){
 
52786 sqlite3PcacheMove(pPgOld, origPgno);
52787 sqlite3PagerUnrefNotNull(pPgOld);
52788 }
52789
52790 if( needSyncPgno ){
@@ -52643,11 +53032,12 @@
53032 #ifndef SQLITE_OMIT_VACUUM
53033 /*
53034 ** Unless this is an in-memory or temporary database, clear the pager cache.
53035 */
53036 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
53037 assert( MEMDB==0 || pPager->tempFile );
53038 if( pPager->tempFile==0 ) pager_reset(pPager);
53039 }
53040 #endif
53041
53042 #ifndef SQLITE_OMIT_WAL
53043 /*
@@ -52822,10 +53212,11 @@
53212 if( rc==SQLITE_OK ){
53213 rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
53214 pPager->pageSize, (u8*)pPager->pTmpSpace);
53215 pPager->pWal = 0;
53216 pagerFixMaplimit(pPager);
53217 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
53218 }
53219 }
53220 return rc;
53221 }
53222
@@ -56277,10 +56668,27 @@
56668 /* Try to open on pSnapshot when the next read-transaction starts
56669 */
56670 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
56671 pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
56672 }
56673
56674 /*
56675 ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
56676 ** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
56677 */
56678 SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
56679 WalIndexHdr *pHdr1 = (WalIndexHdr*)p1;
56680 WalIndexHdr *pHdr2 = (WalIndexHdr*)p2;
56681
56682 /* aSalt[0] is a copy of the value stored in the wal file header. It
56683 ** is incremented each time the wal file is restarted. */
56684 if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
56685 if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
56686 if( pHdr1->mxFrame<pHdr2->mxFrame ) return -1;
56687 if( pHdr1->mxFrame>pHdr2->mxFrame ) return +1;
56688 return 0;
56689 }
56690 #endif /* SQLITE_ENABLE_SNAPSHOT */
56691
56692 #ifdef SQLITE_ENABLE_ZIPVFS
56693 /*
56694 ** If the argument is not NULL, it points to a Wal object that holds a
@@ -58992,15 +59400,15 @@
59400 flagByte &= ~PTF_LEAF;
59401 pPage->childPtrSize = 4-4*pPage->leaf;
59402 pPage->xCellSize = cellSizePtr;
59403 pBt = pPage->pBt;
59404 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
59405 /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
59406 ** interior table b-tree page. */
59407 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
59408 /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
59409 ** leaf table b-tree page. */
59410 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
59411 pPage->intKey = 1;
59412 if( pPage->leaf ){
59413 pPage->intKeyLeaf = 1;
59414 pPage->xParseCell = btreeParseCellPtr;
@@ -59010,15 +59418,15 @@
59418 pPage->xParseCell = btreeParseCellPtrNoPayload;
59419 }
59420 pPage->maxLocal = pBt->maxLeaf;
59421 pPage->minLocal = pBt->minLeaf;
59422 }else if( flagByte==PTF_ZERODATA ){
59423 /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
59424 ** interior index b-tree page. */
59425 assert( (PTF_ZERODATA)==2 );
59426 /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
59427 ** leaf index b-tree page. */
59428 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
59429 pPage->intKey = 0;
59430 pPage->intKeyLeaf = 0;
59431 pPage->xParseCell = btreeParseCellPtrIndex;
59432 pPage->maxLocal = pBt->maxLocal;
@@ -65455,10 +65863,32 @@
65863
65864 iCellDepth = pCur->iPage;
65865 iCellIdx = pCur->aiIdx[iCellDepth];
65866 pPage = pCur->apPage[iCellDepth];
65867 pCell = findCell(pPage, iCellIdx);
65868
65869 /* If the bPreserve flag is set to true, then the cursor position must
65870 ** be preserved following this delete operation. If the current delete
65871 ** will cause a b-tree rebalance, then this is done by saving the cursor
65872 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65873 ** returning.
65874 **
65875 ** Or, if the current delete will not cause a rebalance, then the cursor
65876 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65877 ** before or after the deleted entry. In this case set bSkipnext to true. */
65878 if( bPreserve ){
65879 if( !pPage->leaf
65880 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65881 ){
65882 /* A b-tree rebalance will be required after deleting this entry.
65883 ** Save the cursor key. */
65884 rc = saveCursorKey(pCur);
65885 if( rc ) return rc;
65886 }else{
65887 bSkipnext = 1;
65888 }
65889 }
65890
65891 /* If the page containing the entry to delete is not a leaf page, move
65892 ** the cursor to the largest entry in the tree that is smaller than
65893 ** the entry being deleted. This cell will replace the cell being deleted
65894 ** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65912,10 @@
65912 ** invalidate any incrblob cursors open on the row being deleted. */
65913 if( pCur->pKeyInfo==0 ){
65914 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
65915 }
65916
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65917 /* Make the page containing the entry to be deleted writable. Then free any
65918 ** overflow pages associated with the entry and finally remove the cell
65919 ** itself from within the page. */
65920 rc = sqlite3PagerWrite(pPage->pDbPage);
65921 if( rc ) return rc;
@@ -70082,77 +70490,88 @@
70490 ** indicate what the prepared statement actually does.
70491 **
70492 ** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
70493 **
70494 ** (5) Reclaim the memory allocated for storing labels.
70495 **
70496 ** This routine will only function correctly if the mkopcodeh.tcl generator
70497 ** script numbers the opcodes correctly. Changes to this routine must be
70498 ** coordinated with changes to mkopcodeh.tcl.
70499 */
70500 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
 
70501 int nMaxArgs = *pMaxFuncArgs;
70502 Op *pOp;
70503 Parse *pParse = p->pParse;
70504 int *aLabel = pParse->aLabel;
70505 p->readOnly = 1;
70506 p->bIsReader = 0;
70507 pOp = &p->aOp[p->nOp-1];
70508 while(1){
70509
70510 /* Only JUMP opcodes and the short list of special opcodes in the switch
70511 ** below need to be considered. The mkopcodeh.tcl generator script groups
70512 ** all these opcodes together near the front of the opcode list. Skip
70513 ** any opcode that does not need processing by virtual of the fact that
70514 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
70515 */
70516 if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){
70517 /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70518 ** cases from this switch! */
70519 switch( pOp->opcode ){
70520 case OP_Transaction: {
70521 if( pOp->p2!=0 ) p->readOnly = 0;
70522 /* fall thru */
70523 }
70524 case OP_AutoCommit:
70525 case OP_Savepoint: {
70526 p->bIsReader = 1;
70527 break;
70528 }
70529 #ifndef SQLITE_OMIT_WAL
70530 case OP_Checkpoint:
70531 #endif
70532 case OP_Vacuum:
70533 case OP_JournalMode: {
70534 p->readOnly = 0;
70535 p->bIsReader = 1;
70536 break;
70537 }
70538 #ifndef SQLITE_OMIT_VIRTUALTABLE
70539 case OP_VUpdate: {
70540 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70541 break;
70542 }
70543 case OP_VFilter: {
70544 int n;
70545 assert( (pOp - p->aOp) >= 3 );
70546 assert( pOp[-1].opcode==OP_Integer );
70547 n = pOp[-1].p1;
70548 if( n>nMaxArgs ) nMaxArgs = n;
70549 break;
70550 }
70551 #endif
70552 case OP_Next:
70553 case OP_NextIfOpen:
70554 case OP_SorterNext: {
70555 pOp->p4.xAdvance = sqlite3BtreeNext;
70556 pOp->p4type = P4_ADVANCE;
70557 break;
70558 }
70559 case OP_Prev:
70560 case OP_PrevIfOpen: {
70561 pOp->p4.xAdvance = sqlite3BtreePrevious;
70562 pOp->p4type = P4_ADVANCE;
70563 break;
70564 }
70565 }
70566 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70567 assert( ADDR(pOp->p2)<pParse->nLabel );
70568 pOp->p2 = aLabel[ADDR(pOp->p2)];
70569 }
70570 }
70571 if( pOp==p->aOp ) break;
70572 pOp--;
70573 }
70574 sqlite3DbFree(p->db, pParse->aLabel);
70575 pParse->aLabel = 0;
70576 pParse->nLabel = 0;
70577 *pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76799,11 @@
76799 nByte =
76800 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
76801 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
76802
76803 assert( iCur>=0 && iCur<p->nCursor );
76804 if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
76805 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
76806 p->apCsr[iCur] = 0;
76807 }
76808 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
76809 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76876,27 @@
76876 u8 enc /* Use this text encoding */
76877 ){
76878 if( affinity>=SQLITE_AFF_NUMERIC ){
76879 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
76880 || affinity==SQLITE_AFF_NUMERIC );
76881 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
76882 if( (pRec->flags & MEM_Real)==0 ){
76883 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
76884 }else{
76885 sqlite3VdbeIntegerAffinity(pRec);
76886 }
76887 }
76888 }else if( affinity==SQLITE_AFF_TEXT ){
76889 /* Only attempt the conversion to TEXT if there is an integer or real
76890 ** representation (blob and NULL do not get converted) but no string
76891 ** representation. It would be harmless to repeat the conversion if
76892 ** there is already a string rep, but it is pointless to waste those
76893 ** CPU cycles. */
76894 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
76895 if( (pRec->flags&(MEM_Real|MEM_Int)) ){
76896 sqlite3VdbeMemStringify(pRec, enc, 1);
76897 }
76898 }
76899 pRec->flags &= ~(MEM_Real|MEM_Int);
76900 }
76901 }
76902
@@ -76796,11 +77218,11 @@
77218 Mem *pOut;
77219 assert( pOp->p2>0 );
77220 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77221 pOut = &p->aMem[pOp->p2];
77222 memAboutToChange(p, pOut);
77223 if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/
77224 return out2PrereleaseWithClear(pOut);
77225 }else{
77226 pOut->flags = MEM_Int;
77227 return pOut;
77228 }
@@ -76928,41 +77350,43 @@
77350 }
77351 #endif
77352
77353 /* Sanity checking on other operands */
77354 #ifdef SQLITE_DEBUG
77355 {
77356 u8 opProperty = sqlite3OpcodeProperty[pOp->opcode];
77357 if( (opProperty & OPFLG_IN1)!=0 ){
77358 assert( pOp->p1>0 );
77359 assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
77360 assert( memIsValid(&aMem[pOp->p1]) );
77361 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
77362 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
77363 }
77364 if( (opProperty & OPFLG_IN2)!=0 ){
77365 assert( pOp->p2>0 );
77366 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77367 assert( memIsValid(&aMem[pOp->p2]) );
77368 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
77369 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
77370 }
77371 if( (opProperty & OPFLG_IN3)!=0 ){
77372 assert( pOp->p3>0 );
77373 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77374 assert( memIsValid(&aMem[pOp->p3]) );
77375 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
77376 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
77377 }
77378 if( (opProperty & OPFLG_OUT2)!=0 ){
77379 assert( pOp->p2>0 );
77380 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77381 memAboutToChange(p, &aMem[pOp->p2]);
77382 }
77383 if( (opProperty & OPFLG_OUT3)!=0 ){
77384 assert( pOp->p3>0 );
77385 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77386 memAboutToChange(p, &aMem[pOp->p3]);
77387 }
77388 }
77389 #endif
77390 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
77391 pOrigOp = pOp;
77392 #endif
@@ -77198,12 +77622,10 @@
77622 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
77623 ** every program. So a jump past the last instruction of the program
77624 ** is the same as executing Halt.
77625 */
77626 case OP_Halt: {
 
 
77627 VdbeFrame *pFrame;
77628 int pcx;
77629
77630 pcx = (int)(pOp - aOp);
77631 if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77650,32 @@
77650 break;
77651 }
77652 p->rc = pOp->p1;
77653 p->errorAction = (u8)pOp->p2;
77654 p->pc = pcx;
77655 assert( pOp->p5>=0 && pOp->p5<=4 );
77656 if( p->rc ){
77657 if( pOp->p5 ){
77658 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
77659 "FOREIGN KEY" };
 
77660 testcase( pOp->p5==1 );
77661 testcase( pOp->p5==2 );
77662 testcase( pOp->p5==3 );
77663 testcase( pOp->p5==4 );
77664 sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]);
77665 if( pOp->p4.z ){
77666 p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
77667 }
77668 }else{
 
 
 
 
 
 
 
77669 sqlite3VdbeError(p, "%s", pOp->p4.z);
 
 
77670 }
77671 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
77672 }
77673 rc = sqlite3VdbeHalt(p);
77674 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
77675 if( rc==SQLITE_BUSY ){
77676 p->rc = SQLITE_BUSY;
77677 }else{
77678 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
77679 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
77680 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
77681 }
@@ -77321,14 +77737,11 @@
77737 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
77738
77739 #ifndef SQLITE_OMIT_UTF16
77740 if( encoding!=SQLITE_UTF8 ){
77741 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77742 assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
 
 
 
77743 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
77744 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
77745 assert( VdbeMemDynamic(pOut)==0 );
77746 pOut->szMalloc = 0;
77747 pOut->flags |= MEM_Static;
@@ -77337,26 +77750,30 @@
77750 }
77751 pOp->p4type = P4_DYNAMIC;
77752 pOp->p4.z = pOut->z;
77753 pOp->p1 = pOut->n;
77754 }
77755 testcase( rc==SQLITE_TOOBIG );
77756 #endif
77757 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77758 goto too_big;
77759 }
77760 assert( rc==SQLITE_OK );
77761 /* Fall through to the next case, OP_String */
77762 }
77763
77764 /* Opcode: String P1 P2 P3 P4 P5
77765 ** Synopsis: r[P2]='P4' (len=P1)
77766 **
77767 ** The string value P4 of length P1 (bytes) is stored in register P2.
77768 **
77769 ** If P3 is not zero and the content of register P3 is equal to P5, then
77770 ** the datatype of the register P2 is converted to BLOB. The content is
77771 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
77772 ** of a string, as if it had been CAST. In other words:
77773 **
77774 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
77775 */
77776 case OP_String: { /* out2 */
77777 assert( pOp->p4.z!=0 );
77778 pOut = out2Prerelease(p, pOp);
77779 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77780,15 @@
77780 pOut->z = pOp->p4.z;
77781 pOut->n = pOp->p1;
77782 pOut->enc = encoding;
77783 UPDATE_MAX_BLOBSIZE(pOut);
77784 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77785 if( pOp->p3>0 ){
 
77786 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77787 pIn3 = &aMem[pOp->p3];
77788 assert( pIn3->flags & MEM_Int );
77789 if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77790 }
77791 #endif
77792 break;
77793 }
77794
@@ -82224,25 +82640,10 @@
82640 if( pIn1->u.i==0 ) goto jump_to_p2;
82641 break;
82642 }
82643
82644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82645 /* Opcode: AggStep0 * P2 P3 P4 P5
82646 ** Synopsis: accum=r[P3] step(r[P2@P5])
82647 **
82648 ** Execute the step function for an aggregate. The
82649 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83532,16 @@
83532 #ifndef NDEBUG
83533 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
83534
83535 #ifdef SQLITE_DEBUG
83536 if( db->flags & SQLITE_VdbeTrace ){
83537 u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode];
83538 if( rc!=0 ) printf("rc=%d\n",rc);
83539 if( opProperty & (OPFLG_OUT2) ){
83540 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
83541 }
83542 if( opProperty & OPFLG_OUT3 ){
83543 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
83544 }
83545 }
83546 #endif /* SQLITE_DEBUG */
83547 #endif /* NDEBUG */
@@ -84648,11 +85050,10 @@
85050 int nField, /* Number of key fields in each record */
85051 VdbeCursor *pCsr /* Cursor that holds the new sorter */
85052 ){
85053 int pgsz; /* Page size of main database */
85054 int i; /* Used to iterate through aTask[] */
 
85055 VdbeSorter *pSorter; /* The new sorter */
85056 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
85057 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
85058 int sz; /* Size of pSorter in bytes */
85059 int rc = SQLITE_OK;
@@ -84705,15 +85106,24 @@
85106 SortSubtask *pTask = &pSorter->aTask[i];
85107 pTask->pSorter = pSorter;
85108 }
85109
85110 if( !sqlite3TempInMemory(db) ){
85111 i64 mxCache; /* Cache size in bytes*/
85112 u32 szPma = sqlite3GlobalConfig.szPma;
85113 pSorter->mnPmaSize = szPma * pgsz;
85114
85115 mxCache = db->aDb[0].pSchema->cache_size;
85116 if( mxCache<0 ){
85117 /* A negative cache-size value C indicates that the cache is abs(C)
85118 ** KiB in size. */
85119 mxCache = mxCache * -1024;
85120 }else{
85121 mxCache = mxCache * pgsz;
85122 }
85123 mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
85124 pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
85125
85126 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
85127 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
85128 ** large heap allocations.
85129 */
@@ -86473,10 +86883,19 @@
86883 *************************************************************************
86884 **
86885 ** This file contains code use to implement an in-memory rollback journal.
86886 ** The in-memory rollback journal is used to journal transactions for
86887 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
86888 **
86889 ** Update: The in-memory journal is also used to temporarily cache
86890 ** smaller journals that are not critical for power-loss recovery.
86891 ** For example, statement journals that are not too big will be held
86892 ** entirely in memory, thus reducing the number of file I/O calls, and
86893 ** more importantly, reducing temporary file creation events. If these
86894 ** journals become too large for memory, they are spilled to disk. But
86895 ** in the common case, they are usually small and no file I/O needs to
86896 ** occur.
86897 */
86898 /* #include "sqliteInt.h" */
86899
86900 /* Forward references to internal structures */
86901 typedef struct MemJournal MemJournal;
@@ -87799,10 +88218,11 @@
88218 notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
88219 sqlite3WalkSelect(pWalker, pExpr->x.pSelect);
88220 assert( pNC->nRef>=nRef );
88221 if( nRef!=pNC->nRef ){
88222 ExprSetProperty(pExpr, EP_VarSelect);
88223 pNC->ncFlags |= NC_VarSelect;
88224 }
88225 }
88226 break;
88227 }
88228 case TK_VARIABLE: {
@@ -89006,19 +89426,17 @@
89426 if( pToken ){
89427 if( nExtra==0 ){
89428 pNew->flags |= EP_IntValue;
89429 pNew->u.iValue = iValue;
89430 }else{
 
89431 pNew->u.zToken = (char*)&pNew[1];
89432 assert( pToken->z!=0 || pToken->n==0 );
89433 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
89434 pNew->u.zToken[pToken->n] = 0;
89435 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
89436 if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted;
89437 sqlite3Dequote(pNew->u.zToken);
 
89438 }
89439 }
89440 }
89441 #if SQLITE_MAX_EXPR_DEPTH>0
89442 pNew->nHeight = 1;
@@ -89096,10 +89514,26 @@
89514 if( p ) {
89515 sqlite3ExprCheckHeight(pParse, p->nHeight);
89516 }
89517 return p;
89518 }
89519
89520 /*
89521 ** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due
89522 ** do a memory allocation failure) then delete the pSelect object.
89523 */
89524 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){
89525 if( pExpr ){
89526 pExpr->x.pSelect = pSelect;
89527 ExprSetProperty(pExpr, EP_xIsSelect|EP_Subquery);
89528 sqlite3ExprSetHeightAndFlags(pParse, pExpr);
89529 }else{
89530 assert( pParse->db->mallocFailed );
89531 sqlite3SelectDelete(pParse->db, pSelect);
89532 }
89533 }
89534
89535
89536 /*
89537 ** If the expression is always either TRUE or FALSE (respectively),
89538 ** then return 1. If one cannot determine the truth value of the
89539 ** expression at compile-time return 0.
@@ -89257,12 +89691,12 @@
89691 }
89692
89693 /*
89694 ** Recursively delete an expression tree.
89695 */
89696 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
89697 assert( p!=0 );
89698 /* Sanity check: Assert that the IntValue is non-negative if it exists */
89699 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
89700 if( !ExprHasProperty(p, EP_TokenOnly) ){
89701 /* The Expr.x union is never used at the same time as Expr.pRight */
89702 assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89710,13 @@
89710 }
89711 }
89712 if( !ExprHasProperty(p, EP_Static) ){
89713 sqlite3DbFree(db, p);
89714 }
89715 }
89716 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89717 if( p ) sqlite3ExprDeleteNN(db, p);
89718 }
89719
89720 /*
89721 ** Return the number of bytes allocated for the expression structure
89722 ** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89765,11 @@
89765 static int dupedExprStructSize(Expr *p, int flags){
89766 int nSize;
89767 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
89768 assert( EXPR_FULLSIZE<=0xfff );
89769 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89770 if( 0==flags ){
89771 nSize = EXPR_FULLSIZE;
89772 }else{
89773 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
89774 assert( !ExprHasProperty(p, EP_FromJoin) );
89775 assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89827,92 @@
89827 ** to store the copy of expression p, the copies of p->u.zToken
89828 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
89829 ** if any. Before returning, *pzBuffer is set to the first byte past the
89830 ** portion of the buffer copied into by this function.
89831 */
89832 static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
89833 Expr *pNew; /* Value to return */
89834 u8 *zAlloc; /* Memory space from which to build Expr object */
89835 u32 staticFlag; /* EP_Static if space not obtained from malloc */
89836
89837 assert( db!=0 );
89838 assert( p );
89839 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
89840 assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE );
89841
89842 /* Figure out where to write the new Expr structure. */
89843 if( pzBuffer ){
89844 zAlloc = *pzBuffer;
89845 staticFlag = EP_Static;
89846 }else{
89847 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
89848 staticFlag = 0;
89849 }
89850 pNew = (Expr *)zAlloc;
89851
89852 if( pNew ){
89853 /* Set nNewSize to the size allocated for the structure pointed to
89854 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89855 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89856 ** by the copy of the p->u.zToken string (if any).
89857 */
89858 const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
89859 const int nNewSize = nStructSize & 0xfff;
89860 int nToken;
89861 if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89862 nToken = sqlite3Strlen30(p->u.zToken) + 1;
89863 }else{
89864 nToken = 0;
89865 }
89866 if( dupFlags ){
89867 assert( ExprHasProperty(p, EP_Reduced)==0 );
89868 memcpy(zAlloc, p, nNewSize);
89869 }else{
89870 u32 nSize = (u32)exprStructSize(p);
89871 memcpy(zAlloc, p, nSize);
89872 if( nSize<EXPR_FULLSIZE ){
89873 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89874 }
89875 }
89876
89877 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89878 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89879 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89880 pNew->flags |= staticFlag;
89881
89882 /* Copy the p->u.zToken string, if any. */
89883 if( nToken ){
89884 char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89885 memcpy(zToken, p->u.zToken, nToken);
89886 }
89887
89888 if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89889 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89890 if( ExprHasProperty(p, EP_xIsSelect) ){
89891 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
89892 }else{
89893 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
89894 }
89895 }
89896
89897 /* Fill in pNew->pLeft and pNew->pRight. */
89898 if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89899 zAlloc += dupedExprNodeSize(p, dupFlags);
89900 if( ExprHasProperty(pNew, EP_Reduced) ){
89901 pNew->pLeft = p->pLeft ?
89902 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0;
89903 pNew->pRight = p->pRight ?
89904 exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
89905 }
89906 if( pzBuffer ){
89907 *pzBuffer = zAlloc;
89908 }
89909 }else{
89910 if( !ExprHasProperty(p, EP_TokenOnly) ){
89911 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89912 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89913 }
 
 
89914 }
89915 }
89916 return pNew;
89917 }
89918
@@ -89523,11 +89960,11 @@
89960 ** truncated version of the usual Expr structure that will be stored as
89961 ** part of the in-memory representation of the database schema.
89962 */
89963 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
89964 assert( flags==0 || flags==EXPRDUP_REDUCE );
89965 return p ? exprDup(db, p, flags, 0) : 0;
89966 }
89967 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
89968 ExprList *pNew;
89969 struct ExprList_item *pItem, *pOldItem;
89970 int i;
@@ -89745,11 +90182,11 @@
90182 struct ExprList_item *pItem;
90183 assert( pList->nExpr>0 );
90184 pItem = &pList->a[pList->nExpr-1];
90185 assert( pItem->zName==0 );
90186 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
90187 if( dequote ) sqlite3Dequote(pItem->zName);
90188 }
90189 }
90190
90191 /*
90192 ** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90231,24 @@
90231 }
90232
90233 /*
90234 ** Delete an entire expression list.
90235 */
90236 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
90237 int i;
90238 struct ExprList_item *pItem;
 
90239 assert( pList->a!=0 || pList->nExpr==0 );
90240 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
90241 sqlite3ExprDelete(db, pItem->pExpr);
90242 sqlite3DbFree(db, pItem->zName);
90243 sqlite3DbFree(db, pItem->zSpan);
90244 }
90245 sqlite3DbFree(db, pList->a);
90246 sqlite3DbFree(db, pList);
90247 }
90248 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90249 if( pList ) exprListDeleteNN(db, pList);
90250 }
90251
90252 /*
90253 ** Return the bitwise-OR of all Expr.flags fields in the given
90254 ** ExprList.
@@ -90851,10 +91290,23 @@
91290 #endif
91291 }
91292 }
91293 }
91294
91295 #if defined(SQLITE_DEBUG)
91296 /*
91297 ** Verify the consistency of the column cache
91298 */
91299 static int cacheIsValid(Parse *pParse){
91300 int i, n;
91301 for(i=n=0; i<SQLITE_N_COLCACHE; i++){
91302 if( pParse->aColCache[i].iReg>0 ) n++;
91303 }
91304 return n==pParse->nColCache;
91305 }
91306 #endif
91307
91308 /*
91309 ** Clear a cache entry.
91310 */
91311 static void cacheEntryClear(Parse *pParse, struct yColCache *p){
91312 if( p->tempReg ){
@@ -90861,10 +91313,13 @@
91313 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
91314 pParse->aTempReg[pParse->nTempReg++] = p->iReg;
91315 }
91316 p->tempReg = 0;
91317 }
91318 p->iReg = 0;
91319 pParse->nColCache--;
91320 assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
91321 }
91322
91323
91324 /*
91325 ** Record in the column cache that a particular column from a
@@ -90904,10 +91359,12 @@
91359 p->iTable = iTab;
91360 p->iColumn = iCol;
91361 p->iReg = iReg;
91362 p->tempReg = 0;
91363 p->lru = pParse->iCacheCnt++;
91364 pParse->nColCache++;
91365 assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
91366 return;
91367 }
91368 }
91369
91370 /* Replace the last recently used */
@@ -90925,28 +91382,27 @@
91382 p->iTable = iTab;
91383 p->iColumn = iCol;
91384 p->iReg = iReg;
91385 p->tempReg = 0;
91386 p->lru = pParse->iCacheCnt++;
91387 assert( cacheIsValid(pParse) );
91388 return;
91389 }
91390 }
91391
91392 /*
91393 ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
91394 ** Purge the range of registers from the column cache.
91395 */
91396 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
 
 
91397 struct yColCache *p;
91398 if( iReg<=0 || pParse->nColCache==0 ) return;
91399 p = &pParse->aColCache[SQLITE_N_COLCACHE-1];
91400 while(1){
91401 if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p);
91402 if( p==pParse->aColCache ) break;
91403 p--;
91404 }
91405 }
91406
91407 /*
91408 ** Remember the current column cache context. Any new entries added
@@ -90978,11 +91434,10 @@
91434 }
91435 #endif
91436 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91437 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
91438 cacheEntryClear(pParse, p);
 
91439 }
91440 }
91441 }
91442
91443 /*
@@ -91113,11 +91568,10 @@
91568 }
91569 #endif
91570 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91571 if( p->iReg ){
91572 cacheEntryClear(pParse, p);
 
91573 }
91574 }
91575 }
91576
91577 /*
@@ -91154,10 +91608,11 @@
91608 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
91609 }
91610 return 0;
91611 }
91612 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
91613
91614
91615 /*
91616 ** Convert an expression node to a TK_REGISTER
91617 */
91618 static void exprToRegister(Expr *p, int iReg){
@@ -96951,20 +97406,14 @@
97406 ** contains lookaside memory. (Table objects in the schema do not use
97407 ** lookaside memory, but some ephemeral Table objects do.) Or the
97408 ** db parameter can be used with db->pnBytesFreed to measure the memory
97409 ** used by the Table object.
97410 */
97411 static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
97412 Index *pIndex, *pNext;
97413 TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
97414
 
 
 
 
 
 
97415 /* Record the number of outstanding lookaside allocations in schema Tables
97416 ** prior to doing any free() operations. Since schema Tables do not use
97417 ** lookaside, this number should not change. */
97418 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
97419 db->lookaside.nOut : 0 );
@@ -97000,10 +97449,17 @@
97449 sqlite3DbFree(db, pTable);
97450
97451 /* Verify that no lookaside memory was used by schema tables */
97452 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
97453 }
97454 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
97455 /* Do not delete the table until the reference count reaches zero. */
97456 if( !pTable ) return;
97457 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
97458 deleteTable(db, pTable);
97459 }
97460
97461
97462 /*
97463 ** Unlink the given table from the hash tables and the delete the
97464 ** table structure with all its indices and foreign keys.
97465 */
@@ -97445,10 +97901,11 @@
97901 pCol->szEst = 1;
97902 }else{
97903 zType = z + sqlite3Strlen30(z) + 1;
97904 memcpy(zType, pType->z, pType->n);
97905 zType[pType->n] = 0;
97906 sqlite3Dequote(zType);
97907 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
97908 pCol->colFlags |= COLFLAG_HASTYPE;
97909 }
97910 p->nCol++;
97911 pParse->constraintName.n = 0;
@@ -98579,11 +99036,11 @@
99036 assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
99037 }else{
99038 pTable->nCol = 0;
99039 nErr++;
99040 }
99041 sqlite3DeleteTable(db, pSelTab);
99042 sqlite3SelectDelete(db, pSel);
99043 db->lookaside.bDisable--;
99044 } else {
99045 nErr++;
99046 }
@@ -101410,11 +101867,11 @@
101867
101868 /* Check that there isn't an ORDER BY without a LIMIT clause.
101869 */
101870 if( pOrderBy && (pLimit == 0) ) {
101871 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101872 goto limit_where_cleanup;
101873 }
101874
101875 /* We only need to generate a select expression if there
101876 ** is a limit/offset term to enforce.
101877 */
@@ -101432,44 +101889,34 @@
101889 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101890 ** );
101891 */
101892
101893 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101894 if( pSelectRowid == 0 ) goto limit_where_cleanup;
101895 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101896 if( pEList == 0 ) goto limit_where_cleanup;
101897
101898 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101899 ** and the SELECT subtree. */
101900 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101901 if( pSelectSrc == 0 ) {
101902 sqlite3ExprListDelete(pParse->db, pEList);
101903 goto limit_where_cleanup;
101904 }
101905
101906 /* generate the SELECT expression tree. */
101907 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101908 pOrderBy,0,pLimit,pOffset);
101909 if( pSelect == 0 ) return 0;
101910
101911 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101912 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101913 pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
101914 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
 
 
 
 
 
101915 return pInClause;
101916
101917 limit_where_cleanup:
 
 
 
 
 
101918 sqlite3ExprDelete(pParse->db, pWhere);
101919 sqlite3ExprListDelete(pParse->db, pOrderBy);
101920 sqlite3ExprDelete(pParse->db, pLimit);
101921 sqlite3ExprDelete(pParse->db, pOffset);
101922 return 0;
@@ -101516,15 +101963,16 @@
101963 int iEphCur = 0; /* Ephemeral table holding all primary key values */
101964 int iRowSet = 0; /* Register for rowset of rows to delete */
101965 int addrBypass = 0; /* Address of jump over the delete logic */
101966 int addrLoop = 0; /* Top of the delete loop */
101967 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
101968 int bComplex; /* True if there are triggers or FKs or
101969 ** subqueries in the WHERE clause */
101970
101971 #ifndef SQLITE_OMIT_TRIGGER
101972 int isView; /* True if attempting to delete from a view */
101973 Trigger *pTrigger; /* List of table triggers, if required */
 
101974 #endif
101975
101976 memset(&sContext, 0, sizeof(sContext));
101977 db = pParse->db;
101978 if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101996,10 @@
101996 isView = pTab->pSelect!=0;
101997 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101998 #else
101999 # define pTrigger 0
102000 # define isView 0
 
102001 #endif
102002 #ifdef SQLITE_OMIT_VIEW
102003 # undef isView
102004 # define isView 0
102005 #endif
@@ -101650,11 +102097,12 @@
102097 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
102098 }
102099 }else
102100 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
102101 {
102102 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE;
102103 if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
102104 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
102105 if( HasRowid(pTab) ){
102106 /* For a rowid table, initialize the RowSet to an empty set */
102107 pPk = 0;
102108 nPk = 1;
@@ -103561,10 +104009,18 @@
104009 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
104010 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
104011 const char *zProc;
104012 sqlite3 *db = sqlite3_context_db_handle(context);
104013 char *zErrMsg = 0;
104014
104015 /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
104016 ** flag is set. See the sqlite3_enable_load_extension() API.
104017 */
104018 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
104019 sqlite3_result_error(context, "not authorized", -1);
104020 return;
104021 }
104022
104023 if( argc==2 ){
104024 zProc = (const char *)sqlite3_value_text(argv[1]);
104025 }else{
104026 zProc = 0;
@@ -108756,12 +109212,13 @@
109212 if( pzErrMsg ) *pzErrMsg = 0;
109213
109214 /* Ticket #1863. To avoid a creating security problems for older
109215 ** applications that relink against newer versions of SQLite, the
109216 ** ability to run load_extension is turned off by default. One
109217 ** must call either sqlite3_enable_load_extension(db) or
109218 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
109219 ** to turn on extension loading.
109220 */
109221 if( (db->flags & SQLITE_LoadExtension)==0 ){
109222 if( pzErrMsg ){
109223 *pzErrMsg = sqlite3_mprintf("not authorized");
109224 }
@@ -108896,13 +109353,13 @@
109353 ** default so as not to open security holes in older applications.
109354 */
109355 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
109356 sqlite3_mutex_enter(db->mutex);
109357 if( onoff ){
109358 db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
109359 }else{
109360 db->flags &= ~(SQLITE_LoadExtension|SQLITE_LoadExtFunc);
109361 }
109362 sqlite3_mutex_leave(db->mutex);
109363 return SQLITE_OK;
109364 }
109365
@@ -112475,11 +112932,11 @@
112932 sqlite3ExprListDelete(db, p->pGroupBy);
112933 sqlite3ExprDelete(db, p->pHaving);
112934 sqlite3ExprListDelete(db, p->pOrderBy);
112935 sqlite3ExprDelete(db, p->pLimit);
112936 sqlite3ExprDelete(db, p->pOffset);
112937 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
112938 if( bFree ) sqlite3DbFree(db, p);
112939 p = pPrior;
112940 bFree = 1;
112941 }
112942 }
@@ -112570,11 +113027,11 @@
113027
113028 /*
113029 ** Delete the given Select structure and all of its substructures.
113030 */
113031 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
113032 if( p ) clearSelect(db, p, 1);
113033 }
113034
113035 /*
113036 ** Return a pointer to the right-most SELECT statement in a compound.
113037 */
@@ -114190,23 +114647,23 @@
114647
114648 /*
114649 ** Get a VDBE for the given parser context. Create a new one if necessary.
114650 ** If an error occurs, return NULL and leave a message in pParse.
114651 */
114652 static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
114653 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114654 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114655 if( pParse->pToplevel==0
114656 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114657 ){
114658 pParse->okConstFactor = 1;
 
 
 
 
114659 }
114660 return v;
114661 }
114662 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114663 Vdbe *v = pParse->pVdbe;
114664 return v ? v : allocVdbe(pParse);
114665 }
114666
114667
114668 /*
114669 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116643,22 @@
116643 Expr *pWhere, /* The WHERE clause of the outer query */
116644 int iCursor /* Cursor number of the subquery */
116645 ){
116646 Expr *pNew;
116647 int nChng = 0;
116648 Select *pX; /* For looping over compound SELECTs in pSubq */
116649 if( pWhere==0 ) return 0;
116650 for(pX=pSubq; pX; pX=pX->pPrior){
116651 if( (pX->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116652 testcase( pX->selFlags & SF_Aggregate );
116653 testcase( pX->selFlags & SF_Recursive );
116654 testcase( pX!=pSubq );
116655 return 0; /* restrictions (1) and (2) */
116656 }
116657 }
116658 if( pSubq->pLimit!=0 ){
116659 return 0; /* restriction (3) */
116660 }
116661 while( pWhere->op==TK_AND ){
116662 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116663 pWhere = pWhere->pLeft;
116664 }
@@ -117493,10 +117956,17 @@
117956 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117957 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117958 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
117959 ** original setting of the SF_Distinct flag, not the current setting */
117960 assert( sDistinct.isTnct );
117961
117962 #if SELECTTRACE_ENABLED
117963 if( sqlite3SelectTrace & 0x400 ){
117964 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
117965 sqlite3TreeViewSelect(0, p, 0);
117966 }
117967 #endif
117968 }
117969
117970 /* If there is an ORDER BY clause, then create an ephemeral index to
117971 ** do the sorting. But this sorting ephemeral index might end up
117972 ** being unused if the data can be extracted in pre-sorted order.
@@ -119731,11 +120201,12 @@
120201 /* Begin the database scan
120202 */
120203 if( HasRowid(pTab) ){
120204 sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid);
120205 pWInfo = sqlite3WhereBegin(
120206 pParse, pTabList, pWhere, 0, 0,
120207 WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur
120208 );
120209 if( pWInfo==0 ) goto update_cleanup;
120210 okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass);
120211
120212 /* Remember the rowid of every item to be updated.
@@ -121888,11 +122359,11 @@
122359 int addrSkip; /* Jump here for next iteration of skip-scan */
122360 int addrCont; /* Jump here to continue with the next loop cycle */
122361 int addrFirst; /* First instruction of interior of the loop */
122362 int addrBody; /* Beginning of the body of this loop */
122363 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122364 u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */
122365 int addrLikeRep; /* LIKE range processing address */
122366 #endif
122367 u8 iFrom; /* Which entry in the FROM clause */
122368 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
122369 int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122697,11 @@
122697 */
122698 struct WhereInfo {
122699 Parse *pParse; /* Parsing and code generating context */
122700 SrcList *pTabList; /* List of tables in the join */
122701 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122702 ExprList *pDistinctSet; /* DISTINCT over all these values */
122703 WhereLoop *pLoops; /* List of all WhereLoop objects */
122704 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122705 LogEst nRowOut; /* Estimated number of output rows */
122706 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122707 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122781,18 @@
122781 /*
122782 ** Bitmasks for the operators on WhereTerm objects. These are all
122783 ** operators that are of interest to the query planner. An
122784 ** OR-ed combination of these values can be used when searching for
122785 ** particular WhereTerms within a WhereClause.
122786 **
122787 ** Value constraints:
122788 ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
122789 ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
122790 ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
122791 ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
122792 ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
122793 ** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
122794 */
122795 #define WO_IN 0x0001
122796 #define WO_EQ 0x0002
122797 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122798 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123375,14 @@
123375 return regBase;
123376 }
123377
123378 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123379 /*
123380 ** If the most recently coded instruction is a constant range constraint
123381 ** (a string literal) that originated from the LIKE optimization, then
123382 ** set P3 and P5 on the OP_String opcode so that the string will be cast
123383 ** to a BLOB at appropriate times.
123384 **
123385 ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
123386 ** expression: "x>='ABC' AND x<'abd'". But this requires that the range
123387 ** scan loop run twice, once for strings and a second time for BLOBs.
123388 ** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123403,12 @@
123403 assert( pLevel->iLikeRepCntr>0 );
123404 pOp = sqlite3VdbeGetOp(v, -1);
123405 assert( pOp!=0 );
123406 assert( pOp->opcode==OP_String8
123407 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
123408 pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
123409 pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
123410 }
123411 }
123412 #else
123413 # define whereLikeOptimizationStringFixup(A,B,C)
123414 #endif
@@ -123277,11 +123757,17 @@
123757 pCompare->pLeft = 0;
123758 sqlite3ExprDelete(db, pCompare);
123759 }
123760 }
123761 }
123762 /* These registers need to be preserved in case there is an IN operator
123763 ** loop. So we could deallocate the registers here (and potentially
123764 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
123765 ** simpler and safer to simply not reuse the registers.
123766 **
123767 ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123768 */
123769 sqlite3ExprCachePop(pParse);
123770 }else
123771 #endif /* SQLITE_OMIT_VIRTUALTABLE */
123772
123773 if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123991,21 @@
123991 nExtraReg = 1;
123992 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123993 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123994 assert( pRangeStart!=0 ); /* LIKE opt constraints */
123995 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123996 pLevel->iLikeRepCntr = (u32)++pParse->nMem;
123997 sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
123998 VdbeComment((v, "LIKE loop counter"));
123999 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
124000 /* iLikeRepCntr actually stores 2x the counter register number. The
124001 ** bottom bit indicates whether the search order is ASC or DESC. */
124002 testcase( bRev );
124003 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
124004 assert( (bRev & ~1)==0 );
124005 pLevel->iLikeRepCntr <<=1;
124006 pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
 
 
124007 }
124008 #endif
124009 if( pRangeStart==0
124010 && (j = pIdx->aiColumn[nEq])>=0
124011 && pIdx->pTable->aCol[j].notNull==0
@@ -123650,11 +124139,11 @@
124139 disableTerm(pLevel, pRangeStart);
124140 disableTerm(pLevel, pRangeEnd);
124141 if( omitTable ){
124142 /* pIdx is a covering index. No need to access the main table. */
124143 }else if( HasRowid(pIdx->pTable) ){
124144 if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){
124145 iRowidReg = ++pParse->nMem;
124146 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
124147 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
124148 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg);
124149 VdbeCoverage(v);
@@ -123846,11 +124335,12 @@
124335 ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
124336 */
124337 wctrlFlags = WHERE_OMIT_OPEN_CLOSE
124338 | WHERE_FORCE_TABLE
124339 | WHERE_ONETABLE_ONLY
124340 | WHERE_NO_AUTOINDEX
124341 | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE);
124342 for(ii=0; ii<pOrWc->nTerm; ii++){
124343 WhereTerm *pOrTerm = &pOrWc->a[ii];
124344 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
124345 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
124346 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
@@ -124026,15 +124516,21 @@
124516 assert( pE!=0 );
124517 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124518 continue;
124519 }
124520 if( pTerm->wtFlags & TERM_LIKECOND ){
124521 /* If the TERM_LIKECOND flag is set, that means that the range search
124522 ** is sufficient to guarantee that the LIKE operator is true, so we
124523 ** can skip the call to the like(A,B) function. But this only works
124524 ** for strings. So do not skip the call to the function on the pass
124525 ** that compares BLOBs. */
124526 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124527 continue;
124528 #else
124529 u32 x = pLevel->iLikeRepCntr;
124530 assert( x>0 );
124531 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
124532 VdbeCoverage(v);
124533 #endif
124534 }
124535 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124536 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125882,14 @@
125882 if( p->op==TK_COLUMN ){
125883 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125884 return mask;
125885 }
125886 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125887 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125888 if( ExprHasProperty(p, EP_xIsSelect) ){
125889 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125890 }else if( p->x.pList ){
125891 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125892 }
125893 return mask;
125894 }
125895 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -125729,11 +126225,14 @@
126225 ** Initialize a WHERE clause scanner object. Return a pointer to the
126226 ** first match. Return NULL if there are no matches.
126227 **
126228 ** The scanner will be searching the WHERE clause pWC. It will look
126229 ** for terms of the form "X <op> <expr>" where X is column iColumn of table
126230 ** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx
126231 ** must be one of the indexes of table iCur.
126232 **
126233 ** The <op> must be one of the operators described by opMask.
126234 **
126235 ** If the search is for X and the WHERE clause contains terms of the
126236 ** form X=Y then this routine might also return terms of the form
126237 ** "Y <op> <expr>". The number of levels of transitivity is limited,
126238 ** but is enough to handle most commonly occurring SQL statements.
@@ -125777,15 +126276,16 @@
126276 return whereScanNext(pScan);
126277 }
126278
126279 /*
126280 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
126281 ** where X is a reference to the iColumn of table iCur or of index pIdx
126282 ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
126283 ** the op parameter. Return a pointer to the term. Return 0 if not found.
126284 **
126285 ** If pIdx!=0 then it must be one of the indexes of table iCur.
126286 ** Search for terms matching the iColumn-th column of pIdx
126287 ** rather than the iColumn-th column of table iCur.
126288 **
126289 ** The term returned might by Y=<expr> if there is another constraint in
126290 ** the WHERE clause that specifies that X=Y. Any such constraints will be
126291 ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The
@@ -127119,15 +127619,16 @@
127619 /*
127620 ** Print a WhereLoop object for debugging purposes
127621 */
127622 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127623 WhereInfo *pWInfo = pWC->pWInfo;
127624 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
127625 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127626 Table *pTab = pItem->pTab;
127627 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
127628 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127629 p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
127630 sqlite3DebugPrintf(" %12s",
127631 pItem->zAlias ? pItem->zAlias : pTab->zName);
127632 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127633 const char *zName;
127634 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129849,13 @@
129849 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129850 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129851 && nRowEst
129852 ){
129853 Bitmask notUsed;
129854 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
129855 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129856 if( rc==pWInfo->pDistinctSet->nExpr ){
129857 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129858 }
129859 }
129860 if( pWInfo->pOrderBy ){
129861 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +130066,18 @@
130066 ** the first cursor in an array of cursors for all indices. iIdxCur should
130067 ** be used to compute the appropriate cursor depending on which index is
130068 ** used.
130069 */
130070 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
130071 Parse *pParse, /* The parser context */
130072 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
130073 Expr *pWhere, /* The WHERE clause */
130074 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
130075 ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
130076 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
130077 int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number
130078 ** If WHERE_USE_LIMIT, then the limit amount */
130079 ){
130080 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
130081 int nTabList; /* Number of elements in pTabList */
130082 WhereInfo *pWInfo; /* Will become the return value of this function */
130083 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +130148,11 @@
130148 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
130149 pWInfo->nLevel = nTabList;
130150 pWInfo->pParse = pParse;
130151 pWInfo->pTabList = pTabList;
130152 pWInfo->pOrderBy = pOrderBy;
130153 pWInfo->pDistinctSet = pDistinctSet;
130154 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
130155 pWInfo->wctrlFlags = wctrlFlags;
130156 pWInfo->iLimit = iAuxArg;
130157 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
130158 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130221,17 @@
130221 /* Analyze all of the subexpressions. */
130222 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
130223 if( db->mallocFailed ) goto whereBeginError;
130224
130225 if( wctrlFlags & WHERE_WANT_DISTINCT ){
130226 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
130227 /* The DISTINCT marking is pointless. Ignore it. */
130228 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
130229 }else if( pOrderBy==0 ){
130230 /* Try to ORDER BY the result set to make distinct processing easier */
130231 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
130232 pWInfo->pOrderBy = pDistinctSet;
130233 }
130234 }
130235
130236 /* Construct the WhereLoop objects */
130237 #if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130306,14 @@
130306 }
130307 }
130308 #endif
130309 /* Attempt to omit tables from the join that do not effect the result */
130310 if( pWInfo->nLevel>=2
130311 && pDistinctSet!=0
130312 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
130313 ){
130314 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
130315 if( sWLB.pOrderBy ){
130316 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
130317 }
130318 while( pWInfo->nLevel>=2 ){
130319 WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130575,12 @@
130575 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130576 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130577 }
130578 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130579 if( pLevel->addrLikeRep ){
130580 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
130581 pLevel->addrLikeRep);
 
 
 
 
 
130582 VdbeCoverage(v);
130583 }
130584 #endif
130585 if( pLevel->iLeftJoin ){
130586 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130982,11 @@
130982 #endif
130983 /************* Begin control #defines *****************************************/
130984 #define YYCODETYPE unsigned char
130985 #define YYNOCODE 251
130986 #define YYACTIONTYPE unsigned short int
130987 #define YYWILDCARD 96
130988 #define sqlite3ParserTOKENTYPE Token
130989 typedef union {
130990 int yyinit;
130991 sqlite3ParserTOKENTYPE yy0;
130992 struct LimitVal yy64;
@@ -130590,402 +131086,404 @@
131086 ** yy_reduce_ofst[] For each state, the offset into yy_action for
131087 ** shifting non-terminals after a reduce.
131088 ** yy_default[] Default action for each state.
131089 **
131090 *********** Begin parsing tables **********************************************/
131091 #define YY_ACTTAB_COUNT (1501)
131092 static const YYACTIONTYPE yy_action[] = {
131093 /* 0 */ 315, 810, 339, 804, 5, 194, 194, 798, 92, 93,
131094 /* 10 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
131095 /* 20 */ 91, 91, 91, 290, 89, 89, 89, 89, 88, 88,
131096 /* 30 */ 87, 87, 87, 86, 339, 315, 952, 952, 803, 803,
131097 /* 40 */ 803, 922, 342, 92, 93, 83, 819, 819, 831, 834,
131098 /* 50 */ 823, 823, 90, 90, 91, 91, 91, 91, 123, 89,
131099 /* 60 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131100 /* 70 */ 88, 88, 87, 87, 87, 86, 339, 772, 952, 952,
131101 /* 80 */ 315, 87, 87, 87, 86, 339, 773, 68, 92, 93,
131102 /* 90 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
131103 /* 100 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
131104 /* 110 */ 87, 87, 87, 86, 339, 1302, 146, 921, 2, 315,
131105 /* 120 */ 427, 24, 679, 953, 48, 86, 339, 92, 93, 83,
131106 /* 130 */ 819, 819, 831, 834, 823, 823, 90, 90, 91, 91,
131107 /* 140 */ 91, 91, 94, 89, 89, 89, 89, 88, 88, 87,
131108 /* 150 */ 87, 87, 86, 339, 933, 933, 315, 259, 412, 398,
131109 /* 160 */ 396, 57, 733, 733, 92, 93, 83, 819, 819, 831,
131110 /* 170 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 56,
131111 /* 180 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131112 /* 190 */ 339, 315, 1245, 922, 342, 268, 934, 935, 241, 92,
131113 /* 200 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131114 /* 210 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
131115 /* 220 */ 88, 87, 87, 87, 86, 339, 315, 913, 1295, 682,
131116 /* 230 */ 687, 1295, 233, 397, 92, 93, 83, 819, 819, 831,
131117 /* 240 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
131118 /* 250 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131119 /* 260 */ 339, 315, 85, 82, 168, 680, 431, 938, 939, 92,
131120 /* 270 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131121 /* 280 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
131122 /* 290 */ 88, 87, 87, 87, 86, 339, 315, 319, 913, 1296,
131123 /* 300 */ 797, 911, 1296, 681, 92, 93, 83, 819, 819, 831,
131124 /* 310 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 335,
131125 /* 320 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131126 /* 330 */ 339, 315, 876, 876, 373, 85, 82, 168, 944, 92,
131127 /* 340 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131128 /* 350 */ 91, 91, 91, 91, 896, 89, 89, 89, 89, 88,
131129 /* 360 */ 88, 87, 87, 87, 86, 339, 315, 370, 307, 973,
131130 /* 370 */ 367, 1, 911, 433, 92, 93, 83, 819, 819, 831,
131131 /* 380 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 189,
131132 /* 390 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
131133 /* 400 */ 339, 315, 720, 948, 933, 933, 149, 718, 948, 92,
131134 /* 410 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
131135 /* 420 */ 91, 91, 91, 91, 434, 89, 89, 89, 89, 88,
131136 /* 430 */ 88, 87, 87, 87, 86, 339, 338, 938, 939, 947,
131137 /* 440 */ 694, 940, 974, 315, 953, 48, 934, 935, 715, 689,
131138 /* 450 */ 71, 92, 93, 83, 819, 819, 831, 834, 823, 823,
131139 /* 460 */ 90, 90, 91, 91, 91, 91, 320, 89, 89, 89,
131140 /* 470 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 412,
131141 /* 480 */ 403, 820, 820, 832, 835, 74, 92, 81, 83, 819,
131142 /* 490 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
131143 /* 500 */ 91, 698, 89, 89, 89, 89, 88, 88, 87, 87,
131144 /* 510 */ 87, 86, 339, 315, 259, 654, 655, 656, 393, 111,
131145 /* 520 */ 331, 153, 93, 83, 819, 819, 831, 834, 823, 823,
131146 /* 530 */ 90, 90, 91, 91, 91, 91, 434, 89, 89, 89,
131147 /* 540 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 188,
131148 /* 550 */ 187, 186, 824, 937, 328, 219, 953, 48, 83, 819,
131149 /* 560 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
131150 /* 570 */ 91, 956, 89, 89, 89, 89, 88, 88, 87, 87,
131151 /* 580 */ 87, 86, 339, 79, 429, 738, 3, 1174, 955, 348,
131152 /* 590 */ 737, 332, 792, 933, 933, 937, 79, 429, 730, 3,
131153 /* 600 */ 203, 160, 278, 391, 273, 390, 190, 892, 434, 400,
131154 /* 610 */ 741, 76, 77, 271, 287, 253, 353, 242, 78, 340,
131155 /* 620 */ 340, 85, 82, 168, 76, 77, 233, 397, 953, 48,
131156 /* 630 */ 432, 78, 340, 340, 277, 934, 935, 185, 439, 651,
131157 /* 640 */ 388, 385, 384, 432, 234, 276, 107, 418, 349, 337,
131158 /* 650 */ 336, 383, 893, 728, 215, 949, 123, 971, 308, 810,
131159 /* 660 */ 418, 436, 435, 412, 394, 798, 400, 873, 894, 123,
131160 /* 670 */ 721, 872, 810, 889, 436, 435, 215, 949, 798, 351,
131161 /* 680 */ 722, 697, 380, 434, 771, 371, 22, 434, 400, 79,
131162 /* 690 */ 429, 232, 3, 189, 413, 870, 803, 803, 803, 805,
131163 /* 700 */ 18, 54, 148, 953, 48, 956, 113, 953, 9, 803,
131164 /* 710 */ 803, 803, 805, 18, 310, 123, 748, 76, 77, 742,
131165 /* 720 */ 123, 325, 955, 866, 78, 340, 340, 113, 350, 359,
131166 /* 730 */ 85, 82, 168, 343, 960, 960, 432, 770, 412, 414,
131167 /* 740 */ 407, 23, 1240, 1240, 79, 429, 357, 3, 166, 91,
131168 /* 750 */ 91, 91, 91, 418, 89, 89, 89, 89, 88, 88,
131169 /* 760 */ 87, 87, 87, 86, 339, 810, 434, 436, 435, 792,
131170 /* 770 */ 320, 798, 76, 77, 789, 271, 123, 434, 360, 78,
131171 /* 780 */ 340, 340, 864, 85, 82, 168, 953, 9, 395, 743,
131172 /* 790 */ 360, 432, 253, 358, 252, 933, 933, 953, 30, 889,
131173 /* 800 */ 327, 216, 803, 803, 803, 805, 18, 113, 418, 89,
131174 /* 810 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131175 /* 820 */ 810, 113, 436, 435, 792, 185, 798, 288, 388, 385,
131176 /* 830 */ 384, 123, 113, 920, 2, 796, 696, 934, 935, 383,
131177 /* 840 */ 69, 429, 434, 3, 218, 110, 738, 253, 358, 252,
131178 /* 850 */ 434, 737, 933, 933, 892, 359, 222, 803, 803, 803,
131179 /* 860 */ 805, 18, 953, 47, 933, 933, 933, 933, 76, 77,
131180 /* 870 */ 953, 9, 366, 904, 217, 78, 340, 340, 677, 305,
131181 /* 880 */ 304, 303, 206, 301, 224, 259, 664, 432, 337, 336,
131182 /* 890 */ 434, 228, 247, 144, 934, 935, 933, 933, 667, 893,
131183 /* 900 */ 324, 1259, 96, 434, 418, 796, 934, 935, 934, 935,
131184 /* 910 */ 953, 48, 401, 148, 289, 894, 810, 417, 436, 435,
131185 /* 920 */ 677, 759, 798, 953, 9, 314, 220, 162, 161, 170,
131186 /* 930 */ 402, 239, 953, 8, 194, 683, 683, 410, 934, 935,
131187 /* 940 */ 238, 959, 933, 933, 225, 408, 945, 365, 957, 212,
131188 /* 950 */ 958, 172, 757, 803, 803, 803, 805, 18, 173, 365,
131189 /* 960 */ 176, 123, 171, 113, 244, 952, 246, 434, 356, 796,
131190 /* 970 */ 372, 365, 236, 960, 960, 810, 290, 804, 191, 165,
131191 /* 980 */ 852, 798, 259, 316, 934, 935, 237, 953, 34, 404,
131192 /* 990 */ 91, 91, 91, 91, 84, 89, 89, 89, 89, 88,
131193 /* 1000 */ 88, 87, 87, 87, 86, 339, 701, 952, 434, 240,
131194 /* 1010 */ 347, 758, 803, 803, 803, 434, 245, 1179, 434, 389,
131195 /* 1020 */ 434, 376, 434, 895, 167, 434, 405, 702, 953, 35,
131196 /* 1030 */ 673, 321, 221, 434, 333, 953, 11, 434, 953, 26,
131197 /* 1040 */ 953, 36, 953, 37, 251, 953, 38, 434, 259, 434,
131198 /* 1050 */ 757, 434, 329, 953, 27, 434, 223, 953, 28, 434,
131199 /* 1060 */ 690, 434, 67, 434, 65, 434, 862, 953, 39, 953,
131200 /* 1070 */ 40, 953, 41, 423, 434, 953, 10, 434, 772, 953,
131201 /* 1080 */ 42, 953, 98, 953, 43, 953, 44, 773, 434, 346,
131202 /* 1090 */ 434, 75, 434, 73, 953, 31, 434, 953, 45, 434,
131203 /* 1100 */ 259, 434, 690, 434, 757, 434, 887, 434, 953, 46,
131204 /* 1110 */ 953, 32, 953, 115, 434, 266, 953, 116, 951, 953,
131205 /* 1120 */ 117, 953, 52, 953, 33, 953, 99, 953, 49, 726,
131206 /* 1130 */ 434, 909, 434, 19, 953, 100, 434, 344, 434, 113,
131207 /* 1140 */ 434, 258, 692, 434, 259, 434, 670, 434, 20, 434,
131208 /* 1150 */ 953, 101, 953, 97, 434, 259, 953, 114, 953, 112,
131209 /* 1160 */ 953, 105, 113, 953, 104, 953, 102, 953, 103, 953,
131210 /* 1170 */ 51, 434, 148, 434, 953, 53, 167, 434, 259, 113,
131211 /* 1180 */ 300, 307, 912, 363, 311, 860, 248, 261, 209, 264,
131212 /* 1190 */ 416, 953, 50, 953, 25, 420, 727, 953, 29, 430,
131213 /* 1200 */ 321, 424, 757, 428, 322, 124, 1269, 214, 165, 710,
131214 /* 1210 */ 859, 908, 806, 794, 309, 158, 193, 361, 254, 723,
131215 /* 1220 */ 364, 67, 381, 269, 735, 199, 67, 70, 113, 700,
131216 /* 1230 */ 699, 707, 708, 884, 113, 766, 113, 855, 193, 883,
131217 /* 1240 */ 199, 869, 869, 675, 868, 868, 109, 368, 255, 260,
131218 /* 1250 */ 263, 280, 859, 265, 806, 974, 267, 711, 695, 272,
131219 /* 1260 */ 764, 282, 795, 284, 150, 744, 755, 415, 292, 293,
131220 /* 1270 */ 802, 678, 672, 661, 660, 662, 927, 6, 306, 386,
131221 /* 1280 */ 352, 786, 243, 250, 886, 362, 163, 286, 419, 298,
131222 /* 1290 */ 930, 159, 968, 196, 126, 903, 901, 965, 55, 58,
131223 /* 1300 */ 323, 275, 857, 136, 147, 694, 856, 121, 65, 354,
131224 /* 1310 */ 355, 379, 175, 61, 151, 369, 180, 871, 375, 129,
131225 /* 1320 */ 257, 756, 210, 181, 145, 131, 132, 377, 262, 663,
131226 /* 1330 */ 133, 134, 139, 783, 791, 182, 392, 183, 312, 330,
131227 /* 1340 */ 714, 888, 713, 851, 692, 195, 712, 406, 686, 705,
131228 /* 1350 */ 313, 685, 64, 839, 274, 72, 684, 334, 942, 95,
131229 /* 1360 */ 752, 279, 281, 704, 753, 751, 422, 283, 411, 750,
131230 /* 1370 */ 426, 66, 204, 409, 21, 285, 928, 669, 437, 205,
131231 /* 1380 */ 207, 208, 438, 658, 657, 652, 118, 108, 119, 226,
131232 /* 1390 */ 650, 341, 157, 235, 169, 345, 106, 734, 790, 296,
131233 /* 1400 */ 294, 295, 120, 297, 867, 865, 127, 128, 130, 724,
131234 /* 1410 */ 229, 174, 249, 882, 137, 230, 138, 135, 885, 231,
131235 /* 1420 */ 59, 60, 177, 881, 7, 178, 12, 179, 256, 874,
131236 /* 1430 */ 140, 193, 962, 374, 141, 152, 666, 378, 276, 184,
131237 /* 1440 */ 270, 122, 142, 382, 387, 62, 13, 14, 703, 63,
131238 /* 1450 */ 125, 317, 318, 227, 809, 808, 837, 732, 15, 164,
131239 /* 1460 */ 736, 4, 765, 211, 399, 213, 192, 143, 760, 70,
131240 /* 1470 */ 67, 16, 17, 838, 836, 891, 841, 890, 198, 197,
131241 /* 1480 */ 917, 154, 421, 923, 918, 155, 200, 977, 425, 840,
131242 /* 1490 */ 156, 201, 807, 676, 80, 302, 299, 977, 202, 1261,
131243 /* 1500 */ 1260,
131244 };
131245 static const YYCODETYPE yy_lookahead[] = {
131246 /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
131247 /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131248 /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131249 /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
131250 /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
131251 /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 92, 43,
131252 /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131253 /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
131254 /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
131255 /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131256 /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131257 /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
131258 /* 120 */ 249, 22, 172, 172, 173, 52, 53, 27, 28, 29,
131259 /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
131260 /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
131261 /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
131262 /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
131263 /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
131264 /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131265 /* 190 */ 53, 19, 0, 1, 2, 23, 97, 98, 193, 27,
131266 /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131267 /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131268 /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
131269 /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
131270 /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131271 /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131272 /* 260 */ 53, 19, 221, 222, 223, 23, 168, 169, 170, 27,
131273 /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131274 /* 280 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131275 /* 290 */ 48, 49, 50, 51, 52, 53, 19, 157, 22, 23,
131276 /* 300 */ 23, 96, 26, 172, 27, 28, 29, 30, 31, 32,
131277 /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131278 /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131279 /* 330 */ 53, 19, 108, 109, 110, 221, 222, 223, 185, 27,
131280 /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131281 /* 350 */ 38, 39, 40, 41, 240, 43, 44, 45, 46, 47,
131282 /* 360 */ 48, 49, 50, 51, 52, 53, 19, 227, 22, 23,
131283 /* 370 */ 230, 22, 96, 152, 27, 28, 29, 30, 31, 32,
131284 /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 30,
131285 /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131286 /* 400 */ 53, 19, 190, 191, 55, 56, 24, 190, 191, 27,
131287 /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131288 /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131289 /* 430 */ 48, 49, 50, 51, 52, 53, 168, 169, 170, 179,
131290 /* 440 */ 180, 171, 96, 19, 172, 173, 97, 98, 188, 179,
131291 /* 450 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
131292 /* 460 */ 36, 37, 38, 39, 40, 41, 107, 43, 44, 45,
131293 /* 470 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 207,
131294 /* 480 */ 208, 30, 31, 32, 33, 138, 27, 28, 29, 30,
131295 /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131296 /* 500 */ 41, 181, 43, 44, 45, 46, 47, 48, 49, 50,
131297 /* 510 */ 51, 52, 53, 19, 152, 7, 8, 9, 49, 22,
131298 /* 520 */ 19, 24, 28, 29, 30, 31, 32, 33, 34, 35,
131299 /* 530 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
131300 /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 108,
131301 /* 550 */ 109, 110, 101, 55, 53, 193, 172, 173, 29, 30,
131302 /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131303 /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
131304 /* 580 */ 51, 52, 53, 19, 20, 116, 22, 23, 169, 170,
131305 /* 590 */ 121, 207, 85, 55, 56, 97, 19, 20, 195, 22,
131306 /* 600 */ 99, 100, 101, 102, 103, 104, 105, 12, 152, 206,
131307 /* 610 */ 210, 47, 48, 112, 152, 108, 109, 110, 54, 55,
131308 /* 620 */ 56, 221, 222, 223, 47, 48, 119, 120, 172, 173,
131309 /* 630 */ 66, 54, 55, 56, 101, 97, 98, 99, 148, 149,
131310 /* 640 */ 102, 103, 104, 66, 154, 112, 156, 83, 229, 47,
131311 /* 650 */ 48, 113, 57, 163, 194, 195, 92, 246, 247, 95,
131312 /* 660 */ 83, 97, 98, 207, 208, 101, 206, 59, 73, 92,
131313 /* 670 */ 75, 63, 95, 163, 97, 98, 194, 195, 101, 219,
131314 /* 680 */ 85, 181, 19, 152, 175, 77, 196, 152, 206, 19,
131315 /* 690 */ 20, 199, 22, 30, 163, 11, 132, 133, 134, 135,
131316 /* 700 */ 136, 209, 152, 172, 173, 152, 196, 172, 173, 132,
131317 /* 710 */ 133, 134, 135, 136, 164, 92, 213, 47, 48, 49,
131318 /* 720 */ 92, 186, 169, 170, 54, 55, 56, 196, 100, 219,
131319 /* 730 */ 221, 222, 223, 243, 132, 133, 66, 175, 207, 208,
131320 /* 740 */ 152, 231, 119, 120, 19, 20, 236, 22, 152, 38,
131321 /* 750 */ 39, 40, 41, 83, 43, 44, 45, 46, 47, 48,
131322 /* 760 */ 49, 50, 51, 52, 53, 95, 152, 97, 98, 85,
131323 /* 770 */ 107, 101, 47, 48, 163, 112, 92, 152, 152, 54,
131324 /* 780 */ 55, 56, 229, 221, 222, 223, 172, 173, 163, 49,
131325 /* 790 */ 152, 66, 108, 109, 110, 55, 56, 172, 173, 163,
131326 /* 800 */ 186, 22, 132, 133, 134, 135, 136, 196, 83, 43,
131327 /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131328 /* 820 */ 95, 196, 97, 98, 85, 99, 101, 152, 102, 103,
131329 /* 830 */ 104, 92, 196, 146, 147, 152, 181, 97, 98, 113,
131330 /* 840 */ 19, 20, 152, 22, 218, 22, 116, 108, 109, 110,
131331 /* 850 */ 152, 121, 55, 56, 12, 219, 218, 132, 133, 134,
131332 /* 860 */ 135, 136, 172, 173, 55, 56, 55, 56, 47, 48,
131333 /* 870 */ 172, 173, 236, 152, 5, 54, 55, 56, 55, 10,
131334 /* 880 */ 11, 12, 13, 14, 186, 152, 17, 66, 47, 48,
131335 /* 890 */ 152, 210, 16, 84, 97, 98, 55, 56, 21, 57,
131336 /* 900 */ 217, 122, 22, 152, 83, 152, 97, 98, 97, 98,
131337 /* 910 */ 172, 173, 152, 152, 224, 73, 95, 75, 97, 98,
131338 /* 920 */ 97, 124, 101, 172, 173, 164, 193, 47, 48, 60,
131339 /* 930 */ 163, 62, 172, 173, 24, 55, 56, 186, 97, 98,
131340 /* 940 */ 71, 100, 55, 56, 183, 207, 185, 152, 107, 23,
131341 /* 950 */ 109, 82, 26, 132, 133, 134, 135, 136, 89, 152,
131342 /* 960 */ 26, 92, 93, 196, 88, 55, 90, 152, 91, 152,
131343 /* 970 */ 217, 152, 152, 132, 133, 95, 152, 97, 211, 212,
131344 /* 980 */ 103, 101, 152, 114, 97, 98, 152, 172, 173, 19,
131345 /* 990 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
131346 /* 1000 */ 48, 49, 50, 51, 52, 53, 65, 97, 152, 152,
131347 /* 1010 */ 141, 124, 132, 133, 134, 152, 140, 140, 152, 78,
131348 /* 1020 */ 152, 233, 152, 193, 98, 152, 56, 86, 172, 173,
131349 /* 1030 */ 166, 167, 237, 152, 217, 172, 173, 152, 172, 173,
131350 /* 1040 */ 172, 173, 172, 173, 237, 172, 173, 152, 152, 152,
131351 /* 1050 */ 124, 152, 111, 172, 173, 152, 237, 172, 173, 152,
131352 /* 1060 */ 55, 152, 26, 152, 130, 152, 152, 172, 173, 172,
131353 /* 1070 */ 173, 172, 173, 249, 152, 172, 173, 152, 61, 172,
131354 /* 1080 */ 173, 172, 173, 172, 173, 172, 173, 70, 152, 193,
131355 /* 1090 */ 152, 137, 152, 139, 172, 173, 152, 172, 173, 152,
131356 /* 1100 */ 152, 152, 97, 152, 26, 152, 163, 152, 172, 173,
131357 /* 1110 */ 172, 173, 172, 173, 152, 16, 172, 173, 26, 172,
131358 /* 1120 */ 173, 172, 173, 172, 173, 172, 173, 172, 173, 163,
131359 /* 1130 */ 152, 152, 152, 22, 172, 173, 152, 241, 152, 196,
131360 /* 1140 */ 152, 193, 106, 152, 152, 152, 163, 152, 37, 152,
131361 /* 1150 */ 172, 173, 172, 173, 152, 152, 172, 173, 172, 173,
131362 /* 1160 */ 172, 173, 196, 172, 173, 172, 173, 172, 173, 172,
131363 /* 1170 */ 173, 152, 152, 152, 172, 173, 98, 152, 152, 196,
131364 /* 1180 */ 160, 22, 23, 19, 164, 193, 152, 88, 232, 90,
131365 /* 1190 */ 191, 172, 173, 172, 173, 163, 193, 172, 173, 166,
131366 /* 1200 */ 167, 163, 124, 163, 244, 245, 23, 211, 212, 26,
131367 /* 1210 */ 55, 23, 55, 23, 26, 123, 26, 152, 23, 193,
131368 /* 1220 */ 56, 26, 23, 23, 23, 26, 26, 26, 196, 100,
131369 /* 1230 */ 101, 7, 8, 152, 196, 23, 196, 23, 26, 152,
131370 /* 1240 */ 26, 132, 133, 23, 132, 133, 26, 152, 152, 152,
131371 /* 1250 */ 152, 210, 97, 152, 97, 96, 152, 152, 152, 152,
131372 /* 1260 */ 152, 210, 152, 210, 197, 152, 152, 152, 152, 152,
131373 /* 1270 */ 152, 152, 152, 152, 152, 152, 152, 198, 150, 176,
131374 /* 1280 */ 214, 201, 214, 238, 201, 238, 184, 214, 226, 200,
131375 /* 1290 */ 155, 198, 67, 122, 242, 159, 159, 69, 239, 239,
131376 /* 1300 */ 159, 175, 175, 22, 220, 180, 175, 27, 130, 18,
131377 /* 1310 */ 159, 18, 158, 137, 220, 159, 158, 235, 74, 189,
131378 /* 1320 */ 234, 159, 159, 158, 22, 192, 192, 177, 159, 159,
131379 /* 1330 */ 192, 192, 189, 201, 189, 158, 107, 158, 177, 76,
131380 /* 1340 */ 174, 201, 174, 201, 106, 159, 174, 125, 174, 182,
131381 /* 1350 */ 177, 176, 107, 159, 174, 137, 174, 53, 174, 129,
131382 /* 1360 */ 216, 215, 215, 182, 216, 216, 177, 215, 126, 216,
131383 /* 1370 */ 177, 128, 25, 127, 26, 215, 13, 162, 161, 153,
131384 /* 1380 */ 153, 6, 151, 151, 151, 151, 165, 178, 165, 178,
131385 /* 1390 */ 4, 3, 22, 142, 15, 94, 16, 205, 120, 202,
131386 /* 1400 */ 204, 203, 165, 201, 23, 23, 131, 111, 123, 20,
131387 /* 1410 */ 225, 125, 16, 1, 131, 228, 111, 123, 56, 228,
131388 /* 1420 */ 37, 37, 64, 1, 5, 122, 22, 107, 140, 80,
131389 /* 1430 */ 80, 26, 87, 72, 107, 24, 20, 19, 112, 105,
131390 /* 1440 */ 23, 68, 22, 79, 79, 22, 22, 22, 58, 22,
131391 /* 1450 */ 245, 248, 248, 79, 23, 23, 23, 116, 22, 122,
131392 /* 1460 */ 23, 22, 56, 23, 26, 23, 64, 22, 124, 26,
131393 /* 1470 */ 26, 64, 64, 23, 23, 23, 11, 23, 22, 26,
131394 /* 1480 */ 23, 22, 24, 1, 23, 22, 26, 250, 24, 23,
131395 /* 1490 */ 22, 122, 23, 23, 22, 15, 23, 250, 122, 122,
131396 /* 1500 */ 122,
131397 };
131398 #define YY_SHIFT_USE_DFLT (-95)
131399 #define YY_SHIFT_COUNT (439)
131400 #define YY_SHIFT_MIN (-94)
131401 #define YY_SHIFT_MAX (1482)
131402 static const short yy_shift_ofst[] = {
131403 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 739, -19, 16,
131404 /* 10 */ 16, 100, 725, 725, 725, 725, 725, 725, 725, 841,
131405 /* 20 */ 841, 538, 507, 684, 623, 61, 137, 172, 207, 242,
131406 /* 30 */ 277, 312, 347, 382, 424, 424, 424, 424, 424, 424,
131407 /* 40 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 459,
131408 /* 50 */ 424, 494, 529, 529, 670, 725, 725, 725, 725, 725,
131409 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131410 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131411 /* 80 */ 725, 725, 725, 821, 725, 725, 725, 725, 725, 725,
131412 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 952, 711, 711,
131413 /* 100 */ 711, 711, 711, 766, 23, 32, 811, 877, 663, 602,
131414 /* 110 */ 602, 811, 73, 113, -51, -95, -95, -95, 501, 501,
131415 /* 120 */ 501, 595, 595, 809, 205, 276, 811, 811, 811, 811,
131416 /* 130 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131417 /* 140 */ 811, 811, 811, 811, 811, 811, 192, 628, 498, 498,
131418 /* 150 */ 113, -34, -34, -34, -34, -34, -34, -95, -95, -95,
131419 /* 160 */ 880, -94, -94, 726, 740, 99, 797, 887, 349, 811,
131420 /* 170 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131421 /* 180 */ 811, 811, 811, 811, 811, 811, 941, 941, 941, 811,
131422 /* 190 */ 811, 926, 811, 811, 811, -18, 811, 811, 842, 811,
131423 /* 200 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 224,
131424 /* 210 */ 608, 910, 910, 910, 1078, 45, 469, 508, 934, 970,
131425 /* 220 */ 970, 1164, 934, 1164, 1036, 1183, 359, 1017, 970, 954,
131426 /* 230 */ 1017, 1017, 1092, 730, 497, 1225, 1171, 1171, 1228, 1228,
131427 /* 240 */ 1171, 1281, 1280, 1178, 1291, 1291, 1291, 1291, 1171, 1293,
131428 /* 250 */ 1178, 1281, 1280, 1280, 1178, 1171, 1293, 1176, 1244, 1171,
131429 /* 260 */ 1171, 1293, 1302, 1171, 1293, 1171, 1293, 1302, 1229, 1229,
131430 /* 270 */ 1229, 1263, 1302, 1229, 1238, 1229, 1263, 1229, 1229, 1222,
131431 /* 280 */ 1245, 1222, 1245, 1222, 1245, 1222, 1245, 1171, 1171, 1218,
131432 /* 290 */ 1302, 1304, 1304, 1302, 1230, 1242, 1243, 1246, 1178, 1347,
131433 /* 300 */ 1348, 1363, 1363, 1375, 1375, 1375, 1375, -95, -95, -95,
131434 /* 310 */ -95, -95, -95, -95, -95, 451, 876, 346, 1159, 1099,
131435 /* 320 */ 441, 823, 1188, 1111, 1190, 1195, 1199, 1200, 1005, 1129,
131436 /* 330 */ 1224, 533, 1201, 1212, 1155, 1214, 1109, 1112, 1220, 1157,
131437 /* 340 */ 779, 1386, 1388, 1370, 1251, 1379, 1301, 1380, 1381, 1382,
131438 /* 350 */ 1278, 1275, 1296, 1285, 1389, 1286, 1396, 1412, 1294, 1283,
131439 /* 360 */ 1383, 1384, 1305, 1362, 1358, 1303, 1422, 1419, 1404, 1320,
131440 /* 370 */ 1288, 1349, 1405, 1350, 1345, 1361, 1327, 1411, 1416, 1418,
131441 /* 380 */ 1326, 1334, 1420, 1364, 1423, 1424, 1417, 1425, 1365, 1390,
131442 /* 390 */ 1427, 1374, 1373, 1431, 1432, 1433, 1341, 1436, 1437, 1439,
131443 /* 400 */ 1438, 1337, 1440, 1442, 1406, 1402, 1445, 1344, 1443, 1407,
131444 /* 410 */ 1444, 1408, 1443, 1450, 1451, 1452, 1453, 1454, 1456, 1465,
131445 /* 420 */ 1457, 1459, 1458, 1460, 1461, 1463, 1464, 1460, 1466, 1468,
131446 /* 430 */ 1469, 1470, 1472, 1369, 1376, 1377, 1378, 1473, 1480, 1482,
131447 };
131448 #define YY_REDUCE_USE_DFLT (-130)
131449 #define YY_REDUCE_COUNT (314)
131450 #define YY_REDUCE_MIN (-129)
131451 #define YY_REDUCE_MAX (1237)
131452 static const short yy_reduce_ofst[] = {
131453 /* 0 */ -29, 531, 490, 625, -49, 272, 456, 510, 400, 509,
131454 /* 10 */ 562, 114, 535, 614, 698, 384, 738, 751, 690, 419,
131455 /* 20 */ 553, 761, 460, 636, 767, 41, 41, 41, 41, 41,
131456 /* 30 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131457 /* 40 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131458 /* 50 */ 41, 41, 41, 41, 760, 815, 856, 863, 866, 868,
131459 /* 60 */ 870, 873, 881, 885, 895, 897, 899, 903, 907, 909,
131460 /* 70 */ 911, 913, 922, 925, 936, 938, 940, 944, 947, 949,
131461 /* 80 */ 951, 953, 955, 962, 978, 980, 984, 986, 988, 991,
131462 /* 90 */ 993, 995, 997, 1002, 1019, 1021, 1025, 41, 41, 41,
131463 /* 100 */ 41, 41, 41, 41, 41, 41, 896, 140, 260, 98,
131464 /* 110 */ 268, 1020, 41, 482, 41, 41, 41, 41, 270, 270,
131465 /* 120 */ 270, 212, 217, -129, 411, 411, 550, 5, 626, 362,
131466 /* 130 */ 733, 830, 992, 1003, 1026, 795, 683, 807, 638, 819,
131467 /* 140 */ 753, 948, 62, 817, 824, 132, 687, 611, 864, 1033,
131468 /* 150 */ 403, 943, 966, 983, 1032, 1038, 1040, 960, 996, 492,
131469 /* 160 */ -50, 57, 131, 153, 221, 462, 588, 596, 675, 721,
131470 /* 170 */ 820, 834, 857, 914, 979, 1034, 1065, 1081, 1087, 1095,
131471 /* 180 */ 1096, 1097, 1098, 1101, 1104, 1105, 320, 500, 655, 1106,
131472 /* 190 */ 1107, 503, 1108, 1110, 1113, 681, 1114, 1115, 999, 1116,
131473 /* 200 */ 1117, 1118, 221, 1119, 1120, 1121, 1122, 1123, 1124, 788,
131474 /* 210 */ 956, 1041, 1051, 1053, 503, 1067, 1079, 1128, 1080, 1066,
131475 /* 220 */ 1068, 1045, 1083, 1047, 1103, 1102, 1125, 1126, 1073, 1062,
131476 /* 230 */ 1127, 1131, 1089, 1093, 1135, 1052, 1136, 1137, 1059, 1060,
131477 /* 240 */ 1141, 1084, 1130, 1132, 1133, 1134, 1138, 1139, 1151, 1154,
131478 /* 250 */ 1140, 1094, 1143, 1145, 1142, 1156, 1158, 1082, 1086, 1162,
131479 /* 260 */ 1163, 1165, 1150, 1169, 1177, 1170, 1179, 1161, 1166, 1168,
131480 /* 270 */ 1172, 1167, 1173, 1174, 1175, 1180, 1181, 1182, 1184, 1144,
131481 /* 280 */ 1146, 1148, 1147, 1149, 1152, 1153, 1160, 1186, 1194, 1185,
131482 /* 290 */ 1189, 1187, 1191, 1193, 1192, 1196, 1198, 1197, 1202, 1215,
131483 /* 300 */ 1217, 1226, 1227, 1231, 1232, 1233, 1234, 1203, 1204, 1205,
131484 /* 310 */ 1221, 1223, 1209, 1211, 1237,
131485 };
131486 static const YYACTIONTYPE yy_default[] = {
131487 /* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
131488 /* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
131489 /* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131547,104 @@
131547 */
131548 #ifdef YYFALLBACK
131549 static const YYCODETYPE yyFallback[] = {
131550 0, /* $ => nothing */
131551 0, /* SEMI => nothing */
131552 55, /* EXPLAIN => ID */
131553 55, /* QUERY => ID */
131554 55, /* PLAN => ID */
131555 55, /* BEGIN => ID */
131556 0, /* TRANSACTION => nothing */
131557 55, /* DEFERRED => ID */
131558 55, /* IMMEDIATE => ID */
131559 55, /* EXCLUSIVE => ID */
131560 0, /* COMMIT => nothing */
131561 55, /* END => ID */
131562 55, /* ROLLBACK => ID */
131563 55, /* SAVEPOINT => ID */
131564 55, /* RELEASE => ID */
131565 0, /* TO => nothing */
131566 0, /* TABLE => nothing */
131567 0, /* CREATE => nothing */
131568 55, /* IF => ID */
131569 0, /* NOT => nothing */
131570 0, /* EXISTS => nothing */
131571 55, /* TEMP => ID */
131572 0, /* LP => nothing */
131573 0, /* RP => nothing */
131574 0, /* AS => nothing */
131575 55, /* WITHOUT => ID */
131576 0, /* COMMA => nothing */
131577 0, /* OR => nothing */
131578 0, /* AND => nothing */
131579 0, /* IS => nothing */
131580 55, /* MATCH => ID */
131581 55, /* LIKE_KW => ID */
131582 0, /* BETWEEN => nothing */
131583 0, /* IN => nothing */
131584 0, /* ISNULL => nothing */
131585 0, /* NOTNULL => nothing */
131586 0, /* NE => nothing */
131587 0, /* EQ => nothing */
131588 0, /* GT => nothing */
131589 0, /* LE => nothing */
131590 0, /* LT => nothing */
131591 0, /* GE => nothing */
131592 0, /* ESCAPE => nothing */
131593 0, /* BITAND => nothing */
131594 0, /* BITOR => nothing */
131595 0, /* LSHIFT => nothing */
131596 0, /* RSHIFT => nothing */
131597 0, /* PLUS => nothing */
131598 0, /* MINUS => nothing */
131599 0, /* STAR => nothing */
131600 0, /* SLASH => nothing */
131601 0, /* REM => nothing */
131602 0, /* CONCAT => nothing */
131603 0, /* COLLATE => nothing */
131604 0, /* BITNOT => nothing */
131605 0, /* ID => nothing */
131606 0, /* INDEXED => nothing */
131607 55, /* ABORT => ID */
131608 55, /* ACTION => ID */
131609 55, /* AFTER => ID */
131610 55, /* ANALYZE => ID */
131611 55, /* ASC => ID */
131612 55, /* ATTACH => ID */
131613 55, /* BEFORE => ID */
131614 55, /* BY => ID */
131615 55, /* CASCADE => ID */
131616 55, /* CAST => ID */
131617 55, /* COLUMNKW => ID */
131618 55, /* CONFLICT => ID */
131619 55, /* DATABASE => ID */
131620 55, /* DESC => ID */
131621 55, /* DETACH => ID */
131622 55, /* EACH => ID */
131623 55, /* FAIL => ID */
131624 55, /* FOR => ID */
131625 55, /* IGNORE => ID */
131626 55, /* INITIALLY => ID */
131627 55, /* INSTEAD => ID */
131628 55, /* NO => ID */
131629 55, /* KEY => ID */
131630 55, /* OF => ID */
131631 55, /* OFFSET => ID */
131632 55, /* PRAGMA => ID */
131633 55, /* RAISE => ID */
131634 55, /* RECURSIVE => ID */
131635 55, /* REPLACE => ID */
131636 55, /* RESTRICT => ID */
131637 55, /* ROW => ID */
131638 55, /* TRIGGER => ID */
131639 55, /* VACUUM => ID */
131640 55, /* VIEW => ID */
131641 55, /* VIRTUAL => ID */
131642 55, /* WITH => ID */
131643 55, /* REINDEX => ID */
131644 55, /* RENAME => ID */
131645 55, /* CTIME_KW => ID */
 
 
131646 };
131647 #endif /* YYFALLBACK */
131648
131649 /* The following structure represents a single element of the
131650 ** parser's stack. Information stored includes:
@@ -131207,29 +131731,29 @@
131731 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131732 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131733 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131734 "TABLE", "CREATE", "IF", "NOT",
131735 "EXISTS", "TEMP", "LP", "RP",
131736 "AS", "WITHOUT", "COMMA", "OR",
131737 "AND", "IS", "MATCH", "LIKE_KW",
131738 "BETWEEN", "IN", "ISNULL", "NOTNULL",
131739 "NE", "EQ", "GT", "LE",
131740 "LT", "GE", "ESCAPE", "BITAND",
131741 "BITOR", "LSHIFT", "RSHIFT", "PLUS",
131742 "MINUS", "STAR", "SLASH", "REM",
131743 "CONCAT", "COLLATE", "BITNOT", "ID",
131744 "INDEXED", "ABORT", "ACTION", "AFTER",
131745 "ANALYZE", "ASC", "ATTACH", "BEFORE",
131746 "BY", "CASCADE", "CAST", "COLUMNKW",
131747 "CONFLICT", "DATABASE", "DESC", "DETACH",
131748 "EACH", "FAIL", "FOR", "IGNORE",
131749 "INITIALLY", "INSTEAD", "NO", "KEY",
131750 "OF", "OFFSET", "PRAGMA", "RAISE",
131751 "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
131752 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
131753 "WITH", "REINDEX", "RENAME", "CTIME_KW",
131754 "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
 
 
 
 
 
 
 
131755 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131756 "CHECK", "REFERENCES", "AUTOINCR", "ON",
131757 "INSERT", "DELETE", "UPDATE", "SET",
131758 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
131759 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133529,27 @@
133529 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133530 }
133531 break;
133532 case 156: /* expr ::= VARIABLE */
133533 {
133534 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
133535 spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
133536 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133537 }else{
133538 /* When doing a nested parse, one can include terms in an expression
133539 ** that look like this: #1 #2 ... These terms refer to registers
133540 ** in the virtual machine. #N is the N-th register. */
133541 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133542 assert( t.n>=2 );
133543 spanSet(&yymsp[0].minor.yy342, &t, &t);
133544 if( pParse->nested==0 ){
133545 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133546 yymsp[0].minor.yy342.pExpr = 0;
133547 }else{
133548 yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133549 if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133550 }
 
 
 
133551 }
133552 }
133553 break;
133554 case 157: /* expr ::= expr COLLATE ID|STRING */
133555 {
@@ -133205,60 +133730,37 @@
133730 break;
133731 case 188: /* expr ::= LP select RP */
133732 {
133733 spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133734 yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133735 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy342.pExpr, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133736 }
133737 break;
133738 case 189: /* expr ::= expr in_op LP select RP */
133739 {
133740 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133741 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy342.pExpr, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133742 exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133743 yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133744 }
133745 break;
133746 case 190: /* expr ::= expr in_op nm dbnm */
133747 {
133748 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
133749 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133750 yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133751 sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy342.pExpr, pSelect);
 
 
 
 
 
 
133752 exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133753 yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133754 }
133755 break;
133756 case 191: /* expr ::= EXISTS LP select RP */
133757 {
133758 Expr *p;
133759 spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133760 p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133761 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133762 }
133763 break;
133764 case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133765 {
133766 spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135241,11 @@
135241 ** will take responsibility for freeing the Table structure.
135242 */
135243 sqlite3DeleteTable(db, pParse->pNewTable);
135244 }
135245
135246 if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
135247 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
135248 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
135249 sqlite3DbFree(db, pParse->azVar);
135250 while( pParse->pAinc ){
135251 AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136451,11 @@
136451 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
136452 } aFlagOp[] = {
136453 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
136454 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
136455 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
136456 { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
136457 };
136458 unsigned int i;
136459 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
136460 for(i=0; i<ArraySize(aFlagOp); i++){
136461 if( aFlagOp[i].op==op ){
@@ -162447,19 +162950,21 @@
162950 ** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162951 **
162952 ** http://www.icu-project.org/userguide/posix.html#case_mappings
162953 */
162954 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162955 const UChar *zInput; /* Pointer to input string */
162956 UChar *zOutput = 0; /* Pointer to output buffer */
162957 int nInput; /* Size of utf-16 input string in bytes */
162958 int nOut; /* Size of output buffer in bytes */
162959 int cnt;
162960 int bToUpper; /* True for toupper(), false for tolower() */
162961 UErrorCode status;
162962 const char *zLocale = 0;
162963
162964 assert(nArg==1 || nArg==2);
162965 bToUpper = (sqlite3_user_data(p)!=0);
162966 if( nArg==2 ){
162967 zLocale = (const char *)sqlite3_value_text(apArg[1]);
162968 }
162969
162970 zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162984,27 @@
162984 sqlite3_result_error_nomem(p);
162985 return;
162986 }
162987 zOutput = zNew;
162988 status = U_ZERO_ERROR;
162989 if( bToUpper ){
162990 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162991 }else{
162992 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162993 }
162994
162995 if( U_SUCCESS(status) ){
162996 sqlite3_result_text16(p, zOutput, nOut, xFree);
162997 }else if( status==U_BUFFER_OVERFLOW_ERROR ){
162998 assert( cnt==0 );
162999 continue;
163000 }else{
163001 icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status);
163002 }
163003 return;
163004 }
163005 assert( 0 ); /* Unreachable */
163006 }
163007
163008 /*
163009 ** Collation sequence destructor function. The pCtx argument points to
163010 ** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163817,42 @@
163817 const char *zTarget,
163818 const char *zRbu,
163819 const char *zState
163820 );
163821
163822 /*
163823 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
163824 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
163825 ** that it can be suspended and resumed like an RBU update.
163826 **
163827 ** The second argument to this function, which may not be NULL, identifies
163828 ** a database in which to store the state of the RBU vacuum operation if
163829 ** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
163830 ** an RBU vacuum operation, the state database should either not exist or
163831 ** be empty (contain no tables). If an RBU vacuum is suspended by calling
163832 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
163833 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
163834 ** The vacuum can be resumed by calling this function to open a new RBU
163835 ** handle specifying the same target and state databases.
163836 **
163837 ** This function does not delete the state database after an RBU vacuum
163838 ** is completed, even if it created it. However, if the call to
163839 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
163840 ** of the state tables within the state database are zeroed. This way,
163841 ** the next call to sqlite3rbu_vacuum() opens a handle that starts a
163842 ** new RBU vacuum operation.
163843 **
163844 ** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
163845 ** describing the sqlite3rbu_create_vfs() API function below for
163846 ** a description of the complications associated with using RBU with
163847 ** zipvfs databases.
163848 */
163849 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
163850 const char *zTarget,
163851 const char *zState
163852 );
163853
163854 /*
163855 ** Internally, each RBU connection uses a separate SQLite database
163856 ** connection to access the target and rbu update databases. This
163857 ** API allows the application direct access to these database handles.
163858 **
@@ -163586,10 +164127,11 @@
164127 typedef struct rbu_file rbu_file;
164128 typedef struct RbuUpdateStmt RbuUpdateStmt;
164129
164130 #if !defined(SQLITE_AMALGAMATION)
164131 typedef unsigned int u32;
164132 typedef unsigned short u16;
164133 typedef unsigned char u8;
164134 typedef sqlite3_int64 i64;
164135 #endif
164136
164137 /*
@@ -163598,10 +164140,12 @@
164140 ** format.
164141 */
164142 #define WAL_LOCK_WRITE 0
164143 #define WAL_LOCK_CKPT 1
164144 #define WAL_LOCK_READ0 3
164145
164146 #define SQLITE_FCNTL_RBUCNT 5149216
164147
164148 /*
164149 ** A structure to store values read from the rbu_state table in memory.
164150 */
164151 struct RbuState {
@@ -163777,10 +164321,14 @@
164321 int nFrameAlloc; /* Allocated size of aFrame[] array */
164322 RbuFrame *aFrame;
164323 int pgsz;
164324 u8 *aBuf;
164325 i64 iWalCksum;
164326
164327 /* Used in RBU vacuum mode only */
164328 int nRbu; /* Number of RBU VFS in the stack */
164329 rbu_file *pRbuFd; /* Fd for main db of dbRbu */
164330 };
164331
164332 /*
164333 ** An rbu VFS is implemented using an instance of this structure.
164334 */
@@ -163802,10 +164350,11 @@
164350 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
164351
164352 int openFlags; /* Flags this file was opened with */
164353 u32 iCookie; /* Cookie value for main db files */
164354 u8 iWriteVer; /* "write-version" value for main db files */
164355 u8 bNolock; /* True to fail EXCLUSIVE locks */
164356
164357 int nShm; /* Number of entries in apShm[] array */
164358 char **apShm; /* Array of mmap'd *-shm regions */
164359 char *zDel; /* Delete this when closing file */
164360
@@ -163812,10 +164361,15 @@
164361 const char *zWal; /* Wal filename for this main db file */
164362 rbu_file *pWalFd; /* Wal file descriptor for this main db */
164363 rbu_file *pMainNext; /* Next MAIN_DB file */
164364 };
164365
164366 /*
164367 ** True for an RBU vacuum handle, or false otherwise.
164368 */
164369 #define rbuIsVacuum(p) ((p)->zTarget==0)
164370
164371
164372 /*************************************************************************
164373 ** The following three functions, found below:
164374 **
164375 ** rbuDeltaGetInt()
@@ -164260,12 +164814,15 @@
164814 }
164815
164816
164817 /*
164818 ** The implementation of the rbu_target_name() SQL function. This function
164819 ** accepts one or two arguments. The first argument is the name of a table -
164820 ** the name of a table in the RBU database. The second, if it is present, is 1
164821 ** for a view or 0 for a table.
164822 **
164823 ** For a non-vacuum RBU handle, if the table name matches the pattern:
164824 **
164825 ** data[0-9]_<name>
164826 **
164827 ** where <name> is any sequence of 1 or more characters, <name> is returned.
164828 ** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164829,37 @@
164829 ** NULL is returned.
164830 **
164831 ** "data_t1" -> "t1"
164832 ** "data0123_t2" -> "t2"
164833 ** "dataAB_t3" -> NULL
164834 **
164835 ** For an rbu vacuum handle, a copy of the first argument is returned if
164836 ** the second argument is either missing or 0 (not a view).
164837 */
164838 static void rbuTargetNameFunc(
164839 sqlite3_context *pCtx,
164840 int argc,
164841 sqlite3_value **argv
164842 ){
164843 sqlite3rbu *p = sqlite3_user_data(pCtx);
164844 const char *zIn;
164845 assert( argc==1 || argc==2 );
164846
164847 zIn = (const char*)sqlite3_value_text(argv[0]);
164848 if( zIn ){
164849 if( rbuIsVacuum(p) ){
164850 if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
164851 sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC);
164852 }
164853 }else{
164854 if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164855 int i;
164856 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164857 if( zIn[i]=='_' && zIn[i+1] ){
164858 sqlite3_result_text(pCtx, &zIn[i+1], -1, SQLITE_STATIC);
164859 }
164860 }
164861 }
164862 }
164863 }
164864
164865 /*
@@ -164304,11 +164873,12 @@
164873 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164874 int rc;
164875 memset(pIter, 0, sizeof(RbuObjIter));
164876
164877 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164878 "SELECT rbu_target_name(name, type='view') AS target, name "
164879 "FROM sqlite_master "
164880 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
164881 "ORDER BY name"
164882 );
164883
164884 if( rc==SQLITE_OK ){
@@ -164680,10 +165250,11 @@
165250 }
165251 sqlite3_finalize(pStmt);
165252 pStmt = 0;
165253
165254 if( p->rc==SQLITE_OK
165255 && rbuIsVacuum(p)==0
165256 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
165257 ){
165258 p->rc = SQLITE_ERROR;
165259 p->zErrmsg = sqlite3_mprintf(
165260 "table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165390,12 @@
165390 if( pIter->eType==RBU_PK_IPK ){
165391 int i;
165392 for(i=0; pIter->abTblPk[i]==0; i++);
165393 assert( i<pIter->nTblCol );
165394 zCol = pIter->azTblCol[i];
165395 }else if( rbuIsVacuum(p) ){
165396 zCol = "_rowid_";
165397 }else{
165398 zCol = "rbu_rowid";
165399 }
165400 zType = "INTEGER";
165401 }else{
@@ -165359,20 +165932,29 @@
165932 sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165933 );
165934 }
165935
165936 /* And to delete index entries */
165937 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165938 p->rc = prepareFreeAndCollectError(
165939 p->dbMain, &pIter->pDelete, &p->zErrmsg,
165940 sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165941 );
165942 }
165943
165944 /* Create the SELECT statement to read keys in sorted order */
165945 if( p->rc==SQLITE_OK ){
165946 char *zSql;
165947 if( rbuIsVacuum(p) ){
165948 zSql = sqlite3_mprintf(
165949 "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
165950 zCollist,
165951 pIter->zDataTbl,
165952 zCollist, zLimit
165953 );
165954 }else
165955
165956 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165957 zSql = sqlite3_mprintf(
165958 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165959 zCollist, p->zStateDb, pIter->zDataTbl,
165960 zCollist, zLimit
@@ -165395,11 +165977,13 @@
165977 sqlite3_free(zImposterCols);
165978 sqlite3_free(zImposterPK);
165979 sqlite3_free(zWhere);
165980 sqlite3_free(zBind);
165981 }else{
165982 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
165983 ||(pIter->eType==RBU_PK_NONE)
165984 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
165985 const char *zTbl = pIter->zTbl; /* Table this step applies to */
165986 const char *zWrite; /* Imposter table name */
165987
165988 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165989 char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +166006,22 @@
166006 zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
166007 )
166008 );
166009 }
166010
166011 /* Create the DELETE statement to write to the target PK b-tree.
166012 ** Because it only performs INSERT operations, this is not required for
166013 ** an rbu vacuum handle. */
166014 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
166015 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
166016 sqlite3_mprintf(
166017 "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
166018 )
166019 );
166020 }
166021
166022 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
166023 const char *zRbuRowid = "";
166024 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
166025 zRbuRowid = ", rbu_rowid";
166026 }
166027
@@ -165481,14 +166067,20 @@
166067 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
166068 }
166069
166070 /* Create the SELECT statement to read keys from data_xxx */
166071 if( p->rc==SQLITE_OK ){
166072 const char *zRbuRowid = "";
166073 if( bRbuRowid ){
166074 zRbuRowid = rbuIsVacuum(p) ? ",_rowid_ " : ",rbu_rowid";
166075 }
166076 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
166077 sqlite3_mprintf(
166078 "SELECT %s,%s rbu_control%s FROM '%q'%s",
166079 zCollist,
166080 (rbuIsVacuum(p) ? "0 AS " : ""),
166081 zRbuRowid,
166082 pIter->zDataTbl, zLimit
166083 )
166084 );
166085 }
166086
@@ -165579,44 +166171,231 @@
166171 }
166172
166173 return p->rc;
166174 }
166175
166176 static sqlite3 *rbuOpenDbhandle(
166177 sqlite3rbu *p,
166178 const char *zName,
166179 int bUseVfs
166180 ){
166181 sqlite3 *db = 0;
166182 if( p->rc==SQLITE_OK ){
166183 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
166184 p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
166185 if( p->rc ){
166186 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
166187 sqlite3_close(db);
166188 db = 0;
166189 }
166190 }
166191 return db;
166192 }
166193
166194 /*
166195 ** Free an RbuState object allocated by rbuLoadState().
166196 */
166197 static void rbuFreeState(RbuState *p){
166198 if( p ){
166199 sqlite3_free(p->zTbl);
166200 sqlite3_free(p->zIdx);
166201 sqlite3_free(p);
166202 }
166203 }
166204
166205 /*
166206 ** Allocate an RbuState object and load the contents of the rbu_state
166207 ** table into it. Return a pointer to the new object. It is the
166208 ** responsibility of the caller to eventually free the object using
166209 ** sqlite3_free().
166210 **
166211 ** If an error occurs, leave an error code and message in the rbu handle
166212 ** and return NULL.
166213 */
166214 static RbuState *rbuLoadState(sqlite3rbu *p){
166215 RbuState *pRet = 0;
166216 sqlite3_stmt *pStmt = 0;
166217 int rc;
166218 int rc2;
166219
166220 pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166221 if( pRet==0 ) return 0;
166222
166223 rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166224 sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166225 );
166226 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166227 switch( sqlite3_column_int(pStmt, 0) ){
166228 case RBU_STATE_STAGE:
166229 pRet->eStage = sqlite3_column_int(pStmt, 1);
166230 if( pRet->eStage!=RBU_STAGE_OAL
166231 && pRet->eStage!=RBU_STAGE_MOVE
166232 && pRet->eStage!=RBU_STAGE_CKPT
166233 ){
166234 p->rc = SQLITE_CORRUPT;
166235 }
166236 break;
166237
166238 case RBU_STATE_TBL:
166239 pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166240 break;
166241
166242 case RBU_STATE_IDX:
166243 pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166244 break;
166245
166246 case RBU_STATE_ROW:
166247 pRet->nRow = sqlite3_column_int(pStmt, 1);
166248 break;
166249
166250 case RBU_STATE_PROGRESS:
166251 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166252 break;
166253
166254 case RBU_STATE_CKPT:
166255 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166256 break;
166257
166258 case RBU_STATE_COOKIE:
166259 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166260 break;
166261
166262 case RBU_STATE_OALSZ:
166263 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166264 break;
166265
166266 case RBU_STATE_PHASEONESTEP:
166267 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166268 break;
166269
166270 default:
166271 rc = SQLITE_CORRUPT;
166272 break;
166273 }
166274 }
166275 rc2 = sqlite3_finalize(pStmt);
166276 if( rc==SQLITE_OK ) rc = rc2;
166277
166278 p->rc = rc;
166279 return pRet;
166280 }
166281
166282
166283 /*
166284 ** Open the database handle and attach the RBU database as "rbu". If an
166285 ** error occurs, leave an error code and message in the RBU handle.
166286 */
166287 static void rbuOpenDatabase(sqlite3rbu *p){
166288 assert( p->rc==SQLITE_OK );
166289 assert( p->dbMain==0 && p->dbRbu==0 );
166290 assert( rbuIsVacuum(p) || p->zTarget!=0 );
166291
166292 /* Open the RBU database */
166293 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
166294
166295 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166296 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166297 }
166298
166299 /* If using separate RBU and state databases, attach the state database to
166300 ** the RBU db handle now. */
166301 if( p->zState ){
166302 rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
166303 memcpy(p->zStateDb, "stat", 4);
166304 }else{
166305 memcpy(p->zStateDb, "main", 4);
166306 }
166307
166308 #if 0
166309 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166310 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
166311 }
166312 #endif
166313
166314 /* If it has not already been created, create the rbu_state table */
166315 rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166316
166317 #if 0
166318 if( rbuIsVacuum(p) ){
166319 if( p->rc==SQLITE_OK ){
166320 int rc2;
166321 int bOk = 0;
166322 sqlite3_stmt *pCnt = 0;
166323 p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
166324 "SELECT count(*) FROM stat.sqlite_master"
166325 );
166326 if( p->rc==SQLITE_OK
166327 && sqlite3_step(pCnt)==SQLITE_ROW
166328 && 1==sqlite3_column_int(pCnt, 0)
166329 ){
166330 bOk = 1;
166331 }
166332 rc2 = sqlite3_finalize(pCnt);
166333 if( p->rc==SQLITE_OK ) p->rc = rc2;
166334
166335 if( p->rc==SQLITE_OK && bOk==0 ){
166336 p->rc = SQLITE_ERROR;
166337 p->zErrmsg = sqlite3_mprintf("invalid state database");
166338 }
166339
166340 if( p->rc==SQLITE_OK ){
166341 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
166342 }
166343 }
166344 }
166345 #endif
166346
166347 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166348 int bOpen = 0;
166349 int rc;
166350 p->nRbu = 0;
166351 p->pRbuFd = 0;
166352 rc = sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166353 if( rc!=SQLITE_NOTFOUND ) p->rc = rc;
166354 if( p->eStage>=RBU_STAGE_MOVE ){
166355 bOpen = 1;
166356 }else{
166357 RbuState *pState = rbuLoadState(p);
166358 if( pState ){
166359 bOpen = (pState->eStage>RBU_STAGE_MOVE);
166360 rbuFreeState(pState);
166361 }
166362 }
166363 if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
166364 }
166365
166366 p->eStage = 0;
166367 if( p->rc==SQLITE_OK && p->dbMain==0 ){
166368 if( !rbuIsVacuum(p) ){
166369 p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
166370 }else if( p->pRbuFd->pWalFd ){
166371 p->rc = SQLITE_ERROR;
166372 p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
166373 }else{
166374 char *zTarget;
166375 char *zExtra = 0;
166376 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
166377 zExtra = &p->zRbu[5];
166378 while( *zExtra ){
166379 if( *zExtra++=='?' ) break;
166380 }
166381 if( *zExtra=='\0' ) zExtra = 0;
166382 }
166383
166384 zTarget = sqlite3_mprintf("file:%s-vacuum?rbu_memory=1%s%s",
166385 sqlite3_db_filename(p->dbRbu, "main"),
166386 (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
166387 );
166388
166389 if( zTarget==0 ){
166390 p->rc = SQLITE_NOMEM;
166391 return;
166392 }
166393 p->dbMain = rbuOpenDbhandle(p, zTarget, p->nRbu<=1);
166394 sqlite3_free(zTarget);
166395 }
166396 }
166397
166398 if( p->rc==SQLITE_OK ){
166399 p->rc = sqlite3_create_function(p->dbMain,
166400 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
166401 );
@@ -165628,11 +166407,11 @@
166407 );
166408 }
166409
166410 if( p->rc==SQLITE_OK ){
166411 p->rc = sqlite3_create_function(p->dbRbu,
166412 "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
166413 );
166414 }
166415
166416 if( p->rc==SQLITE_OK ){
166417 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166666,19 @@
166666 ** If an error occurs, leave an error code and error message in the rbu
166667 ** handle.
166668 */
166669 static void rbuMoveOalFile(sqlite3rbu *p){
166670 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
166671 const char *zMove = zBase;
166672 char *zOal;
166673 char *zWal;
166674
166675 if( rbuIsVacuum(p) ){
166676 zMove = sqlite3_db_filename(p->dbRbu, "main");
166677 }
166678 zOal = sqlite3_mprintf("%s-oal", zMove);
166679 zWal = sqlite3_mprintf("%s-wal", zMove);
166680
166681 assert( p->eStage==RBU_STAGE_MOVE );
166682 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
166683 if( zWal==0 || zOal==0 ){
166684 p->rc = SQLITE_NOMEM;
@@ -165910,12 +166695,12 @@
166695 rbuFileSuffix3(zBase, zWal);
166696 rbuFileSuffix3(zBase, zOal);
166697
166698 /* Re-open the databases. */
166699 rbuObjIterFinalize(&p->objiter);
 
166700 sqlite3_close(p->dbRbu);
166701 sqlite3_close(p->dbMain);
166702 p->dbMain = 0;
166703 p->dbRbu = 0;
166704
166705 #if defined(_WIN32_WCE)
166706 {
@@ -166073,23 +166858,28 @@
166858
166859 pVal = sqlite3_column_value(pIter->pSelect, i);
166860 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166861 if( p->rc ) return;
166862 }
166863 if( pIter->zIdx==0 ){
166864 if( pIter->eType==RBU_PK_VTAB
166865 || pIter->eType==RBU_PK_NONE
166866 || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p))
166867 ){
166868 /* For a virtual table, or a table with no primary key, the
166869 ** SELECT statement is:
166870 **
166871 ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166872 **
166873 ** Hence column_value(pIter->nCol+1).
166874 */
166875 assertColumnName(pIter->pSelect, pIter->nCol+1,
166876 rbuIsVacuum(p) ? "rowid" : "rbu_rowid"
166877 );
166878 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166879 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166880 }
166881 }
166882 if( p->rc==SQLITE_OK ){
166883 sqlite3_step(pWriter);
166884 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166885 }
@@ -166164,17 +166954,22 @@
166954 return p->rc;
166955 }
166956
166957 /*
166958 ** Increment the schema cookie of the main database opened by p->dbMain.
166959 **
166960 ** Or, if this is an RBU vacuum, set the schema cookie of the main db
166961 ** opened by p->dbMain to one more than the schema cookie of the main
166962 ** db opened by p->dbRbu.
166963 */
166964 static void rbuIncrSchemaCookie(sqlite3rbu *p){
166965 if( p->rc==SQLITE_OK ){
166966 sqlite3 *dbread = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
166967 int iCookie = 1000000;
166968 sqlite3_stmt *pStmt;
166969
166970 p->rc = prepareAndCollectError(dbread, &pStmt, &p->zErrmsg,
166971 "PRAGMA schema_version"
166972 );
166973 if( p->rc==SQLITE_OK ){
166974 /* Coverage: it may be that this sqlite3_step() cannot fail. There
166975 ** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166993,11 @@
166993 ** are determined by inspecting the rbu handle passed as the first argument.
166994 */
166995 static void rbuSaveState(sqlite3rbu *p, int eStage){
166996 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166997 sqlite3_stmt *pInsert = 0;
166998 rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
166999 int rc;
167000
167001 assert( p->zErrmsg==0 );
167002 rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
167003 sqlite3_mprintf(
@@ -166220,11 +167016,11 @@
167016 RBU_STATE_TBL, p->objiter.zTbl,
167017 RBU_STATE_IDX, p->objiter.zIdx,
167018 RBU_STATE_ROW, p->nStep,
167019 RBU_STATE_PROGRESS, p->nProgress,
167020 RBU_STATE_CKPT, p->iWalCksum,
167021 RBU_STATE_COOKIE, (i64)pFd->iCookie,
167022 RBU_STATE_OALSZ, p->iOalSz,
167023 RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
167024 )
167025 );
167026 assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +167031,121 @@
167031 }
167032 if( rc!=SQLITE_OK ) p->rc = rc;
167033 }
167034 }
167035
167036
167037 /*
167038 ** The second argument passed to this function is the name of a PRAGMA
167039 ** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
167040 ** This function executes the following on sqlite3rbu.dbRbu:
167041 **
167042 ** "PRAGMA main.$zPragma"
167043 **
167044 ** where $zPragma is the string passed as the second argument, then
167045 ** on sqlite3rbu.dbMain:
167046 **
167047 ** "PRAGMA main.$zPragma = $val"
167048 **
167049 ** where $val is the value returned by the first PRAGMA invocation.
167050 **
167051 ** In short, it copies the value of the specified PRAGMA setting from
167052 ** dbRbu to dbMain.
167053 */
167054 static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){
167055 if( p->rc==SQLITE_OK ){
167056 sqlite3_stmt *pPragma = 0;
167057 p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg,
167058 sqlite3_mprintf("PRAGMA main.%s", zPragma)
167059 );
167060 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){
167061 p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d",
167062 zPragma, sqlite3_column_int(pPragma, 0)
167063 );
167064 }
167065 rbuFinalize(p, pPragma);
167066 }
167067 }
167068
167069 /*
167070 ** The RBU handle passed as the only argument has just been opened and
167071 ** the state database is empty. If this RBU handle was opened for an
167072 ** RBU vacuum operation, create the schema in the target db.
167073 */
167074 static void rbuCreateTargetSchema(sqlite3rbu *p){
167075 sqlite3_stmt *pSql = 0;
167076 sqlite3_stmt *pInsert = 0;
167077
167078 assert( rbuIsVacuum(p) );
167079 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
167080 if( p->rc==SQLITE_OK ){
167081 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
167082 "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
167083 " AND name!='sqlite_sequence' "
167084 " ORDER BY type DESC"
167085 );
167086 }
167087
167088 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
167089 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
167090 p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
167091 }
167092 rbuFinalize(p, pSql);
167093 if( p->rc!=SQLITE_OK ) return;
167094
167095 if( p->rc==SQLITE_OK ){
167096 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
167097 "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
167098 );
167099 }
167100
167101 if( p->rc==SQLITE_OK ){
167102 p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
167103 "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
167104 );
167105 }
167106
167107 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
167108 int i;
167109 for(i=0; i<5; i++){
167110 sqlite3_bind_value(pInsert, i+1, sqlite3_column_value(pSql, i));
167111 }
167112 sqlite3_step(pInsert);
167113 p->rc = sqlite3_reset(pInsert);
167114 }
167115 if( p->rc==SQLITE_OK ){
167116 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
167117 }
167118
167119 rbuFinalize(p, pSql);
167120 rbuFinalize(p, pInsert);
167121 }
167122
167123 /*
167124 ** Step the RBU object.
167125 */
167126 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
167127 if( p ){
167128 switch( p->eStage ){
167129 case RBU_STAGE_OAL: {
167130 RbuObjIter *pIter = &p->objiter;
167131
167132 /* If this is an RBU vacuum operation and the state table was empty
167133 ** when this handle was opened, create the target database schema. */
167134 if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
167135 rbuCreateTargetSchema(p);
167136 rbuCopyPragma(p, "user_version");
167137 rbuCopyPragma(p, "application_id");
167138 }
167139
167140 while( p->rc==SQLITE_OK && pIter->zTbl ){
167141
167142 if( pIter->bCleanup ){
167143 /* Clean up the rbu_tmp_xxx table for the previous table. It
167144 ** cannot be dropped as there are currently active SQL statements.
167145 ** But the contents can be deleted. */
167146 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
167147 rbuMPrintfExec(p, p->dbRbu,
167148 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
167149 );
167150 }
167151 }else{
@@ -166337,98 +167228,10 @@
167228 }else{
167229 return SQLITE_NOMEM;
167230 }
167231 }
167232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167233 /*
167234 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
167235 ** otherwise. Either or both argument may be NULL. Two NULL values are
167236 ** considered equal, and NULL is considered distinct from all other values.
167237 */
@@ -166614,20 +167417,18 @@
167417 }
167418 }
167419 }
167420 }
167421
167422
167423 static sqlite3rbu *openRbuHandle(
 
 
167424 const char *zTarget,
167425 const char *zRbu,
167426 const char *zState
167427 ){
167428 sqlite3rbu *p;
167429 size_t nTarget = zTarget ? strlen(zTarget) : 0;
167430 size_t nRbu = strlen(zRbu);
167431 size_t nState = zState ? strlen(zState) : 0;
167432 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
167433
167434 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167437,28 @@
167437
167438 /* Create the custom VFS. */
167439 memset(p, 0, sizeof(sqlite3rbu));
167440 rbuCreateVfs(p);
167441
167442 /* Open the target, RBU and state databases */
167443 if( p->rc==SQLITE_OK ){
167444 char *pCsr = (char*)&p[1];
167445 if( zTarget ){
167446 p->zTarget = pCsr;
167447 memcpy(p->zTarget, zTarget, nTarget+1);
167448 pCsr += nTarget+1;
167449 }
167450 p->zRbu = pCsr;
167451 memcpy(p->zRbu, zRbu, nRbu+1);
167452 pCsr += nRbu+1;
167453 if( zState ){
167454 p->zState = pCsr;
167455 memcpy(p->zState, zState, nState+1);
167456 }
167457 rbuOpenDatabase(p);
167458 }
167459
 
 
 
167460 if( p->rc==SQLITE_OK ){
167461 pState = rbuLoadState(p);
167462 assert( pState || p->rc!=SQLITE_OK );
167463 if( p->rc==SQLITE_OK ){
167464
@@ -166681,31 +167484,43 @@
167484 p->eStage = RBU_STAGE_CKPT;
167485 p->nStep = 0;
167486 }
167487 }
167488
167489 if( p->rc==SQLITE_OK
167490 && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
167491 && pState->eStage!=0
167492 ){
167493 rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
167494 if( pFd->iCookie!=pState->iCookie ){
167495 /* At this point (pTargetFd->iCookie) contains the value of the
167496 ** change-counter cookie (the thing that gets incremented when a
167497 ** transaction is committed in rollback mode) currently stored on
167498 ** page 1 of the database file. */
167499 p->rc = SQLITE_BUSY;
167500 p->zErrmsg = sqlite3_mprintf("database modified during rbu %s",
167501 (rbuIsVacuum(p) ? "vacuum" : "update")
167502 );
167503 }
167504 }
167505
167506 if( p->rc==SQLITE_OK ){
167507 if( p->eStage==RBU_STAGE_OAL ){
167508 sqlite3 *db = p->dbMain;
167509
167510 if( pState->eStage==0 && rbuIsVacuum(p) ){
167511 rbuCopyPragma(p, "page_size");
167512 rbuCopyPragma(p, "auto_vacuum");
167513 }
167514
167515 /* Open transactions both databases. The *-oal file is opened or
167516 ** created at this point. */
167517 if( p->rc==SQLITE_OK ){
167518 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167519 }
167520 if( p->rc==SQLITE_OK ){
167521 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
167522 }
167523
167524 /* Check if the main database is a zipvfs db. If it is, set the upper
167525 ** level pager to use "journal_mode=off". This prevents it from
167526 ** generating a large journal using a temp file. */
@@ -166746,10 +167561,32 @@
167561 }
167562
167563 return p;
167564 }
167565
167566 /*
167567 ** Open and return a new RBU handle.
167568 */
167569 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167570 const char *zTarget,
167571 const char *zRbu,
167572 const char *zState
167573 ){
167574 /* TODO: Check that zTarget and zRbu are non-NULL */
167575 return openRbuHandle(zTarget, zRbu, zState);
167576 }
167577
167578 /*
167579 ** Open a handle to begin or resume an RBU VACUUM operation.
167580 */
167581 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
167582 const char *zTarget,
167583 const char *zState
167584 ){
167585 /* TODO: Check that both arguments are non-NULL */
167586 return openRbuHandle(0, zTarget, zState);
167587 }
167588
167589 /*
167590 ** Return the database handle used by pRbu.
167591 */
167592 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167603,11 @@
167603 ** then edit any error message string so as to remove all occurrences of
167604 ** the pattern "rbu_imp_[0-9]*".
167605 */
167606 static void rbuEditErrmsg(sqlite3rbu *p){
167607 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
167608 unsigned int i;
167609 size_t nErrmsg = strlen(p->zErrmsg);
167610 for(i=0; i<(nErrmsg-8); i++){
167611 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
167612 int nDel = 8;
167613 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167636,24 @@
167636 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
167637 }
167638
167639 /* Close any open statement handles. */
167640 rbuObjIterFinalize(&p->objiter);
167641
167642 /* If this is an RBU vacuum handle and the vacuum has either finished
167643 ** successfully or encountered an error, delete the contents of the
167644 ** state table. This causes the next call to sqlite3rbu_vacuum()
167645 ** specifying the current target and state databases to start a new
167646 ** vacuum from scratch. */
167647 if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){
167648 int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
167649 if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2;
167650 }
167651
167652 /* Close the open database handle and VFS object. */
 
167653 sqlite3_close(p->dbRbu);
167654 sqlite3_close(p->dbMain);
167655 rbuDeleteVfs(p);
167656 sqlite3_free(p->aBuf);
167657 sqlite3_free(p->aFrame);
167658
167659 rbuEditErrmsg(p);
@@ -167003,10 +167850,26 @@
167850 return ((u32)aBuf[0] << 24)
167851 + ((u32)aBuf[1] << 16)
167852 + ((u32)aBuf[2] << 8)
167853 + ((u32)aBuf[3]);
167854 }
167855
167856 /*
167857 ** Write an unsigned 32-bit value in big-endian format to the supplied
167858 ** buffer.
167859 */
167860 static void rbuPutU32(u8 *aBuf, u32 iVal){
167861 aBuf[0] = (iVal >> 24) & 0xFF;
167862 aBuf[1] = (iVal >> 16) & 0xFF;
167863 aBuf[2] = (iVal >> 8) & 0xFF;
167864 aBuf[3] = (iVal >> 0) & 0xFF;
167865 }
167866
167867 static void rbuPutU16(u8 *aBuf, u16 iVal){
167868 aBuf[0] = (iVal >> 8) & 0xFF;
167869 aBuf[1] = (iVal >> 0) & 0xFF;
167870 }
167871
167872 /*
167873 ** Read data from an rbuVfs-file.
167874 */
167875 static int rbuVfsRead(
@@ -167029,10 +167892,39 @@
167892 ){
167893 rc = SQLITE_OK;
167894 memset(zBuf, 0, iAmt);
167895 }else{
167896 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
167897 #if 1
167898 /* If this is being called to read the first page of the target
167899 ** database as part of an rbu vacuum operation, synthesize the
167900 ** contents of the first page if it does not yet exist. Otherwise,
167901 ** SQLite will not check for a *-wal file. */
167902 if( pRbu && rbuIsVacuum(pRbu)
167903 && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
167904 && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167905 && pRbu->rc==SQLITE_OK
167906 ){
167907 sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd;
167908 rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst);
167909 if( rc==SQLITE_OK ){
167910 u8 *aBuf = (u8*)zBuf;
167911 u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
167912 rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
167913 rbuPutU32(&aBuf[36], 0); /* number of free pages */
167914 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
167915 rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
167916 rbuPutU32(&aBuf[24], pRbu->pRbuFd->iCookie+1); /* Change counter */
167917
167918 if( iAmt>100 ){
167919 memset(&aBuf[100], 0, iAmt-100);
167920 rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
167921 aBuf[100] = 0x0D;
167922 }
167923 }
167924 }
167925 #endif
167926 }
167927 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167928 /* These look like magic numbers. But they are stable, as they are part
167929 ** of the definition of the SQLite file format, which may not change. */
167930 u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167995,24 @@
167995 /*
167996 ** Return the current file-size of an rbuVfs-file.
167997 */
167998 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167999 rbu_file *p = (rbu_file *)pFile;
168000 int rc;
168001 rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
168002
168003 /* If this is an RBU vacuum operation and this is the target database,
168004 ** pretend that it has at least one page. Otherwise, SQLite will not
168005 ** check for the existance of a *-wal file. rbuVfsRead() contains
168006 ** similar logic. */
168007 if( rc==SQLITE_OK && *pSize==0
168008 && p->pRbu && rbuIsVacuum(p->pRbu)
168009 && (p->openFlags & SQLITE_OPEN_MAIN_DB)
168010 ){
168011 *pSize = 1024;
168012 }
168013 return rc;
168014 }
168015
168016 /*
168017 ** Lock an rbuVfs-file.
168018 */
@@ -167115,11 +168020,13 @@
168020 rbu_file *p = (rbu_file*)pFile;
168021 sqlite3rbu *pRbu = p->pRbu;
168022 int rc = SQLITE_OK;
168023
168024 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
168025 if( eLock==SQLITE_LOCK_EXCLUSIVE
168026 && (p->bNolock || (pRbu && pRbu->eStage!=RBU_STAGE_DONE))
168027 ){
168028 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
168029 ** prevents it from checkpointing the database from sqlite3_close(). */
168030 rc = SQLITE_BUSY;
168031 }else{
168032 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +168084,16 @@
168084 if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
168085 rc = SQLITE_OK;
168086 }
168087 }
168088 return rc;
168089 }
168090 else if( op==SQLITE_FCNTL_RBUCNT ){
168091 sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
168092 pRbu->nRbu++;
168093 pRbu->pRbuFd = p;
168094 p->bNolock = 1;
168095 }
168096
168097 rc = xControl(p->pReal, op, pArg);
168098 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
168099 rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168253,37 @@
168253 sqlite3_mutex_enter(pRbuVfs->mutex);
168254 for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
168255 sqlite3_mutex_leave(pRbuVfs->mutex);
168256 return pDb;
168257 }
168258
168259 /*
168260 ** A main database named zName has just been opened. The following
168261 ** function returns a pointer to a buffer owned by SQLite that contains
168262 ** the name of the *-wal file this db connection will use. SQLite
168263 ** happens to pass a pointer to this buffer when using xAccess()
168264 ** or xOpen() to operate on the *-wal file.
168265 */
168266 static const char *rbuMainToWal(const char *zName, int flags){
168267 int n = (int)strlen(zName);
168268 const char *z = &zName[n];
168269 if( flags & SQLITE_OPEN_URI ){
168270 int odd = 0;
168271 while( 1 ){
168272 if( z[0]==0 ){
168273 odd = 1 - odd;
168274 if( odd && z[1]==0 ) break;
168275 }
168276 z++;
168277 }
168278 z += 2;
168279 }else{
168280 while( *z==0 ) z++;
168281 }
168282 z += (n + 8 + 1);
168283 return z;
168284 }
168285
168286 /*
168287 ** Open an rbu file handle.
168288 */
168289 static int rbuVfsOpen(
@@ -167376,10 +168316,11 @@
168316 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
168317 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
168318 rbu_file *pFd = (rbu_file *)pFile;
168319 int rc = SQLITE_OK;
168320 const char *zOpen = zName;
168321 int oflags = flags;
168322
168323 memset(pFd, 0, sizeof(rbu_file));
168324 pFd->pReal = (sqlite3_file*)&pFd[1];
168325 pFd->pRbuVfs = pRbuVfs;
168326 pFd->openFlags = flags;
@@ -167388,40 +168329,31 @@
168329 /* A main database has just been opened. The following block sets
168330 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
168331 ** the name of the *-wal file this db connection will use. SQLite
168332 ** happens to pass a pointer to this buffer when using xAccess()
168333 ** or xOpen() to operate on the *-wal file. */
168334 pFd->zWal = rbuMainToWal(zName, flags);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168335 }
168336 else if( flags & SQLITE_OPEN_WAL ){
168337 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
168338 if( pDb ){
168339 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
168340 /* This call is to open a *-wal file. Intead, open the *-oal. This
168341 ** code ensures that the string passed to xOpen() is terminated by a
168342 ** pair of '\0' bytes in case the VFS attempts to extract a URI
168343 ** parameter from it. */
168344 const char *zBase = zName;
168345 size_t nCopy;
168346 char *zCopy;
168347 if( rbuIsVacuum(pDb->pRbu) ){
168348 zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
168349 zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
168350 }
168351 nCopy = strlen(zBase);
168352 zCopy = sqlite3_malloc64(nCopy+2);
168353 if( zCopy ){
168354 memcpy(zCopy, zBase, nCopy);
168355 zCopy[nCopy-3] = 'o';
168356 zCopy[nCopy] = '\0';
168357 zCopy[nCopy+1] = '\0';
168358 zOpen = (const char*)(pFd->zDel = zCopy);
168359 }else{
@@ -167431,13 +168363,22 @@
168363 }
168364 pDb->pWalFd = pFd;
168365 }
168366 }
168367 }
168368
168369 if( oflags & SQLITE_OPEN_MAIN_DB
168370 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
168371 ){
168372 assert( oflags & SQLITE_OPEN_MAIN_DB );
168373 oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
168374 SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
168375 zOpen = 0;
168376 }
168377
168378 if( rc==SQLITE_OK ){
168379 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
168380 }
168381 if( pFd->pReal->pMethods ){
168382 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
168383 ** pointer and, if the file is a main database file, link it into the
168384 ** mutex protected linked list of all such files. */
@@ -168678,23 +169619,22 @@
169619 */
169620 static int sessionVarintGet(u8 *aBuf, int *piVal){
169621 return getVarint32(aBuf, *piVal);
169622 }
169623
169624 /* Load an unaligned and unsigned 32-bit integer */
169625 #define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
169626
169627 /*
169628 ** Read a 64-bit big-endian integer value from buffer aRec[]. Return
169629 ** the value read.
169630 */
169631 static sqlite3_int64 sessionGetI64(u8 *aRec){
169632 u64 x = SESSION_UINT32(aRec);
169633 u32 y = SESSION_UINT32(aRec+4);
169634 x = (x<<32) + y;
169635 return (sqlite3_int64)x;
 
 
 
 
169636 }
169637
169638 /*
169639 ** Write a 64-bit big-endian integer value to the buffer aBuf[].
169640 */
@@ -168992,18 +169932,23 @@
169932 u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
169933 u8 *a2 = aRight; /* Cursor to iterate through aRight */
169934 int iCol; /* Used to iterate through table columns */
169935
169936 for(iCol=0; iCol<pTab->nCol; iCol++){
169937 if( pTab->abPK[iCol] ){
169938 int n1 = sessionSerialLen(a1);
169939 int n2 = sessionSerialLen(a2);
169940
169941 if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169942 return 0;
169943 }
169944 a1 += n1;
169945 a2 += n2;
169946 }else{
169947 if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
169948 if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
169949 }
169950 }
169951
169952 return 1;
169953 }
169954
@@ -169335,13 +170280,13 @@
170280 int rc;
170281 int nByte;
170282 int nDbCol = 0;
170283 int nThis;
170284 int i;
170285 u8 *pAlloc = 0;
170286 char **azCol = 0;
170287 u8 *abPK = 0;
170288
170289 assert( pazCol && pabPK );
170290
170291 nThis = sqlite3Strlen30(zThis);
170292 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170938,13 @@
170938 for(pTab=pList; pTab; pTab=pNext){
170939 int i;
170940 pNext = pTab->pNext;
170941 for(i=0; i<pTab->nChange; i++){
170942 SessionChange *p;
170943 SessionChange *pNextChange;
170944 for(p=pTab->apChange[i]; p; p=pNextChange){
170945 pNextChange = p->pNext;
170946 sqlite3_free(p);
170947 }
170948 }
170949 sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170950 sqlite3_free(pTab->apChange);
@@ -171282,11 +172227,10 @@
172227 if( p->bPatchset && p->op==SQLITE_UPDATE ){
172228 /* If this is an UPDATE that is part of a patchset, then all PK and
172229 ** modified fields are present in the new.* record. The old.* record
172230 ** is currently completely empty. This block shifts the PK fields from
172231 ** new.* to old.*, to accommodate the code that reads these arrays. */
 
172232 for(i=0; i<p->nCol; i++){
172233 assert( p->apValue[i]==0 );
172234 assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
172235 if( p->abPK[i] ){
172236 p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172999,11 @@
172999 sqlite3_changeset_iter *pIter, /* Changeset iterator */
173000 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
173001 void *pCtx, /* First argument for conflict handler */
173002 int *pbReplace /* OUT: Set to true if PK row is found */
173003 ){
173004 int res = 0; /* Value returned by conflict handler */
173005 int rc;
173006 int nCol;
173007 int op;
173008 const char *zDummy;
173009
@@ -175390,15 +176334,17 @@
176334 ** of the current query. Specifically, a query equivalent to:
176335 **
176336 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
176337 **
176338 ** with $p set to a phrase equivalent to the phrase iPhrase of the
176339 ** current query is executed. Any column filter that applies to
176340 ** phrase iPhrase of the current query is included in $p. For each
176341 ** row visited, the callback function passed as the fourth argument
176342 ** is invoked. The context and API objects passed to the callback
176343 ** function may be used to access the properties of each matched row.
176344 ** Invoking Api.xUserData() returns a copy of the pointer passed as
176345 ** the third argument to pUserData.
176346 **
176347 ** If the callback function returns any value other than SQLITE_OK, the
176348 ** query is abandoned and the xQueryPhrase function returns immediately.
176349 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
176350 ** Otherwise, the error code is propagated upwards.
@@ -181429,10 +182375,21 @@
182375 }
182376 if( rc==SQLITE_OK ){
182377 pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc,
182378 sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
182379 }
182380 if( rc==SQLITE_OK ){
182381 Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
182382 if( pColsetOrig ){
182383 int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int);
182384 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
182385 if( pColset ){
182386 memcpy(pColset, pColsetOrig, nByte);
182387 }
182388 pNew->pRoot->pNear->pColset = pColset;
182389 }
182390 }
182391
182392 for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){
182393 int tflags = 0;
182394 Fts5ExprTerm *p;
182395 for(p=&pOrig->aTerm[i]; p && rc==SQLITE_OK; p=p->pSynonym){
@@ -182777,15 +183734,15 @@
183734 assert( iCol>=p->iCol );
183735 if( iCol!=p->iCol ){
183736 if( pHash->eDetail==FTS5_DETAIL_FULL ){
183737 pPtr[p->nData++] = 0x01;
183738 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
183739 p->iCol = (i16)iCol;
183740 p->iPos = 0;
183741 }else{
183742 bNew = 1;
183743 p->iCol = (i16)(iPos = iCol);
183744 }
183745 }
183746
183747 /* Append the new position offset, if necessary */
183748 if( bNew ){
@@ -186204,11 +187161,11 @@
187161 while( *aiCol<iPrev ){
187162 aiCol++;
187163 if( aiCol==aiColEnd ) goto setoutputs_col_out;
187164 }
187165 if( *aiCol==iPrev ){
187166 *aOut++ = (u8)((iPrev - iPrevOut) + 2);
187167 iPrevOut = iPrev;
187168 }
187169 }
187170
187171 setoutputs_col_out:
@@ -192037,11 +192994,11 @@
192994 int nArg, /* Number of args */
192995 sqlite3_value **apUnused /* Function arguments */
192996 ){
192997 assert( nArg==0 );
192998 UNUSED_PARAM2(nArg, apUnused);
192999 sqlite3_result_text(pCtx, "fts5: 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2", -1, SQLITE_TRANSIENT);
193000 }
193001
193002 static int fts5Init(sqlite3 *db){
193003 static const sqlite3_module fts5Mod = {
193004 /* iVersion */ 2,
193005
+94 -18
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.13.0"
115115
#define SQLITE_VERSION_NUMBER 3013000
116
-#define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
116
+#define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -1930,16 +1930,34 @@
19301930
** The second parameter is a pointer to an integer into which
19311931
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
19321932
** following this call. The second parameter may be a NULL pointer, in
19331933
** which case the new setting is not reported back. </dd>
19341934
**
1935
+** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
1936
+** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
1937
+** interface independently of the [load_extension()] SQL function.
1938
+** The [sqlite3_enable_load_extension()] API enables or disables both the
1939
+** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
1940
+** There should be two additional arguments.
1941
+** When the first argument to this interface is 1, then only the C-API is
1942
+** enabled and the SQL function remains disabled. If the first argment to
1943
+** this interface is 0, then both the C-API and the SQL function are disabled.
1944
+** If the first argument is -1, then no changes are made to state of either the
1945
+** C-API or the SQL function.
1946
+** The second parameter is a pointer to an integer into which
1947
+** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1948
+** is disabled or enabled following this call. The second parameter may
1949
+** be a NULL pointer, in which case the new setting is not reported back.
1950
+** </dd>
1951
+**
19351952
** </dl>
19361953
*/
19371954
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
19381955
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
19391956
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
19401957
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1958
+#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
19411959
19421960
19431961
/*
19441962
** CAPI3REF: Enable Or Disable Extended Result Codes
19451963
** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
54725490
** fill *pzErrMsg with error message text stored in memory
54735491
** obtained from [sqlite3_malloc()]. The calling function
54745492
** should free this memory by calling [sqlite3_free()].
54755493
**
54765494
** ^Extension loading must be enabled using
5477
-** [sqlite3_enable_load_extension()] prior to calling this API,
5495
+** [sqlite3_enable_load_extension()] or
5496
+** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5497
+** prior to calling this API,
54785498
** otherwise an error will be returned.
5499
+**
5500
+** <b>Security warning:</b> It is recommended that the
5501
+** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5502
+** interface. The use of the [sqlite3_enable_load_extension()] interface
5503
+** should be avoided. This will keep the SQL function [load_extension()]
5504
+** disabled and prevent SQL injections from giving attackers
5505
+** access to extension loading capabilities.
54795506
**
54805507
** See also the [load_extension() SQL function].
54815508
*/
54825509
SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
54835510
sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
54975524
**
54985525
** ^Extension loading is off by default.
54995526
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
55005527
** to turn extension loading on and call it with onoff==0 to turn
55015528
** it back off again.
5529
+**
5530
+** ^This interface enables or disables both the C-API
5531
+** [sqlite3_load_extension()] and the SQL function [load_extension()].
5532
+** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5533
+** to enable or disable only the C-API.
5534
+**
5535
+** <b>Security warning:</b> It is recommended that extension loading
5536
+** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5537
+** rather than this interface, so the [load_extension()] SQL function
5538
+** remains disabled. This will prevent SQL injections from giving attackers
5539
+** access to extension loading capabilities.
55025540
*/
55035541
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
55045542
55055543
/*
55065544
** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
80798117
80808118
/*
80818119
** CAPI3REF: Start a read transaction on an historical snapshot
80828120
** EXPERIMENTAL
80838121
**
8084
-** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8085
-** read transaction that is currently open on schema S of
8086
-** [database connection] D so that it refers to historical [snapshot] P.
8122
+** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8123
+** read transaction for schema S of
8124
+** [database connection] D such that the read transaction
8125
+** refers to historical [snapshot] P, rather than the most
8126
+** recent change to the database.
80878127
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
80888128
** or an appropriate [error code] if it fails.
80898129
**
80908130
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8091
-** the first operation, apart from other sqlite3_snapshot_open() calls,
8092
-** following the [BEGIN] that starts a new read transaction.
8093
-** ^A [snapshot] will fail to open if it has been overwritten by a
8131
+** the first operation following the [BEGIN] that takes the schema S
8132
+** out of [autocommit mode].
8133
+** ^In other words, schema S must not currently be in
8134
+** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8135
+** database connection D must be out of [autocommit mode].
8136
+** ^A [snapshot] will fail to open if it has been overwritten by a
80948137
** [checkpoint].
8095
-** ^A [snapshot] will fail to open if the database connection D has not
8096
-** previously completed at least one read operation against the database
8097
-** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
8138
+** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8139
+** database connection D does not know that the database file for
8140
+** schema S is in [WAL mode]. A database connection might not know
8141
+** that the database file is in [WAL mode] if there has been no prior
8142
+** I/O on that database connection, or if the database entered [WAL mode]
8143
+** after the most recent I/O on the database connection.)^
8144
+** (Hint: Run "[PRAGMA application_id]" against a newly opened
80988145
** database connection in order to make it ready to use snapshots.)
80998146
**
81008147
** The [sqlite3_snapshot_open()] interface is only available when the
81018148
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
81028149
*/
@@ -8116,10 +8163,37 @@
81168163
**
81178164
** The [sqlite3_snapshot_free()] interface is only available when the
81188165
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
81198166
*/
81208167
SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8168
+
8169
+/*
8170
+** CAPI3REF: Compare the ages of two snapshot handles.
8171
+** EXPERIMENTAL
8172
+**
8173
+** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8174
+** of two valid snapshot handles.
8175
+**
8176
+** If the two snapshot handles are not associated with the same database
8177
+** file, the result of the comparison is undefined.
8178
+**
8179
+** Additionally, the result of the comparison is only valid if both of the
8180
+** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8181
+** last time the wal file was deleted. The wal file is deleted when the
8182
+** database is changed back to rollback mode or when the number of database
8183
+** clients drops to zero. If either snapshot handle was obtained before the
8184
+** wal file was last deleted, the value returned by this function
8185
+** is undefined.
8186
+**
8187
+** Otherwise, this API returns a negative value if P1 refers to an older
8188
+** snapshot than P2, zero if the two handles refer to the same database
8189
+** snapshot, and a positive value if P1 is a newer snapshot than P2.
8190
+*/
8191
+SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8192
+ sqlite3_snapshot *p1,
8193
+ sqlite3_snapshot *p2
8194
+);
81218195
81228196
/*
81238197
** Undo the hack that converts floating point types to integer for
81248198
** builds on processors without floating point support.
81258199
*/
@@ -8251,11 +8325,11 @@
82518325
#endif /* ifndef _SQLITE3RTREE_H_ */
82528326
82538327
/******** End of sqlite3rtree.h *********/
82548328
/******** Begin file sqlite3session.h *********/
82558329
8256
-#ifndef __SQLITESESSION_H_
8330
+#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
82578331
#define __SQLITESESSION_H_ 1
82588332
82598333
/*
82608334
** Make sure we can call this stuff from C++.
82618335
*/
@@ -9525,11 +9599,11 @@
95259599
*/
95269600
#ifdef __cplusplus
95279601
}
95289602
#endif
95299603
9530
-#endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
9604
+#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
95319605
95329606
/******** End of sqlite3session.h *********/
95339607
/******** Begin file fts5.h *********/
95349608
/*
95359609
** 2014 May 31
@@ -9673,15 +9747,17 @@
96739747
** of the current query. Specifically, a query equivalent to:
96749748
**
96759749
** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
96769750
**
96779751
** with $p set to a phrase equivalent to the phrase iPhrase of the
9678
-** current query is executed. For each row visited, the callback function
9679
-** passed as the fourth argument is invoked. The context and API objects
9680
-** passed to the callback function may be used to access the properties of
9681
-** each matched row. Invoking Api.xUserData() returns a copy of the pointer
9682
-** passed as the third argument to pUserData.
9752
+** current query is executed. Any column filter that applies to
9753
+** phrase iPhrase of the current query is included in $p. For each
9754
+** row visited, the callback function passed as the fourth argument
9755
+** is invoked. The context and API objects passed to the callback
9756
+** function may be used to access the properties of each matched row.
9757
+** Invoking Api.xUserData() returns a copy of the pointer passed as
9758
+** the third argument to pUserData.
96839759
**
96849760
** If the callback function returns any value other than SQLITE_OK, the
96859761
** query is abandoned and the xQueryPhrase function returns immediately.
96869762
** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
96879763
** Otherwise, the error code is propagated upwards.
96889764
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -1930,16 +1930,34 @@
1930 ** The second parameter is a pointer to an integer into which
1931 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
1932 ** following this call. The second parameter may be a NULL pointer, in
1933 ** which case the new setting is not reported back. </dd>
1934 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1935 ** </dl>
1936 */
1937 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1938 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1939 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1940 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
 
1941
1942
1943 /*
1944 ** CAPI3REF: Enable Or Disable Extended Result Codes
1945 ** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
5472 ** fill *pzErrMsg with error message text stored in memory
5473 ** obtained from [sqlite3_malloc()]. The calling function
5474 ** should free this memory by calling [sqlite3_free()].
5475 **
5476 ** ^Extension loading must be enabled using
5477 ** [sqlite3_enable_load_extension()] prior to calling this API,
 
 
5478 ** otherwise an error will be returned.
 
 
 
 
 
 
 
5479 **
5480 ** See also the [load_extension() SQL function].
5481 */
5482 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5483 sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
5497 **
5498 ** ^Extension loading is off by default.
5499 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5500 ** to turn extension loading on and call it with onoff==0 to turn
5501 ** it back off again.
 
 
 
 
 
 
 
 
 
 
 
5502 */
5503 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5504
5505 /*
5506 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
8079
8080 /*
8081 ** CAPI3REF: Start a read transaction on an historical snapshot
8082 ** EXPERIMENTAL
8083 **
8084 ** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8085 ** read transaction that is currently open on schema S of
8086 ** [database connection] D so that it refers to historical [snapshot] P.
 
 
8087 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8088 ** or an appropriate [error code] if it fails.
8089 **
8090 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8091 ** the first operation, apart from other sqlite3_snapshot_open() calls,
8092 ** following the [BEGIN] that starts a new read transaction.
8093 ** ^A [snapshot] will fail to open if it has been overwritten by a
 
 
 
8094 ** [checkpoint].
8095 ** ^A [snapshot] will fail to open if the database connection D has not
8096 ** previously completed at least one read operation against the database
8097 ** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
 
 
 
 
8098 ** database connection in order to make it ready to use snapshots.)
8099 **
8100 ** The [sqlite3_snapshot_open()] interface is only available when the
8101 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8102 */
@@ -8116,10 +8163,37 @@
8116 **
8117 ** The [sqlite3_snapshot_free()] interface is only available when the
8118 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8119 */
8120 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8121
8122 /*
8123 ** Undo the hack that converts floating point types to integer for
8124 ** builds on processors without floating point support.
8125 */
@@ -8251,11 +8325,11 @@
8251 #endif /* ifndef _SQLITE3RTREE_H_ */
8252
8253 /******** End of sqlite3rtree.h *********/
8254 /******** Begin file sqlite3session.h *********/
8255
8256 #ifndef __SQLITESESSION_H_
8257 #define __SQLITESESSION_H_ 1
8258
8259 /*
8260 ** Make sure we can call this stuff from C++.
8261 */
@@ -9525,11 +9599,11 @@
9525 */
9526 #ifdef __cplusplus
9527 }
9528 #endif
9529
9530 #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */
9531
9532 /******** End of sqlite3session.h *********/
9533 /******** Begin file fts5.h *********/
9534 /*
9535 ** 2014 May 31
@@ -9673,15 +9747,17 @@
9673 ** of the current query. Specifically, a query equivalent to:
9674 **
9675 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
9676 **
9677 ** with $p set to a phrase equivalent to the phrase iPhrase of the
9678 ** current query is executed. For each row visited, the callback function
9679 ** passed as the fourth argument is invoked. The context and API objects
9680 ** passed to the callback function may be used to access the properties of
9681 ** each matched row. Invoking Api.xUserData() returns a copy of the pointer
9682 ** passed as the third argument to pUserData.
 
 
9683 **
9684 ** If the callback function returns any value other than SQLITE_OK, the
9685 ** query is abandoned and the xQueryPhrase function returns immediately.
9686 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
9687 ** Otherwise, the error code is propagated upwards.
9688
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -1930,16 +1930,34 @@
1930 ** The second parameter is a pointer to an integer into which
1931 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
1932 ** following this call. The second parameter may be a NULL pointer, in
1933 ** which case the new setting is not reported back. </dd>
1934 **
1935 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
1936 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
1937 ** interface independently of the [load_extension()] SQL function.
1938 ** The [sqlite3_enable_load_extension()] API enables or disables both the
1939 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
1940 ** There should be two additional arguments.
1941 ** When the first argument to this interface is 1, then only the C-API is
1942 ** enabled and the SQL function remains disabled. If the first argment to
1943 ** this interface is 0, then both the C-API and the SQL function are disabled.
1944 ** If the first argument is -1, then no changes are made to state of either the
1945 ** C-API or the SQL function.
1946 ** The second parameter is a pointer to an integer into which
1947 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1948 ** is disabled or enabled following this call. The second parameter may
1949 ** be a NULL pointer, in which case the new setting is not reported back.
1950 ** </dd>
1951 **
1952 ** </dl>
1953 */
1954 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1955 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1956 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1957 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1958 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1959
1960
1961 /*
1962 ** CAPI3REF: Enable Or Disable Extended Result Codes
1963 ** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
5490 ** fill *pzErrMsg with error message text stored in memory
5491 ** obtained from [sqlite3_malloc()]. The calling function
5492 ** should free this memory by calling [sqlite3_free()].
5493 **
5494 ** ^Extension loading must be enabled using
5495 ** [sqlite3_enable_load_extension()] or
5496 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5497 ** prior to calling this API,
5498 ** otherwise an error will be returned.
5499 **
5500 ** <b>Security warning:</b> It is recommended that the
5501 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5502 ** interface. The use of the [sqlite3_enable_load_extension()] interface
5503 ** should be avoided. This will keep the SQL function [load_extension()]
5504 ** disabled and prevent SQL injections from giving attackers
5505 ** access to extension loading capabilities.
5506 **
5507 ** See also the [load_extension() SQL function].
5508 */
5509 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5510 sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
5524 **
5525 ** ^Extension loading is off by default.
5526 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5527 ** to turn extension loading on and call it with onoff==0 to turn
5528 ** it back off again.
5529 **
5530 ** ^This interface enables or disables both the C-API
5531 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5532 ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5533 ** to enable or disable only the C-API.
5534 **
5535 ** <b>Security warning:</b> It is recommended that extension loading
5536 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5537 ** rather than this interface, so the [load_extension()] SQL function
5538 ** remains disabled. This will prevent SQL injections from giving attackers
5539 ** access to extension loading capabilities.
5540 */
5541 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5542
5543 /*
5544 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
8117
8118 /*
8119 ** CAPI3REF: Start a read transaction on an historical snapshot
8120 ** EXPERIMENTAL
8121 **
8122 ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8123 ** read transaction for schema S of
8124 ** [database connection] D such that the read transaction
8125 ** refers to historical [snapshot] P, rather than the most
8126 ** recent change to the database.
8127 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8128 ** or an appropriate [error code] if it fails.
8129 **
8130 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8131 ** the first operation following the [BEGIN] that takes the schema S
8132 ** out of [autocommit mode].
8133 ** ^In other words, schema S must not currently be in
8134 ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8135 ** database connection D must be out of [autocommit mode].
8136 ** ^A [snapshot] will fail to open if it has been overwritten by a
8137 ** [checkpoint].
8138 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8139 ** database connection D does not know that the database file for
8140 ** schema S is in [WAL mode]. A database connection might not know
8141 ** that the database file is in [WAL mode] if there has been no prior
8142 ** I/O on that database connection, or if the database entered [WAL mode]
8143 ** after the most recent I/O on the database connection.)^
8144 ** (Hint: Run "[PRAGMA application_id]" against a newly opened
8145 ** database connection in order to make it ready to use snapshots.)
8146 **
8147 ** The [sqlite3_snapshot_open()] interface is only available when the
8148 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8149 */
@@ -8116,10 +8163,37 @@
8163 **
8164 ** The [sqlite3_snapshot_free()] interface is only available when the
8165 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8166 */
8167 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8168
8169 /*
8170 ** CAPI3REF: Compare the ages of two snapshot handles.
8171 ** EXPERIMENTAL
8172 **
8173 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8174 ** of two valid snapshot handles.
8175 **
8176 ** If the two snapshot handles are not associated with the same database
8177 ** file, the result of the comparison is undefined.
8178 **
8179 ** Additionally, the result of the comparison is only valid if both of the
8180 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8181 ** last time the wal file was deleted. The wal file is deleted when the
8182 ** database is changed back to rollback mode or when the number of database
8183 ** clients drops to zero. If either snapshot handle was obtained before the
8184 ** wal file was last deleted, the value returned by this function
8185 ** is undefined.
8186 **
8187 ** Otherwise, this API returns a negative value if P1 refers to an older
8188 ** snapshot than P2, zero if the two handles refer to the same database
8189 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
8190 */
8191 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8192 sqlite3_snapshot *p1,
8193 sqlite3_snapshot *p2
8194 );
8195
8196 /*
8197 ** Undo the hack that converts floating point types to integer for
8198 ** builds on processors without floating point support.
8199 */
@@ -8251,11 +8325,11 @@
8325 #endif /* ifndef _SQLITE3RTREE_H_ */
8326
8327 /******** End of sqlite3rtree.h *********/
8328 /******** Begin file sqlite3session.h *********/
8329
8330 #if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION)
8331 #define __SQLITESESSION_H_ 1
8332
8333 /*
8334 ** Make sure we can call this stuff from C++.
8335 */
@@ -9525,11 +9599,11 @@
9599 */
9600 #ifdef __cplusplus
9601 }
9602 #endif
9603
9604 #endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */
9605
9606 /******** End of sqlite3session.h *********/
9607 /******** Begin file fts5.h *********/
9608 /*
9609 ** 2014 May 31
@@ -9673,15 +9747,17 @@
9747 ** of the current query. Specifically, a query equivalent to:
9748 **
9749 ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid
9750 **
9751 ** with $p set to a phrase equivalent to the phrase iPhrase of the
9752 ** current query is executed. Any column filter that applies to
9753 ** phrase iPhrase of the current query is included in $p. For each
9754 ** row visited, the callback function passed as the fourth argument
9755 ** is invoked. The context and API objects passed to the callback
9756 ** function may be used to access the properties of each matched row.
9757 ** Invoking Api.xUserData() returns a copy of the pointer passed as
9758 ** the third argument to pUserData.
9759 **
9760 ** If the callback function returns any value other than SQLITE_OK, the
9761 ** query is abandoned and the xQueryPhrase function returns immediately.
9762 ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK.
9763 ** Otherwise, the error code is propagated upwards.
9764
--- src/th_main.c
+++ src/th_main.c
@@ -728,10 +728,11 @@
728728
** "tclPrivateStubs" = FOSSIL_ENABLE_TCL_PRIVATE_STUBS
729729
** "json" = FOSSIL_ENABLE_JSON
730730
** "markdown" = FOSSIL_ENABLE_MARKDOWN
731731
** "unicodeCmdLine" = !BROKEN_MINGW_CMDLINE
732732
** "dynamicBuild" = FOSSIL_DYNAMIC_BUILD
733
+** "see" = USE_SEE
733734
**
734735
** Specifying an unknown feature will return a value of false, it will not
735736
** raise a script error.
736737
*/
737738
static int hasfeatureCmd(
@@ -807,10 +808,15 @@
807808
#endif
808809
#if defined(FOSSIL_DYNAMIC_BUILD)
809810
else if( 0 == fossil_strnicmp( zArg, "dynamicBuild\0", 13 ) ){
810811
rc = 1;
811812
}
813
+#endif
814
+#if defined(USE_SEE)
815
+ else if( 0 == fossil_strnicmp( zArg, "see\0", 4 ) ){
816
+ rc = 1;
817
+ }
812818
#endif
813819
else if( 0 == fossil_strnicmp( zArg, "markdown\0", 9 ) ){
814820
rc = 1;
815821
}
816822
if( g.thTrace ){
817823
--- src/th_main.c
+++ src/th_main.c
@@ -728,10 +728,11 @@
728 ** "tclPrivateStubs" = FOSSIL_ENABLE_TCL_PRIVATE_STUBS
729 ** "json" = FOSSIL_ENABLE_JSON
730 ** "markdown" = FOSSIL_ENABLE_MARKDOWN
731 ** "unicodeCmdLine" = !BROKEN_MINGW_CMDLINE
732 ** "dynamicBuild" = FOSSIL_DYNAMIC_BUILD
 
733 **
734 ** Specifying an unknown feature will return a value of false, it will not
735 ** raise a script error.
736 */
737 static int hasfeatureCmd(
@@ -807,10 +808,15 @@
807 #endif
808 #if defined(FOSSIL_DYNAMIC_BUILD)
809 else if( 0 == fossil_strnicmp( zArg, "dynamicBuild\0", 13 ) ){
810 rc = 1;
811 }
 
 
 
 
 
812 #endif
813 else if( 0 == fossil_strnicmp( zArg, "markdown\0", 9 ) ){
814 rc = 1;
815 }
816 if( g.thTrace ){
817
--- src/th_main.c
+++ src/th_main.c
@@ -728,10 +728,11 @@
728 ** "tclPrivateStubs" = FOSSIL_ENABLE_TCL_PRIVATE_STUBS
729 ** "json" = FOSSIL_ENABLE_JSON
730 ** "markdown" = FOSSIL_ENABLE_MARKDOWN
731 ** "unicodeCmdLine" = !BROKEN_MINGW_CMDLINE
732 ** "dynamicBuild" = FOSSIL_DYNAMIC_BUILD
733 ** "see" = USE_SEE
734 **
735 ** Specifying an unknown feature will return a value of false, it will not
736 ** raise a script error.
737 */
738 static int hasfeatureCmd(
@@ -807,10 +808,15 @@
808 #endif
809 #if defined(FOSSIL_DYNAMIC_BUILD)
810 else if( 0 == fossil_strnicmp( zArg, "dynamicBuild\0", 13 ) ){
811 rc = 1;
812 }
813 #endif
814 #if defined(USE_SEE)
815 else if( 0 == fossil_strnicmp( zArg, "see\0", 4 ) ){
816 rc = 1;
817 }
818 #endif
819 else if( 0 == fossil_strnicmp( zArg, "markdown\0", 9 ) ){
820 rc = 1;
821 }
822 if( g.thTrace ){
823
--- src/vfile.c
+++ src/vfile.c
@@ -187,12 +187,14 @@
187187
while( db_step(&q)==SQLITE_ROW ){
188188
int id, rid, isDeleted;
189189
const char *zName;
190190
int chnged = 0;
191191
int oldChnged;
192
+#ifndef _WIN32
192193
int origPerm;
193194
int currentPerm;
195
+#endif
194196
i64 oldMtime;
195197
i64 currentMtime;
196198
i64 origSize;
197199
i64 currentSize;
198200
@@ -203,12 +205,14 @@
203205
oldChnged = chnged = db_column_int(&q, 4);
204206
oldMtime = db_column_int64(&q, 7);
205207
origSize = db_column_int64(&q, 6);
206208
currentSize = file_wd_size(zName);
207209
currentMtime = file_wd_mtime(0);
210
+#ifndef _WIN32
208211
origPerm = db_column_int(&q, 8);
209212
currentPerm = file_wd_perm(zName);
213
+#endif
210214
if( chnged==0 && (isDeleted || rid==0) ){
211215
/* "fossil rm" or "fossil add" always change the file */
212216
chnged = 1;
213217
}else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
214218
if( cksigFlags & CKSIG_ENOTFILE ){
215219
--- src/vfile.c
+++ src/vfile.c
@@ -187,12 +187,14 @@
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
@@ -203,12 +205,14 @@
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 ){
215
--- src/vfile.c
+++ src/vfile.c
@@ -187,12 +187,14 @@
187 while( db_step(&q)==SQLITE_ROW ){
188 int id, rid, isDeleted;
189 const char *zName;
190 int chnged = 0;
191 int oldChnged;
192 #ifndef _WIN32
193 int origPerm;
194 int currentPerm;
195 #endif
196 i64 oldMtime;
197 i64 currentMtime;
198 i64 origSize;
199 i64 currentSize;
200
@@ -203,12 +205,14 @@
205 oldChnged = chnged = db_column_int(&q, 4);
206 oldMtime = db_column_int64(&q, 7);
207 origSize = db_column_int64(&q, 6);
208 currentSize = file_wd_size(zName);
209 currentMtime = file_wd_mtime(0);
210 #ifndef _WIN32
211 origPerm = db_column_int(&q, 8);
212 currentPerm = file_wd_perm(zName);
213 #endif
214 if( chnged==0 && (isDeleted || rid==0) ){
215 /* "fossil rm" or "fossil add" always change the file */
216 chnged = 1;
217 }else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
218 if( cksigFlags & CKSIG_ENOTFILE ){
219
+162 -86
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122122
static int is_sandbox(const char *zPagename){
123123
return fossil_stricmp(zPagename,"sandbox")==0 ||
124124
fossil_stricmp(zPagename,"sand box")==0;
125125
}
126126
127
+/*
128
+** Formal, common and short names for the various wiki styles.
129
+*/
130
+static const char *const azStyles[] = {
131
+ "text/x-fossil-wiki", "Fossil Wiki", "wiki",
132
+ "text/x-markdown", "Markdown", "markdown",
133
+ "text/plain", "Plain Text", "plain"
134
+};
135
+
127136
/*
128137
** Only allow certain mimetypes through.
129138
** All others become "text/x-fossil-wiki"
130139
*/
131140
const char *wiki_filter_mimetypes(const char *zMimetype){
132
- if( zMimetype!=0 &&
133
- ( fossil_strcmp(zMimetype, "text/x-markdown")==0
134
- || fossil_strcmp(zMimetype, "text/plain")==0 )
135
- ){
136
- return zMimetype;
141
+ if( zMimetype!=0 ){
142
+ int i;
143
+ for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
144
+ if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){
145
+ return azStyles[i];
146
+ }
147
+ }
148
+ if( fossil_strcmp(zMimetype, "text/x-markdown")==0
149
+ || fossil_strcmp(zMimetype, "text/plain")==0 ){
150
+ return zMimetype;
151
+ }
137152
}
138153
return "text/x-fossil-wiki";
139154
}
140155
141156
/*
@@ -412,27 +427,18 @@
412427
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
413428
db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
414429
manifest_crosslink(nrid, pWiki, MC_NONE);
415430
}
416431
417
-/*
418
-** Formal names and common names for the various wiki styles.
419
-*/
420
-static const char *const azStyles[] = {
421
- "text/x-fossil-wiki", "Fossil Wiki",
422
- "text/x-markdown", "Markdown",
423
- "text/plain", "Plain Text"
424
-};
425
-
426432
/*
427433
** Output a selection box from which the user can select the
428434
** wiki mimetype.
429435
*/
430436
void mimetype_option_menu(const char *zMimetype){
431437
unsigned i;
432438
@ <select name="mimetype" size="1">
433
- for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){
439
+ for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
434440
if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
435441
@ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
436442
}else{
437443
@ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
438444
}
@@ -1068,47 +1074,26 @@
10681074
style_footer();
10691075
}
10701076
10711077
/*
10721078
** Add a new wiki page to the repository. The page name is
1073
-** given by the zPageName parameter. isNew must be true to create
1074
-** a new page. If no previous page with the name zPageName exists
1075
-** and isNew is false, then this routine throws an error.
1079
+** given by the zPageName parameter. rid must be zero to create
1080
+** a new page otherwise the page identified by rid is updated.
10761081
**
10771082
** The content of the new page is given by the blob pContent.
10781083
**
10791084
** zMimeType specifies the N-card for the wiki page. If it is 0,
10801085
** empty, or "text/x-fossil-wiki" (the default format) then it is
10811086
** ignored.
10821087
*/
1083
-int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1088
+int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
10841089
const char *zMimeType, int localUser){
10851090
Blob wiki; /* Wiki page content */
10861091
Blob cksum; /* wiki checksum */
1087
- int rid; /* artifact ID of parent page */
10881092
char *zDate; /* timestamp */
10891093
char *zUuid; /* uuid for rid */
10901094
1091
- rid = db_int(0,
1092
- "SELECT x.rid FROM tag t, tagxref x"
1093
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094
- " ORDER BY x.mtime DESC LIMIT 1",
1095
- zPageName
1096
- );
1097
- if( rid==0 && !isNew ){
1098
-#ifdef FOSSIL_ENABLE_JSON
1099
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100
-#endif
1101
- fossil_fatal("no such wiki page: %s", zPageName);
1102
- }
1103
- if( rid!=0 && isNew ){
1104
-#ifdef FOSSIL_ENABLE_JSON
1105
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106
-#endif
1107
- fossil_fatal("wiki page %s already exists", zPageName);
1108
- }
1109
-
11101095
blob_zero(&wiki);
11111096
zDate = date_in_standard_format("now");
11121097
blob_appendf(&wiki, "D %s\n", zDate);
11131098
free(zDate);
11141099
blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
11331118
db_begin_transaction();
11341119
wiki_put(&wiki, 0, wiki_need_moderation(localUser));
11351120
db_end_transaction(0);
11361121
return 1;
11371122
}
1123
+
1124
+/*
1125
+** Determine the rid for a tech note given either its id or its
1126
+** timestamp. Returns 0 if there is no such item and -1 if the details
1127
+** are ambiguous and could refer to multiple items.
1128
+*/
1129
+int wiki_technote_to_rid(const char *zETime) {
1130
+ int rid=0; /* Artifact ID of the tech note */
1131
+ int nETime = strlen(zETime);
1132
+ Stmt q;
1133
+ if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){
1134
+ char zUuid[UUID_SIZE+1];
1135
+ memcpy(zUuid, zETime, nETime+1);
1136
+ canonical16(zUuid, nETime);
1137
+ db_prepare(&q,
1138
+ "SELECT e.objid"
1139
+ " FROM event e, tag t"
1140
+ " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid"
1141
+ " AND t.tagname GLOB 'event-%q*'",
1142
+ zUuid
1143
+ );
1144
+ if( db_step(&q)==SQLITE_ROW ){
1145
+ rid = db_column_int(&q, 0);
1146
+ if( db_step(&q)==SQLITE_ROW ) rid = -1;
1147
+ }
1148
+ db_finalize(&q);
1149
+ }
1150
+ if (!rid) {
1151
+ if (strlen(zETime)>4) {
1152
+ rid = db_int(0, "SELECT objid"
1153
+ " FROM event"
1154
+ " WHERE datetime(mtime)=datetime('%q')"
1155
+ " AND type='e'"
1156
+ " AND tagid IS NOT NULL"
1157
+ " ORDER BY objid DESC LIMIT 1",
1158
+ zETime);
1159
+ }
1160
+ }
1161
+ return rid;
1162
+}
11381163
11391164
/*
11401165
** COMMAND: wiki*
11411166
**
11421167
** Usage: %fossil wiki (export|create|commit|list) WikiName
11431168
**
11441169
** Run various subcommands to work with wiki entries or tech notes.
11451170
**
1146
-** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ]
1171
+** %fossil wiki export PAGENAME ?FILE?
1172
+** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
11471173
**
1148
-** Sends the latest version of either the PAGENAME wiki entry
1149
-** or the DATETIME tech note to the given file or standard
1150
-** output. One of PAGENAME or DATETIME must be specified.
1174
+** Sends the latest version of either a wiki page or of a tech note
1175
+** to the given file or standard output.
1176
+** If PAGENAME is provided, the wiki page will be output. For
1177
+** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1178
+** DATETIME is used, the most recently modified tech note with that
1179
+** DATETIME will be sent.
11511180
**
11521181
** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
11531182
**
11541183
** Create a new or commit changes to an existing wiki page or
1155
-** technote from FILE or from standard input.
1184
+** technote from FILE or from standard input. PAGENAME is the
1185
+** name of the wiki entry or the timeline comment of the
1186
+** technote.
11561187
**
11571188
** Options:
1158
-** -M|--mimetype TEXT-FORMAT The mimetype of the update defaulting
1159
-** to the type used by the previous version
1160
-** of the page or text/x-fossil-wiki.
1161
-** -t|--technote DATETIME Specifies the timestamp of the technote
1162
-** to be created or updated.
1189
+** -M|--mimetype TEXT-FORMAT The mime type of the update.
1190
+** Defaults to the type used by
1191
+** the previous version of the
1192
+** page, or text/x-fossil-wiki.
1193
+** Valid values are: text/x-fossil-wiki,
1194
+** text/markdown and text/plain. fossil,
1195
+** markdown or plain can be specified as
1196
+** synonyms of these values.
1197
+** -t|--technote DATETIME Specifies the timestamp of
1198
+** the technote to be created or
1199
+** updated. When updating a tech note
1200
+** the most recently modified tech note
1201
+** with the specified timestamp will be
1202
+** updated.
1203
+** -t|--technote TECHNOTE-ID Specifies the technote to be
1204
+** updated by its technote id.
11631205
** --technote-tags TAGS The set of tags for a technote.
1164
-** --technote-bgcolor COLOR The color used for the technote on the
1165
-** timeline.
1206
+** --technote-bgcolor COLOR The color used for the technote
1207
+** on the timeline.
11661208
**
1167
-** %fossil wiki list ?--technote?
1168
-** %fossil wiki ls ?--technote?
1209
+** %fossil wiki list ?OPTIONS?
1210
+** %fossil wiki ls ?OPTIONS?
11691211
**
11701212
** Lists all wiki entries, one per line, ordered
1171
-** case-insensitively by name. The --technote flag
1172
-** specifies that technotes will be listed instead of
1173
-** the wiki entries, which will be listed in order
1174
-** timestamp.
1213
+** case-insensitively by name.
1214
+**
1215
+** Options:
1216
+** -t|--technote Technotes will be listed instead of
1217
+** pages. The technotes will be in order
1218
+** of timestamp with the most recent
1219
+** first.
1220
+** -s|--show-technote-ids The id of the tech note will be listed
1221
+** along side the timestamp. The tech note
1222
+** id will be the first word on each line.
1223
+** This option only applies if the
1224
+** --technote option is also specified.
11751225
**
11761226
*/
11771227
void wiki_cmd(void){
11781228
int n;
11791229
db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
12131263
fossil_fatal("wiki page [%s] not found",zPageName);
12141264
}
12151265
zFile = (g.argc==4) ? "-" : g.argv[4];
12161266
}else{
12171267
if( (g.argc!=3) && (g.argc!=4) ){
1218
- usage("export ?FILE? --technote DATETIME");
1268
+ usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
12191269
}
1220
- rid = db_int(0, "SELECT objid FROM event"
1221
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1222
- " ORDER BY mtime DESC LIMIT 1",
1223
- zETime
1224
- );
1270
+ rid = wiki_technote_to_rid(zETime);
1271
+ if (rid == -1) {
1272
+ fossil_fatal("ambiguous tech note id: %s", zETime);
1273
+ }
12251274
if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
12261275
zBody = pWiki->zWiki;
12271276
}
12281277
if( zBody==0 ){
1229
- fossil_fatal("technote not found");
1278
+ fossil_fatal("technote [%s] not found",zETime);
12301279
}
12311280
zFile = (g.argc==3) ? "-" : g.argv[3];
12321281
}
12331282
for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
12341283
zBody[i] = 0;
@@ -1270,43 +1319,58 @@
12701319
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
12711320
&& (pWiki->zMimetype && *pWiki->zMimetype)){
12721321
zMimeType = pWiki->zMimetype;
12731322
}
12741323
}else{
1275
- rid = db_int(0, "SELECT objid FROM event"
1276
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1277
- " ORDER BY mtime DESC LIMIT 1",
1278
- zPageName
1279
- );
1324
+ rid = wiki_technote_to_rid(zETime);
12801325
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
12811326
&& (pWiki->zMimetype && *pWiki->zMimetype)){
12821327
zMimeType = pWiki->zMimetype;
12831328
}
12841329
}
1330
+ }else{
1331
+ zMimeType = wiki_filter_mimetypes(zMimeType);
1332
+ }
1333
+ if( g.argv[2][1]=='r' && rid>0 ){
1334
+ if ( !zETime ){
1335
+ fossil_fatal("wiki page %s already exists", zPageName);
1336
+ }else{
1337
+ /* Creating a tech note with same timestamp is permitted
1338
+ and should create a new tech note */
1339
+ rid = 0;
1340
+ }
1341
+ }else if( g.argv[2][1]=='o' && rid == 0 ){
1342
+ if ( !zETime ){
1343
+ fossil_fatal("no such wiki page: %s", zPageName);
1344
+ }else{
1345
+ fossil_fatal("no such tech note: %s", zETime);
1346
+ }
12851347
}
1348
+
12861349
if( !zETime ){
1350
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
12871351
if( g.argv[2][1]=='r' ){
1288
- wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
12891352
fossil_print("Created new wiki page %s.\n", zPageName);
12901353
}else{
1291
- wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
12921354
fossil_print("Updated wiki page %s.\n", zPageName);
12931355
}
12941356
}else{
1295
- char *zMETime; /* Normalized, mutable version of zETime */
1296
- zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1297
- zETime);
1298
- if( g.argv[2][1]=='r' ){
1299
- event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1300
- zTags, zClr);
1301
- fossil_print("Created new tech note %s.\n", zMETime);
1302
- }else{
1303
- event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1304
- zTags, zClr);
1305
- fossil_print("Updated tech note %s.\n", zMETime);
1306
- }
1307
- free(zMETime);
1357
+ if( rid != -1 ){
1358
+ char *zMETime; /* Normalized, mutable version of zETime */
1359
+ zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1360
+ zETime);
1361
+ event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1362
+ zTags, zClr);
1363
+ if( g.argv[2][1]=='r' ){
1364
+ fossil_print("Created new tech note %s.\n", zMETime);
1365
+ }else{
1366
+ fossil_print("Updated tech note %s.\n", zMETime);
1367
+ }
1368
+ free(zMETime);
1369
+ }else{
1370
+ fossil_fatal("ambiguous tech note id: %s", zETime);
1371
+ }
13081372
}
13091373
manifest_destroy(pWiki);
13101374
blob_reset(&content);
13111375
}else if( strncmp(g.argv[2],"delete",n)==0 ){
13121376
if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
13141378
}
13151379
fossil_fatal("delete not yet implemented.");
13161380
}else if(( strncmp(g.argv[2],"list",n)==0 )
13171381
|| ( strncmp(g.argv[2],"ls",n)==0 )){
13181382
Stmt q;
1383
+ int showIds = 0;
1384
+
13191385
if ( !find_option("technote","t",0) ){
13201386
db_prepare(&q,
13211387
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
13221388
" ORDER BY lower(tagname) /*sort*/"
13231389
);
13241390
}else{
1391
+ showIds = find_option("show-technote-ids","s",0)!=0;
13251392
db_prepare(&q,
1326
- "SELECT datetime(mtime) FROM event WHERE type='e'"
1327
- " ORDER BY mtime /*sort*/"
1393
+ "SELECT datetime(e.mtime), substr(t.tagname,7)"
1394
+ " FROM event e, tag t"
1395
+ " WHERE e.type='e'"
1396
+ " AND e.tagid IS NOT NULL"
1397
+ " AND t.tagid=e.tagid"
1398
+ " ORDER BY e.mtime DESC /*sort*/"
13281399
);
13291400
}
1401
+
13301402
while( db_step(&q)==SQLITE_ROW ){
13311403
const char *zName = db_column_text(&q, 0);
1404
+ if (showIds) {
1405
+ const char *zUuid = db_column_text(&q, 1);
1406
+ fossil_print("%s ",zUuid);
1407
+ }
13321408
fossil_print( "%s\n",zName);
13331409
}
13341410
db_finalize(&q);
13351411
}else{
13361412
goto wiki_cmd_usage;
13371413
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122 static int is_sandbox(const char *zPagename){
123 return fossil_stricmp(zPagename,"sandbox")==0 ||
124 fossil_stricmp(zPagename,"sand box")==0;
125 }
126
 
 
 
 
 
 
 
 
 
127 /*
128 ** Only allow certain mimetypes through.
129 ** All others become "text/x-fossil-wiki"
130 */
131 const char *wiki_filter_mimetypes(const char *zMimetype){
132 if( zMimetype!=0 &&
133 ( fossil_strcmp(zMimetype, "text/x-markdown")==0
134 || fossil_strcmp(zMimetype, "text/plain")==0 )
135 ){
136 return zMimetype;
 
 
 
 
 
 
137 }
138 return "text/x-fossil-wiki";
139 }
140
141 /*
@@ -412,27 +427,18 @@
412 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
413 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
414 manifest_crosslink(nrid, pWiki, MC_NONE);
415 }
416
417 /*
418 ** Formal names and common names for the various wiki styles.
419 */
420 static const char *const azStyles[] = {
421 "text/x-fossil-wiki", "Fossil Wiki",
422 "text/x-markdown", "Markdown",
423 "text/plain", "Plain Text"
424 };
425
426 /*
427 ** Output a selection box from which the user can select the
428 ** wiki mimetype.
429 */
430 void mimetype_option_menu(const char *zMimetype){
431 unsigned i;
432 @ <select name="mimetype" size="1">
433 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){
434 if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
435 @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
436 }else{
437 @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
438 }
@@ -1068,47 +1074,26 @@
1068 style_footer();
1069 }
1070
1071 /*
1072 ** Add a new wiki page to the repository. The page name is
1073 ** given by the zPageName parameter. isNew must be true to create
1074 ** a new page. If no previous page with the name zPageName exists
1075 ** and isNew is false, then this routine throws an error.
1076 **
1077 ** The content of the new page is given by the blob pContent.
1078 **
1079 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1080 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1081 ** ignored.
1082 */
1083 int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1084 const char *zMimeType, int localUser){
1085 Blob wiki; /* Wiki page content */
1086 Blob cksum; /* wiki checksum */
1087 int rid; /* artifact ID of parent page */
1088 char *zDate; /* timestamp */
1089 char *zUuid; /* uuid for rid */
1090
1091 rid = db_int(0,
1092 "SELECT x.rid FROM tag t, tagxref x"
1093 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094 " ORDER BY x.mtime DESC LIMIT 1",
1095 zPageName
1096 );
1097 if( rid==0 && !isNew ){
1098 #ifdef FOSSIL_ENABLE_JSON
1099 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100 #endif
1101 fossil_fatal("no such wiki page: %s", zPageName);
1102 }
1103 if( rid!=0 && isNew ){
1104 #ifdef FOSSIL_ENABLE_JSON
1105 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106 #endif
1107 fossil_fatal("wiki page %s already exists", zPageName);
1108 }
1109
1110 blob_zero(&wiki);
1111 zDate = date_in_standard_format("now");
1112 blob_appendf(&wiki, "D %s\n", zDate);
1113 free(zDate);
1114 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
1133 db_begin_transaction();
1134 wiki_put(&wiki, 0, wiki_need_moderation(localUser));
1135 db_end_transaction(0);
1136 return 1;
1137 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1138
1139 /*
1140 ** COMMAND: wiki*
1141 **
1142 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1143 **
1144 ** Run various subcommands to work with wiki entries or tech notes.
1145 **
1146 ** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ]
 
1147 **
1148 ** Sends the latest version of either the PAGENAME wiki entry
1149 ** or the DATETIME tech note to the given file or standard
1150 ** output. One of PAGENAME or DATETIME must be specified.
 
 
 
1151 **
1152 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1153 **
1154 ** Create a new or commit changes to an existing wiki page or
1155 ** technote from FILE or from standard input.
 
 
1156 **
1157 ** Options:
1158 ** -M|--mimetype TEXT-FORMAT The mimetype of the update defaulting
1159 ** to the type used by the previous version
1160 ** of the page or text/x-fossil-wiki.
1161 ** -t|--technote DATETIME Specifies the timestamp of the technote
1162 ** to be created or updated.
 
 
 
 
 
 
 
 
 
 
 
1163 ** --technote-tags TAGS The set of tags for a technote.
1164 ** --technote-bgcolor COLOR The color used for the technote on the
1165 ** timeline.
1166 **
1167 ** %fossil wiki list ?--technote?
1168 ** %fossil wiki ls ?--technote?
1169 **
1170 ** Lists all wiki entries, one per line, ordered
1171 ** case-insensitively by name. The --technote flag
1172 ** specifies that technotes will be listed instead of
1173 ** the wiki entries, which will be listed in order
1174 ** timestamp.
 
 
 
 
 
 
 
 
1175 **
1176 */
1177 void wiki_cmd(void){
1178 int n;
1179 db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
1213 fossil_fatal("wiki page [%s] not found",zPageName);
1214 }
1215 zFile = (g.argc==4) ? "-" : g.argv[4];
1216 }else{
1217 if( (g.argc!=3) && (g.argc!=4) ){
1218 usage("export ?FILE? --technote DATETIME");
1219 }
1220 rid = db_int(0, "SELECT objid FROM event"
1221 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1222 " ORDER BY mtime DESC LIMIT 1",
1223 zETime
1224 );
1225 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1226 zBody = pWiki->zWiki;
1227 }
1228 if( zBody==0 ){
1229 fossil_fatal("technote not found");
1230 }
1231 zFile = (g.argc==3) ? "-" : g.argv[3];
1232 }
1233 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1234 zBody[i] = 0;
@@ -1270,43 +1319,58 @@
1270 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1271 && (pWiki->zMimetype && *pWiki->zMimetype)){
1272 zMimeType = pWiki->zMimetype;
1273 }
1274 }else{
1275 rid = db_int(0, "SELECT objid FROM event"
1276 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1277 " ORDER BY mtime DESC LIMIT 1",
1278 zPageName
1279 );
1280 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1281 && (pWiki->zMimetype && *pWiki->zMimetype)){
1282 zMimeType = pWiki->zMimetype;
1283 }
1284 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1285 }
 
1286 if( !zETime ){
 
1287 if( g.argv[2][1]=='r' ){
1288 wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
1289 fossil_print("Created new wiki page %s.\n", zPageName);
1290 }else{
1291 wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
1292 fossil_print("Updated wiki page %s.\n", zPageName);
1293 }
1294 }else{
1295 char *zMETime; /* Normalized, mutable version of zETime */
1296 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1297 zETime);
1298 if( g.argv[2][1]=='r' ){
1299 event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1300 zTags, zClr);
1301 fossil_print("Created new tech note %s.\n", zMETime);
1302 }else{
1303 event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1304 zTags, zClr);
1305 fossil_print("Updated tech note %s.\n", zMETime);
1306 }
1307 free(zMETime);
 
 
1308 }
1309 manifest_destroy(pWiki);
1310 blob_reset(&content);
1311 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1312 if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
1314 }
1315 fossil_fatal("delete not yet implemented.");
1316 }else if(( strncmp(g.argv[2],"list",n)==0 )
1317 || ( strncmp(g.argv[2],"ls",n)==0 )){
1318 Stmt q;
 
 
1319 if ( !find_option("technote","t",0) ){
1320 db_prepare(&q,
1321 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1322 " ORDER BY lower(tagname) /*sort*/"
1323 );
1324 }else{
 
1325 db_prepare(&q,
1326 "SELECT datetime(mtime) FROM event WHERE type='e'"
1327 " ORDER BY mtime /*sort*/"
 
 
 
 
1328 );
1329 }
 
1330 while( db_step(&q)==SQLITE_ROW ){
1331 const char *zName = db_column_text(&q, 0);
 
 
 
 
1332 fossil_print( "%s\n",zName);
1333 }
1334 db_finalize(&q);
1335 }else{
1336 goto wiki_cmd_usage;
1337
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122 static int is_sandbox(const char *zPagename){
123 return fossil_stricmp(zPagename,"sandbox")==0 ||
124 fossil_stricmp(zPagename,"sand box")==0;
125 }
126
127 /*
128 ** Formal, common and short names for the various wiki styles.
129 */
130 static const char *const azStyles[] = {
131 "text/x-fossil-wiki", "Fossil Wiki", "wiki",
132 "text/x-markdown", "Markdown", "markdown",
133 "text/plain", "Plain Text", "plain"
134 };
135
136 /*
137 ** Only allow certain mimetypes through.
138 ** All others become "text/x-fossil-wiki"
139 */
140 const char *wiki_filter_mimetypes(const char *zMimetype){
141 if( zMimetype!=0 ){
142 int i;
143 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
144 if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){
145 return azStyles[i];
146 }
147 }
148 if( fossil_strcmp(zMimetype, "text/x-markdown")==0
149 || fossil_strcmp(zMimetype, "text/plain")==0 ){
150 return zMimetype;
151 }
152 }
153 return "text/x-fossil-wiki";
154 }
155
156 /*
@@ -412,27 +427,18 @@
427 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
428 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
429 manifest_crosslink(nrid, pWiki, MC_NONE);
430 }
431
 
 
 
 
 
 
 
 
 
432 /*
433 ** Output a selection box from which the user can select the
434 ** wiki mimetype.
435 */
436 void mimetype_option_menu(const char *zMimetype){
437 unsigned i;
438 @ <select name="mimetype" size="1">
439 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
440 if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
441 @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
442 }else{
443 @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
444 }
@@ -1068,47 +1074,26 @@
1074 style_footer();
1075 }
1076
1077 /*
1078 ** Add a new wiki page to the repository. The page name is
1079 ** given by the zPageName parameter. rid must be zero to create
1080 ** a new page otherwise the page identified by rid is updated.
 
1081 **
1082 ** The content of the new page is given by the blob pContent.
1083 **
1084 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1085 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1086 ** ignored.
1087 */
1088 int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
1089 const char *zMimeType, int localUser){
1090 Blob wiki; /* Wiki page content */
1091 Blob cksum; /* wiki checksum */
 
1092 char *zDate; /* timestamp */
1093 char *zUuid; /* uuid for rid */
1094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1095 blob_zero(&wiki);
1096 zDate = date_in_standard_format("now");
1097 blob_appendf(&wiki, "D %s\n", zDate);
1098 free(zDate);
1099 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
1118 db_begin_transaction();
1119 wiki_put(&wiki, 0, wiki_need_moderation(localUser));
1120 db_end_transaction(0);
1121 return 1;
1122 }
1123
1124 /*
1125 ** Determine the rid for a tech note given either its id or its
1126 ** timestamp. Returns 0 if there is no such item and -1 if the details
1127 ** are ambiguous and could refer to multiple items.
1128 */
1129 int wiki_technote_to_rid(const char *zETime) {
1130 int rid=0; /* Artifact ID of the tech note */
1131 int nETime = strlen(zETime);
1132 Stmt q;
1133 if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){
1134 char zUuid[UUID_SIZE+1];
1135 memcpy(zUuid, zETime, nETime+1);
1136 canonical16(zUuid, nETime);
1137 db_prepare(&q,
1138 "SELECT e.objid"
1139 " FROM event e, tag t"
1140 " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid"
1141 " AND t.tagname GLOB 'event-%q*'",
1142 zUuid
1143 );
1144 if( db_step(&q)==SQLITE_ROW ){
1145 rid = db_column_int(&q, 0);
1146 if( db_step(&q)==SQLITE_ROW ) rid = -1;
1147 }
1148 db_finalize(&q);
1149 }
1150 if (!rid) {
1151 if (strlen(zETime)>4) {
1152 rid = db_int(0, "SELECT objid"
1153 " FROM event"
1154 " WHERE datetime(mtime)=datetime('%q')"
1155 " AND type='e'"
1156 " AND tagid IS NOT NULL"
1157 " ORDER BY objid DESC LIMIT 1",
1158 zETime);
1159 }
1160 }
1161 return rid;
1162 }
1163
1164 /*
1165 ** COMMAND: wiki*
1166 **
1167 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1168 **
1169 ** Run various subcommands to work with wiki entries or tech notes.
1170 **
1171 ** %fossil wiki export PAGENAME ?FILE?
1172 ** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
1173 **
1174 ** Sends the latest version of either a wiki page or of a tech note
1175 ** to the given file or standard output.
1176 ** If PAGENAME is provided, the wiki page will be output. For
1177 ** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1178 ** DATETIME is used, the most recently modified tech note with that
1179 ** DATETIME will be sent.
1180 **
1181 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1182 **
1183 ** Create a new or commit changes to an existing wiki page or
1184 ** technote from FILE or from standard input. PAGENAME is the
1185 ** name of the wiki entry or the timeline comment of the
1186 ** technote.
1187 **
1188 ** Options:
1189 ** -M|--mimetype TEXT-FORMAT The mime type of the update.
1190 ** Defaults to the type used by
1191 ** the previous version of the
1192 ** page, or text/x-fossil-wiki.
1193 ** Valid values are: text/x-fossil-wiki,
1194 ** text/markdown and text/plain. fossil,
1195 ** markdown or plain can be specified as
1196 ** synonyms of these values.
1197 ** -t|--technote DATETIME Specifies the timestamp of
1198 ** the technote to be created or
1199 ** updated. When updating a tech note
1200 ** the most recently modified tech note
1201 ** with the specified timestamp will be
1202 ** updated.
1203 ** -t|--technote TECHNOTE-ID Specifies the technote to be
1204 ** updated by its technote id.
1205 ** --technote-tags TAGS The set of tags for a technote.
1206 ** --technote-bgcolor COLOR The color used for the technote
1207 ** on the timeline.
1208 **
1209 ** %fossil wiki list ?OPTIONS?
1210 ** %fossil wiki ls ?OPTIONS?
1211 **
1212 ** Lists all wiki entries, one per line, ordered
1213 ** case-insensitively by name.
1214 **
1215 ** Options:
1216 ** -t|--technote Technotes will be listed instead of
1217 ** pages. The technotes will be in order
1218 ** of timestamp with the most recent
1219 ** first.
1220 ** -s|--show-technote-ids The id of the tech note will be listed
1221 ** along side the timestamp. The tech note
1222 ** id will be the first word on each line.
1223 ** This option only applies if the
1224 ** --technote option is also specified.
1225 **
1226 */
1227 void wiki_cmd(void){
1228 int n;
1229 db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
1263 fossil_fatal("wiki page [%s] not found",zPageName);
1264 }
1265 zFile = (g.argc==4) ? "-" : g.argv[4];
1266 }else{
1267 if( (g.argc!=3) && (g.argc!=4) ){
1268 usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
1269 }
1270 rid = wiki_technote_to_rid(zETime);
1271 if (rid == -1) {
1272 fossil_fatal("ambiguous tech note id: %s", zETime);
1273 }
 
1274 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1275 zBody = pWiki->zWiki;
1276 }
1277 if( zBody==0 ){
1278 fossil_fatal("technote [%s] not found",zETime);
1279 }
1280 zFile = (g.argc==3) ? "-" : g.argv[3];
1281 }
1282 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1283 zBody[i] = 0;
@@ -1270,43 +1319,58 @@
1319 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1320 && (pWiki->zMimetype && *pWiki->zMimetype)){
1321 zMimeType = pWiki->zMimetype;
1322 }
1323 }else{
1324 rid = wiki_technote_to_rid(zETime);
 
 
 
 
1325 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1326 && (pWiki->zMimetype && *pWiki->zMimetype)){
1327 zMimeType = pWiki->zMimetype;
1328 }
1329 }
1330 }else{
1331 zMimeType = wiki_filter_mimetypes(zMimeType);
1332 }
1333 if( g.argv[2][1]=='r' && rid>0 ){
1334 if ( !zETime ){
1335 fossil_fatal("wiki page %s already exists", zPageName);
1336 }else{
1337 /* Creating a tech note with same timestamp is permitted
1338 and should create a new tech note */
1339 rid = 0;
1340 }
1341 }else if( g.argv[2][1]=='o' && rid == 0 ){
1342 if ( !zETime ){
1343 fossil_fatal("no such wiki page: %s", zPageName);
1344 }else{
1345 fossil_fatal("no such tech note: %s", zETime);
1346 }
1347 }
1348
1349 if( !zETime ){
1350 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
1351 if( g.argv[2][1]=='r' ){
 
1352 fossil_print("Created new wiki page %s.\n", zPageName);
1353 }else{
 
1354 fossil_print("Updated wiki page %s.\n", zPageName);
1355 }
1356 }else{
1357 if( rid != -1 ){
1358 char *zMETime; /* Normalized, mutable version of zETime */
1359 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1360 zETime);
1361 event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1362 zTags, zClr);
1363 if( g.argv[2][1]=='r' ){
1364 fossil_print("Created new tech note %s.\n", zMETime);
1365 }else{
1366 fossil_print("Updated tech note %s.\n", zMETime);
1367 }
1368 free(zMETime);
1369 }else{
1370 fossil_fatal("ambiguous tech note id: %s", zETime);
1371 }
1372 }
1373 manifest_destroy(pWiki);
1374 blob_reset(&content);
1375 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1376 if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
1378 }
1379 fossil_fatal("delete not yet implemented.");
1380 }else if(( strncmp(g.argv[2],"list",n)==0 )
1381 || ( strncmp(g.argv[2],"ls",n)==0 )){
1382 Stmt q;
1383 int showIds = 0;
1384
1385 if ( !find_option("technote","t",0) ){
1386 db_prepare(&q,
1387 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1388 " ORDER BY lower(tagname) /*sort*/"
1389 );
1390 }else{
1391 showIds = find_option("show-technote-ids","s",0)!=0;
1392 db_prepare(&q,
1393 "SELECT datetime(e.mtime), substr(t.tagname,7)"
1394 " FROM event e, tag t"
1395 " WHERE e.type='e'"
1396 " AND e.tagid IS NOT NULL"
1397 " AND t.tagid=e.tagid"
1398 " ORDER BY e.mtime DESC /*sort*/"
1399 );
1400 }
1401
1402 while( db_step(&q)==SQLITE_ROW ){
1403 const char *zName = db_column_text(&q, 0);
1404 if (showIds) {
1405 const char *zUuid = db_column_text(&q, 1);
1406 fossil_print("%s ",zUuid);
1407 }
1408 fossil_print( "%s\n",zName);
1409 }
1410 db_finalize(&q);
1411 }else{
1412 goto wiki_cmd_usage;
1413
+162 -86
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122122
static int is_sandbox(const char *zPagename){
123123
return fossil_stricmp(zPagename,"sandbox")==0 ||
124124
fossil_stricmp(zPagename,"sand box")==0;
125125
}
126126
127
+/*
128
+** Formal, common and short names for the various wiki styles.
129
+*/
130
+static const char *const azStyles[] = {
131
+ "text/x-fossil-wiki", "Fossil Wiki", "wiki",
132
+ "text/x-markdown", "Markdown", "markdown",
133
+ "text/plain", "Plain Text", "plain"
134
+};
135
+
127136
/*
128137
** Only allow certain mimetypes through.
129138
** All others become "text/x-fossil-wiki"
130139
*/
131140
const char *wiki_filter_mimetypes(const char *zMimetype){
132
- if( zMimetype!=0 &&
133
- ( fossil_strcmp(zMimetype, "text/x-markdown")==0
134
- || fossil_strcmp(zMimetype, "text/plain")==0 )
135
- ){
136
- return zMimetype;
141
+ if( zMimetype!=0 ){
142
+ int i;
143
+ for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
144
+ if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){
145
+ return azStyles[i];
146
+ }
147
+ }
148
+ if( fossil_strcmp(zMimetype, "text/x-markdown")==0
149
+ || fossil_strcmp(zMimetype, "text/plain")==0 ){
150
+ return zMimetype;
151
+ }
137152
}
138153
return "text/x-fossil-wiki";
139154
}
140155
141156
/*
@@ -412,27 +427,18 @@
412427
db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
413428
db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
414429
manifest_crosslink(nrid, pWiki, MC_NONE);
415430
}
416431
417
-/*
418
-** Formal names and common names for the various wiki styles.
419
-*/
420
-static const char *const azStyles[] = {
421
- "text/x-fossil-wiki", "Fossil Wiki",
422
- "text/x-markdown", "Markdown",
423
- "text/plain", "Plain Text"
424
-};
425
-
426432
/*
427433
** Output a selection box from which the user can select the
428434
** wiki mimetype.
429435
*/
430436
void mimetype_option_menu(const char *zMimetype){
431437
unsigned i;
432438
@ <select name="mimetype" size="1">
433
- for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){
439
+ for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
434440
if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
435441
@ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
436442
}else{
437443
@ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
438444
}
@@ -1068,47 +1074,26 @@
10681074
style_footer();
10691075
}
10701076
10711077
/*
10721078
** Add a new wiki page to the repository. The page name is
1073
-** given by the zPageName parameter. isNew must be true to create
1074
-** a new page. If no previous page with the name zPageName exists
1075
-** and isNew is false, then this routine throws an error.
1079
+** given by the zPageName parameter. rid must be zero to create
1080
+** a new page otherwise the page identified by rid is updated.
10761081
**
10771082
** The content of the new page is given by the blob pContent.
10781083
**
10791084
** zMimeType specifies the N-card for the wiki page. If it is 0,
10801085
** empty, or "text/x-fossil-wiki" (the default format) then it is
10811086
** ignored.
10821087
*/
1083
-int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1088
+int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
10841089
const char *zMimeType, int localUser){
10851090
Blob wiki; /* Wiki page content */
10861091
Blob cksum; /* wiki checksum */
1087
- int rid; /* artifact ID of parent page */
10881092
char *zDate; /* timestamp */
10891093
char *zUuid; /* uuid for rid */
10901094
1091
- rid = db_int(0,
1092
- "SELECT x.rid FROM tag t, tagxref x"
1093
- " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094
- " ORDER BY x.mtime DESC LIMIT 1",
1095
- zPageName
1096
- );
1097
- if( rid==0 && !isNew ){
1098
-#ifdef FOSSIL_ENABLE_JSON
1099
- g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100
-#endif
1101
- fossil_fatal("no such wiki page: %s", zPageName);
1102
- }
1103
- if( rid!=0 && isNew ){
1104
-#ifdef FOSSIL_ENABLE_JSON
1105
- g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106
-#endif
1107
- fossil_fatal("wiki page %s already exists", zPageName);
1108
- }
1109
-
11101095
blob_zero(&wiki);
11111096
zDate = date_in_standard_format("now");
11121097
blob_appendf(&wiki, "D %s\n", zDate);
11131098
free(zDate);
11141099
blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
11331118
db_begin_transaction();
11341119
wiki_put(&wiki, 0, wiki_need_moderation(localUser));
11351120
db_end_transaction(0);
11361121
return 1;
11371122
}
1123
+
1124
+/*
1125
+** Determine the rid for a tech note given either its id or its
1126
+** timestamp. Returns 0 if there is no such item and -1 if the details
1127
+** are ambiguous and could refer to multiple items.
1128
+*/
1129
+int wiki_technote_to_rid(const char *zETime) {
1130
+ int rid=0; /* Artifact ID of the tech note */
1131
+ int nETime = strlen(zETime);
1132
+ Stmt q;
1133
+ if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){
1134
+ char zUuid[UUID_SIZE+1];
1135
+ memcpy(zUuid, zETime, nETime+1);
1136
+ canonical16(zUuid, nETime);
1137
+ db_prepare(&q,
1138
+ "SELECT e.objid"
1139
+ " FROM event e, tag t"
1140
+ " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid"
1141
+ " AND t.tagname GLOB 'event-%q*'",
1142
+ zUuid
1143
+ );
1144
+ if( db_step(&q)==SQLITE_ROW ){
1145
+ rid = db_column_int(&q, 0);
1146
+ if( db_step(&q)==SQLITE_ROW ) rid = -1;
1147
+ }
1148
+ db_finalize(&q);
1149
+ }
1150
+ if (!rid) {
1151
+ if (strlen(zETime)>4) {
1152
+ rid = db_int(0, "SELECT objid"
1153
+ " FROM event"
1154
+ " WHERE datetime(mtime)=datetime('%q')"
1155
+ " AND type='e'"
1156
+ " AND tagid IS NOT NULL"
1157
+ " ORDER BY objid DESC LIMIT 1",
1158
+ zETime);
1159
+ }
1160
+ }
1161
+ return rid;
1162
+}
11381163
11391164
/*
11401165
** COMMAND: wiki*
11411166
**
11421167
** Usage: %fossil wiki (export|create|commit|list) WikiName
11431168
**
11441169
** Run various subcommands to work with wiki entries or tech notes.
11451170
**
1146
-** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ]
1171
+** %fossil wiki export PAGENAME ?FILE?
1172
+** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
11471173
**
1148
-** Sends the latest version of either the PAGENAME wiki entry
1149
-** or the DATETIME tech note to the given file or standard
1150
-** output. One of PAGENAME or DATETIME must be specified.
1174
+** Sends the latest version of either a wiki page or of a tech note
1175
+** to the given file or standard output.
1176
+** If PAGENAME is provided, the wiki page will be output. For
1177
+** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1178
+** DATETIME is used, the most recently modified tech note with that
1179
+** DATETIME will be sent.
11511180
**
11521181
** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
11531182
**
11541183
** Create a new or commit changes to an existing wiki page or
1155
-** technote from FILE or from standard input.
1184
+** technote from FILE or from standard input. PAGENAME is the
1185
+** name of the wiki entry or the timeline comment of the
1186
+** technote.
11561187
**
11571188
** Options:
1158
-** -M|--mimetype TEXT-FORMAT The mimetype of the update defaulting
1159
-** to the type used by the previous version
1160
-** of the page or text/x-fossil-wiki.
1161
-** -t|--technote DATETIME Specifies the timestamp of the technote
1162
-** to be created or updated.
1189
+** -M|--mimetype TEXT-FORMAT The mime type of the update.
1190
+** Defaults to the type used by
1191
+** the previous version of the
1192
+** page, or text/x-fossil-wiki.
1193
+** Valid values are: text/x-fossil-wiki,
1194
+** text/markdown and text/plain. fossil,
1195
+** markdown or plain can be specified as
1196
+** synonyms of these values.
1197
+** -t|--technote DATETIME Specifies the timestamp of
1198
+** the technote to be created or
1199
+** updated. When updating a tech note
1200
+** the most recently modified tech note
1201
+** with the specified timestamp will be
1202
+** updated.
1203
+** -t|--technote TECHNOTE-ID Specifies the technote to be
1204
+** updated by its technote id.
11631205
** --technote-tags TAGS The set of tags for a technote.
1164
-** --technote-bgcolor COLOR The color used for the technote on the
1165
-** timeline.
1206
+** --technote-bgcolor COLOR The color used for the technote
1207
+** on the timeline.
11661208
**
1167
-** %fossil wiki list ?--technote?
1168
-** %fossil wiki ls ?--technote?
1209
+** %fossil wiki list ?OPTIONS?
1210
+** %fossil wiki ls ?OPTIONS?
11691211
**
11701212
** Lists all wiki entries, one per line, ordered
1171
-** case-insensitively by name. The --technote flag
1172
-** specifies that technotes will be listed instead of
1173
-** the wiki entries, which will be listed in order
1174
-** timestamp.
1213
+** case-insensitively by name.
1214
+**
1215
+** Options:
1216
+** -t|--technote Technotes will be listed instead of
1217
+** pages. The technotes will be in order
1218
+** of timestamp with the most recent
1219
+** first.
1220
+** -s|--show-technote-ids The id of the tech note will be listed
1221
+** along side the timestamp. The tech note
1222
+** id will be the first word on each line.
1223
+** This option only applies if the
1224
+** --technote option is also specified.
11751225
**
11761226
*/
11771227
void wiki_cmd(void){
11781228
int n;
11791229
db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
12131263
fossil_fatal("wiki page [%s] not found",zPageName);
12141264
}
12151265
zFile = (g.argc==4) ? "-" : g.argv[4];
12161266
}else{
12171267
if( (g.argc!=3) && (g.argc!=4) ){
1218
- usage("export ?FILE? --technote DATETIME");
1268
+ usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
12191269
}
1220
- rid = db_int(0, "SELECT objid FROM event"
1221
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1222
- " ORDER BY mtime DESC LIMIT 1",
1223
- zETime
1224
- );
1270
+ rid = wiki_technote_to_rid(zETime);
1271
+ if (rid == -1) {
1272
+ fossil_fatal("ambiguous tech note id: %s", zETime);
1273
+ }
12251274
if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
12261275
zBody = pWiki->zWiki;
12271276
}
12281277
if( zBody==0 ){
1229
- fossil_fatal("technote not found");
1278
+ fossil_fatal("technote [%s] not found",zETime);
12301279
}
12311280
zFile = (g.argc==3) ? "-" : g.argv[3];
12321281
}
12331282
for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
12341283
zBody[i] = 0;
@@ -1270,43 +1319,58 @@
12701319
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
12711320
&& (pWiki->zMimetype && *pWiki->zMimetype)){
12721321
zMimeType = pWiki->zMimetype;
12731322
}
12741323
}else{
1275
- rid = db_int(0, "SELECT objid FROM event"
1276
- " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1277
- " ORDER BY mtime DESC LIMIT 1",
1278
- zPageName
1279
- );
1324
+ rid = wiki_technote_to_rid(zETime);
12801325
if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
12811326
&& (pWiki->zMimetype && *pWiki->zMimetype)){
12821327
zMimeType = pWiki->zMimetype;
12831328
}
12841329
}
1330
+ }else{
1331
+ zMimeType = wiki_filter_mimetypes(zMimeType);
1332
+ }
1333
+ if( g.argv[2][1]=='r' && rid>0 ){
1334
+ if ( !zETime ){
1335
+ fossil_fatal("wiki page %s already exists", zPageName);
1336
+ }else{
1337
+ /* Creating a tech note with same timestamp is permitted
1338
+ and should create a new tech note */
1339
+ rid = 0;
1340
+ }
1341
+ }else if( g.argv[2][1]=='o' && rid == 0 ){
1342
+ if ( !zETime ){
1343
+ fossil_fatal("no such wiki page: %s", zPageName);
1344
+ }else{
1345
+ fossil_fatal("no such tech note: %s", zETime);
1346
+ }
12851347
}
1348
+
12861349
if( !zETime ){
1350
+ wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
12871351
if( g.argv[2][1]=='r' ){
1288
- wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
12891352
fossil_print("Created new wiki page %s.\n", zPageName);
12901353
}else{
1291
- wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
12921354
fossil_print("Updated wiki page %s.\n", zPageName);
12931355
}
12941356
}else{
1295
- char *zMETime; /* Normalized, mutable version of zETime */
1296
- zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1297
- zETime);
1298
- if( g.argv[2][1]=='r' ){
1299
- event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1300
- zTags, zClr);
1301
- fossil_print("Created new tech note %s.\n", zMETime);
1302
- }else{
1303
- event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1304
- zTags, zClr);
1305
- fossil_print("Updated tech note %s.\n", zMETime);
1306
- }
1307
- free(zMETime);
1357
+ if( rid != -1 ){
1358
+ char *zMETime; /* Normalized, mutable version of zETime */
1359
+ zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1360
+ zETime);
1361
+ event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1362
+ zTags, zClr);
1363
+ if( g.argv[2][1]=='r' ){
1364
+ fossil_print("Created new tech note %s.\n", zMETime);
1365
+ }else{
1366
+ fossil_print("Updated tech note %s.\n", zMETime);
1367
+ }
1368
+ free(zMETime);
1369
+ }else{
1370
+ fossil_fatal("ambiguous tech note id: %s", zETime);
1371
+ }
13081372
}
13091373
manifest_destroy(pWiki);
13101374
blob_reset(&content);
13111375
}else if( strncmp(g.argv[2],"delete",n)==0 ){
13121376
if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
13141378
}
13151379
fossil_fatal("delete not yet implemented.");
13161380
}else if(( strncmp(g.argv[2],"list",n)==0 )
13171381
|| ( strncmp(g.argv[2],"ls",n)==0 )){
13181382
Stmt q;
1383
+ int showIds = 0;
1384
+
13191385
if ( !find_option("technote","t",0) ){
13201386
db_prepare(&q,
13211387
"SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
13221388
" ORDER BY lower(tagname) /*sort*/"
13231389
);
13241390
}else{
1391
+ showIds = find_option("show-technote-ids","s",0)!=0;
13251392
db_prepare(&q,
1326
- "SELECT datetime(mtime) FROM event WHERE type='e'"
1327
- " ORDER BY mtime /*sort*/"
1393
+ "SELECT datetime(e.mtime), substr(t.tagname,7)"
1394
+ " FROM event e, tag t"
1395
+ " WHERE e.type='e'"
1396
+ " AND e.tagid IS NOT NULL"
1397
+ " AND t.tagid=e.tagid"
1398
+ " ORDER BY e.mtime DESC /*sort*/"
13281399
);
13291400
}
1401
+
13301402
while( db_step(&q)==SQLITE_ROW ){
13311403
const char *zName = db_column_text(&q, 0);
1404
+ if (showIds) {
1405
+ const char *zUuid = db_column_text(&q, 1);
1406
+ fossil_print("%s ",zUuid);
1407
+ }
13321408
fossil_print( "%s\n",zName);
13331409
}
13341410
db_finalize(&q);
13351411
}else{
13361412
goto wiki_cmd_usage;
13371413
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122 static int is_sandbox(const char *zPagename){
123 return fossil_stricmp(zPagename,"sandbox")==0 ||
124 fossil_stricmp(zPagename,"sand box")==0;
125 }
126
 
 
 
 
 
 
 
 
 
127 /*
128 ** Only allow certain mimetypes through.
129 ** All others become "text/x-fossil-wiki"
130 */
131 const char *wiki_filter_mimetypes(const char *zMimetype){
132 if( zMimetype!=0 &&
133 ( fossil_strcmp(zMimetype, "text/x-markdown")==0
134 || fossil_strcmp(zMimetype, "text/plain")==0 )
135 ){
136 return zMimetype;
 
 
 
 
 
 
137 }
138 return "text/x-fossil-wiki";
139 }
140
141 /*
@@ -412,27 +427,18 @@
412 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
413 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
414 manifest_crosslink(nrid, pWiki, MC_NONE);
415 }
416
417 /*
418 ** Formal names and common names for the various wiki styles.
419 */
420 static const char *const azStyles[] = {
421 "text/x-fossil-wiki", "Fossil Wiki",
422 "text/x-markdown", "Markdown",
423 "text/plain", "Plain Text"
424 };
425
426 /*
427 ** Output a selection box from which the user can select the
428 ** wiki mimetype.
429 */
430 void mimetype_option_menu(const char *zMimetype){
431 unsigned i;
432 @ <select name="mimetype" size="1">
433 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=2){
434 if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
435 @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
436 }else{
437 @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
438 }
@@ -1068,47 +1074,26 @@
1068 style_footer();
1069 }
1070
1071 /*
1072 ** Add a new wiki page to the repository. The page name is
1073 ** given by the zPageName parameter. isNew must be true to create
1074 ** a new page. If no previous page with the name zPageName exists
1075 ** and isNew is false, then this routine throws an error.
1076 **
1077 ** The content of the new page is given by the blob pContent.
1078 **
1079 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1080 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1081 ** ignored.
1082 */
1083 int wiki_cmd_commit(const char *zPageName, int isNew, Blob *pContent,
1084 const char *zMimeType, int localUser){
1085 Blob wiki; /* Wiki page content */
1086 Blob cksum; /* wiki checksum */
1087 int rid; /* artifact ID of parent page */
1088 char *zDate; /* timestamp */
1089 char *zUuid; /* uuid for rid */
1090
1091 rid = db_int(0,
1092 "SELECT x.rid FROM tag t, tagxref x"
1093 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
1094 " ORDER BY x.mtime DESC LIMIT 1",
1095 zPageName
1096 );
1097 if( rid==0 && !isNew ){
1098 #ifdef FOSSIL_ENABLE_JSON
1099 g.json.resultCode = FSL_JSON_E_RESOURCE_NOT_FOUND;
1100 #endif
1101 fossil_fatal("no such wiki page: %s", zPageName);
1102 }
1103 if( rid!=0 && isNew ){
1104 #ifdef FOSSIL_ENABLE_JSON
1105 g.json.resultCode = FSL_JSON_E_RESOURCE_ALREADY_EXISTS;
1106 #endif
1107 fossil_fatal("wiki page %s already exists", zPageName);
1108 }
1109
1110 blob_zero(&wiki);
1111 zDate = date_in_standard_format("now");
1112 blob_appendf(&wiki, "D %s\n", zDate);
1113 free(zDate);
1114 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
1133 db_begin_transaction();
1134 wiki_put(&wiki, 0, wiki_need_moderation(localUser));
1135 db_end_transaction(0);
1136 return 1;
1137 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1138
1139 /*
1140 ** COMMAND: wiki*
1141 **
1142 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1143 **
1144 ** Run various subcommands to work with wiki entries or tech notes.
1145 **
1146 ** %fossil wiki export ?PAGENAME? ?FILE? [-t|--technote DATETIME ]
 
1147 **
1148 ** Sends the latest version of either the PAGENAME wiki entry
1149 ** or the DATETIME tech note to the given file or standard
1150 ** output. One of PAGENAME or DATETIME must be specified.
 
 
 
1151 **
1152 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1153 **
1154 ** Create a new or commit changes to an existing wiki page or
1155 ** technote from FILE or from standard input.
 
 
1156 **
1157 ** Options:
1158 ** -M|--mimetype TEXT-FORMAT The mimetype of the update defaulting
1159 ** to the type used by the previous version
1160 ** of the page or text/x-fossil-wiki.
1161 ** -t|--technote DATETIME Specifies the timestamp of the technote
1162 ** to be created or updated.
 
 
 
 
 
 
 
 
 
 
 
1163 ** --technote-tags TAGS The set of tags for a technote.
1164 ** --technote-bgcolor COLOR The color used for the technote on the
1165 ** timeline.
1166 **
1167 ** %fossil wiki list ?--technote?
1168 ** %fossil wiki ls ?--technote?
1169 **
1170 ** Lists all wiki entries, one per line, ordered
1171 ** case-insensitively by name. The --technote flag
1172 ** specifies that technotes will be listed instead of
1173 ** the wiki entries, which will be listed in order
1174 ** timestamp.
 
 
 
 
 
 
 
 
1175 **
1176 */
1177 void wiki_cmd(void){
1178 int n;
1179 db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
1213 fossil_fatal("wiki page [%s] not found",zPageName);
1214 }
1215 zFile = (g.argc==4) ? "-" : g.argv[4];
1216 }else{
1217 if( (g.argc!=3) && (g.argc!=4) ){
1218 usage("export ?FILE? --technote DATETIME");
1219 }
1220 rid = db_int(0, "SELECT objid FROM event"
1221 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1222 " ORDER BY mtime DESC LIMIT 1",
1223 zETime
1224 );
1225 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1226 zBody = pWiki->zWiki;
1227 }
1228 if( zBody==0 ){
1229 fossil_fatal("technote not found");
1230 }
1231 zFile = (g.argc==3) ? "-" : g.argv[3];
1232 }
1233 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1234 zBody[i] = 0;
@@ -1270,43 +1319,58 @@
1270 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1271 && (pWiki->zMimetype && *pWiki->zMimetype)){
1272 zMimeType = pWiki->zMimetype;
1273 }
1274 }else{
1275 rid = db_int(0, "SELECT objid FROM event"
1276 " WHERE datetime(mtime)=datetime('%q') AND type='e'"
1277 " ORDER BY mtime DESC LIMIT 1",
1278 zPageName
1279 );
1280 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1281 && (pWiki->zMimetype && *pWiki->zMimetype)){
1282 zMimeType = pWiki->zMimetype;
1283 }
1284 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1285 }
 
1286 if( !zETime ){
 
1287 if( g.argv[2][1]=='r' ){
1288 wiki_cmd_commit(zPageName, 1, &content, zMimeType, 1);
1289 fossil_print("Created new wiki page %s.\n", zPageName);
1290 }else{
1291 wiki_cmd_commit(zPageName, 0, &content, zMimeType, 1);
1292 fossil_print("Updated wiki page %s.\n", zPageName);
1293 }
1294 }else{
1295 char *zMETime; /* Normalized, mutable version of zETime */
1296 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1297 zETime);
1298 if( g.argv[2][1]=='r' ){
1299 event_cmd_commit(zMETime, 1, &content, zMimeType, zPageName,
1300 zTags, zClr);
1301 fossil_print("Created new tech note %s.\n", zMETime);
1302 }else{
1303 event_cmd_commit(zMETime, 0, &content, zMimeType, zPageName,
1304 zTags, zClr);
1305 fossil_print("Updated tech note %s.\n", zMETime);
1306 }
1307 free(zMETime);
 
 
1308 }
1309 manifest_destroy(pWiki);
1310 blob_reset(&content);
1311 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1312 if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
1314 }
1315 fossil_fatal("delete not yet implemented.");
1316 }else if(( strncmp(g.argv[2],"list",n)==0 )
1317 || ( strncmp(g.argv[2],"ls",n)==0 )){
1318 Stmt q;
 
 
1319 if ( !find_option("technote","t",0) ){
1320 db_prepare(&q,
1321 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1322 " ORDER BY lower(tagname) /*sort*/"
1323 );
1324 }else{
 
1325 db_prepare(&q,
1326 "SELECT datetime(mtime) FROM event WHERE type='e'"
1327 " ORDER BY mtime /*sort*/"
 
 
 
 
1328 );
1329 }
 
1330 while( db_step(&q)==SQLITE_ROW ){
1331 const char *zName = db_column_text(&q, 0);
 
 
 
 
1332 fossil_print( "%s\n",zName);
1333 }
1334 db_finalize(&q);
1335 }else{
1336 goto wiki_cmd_usage;
1337
--- src/wiki.c
+++ src/wiki.c
@@ -122,20 +122,35 @@
122 static int is_sandbox(const char *zPagename){
123 return fossil_stricmp(zPagename,"sandbox")==0 ||
124 fossil_stricmp(zPagename,"sand box")==0;
125 }
126
127 /*
128 ** Formal, common and short names for the various wiki styles.
129 */
130 static const char *const azStyles[] = {
131 "text/x-fossil-wiki", "Fossil Wiki", "wiki",
132 "text/x-markdown", "Markdown", "markdown",
133 "text/plain", "Plain Text", "plain"
134 };
135
136 /*
137 ** Only allow certain mimetypes through.
138 ** All others become "text/x-fossil-wiki"
139 */
140 const char *wiki_filter_mimetypes(const char *zMimetype){
141 if( zMimetype!=0 ){
142 int i;
143 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
144 if( fossil_strcmp(zMimetype,azStyles[i+2])==0 ){
145 return azStyles[i];
146 }
147 }
148 if( fossil_strcmp(zMimetype, "text/x-markdown")==0
149 || fossil_strcmp(zMimetype, "text/plain")==0 ){
150 return zMimetype;
151 }
152 }
153 return "text/x-fossil-wiki";
154 }
155
156 /*
@@ -412,27 +427,18 @@
427 db_multi_exec("INSERT OR IGNORE INTO unsent VALUES(%d)", nrid);
428 db_multi_exec("INSERT OR IGNORE INTO unclustered VALUES(%d);", nrid);
429 manifest_crosslink(nrid, pWiki, MC_NONE);
430 }
431
 
 
 
 
 
 
 
 
 
432 /*
433 ** Output a selection box from which the user can select the
434 ** wiki mimetype.
435 */
436 void mimetype_option_menu(const char *zMimetype){
437 unsigned i;
438 @ <select name="mimetype" size="1">
439 for(i=0; i<sizeof(azStyles)/sizeof(azStyles[0]); i+=3){
440 if( fossil_strcmp(zMimetype,azStyles[i])==0 ){
441 @ <option value="%s(azStyles[i])" selected>%s(azStyles[i+1])</option>
442 }else{
443 @ <option value="%s(azStyles[i])">%s(azStyles[i+1])</option>
444 }
@@ -1068,47 +1074,26 @@
1074 style_footer();
1075 }
1076
1077 /*
1078 ** Add a new wiki page to the repository. The page name is
1079 ** given by the zPageName parameter. rid must be zero to create
1080 ** a new page otherwise the page identified by rid is updated.
 
1081 **
1082 ** The content of the new page is given by the blob pContent.
1083 **
1084 ** zMimeType specifies the N-card for the wiki page. If it is 0,
1085 ** empty, or "text/x-fossil-wiki" (the default format) then it is
1086 ** ignored.
1087 */
1088 int wiki_cmd_commit(const char *zPageName, int rid, Blob *pContent,
1089 const char *zMimeType, int localUser){
1090 Blob wiki; /* Wiki page content */
1091 Blob cksum; /* wiki checksum */
 
1092 char *zDate; /* timestamp */
1093 char *zUuid; /* uuid for rid */
1094
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1095 blob_zero(&wiki);
1096 zDate = date_in_standard_format("now");
1097 blob_appendf(&wiki, "D %s\n", zDate);
1098 free(zDate);
1099 blob_appendf(&wiki, "L %F\n", zPageName );
@@ -1133,47 +1118,112 @@
1118 db_begin_transaction();
1119 wiki_put(&wiki, 0, wiki_need_moderation(localUser));
1120 db_end_transaction(0);
1121 return 1;
1122 }
1123
1124 /*
1125 ** Determine the rid for a tech note given either its id or its
1126 ** timestamp. Returns 0 if there is no such item and -1 if the details
1127 ** are ambiguous and could refer to multiple items.
1128 */
1129 int wiki_technote_to_rid(const char *zETime) {
1130 int rid=0; /* Artifact ID of the tech note */
1131 int nETime = strlen(zETime);
1132 Stmt q;
1133 if( nETime>=4 && nETime<=UUID_SIZE && validate16(zETime, nETime) ){
1134 char zUuid[UUID_SIZE+1];
1135 memcpy(zUuid, zETime, nETime+1);
1136 canonical16(zUuid, nETime);
1137 db_prepare(&q,
1138 "SELECT e.objid"
1139 " FROM event e, tag t"
1140 " WHERE e.type='e' AND e.tagid IS NOT NULL AND t.tagid=e.tagid"
1141 " AND t.tagname GLOB 'event-%q*'",
1142 zUuid
1143 );
1144 if( db_step(&q)==SQLITE_ROW ){
1145 rid = db_column_int(&q, 0);
1146 if( db_step(&q)==SQLITE_ROW ) rid = -1;
1147 }
1148 db_finalize(&q);
1149 }
1150 if (!rid) {
1151 if (strlen(zETime)>4) {
1152 rid = db_int(0, "SELECT objid"
1153 " FROM event"
1154 " WHERE datetime(mtime)=datetime('%q')"
1155 " AND type='e'"
1156 " AND tagid IS NOT NULL"
1157 " ORDER BY objid DESC LIMIT 1",
1158 zETime);
1159 }
1160 }
1161 return rid;
1162 }
1163
1164 /*
1165 ** COMMAND: wiki*
1166 **
1167 ** Usage: %fossil wiki (export|create|commit|list) WikiName
1168 **
1169 ** Run various subcommands to work with wiki entries or tech notes.
1170 **
1171 ** %fossil wiki export PAGENAME ?FILE?
1172 ** %fossil wiki export ?FILE? -t|--technote DATETIME|TECHNOTE-ID
1173 **
1174 ** Sends the latest version of either a wiki page or of a tech note
1175 ** to the given file or standard output.
1176 ** If PAGENAME is provided, the wiki page will be output. For
1177 ** a tech note either DATETIME or TECHNOTE-ID must be specified. If
1178 ** DATETIME is used, the most recently modified tech note with that
1179 ** DATETIME will be sent.
1180 **
1181 ** %fossil wiki (create|commit) PAGENAME ?FILE? ?OPTIONS?
1182 **
1183 ** Create a new or commit changes to an existing wiki page or
1184 ** technote from FILE or from standard input. PAGENAME is the
1185 ** name of the wiki entry or the timeline comment of the
1186 ** technote.
1187 **
1188 ** Options:
1189 ** -M|--mimetype TEXT-FORMAT The mime type of the update.
1190 ** Defaults to the type used by
1191 ** the previous version of the
1192 ** page, or text/x-fossil-wiki.
1193 ** Valid values are: text/x-fossil-wiki,
1194 ** text/markdown and text/plain. fossil,
1195 ** markdown or plain can be specified as
1196 ** synonyms of these values.
1197 ** -t|--technote DATETIME Specifies the timestamp of
1198 ** the technote to be created or
1199 ** updated. When updating a tech note
1200 ** the most recently modified tech note
1201 ** with the specified timestamp will be
1202 ** updated.
1203 ** -t|--technote TECHNOTE-ID Specifies the technote to be
1204 ** updated by its technote id.
1205 ** --technote-tags TAGS The set of tags for a technote.
1206 ** --technote-bgcolor COLOR The color used for the technote
1207 ** on the timeline.
1208 **
1209 ** %fossil wiki list ?OPTIONS?
1210 ** %fossil wiki ls ?OPTIONS?
1211 **
1212 ** Lists all wiki entries, one per line, ordered
1213 ** case-insensitively by name.
1214 **
1215 ** Options:
1216 ** -t|--technote Technotes will be listed instead of
1217 ** pages. The technotes will be in order
1218 ** of timestamp with the most recent
1219 ** first.
1220 ** -s|--show-technote-ids The id of the tech note will be listed
1221 ** along side the timestamp. The tech note
1222 ** id will be the first word on each line.
1223 ** This option only applies if the
1224 ** --technote option is also specified.
1225 **
1226 */
1227 void wiki_cmd(void){
1228 int n;
1229 db_find_and_open_repository(0, 0);
@@ -1213,22 +1263,21 @@
1263 fossil_fatal("wiki page [%s] not found",zPageName);
1264 }
1265 zFile = (g.argc==4) ? "-" : g.argv[4];
1266 }else{
1267 if( (g.argc!=3) && (g.argc!=4) ){
1268 usage("export ?FILE? --technote DATETIME|TECHNOTE-ID");
1269 }
1270 rid = wiki_technote_to_rid(zETime);
1271 if (rid == -1) {
1272 fossil_fatal("ambiguous tech note id: %s", zETime);
1273 }
 
1274 if( (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0 ){
1275 zBody = pWiki->zWiki;
1276 }
1277 if( zBody==0 ){
1278 fossil_fatal("technote [%s] not found",zETime);
1279 }
1280 zFile = (g.argc==3) ? "-" : g.argv[3];
1281 }
1282 for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
1283 zBody[i] = 0;
@@ -1270,43 +1319,58 @@
1319 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_WIKI, 0))!=0
1320 && (pWiki->zMimetype && *pWiki->zMimetype)){
1321 zMimeType = pWiki->zMimetype;
1322 }
1323 }else{
1324 rid = wiki_technote_to_rid(zETime);
 
 
 
 
1325 if(rid>0 && (pWiki = manifest_get(rid, CFTYPE_EVENT, 0))!=0
1326 && (pWiki->zMimetype && *pWiki->zMimetype)){
1327 zMimeType = pWiki->zMimetype;
1328 }
1329 }
1330 }else{
1331 zMimeType = wiki_filter_mimetypes(zMimeType);
1332 }
1333 if( g.argv[2][1]=='r' && rid>0 ){
1334 if ( !zETime ){
1335 fossil_fatal("wiki page %s already exists", zPageName);
1336 }else{
1337 /* Creating a tech note with same timestamp is permitted
1338 and should create a new tech note */
1339 rid = 0;
1340 }
1341 }else if( g.argv[2][1]=='o' && rid == 0 ){
1342 if ( !zETime ){
1343 fossil_fatal("no such wiki page: %s", zPageName);
1344 }else{
1345 fossil_fatal("no such tech note: %s", zETime);
1346 }
1347 }
1348
1349 if( !zETime ){
1350 wiki_cmd_commit(zPageName, rid, &content, zMimeType, 1);
1351 if( g.argv[2][1]=='r' ){
 
1352 fossil_print("Created new wiki page %s.\n", zPageName);
1353 }else{
 
1354 fossil_print("Updated wiki page %s.\n", zPageName);
1355 }
1356 }else{
1357 if( rid != -1 ){
1358 char *zMETime; /* Normalized, mutable version of zETime */
1359 zMETime = db_text(0, "SELECT coalesce(datetime(%Q),datetime('now'))",
1360 zETime);
1361 event_cmd_commit(zMETime, rid, &content, zMimeType, zPageName,
1362 zTags, zClr);
1363 if( g.argv[2][1]=='r' ){
1364 fossil_print("Created new tech note %s.\n", zMETime);
1365 }else{
1366 fossil_print("Updated tech note %s.\n", zMETime);
1367 }
1368 free(zMETime);
1369 }else{
1370 fossil_fatal("ambiguous tech note id: %s", zETime);
1371 }
1372 }
1373 manifest_destroy(pWiki);
1374 blob_reset(&content);
1375 }else if( strncmp(g.argv[2],"delete",n)==0 ){
1376 if( g.argc!=5 ){
@@ -1314,23 +1378,35 @@
1378 }
1379 fossil_fatal("delete not yet implemented.");
1380 }else if(( strncmp(g.argv[2],"list",n)==0 )
1381 || ( strncmp(g.argv[2],"ls",n)==0 )){
1382 Stmt q;
1383 int showIds = 0;
1384
1385 if ( !find_option("technote","t",0) ){
1386 db_prepare(&q,
1387 "SELECT substr(tagname, 6) FROM tag WHERE tagname GLOB 'wiki-*'"
1388 " ORDER BY lower(tagname) /*sort*/"
1389 );
1390 }else{
1391 showIds = find_option("show-technote-ids","s",0)!=0;
1392 db_prepare(&q,
1393 "SELECT datetime(e.mtime), substr(t.tagname,7)"
1394 " FROM event e, tag t"
1395 " WHERE e.type='e'"
1396 " AND e.tagid IS NOT NULL"
1397 " AND t.tagid=e.tagid"
1398 " ORDER BY e.mtime DESC /*sort*/"
1399 );
1400 }
1401
1402 while( db_step(&q)==SQLITE_ROW ){
1403 const char *zName = db_column_text(&q, 0);
1404 if (showIds) {
1405 const char *zUuid = db_column_text(&q, 1);
1406 fossil_print("%s ",zUuid);
1407 }
1408 fossil_print( "%s\n",zName);
1409 }
1410 db_finalize(&q);
1411 }else{
1412 goto wiki_cmd_usage;
1413
+18 -5
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
3333
struct HttpRequest {
3434
int id; /* ID counter */
3535
SOCKET s; /* Socket on which to receive data */
3636
SOCKADDR_IN addr; /* Address from which data is coming */
3737
int flags; /* Flags passed to win32_http_server() */
38
- const char *zOptions; /* --notfound and/or --localauth options */
38
+ const char *zOptions; /* --baseurl, --notfound and/or --localauth options */
3939
};
4040
4141
/*
4242
** Prefix for a temporary file.
4343
*/
@@ -236,10 +236,11 @@
236236
*/
237237
void win32_http_server(
238238
int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239239
const char *zBrowser, /* Command to launch browser. (Or NULL) */
240240
const char *zStopper, /* Stop server when this file is exists (Or NULL) */
241
+ const char *zBaseUrl, /* The --baseurl option, or NULL */
241242
const char *zNotFound, /* The --notfound option, or NULL */
242243
const char *zFileGlob, /* The --fileglob option, or NULL */
243244
const char *zIpAddr, /* Bind to this IP address, if not NULL */
244245
int flags /* One or more HTTP_SERVER_ flags */
245246
){
@@ -251,10 +252,13 @@
251252
Blob options;
252253
wchar_t zTmpPath[MAX_PATH];
253254
254255
if( zStopper ) file_delete(zStopper);
255256
blob_zero(&options);
257
+ if( zBaseUrl ){
258
+ blob_appendf(&options, " --baseurl %s", zBaseUrl);
259
+ }
256260
if( zNotFound ){
257261
blob_appendf(&options, " --notfound %s", zNotFound);
258262
}
259263
if( zFileGlob ){
260264
blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
365369
** function and to the service control handler function.
366370
*/
367371
typedef struct HttpService HttpService;
368372
struct HttpService {
369373
int port; /* Port on which the http server should run */
374
+ const char *zBaseUrl; /* The --baseurl option, or NULL */
370375
const char *zNotFound; /* The --notfound option, or NULL */
371376
const char *zFileGlob; /* The --files option, or NULL */
372377
int flags; /* One or more HTTP_SERVER_ flags */
373378
int isRunningAsService; /* Are we running as a service ? */
374379
const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
376381
};
377382
378383
/*
379384
** Variables used for running as windows service.
380385
*/
381
-static HttpService hsData = {8080, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
386
+static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
382387
static SERVICE_STATUS ssStatus;
383388
static SERVICE_STATUS_HANDLE sshStatusHandle;
384389
385390
/*
386391
** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
517522
ssStatus.dwServiceSpecificExitCode = 0;
518523
win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
519524
520525
/* Execute the http server */
521526
win32_http_server(hsData.port, hsData.port,
522
- NULL, NULL, hsData.zNotFound, hsData.zFileGlob, 0,
523
- hsData.flags);
527
+ NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
528
+ hsData.zFileGlob, 0, hsData.flags);
524529
525530
/* Service has stopped now. */
526531
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
527532
return;
528533
}
@@ -545,10 +550,11 @@
545550
** integer value. When running as service, this routine does not return until
546551
** the service is stopped. In this case, the return value is zero.
547552
*/
548553
int win32_http_service(
549554
int nPort, /* TCP port number */
555
+ const char *zBaseUrl, /* The --baseurl option, or NULL */
550556
const char *zNotFound, /* The --notfound option, or NULL */
551557
const char *zFileGlob, /* The --files option, or NULL */
552558
int flags /* One or more HTTP_SERVER_ flags */
553559
){
554560
/* Define the service table. */
@@ -555,10 +561,11 @@
555561
SERVICE_TABLE_ENTRYW ServiceTable[] =
556562
{{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
557563
558564
/* Initialize the HttpService structure. */
559565
hsData.port = nPort;
566
+ hsData.zBaseUrl = zBaseUrl;
560567
hsData.zNotFound = zNotFound;
561568
hsData.zFileGlob = zFileGlob;
562569
hsData.flags = flags;
563570
564571
/* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
572579
return 0;
573580
}
574581
575582
/* dupe ifdef needed for mkindex
576583
** COMMAND: winsrv*
577
-**
584
+**
578585
** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
579586
**
580587
** Where METHOD is one of: create delete show start stop.
581588
**
582589
** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
617624
** Password for the user account.
618625
**
619626
** The following options are more or less the same as for the "server"
620627
** command and influence the behaviour of the http server:
621628
**
629
+** --baseurl URL
630
+**
631
+** Use URL as the base (useful for reverse proxies)
632
+**
622633
** -P|--port TCPPORT
623634
**
624635
** Specifies the TCP port (default port is 8080) on which the
625636
** server should listen.
626637
**
@@ -699,10 +710,11 @@
699710
SC_HANDLE hScm;
700711
SC_HANDLE hSvc;
701712
SERVICE_DESCRIPTIONW
702713
svcDescr = {L"Fossil - Distributed Software Configuration Management"};
703714
DWORD dwStartType = SERVICE_DEMAND_START;
715
+ const char *zAltBase = find_option("baseurl", 0, 1);
704716
const char *zDisplay = find_option("display", "D", 1);
705717
const char *zStart = find_option("start", "S", 1);
706718
const char *zUsername = find_option("username", "U", 1);
707719
const char *zPassword = find_option("password", "W", 1);
708720
const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
754766
}
755767
db_close(0);
756768
/* Build the fully-qualified path to the service binary file. */
757769
blob_zero(&binPath);
758770
blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
771
+ if( zAltBase ) blob_appendf(&binPath, " --baseurl %s", zAltBase);
759772
if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
760773
if( useSCGI ) blob_appendf(&binPath, " --scgi");
761774
if( allowRepoList ) blob_appendf(&binPath, " --repolist");
762775
if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
763776
if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
764777
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
37 int flags; /* Flags passed to win32_http_server() */
38 const char *zOptions; /* --notfound and/or --localauth options */
39 };
40
41 /*
42 ** Prefix for a temporary file.
43 */
@@ -236,10 +236,11 @@
236 */
237 void win32_http_server(
238 int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239 const char *zBrowser, /* Command to launch browser. (Or NULL) */
240 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
 
241 const char *zNotFound, /* The --notfound option, or NULL */
242 const char *zFileGlob, /* The --fileglob option, or NULL */
243 const char *zIpAddr, /* Bind to this IP address, if not NULL */
244 int flags /* One or more HTTP_SERVER_ flags */
245 ){
@@ -251,10 +252,13 @@
251 Blob options;
252 wchar_t zTmpPath[MAX_PATH];
253
254 if( zStopper ) file_delete(zStopper);
255 blob_zero(&options);
 
 
 
256 if( zNotFound ){
257 blob_appendf(&options, " --notfound %s", zNotFound);
258 }
259 if( zFileGlob ){
260 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
365 ** function and to the service control handler function.
366 */
367 typedef struct HttpService HttpService;
368 struct HttpService {
369 int port; /* Port on which the http server should run */
 
370 const char *zNotFound; /* The --notfound option, or NULL */
371 const char *zFileGlob; /* The --files option, or NULL */
372 int flags; /* One or more HTTP_SERVER_ flags */
373 int isRunningAsService; /* Are we running as a service ? */
374 const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
376 };
377
378 /*
379 ** Variables used for running as windows service.
380 */
381 static HttpService hsData = {8080, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
382 static SERVICE_STATUS ssStatus;
383 static SERVICE_STATUS_HANDLE sshStatusHandle;
384
385 /*
386 ** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
517 ssStatus.dwServiceSpecificExitCode = 0;
518 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
519
520 /* Execute the http server */
521 win32_http_server(hsData.port, hsData.port,
522 NULL, NULL, hsData.zNotFound, hsData.zFileGlob, 0,
523 hsData.flags);
524
525 /* Service has stopped now. */
526 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
527 return;
528 }
@@ -545,10 +550,11 @@
545 ** integer value. When running as service, this routine does not return until
546 ** the service is stopped. In this case, the return value is zero.
547 */
548 int win32_http_service(
549 int nPort, /* TCP port number */
 
550 const char *zNotFound, /* The --notfound option, or NULL */
551 const char *zFileGlob, /* The --files option, or NULL */
552 int flags /* One or more HTTP_SERVER_ flags */
553 ){
554 /* Define the service table. */
@@ -555,10 +561,11 @@
555 SERVICE_TABLE_ENTRYW ServiceTable[] =
556 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
557
558 /* Initialize the HttpService structure. */
559 hsData.port = nPort;
 
560 hsData.zNotFound = zNotFound;
561 hsData.zFileGlob = zFileGlob;
562 hsData.flags = flags;
563
564 /* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
572 return 0;
573 }
574
575 /* dupe ifdef needed for mkindex
576 ** COMMAND: winsrv*
577 **
578 ** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
579 **
580 ** Where METHOD is one of: create delete show start stop.
581 **
582 ** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
617 ** Password for the user account.
618 **
619 ** The following options are more or less the same as for the "server"
620 ** command and influence the behaviour of the http server:
621 **
 
 
 
 
622 ** -P|--port TCPPORT
623 **
624 ** Specifies the TCP port (default port is 8080) on which the
625 ** server should listen.
626 **
@@ -699,10 +710,11 @@
699 SC_HANDLE hScm;
700 SC_HANDLE hSvc;
701 SERVICE_DESCRIPTIONW
702 svcDescr = {L"Fossil - Distributed Software Configuration Management"};
703 DWORD dwStartType = SERVICE_DEMAND_START;
 
704 const char *zDisplay = find_option("display", "D", 1);
705 const char *zStart = find_option("start", "S", 1);
706 const char *zUsername = find_option("username", "U", 1);
707 const char *zPassword = find_option("password", "W", 1);
708 const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
754 }
755 db_close(0);
756 /* Build the fully-qualified path to the service binary file. */
757 blob_zero(&binPath);
758 blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
 
759 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
760 if( useSCGI ) blob_appendf(&binPath, " --scgi");
761 if( allowRepoList ) blob_appendf(&binPath, " --repolist");
762 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
763 if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
764
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
37 int flags; /* Flags passed to win32_http_server() */
38 const char *zOptions; /* --baseurl, --notfound and/or --localauth options */
39 };
40
41 /*
42 ** Prefix for a temporary file.
43 */
@@ -236,10 +236,11 @@
236 */
237 void win32_http_server(
238 int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239 const char *zBrowser, /* Command to launch browser. (Or NULL) */
240 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
241 const char *zBaseUrl, /* The --baseurl option, or NULL */
242 const char *zNotFound, /* The --notfound option, or NULL */
243 const char *zFileGlob, /* The --fileglob option, or NULL */
244 const char *zIpAddr, /* Bind to this IP address, if not NULL */
245 int flags /* One or more HTTP_SERVER_ flags */
246 ){
@@ -251,10 +252,13 @@
252 Blob options;
253 wchar_t zTmpPath[MAX_PATH];
254
255 if( zStopper ) file_delete(zStopper);
256 blob_zero(&options);
257 if( zBaseUrl ){
258 blob_appendf(&options, " --baseurl %s", zBaseUrl);
259 }
260 if( zNotFound ){
261 blob_appendf(&options, " --notfound %s", zNotFound);
262 }
263 if( zFileGlob ){
264 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
369 ** function and to the service control handler function.
370 */
371 typedef struct HttpService HttpService;
372 struct HttpService {
373 int port; /* Port on which the http server should run */
374 const char *zBaseUrl; /* The --baseurl option, or NULL */
375 const char *zNotFound; /* The --notfound option, or NULL */
376 const char *zFileGlob; /* The --files option, or NULL */
377 int flags; /* One or more HTTP_SERVER_ flags */
378 int isRunningAsService; /* Are we running as a service ? */
379 const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
381 };
382
383 /*
384 ** Variables used for running as windows service.
385 */
386 static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
387 static SERVICE_STATUS ssStatus;
388 static SERVICE_STATUS_HANDLE sshStatusHandle;
389
390 /*
391 ** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
522 ssStatus.dwServiceSpecificExitCode = 0;
523 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
524
525 /* Execute the http server */
526 win32_http_server(hsData.port, hsData.port,
527 NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
528 hsData.zFileGlob, 0, hsData.flags);
529
530 /* Service has stopped now. */
531 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
532 return;
533 }
@@ -545,10 +550,11 @@
550 ** integer value. When running as service, this routine does not return until
551 ** the service is stopped. In this case, the return value is zero.
552 */
553 int win32_http_service(
554 int nPort, /* TCP port number */
555 const char *zBaseUrl, /* The --baseurl option, or NULL */
556 const char *zNotFound, /* The --notfound option, or NULL */
557 const char *zFileGlob, /* The --files option, or NULL */
558 int flags /* One or more HTTP_SERVER_ flags */
559 ){
560 /* Define the service table. */
@@ -555,10 +561,11 @@
561 SERVICE_TABLE_ENTRYW ServiceTable[] =
562 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
563
564 /* Initialize the HttpService structure. */
565 hsData.port = nPort;
566 hsData.zBaseUrl = zBaseUrl;
567 hsData.zNotFound = zNotFound;
568 hsData.zFileGlob = zFileGlob;
569 hsData.flags = flags;
570
571 /* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
579 return 0;
580 }
581
582 /* dupe ifdef needed for mkindex
583 ** COMMAND: winsrv*
584 **
585 ** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
586 **
587 ** Where METHOD is one of: create delete show start stop.
588 **
589 ** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
624 ** Password for the user account.
625 **
626 ** The following options are more or less the same as for the "server"
627 ** command and influence the behaviour of the http server:
628 **
629 ** --baseurl URL
630 **
631 ** Use URL as the base (useful for reverse proxies)
632 **
633 ** -P|--port TCPPORT
634 **
635 ** Specifies the TCP port (default port is 8080) on which the
636 ** server should listen.
637 **
@@ -699,10 +710,11 @@
710 SC_HANDLE hScm;
711 SC_HANDLE hSvc;
712 SERVICE_DESCRIPTIONW
713 svcDescr = {L"Fossil - Distributed Software Configuration Management"};
714 DWORD dwStartType = SERVICE_DEMAND_START;
715 const char *zAltBase = find_option("baseurl", 0, 1);
716 const char *zDisplay = find_option("display", "D", 1);
717 const char *zStart = find_option("start", "S", 1);
718 const char *zUsername = find_option("username", "U", 1);
719 const char *zPassword = find_option("password", "W", 1);
720 const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
766 }
767 db_close(0);
768 /* Build the fully-qualified path to the service binary file. */
769 blob_zero(&binPath);
770 blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
771 if( zAltBase ) blob_appendf(&binPath, " --baseurl %s", zAltBase);
772 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
773 if( useSCGI ) blob_appendf(&binPath, " --scgi");
774 if( allowRepoList ) blob_appendf(&binPath, " --repolist");
775 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
776 if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
777
--- test/merge6.test
+++ test/merge6.test
@@ -62,10 +62,10 @@
6262
fossil ls
6363
6464
test merge_multi-4 {[normalize_result] eq {f1
6565
f2
6666
f3
67
-f4}} knownBug
67
+f4}}
6868
6969
###############################################################################
7070
7171
test_cleanup
7272
7373
ADDED test/merge_exe.test
--- test/merge6.test
+++ test/merge6.test
@@ -62,10 +62,10 @@
62 fossil ls
63
64 test merge_multi-4 {[normalize_result] eq {f1
65 f2
66 f3
67 f4}} knownBug
68
69 ###############################################################################
70
71 test_cleanup
72
73 DDED test/merge_exe.test
--- test/merge6.test
+++ test/merge6.test
@@ -62,10 +62,10 @@
62 fossil ls
63
64 test merge_multi-4 {[normalize_result] eq {f1
65 f2
66 f3
67 f4}}
68
69 ###############################################################################
70
71 test_cleanup
72
73 DDED test/merge_exe.test
--- a/test/merge_exe.test
+++ b/test/merge_exe.test
@@ -0,0 +1,93 @@
1
+#
2
+# Copyright (c) 2016 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
+# Testing changes to a file's execute bit caused by a merge
19
+#
20
+
21
+if {$tcl_platform(platform) eq "unix"} {
22
+ proc setx {fn isexe} {
23
+ file attributes $fn -permissions [expr {$isexe ? "+" : "-"}]x
24
+ }
25
+
26
+ proc test_exe {fn expected} {
27
+ test merge_exe-$fn {[file executable $fn]==$expected}
28
+ }
29
+} else {
30
+ # WARNING: This is a hack for setting and testing a file's execute bit
31
+ # on Windows. Never operate directly on Fossil database files like this
32
+ # unless you really need to and really know what you're doing.
33
+
34
+ proc query {sql} {
35
+ return [exec $::fossilexe sqlite3 --no-repository _FOSSIL_ $sql]
36
+ }
37
+
38
+ proc setx {fn isexe} {
39
+ set isexe [expr {bool($isexe)}]
40
+ query "UPDATE vfile SET isexe=$isexe WHERE pathname='$fn'"
41
+ }
42
+
43
+ proc test_exe {fn expected} {
44
+ set result [query "SELECT isexe FROM vfile WHERE pathname='$fn'"]
45
+ test merge_exe-$fn {$result==$expected}
46
+ }
47
+}
48
+
49
+test_setup
50
+
51
+write_file f1 "line"
52
+write_file f2 "line"
53
+write_file f3 "line"
54
+write_file f4 "line"
55
+fossil addremove
56
+setx f3 1
57
+setx f4 1
58
+fossil commit -m "add files"
59
+
60
+write_file f0 "f0"
61
+fossil add f0
62
+setx f0 1
63
+fossil mv --hard f1 f1n
64
+setx f1n 1
65
+write_file f2 "line\nline2"
66
+setx f2 1
67
+write_file f3 "line\nline2"
68
+setx f3 0
69
+setx f4 0
70
+fossil commit -b b -m "changes"
71
+
72
+fossil update trunk
73
+write_file f3 "line3\nline"
74
+fossil commit -m "edit f3"
75
+
76
+fossil merge b
77
+test_status_list merge_exe-mrg $RESULT {
78
+ EXECUTABLE f1
79
+ EXECUTABLE f2
80
+ UNEXEC f3
81
+ UNEXEC f4
82
+ UPDATE f2
83
+ MERGE f3
84
+ RENAME f1 -> f1n
85
+ ADDED f0
86
+}
87
+foreach {fn isexe} {f0 1 f1n 1 f2 1 f3 0 f4 0} {
88
+ test_exe $fn $isexe
89
+}
90
+
91
+###############################################################################
92
+
93
+test_cleanup
--- a/test/merge_exe.test
+++ b/test/merge_exe.test
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/merge_exe.test
+++ b/test/merge_exe.test
@@ -0,0 +1,93 @@
1 #
2 # Copyright (c) 2016 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 # Testing changes to a file's execute bit caused by a merge
19 #
20
21 if {$tcl_platform(platform) eq "unix"} {
22 proc setx {fn isexe} {
23 file attributes $fn -permissions [expr {$isexe ? "+" : "-"}]x
24 }
25
26 proc test_exe {fn expected} {
27 test merge_exe-$fn {[file executable $fn]==$expected}
28 }
29 } else {
30 # WARNING: This is a hack for setting and testing a file's execute bit
31 # on Windows. Never operate directly on Fossil database files like this
32 # unless you really need to and really know what you're doing.
33
34 proc query {sql} {
35 return [exec $::fossilexe sqlite3 --no-repository _FOSSIL_ $sql]
36 }
37
38 proc setx {fn isexe} {
39 set isexe [expr {bool($isexe)}]
40 query "UPDATE vfile SET isexe=$isexe WHERE pathname='$fn'"
41 }
42
43 proc test_exe {fn expected} {
44 set result [query "SELECT isexe FROM vfile WHERE pathname='$fn'"]
45 test merge_exe-$fn {$result==$expected}
46 }
47 }
48
49 test_setup
50
51 write_file f1 "line"
52 write_file f2 "line"
53 write_file f3 "line"
54 write_file f4 "line"
55 fossil addremove
56 setx f3 1
57 setx f4 1
58 fossil commit -m "add files"
59
60 write_file f0 "f0"
61 fossil add f0
62 setx f0 1
63 fossil mv --hard f1 f1n
64 setx f1n 1
65 write_file f2 "line\nline2"
66 setx f2 1
67 write_file f3 "line\nline2"
68 setx f3 0
69 setx f4 0
70 fossil commit -b b -m "changes"
71
72 fossil update trunk
73 write_file f3 "line3\nline"
74 fossil commit -m "edit f3"
75
76 fossil merge b
77 test_status_list merge_exe-mrg $RESULT {
78 EXECUTABLE f1
79 EXECUTABLE f2
80 UNEXEC f3
81 UNEXEC f4
82 UPDATE f2
83 MERGE f3
84 RENAME f1 -> f1n
85 ADDED f0
86 }
87 foreach {fn isexe} {f0 1 f1n 1 f2 1 f3 0 f4 0} {
88 test_exe $fn $isexe
89 }
90
91 ###############################################################################
92
93 test_cleanup
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,9 +1,14 @@
11
#
22
# Tests for merging with renames
33
#
44
#
5
+
6
+proc commit_id {version} {
7
+ regexp -line {^artifact:\s+(\S+)} [fossil whatis $version] - id
8
+ return $id
9
+}
510
611
require_no_open_checkout
712
813
######################################
914
# Test 1 #
@@ -31,12 +36,11 @@
3136
3237
write_file f1 "line6"
3338
fossil commit -m "c4"
3439
3540
fossil update pivot
36
-fossil mv f1 f2
37
-file rename -force f1 f2
41
+fossil mv --hard f1 f2
3842
fossil commit -b rename -m "c5"
3943
4044
fossil merge trunk
4145
fossil commit -m "trunk merged"
4246
@@ -44,26 +48,11 @@
4448
write_file f3 "someline"
4549
fossil add f3
4650
fossil commit -b branch2 -m "newbranch"
4751
4852
fossil merge trunk
49
-puts $RESULT
50
-
51
-set deletes 0
52
-foreach {status filename} $RESULT {
53
- if {$status=="DELETE"} {
54
- set deletes [expr $deletes + 1]
55
- }
56
-}
57
-
58
-if {$deletes!=0} {
59
- # failed
60
- protOut "Error, the merge should not delete any file"
61
- test merge_renames-1 0
62
-} else {
63
- test merge_renames-1 1
64
-}
53
+test_status_list merge_renames-1 $RESULT {UPDATE f1}
6554
6655
######################################
6756
# Test 2 #
6857
# Reported: Ticket [74413366fe5067] #
6958
######################################
@@ -77,12 +66,11 @@
7766
7867
write_file f2 "line2"
7968
fossil add f2
8069
fossil commit -m "newfile"
8170
82
-fossil mv f2 f2new
83
-file rename -force f2 f2new
71
+fossil mv --hard f2 f2new
8472
fossil commit -m "rename"
8573
8674
fossil update pivot
8775
write_file f1 "line3"
8876
fossil commit -b branch -m "change"
@@ -91,27 +79,11 @@
9179
fossil commit -m "trunk merged"
9280
9381
fossil update trunk
9482
9583
fossil merge branch
96
-puts $RESULT
97
-
98
-# Not a nice way to check, but I don't know more tcl now
99
-set deletes 0
100
-foreach {status filename} $RESULT {
101
- if {$status=="DELETE"} {
102
- set deletes [expr $deletes + 1]
103
- }
104
-}
105
-
106
-if {$deletes!=0} {
107
- # failed
108
- protOut "Error, the merge should not delete any file"
109
- test merge_renames-2 0
110
-} else {
111
- test merge_renames-2 1
112
-}
84
+test_status_list merge_renames-2 $RESULT {UPDATE f1}
11385
11486
######################################
11587
# Test 3 #
11688
# Reported: Ticket [30b28cf351] #
11789
######################################
@@ -125,12 +97,11 @@
12597
12698
write_file f2 "line2"
12799
fossil add f2
128100
fossil commit -m "newfile"
129101
130
-fossil mv f2 f2new
131
-file rename -force f2 f2new
102
+fossil mv --hard f2 f2new
132103
fossil commit -m "rename"
133104
134105
fossil update pivot
135106
write_file f1 "line3"
136107
fossil commit -b branch -m "change"
@@ -139,34 +110,33 @@
139110
fossil commit -m "trunk merged"
140111
141112
fossil update trunk
142113
143114
fossil merge branch
144
-puts $RESULT
145
-
146
-# Not a nice way to check, but I don't know more tcl now
147
-set deletes 0
148
-foreach {status filename} $RESULT {
149
- if {$status=="DELETE"} {
150
- set deletes [expr $deletes + 1]
151
- }
152
-}
153
-
154
-if {$deletes!=0} {
155
- # failed
156
- protOut "Error, the merge should not delete any file"
157
- test merge_renames-3 0
158
-} else {
159
- test merge_renames-3 1
160
-}
115
+test_status_list merge_renames-3 $RESULT {UPDATE f1}
161116
162117
######################################
163118
# Test 4 #
164119
# Reported: Ticket [67176c3aa4] #
165120
######################################
166121
167
-# TO BE WRITTEN.
122
+test_setup
123
+
124
+write_file f1 "f1"
125
+fossil add f1
126
+fossil commit -m "add f1"
127
+
128
+write_file f1 "f1.1"
129
+fossil commit --branch b -m "change f1"
130
+
131
+fossil update trunk
132
+fossil mv --hard f1 f2
133
+fossil commit -m "f1 -> f2"
134
+
135
+fossil merge b
136
+test_status_list merge_renames-4-1 $RESULT {UPDATE f2}
137
+test_file_contents merge_renames-4-2 f2 "f1.1"
168138
169139
######################################
170140
# Test 5 #
171141
# Handle Rename/Add via Merge #
172142
######################################
@@ -180,25 +150,325 @@
180150
write_file f3 "f3 line"
181151
fossil add f3
182152
fossil commit -m "branch file" -b branch_for_f3
183153
184154
fossil update trunk
185
-fossil mv f1 f2
186
-file rename -force f1 f2
155
+fossil mv --hard f1 f2
187156
write_file f1 "new f1 line"
188157
fossil add f1
189158
fossil commit -m "rename and add file with old name"
190159
191160
fossil update branch_for_f3
192161
fossil merge trunk
162
+test_status_list merge_renames-5-1 $RESULT {
163
+ RENAME f1 -> f2
164
+ ADDED f1
165
+}
166
+
193167
fossil commit -m "trunk merged, should have 3 files"
194168
195169
fossil ls
196170
197
-test merge_renames-5 {[normalize_result] eq {f1
171
+test merge_renames-5-2 {[normalize_result] eq {f1
198172
f2
199
-f3}} knownBug
173
+f3}}
174
+
175
+#####################################
176
+# Test 6 #
177
+# Merging a branch multiple times #
178
+#####################################
179
+
180
+test_setup
181
+
182
+write_file f1 "f1"
183
+fossil add f1
184
+fossil commit -m "add f1"
185
+
186
+fossil mv --hard f1 f2
187
+fossil commit -b b -m "f1 -> f2"
188
+
189
+fossil update trunk
190
+write_file f3 "f3"
191
+write_file f4 "f4"
192
+fossil add f3 f4
193
+fossil ci -m "add f3, f4"
194
+
195
+fossil mv --hard f3 f3-old
196
+fossil mv --hard f4 f3
197
+fossil mv --hard f3-old f4
198
+fossil ci -m "swap f3 and f4"
199
+
200
+write_file f1 "f1.1"
201
+fossil commit -m "edit f1"
202
+
203
+fossil update b
204
+fossil merge trunk
205
+fossil commit -m "merge trunk"
206
+
207
+fossil update trunk
208
+write_file f1 "f1.2"
209
+write_file f3 "f3.1"
210
+write_file f4 "f4.1"
211
+fossil commit -m "edit f1, f4"
212
+
213
+fossil update b
214
+fossil merge trunk
215
+test_status_list merge_renames-6-1 $RESULT {
216
+ UPDATE f2
217
+ UPDATE f3
218
+ UPDATE f4
219
+}
220
+test_file_contents merge_renames-6-2 f2 "f1.2"
221
+test_file_contents merge_renames-6-3 f3 "f3.1"
222
+test_file_contents merge_renames-6-4 f4 "f4.1"
223
+
224
+########################################################################
225
+# Test 7 #
226
+# Merging with an uncommitted rename of a file that has been renamed #
227
+# in the merged branch and adding a new file with the original name #
228
+########################################################################
229
+
230
+test_setup
231
+
232
+write_file f1 "f1"
233
+fossil add f1
234
+fossil commit -m "add f1"
235
+
236
+fossil mv --hard f1 f2
237
+write_file f2 "f2"
238
+fossil commit -b b -m "f1 -> f2, edit f2"
239
+
240
+fossil update trunk
241
+fossil mv --hard f1 f3
242
+write_file f1 "f1.1"
243
+fossil add f1
244
+fossil merge b
245
+test_status_list merge_renames-7-1 $RESULT {UPDATE f3}
246
+test_file_contents merge_renames-7-2 f1 "f1.1"
247
+test_file_contents merge_renames-7-3 f3 "f2"
248
+
249
+######################################################
250
+# Test 8 #
251
+# Merging two branches that both add the same file #
252
+######################################################
253
+
254
+test_setup
255
+
256
+write_file f1 "f1.1"
257
+fossil add f1
258
+fossil commit -b b1 -m "add f1"
259
+
260
+fossil update trunk
261
+write_file f1 "f1.2"
262
+fossil add f1
263
+fossil commit -b b2 -m "add f1"
264
+
265
+fossil update trunk
266
+fossil merge b1
267
+fossil merge b2
268
+test_status_list merge_renames-8-1 $RESULT {
269
+ WARNING: no common ancestor for f1
270
+}
271
+
272
+fossil revert
273
+fossil merge --integrate b1
274
+fossil merge b2
275
+test_status_list merge_renames-8-2 $RESULT {
276
+ WARNING: no common ancestor for f1
277
+}
278
+
279
+#############################################
280
+# Test 9 #
281
+# Merging a delete/rename/add combination #
282
+#############################################
283
+
284
+test_setup
285
+
286
+write_file f1 "f1"
287
+write_file f2 "f2"
288
+fossil add f1 f2
289
+fossil commit -m "add files"
290
+
291
+fossil rm --hard f2
292
+fossil commit -b b -m "delete f2"
293
+
294
+fossil mv --hard f1 f2
295
+fossil commit -m "f1 -> f2"
296
+
297
+write_file f1 "f1.1"
298
+fossil add f1
299
+fossil commit -m "add new f1"
300
+
301
+fossil update trunk
302
+fossil merge b
303
+set expectedMerge {
304
+ DELETE f2
305
+ RENAME f1 -> f2
306
+ ADDED f1
307
+}
308
+test_status_list merge_renames-9-1 $RESULT $expectedMerge
309
+fossil changes
310
+test_status_list merge_renames-9-2 $RESULT "
311
+ MERGED_WITH [commit_id b]
312
+ ADDED_BY_MERGE f1
313
+ RENAMED f2
314
+ DELETED f2 (overwritten by rename)
315
+"
316
+test_file_contents merge_renames-9-3 f1 "f1.1"
317
+test_file_contents merge_renames-9-4 f2 "f1"
318
+
319
+# Undo and ensure a dry run merge results in no changes
320
+fossil undo
321
+test_status_list merge_renames-9-5 $RESULT {
322
+ UNDO f1
323
+ UNDO f2
324
+}
325
+fossil merge -n b
326
+test_status_list merge_renames-9-6 $RESULT "
327
+ $expectedMerge
328
+ REMINDER: this was a dry run - no files were actually changed.
329
+"
330
+test merge_renames-9-7 {[fossil changes] eq ""}
331
+
332
+###################################################################
333
+# Test 10 #
334
+# Merge swapped filenames, backout the swap, then merge changes #
335
+###################################################################
336
+
337
+test_setup
338
+
339
+write_file f1 "f1"
340
+write_file f2 "f2"
341
+fossil add f1 f2
342
+fossil commit -m "add files" ;# N
343
+
344
+fossil mv --hard f1 f1-tmp
345
+fossil mv --hard f2 f1
346
+fossil mv --hard f1-tmp f2
347
+fossil commit -b b -m "swap f1, f2" ;# P
348
+
349
+fossil update trunk
350
+fossil merge b
351
+test_status_list merge_renames-10-1 $RESULT {
352
+ RENAME f1 -> f2
353
+ RENAME f2 -> f1
354
+}
355
+test_file_contents merge_renames-10-2 f1 "f2"
356
+test_file_contents merge_renames-10-3 f2 "f1"
357
+fossil commit -m "merge b"
358
+
359
+fossil update b
360
+write_file f1 f1.1
361
+write_file f2 f2.1
362
+fossil commit -m "edit" ;# M
363
+
364
+fossil update trunk
365
+fossil merge --backout trunk
366
+test_status_list merge_renames-10-4 $RESULT {
367
+ RENAME f1 -> f2
368
+ RENAME f2 -> f1
369
+}
370
+test_file_contents merge_renames-10-5 f1 "f1"
371
+test_file_contents merge_renames-10-6 f2 "f2"
372
+test_status_list merge_renames-10-7 [fossil changes] "
373
+ RENAMED f1
374
+ RENAMED f2
375
+ BACKOUT [commit_id trunk]
376
+"
377
+fossil commit -m "swap back" ;# V
378
+
379
+fossil merge b
380
+test_status_list merge_renames-10-8 $RESULT {
381
+ UPDATE f1
382
+ UPDATE f2
383
+}
384
+
385
+test_file_contents merge_renames-10-9 f1 "f2.1"
386
+test_file_contents merge_renames-10-10 f2 "f1.1"
387
+
388
+############################################
389
+# Test 11 #
390
+# Specifying a baseline #
391
+############################################
392
+
393
+test_setup
394
+
395
+write_file f1 "line"
396
+fossil add f1
397
+fossil commit -m "add f1"
398
+
399
+write_file f1 "line\nline2"
400
+fossil commit -b b -m "edit f2" --tag p1
401
+
402
+fossil mv --hard f1 f2
403
+fossil commit -m "f1 -> f2"
404
+
405
+write_file f2 "line\nline2\nline3"
406
+fossil commit -m "edit f2" --tag p2
407
+
408
+write_file f2 "line\nline2\nline3\nline4"
409
+fossil commit -m "edit f2"
410
+
411
+fossil update trunk
412
+fossil merge --baseline p1 b
413
+test_status_list merge_renames-11-1 $RESULT {
414
+ MERGE f1
415
+ RENAME f1 -> f2
416
+}
417
+test_file_contents merge_renames-11-2 f2 "line\nline3\nline4"
418
+fossil revert
419
+fossil merge --baseline p2 b
420
+test_status_list merge_renames-11-3 $RESULT {MERGE f1}
421
+test_file_contents merge_renames-11-4 f1 "line\nline4"
422
+
423
+#################################################################
424
+# Test 12 #
425
+# Merge involving a pivot that isn't a first-parent ancestor #
426
+# of either the checked-out commit or the commit being merged #
427
+#################################################################
428
+
429
+test_setup
430
+
431
+write_file f1 "f1\n"
432
+fossil add f1
433
+fossil commit -m "add f1" --tag n
434
+
435
+fossil mv --hard f1 f1n
436
+fossil commit -m "f1 -> f1n"
437
+
438
+fossil mv --hard f1n f1v
439
+write_file f1v "f1v\n"
440
+fossil commit -b v -m "f1n -> f1v, edit f1v"
441
+
442
+fossil update trunk
443
+fossil mv --hard f1n f1m
444
+fossil commit -b m -m "f1n -> f1m"
445
+
446
+fossil update n
447
+fossil mv --hard f1 f1p
448
+write_file f1p "f1\np"
449
+fossil commit -b p -m "f1 -> f1p, edit f1p"
450
+
451
+fossil update m
452
+fossil merge p
453
+test_status_list merge_renames-12-1 $RESULT {UPDATE f1m}
454
+test_file_contents merge_renames-12-2 f1m "f1\np"
455
+fossil commit -m "merge p"
456
+
457
+write_file f1m "f1\nm"
458
+fossil commit -m "edit f1m"
459
+
460
+fossil update v
461
+fossil merge p
462
+test_status_list merge_renames-12-3 $RESULT {MERGE f1v}
463
+test_file_contents merge_renames-12-4 f1v "f1v\np"
464
+fossil commit -m "merge p"
465
+
466
+fossil merge m
467
+test_status_list merge_renames-12-5 $RESULT {MERGE f1v}
468
+test_file_contents merge_renames-12-6 f1v "f1v\nm"
469
+fossil commit -m "merge m"
200470
201471
######################################
202472
#
203473
# Tests for troubles not specifically linked with renames but that I'd like to
204474
# write:
205475
206476
ADDED test/merge_warn.test
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,9 +1,14 @@
1 #
2 # Tests for merging with renames
3 #
4 #
 
 
 
 
 
5
6 require_no_open_checkout
7
8 ######################################
9 # Test 1 #
@@ -31,12 +36,11 @@
31
32 write_file f1 "line6"
33 fossil commit -m "c4"
34
35 fossil update pivot
36 fossil mv f1 f2
37 file rename -force f1 f2
38 fossil commit -b rename -m "c5"
39
40 fossil merge trunk
41 fossil commit -m "trunk merged"
42
@@ -44,26 +48,11 @@
44 write_file f3 "someline"
45 fossil add f3
46 fossil commit -b branch2 -m "newbranch"
47
48 fossil merge trunk
49 puts $RESULT
50
51 set deletes 0
52 foreach {status filename} $RESULT {
53 if {$status=="DELETE"} {
54 set deletes [expr $deletes + 1]
55 }
56 }
57
58 if {$deletes!=0} {
59 # failed
60 protOut "Error, the merge should not delete any file"
61 test merge_renames-1 0
62 } else {
63 test merge_renames-1 1
64 }
65
66 ######################################
67 # Test 2 #
68 # Reported: Ticket [74413366fe5067] #
69 ######################################
@@ -77,12 +66,11 @@
77
78 write_file f2 "line2"
79 fossil add f2
80 fossil commit -m "newfile"
81
82 fossil mv f2 f2new
83 file rename -force f2 f2new
84 fossil commit -m "rename"
85
86 fossil update pivot
87 write_file f1 "line3"
88 fossil commit -b branch -m "change"
@@ -91,27 +79,11 @@
91 fossil commit -m "trunk merged"
92
93 fossil update trunk
94
95 fossil merge branch
96 puts $RESULT
97
98 # Not a nice way to check, but I don't know more tcl now
99 set deletes 0
100 foreach {status filename} $RESULT {
101 if {$status=="DELETE"} {
102 set deletes [expr $deletes + 1]
103 }
104 }
105
106 if {$deletes!=0} {
107 # failed
108 protOut "Error, the merge should not delete any file"
109 test merge_renames-2 0
110 } else {
111 test merge_renames-2 1
112 }
113
114 ######################################
115 # Test 3 #
116 # Reported: Ticket [30b28cf351] #
117 ######################################
@@ -125,12 +97,11 @@
125
126 write_file f2 "line2"
127 fossil add f2
128 fossil commit -m "newfile"
129
130 fossil mv f2 f2new
131 file rename -force f2 f2new
132 fossil commit -m "rename"
133
134 fossil update pivot
135 write_file f1 "line3"
136 fossil commit -b branch -m "change"
@@ -139,34 +110,33 @@
139 fossil commit -m "trunk merged"
140
141 fossil update trunk
142
143 fossil merge branch
144 puts $RESULT
145
146 # Not a nice way to check, but I don't know more tcl now
147 set deletes 0
148 foreach {status filename} $RESULT {
149 if {$status=="DELETE"} {
150 set deletes [expr $deletes + 1]
151 }
152 }
153
154 if {$deletes!=0} {
155 # failed
156 protOut "Error, the merge should not delete any file"
157 test merge_renames-3 0
158 } else {
159 test merge_renames-3 1
160 }
161
162 ######################################
163 # Test 4 #
164 # Reported: Ticket [67176c3aa4] #
165 ######################################
166
167 # TO BE WRITTEN.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
169 ######################################
170 # Test 5 #
171 # Handle Rename/Add via Merge #
172 ######################################
@@ -180,25 +150,325 @@
180 write_file f3 "f3 line"
181 fossil add f3
182 fossil commit -m "branch file" -b branch_for_f3
183
184 fossil update trunk
185 fossil mv f1 f2
186 file rename -force f1 f2
187 write_file f1 "new f1 line"
188 fossil add f1
189 fossil commit -m "rename and add file with old name"
190
191 fossil update branch_for_f3
192 fossil merge trunk
 
 
 
 
 
193 fossil commit -m "trunk merged, should have 3 files"
194
195 fossil ls
196
197 test merge_renames-5 {[normalize_result] eq {f1
198 f2
199 f3}} knownBug
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
201 ######################################
202 #
203 # Tests for troubles not specifically linked with renames but that I'd like to
204 # write:
205
206 DDED test/merge_warn.test
--- test/merge_renames.test
+++ test/merge_renames.test
@@ -1,9 +1,14 @@
1 #
2 # Tests for merging with renames
3 #
4 #
5
6 proc commit_id {version} {
7 regexp -line {^artifact:\s+(\S+)} [fossil whatis $version] - id
8 return $id
9 }
10
11 require_no_open_checkout
12
13 ######################################
14 # Test 1 #
@@ -31,12 +36,11 @@
36
37 write_file f1 "line6"
38 fossil commit -m "c4"
39
40 fossil update pivot
41 fossil mv --hard f1 f2
 
42 fossil commit -b rename -m "c5"
43
44 fossil merge trunk
45 fossil commit -m "trunk merged"
46
@@ -44,26 +48,11 @@
48 write_file f3 "someline"
49 fossil add f3
50 fossil commit -b branch2 -m "newbranch"
51
52 fossil merge trunk
53 test_status_list merge_renames-1 $RESULT {UPDATE f1}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55 ######################################
56 # Test 2 #
57 # Reported: Ticket [74413366fe5067] #
58 ######################################
@@ -77,12 +66,11 @@
66
67 write_file f2 "line2"
68 fossil add f2
69 fossil commit -m "newfile"
70
71 fossil mv --hard f2 f2new
 
72 fossil commit -m "rename"
73
74 fossil update pivot
75 write_file f1 "line3"
76 fossil commit -b branch -m "change"
@@ -91,27 +79,11 @@
79 fossil commit -m "trunk merged"
80
81 fossil update trunk
82
83 fossil merge branch
84 test_status_list merge_renames-2 $RESULT {UPDATE f1}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
86 ######################################
87 # Test 3 #
88 # Reported: Ticket [30b28cf351] #
89 ######################################
@@ -125,12 +97,11 @@
97
98 write_file f2 "line2"
99 fossil add f2
100 fossil commit -m "newfile"
101
102 fossil mv --hard f2 f2new
 
103 fossil commit -m "rename"
104
105 fossil update pivot
106 write_file f1 "line3"
107 fossil commit -b branch -m "change"
@@ -139,34 +110,33 @@
110 fossil commit -m "trunk merged"
111
112 fossil update trunk
113
114 fossil merge branch
115 test_status_list merge_renames-3 $RESULT {UPDATE f1}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117 ######################################
118 # Test 4 #
119 # Reported: Ticket [67176c3aa4] #
120 ######################################
121
122 test_setup
123
124 write_file f1 "f1"
125 fossil add f1
126 fossil commit -m "add f1"
127
128 write_file f1 "f1.1"
129 fossil commit --branch b -m "change f1"
130
131 fossil update trunk
132 fossil mv --hard f1 f2
133 fossil commit -m "f1 -> f2"
134
135 fossil merge b
136 test_status_list merge_renames-4-1 $RESULT {UPDATE f2}
137 test_file_contents merge_renames-4-2 f2 "f1.1"
138
139 ######################################
140 # Test 5 #
141 # Handle Rename/Add via Merge #
142 ######################################
@@ -180,25 +150,325 @@
150 write_file f3 "f3 line"
151 fossil add f3
152 fossil commit -m "branch file" -b branch_for_f3
153
154 fossil update trunk
155 fossil mv --hard f1 f2
 
156 write_file f1 "new f1 line"
157 fossil add f1
158 fossil commit -m "rename and add file with old name"
159
160 fossil update branch_for_f3
161 fossil merge trunk
162 test_status_list merge_renames-5-1 $RESULT {
163 RENAME f1 -> f2
164 ADDED f1
165 }
166
167 fossil commit -m "trunk merged, should have 3 files"
168
169 fossil ls
170
171 test merge_renames-5-2 {[normalize_result] eq {f1
172 f2
173 f3}}
174
175 #####################################
176 # Test 6 #
177 # Merging a branch multiple times #
178 #####################################
179
180 test_setup
181
182 write_file f1 "f1"
183 fossil add f1
184 fossil commit -m "add f1"
185
186 fossil mv --hard f1 f2
187 fossil commit -b b -m "f1 -> f2"
188
189 fossil update trunk
190 write_file f3 "f3"
191 write_file f4 "f4"
192 fossil add f3 f4
193 fossil ci -m "add f3, f4"
194
195 fossil mv --hard f3 f3-old
196 fossil mv --hard f4 f3
197 fossil mv --hard f3-old f4
198 fossil ci -m "swap f3 and f4"
199
200 write_file f1 "f1.1"
201 fossil commit -m "edit f1"
202
203 fossil update b
204 fossil merge trunk
205 fossil commit -m "merge trunk"
206
207 fossil update trunk
208 write_file f1 "f1.2"
209 write_file f3 "f3.1"
210 write_file f4 "f4.1"
211 fossil commit -m "edit f1, f4"
212
213 fossil update b
214 fossil merge trunk
215 test_status_list merge_renames-6-1 $RESULT {
216 UPDATE f2
217 UPDATE f3
218 UPDATE f4
219 }
220 test_file_contents merge_renames-6-2 f2 "f1.2"
221 test_file_contents merge_renames-6-3 f3 "f3.1"
222 test_file_contents merge_renames-6-4 f4 "f4.1"
223
224 ########################################################################
225 # Test 7 #
226 # Merging with an uncommitted rename of a file that has been renamed #
227 # in the merged branch and adding a new file with the original name #
228 ########################################################################
229
230 test_setup
231
232 write_file f1 "f1"
233 fossil add f1
234 fossil commit -m "add f1"
235
236 fossil mv --hard f1 f2
237 write_file f2 "f2"
238 fossil commit -b b -m "f1 -> f2, edit f2"
239
240 fossil update trunk
241 fossil mv --hard f1 f3
242 write_file f1 "f1.1"
243 fossil add f1
244 fossil merge b
245 test_status_list merge_renames-7-1 $RESULT {UPDATE f3}
246 test_file_contents merge_renames-7-2 f1 "f1.1"
247 test_file_contents merge_renames-7-3 f3 "f2"
248
249 ######################################################
250 # Test 8 #
251 # Merging two branches that both add the same file #
252 ######################################################
253
254 test_setup
255
256 write_file f1 "f1.1"
257 fossil add f1
258 fossil commit -b b1 -m "add f1"
259
260 fossil update trunk
261 write_file f1 "f1.2"
262 fossil add f1
263 fossil commit -b b2 -m "add f1"
264
265 fossil update trunk
266 fossil merge b1
267 fossil merge b2
268 test_status_list merge_renames-8-1 $RESULT {
269 WARNING: no common ancestor for f1
270 }
271
272 fossil revert
273 fossil merge --integrate b1
274 fossil merge b2
275 test_status_list merge_renames-8-2 $RESULT {
276 WARNING: no common ancestor for f1
277 }
278
279 #############################################
280 # Test 9 #
281 # Merging a delete/rename/add combination #
282 #############################################
283
284 test_setup
285
286 write_file f1 "f1"
287 write_file f2 "f2"
288 fossil add f1 f2
289 fossil commit -m "add files"
290
291 fossil rm --hard f2
292 fossil commit -b b -m "delete f2"
293
294 fossil mv --hard f1 f2
295 fossil commit -m "f1 -> f2"
296
297 write_file f1 "f1.1"
298 fossil add f1
299 fossil commit -m "add new f1"
300
301 fossil update trunk
302 fossil merge b
303 set expectedMerge {
304 DELETE f2
305 RENAME f1 -> f2
306 ADDED f1
307 }
308 test_status_list merge_renames-9-1 $RESULT $expectedMerge
309 fossil changes
310 test_status_list merge_renames-9-2 $RESULT "
311 MERGED_WITH [commit_id b]
312 ADDED_BY_MERGE f1
313 RENAMED f2
314 DELETED f2 (overwritten by rename)
315 "
316 test_file_contents merge_renames-9-3 f1 "f1.1"
317 test_file_contents merge_renames-9-4 f2 "f1"
318
319 # Undo and ensure a dry run merge results in no changes
320 fossil undo
321 test_status_list merge_renames-9-5 $RESULT {
322 UNDO f1
323 UNDO f2
324 }
325 fossil merge -n b
326 test_status_list merge_renames-9-6 $RESULT "
327 $expectedMerge
328 REMINDER: this was a dry run - no files were actually changed.
329 "
330 test merge_renames-9-7 {[fossil changes] eq ""}
331
332 ###################################################################
333 # Test 10 #
334 # Merge swapped filenames, backout the swap, then merge changes #
335 ###################################################################
336
337 test_setup
338
339 write_file f1 "f1"
340 write_file f2 "f2"
341 fossil add f1 f2
342 fossil commit -m "add files" ;# N
343
344 fossil mv --hard f1 f1-tmp
345 fossil mv --hard f2 f1
346 fossil mv --hard f1-tmp f2
347 fossil commit -b b -m "swap f1, f2" ;# P
348
349 fossil update trunk
350 fossil merge b
351 test_status_list merge_renames-10-1 $RESULT {
352 RENAME f1 -> f2
353 RENAME f2 -> f1
354 }
355 test_file_contents merge_renames-10-2 f1 "f2"
356 test_file_contents merge_renames-10-3 f2 "f1"
357 fossil commit -m "merge b"
358
359 fossil update b
360 write_file f1 f1.1
361 write_file f2 f2.1
362 fossil commit -m "edit" ;# M
363
364 fossil update trunk
365 fossil merge --backout trunk
366 test_status_list merge_renames-10-4 $RESULT {
367 RENAME f1 -> f2
368 RENAME f2 -> f1
369 }
370 test_file_contents merge_renames-10-5 f1 "f1"
371 test_file_contents merge_renames-10-6 f2 "f2"
372 test_status_list merge_renames-10-7 [fossil changes] "
373 RENAMED f1
374 RENAMED f2
375 BACKOUT [commit_id trunk]
376 "
377 fossil commit -m "swap back" ;# V
378
379 fossil merge b
380 test_status_list merge_renames-10-8 $RESULT {
381 UPDATE f1
382 UPDATE f2
383 }
384
385 test_file_contents merge_renames-10-9 f1 "f2.1"
386 test_file_contents merge_renames-10-10 f2 "f1.1"
387
388 ############################################
389 # Test 11 #
390 # Specifying a baseline #
391 ############################################
392
393 test_setup
394
395 write_file f1 "line"
396 fossil add f1
397 fossil commit -m "add f1"
398
399 write_file f1 "line\nline2"
400 fossil commit -b b -m "edit f2" --tag p1
401
402 fossil mv --hard f1 f2
403 fossil commit -m "f1 -> f2"
404
405 write_file f2 "line\nline2\nline3"
406 fossil commit -m "edit f2" --tag p2
407
408 write_file f2 "line\nline2\nline3\nline4"
409 fossil commit -m "edit f2"
410
411 fossil update trunk
412 fossil merge --baseline p1 b
413 test_status_list merge_renames-11-1 $RESULT {
414 MERGE f1
415 RENAME f1 -> f2
416 }
417 test_file_contents merge_renames-11-2 f2 "line\nline3\nline4"
418 fossil revert
419 fossil merge --baseline p2 b
420 test_status_list merge_renames-11-3 $RESULT {MERGE f1}
421 test_file_contents merge_renames-11-4 f1 "line\nline4"
422
423 #################################################################
424 # Test 12 #
425 # Merge involving a pivot that isn't a first-parent ancestor #
426 # of either the checked-out commit or the commit being merged #
427 #################################################################
428
429 test_setup
430
431 write_file f1 "f1\n"
432 fossil add f1
433 fossil commit -m "add f1" --tag n
434
435 fossil mv --hard f1 f1n
436 fossil commit -m "f1 -> f1n"
437
438 fossil mv --hard f1n f1v
439 write_file f1v "f1v\n"
440 fossil commit -b v -m "f1n -> f1v, edit f1v"
441
442 fossil update trunk
443 fossil mv --hard f1n f1m
444 fossil commit -b m -m "f1n -> f1m"
445
446 fossil update n
447 fossil mv --hard f1 f1p
448 write_file f1p "f1\np"
449 fossil commit -b p -m "f1 -> f1p, edit f1p"
450
451 fossil update m
452 fossil merge p
453 test_status_list merge_renames-12-1 $RESULT {UPDATE f1m}
454 test_file_contents merge_renames-12-2 f1m "f1\np"
455 fossil commit -m "merge p"
456
457 write_file f1m "f1\nm"
458 fossil commit -m "edit f1m"
459
460 fossil update v
461 fossil merge p
462 test_status_list merge_renames-12-3 $RESULT {MERGE f1v}
463 test_file_contents merge_renames-12-4 f1v "f1v\np"
464 fossil commit -m "merge p"
465
466 fossil merge m
467 test_status_list merge_renames-12-5 $RESULT {MERGE f1v}
468 test_file_contents merge_renames-12-6 f1v "f1v\nm"
469 fossil commit -m "merge m"
470
471 ######################################
472 #
473 # Tests for troubles not specifically linked with renames but that I'd like to
474 # write:
475
476 DDED test/merge_warn.test
--- a/test/merge_warn.test
+++ b/test/merge_warn.test
@@ -0,0 +1,55 @@
1
+#
2
+# Copyright (c) 2016 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
+# Testing "merge" command warnings
19
+#
20
+
21
+test_setup
22
+
23
+write_file f1 "f1"
24
+fossil add f1
25
+fossil commit -m "add f1" --tag pivot
26
+
27
+write_file f2 "f2"
28
+fossil add f2
29
+fossil commit -m "add f2"
30
+
31
+fossil update pivot
32
+fossil rm --hard f1
33
+write_file f2 "f2.1"
34
+write_file f3 "f3"
35
+fossil add f2 f3
36
+fossil commit -b b -m "delete f1, add f2 and f3" --tag mrg
37
+
38
+write_file f4 "f4"
39
+fossil add f4
40
+fossil commit -m "add f4"
41
+
42
+fossil update trunk
43
+write_file f1 "f1.1"
44
+write_file f3 "f3.1"
45
+f-integrate mrg -expectError
46
+test_status_list merge_warn-1 $RESULT {
47
+ WARNING: no common cts
48
+ DELETE f
49
+ WARNING: 1 merge conflicts
50
+ WARNING: 1 unmana}
51
+test merge_warn-2 {
52
+ [string first "ignoring --integrate: mrg is not a leaf" $RESULT]>=0
53
+}
54
+
55
+########################################
--- a/test/merge_warn.test
+++ b/test/merge_warn.test
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/merge_warn.test
+++ b/test/merge_warn.test
@@ -0,0 +1,55 @@
1 #
2 # Copyright (c) 2016 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 # Testing "merge" command warnings
19 #
20
21 test_setup
22
23 write_file f1 "f1"
24 fossil add f1
25 fossil commit -m "add f1" --tag pivot
26
27 write_file f2 "f2"
28 fossil add f2
29 fossil commit -m "add f2"
30
31 fossil update pivot
32 fossil rm --hard f1
33 write_file f2 "f2.1"
34 write_file f3 "f3"
35 fossil add f2 f3
36 fossil commit -b b -m "delete f1, add f2 and f3" --tag mrg
37
38 write_file f4 "f4"
39 fossil add f4
40 fossil commit -m "add f4"
41
42 fossil update trunk
43 write_file f1 "f1.1"
44 write_file f3 "f3.1"
45 f-integrate mrg -expectError
46 test_status_list merge_warn-1 $RESULT {
47 WARNING: no common cts
48 DELETE f
49 WARNING: 1 merge conflicts
50 WARNING: 1 unmana}
51 test merge_warn-2 {
52 [string first "ignoring --integrate: mrg is not a leaf" $RESULT]>=0
53 }
54
55 ########################################
--- test/tester.tcl
+++ test/tester.tcl
@@ -390,10 +390,29 @@
390390
protOut " Expected:\n [join $expected "\n "]" 1
391391
protOut " Got:\n [join $result "\n "]" 1
392392
test $name 0 $constraints
393393
}
394394
}
395
+
396
+# Perform a test on the contents of a file
397
+#
398
+proc test_file_contents {name path expected {constraints ""}} {
399
+ if {[file exists $path]} {
400
+ set result [read_file $path]
401
+ set passed [expr {$result eq $expected}]
402
+ if {!$passed} {
403
+ set expectedLines [split $expected "\n"]
404
+ set resultLines [split $result "\n"]
405
+ protOut " Expected:\n [join $expectedLines "\n "]" 1
406
+ protOut " Got:\n [join $resultLines "\n "]" 1
407
+ }
408
+ } else {
409
+ set passed 0
410
+ protOut " File does not exist: $path" 1
411
+ }
412
+ test $name $passed $constraints
413
+}
395414
396415
# Append all arguments into a single value and then returns it.
397416
#
398417
proc appendArgs {args} {
399418
eval append result $args
400419
401420
ADDED test/wiki.test
--- test/tester.tcl
+++ test/tester.tcl
@@ -390,10 +390,29 @@
390 protOut " Expected:\n [join $expected "\n "]" 1
391 protOut " Got:\n [join $result "\n "]" 1
392 test $name 0 $constraints
393 }
394 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
396 # Append all arguments into a single value and then returns it.
397 #
398 proc appendArgs {args} {
399 eval append result $args
400
401 DDED test/wiki.test
--- test/tester.tcl
+++ test/tester.tcl
@@ -390,10 +390,29 @@
390 protOut " Expected:\n [join $expected "\n "]" 1
391 protOut " Got:\n [join $result "\n "]" 1
392 test $name 0 $constraints
393 }
394 }
395
396 # Perform a test on the contents of a file
397 #
398 proc test_file_contents {name path expected {constraints ""}} {
399 if {[file exists $path]} {
400 set result [read_file $path]
401 set passed [expr {$result eq $expected}]
402 if {!$passed} {
403 set expectedLines [split $expected "\n"]
404 set resultLines [split $result "\n"]
405 protOut " Expected:\n [join $expectedLines "\n "]" 1
406 protOut " Got:\n [join $resultLines "\n "]" 1
407 }
408 } else {
409 set passed 0
410 protOut " File does not exist: $path" 1
411 }
412 test $name $passed $constraints
413 }
414
415 # Append all arguments into a single value and then returns it.
416 #
417 proc appendArgs {args} {
418 eval append result $args
419
420 DDED test/wiki.test
--- a/test/wiki.test
+++ b/test/wiki.test
@@ -0,0 +1,334 @@
1
+#
2
+# Copyright (c) 2016 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 wiki and attachment comman (c) 2016 D. Richard Hipp
19
+#
20
+# This program is free software; you can redistribute it and/or
21
+# modify it under the terms of the Simplified BSD License (also
22
+# known as the "2buted in the hoperegsub -all { +\n} $x \n x
23
+ (c) 2016 D. Richard Hipp
24
+#
25
+# #
26
+# Copyright (c) 201 that it will be usefuy \n y
27
+ (c) 2016 D. Richard #
28
+# Coi.com
29
+# http://www.hwaci.com/drh/
30
+#
31
+############################################################################
32
+#
33
+# Test wiki and attachment command Support
34
+#
35
+
36
+test_setup
37
+
38
+# Disable backoffice for this test, otherwise its process lingers for some
39
+# time after the test has completed.
40
+# Perhaps, this should be done in test_setup and enabled explicitly only
41
+# when needed.
42
+fossil set backoffice-disable 1
43
+
44
+# Return true if two files are similar (i.e not only compress trailing spaces
45
+# from a lset CODE [regex regsub -all { +\n} $x \n x
46
+ No info link found [read_file $b]
47
+ regsub -all { +http << "GET /artifact/$info D. Richard Hip#
48
+# Copyright {a b} {
49
+ set x ""
50
+ if {[file exists $a]} {
51
+ set x [read_file $a]
52
+ regsub -all { +\n} $x \n x
53
+ regsub -all {\n$} $x {} x
54
+ }
55
+ set y ""
56
+ if {[file exists $b]} {
57
+ set y [read_file $b]
58
+ regsub -all { +\n} $y \n y
59
+ regsub -all {\n$} $y {} y
60
+ }
61
+ return [expr {$x==$y}]
62
+}
63
+
64
+# Return the mime type in the manifest for a given wiki page
65
+# Defaults to "error: some text" if the manifest can't be located and
66
+# "text/x-fossil-wiki" (the default mimetype for rendering)
67
+# if the N card is omitted in the manifest.
68
+# Note: Makes fossil calls, so $CODE and $RESULT will be corrupted
69
+proc get_mime_type {name} {
70
+ global CODE RESULT
71
+ fossil http << "GET /wiki?name=$name"
72
+ if {$CODE != 0} {
73
+ return "error: /wiki?name=$name $CODE $RESULT"
74
+ }
75
+ fossil whatis --type w $name
76
+ if {$CODE != 0} {
77
+ return "error: fossil whatis --type w $name $CODE $RESULT"
78
+ }
79
+ set CODE [regexp -line {^artifact:\s*([0-9a-f]+)$} $RESULT match info]
80
+ if {$CODE == 0} {
81
+ return "error: whatis returned no info for wiki page $name"
82
+ }
83
+ fossil artifact $info
84
+ if {$CODE != 0} {
85
+ return "error: fossil artifact $info $CODE $RESULT"
86
+ }
87
+ set CODE [regexp -line {^N (.*)$} $RESULT match mimetype]
88
+ if {$CODE == 0} {
89
+ return "text/x-fossil-wiki"
90
+ }
91
+ return $mimetype
92
+}
93
+
94
+
95
+###############################################################################
96
+# Initially there should be no wiki entries
97
+fossil wiki list
98
+test wiki-0 {[normalize_result] eq {}}
99
+
100
+###############################################################################
101
+# Adding an entry should add it to the wiki list
102
+write_file f1 "first wiki note"
103
+fossil wiki create tcltest f1
104
+test wiki-1 {$CODE == 0}
105
+fossil wiki list
106
+test wiki-2 {[normalize_result] eq {tcltest}}
107
+
108
+###############################################################################
109
+# Trying to add the same entry should fail
110
+fossil wiki create tcltest f1 -expectError
111
+test wiki-3 {$CODE != 0}
112
+
113
+###############################################################################
114
+# exporting the wiki page should give back similar text
115
+fossil wiki export tcltest a1
116
+test wiki-4 {[similar_file f1 a1]}
117
+
118
+###############################################################################
119
+# commiting a change to an existing page should replace the page on export
120
+write_file f2 "second version of the page"
121
+fossil wiki commit tcltest f2
122
+test wiki-5 {$CODE == 0}
123
+fossil wiki export tcltest a2
124
+test wiki-6 {[similar_file f2 a2]}
125
+
126
+###############################################################################
127
+# But we shouldn't be able to update non-existant pages
128
+fossil wiki commit doesntexist f1 -expectError
129
+test wiki-7 {$CODE != 0}
130
+
131
+###############################################################################
132
+# There shouldn't be any tech notes at this point
133
+fossil wiki list --technote
134
+test wiki-8 {[normalize_result] eq {}}
135
+
136
+###############################################################################
137
+# Creating a tech note with a specified timestamp should add a technote
138
+write_file f3 "A technote"
139
+f ossil wiki create technote f3 --technote {2016-01-01 12:34}
140
+test wiki-9 {$CODE == 0}
141
+fossil wiki list --technote
142
+test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}}
143
+fossil wiki list --technote --show-technote-ids
144
+set technotelist [split $RESULT "\n"]
145
+set veryfirsttechnoteid [lindex [split [lindex $technotelist 0]] 0]
146
+
147
+###############################################################################
148
+# exporting that technote should give back similar text
149
+fossil wiki export a3 --technote {2016-01-01 12:34:00}
150
+test wiki-11 {[similar_file f3 a3]}
151
+
152
+###############################################################################
153
+# Trying to add a technote with the same timestamp should succeed and create a
154
+# second tech note
155
+fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34}
156
+test wiki-13 {$CODE == 0}
157
+fossil wiki list --technote
158
+set technotelist [split $RESULT "\n"]
159
+test wiki-13.1 {[llength $technotelist] == 2}
160
+
161
+###############################################################################
162
+# commiting a change to an existing technote should replace the page on export
163
+# (this should update th rt
164
+# (this should update the tech note from wiki-13 as that the most recently
165
+# updated one, that should also be the one exported by the export command)
166
+write_file f4 "technote 2nd variant"
167
+fossil wiki commit technote f4 --technote {2016-01-01 12:34}
168
+test wiki-14 {$CODE == 0}
169
+fossil wiki export a4 --technote {2016-01-01 12:34}
170
+test wiki-15 {[similar_file f4 a4]}
171
+# Also check that the tech note with the same timestamp, but modified less
172
+# recently still has its original text
173
+fossil wiki export a4.1 --technote $veryfirsttechnoteid
174
+test wiki-15.1 {[similar_file f3 a4.1]}
175
+
176
+###############################################################################
177
+# But we shouldn't be able to update non-existant pages
178
+fossil wiki commit doesntexist f1 -expectError
179
+test wiki-16 {$CODE != 0}
180
+
181
+###############################################################################
182
+# Check specifying tags for a technote is OK
183
+write_file f5 "technote with tags"
184
+fossil wiki create {tagged technote} f5 --technote {2016-01-02 12:34} --technote-tags {A B}
185
+test wiki-17 {$CODE == 0}
186
+write_file f5.1 "editted and tagged technote"
187
+fossil wiki commit {tagged technote} f5 --technote {2016-01-02 12:34} --t note {2016-01 -03 12:34} --technote-bgcolor blue
188
+test wiki-28 {$CODE == 0}
189
+
190
+###############################################################################
191
+# _file f7 "Different timestamps"
192
+fossil wiki create technotenow f7 --technote {2016-01-04 12:34:56+00:00}
193
+test wiki-29 {$CODE == 0}
194
+
195
+###############################################################################
196
+# Check a technote appears on the timeline
197
+write_file f8 "Contents of a 'unique' tech note"
198
+fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
199
+fossil timeline
200
+test wiki-30 {[string match *Unique*technote* $RESULT]}
201
+
202
+###############################################################################
203
+# Check for a collision between an attachment and a note, this was a
204
+# bug that resulted from some code treating the attachment entry as if it
205
+# were a technote when it isn't really.
206
+#
207
+# First, wait for the top of the next second so the attachment
208
+# happens at a known time, then add an attachment to an existing note
209
+# and a new note immediately after.
210
+
211
+set t0 [clock seconds]
212
+while {$t0 == [clock seconds]} {
213
+ after 100
214
+}
215
+set t1 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
216
+write_fil -%m-%d %H:%M:%S"]
217
+write_file f9 "Timestamp: $t1"
218
+fossil attachment add f9 --technote {2016-01-05 01:02:03}
219
+test wiki-31 {$CODE == 0}
220
+fossil wiki create {A CODE == 0}
221
+#
222
+# Now waste time until the next second so that the remaining tests
223
+# don't have to worry about a potential collision
224
+set t0 [clock seconds]
225
+while {$t0 == [clock seconds]} {
226
+ after 100
227
+}
228
+
229
+###############################################################################
230
+# Check a technote with no timestamp cannot be created, but that
231
+# "now " is a valid stamp.
232
+set t2 [clock format [clock seconds] -gmt 1 -format # Copyright (c) 2016 D. Richard Hiiotelist [llength $technotelified timest ki create technotenow f7 --technote {2016-01-04 12:34:56+00:00}
233
+test wiki-29 {$CODE == 0}
234
+
235
+###############################################################################
236
+# Check a technote appears on the timeline
237
+write_file f8 "Contents of a 'unique' tech note"
238
+fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
239
+fossil timeline
240
+test wiki-30 {[string match *Unique*technote* $RESULT]}
241
+
242
+###############################################################################
243
+# Check for a collision between an attachment and a note, this was a
244
+# bug that resulted from some code treating the attachment entry as if it
245
+# were a technote when it isn't really.
246
+#
247
+# First, wait for the top of the next second so the attachment
248
+# happens at a known time, then add an attachment to an existing note
249
+# and a new note immediately after.
250
+
251
+set t0 [clock seconds]
252
+while {$t0 == [clock seconds]} {
253
+ after 100
254
+}
255
+set t1 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
256
+write_file f9 "Timestamp: $t1"
257
+fossil attachment add f9 --technote {2016-01-05 01:02:03}
258
+test wiki-31 {$CODE == 0}
259
+fossil wiki create {Attachment collision} f9 --technote now
260
+test wiki-32 {$CODE == 0}
261
+#
262
+# Now waste time until the next second so that the remaining tests
263
+# don't have to worry about a potential collision
264
+set t0 [clock seconds]
265
+while {$t0 == [clock seconds]} {
266
+ after 100
267
+}
268
+
269
+###############################################################################
270
+# Check a technote with no timestamp cannot be created, but that
271
+# "now" is a valid stamp.
272
+s et t2 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
273
+write_file f10 "Even unstampted notes are delivered.\nStamped $t2"
274
+fossil wiki create "Unstamped Note" f10 --technote -expectError
275
+test wiki-33 {$CODE != 0}
276
+fossil wiki create "Unstamped Note" f10 --technote now
277
+test wiki-34 {$CODE == 0}
278
+fossil wiki list -t
279
+test wiki-35 {[string match "*$t2*" $RESULT]}
280
+
281
+###############################################################################
282
+# Check an attachment to it in the same second works.
283
+write_file f11 "Time Stamp was $t2"
284
+fossil attachment add f11 --technote $t2
285
+test wiki-36 {$CODE == 0}
286
+fossil timeline
287
+test wiki-36-1 {$CODE == 0}
288
+fossil wiki list -t
289
+test wiki-36-2 {$CODE == 0}
290
+
291
+########################################################################### #technotelist [split $RESULT "\n"]
292
+for {set i 0} {$i < [llength $technotelist]} {incr i} {
293
+ set fullid [lindex $technotelist $i]
294
+ set id [string range $fullid 0 3]
295
+ dict incr idcounts $id
296
+ if {[dict get $idcounts $id] > $maxcount} {
297
+ set maxid $id
298
+ incr maxcount
299
+ }
300
+}
301
+# get i so that, as a julian date, it is in the 1800s, i.e., older than
302
+# any other tech note, but after 1 AD
303
+set i 2400000
304
+while {$maxcount < 2} {
305
+ # keep getting older
306
+ incr i -1
307
+ write_file f13 "A tech note with timestamp of jday=$i"
308
+ fossil wiki create "timestamp of $i" f13 --technote "$i"
309
+ fossil wiki list --technote --show-technote-ids
310
+ set technotelist [split $RESULT "\n"]
311
+ set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
312
+ set id [string range $oldesttechnoteid 0 3]
313
+ dict incr idcounts $id
314
+ if {[dict get $idcounts $id] > $maxcount} {
315
+ set maxid $id
316
+ incr maxcount
317
+ }
318
+}
319
+# Save the duplicate id for this and later tests
320
+set duplicateid $maxid
321
+fossil wiki export a13 --technote $duplicateid -expectError
322
+test wiki-42 {$CODE != 0}
323
+
324
+###############################################################################
325
+# Check we can update technote by its id
326
+write_file f14 "Updated text for the really old tech note"
327
+fossil wiki commit {Old tech note} f14 --technote $anoldtechnoteid
328
+fossil wiki export a14 --technote $anoldtechnoteid
329
+test wiki-43 {[similar_file f14 a14]}
330
+
331
+###############################################################################
332
+# Check we can add attachments to a technote by its id
333
+fossil attachment add fa --technote $anoldtechnoteid
334
+test
--- a/test/wiki.test
+++ b/test/wiki.test
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/test/wiki.test
+++ b/test/wiki.test
@@ -0,0 +1,334 @@
1 #
2 # Copyright (c) 2016 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 wiki and attachment comman (c) 2016 D. Richard Hipp
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the Simplified BSD License (also
22 # known as the "2buted in the hoperegsub -all { +\n} $x \n x
23 (c) 2016 D. Richard Hipp
24 #
25 # #
26 # Copyright (c) 201 that it will be usefuy \n y
27 (c) 2016 D. Richard #
28 # Coi.com
29 # http://www.hwaci.com/drh/
30 #
31 ############################################################################
32 #
33 # Test wiki and attachment command Support
34 #
35
36 test_setup
37
38 # Disable backoffice for this test, otherwise its process lingers for some
39 # time after the test has completed.
40 # Perhaps, this should be done in test_setup and enabled explicitly only
41 # when needed.
42 fossil set backoffice-disable 1
43
44 # Return true if two files are similar (i.e not only compress trailing spaces
45 # from a lset CODE [regex regsub -all { +\n} $x \n x
46 No info link found [read_file $b]
47 regsub -all { +http << "GET /artifact/$info D. Richard Hip#
48 # Copyright {a b} {
49 set x ""
50 if {[file exists $a]} {
51 set x [read_file $a]
52 regsub -all { +\n} $x \n x
53 regsub -all {\n$} $x {} x
54 }
55 set y ""
56 if {[file exists $b]} {
57 set y [read_file $b]
58 regsub -all { +\n} $y \n y
59 regsub -all {\n$} $y {} y
60 }
61 return [expr {$x==$y}]
62 }
63
64 # Return the mime type in the manifest for a given wiki page
65 # Defaults to "error: some text" if the manifest can't be located and
66 # "text/x-fossil-wiki" (the default mimetype for rendering)
67 # if the N card is omitted in the manifest.
68 # Note: Makes fossil calls, so $CODE and $RESULT will be corrupted
69 proc get_mime_type {name} {
70 global CODE RESULT
71 fossil http << "GET /wiki?name=$name"
72 if {$CODE != 0} {
73 return "error: /wiki?name=$name $CODE $RESULT"
74 }
75 fossil whatis --type w $name
76 if {$CODE != 0} {
77 return "error: fossil whatis --type w $name $CODE $RESULT"
78 }
79 set CODE [regexp -line {^artifact:\s*([0-9a-f]+)$} $RESULT match info]
80 if {$CODE == 0} {
81 return "error: whatis returned no info for wiki page $name"
82 }
83 fossil artifact $info
84 if {$CODE != 0} {
85 return "error: fossil artifact $info $CODE $RESULT"
86 }
87 set CODE [regexp -line {^N (.*)$} $RESULT match mimetype]
88 if {$CODE == 0} {
89 return "text/x-fossil-wiki"
90 }
91 return $mimetype
92 }
93
94
95 ###############################################################################
96 # Initially there should be no wiki entries
97 fossil wiki list
98 test wiki-0 {[normalize_result] eq {}}
99
100 ###############################################################################
101 # Adding an entry should add it to the wiki list
102 write_file f1 "first wiki note"
103 fossil wiki create tcltest f1
104 test wiki-1 {$CODE == 0}
105 fossil wiki list
106 test wiki-2 {[normalize_result] eq {tcltest}}
107
108 ###############################################################################
109 # Trying to add the same entry should fail
110 fossil wiki create tcltest f1 -expectError
111 test wiki-3 {$CODE != 0}
112
113 ###############################################################################
114 # exporting the wiki page should give back similar text
115 fossil wiki export tcltest a1
116 test wiki-4 {[similar_file f1 a1]}
117
118 ###############################################################################
119 # commiting a change to an existing page should replace the page on export
120 write_file f2 "second version of the page"
121 fossil wiki commit tcltest f2
122 test wiki-5 {$CODE == 0}
123 fossil wiki export tcltest a2
124 test wiki-6 {[similar_file f2 a2]}
125
126 ###############################################################################
127 # But we shouldn't be able to update non-existant pages
128 fossil wiki commit doesntexist f1 -expectError
129 test wiki-7 {$CODE != 0}
130
131 ###############################################################################
132 # There shouldn't be any tech notes at this point
133 fossil wiki list --technote
134 test wiki-8 {[normalize_result] eq {}}
135
136 ###############################################################################
137 # Creating a tech note with a specified timestamp should add a technote
138 write_file f3 "A technote"
139 f ossil wiki create technote f3 --technote {2016-01-01 12:34}
140 test wiki-9 {$CODE == 0}
141 fossil wiki list --technote
142 test wiki-10 {[normalize_result] eq {2016-01-01 12:34:00}}
143 fossil wiki list --technote --show-technote-ids
144 set technotelist [split $RESULT "\n"]
145 set veryfirsttechnoteid [lindex [split [lindex $technotelist 0]] 0]
146
147 ###############################################################################
148 # exporting that technote should give back similar text
149 fossil wiki export a3 --technote {2016-01-01 12:34:00}
150 test wiki-11 {[similar_file f3 a3]}
151
152 ###############################################################################
153 # Trying to add a technote with the same timestamp should succeed and create a
154 # second tech note
155 fossil wiki create 2ndnote f3 -technote {2016-01-01 12:34}
156 test wiki-13 {$CODE == 0}
157 fossil wiki list --technote
158 set technotelist [split $RESULT "\n"]
159 test wiki-13.1 {[llength $technotelist] == 2}
160
161 ###############################################################################
162 # commiting a change to an existing technote should replace the page on export
163 # (this should update th rt
164 # (this should update the tech note from wiki-13 as that the most recently
165 # updated one, that should also be the one exported by the export command)
166 write_file f4 "technote 2nd variant"
167 fossil wiki commit technote f4 --technote {2016-01-01 12:34}
168 test wiki-14 {$CODE == 0}
169 fossil wiki export a4 --technote {2016-01-01 12:34}
170 test wiki-15 {[similar_file f4 a4]}
171 # Also check that the tech note with the same timestamp, but modified less
172 # recently still has its original text
173 fossil wiki export a4.1 --technote $veryfirsttechnoteid
174 test wiki-15.1 {[similar_file f3 a4.1]}
175
176 ###############################################################################
177 # But we shouldn't be able to update non-existant pages
178 fossil wiki commit doesntexist f1 -expectError
179 test wiki-16 {$CODE != 0}
180
181 ###############################################################################
182 # Check specifying tags for a technote is OK
183 write_file f5 "technote with tags"
184 fossil wiki create {tagged technote} f5 --technote {2016-01-02 12:34} --technote-tags {A B}
185 test wiki-17 {$CODE == 0}
186 write_file f5.1 "editted and tagged technote"
187 fossil wiki commit {tagged technote} f5 --technote {2016-01-02 12:34} --t note {2016-01 -03 12:34} --technote-bgcolor blue
188 test wiki-28 {$CODE == 0}
189
190 ###############################################################################
191 # _file f7 "Different timestamps"
192 fossil wiki create technotenow f7 --technote {2016-01-04 12:34:56+00:00}
193 test wiki-29 {$CODE == 0}
194
195 ###############################################################################
196 # Check a technote appears on the timeline
197 write_file f8 "Contents of a 'unique' tech note"
198 fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
199 fossil timeline
200 test wiki-30 {[string match *Unique*technote* $RESULT]}
201
202 ###############################################################################
203 # Check for a collision between an attachment and a note, this was a
204 # bug that resulted from some code treating the attachment entry as if it
205 # were a technote when it isn't really.
206 #
207 # First, wait for the top of the next second so the attachment
208 # happens at a known time, then add an attachment to an existing note
209 # and a new note immediately after.
210
211 set t0 [clock seconds]
212 while {$t0 == [clock seconds]} {
213 after 100
214 }
215 set t1 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
216 write_fil -%m-%d %H:%M:%S"]
217 write_file f9 "Timestamp: $t1"
218 fossil attachment add f9 --technote {2016-01-05 01:02:03}
219 test wiki-31 {$CODE == 0}
220 fossil wiki create {A CODE == 0}
221 #
222 # Now waste time until the next second so that the remaining tests
223 # don't have to worry about a potential collision
224 set t0 [clock seconds]
225 while {$t0 == [clock seconds]} {
226 after 100
227 }
228
229 ###############################################################################
230 # Check a technote with no timestamp cannot be created, but that
231 # "now " is a valid stamp.
232 set t2 [clock format [clock seconds] -gmt 1 -format # Copyright (c) 2016 D. Richard Hiiotelist [llength $technotelified timest ki create technotenow f7 --technote {2016-01-04 12:34:56+00:00}
233 test wiki-29 {$CODE == 0}
234
235 ###############################################################################
236 # Check a technote appears on the timeline
237 write_file f8 "Contents of a 'unique' tech note"
238 fossil wiki create {Unique technote} f8 --technote {2016-01-05 01:02:03}
239 fossil timeline
240 test wiki-30 {[string match *Unique*technote* $RESULT]}
241
242 ###############################################################################
243 # Check for a collision between an attachment and a note, this was a
244 # bug that resulted from some code treating the attachment entry as if it
245 # were a technote when it isn't really.
246 #
247 # First, wait for the top of the next second so the attachment
248 # happens at a known time, then add an attachment to an existing note
249 # and a new note immediately after.
250
251 set t0 [clock seconds]
252 while {$t0 == [clock seconds]} {
253 after 100
254 }
255 set t1 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
256 write_file f9 "Timestamp: $t1"
257 fossil attachment add f9 --technote {2016-01-05 01:02:03}
258 test wiki-31 {$CODE == 0}
259 fossil wiki create {Attachment collision} f9 --technote now
260 test wiki-32 {$CODE == 0}
261 #
262 # Now waste time until the next second so that the remaining tests
263 # don't have to worry about a potential collision
264 set t0 [clock seconds]
265 while {$t0 == [clock seconds]} {
266 after 100
267 }
268
269 ###############################################################################
270 # Check a technote with no timestamp cannot be created, but that
271 # "now" is a valid stamp.
272 s et t2 [clock format [clock seconds] -gmt 1 -format "%Y-%m-%d %H:%M:%S"]
273 write_file f10 "Even unstampted notes are delivered.\nStamped $t2"
274 fossil wiki create "Unstamped Note" f10 --technote -expectError
275 test wiki-33 {$CODE != 0}
276 fossil wiki create "Unstamped Note" f10 --technote now
277 test wiki-34 {$CODE == 0}
278 fossil wiki list -t
279 test wiki-35 {[string match "*$t2*" $RESULT]}
280
281 ###############################################################################
282 # Check an attachment to it in the same second works.
283 write_file f11 "Time Stamp was $t2"
284 fossil attachment add f11 --technote $t2
285 test wiki-36 {$CODE == 0}
286 fossil timeline
287 test wiki-36-1 {$CODE == 0}
288 fossil wiki list -t
289 test wiki-36-2 {$CODE == 0}
290
291 ########################################################################### #technotelist [split $RESULT "\n"]
292 for {set i 0} {$i < [llength $technotelist]} {incr i} {
293 set fullid [lindex $technotelist $i]
294 set id [string range $fullid 0 3]
295 dict incr idcounts $id
296 if {[dict get $idcounts $id] > $maxcount} {
297 set maxid $id
298 incr maxcount
299 }
300 }
301 # get i so that, as a julian date, it is in the 1800s, i.e., older than
302 # any other tech note, but after 1 AD
303 set i 2400000
304 while {$maxcount < 2} {
305 # keep getting older
306 incr i -1
307 write_file f13 "A tech note with timestamp of jday=$i"
308 fossil wiki create "timestamp of $i" f13 --technote "$i"
309 fossil wiki list --technote --show-technote-ids
310 set technotelist [split $RESULT "\n"]
311 set oldesttechnoteid [lindex [split [lindex $technotelist [llength $technotelist]-1]] 0]
312 set id [string range $oldesttechnoteid 0 3]
313 dict incr idcounts $id
314 if {[dict get $idcounts $id] > $maxcount} {
315 set maxid $id
316 incr maxcount
317 }
318 }
319 # Save the duplicate id for this and later tests
320 set duplicateid $maxid
321 fossil wiki export a13 --technote $duplicateid -expectError
322 test wiki-42 {$CODE != 0}
323
324 ###############################################################################
325 # Check we can update technote by its id
326 write_file f14 "Updated text for the really old tech note"
327 fossil wiki commit {Old tech note} f14 --technote $anoldtechnoteid
328 fossil wiki export a14 --technote $anoldtechnoteid
329 test wiki-43 {[similar_file f14 a14]}
330
331 ###############################################################################
332 # Check we can add attachments to a technote by its id
333 fossil attachment add fa --technote $anoldtechnoteid
334 test
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -88,10 +88,14 @@
8888
# FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
8989
9090
#### Use 'system' SQLite
9191
#
9292
# USE_SYSTEM_SQLITE = 1
93
+
94
+#### Use the SQLite Encryption Extension
95
+#
96
+# USE_SEE = 1
9397
9498
#### Use the miniz compression library
9599
#
96100
# FOSSIL_ENABLE_MINIZ = 1
97101
@@ -158,11 +162,11 @@
158162
#### The directories where the OpenSSL include and library files are located.
159163
# The recommended usage here is to use the Sysinternals junction tool
160164
# to create a hard link between an "openssl-1.x" sub-directory of the
161165
# Fossil source code directory and the target OpenSSL source directory.
162166
#
163
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
167
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
164168
OPENSSLINCDIR = $(OPENSSLDIR)/include
165169
OPENSSLLIBDIR = $(OPENSSLDIR)
166170
167171
#### Either the directory where the Tcl library is installed or the Tcl
168172
# source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
313317
# With JSON support
314318
ifdef FOSSIL_ENABLE_JSON
315319
TCC += -DFOSSIL_ENABLE_JSON=1
316320
RCC += -DFOSSIL_ENABLE_JSON=1
317321
endif
322
+
323
+# With SQLite Encryption Extension support
324
+ifdef USE_SEE
325
+TCC += -DUSE_SEE=1
326
+RCC += -DUSE_SEE=1
327
+endif
318328
319329
#### The option -static has no effect on MinGW(-w64), only dynamic
320330
# executables can be built when linking with MSVCRT. OpenSSL
321331
# (optional) and zlib (required) however are always linked in
322332
# statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
921931
# set to 1. If it is set to 1, the miniz library included in the
922932
# source tree should be used; otherwise, it should not.
923933
MINIZ_OBJ.0 =
924934
MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925935
MINIZ_OBJ. = $(MINIZ_OBJ.0)
936
+
937
+# The USE_SEE variable may be undefined, 0 or 1. If undefined or
938
+# 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
939
+# the source tree) is used and extra flags are provided to enable
940
+# the SQLite Encryption Extension.
941
+SQLITE3_SRC.1 = sqlite3-see.c
942
+SQLITE3_SRC.0 = sqlite3.c
943
+SQLITE3_SRC. = sqlite3.c
944
+SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
945
+SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
946
+SEE_FLAGS.0 =
947
+SEE_FLAGS. =
948
+SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
926949
927950
928951
EXTRAOBJ = \
929952
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930953
$(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
21132136
21142137
MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
21152138
-DMINIZ_NO_TIME \
21162139
-DMINIZ_NO_ARCHIVE_APIS
21172140
2118
-$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
2119
- $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2141
+$(OBJDIR)/sqlite3.o: $(SQLITE3_SRC) $(SRCDIR)/../win/Makefile.mingw
2142
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
2143
+ -c $(SQLITE3_SRC) -o $@
21202144
21212145
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
21222146
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
21232147
21242148
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
21252149
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -88,10 +88,14 @@
88 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
 
 
 
 
93
94 #### Use the miniz compression library
95 #
96 # FOSSIL_ENABLE_MINIZ = 1
97
@@ -158,11 +162,11 @@
158 #### The directories where the OpenSSL include and library files are located.
159 # The recommended usage here is to use the Sysinternals junction tool
160 # to create a hard link between an "openssl-1.x" sub-directory of the
161 # Fossil source code directory and the target OpenSSL source directory.
162 #
163 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
164 OPENSSLINCDIR = $(OPENSSLDIR)/include
165 OPENSSLLIBDIR = $(OPENSSLDIR)
166
167 #### Either the directory where the Tcl library is installed or the Tcl
168 # source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
313 # With JSON support
314 ifdef FOSSIL_ENABLE_JSON
315 TCC += -DFOSSIL_ENABLE_JSON=1
316 RCC += -DFOSSIL_ENABLE_JSON=1
317 endif
 
 
 
 
 
 
318
319 #### The option -static has no effect on MinGW(-w64), only dynamic
320 # executables can be built when linking with MSVCRT. OpenSSL
321 # (optional) and zlib (required) however are always linked in
322 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
921 # set to 1. If it is set to 1, the miniz library included in the
922 # source tree should be used; otherwise, it should not.
923 MINIZ_OBJ.0 =
924 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925 MINIZ_OBJ. = $(MINIZ_OBJ.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
926
927
928 EXTRAOBJ = \
929 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
2113
2114 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2115 -DMINIZ_NO_TIME \
2116 -DMINIZ_NO_ARCHIVE_APIS
2117
2118 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
2119 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
 
2120
2121 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2122 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
2123
2124 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
2125
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -88,10 +88,14 @@
88 # FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
94 #### Use the SQLite Encryption Extension
95 #
96 # USE_SEE = 1
97
98 #### Use the miniz compression library
99 #
100 # FOSSIL_ENABLE_MINIZ = 1
101
@@ -158,11 +162,11 @@
162 #### The directories where the OpenSSL include and library files are located.
163 # The recommended usage here is to use the Sysinternals junction tool
164 # to create a hard link between an "openssl-1.x" sub-directory of the
165 # Fossil source code directory and the target OpenSSL source directory.
166 #
167 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
168 OPENSSLINCDIR = $(OPENSSLDIR)/include
169 OPENSSLLIBDIR = $(OPENSSLDIR)
170
171 #### Either the directory where the Tcl library is installed or the Tcl
172 # source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
317 # With JSON support
318 ifdef FOSSIL_ENABLE_JSON
319 TCC += -DFOSSIL_ENABLE_JSON=1
320 RCC += -DFOSSIL_ENABLE_JSON=1
321 endif
322
323 # With SQLite Encryption Extension support
324 ifdef USE_SEE
325 TCC += -DUSE_SEE=1
326 RCC += -DUSE_SEE=1
327 endif
328
329 #### The option -static has no effect on MinGW(-w64), only dynamic
330 # executables can be built when linking with MSVCRT. OpenSSL
331 # (optional) and zlib (required) however are always linked in
332 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
931 # set to 1. If it is set to 1, the miniz library included in the
932 # source tree should be used; otherwise, it should not.
933 MINIZ_OBJ.0 =
934 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
935 MINIZ_OBJ. = $(MINIZ_OBJ.0)
936
937 # The USE_SEE variable may be undefined, 0 or 1. If undefined or
938 # 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
939 # the source tree) is used and extra flags are provided to enable
940 # the SQLite Encryption Extension.
941 SQLITE3_SRC.1 = sqlite3-see.c
942 SQLITE3_SRC.0 = sqlite3.c
943 SQLITE3_SRC. = sqlite3.c
944 SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
945 SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
946 SEE_FLAGS.0 =
947 SEE_FLAGS. =
948 SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
949
950
951 EXTRAOBJ = \
952 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
953 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
2136
2137 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2138 -DMINIZ_NO_TIME \
2139 -DMINIZ_NO_ARCHIVE_APIS
2140
2141 $(OBJDIR)/sqlite3.o: $(SQLITE3_SRC) $(SRCDIR)/../win/Makefile.mingw
2142 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
2143 -c $(SQLITE3_SRC) -o $@
2144
2145 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2146 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
2147
2148 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
2149
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -88,10 +88,14 @@
8888
FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
8989
9090
#### Use 'system' SQLite
9191
#
9292
# USE_SYSTEM_SQLITE = 1
93
+
94
+#### Use the SQLite Encryption Extension
95
+#
96
+# USE_SEE = 1
9397
9498
#### Use the miniz compression library
9599
#
96100
# FOSSIL_ENABLE_MINIZ = 1
97101
@@ -158,11 +162,11 @@
158162
#### The directories where the OpenSSL include and library files are located.
159163
# The recommended usage here is to use the Sysinternals junction tool
160164
# to create a hard link between an "openssl-1.x" sub-directory of the
161165
# Fossil source code directory and the target OpenSSL source directory.
162166
#
163
-OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
167
+OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
164168
OPENSSLINCDIR = $(OPENSSLDIR)/include
165169
OPENSSLLIBDIR = $(OPENSSLDIR)
166170
167171
#### Either the directory where the Tcl library is installed or the Tcl
168172
# source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
313317
# With JSON support
314318
ifdef FOSSIL_ENABLE_JSON
315319
TCC += -DFOSSIL_ENABLE_JSON=1
316320
RCC += -DFOSSIL_ENABLE_JSON=1
317321
endif
322
+
323
+# With SQLite Encryption Extension support
324
+ifdef USE_SEE
325
+TCC += -DUSE_SEE=1
326
+RCC += -DUSE_SEE=1
327
+endif
318328
319329
#### The option -static has no effect on MinGW(-w64), only dynamic
320330
# executables can be built when linking with MSVCRT. OpenSSL
321331
# (optional) and zlib (required) however are always linked in
322332
# statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
921931
# set to 1. If it is set to 1, the miniz library included in the
922932
# source tree should be used; otherwise, it should not.
923933
MINIZ_OBJ.0 =
924934
MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925935
MINIZ_OBJ. = $(MINIZ_OBJ.0)
936
+
937
+# The USE_SEE variable may be undefined, 0 or 1. If undefined or
938
+# 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
939
+# the source tree) is used and extra flags are provided to enable
940
+# the SQLite Encryption Extension.
941
+SQLITE3_SRC.1 = sqlite3-see.c
942
+SQLITE3_SRC.0 = sqlite3.c
943
+SQLITE3_SRC. = sqlite3.c
944
+SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
945
+SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
946
+SEE_FLAGS.0 =
947
+SEE_FLAGS. =
948
+SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
926949
927950
928951
EXTRAOBJ = \
929952
$(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930953
$(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
21132136
21142137
MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
21152138
-DMINIZ_NO_TIME \
21162139
-DMINIZ_NO_ARCHIVE_APIS
21172140
2118
-$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw.mistachkin
2119
- $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
2141
+$(OBJDIR)/sqlite3.o: $(SQLITE3_SRC) $(SRCDIR)/../win/Makefile.mingw.mistachkin
2142
+ $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
2143
+ -c $(SQLITE3_SRC) -o $@
21202144
21212145
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
21222146
$(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
21232147
21242148
$(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
21252149
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -88,10 +88,14 @@
88 FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
 
 
 
 
93
94 #### Use the miniz compression library
95 #
96 # FOSSIL_ENABLE_MINIZ = 1
97
@@ -158,11 +162,11 @@
158 #### The directories where the OpenSSL include and library files are located.
159 # The recommended usage here is to use the Sysinternals junction tool
160 # to create a hard link between an "openssl-1.x" sub-directory of the
161 # Fossil source code directory and the target OpenSSL source directory.
162 #
163 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2g
164 OPENSSLINCDIR = $(OPENSSLDIR)/include
165 OPENSSLLIBDIR = $(OPENSSLDIR)
166
167 #### Either the directory where the Tcl library is installed or the Tcl
168 # source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
313 # With JSON support
314 ifdef FOSSIL_ENABLE_JSON
315 TCC += -DFOSSIL_ENABLE_JSON=1
316 RCC += -DFOSSIL_ENABLE_JSON=1
317 endif
 
 
 
 
 
 
318
319 #### The option -static has no effect on MinGW(-w64), only dynamic
320 # executables can be built when linking with MSVCRT. OpenSSL
321 # (optional) and zlib (required) however are always linked in
322 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
921 # set to 1. If it is set to 1, the miniz library included in the
922 # source tree should be used; otherwise, it should not.
923 MINIZ_OBJ.0 =
924 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
925 MINIZ_OBJ. = $(MINIZ_OBJ.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
926
927
928 EXTRAOBJ = \
929 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
930 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
2113
2114 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2115 -DMINIZ_NO_TIME \
2116 -DMINIZ_NO_ARCHIVE_APIS
2117
2118 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw.mistachkin
2119 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $@
 
2120
2121 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2122 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
2123
2124 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
2125
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -88,10 +88,14 @@
88 FOSSIL_ENABLE_TCL_PRIVATE_STUBS = 1
89
90 #### Use 'system' SQLite
91 #
92 # USE_SYSTEM_SQLITE = 1
93
94 #### Use the SQLite Encryption Extension
95 #
96 # USE_SEE = 1
97
98 #### Use the miniz compression library
99 #
100 # FOSSIL_ENABLE_MINIZ = 1
101
@@ -158,11 +162,11 @@
162 #### The directories where the OpenSSL include and library files are located.
163 # The recommended usage here is to use the Sysinternals junction tool
164 # to create a hard link between an "openssl-1.x" sub-directory of the
165 # Fossil source code directory and the target OpenSSL source directory.
166 #
167 OPENSSLDIR = $(SRCDIR)/../compat/openssl-1.0.2h
168 OPENSSLINCDIR = $(OPENSSLDIR)/include
169 OPENSSLLIBDIR = $(OPENSSLDIR)
170
171 #### Either the directory where the Tcl library is installed or the Tcl
172 # source code directory resides (depending on the value of the macro
@@ -313,10 +317,16 @@
317 # With JSON support
318 ifdef FOSSIL_ENABLE_JSON
319 TCC += -DFOSSIL_ENABLE_JSON=1
320 RCC += -DFOSSIL_ENABLE_JSON=1
321 endif
322
323 # With SQLite Encryption Extension support
324 ifdef USE_SEE
325 TCC += -DUSE_SEE=1
326 RCC += -DUSE_SEE=1
327 endif
328
329 #### The option -static has no effect on MinGW(-w64), only dynamic
330 # executables can be built when linking with MSVCRT. OpenSSL
331 # (optional) and zlib (required) however are always linked in
332 # statically. Therefore, the FOSSIL_DYNAMIC_BUILD option does
@@ -921,10 +931,23 @@
931 # set to 1. If it is set to 1, the miniz library included in the
932 # source tree should be used; otherwise, it should not.
933 MINIZ_OBJ.0 =
934 MINIZ_OBJ.1 = $(OBJDIR)/miniz.o
935 MINIZ_OBJ. = $(MINIZ_OBJ.0)
936
937 # The USE_SEE variable may be undefined, 0 or 1. If undefined or
938 # 0, ordinary SQLite is used. If 1, then sqlite3-see.c (not part of
939 # the source tree) is used and extra flags are provided to enable
940 # the SQLite Encryption Extension.
941 SQLITE3_SRC.1 = sqlite3-see.c
942 SQLITE3_SRC.0 = sqlite3.c
943 SQLITE3_SRC. = sqlite3.c
944 SQLITE3_SRC = $(SRCDIR)/$(SQLITE3_SRC.$(USE_SEE))
945 SEE_FLAGS.1 = -DSQLITE_HAS_CODEC
946 SEE_FLAGS.0 =
947 SEE_FLAGS. =
948 SEE_FLAGS = $(SEE_FLAGS.$(USE_SEE))
949
950
951 EXTRAOBJ = \
952 $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
953 $(MINIZ_OBJ.$(FOSSIL_ENABLE_MINIZ)) \
@@ -2113,12 +2136,13 @@
2136
2137 MINIZ_OPTIONS = -DMINIZ_NO_STDIO \
2138 -DMINIZ_NO_TIME \
2139 -DMINIZ_NO_ARCHIVE_APIS
2140
2141 $(OBJDIR)/sqlite3.o: $(SQLITE3_SRC) $(SRCDIR)/../win/Makefile.mingw.mistachkin
2142 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) \
2143 -c $(SQLITE3_SRC) -o $@
2144
2145 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR)/cson_amalgamation.c
2146 $(XTCC) -c $(SRCDIR)/cson_amalgamation.c -o $@
2147
2148 $(OBJDIR)/json.o $(OBJDIR)/json_artifact.o $(OBJDIR)/json_branch.o $(OBJDIR)/json_config.o $(OBJDIR)/json_diff.o $(OBJDIR)/json_dir.o $(OBJDIR)/jsos_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 : $(SRCDIR)/json_detail.h
2149
+19 -3
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -91,13 +91,18 @@
9191
9292
# Enable support for Windows XP with Visual Studio 201x?
9393
!ifndef FOSSIL_ENABLE_WINXP
9494
FOSSIL_ENABLE_WINXP = 0
9595
!endif
96
+
97
+# Enable support for the SQLite Encryption Extension?
98
+!ifndef USE_SEE
99
+USE_SEE = 0
100
+!endif
96101
97102
!if $(FOSSIL_ENABLE_SSL)!=0
98
-SSLDIR = $(B)\compat\openssl-1.0.2g
103
+SSLDIR = $(B)\compat\openssl-1.0.2h
99104
SSLINCDIR = $(SSLDIR)\inc32
100105
!if $(FOSSIL_DYNAMIC_BUILD)!=0
101106
SSLLIBDIR = $(SSLDIR)\out32dll
102107
!else
103108
SSLLIBDIR = $(SSLDIR)\out32
@@ -300,10 +305,15 @@
300305
TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
301306
RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
302307
TCC = $(TCC) /DUSE_TCL_STUBS=1
303308
RCC = $(RCC) /DUSE_TCL_STUBS=1
304309
!endif
310
+
311
+!if $(USE_SEE)!=0
312
+TCC = $(TCC) /DUSE_SEE=1
313
+RCC = $(RCC) /DUSE_SEE=1
314
+!endif
305315
306316
SQLITE_OPTIONS = /DNDEBUG=1 \
307317
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
308318
/DSQLITE_ENABLE_LOCKING_STYLE=0 \
309319
/DSQLITE_THREADSAFE=0 \
@@ -833,12 +843,18 @@
833843
$(BCC) $**
834844
835845
$(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
836846
$(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
837847
838
-$(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c $B\win\Makefile.msc
839
- $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SRCDIR)\sqlite3.c
848
+!if $(USE_SEE)!=0
849
+SQLITE3_SRC = $(SRCDIR)\sqlite3-see.c
850
+!else
851
+SQLITE3_SRC = $(SRCDIR)\sqlite3.c
852
+!endif
853
+
854
+$(OX)\sqlite3$O : $(SQLITE3_SRC) $B\win\Makefile.msc
855
+ $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) $(SQLITE3_SRC)
840856
841857
$(OX)\th$O : $(SRCDIR)\th.c
842858
$(TCC) /Fo$@ -c $**
843859
844860
$(OX)\th_lang$O : $(SRCDIR)\th_lang.c
845861
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -91,13 +91,18 @@
91
92 # Enable support for Windows XP with Visual Studio 201x?
93 !ifndef FOSSIL_ENABLE_WINXP
94 FOSSIL_ENABLE_WINXP = 0
95 !endif
 
 
 
 
 
96
97 !if $(FOSSIL_ENABLE_SSL)!=0
98 SSLDIR = $(B)\compat\openssl-1.0.2g
99 SSLINCDIR = $(SSLDIR)\inc32
100 !if $(FOSSIL_DYNAMIC_BUILD)!=0
101 SSLLIBDIR = $(SSLDIR)\out32dll
102 !else
103 SSLLIBDIR = $(SSLDIR)\out32
@@ -300,10 +305,15 @@
300 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
301 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
302 TCC = $(TCC) /DUSE_TCL_STUBS=1
303 RCC = $(RCC) /DUSE_TCL_STUBS=1
304 !endif
 
 
 
 
 
305
306 SQLITE_OPTIONS = /DNDEBUG=1 \
307 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
308 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
309 /DSQLITE_THREADSAFE=0 \
@@ -833,12 +843,18 @@
833 $(BCC) $**
834
835 $(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
836 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
837
838 $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c $B\win\Makefile.msc
839 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SRCDIR)\sqlite3.c
 
 
 
 
 
 
840
841 $(OX)\th$O : $(SRCDIR)\th.c
842 $(TCC) /Fo$@ -c $**
843
844 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
845
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -91,13 +91,18 @@
91
92 # Enable support for Windows XP with Visual Studio 201x?
93 !ifndef FOSSIL_ENABLE_WINXP
94 FOSSIL_ENABLE_WINXP = 0
95 !endif
96
97 # Enable support for the SQLite Encryption Extension?
98 !ifndef USE_SEE
99 USE_SEE = 0
100 !endif
101
102 !if $(FOSSIL_ENABLE_SSL)!=0
103 SSLDIR = $(B)\compat\openssl-1.0.2h
104 SSLINCDIR = $(SSLDIR)\inc32
105 !if $(FOSSIL_DYNAMIC_BUILD)!=0
106 SSLLIBDIR = $(SSLDIR)\out32dll
107 !else
108 SSLLIBDIR = $(SSLDIR)\out32
@@ -300,10 +305,15 @@
305 TCC = $(TCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
306 RCC = $(RCC) /DFOSSIL_ENABLE_TCL_PRIVATE_STUBS=1
307 TCC = $(TCC) /DUSE_TCL_STUBS=1
308 RCC = $(RCC) /DUSE_TCL_STUBS=1
309 !endif
310
311 !if $(USE_SEE)!=0
312 TCC = $(TCC) /DUSE_SEE=1
313 RCC = $(RCC) /DUSE_SEE=1
314 !endif
315
316 SQLITE_OPTIONS = /DNDEBUG=1 \
317 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
318 /DSQLITE_ENABLE_LOCKING_STYLE=0 \
319 /DSQLITE_THREADSAFE=0 \
@@ -833,12 +843,18 @@
843 $(BCC) $**
844
845 $(OX)\shell$O : $(SRCDIR)\shell.c $B\win\Makefile.msc
846 $(TCC) /Fo$@ $(SHELL_OPTIONS) $(SQLITE_OPTIONS) $(SHELL_CFLAGS) -c $(SRCDIR)\shell.c
847
848 !if $(USE_SEE)!=0
849 SQLITE3_SRC = $(SRCDIR)\sqlite3-see.c
850 !else
851 SQLITE3_SRC = $(SRCDIR)\sqlite3.c
852 !endif
853
854 $(OX)\sqlite3$O : $(SQLITE3_SRC) $B\win\Makefile.msc
855 $(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) $(SEE_FLAGS) $(SQLITE3_SRC)
856
857 $(OX)\th$O : $(SRCDIR)\th.c
858 $(TCC) /Fo$@ -c $**
859
860 $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
861
--- win/fossil.rc
+++ win/fossil.rc
@@ -161,10 +161,15 @@
161161
#endif /* defined(FOSSIL_ENABLE_TCL_PRIVATE_STUBS) */
162162
#endif /* defined(FOSSIL_ENABLE_TCL) */
163163
#if defined(FOSSIL_ENABLE_JSON)
164164
VALUE "JsonEnabled", "Yes, cson " FOSSIL_JSON_API_VERSION "\0"
165165
#endif /* defined(FOSSIL_ENABLE_JSON) */
166
+#if defined(USE_SEE)
167
+ VALUE "UseSeeEnabled", "Yes\0"
168
+#else
169
+ VALUE "UseSeeEnabled", "No\0"
170
+#endif /* defined(USE_SEE) */
166171
VALUE "MarkdownEnabled", "Yes\0"
167172
END
168173
END
169174
BLOCK "VarFileInfo"
170175
BEGIN
171176
--- win/fossil.rc
+++ win/fossil.rc
@@ -161,10 +161,15 @@
161 #endif /* defined(FOSSIL_ENABLE_TCL_PRIVATE_STUBS) */
162 #endif /* defined(FOSSIL_ENABLE_TCL) */
163 #if defined(FOSSIL_ENABLE_JSON)
164 VALUE "JsonEnabled", "Yes, cson " FOSSIL_JSON_API_VERSION "\0"
165 #endif /* defined(FOSSIL_ENABLE_JSON) */
 
 
 
 
 
166 VALUE "MarkdownEnabled", "Yes\0"
167 END
168 END
169 BLOCK "VarFileInfo"
170 BEGIN
171
--- win/fossil.rc
+++ win/fossil.rc
@@ -161,10 +161,15 @@
161 #endif /* defined(FOSSIL_ENABLE_TCL_PRIVATE_STUBS) */
162 #endif /* defined(FOSSIL_ENABLE_TCL) */
163 #if defined(FOSSIL_ENABLE_JSON)
164 VALUE "JsonEnabled", "Yes, cson " FOSSIL_JSON_API_VERSION "\0"
165 #endif /* defined(FOSSIL_ENABLE_JSON) */
166 #if defined(USE_SEE)
167 VALUE "UseSeeEnabled", "Yes\0"
168 #else
169 VALUE "UseSeeEnabled", "No\0"
170 #endif /* defined(USE_SEE) */
171 VALUE "MarkdownEnabled", "Yes\0"
172 END
173 END
174 BLOCK "VarFileInfo"
175 BEGIN
176
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -1,30 +1,13 @@
11
/*
2
- * dirent.h - dirent API for Microsoft Visual Studio
2
+ * Dirent interface for Microsoft Visual Studio
3
+ * Version 1.21
34
*
45
* Copyright (C) 2006-2012 Toni Ronkko
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining
7
- * a copy of this software and associated documentation files (the
8
- * ``Software''), to deal in the Software without restriction, including
9
- * without limitation the rights to use, copy, modify, merge, publish,
10
- * distribute, sublicense, and/or sell copies of the Software, and to
11
- * permit persons to whom the Software is furnished to do so, subject to
12
- * the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included
15
- * in all copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
- * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
- * OTHER DEALINGS IN THE SOFTWARE.
24
- *
25
- * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $
6
+ * This file is part of dirent. Dirent may be freely distributed
7
+ * under the MIT license. For all details and documentation, see
8
+ * https://github.com/tronkko/dirent
269
*/
2710
#ifndef DIRENT_H
2811
#define DIRENT_H
2912
3013
/*
@@ -60,58 +43,113 @@
6043
/* Entries missing from MSVC 6.0 */
6144
#if !defined(FILE_ATTRIBUTE_DEVICE)
6245
# define FILE_ATTRIBUTE_DEVICE 0x40
6346
#endif
6447
65
-/* File type and permission flags for stat() */
48
+/* File type and permission flags for stat(), general mask */
6649
#if !defined(S_IFMT)
67
-# define S_IFMT _S_IFMT /* File type mask */
50
+# define S_IFMT _S_IFMT
6851
#endif
52
+
53
+/* Directory bit */
6954
#if !defined(S_IFDIR)
70
-# define S_IFDIR _S_IFDIR /* Directory */
55
+# define S_IFDIR _S_IFDIR
7156
#endif
57
+
58
+/* Character device bit */
7259
#if !defined(S_IFCHR)
73
-# define S_IFCHR _S_IFCHR /* Character device */
60
+# define S_IFCHR _S_IFCHR
7461
#endif
62
+
63
+/* Pipe bit */
7564
#if !defined(S_IFFIFO)
76
-# define S_IFFIFO _S_IFFIFO /* Pipe */
65
+# define S_IFFIFO _S_IFFIFO
7766
#endif
67
+
68
+/* Regular file bit */
7869
#if !defined(S_IFREG)
79
-# define S_IFREG _S_IFREG /* Regular file */
70
+# define S_IFREG _S_IFREG
8071
#endif
72
+
73
+/* Read permission */
8174
#if !defined(S_IREAD)
82
-# define S_IREAD _S_IREAD /* Read permission */
75
+# define S_IREAD _S_IREAD
8376
#endif
77
+
78
+/* Write permission */
8479
#if !defined(S_IWRITE)
85
-# define S_IWRITE _S_IWRITE /* Write permission */
80
+# define S_IWRITE _S_IWRITE
8681
#endif
82
+
83
+/* Execute permission */
8784
#if !defined(S_IEXEC)
88
-# define S_IEXEC _S_IEXEC /* Execute permission */
85
+# define S_IEXEC _S_IEXEC
8986
#endif
87
+
88
+/* Pipe */
9089
#if !defined(S_IFIFO)
91
-# define S_IFIFO _S_IFIFO /* Pipe */
90
+# define S_IFIFO _S_IFIFO
9291
#endif
92
+
93
+/* Block device */
9394
#if !defined(S_IFBLK)
94
-# define S_IFBLK 0 /* Block device */
95
+# define S_IFBLK 0
9596
#endif
97
+
98
+/* Link */
9699
#if !defined(S_IFLNK)
97
-# define S_IFLNK 0 /* Link */
100
+# define S_IFLNK 0
98101
#endif
102
+
103
+/* Socket */
99104
#if !defined(S_IFSOCK)
100
-# define S_IFSOCK 0 /* Socket */
105
+# define S_IFSOCK 0
106
+#endif
107
+
108
+/* Read user permission */
109
+#if !defined(S_IRUSR)
110
+# define S_IRUSR S_IREAD
111
+#endif
112
+
113
+/* Write user permission */
114
+#if !defined(S_IWUSR)
115
+# define S_IWUSR S_IWRITE
116
+#endif
117
+
118
+/* Execute user permission */
119
+#if !defined(S_IXUSR)
120
+# define S_IXUSR 0
121
+#endif
122
+
123
+/* Read group permission */
124
+#if !defined(S_IRGRP)
125
+# define S_IRGRP 0
126
+#endif
127
+
128
+/* Write group permission */
129
+#if !defined(S_IWGRP)
130
+# define S_IWGRP 0
131
+#endif
132
+
133
+/* Execute group permission */
134
+#if !defined(S_IXGRP)
135
+# define S_IXGRP 0
136
+#endif
137
+
138
+/* Read others permission */
139
+#if !defined(S_IROTH)
140
+# define S_IROTH 0
141
+#endif
142
+
143
+/* Write others permission */
144
+#if !defined(S_IWOTH)
145
+# define S_IWOTH 0
101146
#endif
102147
103
-#if defined(_MSC_VER)
104
-# define S_IRUSR S_IREAD /* Read user */
105
-# define S_IWUSR S_IWRITE /* Write user */
106
-# define S_IXUSR 0 /* Execute user */
107
-# define S_IRGRP 0 /* Read group */
108
-# define S_IWGRP 0 /* Write group */
109
-# define S_IXGRP 0 /* Execute group */
110
-# define S_IROTH 0 /* Read others */
111
-# define S_IWOTH 0 /* Write others */
112
-# define S_IXOTH 0 /* Execute others */
148
+/* Execute others permission */
149
+#if !defined(S_IXOTH)
150
+# define S_IXOTH 0
113151
#endif
114152
115153
/* Maximum length of file name */
116154
#if !defined(PATH_MAX)
117155
# define PATH_MAX MAX_PATH
@@ -122,18 +160,18 @@
122160
#if !defined(NAME_MAX)
123161
# define NAME_MAX FILENAME_MAX
124162
#endif
125163
126164
/* File type flags for d_type */
127
-#define DT_UNKNOWN 0
128
-#define DT_REG S_IFREG
129
-#define DT_DIR S_IFDIR
130
-#define DT_FIFO S_IFIFO
131
-#define DT_SOCK S_IFSOCK
132
-#define DT_CHR S_IFCHR
133
-#define DT_BLK S_IFBLK
134
-#define DT_LNK S_IFLNK
165
+#define DT_UNKNOWN 0
166
+#define DT_REG S_IFREG
167
+#define DT_DIR S_IFDIR
168
+#define DT_FIFO S_IFIFO
169
+#define DT_SOCK S_IFSOCK
170
+#define DT_CHR S_IFCHR
171
+#define DT_BLK S_IFBLK
172
+#define DT_LNK S_IFLNK
135173
136174
/* Macros for converting between st_mode and d_type */
137175
#define IFTODT(mode) ((mode) & S_IFMT)
138176
#define DTTOIF(type) (type)
139177
@@ -141,17 +179,31 @@
141179
* File type macros. Note that block devices, sockets and links cannot be
142180
* distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
143181
* only defined for compatibility. These macros should always return false
144182
* on Windows.
145183
*/
146
-#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
147
-#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
148
-#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
149
-#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
150
-#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
151
-#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
152
-#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
184
+#if !defined(S_ISFIFO)
185
+# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
186
+#endif
187
+#if !defined(S_ISDIR)
188
+# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
189
+#endif
190
+#if !defined(S_ISREG)
191
+# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
192
+#endif
193
+#if !defined(S_ISLNK)
194
+# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
195
+#endif
196
+#if !defined(S_ISSOCK)
197
+# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
198
+#endif
199
+#if !defined(S_ISCHR)
200
+# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
201
+#endif
202
+#if !defined(S_ISBLK)
203
+# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
204
+#endif
153205
154206
/* Return the exact length of d_namlen without zero terminator */
155207
#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
156208
157209
/* Return number of bytes needed to store d_namlen */
@@ -163,24 +215,42 @@
163215
#endif
164216
165217
166218
/* Wide-character version */
167219
struct _wdirent {
168
- long d_ino; /* Always zero */
169
- unsigned short d_reclen; /* Structure size */
170
- size_t d_namlen; /* Length of name without \0 */
171
- int d_type; /* File type */
172
- wchar_t d_name[PATH_MAX]; /* File name */
220
+ /* Always zero */
221
+ long d_ino;
222
+
223
+ /* Structure size */
224
+ unsigned short d_reclen;
225
+
226
+ /* Length of name without \0 */
227
+ size_t d_namlen;
228
+
229
+ /* File type */
230
+ int d_type;
231
+
232
+ /* File name */
233
+ wchar_t d_name[PATH_MAX];
173234
};
174235
typedef struct _wdirent _wdirent;
175236
176237
struct _WDIR {
177
- struct _wdirent ent; /* Current directory entry */
178
- WIN32_FIND_DATAW data; /* Private file data */
179
- int cached; /* True if data is valid */
180
- HANDLE handle; /* Win32 search handle */
181
- wchar_t *patt; /* Initial directory name */
238
+ /* Current directory entry */
239
+ struct _wdirent ent;
240
+
241
+ /* Private file data */
242
+ WIN32_FIND_DATAW data;
243
+
244
+ /* True if data is valid */
245
+ int cached;
246
+
247
+ /* Win32 search handle */
248
+ HANDLE handle;
249
+
250
+ /* Initial directory name */
251
+ wchar_t *patt;
182252
};
183253
typedef struct _WDIR _WDIR;
184254
185255
static _WDIR *_wopendir (const wchar_t *dirname);
186256
static struct _wdirent *_wreaddir (_WDIR *dirp);
@@ -197,15 +267,24 @@
197267
#define wrewinddir _wrewinddir
198268
199269
200270
/* Multi-byte character versions */
201271
struct dirent {
202
- long d_ino; /* Always zero */
203
- unsigned short d_reclen; /* Structure size */
204
- size_t d_namlen; /* Length of name without \0 */
205
- int d_type; /* File type */
206
- char d_name[PATH_MAX]; /* File name */
272
+ /* Always zero */
273
+ long d_ino;
274
+
275
+ /* Structure size */
276
+ unsigned short d_reclen;
277
+
278
+ /* Length of name without \0 */
279
+ size_t d_namlen;
280
+
281
+ /* File type */
282
+ int d_type;
283
+
284
+ /* File name */
285
+ char d_name[PATH_MAX];
207286
};
208287
typedef struct dirent dirent;
209288
210289
struct DIR {
211290
struct dirent ent;
212291
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -1,30 +1,13 @@
1 /*
2 * dirent.h - dirent API for Microsoft Visual Studio
 
3 *
4 * Copyright (C) 2006-2012 Toni Ronkko
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * ``Software''), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * $Id: dirent.h,v 1.20 2014/03/19 17:52:23 tronkko Exp $
26 */
27 #ifndef DIRENT_H
28 #define DIRENT_H
29
30 /*
@@ -60,58 +43,113 @@
60 /* Entries missing from MSVC 6.0 */
61 #if !defined(FILE_ATTRIBUTE_DEVICE)
62 # define FILE_ATTRIBUTE_DEVICE 0x40
63 #endif
64
65 /* File type and permission flags for stat() */
66 #if !defined(S_IFMT)
67 # define S_IFMT _S_IFMT /* File type mask */
68 #endif
 
 
69 #if !defined(S_IFDIR)
70 # define S_IFDIR _S_IFDIR /* Directory */
71 #endif
 
 
72 #if !defined(S_IFCHR)
73 # define S_IFCHR _S_IFCHR /* Character device */
74 #endif
 
 
75 #if !defined(S_IFFIFO)
76 # define S_IFFIFO _S_IFFIFO /* Pipe */
77 #endif
 
 
78 #if !defined(S_IFREG)
79 # define S_IFREG _S_IFREG /* Regular file */
80 #endif
 
 
81 #if !defined(S_IREAD)
82 # define S_IREAD _S_IREAD /* Read permission */
83 #endif
 
 
84 #if !defined(S_IWRITE)
85 # define S_IWRITE _S_IWRITE /* Write permission */
86 #endif
 
 
87 #if !defined(S_IEXEC)
88 # define S_IEXEC _S_IEXEC /* Execute permission */
89 #endif
 
 
90 #if !defined(S_IFIFO)
91 # define S_IFIFO _S_IFIFO /* Pipe */
92 #endif
 
 
93 #if !defined(S_IFBLK)
94 # define S_IFBLK 0 /* Block device */
95 #endif
 
 
96 #if !defined(S_IFLNK)
97 # define S_IFLNK 0 /* Link */
98 #endif
 
 
99 #if !defined(S_IFSOCK)
100 # define S_IFSOCK 0 /* Socket */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101 #endif
102
103 #if defined(_MSC_VER)
104 # define S_IRUSR S_IREAD /* Read user */
105 # define S_IWUSR S_IWRITE /* Write user */
106 # define S_IXUSR 0 /* Execute user */
107 # define S_IRGRP 0 /* Read group */
108 # define S_IWGRP 0 /* Write group */
109 # define S_IXGRP 0 /* Execute group */
110 # define S_IROTH 0 /* Read others */
111 # define S_IWOTH 0 /* Write others */
112 # define S_IXOTH 0 /* Execute others */
113 #endif
114
115 /* Maximum length of file name */
116 #if !defined(PATH_MAX)
117 # define PATH_MAX MAX_PATH
@@ -122,18 +160,18 @@
122 #if !defined(NAME_MAX)
123 # define NAME_MAX FILENAME_MAX
124 #endif
125
126 /* File type flags for d_type */
127 #define DT_UNKNOWN 0
128 #define DT_REG S_IFREG
129 #define DT_DIR S_IFDIR
130 #define DT_FIFO S_IFIFO
131 #define DT_SOCK S_IFSOCK
132 #define DT_CHR S_IFCHR
133 #define DT_BLK S_IFBLK
134 #define DT_LNK S_IFLNK
135
136 /* Macros for converting between st_mode and d_type */
137 #define IFTODT(mode) ((mode) & S_IFMT)
138 #define DTTOIF(type) (type)
139
@@ -141,17 +179,31 @@
141 * File type macros. Note that block devices, sockets and links cannot be
142 * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
143 * only defined for compatibility. These macros should always return false
144 * on Windows.
145 */
146 #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
147 #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
148 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
149 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
150 #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
151 #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
152 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
154 /* Return the exact length of d_namlen without zero terminator */
155 #define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
156
157 /* Return number of bytes needed to store d_namlen */
@@ -163,24 +215,42 @@
163 #endif
164
165
166 /* Wide-character version */
167 struct _wdirent {
168 long d_ino; /* Always zero */
169 unsigned short d_reclen; /* Structure size */
170 size_t d_namlen; /* Length of name without \0 */
171 int d_type; /* File type */
172 wchar_t d_name[PATH_MAX]; /* File name */
 
 
 
 
 
 
 
 
 
173 };
174 typedef struct _wdirent _wdirent;
175
176 struct _WDIR {
177 struct _wdirent ent; /* Current directory entry */
178 WIN32_FIND_DATAW data; /* Private file data */
179 int cached; /* True if data is valid */
180 HANDLE handle; /* Win32 search handle */
181 wchar_t *patt; /* Initial directory name */
 
 
 
 
 
 
 
 
 
182 };
183 typedef struct _WDIR _WDIR;
184
185 static _WDIR *_wopendir (const wchar_t *dirname);
186 static struct _wdirent *_wreaddir (_WDIR *dirp);
@@ -197,15 +267,24 @@
197 #define wrewinddir _wrewinddir
198
199
200 /* Multi-byte character versions */
201 struct dirent {
202 long d_ino; /* Always zero */
203 unsigned short d_reclen; /* Structure size */
204 size_t d_namlen; /* Length of name without \0 */
205 int d_type; /* File type */
206 char d_name[PATH_MAX]; /* File name */
 
 
 
 
 
 
 
 
 
207 };
208 typedef struct dirent dirent;
209
210 struct DIR {
211 struct dirent ent;
212
--- win/include/dirent.h
+++ win/include/dirent.h
@@ -1,30 +1,13 @@
1 /*
2 * Dirent interface for Microsoft Visual Studio
3 * Version 1.21
4 *
5 * Copyright (C) 2006-2012 Toni Ronkko
6 * This file is part of dirent. Dirent may be freely distributed
7 * under the MIT license. For all details and documentation, see
8 * https://github.com/tronkko/dirent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9 */
10 #ifndef DIRENT_H
11 #define DIRENT_H
12
13 /*
@@ -60,58 +43,113 @@
43 /* Entries missing from MSVC 6.0 */
44 #if !defined(FILE_ATTRIBUTE_DEVICE)
45 # define FILE_ATTRIBUTE_DEVICE 0x40
46 #endif
47
48 /* File type and permission flags for stat(), general mask */
49 #if !defined(S_IFMT)
50 # define S_IFMT _S_IFMT
51 #endif
52
53 /* Directory bit */
54 #if !defined(S_IFDIR)
55 # define S_IFDIR _S_IFDIR
56 #endif
57
58 /* Character device bit */
59 #if !defined(S_IFCHR)
60 # define S_IFCHR _S_IFCHR
61 #endif
62
63 /* Pipe bit */
64 #if !defined(S_IFFIFO)
65 # define S_IFFIFO _S_IFFIFO
66 #endif
67
68 /* Regular file bit */
69 #if !defined(S_IFREG)
70 # define S_IFREG _S_IFREG
71 #endif
72
73 /* Read permission */
74 #if !defined(S_IREAD)
75 # define S_IREAD _S_IREAD
76 #endif
77
78 /* Write permission */
79 #if !defined(S_IWRITE)
80 # define S_IWRITE _S_IWRITE
81 #endif
82
83 /* Execute permission */
84 #if !defined(S_IEXEC)
85 # define S_IEXEC _S_IEXEC
86 #endif
87
88 /* Pipe */
89 #if !defined(S_IFIFO)
90 # define S_IFIFO _S_IFIFO
91 #endif
92
93 /* Block device */
94 #if !defined(S_IFBLK)
95 # define S_IFBLK 0
96 #endif
97
98 /* Link */
99 #if !defined(S_IFLNK)
100 # define S_IFLNK 0
101 #endif
102
103 /* Socket */
104 #if !defined(S_IFSOCK)
105 # define S_IFSOCK 0
106 #endif
107
108 /* Read user permission */
109 #if !defined(S_IRUSR)
110 # define S_IRUSR S_IREAD
111 #endif
112
113 /* Write user permission */
114 #if !defined(S_IWUSR)
115 # define S_IWUSR S_IWRITE
116 #endif
117
118 /* Execute user permission */
119 #if !defined(S_IXUSR)
120 # define S_IXUSR 0
121 #endif
122
123 /* Read group permission */
124 #if !defined(S_IRGRP)
125 # define S_IRGRP 0
126 #endif
127
128 /* Write group permission */
129 #if !defined(S_IWGRP)
130 # define S_IWGRP 0
131 #endif
132
133 /* Execute group permission */
134 #if !defined(S_IXGRP)
135 # define S_IXGRP 0
136 #endif
137
138 /* Read others permission */
139 #if !defined(S_IROTH)
140 # define S_IROTH 0
141 #endif
142
143 /* Write others permission */
144 #if !defined(S_IWOTH)
145 # define S_IWOTH 0
146 #endif
147
148 /* Execute others permission */
149 #if !defined(S_IXOTH)
150 # define S_IXOTH 0
 
 
 
 
 
 
 
151 #endif
152
153 /* Maximum length of file name */
154 #if !defined(PATH_MAX)
155 # define PATH_MAX MAX_PATH
@@ -122,18 +160,18 @@
160 #if !defined(NAME_MAX)
161 # define NAME_MAX FILENAME_MAX
162 #endif
163
164 /* File type flags for d_type */
165 #define DT_UNKNOWN 0
166 #define DT_REG S_IFREG
167 #define DT_DIR S_IFDIR
168 #define DT_FIFO S_IFIFO
169 #define DT_SOCK S_IFSOCK
170 #define DT_CHR S_IFCHR
171 #define DT_BLK S_IFBLK
172 #define DT_LNK S_IFLNK
173
174 /* Macros for converting between st_mode and d_type */
175 #define IFTODT(mode) ((mode) & S_IFMT)
176 #define DTTOIF(type) (type)
177
@@ -141,17 +179,31 @@
179 * File type macros. Note that block devices, sockets and links cannot be
180 * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
181 * only defined for compatibility. These macros should always return false
182 * on Windows.
183 */
184 #if !defined(S_ISFIFO)
185 # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
186 #endif
187 #if !defined(S_ISDIR)
188 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
189 #endif
190 #if !defined(S_ISREG)
191 # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
192 #endif
193 #if !defined(S_ISLNK)
194 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
195 #endif
196 #if !defined(S_ISSOCK)
197 # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
198 #endif
199 #if !defined(S_ISCHR)
200 # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
201 #endif
202 #if !defined(S_ISBLK)
203 # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
204 #endif
205
206 /* Return the exact length of d_namlen without zero terminator */
207 #define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
208
209 /* Return number of bytes needed to store d_namlen */
@@ -163,24 +215,42 @@
215 #endif
216
217
218 /* Wide-character version */
219 struct _wdirent {
220 /* Always zero */
221 long d_ino;
222
223 /* Structure size */
224 unsigned short d_reclen;
225
226 /* Length of name without \0 */
227 size_t d_namlen;
228
229 /* File type */
230 int d_type;
231
232 /* File name */
233 wchar_t d_name[PATH_MAX];
234 };
235 typedef struct _wdirent _wdirent;
236
237 struct _WDIR {
238 /* Current directory entry */
239 struct _wdirent ent;
240
241 /* Private file data */
242 WIN32_FIND_DATAW data;
243
244 /* True if data is valid */
245 int cached;
246
247 /* Win32 search handle */
248 HANDLE handle;
249
250 /* Initial directory name */
251 wchar_t *patt;
252 };
253 typedef struct _WDIR _WDIR;
254
255 static _WDIR *_wopendir (const wchar_t *dirname);
256 static struct _wdirent *_wreaddir (_WDIR *dirp);
@@ -197,15 +267,24 @@
267 #define wrewinddir _wrewinddir
268
269
270 /* Multi-byte character versions */
271 struct dirent {
272 /* Always zero */
273 long d_ino;
274
275 /* Structure size */
276 unsigned short d_reclen;
277
278 /* Length of name without \0 */
279 size_t d_namlen;
280
281 /* File type */
282 int d_type;
283
284 /* File name */
285 char d_name[PATH_MAX];
286 };
287 typedef struct dirent dirent;
288
289 struct DIR {
290 struct dirent ent;
291
+1 -1
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141141
the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142142
first <a href="https://www.openssl.org/source/">download the official
143143
source code for OpenSSL</a> and extract it to an appropriately named
144144
"<b>openssl-X.Y.ZA</b>" subdirectory within the local
145145
[/tree?ci=trunk&name=compat | compat] directory (e.g.
146
-"<b>compat/openssl-1.0.2g</b>"), then make sure that some recent
146
+"<b>compat/openssl-1.0.2h</b>"), then make sure that some recent
147147
<a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148148
and finally run one of the following commands:
149149
<blockquote><pre>
150150
nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151151
</pre></blockquote>
152152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.0.2g</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
--- www/build.wiki
+++ www/build.wiki
@@ -141,11 +141,11 @@
141 the optional <a href="https://www.openssl.org/">OpenSSL</a> support,
142 first <a href="https://www.openssl.org/source/">download the official
143 source code for OpenSSL</a> and extract it to an appropriately named
144 "<b>openssl-X.Y.ZA</b>" subdirectory within the local
145 [/tree?ci=trunk&name=compat | compat] directory (e.g.
146 "<b>compat/openssl-1.0.2h</b>"), then make sure that some recent
147 <a href="http://www.perl.org/">Perl</a> binaries are installed locally,
148 and finally run one of the following commands:
149 <blockquote><pre>
150 nmake /f Makefile.msc FOSSIL_ENABLE_SSL=1 FOSSIL_BUILD_SSL=1 PERLDIR=C:\full\path\to\Perl\bin
151 </pre></blockquote>
152
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
2929
</ul>
3030
* Get autosetup working with MinGW.
3131
* Fix autosetup detection of zlib in the source tree.
3232
* Added autosetup detection of OpenSSL when it may be present under the
3333
"compat" subdirectory of the source tree.
34
+ * Option --baseurl now works on Windows.
3435
3536
<h2>Changes for Version 1.34 (2015-11-02)</h2>
3637
3738
* Make the [/help?cmd=clean|fossil clean] command undoable for files less
3839
than 10MiB.
3940
4041
ADDED www/encryptedrepos.wiki
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
 
34
35 <h2>Changes for Version 1.34 (2015-11-02)</h2>
36
37 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
38 than 10MiB.
39
40 DDED www/encryptedrepos.wiki
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
34 * Option --baseurl now works on Windows.
35
36 <h2>Changes for Version 1.34 (2015-11-02)</h2>
37
38 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
39 than 10MiB.
40
41 DDED www/encryptedrepos.wiki
--- a/www/encryptedrepos.wiki
+++ b/www/encryptedrepos.wiki
@@ -0,0 +1,20 @@
1
+<title>How To Use Encr<h2>Int Settingcrypted repository.<title>How To Use Encr<h2>Introduction</h2><blockquote>
2
+Fossil can be compiled so that it works with encrypted repositories using
3
+the [https://www.sqlite.org/see/doc/trunk/www/readme.wiki|SQLite Encryption Extension].
4
+This technical note explains the process.
5
+</blockquote>
6
+<h2>Building An Enc<blockquote>
7
+The SQLite Encryption ExtensionSQLite Encryption Extension (SEE) is proprietary software and requires
8
+[http://www.hwaci.com/cgi-bin/see-step1
9
+Assuming you have an SEE license, the first step of compiling Fossil to
10
+use SEE is to create an SEE-enabled version of the SQLite database source code.
11
+This alternative SQLite database source file should be called "sqlite3-see.c"
12
+and should be placed in the src/ subfolder of the Fossil sourrces, right beside
13
+the public-domain "sqlite3.c" source fitps://www.sqlite.org/see/doc/trunk/www/readme.wiki|SQLite Encryption Extension].
14
+This technical note explains the process.
15
+</blockquote>
16
+<h2>Building An Enc<blockquote>
17
+The SQLite Encryption ExtensionSQLite Encryption Extension (SEE) is proprietary software and requires
18
+[http://www.hwaci.com/cgi-bin/see-step1
19
+Assuming you have an SEE license, the first step of compiling Fossil to
20
+use SEE is to create an SEE-enabled version of the SQLite database source couse of requires retyping and "fossil ui
--- a/www/encryptedrepos.wiki
+++ b/www/encryptedrepos.wiki
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/encryptedrepos.wiki
+++ b/www/encryptedrepos.wiki
@@ -0,0 +1,20 @@
1 <title>How To Use Encr<h2>Int Settingcrypted repository.<title>How To Use Encr<h2>Introduction</h2><blockquote>
2 Fossil can be compiled so that it works with encrypted repositories using
3 the [https://www.sqlite.org/see/doc/trunk/www/readme.wiki|SQLite Encryption Extension].
4 This technical note explains the process.
5 </blockquote>
6 <h2>Building An Enc<blockquote>
7 The SQLite Encryption ExtensionSQLite Encryption Extension (SEE) is proprietary software and requires
8 [http://www.hwaci.com/cgi-bin/see-step1
9 Assuming you have an SEE license, the first step of compiling Fossil to
10 use SEE is to create an SEE-enabled version of the SQLite database source code.
11 This alternative SQLite database source file should be called "sqlite3-see.c"
12 and should be placed in the src/ subfolder of the Fossil sourrces, right beside
13 the public-domain "sqlite3.c" source fitps://www.sqlite.org/see/doc/trunk/www/readme.wiki|SQLite Encryption Extension].
14 This technical note explains the process.
15 </blockquote>
16 <h2>Building An Enc<blockquote>
17 The SQLite Encryption ExtensionSQLite Encryption Extension (SEE) is proprietary software and requires
18 [http://www.hwaci.com/cgi-bin/see-step1
19 Assuming you have an SEE license, the first step of compiling Fossil to
20 use SEE is to create an SEE-enabled version of the SQLite database source couse of requires retyping and "fossil ui
+1 -1
--- www/env-opts.md
+++ www/env-opts.md
@@ -51,11 +51,11 @@
5151
comment string _and_ right before line indentation).
5252
5353
* _8_ &mdash; Attempts to break lines on word boundaries while honoring the
5454
logical line length.
5555
56
- * _10_ &mdash; Looks for the original comment text within the text being
56
+ * _16_ &mdash; Looks for the original comment text within the text being
5757
printed. Upon matching, a new line will be emitted, thus
5858
preserving more of the pre-existing formatting.
5959
6060
6161
`--errorlog ERRLOG`: Name a file to which fossil will log panics,
6262
--- www/env-opts.md
+++ www/env-opts.md
@@ -51,11 +51,11 @@
51 comment string _and_ right before line indentation).
52
53 * _8_ &mdash; Attempts to break lines on word boundaries while honoring the
54 logical line length.
55
56 * _10_ &mdash; Looks for the original comment text within the text being
57 printed. Upon matching, a new line will be emitted, thus
58 preserving more of the pre-existing formatting.
59
60
61 `--errorlog ERRLOG`: Name a file to which fossil will log panics,
62
--- www/env-opts.md
+++ www/env-opts.md
@@ -51,11 +51,11 @@
51 comment string _and_ right before line indentation).
52
53 * _8_ &mdash; Attempts to break lines on word boundaries while honoring the
54 logical line length.
55
56 * _16_ &mdash; Looks for the original comment text within the text being
57 printed. Upon matching, a new line will be emitted, thus
58 preserving more of the pre-existing formatting.
59
60
61 `--errorlog ERRLOG`: Name a file to which fossil will log panics,
62
--- www/scgi.wiki
+++ www/scgi.wiki
@@ -15,10 +15,11 @@
1515
<blockquote><pre>
1616
location ~ ^/demo_project/ {
1717
include scgi_params;
1818
scgi_pass localhost:9000;
1919
scgi_param SCRIPT_NAME "/demo_project";
20
+ scgi_param HTTPS "on";
2021
}
2122
</pre></blockquote>
2223
2324
Note that Nginx does not normally send either the PATH_INFO or SCRIPT_NAME
2425
variables via SCGI, but Fossil needs one or the other. So the configuration
2526
--- www/scgi.wiki
+++ www/scgi.wiki
@@ -15,10 +15,11 @@
15 <blockquote><pre>
16 location ~ ^/demo_project/ {
17 include scgi_params;
18 scgi_pass localhost:9000;
19 scgi_param SCRIPT_NAME "/demo_project";
 
20 }
21 </pre></blockquote>
22
23 Note that Nginx does not normally send either the PATH_INFO or SCRIPT_NAME
24 variables via SCGI, but Fossil needs one or the other. So the configuration
25
--- www/scgi.wiki
+++ www/scgi.wiki
@@ -15,10 +15,11 @@
15 <blockquote><pre>
16 location ~ ^/demo_project/ {
17 include scgi_params;
18 scgi_pass localhost:9000;
19 scgi_param SCRIPT_NAME "/demo_project";
20 scgi_param HTTPS "on";
21 }
22 </pre></blockquote>
23
24 Note that Nginx does not normally send either the PATH_INFO or SCRIPT_NAME
25 variables via SCGI, but Fossil needs one or the other. So the configuration
26
--- www/server.wiki
+++ www/server.wiki
@@ -227,10 +227,11 @@
227227
<blockquote><pre>
228228
location /demo_project/ {
229229
include scgi_params;
230230
scgi_pass localhost:9000;
231231
scgi_param SCRIPT_NAME "/demo_project";
232
+ scgi_param HTTPS "on";
232233
}
233234
</pre></blockquote>
234235
<p>
235236
Note that Fossil requires the SCRIPT_NAME variable
236237
in order to function properly, but Nginx does not provide this
237238
--- www/server.wiki
+++ www/server.wiki
@@ -227,10 +227,11 @@
227 <blockquote><pre>
228 location /demo_project/ {
229 include scgi_params;
230 scgi_pass localhost:9000;
231 scgi_param SCRIPT_NAME "/demo_project";
 
232 }
233 </pre></blockquote>
234 <p>
235 Note that Fossil requires the SCRIPT_NAME variable
236 in order to function properly, but Nginx does not provide this
237
--- www/server.wiki
+++ www/server.wiki
@@ -227,10 +227,11 @@
227 <blockquote><pre>
228 location /demo_project/ {
229 include scgi_params;
230 scgi_pass localhost:9000;
231 scgi_param SCRIPT_NAME "/demo_project";
232 scgi_param HTTPS "on";
233 }
234 </pre></blockquote>
235 <p>
236 Note that Fossil requires the SCRIPT_NAME variable
237 in order to function properly, but Nginx does not provide this
238
+1
--- www/th1.md
+++ www/th1.md
@@ -342,10 +342,11 @@
342342
1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
343343
1. **json** -- _Support for the JSON APIs._
344344
1. **markdown** -- _Support for Markdown documentation format._
345345
1. **unicodeCmdLine** -- _The command line arguments are Unicode._
346346
1. **dynamicBuild** -- _Dynamically linked to libraries._
347
+ 1. **see** -- _Uses the SQLite Encryption Extension._
347348
348349
Specifying an unknown feature will return a value of false, it will not
349350
raise a script error.
350351
351352
<a name="html"></a>TH1 html Command
352353
--- www/th1.md
+++ www/th1.md
@@ -342,10 +342,11 @@
342 1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
343 1. **json** -- _Support for the JSON APIs._
344 1. **markdown** -- _Support for Markdown documentation format._
345 1. **unicodeCmdLine** -- _The command line arguments are Unicode._
346 1. **dynamicBuild** -- _Dynamically linked to libraries._
 
347
348 Specifying an unknown feature will return a value of false, it will not
349 raise a script error.
350
351 <a name="html"></a>TH1 html Command
352
--- www/th1.md
+++ www/th1.md
@@ -342,10 +342,11 @@
342 1. **tclPrivateStubs** -- _Uses Tcl private stubs (i.e. header-only)._
343 1. **json** -- _Support for the JSON APIs._
344 1. **markdown** -- _Support for Markdown documentation format._
345 1. **unicodeCmdLine** -- _The command line arguments are Unicode._
346 1. **dynamicBuild** -- _Dynamically linked to libraries._
347 1. **see** -- _Uses the SQLite Encryption Extension._
348
349 Specifying an unknown feature will return a value of false, it will not
350 raise a script error.
351
352 <a name="html"></a>TH1 html Command
353

Keyboard Shortcuts

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