Fossil SCM

Bring tk diff viewer branch up to date

baruch 2014-12-30 21:04 UTC tk-diff-viewer merge
Commit 42436cef32953c82c4e66d092f7fa14985ef152d
66 files changed +1 -1 +1 -1 +14 -2 +2 -2 +394 -192 +303 +1 -3 +1 -1 +1 -2 +1 -1 +1 +4 -4 +168 -43 +4 -4 +2 -2 +1 +7 -1 +8 -6 +3 -1 +4 -3 +7 -2 +4 -4 +26 -1 +6 -1 +61 -1 +43 -8 +22 -2 +1 -1 +9 -2 +3 -6 +352 -51 +2 +1 +12 -7 +5 -3 +53 -37 +111 -6 +185 -75 +44 -13 +43 +17 -6 +2611 -1119 +472 -318 +3 -3 +66 -2 +1 -1 +60 -23 +1 -3 +12 -3 +1 -1 +2 -2 +4 -4 +34 -4 +84 -3 +84 -3 +83 -2 +64 -5 +21 +1 -1 +8 -8 +1 -1 +1 -1 +4 +1 -1 +1 -1
+1 -1
--- Makefile.in
+++ Makefile.in
@@ -37,11 +37,11 @@
3737
# care about testing the end result, this can be blank.
3838
#
3939
TCLSH = tclsh
4040
4141
LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42
-TCC += @EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H -D_HAVE_SQLITE_CONFIG_H
42
+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
FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
4646
4747
include $(SRCDIR)/main.mk
4848
--- Makefile.in
+++ Makefile.in
@@ -37,11 +37,11 @@
37 # care about testing the end result, this can be blank.
38 #
39 TCLSH = tclsh
40
41 LIB = @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
42 TCC += @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 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
46
47 include $(SRCDIR)/main.mk
48
--- Makefile.in
+++ Makefile.in
@@ -37,11 +37,11 @@
37 # care about testing the end result, this can be blank.
38 #
39 TCLSH = tclsh
40
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 FOSSIL_ENABLE_MINIZ = @FOSSIL_ENABLE_MINIZ@
46
47 include $(SRCDIR)/main.mk
48
+1 -1
--- src/allrepo.c
+++ src/allrepo.c
@@ -76,11 +76,11 @@
7676
7777
7878
/*
7979
** COMMAND: all
8080
**
81
-** Usage: %fossil all (changes|clean|extras|ignore|list|ls|pull|push|rebuild|sync)
81
+** Usage: %fossil all SUBCOMMAND ...
8282
**
8383
** The ~/.fossil file records the location of all repositories for a
8484
** user. This command performs certain operations on all repositories
8585
** that can be useful before or after a period of disconnected operation.
8686
**
8787
--- src/allrepo.c
+++ src/allrepo.c
@@ -76,11 +76,11 @@
76
77
78 /*
79 ** COMMAND: all
80 **
81 ** Usage: %fossil all (changes|clean|extras|ignore|list|ls|pull|push|rebuild|sync)
82 **
83 ** The ~/.fossil file records the location of all repositories for a
84 ** user. This command performs certain operations on all repositories
85 ** that can be useful before or after a period of disconnected operation.
86 **
87
--- src/allrepo.c
+++ src/allrepo.c
@@ -76,11 +76,11 @@
76
77
78 /*
79 ** COMMAND: all
80 **
81 ** Usage: %fossil all SUBCOMMAND ...
82 **
83 ** The ~/.fossil file records the location of all repositories for a
84 ** user. This command performs certain operations on all repositories
85 ** that can be useful before or after a period of disconnected operation.
86 **
87
+14 -2
--- src/blob.c
+++ src/blob.c
@@ -24,10 +24,14 @@
2424
# include "miniz.c"
2525
#else
2626
# include <zlib.h>
2727
#endif
2828
#include "blob.h"
29
+#if defined(_WIN32)
30
+#include <fcntl.h>
31
+#include <io.h>
32
+#endif
2933
3034
#if INTERFACE
3135
/*
3236
** A Blob can hold a string or a binary object of arbitrary size. The
3337
** size changes as necessary.
@@ -823,12 +827,18 @@
823827
nWrote = blob_size(pBlob);
824828
#if defined(_WIN32)
825829
if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){
826830
return nWrote;
827831
}
832
+ fflush(stdout);
833
+ _setmode(_fileno(stdout), _O_BINARY);
828834
#endif
829835
fwrite(blob_buffer(pBlob), 1, nWrote, stdout);
836
+#if defined(_WIN32)
837
+ fflush(stdout);
838
+ _setmode(_fileno(stdout), _O_TEXT);
839
+#endif
830840
}else{
831841
file_mkfolder(zFilename, 1);
832842
out = fossil_fopen(zFilename, "wb");
833843
if( out==0 ){
834844
fossil_fatal_recursive("unable to open file \"%s\" for writing",
@@ -1193,14 +1203,16 @@
11931203
/* Make sure the blob contains two terminating 0-bytes */
11941204
blob_append(pBlob, "", 1);
11951205
zUtf8 = blob_str(pBlob) + bomSize;
11961206
zUtf8 = fossil_unicode_to_utf8(zUtf8);
11971207
blob_set_dynamic(pBlob, zUtf8);
1198
-#if defined(_WIN32)
1199
- }else if( useMbcs ){
1208
+ }else if( useMbcs && invalid_utf8(pBlob) ){
1209
+#if defined(_WIN32) || defined(__CYGWIN__)
12001210
zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
12011211
blob_reset(pBlob);
12021212
blob_append(pBlob, zUtf8, -1);
12031213
fossil_mbcs_free(zUtf8);
1214
+#else
1215
+ blob_cp1252_to_utf8(pBlob);
12041216
#endif /* _WIN32 */
12051217
}
12061218
}
12071219
--- src/blob.c
+++ src/blob.c
@@ -24,10 +24,14 @@
24 # include "miniz.c"
25 #else
26 # include <zlib.h>
27 #endif
28 #include "blob.h"
 
 
 
 
29
30 #if INTERFACE
31 /*
32 ** A Blob can hold a string or a binary object of arbitrary size. The
33 ** size changes as necessary.
@@ -823,12 +827,18 @@
823 nWrote = blob_size(pBlob);
824 #if defined(_WIN32)
825 if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){
826 return nWrote;
827 }
 
 
828 #endif
829 fwrite(blob_buffer(pBlob), 1, nWrote, stdout);
 
 
 
 
830 }else{
831 file_mkfolder(zFilename, 1);
832 out = fossil_fopen(zFilename, "wb");
833 if( out==0 ){
834 fossil_fatal_recursive("unable to open file \"%s\" for writing",
@@ -1193,14 +1203,16 @@
1193 /* Make sure the blob contains two terminating 0-bytes */
1194 blob_append(pBlob, "", 1);
1195 zUtf8 = blob_str(pBlob) + bomSize;
1196 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1197 blob_set_dynamic(pBlob, zUtf8);
1198 #if defined(_WIN32)
1199 }else if( useMbcs ){
1200 zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1201 blob_reset(pBlob);
1202 blob_append(pBlob, zUtf8, -1);
1203 fossil_mbcs_free(zUtf8);
 
 
1204 #endif /* _WIN32 */
1205 }
1206 }
1207
--- src/blob.c
+++ src/blob.c
@@ -24,10 +24,14 @@
24 # include "miniz.c"
25 #else
26 # include <zlib.h>
27 #endif
28 #include "blob.h"
29 #if defined(_WIN32)
30 #include <fcntl.h>
31 #include <io.h>
32 #endif
33
34 #if INTERFACE
35 /*
36 ** A Blob can hold a string or a binary object of arbitrary size. The
37 ** size changes as necessary.
@@ -823,12 +827,18 @@
827 nWrote = blob_size(pBlob);
828 #if defined(_WIN32)
829 if( fossil_utf8_to_console(blob_buffer(pBlob), nWrote, 0) >= 0 ){
830 return nWrote;
831 }
832 fflush(stdout);
833 _setmode(_fileno(stdout), _O_BINARY);
834 #endif
835 fwrite(blob_buffer(pBlob), 1, nWrote, stdout);
836 #if defined(_WIN32)
837 fflush(stdout);
838 _setmode(_fileno(stdout), _O_TEXT);
839 #endif
840 }else{
841 file_mkfolder(zFilename, 1);
842 out = fossil_fopen(zFilename, "wb");
843 if( out==0 ){
844 fossil_fatal_recursive("unable to open file \"%s\" for writing",
@@ -1193,14 +1203,16 @@
1203 /* Make sure the blob contains two terminating 0-bytes */
1204 blob_append(pBlob, "", 1);
1205 zUtf8 = blob_str(pBlob) + bomSize;
1206 zUtf8 = fossil_unicode_to_utf8(zUtf8);
1207 blob_set_dynamic(pBlob, zUtf8);
1208 }else if( useMbcs && invalid_utf8(pBlob) ){
1209 #if defined(_WIN32) || defined(__CYGWIN__)
1210 zUtf8 = fossil_mbcs_to_utf8(blob_str(pBlob));
1211 blob_reset(pBlob);
1212 blob_append(pBlob, zUtf8, -1);
1213 fossil_mbcs_free(zUtf8);
1214 #else
1215 blob_cp1252_to_utf8(pBlob);
1216 #endif /* _WIN32 */
1217 }
1218 }
1219
+2 -2
--- src/branch.c
+++ src/branch.c
@@ -357,11 +357,11 @@
357357
if( colorTest ){
358358
const char *zColor = hash_color(zBr);
359359
@ <li><span style="background-color: %s(zColor)">
360360
@ %h(zBr) &rarr; %s(zColor)</span></li>
361361
}else{
362
- @ <li>%z(href("%R/timeline?r=%T",zBr))%h(zBr)</a></li>
362
+ @ <li>%z(href("%R/timeline?r=%T&n=200",zBr))%h(zBr)</a></li>
363363
}
364364
}
365365
if( cnt ){
366366
@ </ul>
367367
}
@@ -385,11 +385,11 @@
385385
" AND tag.tagname GLOB 'sym-*'",
386386
rid
387387
);
388388
while( db_step(&q)==SQLITE_ROW ){
389389
const char *zTagName = db_column_text(&q, 0);
390
- @ %z(href("%R/timeline?r=%T",zTagName))[timeline]</a>
390
+ @ %z(href("%R/timeline?r=%T&n=200",zTagName))[timeline]</a>
391391
}
392392
db_finalize(&q);
393393
}
394394
395395
/*
396396
--- src/branch.c
+++ src/branch.c
@@ -357,11 +357,11 @@
357 if( colorTest ){
358 const char *zColor = hash_color(zBr);
359 @ <li><span style="background-color: %s(zColor)">
360 @ %h(zBr) &rarr; %s(zColor)</span></li>
361 }else{
362 @ <li>%z(href("%R/timeline?r=%T",zBr))%h(zBr)</a></li>
363 }
364 }
365 if( cnt ){
366 @ </ul>
367 }
@@ -385,11 +385,11 @@
385 " AND tag.tagname GLOB 'sym-*'",
386 rid
387 );
388 while( db_step(&q)==SQLITE_ROW ){
389 const char *zTagName = db_column_text(&q, 0);
390 @ %z(href("%R/timeline?r=%T",zTagName))[timeline]</a>
391 }
392 db_finalize(&q);
393 }
394
395 /*
396
--- src/branch.c
+++ src/branch.c
@@ -357,11 +357,11 @@
357 if( colorTest ){
358 const char *zColor = hash_color(zBr);
359 @ <li><span style="background-color: %s(zColor)">
360 @ %h(zBr) &rarr; %s(zColor)</span></li>
361 }else{
362 @ <li>%z(href("%R/timeline?r=%T&n=200",zBr))%h(zBr)</a></li>
363 }
364 }
365 if( cnt ){
366 @ </ul>
367 }
@@ -385,11 +385,11 @@
385 " AND tag.tagname GLOB 'sym-*'",
386 rid
387 );
388 while( db_step(&q)==SQLITE_ROW ){
389 const char *zTagName = db_column_text(&q, 0);
390 @ %z(href("%R/timeline?r=%T&n=200",zTagName))[timeline]</a>
391 }
392 db_finalize(&q);
393 }
394
395 /*
396
+394 -192
--- src/browse.c
+++ src/browse.c
@@ -304,89 +304,206 @@
304304
305305
/*
306306
** A single line of the file hierarchy
307307
*/
308308
struct FileTreeNode {
309
- FileTreeNode *pNext; /* Next line in sequence */
310
- FileTreeNode *pPrev; /* Previous line */
311
- FileTreeNode *pParent; /* Directory containing this line */
309
+ FileTreeNode *pNext; /* Next entry in an ordered list of them all */
310
+ FileTreeNode *pParent; /* Directory containing this entry */
311
+ FileTreeNode *pSibling; /* Next element in the same subdirectory */
312
+ FileTreeNode *pChild; /* List of child nodes */
313
+ FileTreeNode *pLastChild; /* Last child on the pChild list */
312314
char *zName; /* Name of this entry. The "tail" */
313315
char *zFullName; /* Full pathname of this entry */
314316
char *zUuid; /* SHA1 hash of this file. May be NULL. */
317
+ double mtime; /* Modification time for this entry */
315318
unsigned nFullName; /* Length of zFullName */
316319
unsigned iLevel; /* Levels of parent directories */
317
- u8 isDir; /* True if there are children */
318
- u8 isLast; /* True if this is the last child of its parent */
319320
};
320321
321322
/*
322323
** A complete file hierarchy
323324
*/
324325
struct FileTree {
325326
FileTreeNode *pFirst; /* First line of the list */
326327
FileTreeNode *pLast; /* Last line of the list */
328
+ FileTreeNode *pLastTop; /* Last top-level node */
327329
};
328330
329331
/*
330332
** Add one or more new FileTreeNodes to the FileTree object so that the
331
-** leaf object zPathname is at the end of the node list
333
+** leaf object zPathname is at the end of the node list.
334
+**
335
+** The caller invokes this routine once for each leaf node (each file
336
+** as opposed to each directory). This routine fills in any missing
337
+** intermediate nodes automatically.
338
+**
339
+** When constructing a list of FileTreeNodes, all entries that have
340
+** a common directory prefix must be added consecutively in order for
341
+** the tree to be constructed properly.
332342
*/
333343
static void tree_add_node(
334344
FileTree *pTree, /* Tree into which nodes are added */
335345
const char *zPath, /* The full pathname of file to add */
336
- const char *zUuid /* UUID of the file. Might be NULL. */
346
+ const char *zUuid, /* UUID of the file. Might be NULL. */
347
+ double mtime /* Modification time for this entry */
337348
){
338349
int i;
339
- FileTreeNode *pParent;
340
- FileTreeNode *pChild;
350
+ FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
341351
342
- pChild = pTree->pLast;
343
- pParent = pChild ? pChild->pParent : 0;
352
+ /* Make pParent point to the most recent ancestor of zPath, or
353
+ ** NULL if there are no prior entires that are a container for zPath.
354
+ */
355
+ pParent = pTree->pLast;
344356
while( pParent!=0 &&
345357
( strncmp(pParent->zFullName, zPath, pParent->nFullName)!=0
346358
|| zPath[pParent->nFullName]!='/' )
347359
){
348
- pChild = pParent;
349
- pParent = pChild->pParent;
360
+ pParent = pParent->pParent;
350361
}
351362
i = pParent ? pParent->nFullName+1 : 0;
352
- if( pChild ) pChild->isLast = 0;
353363
while( zPath[i] ){
354364
FileTreeNode *pNew;
355365
int iStart = i;
356366
int nByte;
357367
while( zPath[i] && zPath[i]!='/' ){ i++; }
358368
nByte = sizeof(*pNew) + i + 1;
359369
if( zUuid!=0 && zPath[i]==0 ) nByte += UUID_SIZE+1;
360370
pNew = fossil_malloc( nByte );
371
+ memset(pNew, 0, sizeof(*pNew));
361372
pNew->zFullName = (char*)&pNew[1];
362373
memcpy(pNew->zFullName, zPath, i);
363374
pNew->zFullName[i] = 0;
364375
pNew->nFullName = i;
365376
if( zUuid!=0 && zPath[i]==0 ){
366377
pNew->zUuid = pNew->zFullName + i + 1;
367378
memcpy(pNew->zUuid, zUuid, UUID_SIZE+1);
368
- }else{
369
- pNew->zUuid = 0;
370379
}
371380
pNew->zName = pNew->zFullName + iStart;
372381
if( pTree->pLast ){
373382
pTree->pLast->pNext = pNew;
374383
}else{
375384
pTree->pFirst = pNew;
376385
}
377
- pNew->pPrev = pTree->pLast;
378
- pNew->pNext = 0;
386
+ pTree->pLast = pNew;
379387
pNew->pParent = pParent;
380
- pTree->pLast = pNew;
381
- pNew->iLevel = pParent ? pParent->iLevel+1 : 0;
382
- pNew->isDir = zPath[i]=='/';
383
- pNew->isLast = 1;
388
+ if( pParent ){
389
+ if( pParent->pChild ){
390
+ pParent->pLastChild->pSibling = pNew;
391
+ }else{
392
+ pParent->pChild = pNew;
393
+ }
394
+ pNew->iLevel = pParent->iLevel + 1;
395
+ pParent->pLastChild = pNew;
396
+ }else{
397
+ if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
398
+ pTree->pLastTop = pNew;
399
+ }
400
+ pNew->mtime = mtime;
384401
while( zPath[i]=='/' ){ i++; }
385402
pParent = pNew;
386403
}
404
+ while( pParent && pParent->pParent ){
405
+ if( pParent->pParent->mtime < pParent->mtime ){
406
+ pParent->pParent->mtime = pParent->mtime;
407
+ }
408
+ pParent = pParent->pParent;
409
+ }
410
+}
411
+
412
+/* Comparison function for two FileTreeNode objects. Sort first by
413
+** mtime (larger numbers first) and then by zName (smaller names first).
414
+**
415
+** Return negative if pLeft<pRight.
416
+** Return positive if pLeft>pRight.
417
+** Return zero if pLeft==pRight.
418
+*/
419
+static int compareNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
420
+ if( pLeft->mtime>pRight->mtime ) return -1;
421
+ if( pLeft->mtime<pRight->mtime ) return +1;
422
+ return fossil_stricmp(pLeft->zName, pRight->zName);
423
+}
424
+
425
+/* Merge together two sorted lists of FileTreeNode objects */
426
+static FileTreeNode *mergeNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
427
+ FileTreeNode *pEnd;
428
+ FileTreeNode base;
429
+ pEnd = &base;
430
+ while( pLeft && pRight ){
431
+ if( compareNodes(pLeft,pRight)<=0 ){
432
+ pEnd = pEnd->pSibling = pLeft;
433
+ pLeft = pLeft->pSibling;
434
+ }else{
435
+ pEnd = pEnd->pSibling = pRight;
436
+ pRight = pRight->pSibling;
437
+ }
438
+ }
439
+ if( pLeft ){
440
+ pEnd->pSibling = pLeft;
441
+ }else{
442
+ pEnd->pSibling = pRight;
443
+ }
444
+ return base.pSibling;
445
+}
446
+
447
+/* Sort a list of FileTreeNode objects in mtime order. */
448
+static FileTreeNode *sortNodesByMtime(FileTreeNode *p){
449
+ FileTreeNode *a[30];
450
+ FileTreeNode *pX;
451
+ int i;
452
+
453
+ memset(a, 0, sizeof(a));
454
+ while( p ){
455
+ pX = p;
456
+ p = pX->pSibling;
457
+ pX->pSibling = 0;
458
+ for(i=0; i<count(a)-1 && a[i]!=0; i++){
459
+ pX = mergeNodes(a[i], pX);
460
+ a[i] = 0;
461
+ }
462
+ a[i] = mergeNodes(a[i], pX);
463
+ }
464
+ pX = 0;
465
+ for(i=0; i<count(a); i++){
466
+ pX = mergeNodes(a[i], pX);
467
+ }
468
+ return pX;
469
+}
470
+
471
+/* Sort an entire FileTreeNode tree by mtime
472
+**
473
+** This routine invalidates the following fields:
474
+**
475
+** FileTreeNode.pLastChild
476
+** FileTreeNode.pNext
477
+**
478
+** Use relinkTree to reconnect the pNext pointers.
479
+*/
480
+static FileTreeNode *sortTreeByMtime(FileTreeNode *p){
481
+ FileTreeNode *pX;
482
+ for(pX=p; pX; pX=pX->pSibling){
483
+ if( pX->pChild ) pX->pChild = sortTreeByMtime(pX->pChild);
484
+ }
485
+ return sortNodesByMtime(p);
486
+}
487
+
488
+/* Reconstruct the FileTree by reconnecting the FileTreeNode.pNext
489
+** fields in sequential order.
490
+*/
491
+static void relinkTree(FileTree *pTree, FileTreeNode *pRoot){
492
+ while( pRoot ){
493
+ if( pTree->pLast ){
494
+ pTree->pLast->pNext = pRoot;
495
+ }else{
496
+ pTree->pFirst = pRoot;
497
+ }
498
+ pTree->pLast = pRoot;
499
+ if( pRoot->pChild ) relinkTree(pTree, pRoot->pChild);
500
+ pRoot = pRoot->pSibling;
501
+ }
502
+ if( pTree->pLast ) pTree->pLast->pNext = 0;
387503
}
504
+
388505
389506
/*
390507
** WEBPAGE: tree
391508
**
392509
** Query parameters:
@@ -394,19 +511,23 @@
394511
** name=PATH Directory to display. Optional
395512
** ci=LABEL Show only files in this check-in. Optional.
396513
** re=REGEXP Show only files matching REGEXP. Optional.
397514
** expand Begin with the tree fully expanded.
398515
** nofiles Show directories (folders) only. Omit files.
516
+** mtime Order directory elements by decreasing mtime
399517
*/
400518
void page_tree(void){
401519
char *zD = fossil_strdup(P("name"));
402520
int nD = zD ? strlen(zD)+1 : 0;
403521
const char *zCI = P("ci");
404522
int rid = 0;
405523
char *zUuid = 0;
406524
Blob dirname;
407525
Manifest *pM = 0;
526
+ double rNow = 0;
527
+ char *zNow = 0;
528
+ int useMtime = atoi(PD("mtime","0"));
408529
int nFile = 0; /* Number of files (or folders with "nofiles") */
409530
int linkTrunk = 1; /* include link to "trunk" */
410531
int linkTip = 1; /* include link to "tip" */
411532
const char *zRE; /* the value for the re=REGEXP query parameter */
412533
const char *zObjType; /* "files" by default or "folders" for "nofiles" */
@@ -464,14 +585,21 @@
464585
int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
465586
linkTrunk = trunkRid && rid != trunkRid;
466587
linkTip = rid != symbolic_name_to_rid("tip", "ci");
467588
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
468589
url_add_parameter(&sURI, "ci", zCI);
590
+ rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
591
+ zNow = db_text("", "SELECT datetime(mtime,'localtime')"
592
+ " FROM event WHERE objid=%d", rid);
469593
}else{
470594
zCI = 0;
471595
}
472596
}
597
+ if( zCI==0 ){
598
+ rNow = db_double(0.0, "SELECT max(mtime) FROM event");
599
+ zNow = db_text("", "SELECT datetime(max(mtime),'localtime') FROM event");
600
+ }
473601
474602
/* Compute the title of the page */
475603
blob_zero(&dirname);
476604
if( zD ){
477605
url_add_parameter(&sURI, "name", zD);
@@ -483,10 +611,18 @@
483611
}else{
484612
if( zRE ){
485613
blob_appendf(&dirname, "matching \"%s\"", zRE);
486614
}
487615
}
616
+ if( useMtime ){
617
+ style_submenu_element("Sort By Filename","Sort By Filename", "%s",
618
+ url_render(&sURI, 0, 0, 0, 0));
619
+ url_add_parameter(&sURI, "mtime", "1");
620
+ }else{
621
+ style_submenu_element("Sort By Time","Sort By Time", "%s",
622
+ url_render(&sURI, "mtime", "1", 0, 0));
623
+ }
488624
if( zCI ){
489625
style_submenu_element("All", "All", "%s",
490626
url_render(&sURI, "ci", 0, 0, 0));
491627
if( nD==0 && !showDirOnly ){
492628
style_submenu_element("File Ages", "File Ages", "%R/fileage?name=%s",
@@ -499,87 +635,82 @@
499635
}
500636
if( linkTip ){
501637
style_submenu_element("Tip", "Tip", "%s",
502638
url_render(&sURI, "ci", "tip", 0, 0));
503639
}
504
- if( !showDirOnly ){
505
- style_submenu_element("Flat-View", "Flat-View", "%s",
506
- url_render(&sURI, "type", "flat", 0, 0));
507
- }
508640
509641
/* Compute the file hierarchy.
510642
*/
511643
if( zCI ){
512
- Stmt ins, q;
513
- ManifestFile *pFile;
514
-
515
- db_multi_exec(
516
- "CREATE TEMP TABLE filelist("
517
- " x TEXT PRIMARY KEY COLLATE nocase,"
518
- " uuid TEXT"
519
- ") WITHOUT ROWID;"
644
+ Stmt q;
645
+ compute_fileage(rid, 0);
646
+ db_prepare(&q,
647
+ "SELECT filename.name, blob.uuid, fileage.mtime\n"
648
+ " FROM fileage, filename, blob\n"
649
+ " WHERE filename.fnid=fileage.fnid\n"
650
+ " AND blob.rid=fileage.fid\n"
651
+ " ORDER BY filename.name COLLATE nocase;"
520652
);
521
- db_prepare(&ins, "INSERT OR IGNORE INTO filelist VALUES(:f,:u)");
522
- manifest_file_rewind(pM);
523
- while( (pFile = manifest_file_next(pM,0))!=0 ){
524
- if( nD>0
525
- && (fossil_strncmp(pFile->zName, zD, nD-1)!=0
526
- || pFile->zName[nD-1]!='/')
527
- ){
528
- continue;
529
- }
530
- if( pRE && re_match(pRE, (const u8*)pFile->zName, -1)==0 ) continue;
531
- db_bind_text(&ins, ":f", pFile->zName);
532
- db_bind_text(&ins, ":u", pFile->zUuid);
533
- db_step(&ins);
534
- db_reset(&ins);
535
- }
536
- db_finalize(&ins);
537
- db_prepare(&q, "SELECT x, uuid FROM filelist ORDER BY x");
538653
while( db_step(&q)==SQLITE_ROW ){
539
- tree_add_node(&sTree, db_column_text(&q,0), db_column_text(&q,1));
654
+ const char *zFile = db_column_text(&q,0);
655
+ const char *zUuid = db_column_text(&q,1);
656
+ double mtime = db_column_double(&q,2);
657
+ if( pRE && re_match(pRE, (const unsigned char*)zFile, -1)==0 ) continue;
658
+ tree_add_node(&sTree, zFile, zUuid, mtime);
540659
nFile++;
541660
}
542661
db_finalize(&q);
543662
}else{
544663
Stmt q;
545
- db_prepare(&q, "SELECT name FROM filename ORDER BY name COLLATE nocase");
664
+ db_prepare(&q,
665
+ "SELECT filename.name, blob.uuid, max(event.mtime)\n"
666
+ " FROM filename, mlink, blob, event\n"
667
+ " WHERE mlink.fnid=filename.fnid\n"
668
+ " AND event.objid=mlink.mid\n"
669
+ " AND blob.rid=mlink.fid\n"
670
+ " GROUP BY 1 ORDER BY 1 COLLATE nocase");
546671
while( db_step(&q)==SQLITE_ROW ){
547
- const char *z = db_column_text(&q, 0);
548
- if( nD>0 && (fossil_strncmp(z, zD, nD-1)!=0 || z[nD-1]!='/') ){
672
+ const char *zName = db_column_text(&q, 0);
673
+ const char *zUuid = db_column_text(&q,1);
674
+ double mtime = db_column_double(&q,2);
675
+ if( nD>0 && (fossil_strncmp(zName, zD, nD-1)!=0 || zName[nD-1]!='/') ){
549676
continue;
550677
}
551
- if( pRE && re_match(pRE, (const u8*)z, -1)==0 ) continue;
552
- tree_add_node(&sTree, z, 0);
678
+ if( pRE && re_match(pRE, (const u8*)zName, -1)==0 ) continue;
679
+ tree_add_node(&sTree, zName, zUuid, mtime);
553680
nFile++;
554681
}
555682
db_finalize(&q);
556683
}
557684
558685
if( showDirOnly ){
559686
for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
560
- if( p->isDir && p->nFullName>nD ) nFile++;
687
+ if( p->pChild!=0 && p->nFullName>nD ) nFile++;
561688
}
562
- zObjType = "folders";
689
+ zObjType = "Folders";
563690
style_submenu_element("Files","Files","%s",
564691
url_render(&sURI,"nofiles",0,0,0));
565692
}else{
566
- zObjType = "files";
693
+ zObjType = "Files";
567694
style_submenu_element("Folders","Folders","%s",
568695
url_render(&sURI,"nofiles","1",0,0));
569696
}
570697
571698
if( zCI ){
572
- @ <h2>%d(nFile) %s(zObjType) of check-in
699
+ @ <h2>%s(zObjType) from
573700
if( sqlite3_strnicmp(zCI, zUuid, (int)strlen(zCI))!=0 ){
574701
@ "%h(zCI)"
575702
}
576
- @ [%z(href("vinfo?name=%s",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))</h2>
703
+ @ [%z(href("vinfo?name=%s",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))
577704
}else{
578705
int n = db_int(0, "SELECT count(*) FROM plink");
579
- @ <h2>%d(nFile) %s(zObjType) from all %d(n) check-ins
580
- @ %s(blob_str(&dirname))</h2>
706
+ @ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname))
707
+ }
708
+ if( useMtime ){
709
+ @ sorted by modification time</h2>
710
+ }else{
711
+ @ sorted by filename</h2>
581712
}
582713
583714
584715
/* Generate tree of lists.
585716
**
@@ -596,18 +727,33 @@
596727
if( nD ){
597728
@ <li class="dir last">
598729
}else{
599730
@ <li class="dir subdir last">
600731
}
732
+ @ <div class="filetreeline">
601733
@ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a>
734
+ if( zNow ){
735
+ @ <div class="filetreeage">%s(zNow)</div>
736
+ }
737
+ @ </div>
602738
@ <ul>
739
+ if( useMtime ){
740
+ p = sortTreeByMtime(sTree.pFirst);
741
+ memset(&sTree, 0, sizeof(sTree));
742
+ relinkTree(&sTree, p);
743
+ }
603744
for(p=sTree.pFirst, nDir=0; p; p=p->pNext){
604
- const char *zLastClass = p->isLast ? " last" : "";
605
- if( p->isDir ){
745
+ const char *zLastClass = p->pSibling==0 ? " last" : "";
746
+ if( p->pChild ){
606747
const char *zSubdirClass = p->nFullName==nD-1 ? " subdir" : "";
607
- @ <li class="dir%s(zSubdirClass)%s(zLastClass)">
748
+ @ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
608749
@ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
750
+ if( p->mtime>0.0 ){
751
+ char *zAge = human_readable_age(rNow - p->mtime);
752
+ @ <div class="filetreeage">%s(zAge)</div>
753
+ }
754
+ @ </div>
609755
if( startExpanded || p->nFullName<=nD ){
610756
@ <ul id="dir%d(nDir)">
611757
}else{
612758
@ <ul id="dir%d(nDir)" class="collapsed">
613759
}
@@ -614,17 +760,23 @@
614760
nDir++;
615761
}else if( !showDirOnly ){
616762
const char *zFileClass = fileext_class(p->zName);
617763
char *zLink;
618764
if( zCI ){
619
- zLink = href("%R/artifact/%s",p->zUuid);
765
+ zLink = href("%R/artifact/%.16s",p->zUuid);
620766
}else{
621767
zLink = href("%R/finfo?name=%T",p->zFullName);
622768
}
623
- @ <li class="%z(zFileClass)%s(zLastClass)">%z(zLink)%h(p->zName)</a>
769
+ @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
770
+ @ %z(zLink)%h(p->zName)</a>
771
+ if( p->mtime>0 ){
772
+ char *zAge = human_readable_age(rNow - p->mtime);
773
+ @ <div class="filetreeage">%s(zAge)</div>
774
+ }
775
+ @ </div>
624776
}
625
- if( p->isLast ){
777
+ if( p->pSibling==0 ){
626778
int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
627779
while( nClose-- > 0 ){
628780
@ </ul>
629781
}
630782
}
@@ -687,16 +839,16 @@
687839
@ checkState();
688840
@ outer_ul.onclick = function(e){
689841
@ e = e || window.event;
690842
@ var a = e.target || e.srcElement;
691843
@ if( a.nodeName!='A' ) return true;
692
- @ if( a.parentNode==subdir ){
844
+ @ if( a.parentNode.parentNode==subdir ){
693845
@ toggleAll(outer_ul);
694846
@ return false;
695847
@ }
696848
@ if( !belowSubdir(a) ) return true;
697
- @ var ul = a.nextSibling;
849
+ @ var ul = a.parentNode.nextSibling;
698850
@ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
699851
@ if( !ul ) return true; /* This is a file link, not a directory */
700852
@ toggleDir(ul);
701853
@ return false;
702854
@ }
@@ -724,87 +876,115 @@
724876
}else{
725877
zClass = mprintf("file");
726878
}
727879
return zClass;
728880
}
881
+
882
+/*
883
+** SQL used to compute the age of all files in checkin :ckin whose
884
+** names match :glob
885
+*/
886
+static const char zComputeFileAgeSetup[] =
887
+@ CREATE TABLE IF NOT EXISTS temp.fileage(
888
+@ fnid INTEGER PRIMARY KEY,
889
+@ fid INTEGER,
890
+@ mid INTEGER,
891
+@ mtime DATETIME,
892
+@ pathname TEXT
893
+@ );
894
+@ CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;
895
+;
896
+
897
+static const char zComputeFileAgeRun[] =
898
+@ WITH RECURSIVE
899
+@ ckin(x) AS (VALUES(:ckin) UNION ALL
900
+@ SELECT pid FROM ckin, plink WHERE cid=x AND isprim)
901
+@ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname)
902
+@ SELECT mlink.fnid, mlink.fid, x, event.mtime, filename.name
903
+@ FROM ckin, mlink, event, filename
904
+@ WHERE mlink.mid=ckin.x
905
+@ AND mlink.fnid IN (SELECT fnid FROM foci, filename
906
+@ WHERE foci.checkinID=:ckin
907
+@ AND filename.name=foci.filename
908
+@ AND filename.name GLOB :glob)
909
+@ AND filename.fnid=mlink.fnid
910
+@ AND event.objid=mlink.mid;
911
+;
912
+
729913
730914
/*
731915
** Look at all file containing in the version "vid". Construct a
732916
** temporary table named "fileage" that contains the file-id for each
733917
** files, the pathname, the check-in where the file was added, and the
734918
** mtime on that checkin. If zGlob and *zGlob then only files matching
735919
** the given glob are computed.
736920
*/
737921
int compute_fileage(int vid, const char* zGlob){
738
- Manifest *pManifest;
739
- ManifestFile *pFile;
740
- int nFile = 0;
741
- double vmtime;
742
- Stmt ins;
743
- Stmt q1, q2, q3;
744
- Stmt upd;
745
- if(zGlob && !*zGlob) zGlob = NULL;
746
- db_multi_exec(
747
- /*"DROP TABLE IF EXISTS temp.fileage;"*/
748
- "CREATE TEMP TABLE fileage("
749
- " fid INTEGER,"
750
- " mid INTEGER,"
751
- " mtime DATETIME,"
752
- " pathname TEXT"
753
- ");"
754
- "CREATE INDEX fileage_fid ON fileage(fid);"
755
- );
756
- pManifest = manifest_get(vid, CFTYPE_MANIFEST, 0);
757
- if( pManifest==0 ) return 1;
758
- manifest_file_rewind(pManifest);
759
- db_prepare(&ins,
760
- "INSERT INTO temp.fileage(fid, pathname)"
761
- " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762
- );
763
- while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764
- if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765
- db_bind_text(&ins, ":uuid", pFile->zUuid);
766
- db_bind_text(&ins, ":path", pFile->zName);
767
- db_step(&ins);
768
- db_reset(&ins);
769
- nFile++;
770
- }
771
- db_finalize(&ins);
772
- manifest_destroy(pManifest);
773
- db_prepare(&q1,"SELECT fid FROM mlink WHERE mid=:mid");
774
- db_prepare(&upd, "UPDATE fileage SET mid=:mid, mtime=:vmtime"
775
- " WHERE fid=:fid AND mid IS NULL");
776
- db_prepare(&q2,"SELECT pid FROM plink WHERE cid=:vid AND isprim");
777
- db_prepare(&q3,"SELECT mtime FROM event WHERE objid=:vid");
778
- while( nFile>0 && vid>0 ){
779
- db_bind_int(&q3, ":vid", vid);
780
- if( db_step(&q3)==SQLITE_ROW ){
781
- vmtime = db_column_double(&q3, 0);
782
- }else{
783
- break;
784
- }
785
- db_reset(&q3);
786
- db_bind_int(&q1, ":mid", vid);
787
- db_bind_int(&upd, ":mid", vid);
788
- db_bind_double(&upd, ":vmtime", vmtime);
789
- while( db_step(&q1)==SQLITE_ROW ){
790
- db_bind_int(&upd, ":fid", db_column_int(&q1, 0));
791
- db_step(&upd);
792
- nFile -= db_changes();
793
- db_reset(&upd);
794
- }
795
- db_reset(&q1);
796
- db_bind_int(&q2, ":vid", vid);
797
- if( db_step(&q2)!=SQLITE_ROW ) break;
798
- vid = db_column_int(&q2, 0);
799
- db_reset(&q2);
800
- }
801
- db_finalize(&q1);
802
- db_finalize(&upd);
803
- db_finalize(&q2);
804
- db_finalize(&q3);
805
- return 0;
922
+ Stmt q;
923
+ db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
924
+ db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
925
+ db_bind_int(&q, ":ckin", vid);
926
+ db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
927
+ db_exec(&q);
928
+ db_finalize(&q);
929
+ return 0;
930
+}
931
+
932
+/*
933
+** Render the number of days in rAge as a more human-readable time span.
934
+** Different units (seconds, minutes, hours, days, months, years) are
935
+** selected depending on the magnitude of rAge.
936
+**
937
+** The string returned is obtained from fossil_malloc() and should be
938
+** freed by the caller.
939
+*/
940
+char *human_readable_age(double rAge){
941
+ if( rAge*86400.0<120 ){
942
+ if( rAge*86400.0<1.0 ){
943
+ return mprintf("current");
944
+ }else{
945
+ return mprintf("%d seconds", (int)(rAge*86400.0));
946
+ }
947
+ }else if( rAge*1440.0<90 ){
948
+ return mprintf("%.1f minutes", rAge*1440.0);
949
+ }else if( rAge*24.0<36 ){
950
+ return mprintf("%.1f hours", rAge*24.0);
951
+ }else if( rAge<365.0 ){
952
+ return mprintf("%.1f days", rAge);
953
+ }else{
954
+ return mprintf("%.2f years", rAge/365.0);
955
+ }
956
+}
957
+
958
+/*
959
+** COMMAND: test-fileage
960
+**
961
+** Usage: %fossil test-fileage CHECKIN
962
+*/
963
+void test_fileage_cmd(void){
964
+ int mid;
965
+ Stmt q;
966
+ const char *zGlob = find_option("glob",0,1);
967
+ db_find_and_open_repository(0,0);
968
+ verify_all_options();
969
+ if( g.argc!=3 ) usage("test-fileage CHECKIN");
970
+ mid = name_to_typed_rid(g.argv[2],"ci");
971
+ compute_fileage(mid, zGlob);
972
+ db_prepare(&q,
973
+ "SELECT fid, mid, julianday('now') - mtime, pathname"
974
+ " FROM fileage"
975
+ );
976
+ while( db_step(&q)==SQLITE_ROW ){
977
+ char *zAge = human_readable_age(db_column_double(&q,2));
978
+ fossil_print("%8d %8d %16s %s\n",
979
+ db_column_int(&q,0),
980
+ db_column_int(&q,1),
981
+ zAge,
982
+ db_column_text(&q,3));
983
+ fossil_free(zAge);
984
+ }
985
+ db_finalize(&q);
806986
}
807987
808988
/*
809989
** WEBPAGE: fileage
810990
**
@@ -814,72 +994,94 @@
814994
** (e.g. *.c or *.txt).
815995
*/
816996
void fileage_page(void){
817997
int rid;
818998
const char *zName;
819
- char *zBaseTime;
820999
const char *zGlob;
821
- Stmt q;
1000
+ const char *zUuid;
1001
+ const char *zNow; /* Time of checkin */
1002
+ Stmt q1, q2;
8221003
double baseTime;
823
- int lastMid = -1;
8241004
login_check_credentials();
8251005
if( !g.perm.Read ){ login_needed(); return; }
8261006
zName = P("name");
8271007
if( zName==0 ) zName = "tip";
8281008
rid = symbolic_name_to_rid(zName, "ci");
8291009
if( rid==0 ){
8301010
fossil_fatal("not a valid check-in: %s", zName);
8311011
}
832
- style_submenu_element("Tree-View", "Tree-View", "%R/tree?ci=%T", zName);
1012
+ zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1013
+ baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid);
1014
+ zNow = db_text("", "SELECT datetime(mtime,'localtime') FROM event"
1015
+ " WHERE objid=%d", rid);
1016
+ style_submenu_element("Tree-View", "Tree-View", "%R/tree?ci=%T&mtime=1",
1017
+ zName);
8331018
style_header("File Ages");
8341019
zGlob = P("glob");
8351020
compute_fileage(rid,zGlob);
836
- baseTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
837
- zBaseTime = db_text("","SELECT datetime(%.20g%s)", baseTime, timeline_utc());
838
- @ <h2>File Ages For Check-in
839
- @ %z(href("%R/info?name=%T",zName))%h(zName)</a></h2>
840
- @
841
- @ <p>The times given are relative to
842
- @ %z(href("%R/timeline?c=%T",zBaseTime))%s(zBaseTime)</a>, which is the
843
- @ check-in time for
844
- @ %z(href("%R/info?name=%T",zName))%h(zName)</a></p>
845
- @
846
- @ <table border=0 cellspacing=0 cellpadding=0>
847
- db_prepare(&q,
848
- "SELECT mtime, (SELECT uuid FROM blob WHERE rid=fid), mid, pathname"
849
- " FROM fileage"
850
- " ORDER BY mtime DESC, mid, pathname"
851
- );
852
- while( db_step(&q)==SQLITE_ROW ){
853
- double age = baseTime - db_column_double(&q, 0);
854
- int mid = db_column_int(&q, 2);
855
- const char *zFUuid = db_column_text(&q, 1);
856
- char zAge[200];
857
- if( lastMid!=mid ){
858
- @ <tr><td colspan=3><hr></tr>
859
- lastMid = mid;
860
- if( age*86400.0<120 ){
861
- sqlite3_snprintf(sizeof(zAge), zAge, "%d seconds", (int)(age*86400.0));
862
- }else if( age*1440.0<90 ){
863
- sqlite3_snprintf(sizeof(zAge), zAge, "%.1f minutes", age*1440.0);
864
- }else if( age*24.0<36 ){
865
- sqlite3_snprintf(sizeof(zAge), zAge, "%.1f hours", age*24.0);
866
- }else if( age<365.0 ){
867
- sqlite3_snprintf(sizeof(zAge), zAge, "%.1f days", age);
868
- }else{
869
- sqlite3_snprintf(sizeof(zAge), zAge, "%.2f years", age/365.0);
870
- }
871
- }else{
872
- zAge[0] = 0;
873
- }
874
- @ <tr>
875
- @ <td>%s(zAge)
876
- @ <td width="25">
877
- @ <td>%z(href("%R/artifact/%s?ln", zFUuid))%h(db_column_text(&q, 3))</a>
878
- @ </tr>
879
- @
880
- }
881
- @ <tr><td colspan=3><hr></tr>
882
- @ </table>
883
- db_finalize(&q);
1021
+ db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);");
1022
+
1023
+ @ <h2>Files in
1024
+ @ %z(href("%R/info?name=%T",zUuid))[%S(zUuid)]</a>
1025
+ if( zGlob && zGlob[0] ){
1026
+ @ that match "%h(zGlob)" and
1027
+ }
1028
+ @ ordered by check-in time</h2>
1029
+ @
1030
+ @ <p>Times are relative to the checkin time for
1031
+ @ %z(href("%R/ci/%s",zUuid))[%S(zUuid)]</a> which is
1032
+ @ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p>
1033
+ @
1034
+ @ <div class='fileage'><table>
1035
+ @ <tr><th>Time</th><th>Files</th><th>Checkin</th></tr>
1036
+ db_prepare(&q1,
1037
+ "SELECT event.mtime, event.objid, blob.uuid,\n"
1038
+ " coalesce(event.ecomment,event.comment),\n"
1039
+ " coalesce(event.euser,event.user),\n"
1040
+ " coalesce((SELECT value FROM tagxref\n"
1041
+ " WHERE tagtype>0 AND tagid=%d\n"
1042
+ " AND rid=event.objid),'trunk')\n"
1043
+ " FROM event, blob\n"
1044
+ " WHERE event.objid IN (SELECT mid FROM fileage)\n"
1045
+ " AND blob.rid=event.objid\n"
1046
+ " ORDER BY event.mtime DESC;",
1047
+ TAG_BRANCH
1048
+ );
1049
+ db_prepare(&q2,
1050
+ "SELECT blob.uuid, filename.name\n"
1051
+ " FROM fileage, blob, filename\n"
1052
+ " WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid"
1053
+ " AND blob.rid=fileage.fid;"
1054
+ );
1055
+ while( db_step(&q1)==SQLITE_ROW ){
1056
+ double age = baseTime - db_column_double(&q1, 0);
1057
+ int mid = db_column_int(&q1, 1);
1058
+ const char *zUuid = db_column_text(&q1, 2);
1059
+ const char *zComment = db_column_text(&q1, 3);
1060
+ const char *zUser = db_column_text(&q1, 4);
1061
+ const char *zBranch = db_column_text(&q1, 5);
1062
+ char *zAge = human_readable_age(age);
1063
+ @ <tr><td>%s(zAge)</td>
1064
+ @ <td>
1065
+ db_bind_int(&q2, ":mid", mid);
1066
+ while( db_step(&q2)==SQLITE_ROW ){
1067
+ const char *zFUuid = db_column_text(&q2,0);
1068
+ const char *zFile = db_column_text(&q2,1);
1069
+ @ %z(href("%R/artifact/%s",zFUuid))%h(zFile)</a><br>
1070
+ }
1071
+ db_reset(&q2);
1072
+ @ </td>
1073
+ @ <td>
1074
+ @ %z(href("%R/info/%s",zUuid))[%S(zUuid)]</a>
1075
+ @ %W(zComment) (user:
1076
+ @ %z(href("%R/timeline?u=%t&c=%t&nd&n=200",zUser,zUuid))%h(zUser)</a>,
1077
+ @ branch:
1078
+ @ %z(href("%R/timeline?r=%t&c=%t&nd&n=200",zBranch,zUuid))%h(zBranch)</a>)
1079
+ @ </td></tr>
1080
+ @
1081
+ fossil_free(zAge);
1082
+ }
1083
+ @ </table></div>
1084
+ db_finalize(&q1);
1085
+ db_finalize(&q2);
8841086
style_footer();
8851087
}
8861088
8871089
ADDED src/bundle.c
--- src/browse.c
+++ src/browse.c
@@ -304,89 +304,206 @@
304
305 /*
306 ** A single line of the file hierarchy
307 */
308 struct FileTreeNode {
309 FileTreeNode *pNext; /* Next line in sequence */
310 FileTreeNode *pPrev; /* Previous line */
311 FileTreeNode *pParent; /* Directory containing this line */
 
 
312 char *zName; /* Name of this entry. The "tail" */
313 char *zFullName; /* Full pathname of this entry */
314 char *zUuid; /* SHA1 hash of this file. May be NULL. */
 
315 unsigned nFullName; /* Length of zFullName */
316 unsigned iLevel; /* Levels of parent directories */
317 u8 isDir; /* True if there are children */
318 u8 isLast; /* True if this is the last child of its parent */
319 };
320
321 /*
322 ** A complete file hierarchy
323 */
324 struct FileTree {
325 FileTreeNode *pFirst; /* First line of the list */
326 FileTreeNode *pLast; /* Last line of the list */
 
327 };
328
329 /*
330 ** Add one or more new FileTreeNodes to the FileTree object so that the
331 ** leaf object zPathname is at the end of the node list
 
 
 
 
 
 
 
 
332 */
333 static void tree_add_node(
334 FileTree *pTree, /* Tree into which nodes are added */
335 const char *zPath, /* The full pathname of file to add */
336 const char *zUuid /* UUID of the file. Might be NULL. */
 
337 ){
338 int i;
339 FileTreeNode *pParent;
340 FileTreeNode *pChild;
341
342 pChild = pTree->pLast;
343 pParent = pChild ? pChild->pParent : 0;
 
 
344 while( pParent!=0 &&
345 ( strncmp(pParent->zFullName, zPath, pParent->nFullName)!=0
346 || zPath[pParent->nFullName]!='/' )
347 ){
348 pChild = pParent;
349 pParent = pChild->pParent;
350 }
351 i = pParent ? pParent->nFullName+1 : 0;
352 if( pChild ) pChild->isLast = 0;
353 while( zPath[i] ){
354 FileTreeNode *pNew;
355 int iStart = i;
356 int nByte;
357 while( zPath[i] && zPath[i]!='/' ){ i++; }
358 nByte = sizeof(*pNew) + i + 1;
359 if( zUuid!=0 && zPath[i]==0 ) nByte += UUID_SIZE+1;
360 pNew = fossil_malloc( nByte );
 
361 pNew->zFullName = (char*)&pNew[1];
362 memcpy(pNew->zFullName, zPath, i);
363 pNew->zFullName[i] = 0;
364 pNew->nFullName = i;
365 if( zUuid!=0 && zPath[i]==0 ){
366 pNew->zUuid = pNew->zFullName + i + 1;
367 memcpy(pNew->zUuid, zUuid, UUID_SIZE+1);
368 }else{
369 pNew->zUuid = 0;
370 }
371 pNew->zName = pNew->zFullName + iStart;
372 if( pTree->pLast ){
373 pTree->pLast->pNext = pNew;
374 }else{
375 pTree->pFirst = pNew;
376 }
377 pNew->pPrev = pTree->pLast;
378 pNew->pNext = 0;
379 pNew->pParent = pParent;
380 pTree->pLast = pNew;
381 pNew->iLevel = pParent ? pParent->iLevel+1 : 0;
382 pNew->isDir = zPath[i]=='/';
383 pNew->isLast = 1;
 
 
 
 
 
 
 
 
 
384 while( zPath[i]=='/' ){ i++; }
385 pParent = pNew;
386 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387 }
 
388
389 /*
390 ** WEBPAGE: tree
391 **
392 ** Query parameters:
@@ -394,19 +511,23 @@
394 ** name=PATH Directory to display. Optional
395 ** ci=LABEL Show only files in this check-in. Optional.
396 ** re=REGEXP Show only files matching REGEXP. Optional.
397 ** expand Begin with the tree fully expanded.
398 ** nofiles Show directories (folders) only. Omit files.
 
399 */
400 void page_tree(void){
401 char *zD = fossil_strdup(P("name"));
402 int nD = zD ? strlen(zD)+1 : 0;
403 const char *zCI = P("ci");
404 int rid = 0;
405 char *zUuid = 0;
406 Blob dirname;
407 Manifest *pM = 0;
 
 
 
408 int nFile = 0; /* Number of files (or folders with "nofiles") */
409 int linkTrunk = 1; /* include link to "trunk" */
410 int linkTip = 1; /* include link to "tip" */
411 const char *zRE; /* the value for the re=REGEXP query parameter */
412 const char *zObjType; /* "files" by default or "folders" for "nofiles" */
@@ -464,14 +585,21 @@
464 int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
465 linkTrunk = trunkRid && rid != trunkRid;
466 linkTip = rid != symbolic_name_to_rid("tip", "ci");
467 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
468 url_add_parameter(&sURI, "ci", zCI);
 
 
 
469 }else{
470 zCI = 0;
471 }
472 }
 
 
 
 
473
474 /* Compute the title of the page */
475 blob_zero(&dirname);
476 if( zD ){
477 url_add_parameter(&sURI, "name", zD);
@@ -483,10 +611,18 @@
483 }else{
484 if( zRE ){
485 blob_appendf(&dirname, "matching \"%s\"", zRE);
486 }
487 }
 
 
 
 
 
 
 
 
488 if( zCI ){
489 style_submenu_element("All", "All", "%s",
490 url_render(&sURI, "ci", 0, 0, 0));
491 if( nD==0 && !showDirOnly ){
492 style_submenu_element("File Ages", "File Ages", "%R/fileage?name=%s",
@@ -499,87 +635,82 @@
499 }
500 if( linkTip ){
501 style_submenu_element("Tip", "Tip", "%s",
502 url_render(&sURI, "ci", "tip", 0, 0));
503 }
504 if( !showDirOnly ){
505 style_submenu_element("Flat-View", "Flat-View", "%s",
506 url_render(&sURI, "type", "flat", 0, 0));
507 }
508
509 /* Compute the file hierarchy.
510 */
511 if( zCI ){
512 Stmt ins, q;
513 ManifestFile *pFile;
514
515 db_multi_exec(
516 "CREATE TEMP TABLE filelist("
517 " x TEXT PRIMARY KEY COLLATE nocase,"
518 " uuid TEXT"
519 ") WITHOUT ROWID;"
520 );
521 db_prepare(&ins, "INSERT OR IGNORE INTO filelist VALUES(:f,:u)");
522 manifest_file_rewind(pM);
523 while( (pFile = manifest_file_next(pM,0))!=0 ){
524 if( nD>0
525 && (fossil_strncmp(pFile->zName, zD, nD-1)!=0
526 || pFile->zName[nD-1]!='/')
527 ){
528 continue;
529 }
530 if( pRE && re_match(pRE, (const u8*)pFile->zName, -1)==0 ) continue;
531 db_bind_text(&ins, ":f", pFile->zName);
532 db_bind_text(&ins, ":u", pFile->zUuid);
533 db_step(&ins);
534 db_reset(&ins);
535 }
536 db_finalize(&ins);
537 db_prepare(&q, "SELECT x, uuid FROM filelist ORDER BY x");
538 while( db_step(&q)==SQLITE_ROW ){
539 tree_add_node(&sTree, db_column_text(&q,0), db_column_text(&q,1));
 
 
 
 
540 nFile++;
541 }
542 db_finalize(&q);
543 }else{
544 Stmt q;
545 db_prepare(&q, "SELECT name FROM filename ORDER BY name COLLATE nocase");
 
 
 
 
 
 
546 while( db_step(&q)==SQLITE_ROW ){
547 const char *z = db_column_text(&q, 0);
548 if( nD>0 && (fossil_strncmp(z, zD, nD-1)!=0 || z[nD-1]!='/') ){
 
 
549 continue;
550 }
551 if( pRE && re_match(pRE, (const u8*)z, -1)==0 ) continue;
552 tree_add_node(&sTree, z, 0);
553 nFile++;
554 }
555 db_finalize(&q);
556 }
557
558 if( showDirOnly ){
559 for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
560 if( p->isDir && p->nFullName>nD ) nFile++;
561 }
562 zObjType = "folders";
563 style_submenu_element("Files","Files","%s",
564 url_render(&sURI,"nofiles",0,0,0));
565 }else{
566 zObjType = "files";
567 style_submenu_element("Folders","Folders","%s",
568 url_render(&sURI,"nofiles","1",0,0));
569 }
570
571 if( zCI ){
572 @ <h2>%d(nFile) %s(zObjType) of check-in
573 if( sqlite3_strnicmp(zCI, zUuid, (int)strlen(zCI))!=0 ){
574 @ "%h(zCI)"
575 }
576 @ [%z(href("vinfo?name=%s",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))</h2>
577 }else{
578 int n = db_int(0, "SELECT count(*) FROM plink");
579 @ <h2>%d(nFile) %s(zObjType) from all %d(n) check-ins
580 @ %s(blob_str(&dirname))</h2>
 
 
 
 
581 }
582
583
584 /* Generate tree of lists.
585 **
@@ -596,18 +727,33 @@
596 if( nD ){
597 @ <li class="dir last">
598 }else{
599 @ <li class="dir subdir last">
600 }
 
601 @ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a>
 
 
 
 
602 @ <ul>
 
 
 
 
 
603 for(p=sTree.pFirst, nDir=0; p; p=p->pNext){
604 const char *zLastClass = p->isLast ? " last" : "";
605 if( p->isDir ){
606 const char *zSubdirClass = p->nFullName==nD-1 ? " subdir" : "";
607 @ <li class="dir%s(zSubdirClass)%s(zLastClass)">
608 @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
 
 
 
 
 
609 if( startExpanded || p->nFullName<=nD ){
610 @ <ul id="dir%d(nDir)">
611 }else{
612 @ <ul id="dir%d(nDir)" class="collapsed">
613 }
@@ -614,17 +760,23 @@
614 nDir++;
615 }else if( !showDirOnly ){
616 const char *zFileClass = fileext_class(p->zName);
617 char *zLink;
618 if( zCI ){
619 zLink = href("%R/artifact/%s",p->zUuid);
620 }else{
621 zLink = href("%R/finfo?name=%T",p->zFullName);
622 }
623 @ <li class="%z(zFileClass)%s(zLastClass)">%z(zLink)%h(p->zName)</a>
 
 
 
 
 
 
624 }
625 if( p->isLast ){
626 int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
627 while( nClose-- > 0 ){
628 @ </ul>
629 }
630 }
@@ -687,16 +839,16 @@
687 @ checkState();
688 @ outer_ul.onclick = function(e){
689 @ e = e || window.event;
690 @ var a = e.target || e.srcElement;
691 @ if( a.nodeName!='A' ) return true;
692 @ if( a.parentNode==subdir ){
693 @ toggleAll(outer_ul);
694 @ return false;
695 @ }
696 @ if( !belowSubdir(a) ) return true;
697 @ var ul = a.nextSibling;
698 @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
699 @ if( !ul ) return true; /* This is a file link, not a directory */
700 @ toggleDir(ul);
701 @ return false;
702 @ }
@@ -724,87 +876,115 @@
724 }else{
725 zClass = mprintf("file");
726 }
727 return zClass;
728 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
730 /*
731 ** Look at all file containing in the version "vid". Construct a
732 ** temporary table named "fileage" that contains the file-id for each
733 ** files, the pathname, the check-in where the file was added, and the
734 ** mtime on that checkin. If zGlob and *zGlob then only files matching
735 ** the given glob are computed.
736 */
737 int compute_fileage(int vid, const char* zGlob){
738 Manifest *pManifest;
739 ManifestFile *pFile;
740 int nFile = 0;
741 double vmtime;
742 Stmt ins;
743 Stmt q1, q2, q3;
744 Stmt upd;
745 if(zGlob && !*zGlob) zGlob = NULL;
746 db_multi_exec(
747 /*"DROP TABLE IF EXISTS temp.fileage;"*/
748 "CREATE TEMP TABLE fileage("
749 " fid INTEGER,"
750 " mid INTEGER,"
751 " mtime DATETIME,"
752 " pathname TEXT"
753 ");"
754 "CREATE INDEX fileage_fid ON fileage(fid);"
755 );
756 pManifest = manifest_get(vid, CFTYPE_MANIFEST, 0);
757 if( pManifest==0 ) return 1;
758 manifest_file_rewind(pManifest);
759 db_prepare(&ins,
760 "INSERT INTO temp.fileage(fid, pathname)"
761 " SELECT rid, :path FROM blob WHERE uuid=:uuid"
762 );
763 while( (pFile = manifest_file_next(pManifest, 0))!=0 ){
764 if( zGlob && sqlite3_strglob(zGlob, pFile->zName)!=0 ) continue;
765 db_bind_text(&ins, ":uuid", pFile->zUuid);
766 db_bind_text(&ins, ":path", pFile->zName);
767 db_step(&ins);
768 db_reset(&ins);
769 nFile++;
770 }
771 db_finalize(&ins);
772 manifest_destroy(pManifest);
773 db_prepare(&q1,"SELECT fid FROM mlink WHERE mid=:mid");
774 db_prepare(&upd, "UPDATE fileage SET mid=:mid, mtime=:vmtime"
775 " WHERE fid=:fid AND mid IS NULL");
776 db_prepare(&q2,"SELECT pid FROM plink WHERE cid=:vid AND isprim");
777 db_prepare(&q3,"SELECT mtime FROM event WHERE objid=:vid");
778 while( nFile>0 && vid>0 ){
779 db_bind_int(&q3, ":vid", vid);
780 if( db_step(&q3)==SQLITE_ROW ){
781 vmtime = db_column_double(&q3, 0);
782 }else{
783 break;
784 }
785 db_reset(&q3);
786 db_bind_int(&q1, ":mid", vid);
787 db_bind_int(&upd, ":mid", vid);
788 db_bind_double(&upd, ":vmtime", vmtime);
789 while( db_step(&q1)==SQLITE_ROW ){
790 db_bind_int(&upd, ":fid", db_column_int(&q1, 0));
791 db_step(&upd);
792 nFile -= db_changes();
793 db_reset(&upd);
794 }
795 db_reset(&q1);
796 db_bind_int(&q2, ":vid", vid);
797 if( db_step(&q2)!=SQLITE_ROW ) break;
798 vid = db_column_int(&q2, 0);
799 db_reset(&q2);
800 }
801 db_finalize(&q1);
802 db_finalize(&upd);
803 db_finalize(&q2);
804 db_finalize(&q3);
805 return 0;
806 }
807
808 /*
809 ** WEBPAGE: fileage
810 **
@@ -814,72 +994,94 @@
814 ** (e.g. *.c or *.txt).
815 */
816 void fileage_page(void){
817 int rid;
818 const char *zName;
819 char *zBaseTime;
820 const char *zGlob;
821 Stmt q;
 
 
822 double baseTime;
823 int lastMid = -1;
824 login_check_credentials();
825 if( !g.perm.Read ){ login_needed(); return; }
826 zName = P("name");
827 if( zName==0 ) zName = "tip";
828 rid = symbolic_name_to_rid(zName, "ci");
829 if( rid==0 ){
830 fossil_fatal("not a valid check-in: %s", zName);
831 }
832 style_submenu_element("Tree-View", "Tree-View", "%R/tree?ci=%T", zName);
 
 
 
 
 
833 style_header("File Ages");
834 zGlob = P("glob");
835 compute_fileage(rid,zGlob);
836 baseTime = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
837 zBaseTime = db_text("","SELECT datetime(%.20g%s)", baseTime, timeline_utc());
838 @ <h2>File Ages For Check-in
839 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></h2>
840 @
841 @ <p>The times given are relative to
842 @ %z(href("%R/timeline?c=%T",zBaseTime))%s(zBaseTime)</a>, which is the
843 @ check-in time for
844 @ %z(href("%R/info?name=%T",zName))%h(zName)</a></p>
845 @
846 @ <table border=0 cellspacing=0 cellpadding=0>
847 db_prepare(&q,
848 "SELECT mtime, (SELECT uuid FROM blob WHERE rid=fid), mid, pathname"
849 " FROM fileage"
850 " ORDER BY mtime DESC, mid, pathname"
851 );
852 while( db_step(&q)==SQLITE_ROW ){
853 double age = baseTime - db_column_double(&q, 0);
854 int mid = db_column_int(&q, 2);
855 const char *zFUuid = db_column_text(&q, 1);
856 char zAge[200];
857 if( lastMid!=mid ){
858 @ <tr><td colspan=3><hr></tr>
859 lastMid = mid;
860 if( age*86400.0<120 ){
861 sqlite3_snprintf(sizeof(zAge), zAge, "%d seconds", (int)(age*86400.0));
862 }else if( age*1440.0<90 ){
863 sqlite3_snprintf(sizeof(zAge), zAge, "%.1f minutes", age*1440.0);
864 }else if( age*24.0<36 ){
865 sqlite3_snprintf(sizeof(zAge), zAge, "%.1f hours", age*24.0);
866 }else if( age<365.0 ){
867 sqlite3_snprintf(sizeof(zAge), zAge, "%.1f days", age);
868 }else{
869 sqlite3_snprintf(sizeof(zAge), zAge, "%.2f years", age/365.0);
870 }
871 }else{
872 zAge[0] = 0;
873 }
874 @ <tr>
875 @ <td>%s(zAge)
876 @ <td width="25">
877 @ <td>%z(href("%R/artifact/%s?ln", zFUuid))%h(db_column_text(&q, 3))</a>
878 @ </tr>
879 @
880 }
881 @ <tr><td colspan=3><hr></tr>
882 @ </table>
883 db_finalize(&q);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884 style_footer();
885 }
886
887 DDED src/bundle.c
--- src/browse.c
+++ src/browse.c
@@ -304,89 +304,206 @@
304
305 /*
306 ** A single line of the file hierarchy
307 */
308 struct FileTreeNode {
309 FileTreeNode *pNext; /* Next entry in an ordered list of them all */
310 FileTreeNode *pParent; /* Directory containing this entry */
311 FileTreeNode *pSibling; /* Next element in the same subdirectory */
312 FileTreeNode *pChild; /* List of child nodes */
313 FileTreeNode *pLastChild; /* Last child on the pChild list */
314 char *zName; /* Name of this entry. The "tail" */
315 char *zFullName; /* Full pathname of this entry */
316 char *zUuid; /* SHA1 hash of this file. May be NULL. */
317 double mtime; /* Modification time for this entry */
318 unsigned nFullName; /* Length of zFullName */
319 unsigned iLevel; /* Levels of parent directories */
 
 
320 };
321
322 /*
323 ** A complete file hierarchy
324 */
325 struct FileTree {
326 FileTreeNode *pFirst; /* First line of the list */
327 FileTreeNode *pLast; /* Last line of the list */
328 FileTreeNode *pLastTop; /* Last top-level node */
329 };
330
331 /*
332 ** Add one or more new FileTreeNodes to the FileTree object so that the
333 ** leaf object zPathname is at the end of the node list.
334 **
335 ** The caller invokes this routine once for each leaf node (each file
336 ** as opposed to each directory). This routine fills in any missing
337 ** intermediate nodes automatically.
338 **
339 ** When constructing a list of FileTreeNodes, all entries that have
340 ** a common directory prefix must be added consecutively in order for
341 ** the tree to be constructed properly.
342 */
343 static void tree_add_node(
344 FileTree *pTree, /* Tree into which nodes are added */
345 const char *zPath, /* The full pathname of file to add */
346 const char *zUuid, /* UUID of the file. Might be NULL. */
347 double mtime /* Modification time for this entry */
348 ){
349 int i;
350 FileTreeNode *pParent; /* Parent (directory) of the next node to insert */
 
351
352 /* Make pParent point to the most recent ancestor of zPath, or
353 ** NULL if there are no prior entires that are a container for zPath.
354 */
355 pParent = pTree->pLast;
356 while( pParent!=0 &&
357 ( strncmp(pParent->zFullName, zPath, pParent->nFullName)!=0
358 || zPath[pParent->nFullName]!='/' )
359 ){
360 pParent = pParent->pParent;
 
361 }
362 i = pParent ? pParent->nFullName+1 : 0;
 
363 while( zPath[i] ){
364 FileTreeNode *pNew;
365 int iStart = i;
366 int nByte;
367 while( zPath[i] && zPath[i]!='/' ){ i++; }
368 nByte = sizeof(*pNew) + i + 1;
369 if( zUuid!=0 && zPath[i]==0 ) nByte += UUID_SIZE+1;
370 pNew = fossil_malloc( nByte );
371 memset(pNew, 0, sizeof(*pNew));
372 pNew->zFullName = (char*)&pNew[1];
373 memcpy(pNew->zFullName, zPath, i);
374 pNew->zFullName[i] = 0;
375 pNew->nFullName = i;
376 if( zUuid!=0 && zPath[i]==0 ){
377 pNew->zUuid = pNew->zFullName + i + 1;
378 memcpy(pNew->zUuid, zUuid, UUID_SIZE+1);
 
 
379 }
380 pNew->zName = pNew->zFullName + iStart;
381 if( pTree->pLast ){
382 pTree->pLast->pNext = pNew;
383 }else{
384 pTree->pFirst = pNew;
385 }
386 pTree->pLast = pNew;
 
387 pNew->pParent = pParent;
388 if( pParent ){
389 if( pParent->pChild ){
390 pParent->pLastChild->pSibling = pNew;
391 }else{
392 pParent->pChild = pNew;
393 }
394 pNew->iLevel = pParent->iLevel + 1;
395 pParent->pLastChild = pNew;
396 }else{
397 if( pTree->pLastTop ) pTree->pLastTop->pSibling = pNew;
398 pTree->pLastTop = pNew;
399 }
400 pNew->mtime = mtime;
401 while( zPath[i]=='/' ){ i++; }
402 pParent = pNew;
403 }
404 while( pParent && pParent->pParent ){
405 if( pParent->pParent->mtime < pParent->mtime ){
406 pParent->pParent->mtime = pParent->mtime;
407 }
408 pParent = pParent->pParent;
409 }
410 }
411
412 /* Comparison function for two FileTreeNode objects. Sort first by
413 ** mtime (larger numbers first) and then by zName (smaller names first).
414 **
415 ** Return negative if pLeft<pRight.
416 ** Return positive if pLeft>pRight.
417 ** Return zero if pLeft==pRight.
418 */
419 static int compareNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
420 if( pLeft->mtime>pRight->mtime ) return -1;
421 if( pLeft->mtime<pRight->mtime ) return +1;
422 return fossil_stricmp(pLeft->zName, pRight->zName);
423 }
424
425 /* Merge together two sorted lists of FileTreeNode objects */
426 static FileTreeNode *mergeNodes(FileTreeNode *pLeft, FileTreeNode *pRight){
427 FileTreeNode *pEnd;
428 FileTreeNode base;
429 pEnd = &base;
430 while( pLeft && pRight ){
431 if( compareNodes(pLeft,pRight)<=0 ){
432 pEnd = pEnd->pSibling = pLeft;
433 pLeft = pLeft->pSibling;
434 }else{
435 pEnd = pEnd->pSibling = pRight;
436 pRight = pRight->pSibling;
437 }
438 }
439 if( pLeft ){
440 pEnd->pSibling = pLeft;
441 }else{
442 pEnd->pSibling = pRight;
443 }
444 return base.pSibling;
445 }
446
447 /* Sort a list of FileTreeNode objects in mtime order. */
448 static FileTreeNode *sortNodesByMtime(FileTreeNode *p){
449 FileTreeNode *a[30];
450 FileTreeNode *pX;
451 int i;
452
453 memset(a, 0, sizeof(a));
454 while( p ){
455 pX = p;
456 p = pX->pSibling;
457 pX->pSibling = 0;
458 for(i=0; i<count(a)-1 && a[i]!=0; i++){
459 pX = mergeNodes(a[i], pX);
460 a[i] = 0;
461 }
462 a[i] = mergeNodes(a[i], pX);
463 }
464 pX = 0;
465 for(i=0; i<count(a); i++){
466 pX = mergeNodes(a[i], pX);
467 }
468 return pX;
469 }
470
471 /* Sort an entire FileTreeNode tree by mtime
472 **
473 ** This routine invalidates the following fields:
474 **
475 ** FileTreeNode.pLastChild
476 ** FileTreeNode.pNext
477 **
478 ** Use relinkTree to reconnect the pNext pointers.
479 */
480 static FileTreeNode *sortTreeByMtime(FileTreeNode *p){
481 FileTreeNode *pX;
482 for(pX=p; pX; pX=pX->pSibling){
483 if( pX->pChild ) pX->pChild = sortTreeByMtime(pX->pChild);
484 }
485 return sortNodesByMtime(p);
486 }
487
488 /* Reconstruct the FileTree by reconnecting the FileTreeNode.pNext
489 ** fields in sequential order.
490 */
491 static void relinkTree(FileTree *pTree, FileTreeNode *pRoot){
492 while( pRoot ){
493 if( pTree->pLast ){
494 pTree->pLast->pNext = pRoot;
495 }else{
496 pTree->pFirst = pRoot;
497 }
498 pTree->pLast = pRoot;
499 if( pRoot->pChild ) relinkTree(pTree, pRoot->pChild);
500 pRoot = pRoot->pSibling;
501 }
502 if( pTree->pLast ) pTree->pLast->pNext = 0;
503 }
504
505
506 /*
507 ** WEBPAGE: tree
508 **
509 ** Query parameters:
@@ -394,19 +511,23 @@
511 ** name=PATH Directory to display. Optional
512 ** ci=LABEL Show only files in this check-in. Optional.
513 ** re=REGEXP Show only files matching REGEXP. Optional.
514 ** expand Begin with the tree fully expanded.
515 ** nofiles Show directories (folders) only. Omit files.
516 ** mtime Order directory elements by decreasing mtime
517 */
518 void page_tree(void){
519 char *zD = fossil_strdup(P("name"));
520 int nD = zD ? strlen(zD)+1 : 0;
521 const char *zCI = P("ci");
522 int rid = 0;
523 char *zUuid = 0;
524 Blob dirname;
525 Manifest *pM = 0;
526 double rNow = 0;
527 char *zNow = 0;
528 int useMtime = atoi(PD("mtime","0"));
529 int nFile = 0; /* Number of files (or folders with "nofiles") */
530 int linkTrunk = 1; /* include link to "trunk" */
531 int linkTip = 1; /* include link to "tip" */
532 const char *zRE; /* the value for the re=REGEXP query parameter */
533 const char *zObjType; /* "files" by default or "folders" for "nofiles" */
@@ -464,14 +585,21 @@
585 int trunkRid = symbolic_name_to_rid("tag:trunk", "ci");
586 linkTrunk = trunkRid && rid != trunkRid;
587 linkTip = rid != symbolic_name_to_rid("tip", "ci");
588 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
589 url_add_parameter(&sURI, "ci", zCI);
590 rNow = db_double(0.0, "SELECT mtime FROM event WHERE objid=%d", rid);
591 zNow = db_text("", "SELECT datetime(mtime,'localtime')"
592 " FROM event WHERE objid=%d", rid);
593 }else{
594 zCI = 0;
595 }
596 }
597 if( zCI==0 ){
598 rNow = db_double(0.0, "SELECT max(mtime) FROM event");
599 zNow = db_text("", "SELECT datetime(max(mtime),'localtime') FROM event");
600 }
601
602 /* Compute the title of the page */
603 blob_zero(&dirname);
604 if( zD ){
605 url_add_parameter(&sURI, "name", zD);
@@ -483,10 +611,18 @@
611 }else{
612 if( zRE ){
613 blob_appendf(&dirname, "matching \"%s\"", zRE);
614 }
615 }
616 if( useMtime ){
617 style_submenu_element("Sort By Filename","Sort By Filename", "%s",
618 url_render(&sURI, 0, 0, 0, 0));
619 url_add_parameter(&sURI, "mtime", "1");
620 }else{
621 style_submenu_element("Sort By Time","Sort By Time", "%s",
622 url_render(&sURI, "mtime", "1", 0, 0));
623 }
624 if( zCI ){
625 style_submenu_element("All", "All", "%s",
626 url_render(&sURI, "ci", 0, 0, 0));
627 if( nD==0 && !showDirOnly ){
628 style_submenu_element("File Ages", "File Ages", "%R/fileage?name=%s",
@@ -499,87 +635,82 @@
635 }
636 if( linkTip ){
637 style_submenu_element("Tip", "Tip", "%s",
638 url_render(&sURI, "ci", "tip", 0, 0));
639 }
 
 
 
 
640
641 /* Compute the file hierarchy.
642 */
643 if( zCI ){
644 Stmt q;
645 compute_fileage(rid, 0);
646 db_prepare(&q,
647 "SELECT filename.name, blob.uuid, fileage.mtime\n"
648 " FROM fileage, filename, blob\n"
649 " WHERE filename.fnid=fileage.fnid\n"
650 " AND blob.rid=fileage.fid\n"
651 " ORDER BY filename.name COLLATE nocase;"
652 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
653 while( db_step(&q)==SQLITE_ROW ){
654 const char *zFile = db_column_text(&q,0);
655 const char *zUuid = db_column_text(&q,1);
656 double mtime = db_column_double(&q,2);
657 if( pRE && re_match(pRE, (const unsigned char*)zFile, -1)==0 ) continue;
658 tree_add_node(&sTree, zFile, zUuid, mtime);
659 nFile++;
660 }
661 db_finalize(&q);
662 }else{
663 Stmt q;
664 db_prepare(&q,
665 "SELECT filename.name, blob.uuid, max(event.mtime)\n"
666 " FROM filename, mlink, blob, event\n"
667 " WHERE mlink.fnid=filename.fnid\n"
668 " AND event.objid=mlink.mid\n"
669 " AND blob.rid=mlink.fid\n"
670 " GROUP BY 1 ORDER BY 1 COLLATE nocase");
671 while( db_step(&q)==SQLITE_ROW ){
672 const char *zName = db_column_text(&q, 0);
673 const char *zUuid = db_column_text(&q,1);
674 double mtime = db_column_double(&q,2);
675 if( nD>0 && (fossil_strncmp(zName, zD, nD-1)!=0 || zName[nD-1]!='/') ){
676 continue;
677 }
678 if( pRE && re_match(pRE, (const u8*)zName, -1)==0 ) continue;
679 tree_add_node(&sTree, zName, zUuid, mtime);
680 nFile++;
681 }
682 db_finalize(&q);
683 }
684
685 if( showDirOnly ){
686 for(nFile=0, p=sTree.pFirst; p; p=p->pNext){
687 if( p->pChild!=0 && p->nFullName>nD ) nFile++;
688 }
689 zObjType = "Folders";
690 style_submenu_element("Files","Files","%s",
691 url_render(&sURI,"nofiles",0,0,0));
692 }else{
693 zObjType = "Files";
694 style_submenu_element("Folders","Folders","%s",
695 url_render(&sURI,"nofiles","1",0,0));
696 }
697
698 if( zCI ){
699 @ <h2>%s(zObjType) from
700 if( sqlite3_strnicmp(zCI, zUuid, (int)strlen(zCI))!=0 ){
701 @ "%h(zCI)"
702 }
703 @ [%z(href("vinfo?name=%s",zUuid))%S(zUuid)</a>] %s(blob_str(&dirname))
704 }else{
705 int n = db_int(0, "SELECT count(*) FROM plink");
706 @ <h2>%s(zObjType) from all %d(n) check-ins %s(blob_str(&dirname))
707 }
708 if( useMtime ){
709 @ sorted by modification time</h2>
710 }else{
711 @ sorted by filename</h2>
712 }
713
714
715 /* Generate tree of lists.
716 **
@@ -596,18 +727,33 @@
727 if( nD ){
728 @ <li class="dir last">
729 }else{
730 @ <li class="dir subdir last">
731 }
732 @ <div class="filetreeline">
733 @ %z(href("%s",url_render(&sURI,"name",0,0,0)))%h(zProjectName)</a>
734 if( zNow ){
735 @ <div class="filetreeage">%s(zNow)</div>
736 }
737 @ </div>
738 @ <ul>
739 if( useMtime ){
740 p = sortTreeByMtime(sTree.pFirst);
741 memset(&sTree, 0, sizeof(sTree));
742 relinkTree(&sTree, p);
743 }
744 for(p=sTree.pFirst, nDir=0; p; p=p->pNext){
745 const char *zLastClass = p->pSibling==0 ? " last" : "";
746 if( p->pChild ){
747 const char *zSubdirClass = p->nFullName==nD-1 ? " subdir" : "";
748 @ <li class="dir%s(zSubdirClass)%s(zLastClass)"><div class="filetreeline">
749 @ %z(href("%s",url_render(&sURI,"name",p->zFullName,0,0)))%h(p->zName)</a>
750 if( p->mtime>0.0 ){
751 char *zAge = human_readable_age(rNow - p->mtime);
752 @ <div class="filetreeage">%s(zAge)</div>
753 }
754 @ </div>
755 if( startExpanded || p->nFullName<=nD ){
756 @ <ul id="dir%d(nDir)">
757 }else{
758 @ <ul id="dir%d(nDir)" class="collapsed">
759 }
@@ -614,17 +760,23 @@
760 nDir++;
761 }else if( !showDirOnly ){
762 const char *zFileClass = fileext_class(p->zName);
763 char *zLink;
764 if( zCI ){
765 zLink = href("%R/artifact/%.16s",p->zUuid);
766 }else{
767 zLink = href("%R/finfo?name=%T",p->zFullName);
768 }
769 @ <li class="%z(zFileClass)%s(zLastClass)"><div class="filetreeline">
770 @ %z(zLink)%h(p->zName)</a>
771 if( p->mtime>0 ){
772 char *zAge = human_readable_age(rNow - p->mtime);
773 @ <div class="filetreeage">%s(zAge)</div>
774 }
775 @ </div>
776 }
777 if( p->pSibling==0 ){
778 int nClose = p->iLevel - (p->pNext ? p->pNext->iLevel : 0);
779 while( nClose-- > 0 ){
780 @ </ul>
781 }
782 }
@@ -687,16 +839,16 @@
839 @ checkState();
840 @ outer_ul.onclick = function(e){
841 @ e = e || window.event;
842 @ var a = e.target || e.srcElement;
843 @ if( a.nodeName!='A' ) return true;
844 @ if( a.parentNode.parentNode==subdir ){
845 @ toggleAll(outer_ul);
846 @ return false;
847 @ }
848 @ if( !belowSubdir(a) ) return true;
849 @ var ul = a.parentNode.nextSibling;
850 @ while( ul && ul.nodeName!='UL' ) ul = ul.nextSibling;
851 @ if( !ul ) return true; /* This is a file link, not a directory */
852 @ toggleDir(ul);
853 @ return false;
854 @ }
@@ -724,87 +876,115 @@
876 }else{
877 zClass = mprintf("file");
878 }
879 return zClass;
880 }
881
882 /*
883 ** SQL used to compute the age of all files in checkin :ckin whose
884 ** names match :glob
885 */
886 static const char zComputeFileAgeSetup[] =
887 @ CREATE TABLE IF NOT EXISTS temp.fileage(
888 @ fnid INTEGER PRIMARY KEY,
889 @ fid INTEGER,
890 @ mid INTEGER,
891 @ mtime DATETIME,
892 @ pathname TEXT
893 @ );
894 @ CREATE VIRTUAL TABLE IF NOT EXISTS temp.foci USING files_of_checkin;
895 ;
896
897 static const char zComputeFileAgeRun[] =
898 @ WITH RECURSIVE
899 @ ckin(x) AS (VALUES(:ckin) UNION ALL
900 @ SELECT pid FROM ckin, plink WHERE cid=x AND isprim)
901 @ INSERT OR IGNORE INTO fileage(fnid, fid, mid, mtime, pathname)
902 @ SELECT mlink.fnid, mlink.fid, x, event.mtime, filename.name
903 @ FROM ckin, mlink, event, filename
904 @ WHERE mlink.mid=ckin.x
905 @ AND mlink.fnid IN (SELECT fnid FROM foci, filename
906 @ WHERE foci.checkinID=:ckin
907 @ AND filename.name=foci.filename
908 @ AND filename.name GLOB :glob)
909 @ AND filename.fnid=mlink.fnid
910 @ AND event.objid=mlink.mid;
911 ;
912
913
914 /*
915 ** Look at all file containing in the version "vid". Construct a
916 ** temporary table named "fileage" that contains the file-id for each
917 ** files, the pathname, the check-in where the file was added, and the
918 ** mtime on that checkin. If zGlob and *zGlob then only files matching
919 ** the given glob are computed.
920 */
921 int compute_fileage(int vid, const char* zGlob){
922 Stmt q;
923 db_multi_exec(zComputeFileAgeSetup /*works-like:"constant"*/);
924 db_prepare(&q, zComputeFileAgeRun /*works-like:"constant"*/);
925 db_bind_int(&q, ":ckin", vid);
926 db_bind_text(&q, ":glob", zGlob && zGlob[0] ? zGlob : "*");
927 db_exec(&q);
928 db_finalize(&q);
929 return 0;
930 }
931
932 /*
933 ** Render the number of days in rAge as a more human-readable time span.
934 ** Different units (seconds, minutes, hours, days, months, years) are
935 ** selected depending on the magnitude of rAge.
936 **
937 ** The string returned is obtained from fossil_malloc() and should be
938 ** freed by the caller.
939 */
940 char *human_readable_age(double rAge){
941 if( rAge*86400.0<120 ){
942 if( rAge*86400.0<1.0 ){
943 return mprintf("current");
944 }else{
945 return mprintf("%d seconds", (int)(rAge*86400.0));
946 }
947 }else if( rAge*1440.0<90 ){
948 return mprintf("%.1f minutes", rAge*1440.0);
949 }else if( rAge*24.0<36 ){
950 return mprintf("%.1f hours", rAge*24.0);
951 }else if( rAge<365.0 ){
952 return mprintf("%.1f days", rAge);
953 }else{
954 return mprintf("%.2f years", rAge/365.0);
955 }
956 }
957
958 /*
959 ** COMMAND: test-fileage
960 **
961 ** Usage: %fossil test-fileage CHECKIN
962 */
963 void test_fileage_cmd(void){
964 int mid;
965 Stmt q;
966 const char *zGlob = find_option("glob",0,1);
967 db_find_and_open_repository(0,0);
968 verify_all_options();
969 if( g.argc!=3 ) usage("test-fileage CHECKIN");
970 mid = name_to_typed_rid(g.argv[2],"ci");
971 compute_fileage(mid, zGlob);
972 db_prepare(&q,
973 "SELECT fid, mid, julianday('now') - mtime, pathname"
974 " FROM fileage"
975 );
976 while( db_step(&q)==SQLITE_ROW ){
977 char *zAge = human_readable_age(db_column_double(&q,2));
978 fossil_print("%8d %8d %16s %s\n",
979 db_column_int(&q,0),
980 db_column_int(&q,1),
981 zAge,
982 db_column_text(&q,3));
983 fossil_free(zAge);
984 }
985 db_finalize(&q);
 
 
 
 
986 }
987
988 /*
989 ** WEBPAGE: fileage
990 **
@@ -814,72 +994,94 @@
994 ** (e.g. *.c or *.txt).
995 */
996 void fileage_page(void){
997 int rid;
998 const char *zName;
 
999 const char *zGlob;
1000 const char *zUuid;
1001 const char *zNow; /* Time of checkin */
1002 Stmt q1, q2;
1003 double baseTime;
 
1004 login_check_credentials();
1005 if( !g.perm.Read ){ login_needed(); return; }
1006 zName = P("name");
1007 if( zName==0 ) zName = "tip";
1008 rid = symbolic_name_to_rid(zName, "ci");
1009 if( rid==0 ){
1010 fossil_fatal("not a valid check-in: %s", zName);
1011 }
1012 zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid);
1013 baseTime = db_double(0.0,"SELECT mtime FROM event WHERE objid=%d", rid);
1014 zNow = db_text("", "SELECT datetime(mtime,'localtime') FROM event"
1015 " WHERE objid=%d", rid);
1016 style_submenu_element("Tree-View", "Tree-View", "%R/tree?ci=%T&mtime=1",
1017 zName);
1018 style_header("File Ages");
1019 zGlob = P("glob");
1020 compute_fileage(rid,zGlob);
1021 db_multi_exec("CREATE INDEX fileage_ix1 ON fileage(mid,pathname);");
1022
1023 @ <h2>Files in
1024 @ %z(href("%R/info?name=%T",zUuid))[%S(zUuid)]</a>
1025 if( zGlob && zGlob[0] ){
1026 @ that match "%h(zGlob)" and
1027 }
1028 @ ordered by check-in time</h2>
1029 @
1030 @ <p>Times are relative to the checkin time for
1031 @ %z(href("%R/ci/%s",zUuid))[%S(zUuid)]</a> which is
1032 @ %z(href("%R/timeline?c=%t",zNow))%s(zNow)</a>.</p>
1033 @
1034 @ <div class='fileage'><table>
1035 @ <tr><th>Time</th><th>Files</th><th>Checkin</th></tr>
1036 db_prepare(&q1,
1037 "SELECT event.mtime, event.objid, blob.uuid,\n"
1038 " coalesce(event.ecomment,event.comment),\n"
1039 " coalesce(event.euser,event.user),\n"
1040 " coalesce((SELECT value FROM tagxref\n"
1041 " WHERE tagtype>0 AND tagid=%d\n"
1042 " AND rid=event.objid),'trunk')\n"
1043 " FROM event, blob\n"
1044 " WHERE event.objid IN (SELECT mid FROM fileage)\n"
1045 " AND blob.rid=event.objid\n"
1046 " ORDER BY event.mtime DESC;",
1047 TAG_BRANCH
1048 );
1049 db_prepare(&q2,
1050 "SELECT blob.uuid, filename.name\n"
1051 " FROM fileage, blob, filename\n"
1052 " WHERE fileage.mid=:mid AND filename.fnid=fileage.fnid"
1053 " AND blob.rid=fileage.fid;"
1054 );
1055 while( db_step(&q1)==SQLITE_ROW ){
1056 double age = baseTime - db_column_double(&q1, 0);
1057 int mid = db_column_int(&q1, 1);
1058 const char *zUuid = db_column_text(&q1, 2);
1059 const char *zComment = db_column_text(&q1, 3);
1060 const char *zUser = db_column_text(&q1, 4);
1061 const char *zBranch = db_column_text(&q1, 5);
1062 char *zAge = human_readable_age(age);
1063 @ <tr><td>%s(zAge)</td>
1064 @ <td>
1065 db_bind_int(&q2, ":mid", mid);
1066 while( db_step(&q2)==SQLITE_ROW ){
1067 const char *zFUuid = db_column_text(&q2,0);
1068 const char *zFile = db_column_text(&q2,1);
1069 @ %z(href("%R/artifact/%s",zFUuid))%h(zFile)</a><br>
1070 }
1071 db_reset(&q2);
1072 @ </td>
1073 @ <td>
1074 @ %z(href("%R/info/%s",zUuid))[%S(zUuid)]</a>
1075 @ %W(zComment) (user:
1076 @ %z(href("%R/timeline?u=%t&c=%t&nd&n=200",zUser,zUuid))%h(zUser)</a>,
1077 @ branch:
1078 @ %z(href("%R/timeline?r=%t&c=%t&nd&n=200",zBranch,zUuid))%h(zBranch)</a>)
1079 @ </td></tr>
1080 @
1081 fossil_free(zAge);
1082 }
1083 @ </table></div>
1084 db_finalize(&q1);
1085 db_finalize(&q2);
1086 style_footer();
1087 }
1088
1089 DDED src/bundle.c
+303
--- a/src/bundle.c
+++ b/src/bundle.c
@@ -0,0 +1,303 @@
1
+/*
2
+** Copyright (==40** Copyright (c) 2014 D/*
3
+** Copyright (c) 2014 D. Richard Hipp
4
+**
5
+** This program is free software; you can redistribute it and/or
6
+** modify it under the terms of the Simplified BSD License (also
7
+** known as the "2-Clause License" or "FreeBSD License".)
8
+
9
+** This program is distributed in the hope that it will be useful,
10
+** but without any warranty; without even the implied warranty of
11
+** merchantability or fitness for a particular purpose.
12
+**
13
+** Author contact information:
14
+** [email protected]
15
+** http://www.hwaci.com/drh/
16
+**
17
+*******************************************************************************
18
+**
19
+** This file contains code used to implement and manage a "bundle" file.
20
+*/
21
+#include "config.h"
22
+#include "bundle.h"
23
+#include <assert.h>
24
+
25
+/*
26
+** SQL code used to initialize the schema of a bundle.
27
+**
28
+** The bblob.delta field can be an integer, a text string, or NULL.
29
+** If an integer, then the corresponding blobid is the delta basis.
30
+** If a text string, then that string is a SHA1 hash for the delta
31
+** basis, whister is ainory. If NULL, then
32
+** data contains content without delta compression.
33
+*/
34
+static const cha r zBundleInit[] =
35
+@ CREATE TABLE IF NOT EXISTS "%w".bconfig(
36
+@ bcname TEXT,
37
+@ bcvalue ANY
38
+@ );
39
+@ CREATE TABLE IF NOT EXISTS "%w".bblob(
40
+@ blobid INTEGER PRIMARY KEY, -- Blob ID
41
+@ uuid TEXT SHA1 NOT NULL, -- hash of expanded blob
42
+@ sz INT NOT NULL, -- Size of blob after expansion
43
+@ delta ANY, -- Delta compression basis, or NULL
44
+@ notes TEXT, -- Description of content
45
+@ data BLOB -- compressed content
46
+@ );
47
+;
48
+
49
+/*
50
+** Attach a bundle file to the current database connection using the
51
+** attachment name zBName.
52
+*/
53
+static void bundle_attach_file(
54
+ const char *zFile, /* Name of the file that contains the bundle */
55
+ const char *zBName, /* Attachment name */
56
+ int doInit /* Initialize a new bundle, if true */
57
+){
58
+ int rc;
59
+ char *zErrMsg = 0;
60
+ char *zSql;
61
+ if( )<0 ){blob.rid=tobundle.rid"
62
+ _size(zFile, ExtFILE)<0 ){
63
+ fossil_fatal("no such file: %s", zFile);
64
+ }
65
+ assert( g.db );
66
+ zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
67
+ sqlite3_free(zSql);
68
+ if( rc!=SQLITE_OK || zErrMsg ){
69
+ if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
70
+ fossil_fatal("not a valid bundle: %s", zFile);
71
+ }
72
+ if( doInit ){
73
+ db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
74
+ }else{
75
+ sqlite3_stmt *pStmt;
76
+ zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
77
+ " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
78
+** basis, whister is presumably in the main repository. If NULL, then
79
+** data contains content without delta compression.
80
+*/
81
+static const char zBundleInit[] =
82
+@ CREATE TABLE IF NOT EXISTS "%w".bconfig(
83
+@ bcname TEXT,
84
+@ bcvalue ANY
85
+@ );
86
+@ CREATE TABLE IF NOT EXISTS "%w".bblob(
87
+@ blobid INTEGER Pfatalhat string is a SHA1 hash for the delta
88
+** basis, whister is presumably in the main repository. If NULL, then
89
+** data contains content without delta compressio}
90
+}
91
+
92
+/*
93
+** artifacts from the bundlNULL
94
+@ notes TEXT, -- Description of content
95
+@ data BLOB -- compressed content
96
+@ );
97
+;
98
+
99
+/*
100
+** Attac ter is presumably iHipp
101
+**
102
+** This program is free software; you can redistribute it and/or
103
+** modify it under the terms of the Simplified BSD License (also
104
+** known as the "2-Clause License" or "FreeBSD License".)
105
+
106
+** This program is distributed in the hope that it will be useful,
107
+** but without any warranty; without even the implied warranty of
108
+** merchantability or fitness for a particular purpose.
109
+**
110
+** Author contact information:
111
+** [email protected]
112
+** http://www.hwaci.com/drh/
113
+**
114
+*******************************************************************************
115
+**
116
+** This file contains code used to implement and manage a "bundle" file.
117
+*/
118
+#include "config.h"
119
+#include "bundle.h"
120
+#include <assert.h>
121
+
122
+/*
123
+** SQL code used to initialize the schema of a bundle.
124
+**
125
+** The bblob.delta field can be an integer, a text string, or NULL.
126
+** If an integer, then the corresponding blobid is the delta basis.
127
+** If a text string, then that string is a SHA1 hash for the delta
128
+** basis, whister is ainory. If NULL, then
129
+** data contains content without delta compression.
130
+*/
131
+static const char zBundleInit[] =
132
+@ CREATE TABLE IF NOT EXISTS "%w/mpressed content
133
+@ );
134
+;
135
+
136
+/*
137
+** Attach a bundle file to the current database connection using the
138
+** attachment name zBName.
139
+*/
140
+static void bundle_attach_file(
141
+ const char *zFile, /* Name of the file that contains the bundle */
142
+ const char *zBName, /* Attachment name */
143
+ int doInit /* Initialize a new bundle, if true */
144
+){
145
+ int rc;
146
+ char *zErrMsg = 0;
147
+ char *zSql;
148
+ if( )<0 ){blob.rid=tobundle.rid"
149
+ _size(zFile, ExtFILE)<0 ){
150
+ fossil_fatal("no such file: %s", zFile);
151
+ }
152
+ assert( g.db );
153
+ zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
154
+ sqlite3_free(zSql);
155
+ if( rc!=SQLITE_OK || zErrMsg ){
156
+ if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
157
+ fossil_fatal("not a valid bundle: %s", zFile);
158
+ }
159
+ if( doInit ){
160
+ db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
161
+ }else{
162
+ sqlite3_stmt *pStmt;
163
+ zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
164
+ " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
165
+** basis, whister is presumably in the main repository. If NULL, then
166
+** data contains content without delta compression.
167
+*/
168
+statc const char zBundleInit[] =
169
+@ CREATE TABLE IF NOT EXISTS "%w".bconfig(
170
+@ bcname TEXT,
171
+@ bcvalue ANY
172
+@ );
173
+@ CREATE TABLE IF NOT EXISTS "% Pfatalhat string is a SHA1 hash for the delta
174
+** basis, whister is presumably in the main reposa contains content without delta compressio}
175
+}
176
+
177
+/*
178
+** artifacts from the bundlNULL
179
+@ notes TEXT, -- Description of ontent
180
+@ data BLOB content
181
+@ );
182
+;
183
+
184
+/*
185
+** Attach a bundle file to the current database connection using the
186
+** attachment name zBName.
187
+*/
188
+static void bundle_attach_file(
189
+ const char *zFile, /* Name of the file that contains the bundle */
190
+ const char *zBName, */
191
+){
192
+ int rc;
193
+ char *zErrMsg = 0;
194
+ char *zSql;
195
+ if( !doInit && file_size(zFile, ExtFILE)<0 ){
196
+ fossil_fatal("no such file: %s", zFile);
197
+ }
198
+ assert( g.db );
199
+ zSql = sqlite3_mprintf("ATTACH %Q AS %Q", zFile, zBName);
200
+ if( zSql==0 ) fossil_fatal("out of memory");
201
+ rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
202
+ sqlite3_free(zSql);
203
+ if( rc!=SQLITE_OK || zErrMsg ){
204
+ if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
205
+ fossil_fatal("not a valid bundle: %s", zFile);
206
+ }
207
+ if( doInit ){
208
+ db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
209
+ }else{
210
+ sqlite3_stmt *pStmt;
211
+ zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
212
+ " FROM \"%w\".bconfig", zBName);
213
+ if( zSql==0 ) fossil_fatal("out of memory");
214
+ rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0);
215
+ if( rc ) fossil_fatal("not a valid bundle: %s", zFile);
216
+ sqlite3_free(zSql);
217
+ sqlite3_finalize(pStmt);
218
+ zSql = sqlite3_mprintf("SELECT blobid, uuid,
219
+**makesright (==40** Copyright (c) 2014 D/*
220
+** Copyright (c) 2014 D. Richard Hipp
221
+**
222
+** This program is free software; you can redistribute it and/or
223
+** modify it under the terms of the Simplified BSD License (also
224
+** known as the "2-Clause License" or "FreeBSD License".)
225
+
226
+** This program is distributed in the hope that it will be useful,
227
+** but without any warranty; without even the implied warranty of
228
+** merchantability or fitness for a particular purpose.
229
+**
230
+** Author contact information:
231
+** [email protected]
232
+** http://www.hwaci.com/drh/
233
+**
234
+*******************************************************************************
235
+**
236
+** This file contains code used to implement and manage a "bundle" file.
237
+*/
238
+#include "config.h"
239
+#include "bundle.h"
240
+#include <assert.h>
241
+
242
+/*
243
+** SQe schema of a bundle.
244
+**
245
+** The bblob.delta field can be an integer, a text string, or NULL.
246
+** If an integer, then the corresponding blobid is the delta basis.
247
+** If a text string, then that string is a SHA1 hash for the delta
248
+** basis, whister is presumably in the ain repository. If NULL, then
249
+** data contains content without delta compression.
250
+*/
251
+static const char zBundleInit[] =
252
+@ CREATE TABLE IF NOT EXISTS "%w".bconfig(e ANY
253
+@ );
254
+@ CREATE TABLE IF NOT EXISTS "%w".bblob(
255
+@ blobid INTEGER PRIMARY KEY, -- Blob ID
256
+@ uuid TEXT SHA1 NOT NULL, -- hash of expanded blob
257
+@ sz INT NOT NULL, -- Size of blob after expansion
258
+@ delta ANY, -- Delta compression basis, or NULL
259
+@ notes TEXT, -- Description of content
260
+@ data BLOB -- compressed content
261
+@ );
262
+;
263
+
264
+/*
265
+** Attach a bundle file to the current database connection using the
266
+** attachment name zBName.
267
+*/
268
+static void bundle_attach_file(
269
+ const char *zFile, /* Name of the file that contains the bundle */
270
+ const char *zBName, /* Attachment name */
271
+ int doInit /* Initialize a new bundle, if true */
272
+){
273
+ int rc;
274
+ char *zErrMsg = 0;
275
+ char *zSql;
276
+ if( )<0 ){blob.rid=tobundle.rid"
277
+ _size(zFile, ExtFILE)<0 ){
278
+ fossil_fatal("no such file: %s", zFile);
279
+ }
280
+ assert( g.db );
281
+ zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
282
+ sqlite3_free(zSql);
283
+ if( rc!=SQLITE_OK || zErrMsg ){
284
+ if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
285
+ fossil_fatal("not a valid bundle: %s", zFile);
286
+ }
287
+ if( doInit ){
288
+ db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
289
+ }else{
290
+ sqlite3_stmt *pStmt;
291
+ zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
292
+ " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
293
+** basis, whister is presumably in the main repository. If NULL, then
294
+** data contains content without delta compression.
295
+*/
296
+static const char zBundleInit[] =
297
+@ CREATE TABLE IF NOT EXISTS "%w".bconfig(
298
+@ bcname TEXT,
299
+@ bcvalue ANY
300
+@ );
301
+@ CREATE TABLE IF NOT EXISTS "%w".bblob(
302
+@ blobid INTEGER Pfatalhat string is a SHA1 hash for the delta
303
+** basis, whist ins
--- a/src/bundle.c
+++ b/src/bundle.c
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/bundle.c
+++ b/src/bundle.c
@@ -0,0 +1,303 @@
1 /*
2 ** Copyright (==40** Copyright (c) 2014 D/*
3 ** Copyright (c) 2014 D. Richard Hipp
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of the Simplified BSD License (also
7 ** known as the "2-Clause License" or "FreeBSD License".)
8
9 ** This program is distributed in the hope that it will be useful,
10 ** but without any warranty; without even the implied warranty of
11 ** merchantability or fitness for a particular purpose.
12 **
13 ** Author contact information:
14 ** [email protected]
15 ** http://www.hwaci.com/drh/
16 **
17 *******************************************************************************
18 **
19 ** This file contains code used to implement and manage a "bundle" file.
20 */
21 #include "config.h"
22 #include "bundle.h"
23 #include <assert.h>
24
25 /*
26 ** SQL code used to initialize the schema of a bundle.
27 **
28 ** The bblob.delta field can be an integer, a text string, or NULL.
29 ** If an integer, then the corresponding blobid is the delta basis.
30 ** If a text string, then that string is a SHA1 hash for the delta
31 ** basis, whister is ainory. If NULL, then
32 ** data contains content without delta compression.
33 */
34 static const cha r zBundleInit[] =
35 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
36 @ bcname TEXT,
37 @ bcvalue ANY
38 @ );
39 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
40 @ blobid INTEGER PRIMARY KEY, -- Blob ID
41 @ uuid TEXT SHA1 NOT NULL, -- hash of expanded blob
42 @ sz INT NOT NULL, -- Size of blob after expansion
43 @ delta ANY, -- Delta compression basis, or NULL
44 @ notes TEXT, -- Description of content
45 @ data BLOB -- compressed content
46 @ );
47 ;
48
49 /*
50 ** Attach a bundle file to the current database connection using the
51 ** attachment name zBName.
52 */
53 static void bundle_attach_file(
54 const char *zFile, /* Name of the file that contains the bundle */
55 const char *zBName, /* Attachment name */
56 int doInit /* Initialize a new bundle, if true */
57 ){
58 int rc;
59 char *zErrMsg = 0;
60 char *zSql;
61 if( )<0 ){blob.rid=tobundle.rid"
62 _size(zFile, ExtFILE)<0 ){
63 fossil_fatal("no such file: %s", zFile);
64 }
65 assert( g.db );
66 zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
67 sqlite3_free(zSql);
68 if( rc!=SQLITE_OK || zErrMsg ){
69 if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
70 fossil_fatal("not a valid bundle: %s", zFile);
71 }
72 if( doInit ){
73 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
74 }else{
75 sqlite3_stmt *pStmt;
76 zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
77 " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
78 ** basis, whister is presumably in the main repository. If NULL, then
79 ** data contains content without delta compression.
80 */
81 static const char zBundleInit[] =
82 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
83 @ bcname TEXT,
84 @ bcvalue ANY
85 @ );
86 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
87 @ blobid INTEGER Pfatalhat string is a SHA1 hash for the delta
88 ** basis, whister is presumably in the main repository. If NULL, then
89 ** data contains content without delta compressio}
90 }
91
92 /*
93 ** artifacts from the bundlNULL
94 @ notes TEXT, -- Description of content
95 @ data BLOB -- compressed content
96 @ );
97 ;
98
99 /*
100 ** Attac ter is presumably iHipp
101 **
102 ** This program is free software; you can redistribute it and/or
103 ** modify it under the terms of the Simplified BSD License (also
104 ** known as the "2-Clause License" or "FreeBSD License".)
105
106 ** This program is distributed in the hope that it will be useful,
107 ** but without any warranty; without even the implied warranty of
108 ** merchantability or fitness for a particular purpose.
109 **
110 ** Author contact information:
111 ** [email protected]
112 ** http://www.hwaci.com/drh/
113 **
114 *******************************************************************************
115 **
116 ** This file contains code used to implement and manage a "bundle" file.
117 */
118 #include "config.h"
119 #include "bundle.h"
120 #include <assert.h>
121
122 /*
123 ** SQL code used to initialize the schema of a bundle.
124 **
125 ** The bblob.delta field can be an integer, a text string, or NULL.
126 ** If an integer, then the corresponding blobid is the delta basis.
127 ** If a text string, then that string is a SHA1 hash for the delta
128 ** basis, whister is ainory. If NULL, then
129 ** data contains content without delta compression.
130 */
131 static const char zBundleInit[] =
132 @ CREATE TABLE IF NOT EXISTS "%w/mpressed content
133 @ );
134 ;
135
136 /*
137 ** Attach a bundle file to the current database connection using the
138 ** attachment name zBName.
139 */
140 static void bundle_attach_file(
141 const char *zFile, /* Name of the file that contains the bundle */
142 const char *zBName, /* Attachment name */
143 int doInit /* Initialize a new bundle, if true */
144 ){
145 int rc;
146 char *zErrMsg = 0;
147 char *zSql;
148 if( )<0 ){blob.rid=tobundle.rid"
149 _size(zFile, ExtFILE)<0 ){
150 fossil_fatal("no such file: %s", zFile);
151 }
152 assert( g.db );
153 zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
154 sqlite3_free(zSql);
155 if( rc!=SQLITE_OK || zErrMsg ){
156 if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
157 fossil_fatal("not a valid bundle: %s", zFile);
158 }
159 if( doInit ){
160 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
161 }else{
162 sqlite3_stmt *pStmt;
163 zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
164 " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
165 ** basis, whister is presumably in the main repository. If NULL, then
166 ** data contains content without delta compression.
167 */
168 statc const char zBundleInit[] =
169 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
170 @ bcname TEXT,
171 @ bcvalue ANY
172 @ );
173 @ CREATE TABLE IF NOT EXISTS "% Pfatalhat string is a SHA1 hash for the delta
174 ** basis, whister is presumably in the main reposa contains content without delta compressio}
175 }
176
177 /*
178 ** artifacts from the bundlNULL
179 @ notes TEXT, -- Description of ontent
180 @ data BLOB content
181 @ );
182 ;
183
184 /*
185 ** Attach a bundle file to the current database connection using the
186 ** attachment name zBName.
187 */
188 static void bundle_attach_file(
189 const char *zFile, /* Name of the file that contains the bundle */
190 const char *zBName, */
191 ){
192 int rc;
193 char *zErrMsg = 0;
194 char *zSql;
195 if( !doInit && file_size(zFile, ExtFILE)<0 ){
196 fossil_fatal("no such file: %s", zFile);
197 }
198 assert( g.db );
199 zSql = sqlite3_mprintf("ATTACH %Q AS %Q", zFile, zBName);
200 if( zSql==0 ) fossil_fatal("out of memory");
201 rc = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
202 sqlite3_free(zSql);
203 if( rc!=SQLITE_OK || zErrMsg ){
204 if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
205 fossil_fatal("not a valid bundle: %s", zFile);
206 }
207 if( doInit ){
208 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
209 }else{
210 sqlite3_stmt *pStmt;
211 zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
212 " FROM \"%w\".bconfig", zBName);
213 if( zSql==0 ) fossil_fatal("out of memory");
214 rc = sqlite3_prepare(g.db, zSql, -1, &pStmt, 0);
215 if( rc ) fossil_fatal("not a valid bundle: %s", zFile);
216 sqlite3_free(zSql);
217 sqlite3_finalize(pStmt);
218 zSql = sqlite3_mprintf("SELECT blobid, uuid,
219 **makesright (==40** Copyright (c) 2014 D/*
220 ** Copyright (c) 2014 D. Richard Hipp
221 **
222 ** This program is free software; you can redistribute it and/or
223 ** modify it under the terms of the Simplified BSD License (also
224 ** known as the "2-Clause License" or "FreeBSD License".)
225
226 ** This program is distributed in the hope that it will be useful,
227 ** but without any warranty; without even the implied warranty of
228 ** merchantability or fitness for a particular purpose.
229 **
230 ** Author contact information:
231 ** [email protected]
232 ** http://www.hwaci.com/drh/
233 **
234 *******************************************************************************
235 **
236 ** This file contains code used to implement and manage a "bundle" file.
237 */
238 #include "config.h"
239 #include "bundle.h"
240 #include <assert.h>
241
242 /*
243 ** SQe schema of a bundle.
244 **
245 ** The bblob.delta field can be an integer, a text string, or NULL.
246 ** If an integer, then the corresponding blobid is the delta basis.
247 ** If a text string, then that string is a SHA1 hash for the delta
248 ** basis, whister is presumably in the ain repository. If NULL, then
249 ** data contains content without delta compression.
250 */
251 static const char zBundleInit[] =
252 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(e ANY
253 @ );
254 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
255 @ blobid INTEGER PRIMARY KEY, -- Blob ID
256 @ uuid TEXT SHA1 NOT NULL, -- hash of expanded blob
257 @ sz INT NOT NULL, -- Size of blob after expansion
258 @ delta ANY, -- Delta compression basis, or NULL
259 @ notes TEXT, -- Description of content
260 @ data BLOB -- compressed content
261 @ );
262 ;
263
264 /*
265 ** Attach a bundle file to the current database connection using the
266 ** attachment name zBName.
267 */
268 static void bundle_attach_file(
269 const char *zFile, /* Name of the file that contains the bundle */
270 const char *zBName, /* Attachment name */
271 int doInit /* Initialize a new bundle, if true */
272 ){
273 int rc;
274 char *zErrMsg = 0;
275 char *zSql;
276 if( )<0 ){blob.rid=tobundle.rid"
277 _size(zFile, ExtFILE)<0 ){
278 fossil_fatal("no such file: %s", zFile);
279 }
280 assert( g.db );
281 zSql = sqlite3_mprintf("ATTAfatalhat string is a SHA1 c = sqlite3_exec(g.db, zSql, 0, 0, &zErrMsg);
282 sqlite3_free(zSql);
283 if( rc!=SQLITE_OK || zErrMsg ){
284 if( zErrMsg==0 ) zErrMsg = (char*)sqlite3_errmsg(g.db);
285 fossil_fatal("not a valid bundle: %s", zFile);
286 }
287 if( doInit ){
288 db_multi_exec(zBundleInit /*works-like:"%w%w"*/, zBName, zBName);
289 }else{
290 sqlite3_stmt *pStmt;
291 zSql = sqlite3_mprintf("SELECT bcname, bcvalue"
292 " FROM \"%w\".bconfig", zBName);panic that string is a SHA1fatalhat string is a SHA1 hash for the delta
293 ** basis, whister is presumably in the main repository. If NULL, then
294 ** data contains content without delta compression.
295 */
296 static const char zBundleInit[] =
297 @ CREATE TABLE IF NOT EXISTS "%w".bconfig(
298 @ bcname TEXT,
299 @ bcvalue ANY
300 @ );
301 @ CREATE TABLE IF NOT EXISTS "%w".bblob(
302 @ blobid INTEGER Pfatalhat string is a SHA1 hash for the delta
303 ** basis, whist ins
+1 -3
--- src/cgi.c
+++ src/cgi.c
@@ -342,13 +342,11 @@
342342
** case of most /getfile calls for specific versions, the only way the
343343
** content changes is if someone breaks the SCM. And if that happens, a
344344
** stale cache is the least of the problem. So we provide an Expires
345345
** header set to a reasonable period (default: one week).
346346
*/
347
- /*time_t expires = time(0) + atoi(db_config("constant_expires","604800"));*/
348
- time_t expires = time(0) + 604800;
349
- fprintf(g.httpOut, "Expires: %s\r\n", cgi_rfc822_datestamp(expires));
347
+ fprintf(g.httpOut, "Cache-control: max-age=28800\r\n");
350348
}else{
351349
fprintf(g.httpOut, "Cache-control: no-cache\r\n");
352350
}
353351
354352
/* Content intended for logged in users should only be cached in
355353
--- src/cgi.c
+++ src/cgi.c
@@ -342,13 +342,11 @@
342 ** case of most /getfile calls for specific versions, the only way the
343 ** content changes is if someone breaks the SCM. And if that happens, a
344 ** stale cache is the least of the problem. So we provide an Expires
345 ** header set to a reasonable period (default: one week).
346 */
347 /*time_t expires = time(0) + atoi(db_config("constant_expires","604800"));*/
348 time_t expires = time(0) + 604800;
349 fprintf(g.httpOut, "Expires: %s\r\n", cgi_rfc822_datestamp(expires));
350 }else{
351 fprintf(g.httpOut, "Cache-control: no-cache\r\n");
352 }
353
354 /* Content intended for logged in users should only be cached in
355
--- src/cgi.c
+++ src/cgi.c
@@ -342,13 +342,11 @@
342 ** case of most /getfile calls for specific versions, the only way the
343 ** content changes is if someone breaks the SCM. And if that happens, a
344 ** stale cache is the least of the problem. So we provide an Expires
345 ** header set to a reasonable period (default: one week).
346 */
347 fprintf(g.httpOut, "Cache-control: max-age=28800\r\n");
 
 
348 }else{
349 fprintf(g.httpOut, "Cache-control: no-cache\r\n");
350 }
351
352 /* Content intended for logged in users should only be cached in
353
+1 -1
--- src/checkin.c
+++ src/checkin.c
@@ -65,11 +65,11 @@
6565
6666
db_prepare(&q,
6767
"SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
6868
" FROM vfile "
6969
" WHERE is_selected(id) %s"
70
- " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1",
70
+ " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1 /*scan*/",
7171
blob_sql_text(&where)
7272
);
7373
blob_zero(&rewrittenPathname);
7474
while( db_step(&q)==SQLITE_ROW ){
7575
const char *zPathname = db_column_text(&q,0);
7676
--- src/checkin.c
+++ src/checkin.c
@@ -65,11 +65,11 @@
65
66 db_prepare(&q,
67 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
68 " FROM vfile "
69 " WHERE is_selected(id) %s"
70 " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1",
71 blob_sql_text(&where)
72 );
73 blob_zero(&rewrittenPathname);
74 while( db_step(&q)==SQLITE_ROW ){
75 const char *zPathname = db_column_text(&q,0);
76
--- src/checkin.c
+++ src/checkin.c
@@ -65,11 +65,11 @@
65
66 db_prepare(&q,
67 "SELECT pathname, deleted, chnged, rid, coalesce(origname!=pathname,0)"
68 " FROM vfile "
69 " WHERE is_selected(id) %s"
70 " AND (chnged OR deleted OR rid=0 OR pathname!=origname) ORDER BY 1 /*scan*/",
71 blob_sql_text(&where)
72 );
73 blob_zero(&rewrittenPathname);
74 while( db_step(&q)==SQLITE_ROW ){
75 const char *zPathname = db_column_text(&q,0);
76
+1 -2
--- src/checkout.c
+++ src/checkout.c
@@ -305,12 +305,11 @@
305305
306306
if( !forceFlag && unsaved_changes(0) ){
307307
fossil_fatal("there are unsaved changes in the current checkout");
308308
}
309309
if( !forceFlag
310
- && db_exists("SELECT 1 FROM %s.sqlite_master WHERE name='stash'",
311
- db_name("localdb"))
310
+ && db_table_exists("localdb","stash")
312311
&& db_exists("SELECT 1 FROM %s.stash", db_name("localdb"))
313312
){
314313
fossil_fatal("closing the checkout will delete your stash");
315314
}
316315
if( db_is_writeable("repository") ){
317316
--- src/checkout.c
+++ src/checkout.c
@@ -305,12 +305,11 @@
305
306 if( !forceFlag && unsaved_changes(0) ){
307 fossil_fatal("there are unsaved changes in the current checkout");
308 }
309 if( !forceFlag
310 && db_exists("SELECT 1 FROM %s.sqlite_master WHERE name='stash'",
311 db_name("localdb"))
312 && db_exists("SELECT 1 FROM %s.stash", db_name("localdb"))
313 ){
314 fossil_fatal("closing the checkout will delete your stash");
315 }
316 if( db_is_writeable("repository") ){
317
--- src/checkout.c
+++ src/checkout.c
@@ -305,12 +305,11 @@
305
306 if( !forceFlag && unsaved_changes(0) ){
307 fossil_fatal("there are unsaved changes in the current checkout");
308 }
309 if( !forceFlag
310 && db_table_exists("localdb","stash")
 
311 && db_exists("SELECT 1 FROM %s.stash", db_name("localdb"))
312 ){
313 fossil_fatal("closing the checkout will delete your stash");
314 }
315 if( db_is_writeable("repository") ){
316
+1 -1
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164164
db_begin_transaction();
165165
db_record_repository_filename(g.argv[3]);
166166
db_initial_setup(0, 0, zDefaultUser, 0);
167167
user_select();
168168
db_set("content-schema", CONTENT_SCHEMA, 0);
169
- db_set("aux-schema", AUX_SCHEMA, 0);
169
+ db_set("aux-schema", AUX_SCHEMA_MAX, 0);
170170
db_set("rebuilt", get_version(), 0);
171171
remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172172
url_remember();
173173
if( g.zSSLIdentity!=0 ){
174174
/* If the --ssl-identity option was specified, store it as a setting */
175175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 db_begin_transaction();
165 db_record_repository_filename(g.argv[3]);
166 db_initial_setup(0, 0, zDefaultUser, 0);
167 user_select();
168 db_set("content-schema", CONTENT_SCHEMA, 0);
169 db_set("aux-schema", AUX_SCHEMA, 0);
170 db_set("rebuilt", get_version(), 0);
171 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172 url_remember();
173 if( g.zSSLIdentity!=0 ){
174 /* If the --ssl-identity option was specified, store it as a setting */
175
--- src/clone.c
+++ src/clone.c
@@ -164,11 +164,11 @@
164 db_begin_transaction();
165 db_record_repository_filename(g.argv[3]);
166 db_initial_setup(0, 0, zDefaultUser, 0);
167 user_select();
168 db_set("content-schema", CONTENT_SCHEMA, 0);
169 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
170 db_set("rebuilt", get_version(), 0);
171 remember_or_get_http_auth(zHttpAuth, urlFlags & URL_REMEMBER, g.argv[2]);
172 url_remember();
173 if( g.zSSLIdentity!=0 ){
174 /* If the --ssl-identity option was specified, store it as a setting */
175
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -309,10 +309,11 @@
309309
struct {
310310
const char *zFName; /* Name of the function */
311311
int iFmtArg; /* Index of format argument. Leftmost is 1. */
312312
unsigned fmtFlags; /* Processing flags */
313313
} aFmtFunc[] = {
314
+ { "admin_log", 1, 0 },
314315
{ "blob_append_sql", 2, FMT_NO_S },
315316
{ "blob_appendf", 2, 0 },
316317
{ "cgi_panic", 1, 0 },
317318
{ "cgi_redirectf", 1, 0 },
318319
{ "db_blob", 2, FMT_NO_S },
319320
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -309,10 +309,11 @@
309 struct {
310 const char *zFName; /* Name of the function */
311 int iFmtArg; /* Index of format argument. Leftmost is 1. */
312 unsigned fmtFlags; /* Processing flags */
313 } aFmtFunc[] = {
 
314 { "blob_append_sql", 2, FMT_NO_S },
315 { "blob_appendf", 2, 0 },
316 { "cgi_panic", 1, 0 },
317 { "cgi_redirectf", 1, 0 },
318 { "db_blob", 2, FMT_NO_S },
319
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -309,10 +309,11 @@
309 struct {
310 const char *zFName; /* Name of the function */
311 int iFmtArg; /* Index of format argument. Leftmost is 1. */
312 unsigned fmtFlags; /* Processing flags */
313 } aFmtFunc[] = {
314 { "admin_log", 1, 0 },
315 { "blob_append_sql", 2, FMT_NO_S },
316 { "blob_appendf", 2, 0 },
317 { "cgi_panic", 1, 0 },
318 { "cgi_redirectf", 1, 0 },
319 { "db_blob", 2, FMT_NO_S },
320
+4 -4
--- src/content.c
+++ src/content.c
@@ -567,14 +567,14 @@
567567
db_exec(&s1);
568568
rid = db_last_insert_rowid();
569569
if( !pBlob ){
570570
db_multi_exec("INSERT OR IGNORE INTO phantom VALUES(%d)", rid);
571571
}
572
- if( g.markPrivate || isPrivate ){
573
- db_multi_exec("INSERT INTO private VALUES(%d)", rid);
574
- markAsUnclustered = 0;
575
- }
572
+ }
573
+ if( g.markPrivate || isPrivate ){
574
+ db_multi_exec("INSERT INTO private VALUES(%d)", rid);
575
+ markAsUnclustered = 0;
576576
}
577577
if( nBlob==0 ) blob_reset(&cmpr);
578578
579579
/* If the srcId is specified, then the data we just added is
580580
** really a delta. Record this fact in the delta table.
581581
--- src/content.c
+++ src/content.c
@@ -567,14 +567,14 @@
567 db_exec(&s1);
568 rid = db_last_insert_rowid();
569 if( !pBlob ){
570 db_multi_exec("INSERT OR IGNORE INTO phantom VALUES(%d)", rid);
571 }
572 if( g.markPrivate || isPrivate ){
573 db_multi_exec("INSERT INTO private VALUES(%d)", rid);
574 markAsUnclustered = 0;
575 }
576 }
577 if( nBlob==0 ) blob_reset(&cmpr);
578
579 /* If the srcId is specified, then the data we just added is
580 ** really a delta. Record this fact in the delta table.
581
--- src/content.c
+++ src/content.c
@@ -567,14 +567,14 @@
567 db_exec(&s1);
568 rid = db_last_insert_rowid();
569 if( !pBlob ){
570 db_multi_exec("INSERT OR IGNORE INTO phantom VALUES(%d)", rid);
571 }
572 }
573 if( g.markPrivate || isPrivate ){
574 db_multi_exec("INSERT INTO private VALUES(%d)", rid);
575 markAsUnclustered = 0;
576 }
577 if( nBlob==0 ) blob_reset(&cmpr);
578
579 /* If the srcId is specified, then the data we just added is
580 ** really a delta. Record this fact in the delta table.
581
+168 -43
--- src/db.c
+++ src/db.c
@@ -424,10 +424,13 @@
424424
425425
/*
426426
** Extract text, integer, or blob values from the N-th column of the
427427
** current row.
428428
*/
429
+int db_column_type(Stmt *pStmt, int N){
430
+ return sqlite3_column_type(pStmt->pStmt, N);
431
+}
429432
int db_column_bytes(Stmt *pStmt, int N){
430433
return sqlite3_column_bytes(pStmt->pStmt, N);
431434
}
432435
int db_column_int(Stmt *pStmt, int N){
433436
return sqlite3_column_int(pStmt->pStmt, N);
@@ -486,10 +489,50 @@
486489
while( (rc = db_step(pStmt))==SQLITE_ROW ){}
487490
rc = db_reset(pStmt);
488491
db_check_result(rc);
489492
return rc;
490493
}
494
+
495
+/*
496
+** Print the output of one or more SQL queries on standard output.
497
+** This routine is used for debugging purposes only.
498
+*/
499
+int db_debug(const char *zSql, ...){
500
+ Blob sql;
501
+ int rc = SQLITE_OK;
502
+ va_list ap;
503
+ const char *z, *zEnd;
504
+ sqlite3_stmt *pStmt;
505
+ blob_init(&sql, 0, 0);
506
+ va_start(ap, zSql);
507
+ blob_vappendf(&sql, zSql, ap);
508
+ va_end(ap);
509
+ z = blob_str(&sql);
510
+ while( rc==SQLITE_OK && z[0] ){
511
+ pStmt = 0;
512
+ rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
513
+ if( rc!=SQLITE_OK ) break;
514
+ if( pStmt ){
515
+ int nRow = 0;
516
+ db.nPrepare++;
517
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
518
+ int i, n;
519
+ if( nRow++ > 0 ) fossil_print("\n");
520
+ n = sqlite3_column_count(pStmt);
521
+ for(i=0; i<n; i++){
522
+ fossil_print("%s = %s\n", sqlite3_column_name(pStmt, i),
523
+ sqlite3_column_text(pStmt,i));
524
+ }
525
+ }
526
+ rc = sqlite3_finalize(pStmt);
527
+ if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
528
+ }
529
+ z = zEnd;
530
+ }
531
+ blob_reset(&sql);
532
+ return rc;
533
+}
491534
492535
/*
493536
** Execute multiple SQL statements.
494537
*/
495538
int db_multi_exec(const char *zSql, ...){
@@ -706,10 +749,39 @@
706749
if( rc==0 ){
707750
sqlite3_result_int64(context, mtime);
708751
}
709752
}
710753
754
+void db_sym2rid_function(
755
+ sqlite3_context *context,
756
+ int argc,
757
+ sqlite3_value **argv
758
+){
759
+ char const * arg;
760
+ char const * type;
761
+ if(1 != argc && 2 != argc){
762
+ sqlite3_result_error(context, "Expecting one or two arguments", -1);
763
+ return;
764
+ }
765
+ arg = (const char*)sqlite3_value_text(argv[0]);
766
+ if(!arg){
767
+ sqlite3_result_error(context, "Expecting a STRING argument", -1);
768
+ }else{
769
+ int rid;
770
+ type = (2==argc) ? (const char*)sqlite3_value_text(argv[1]) : 0;
771
+ if(!type) type = "ci";
772
+ rid = symbolic_name_to_rid( arg, type );
773
+ if(rid<0){
774
+ sqlite3_result_error(context, "Symbolic name is ambiguous.", -1);
775
+ }else if(0==rid){
776
+ sqlite3_result_null(context);
777
+ }else{
778
+ sqlite3_result_int64(context, rid);
779
+ }
780
+ }
781
+}
782
+
711783
712784
/*
713785
** Open a database file. Return a pointer to the new database
714786
** connection. An error results in process abort.
715787
*/
@@ -738,13 +810,22 @@
738810
sqlite3_create_function(
739811
db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
740812
);
741813
sqlite3_create_function(
742814
db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
815
+ );
816
+ sqlite3_create_function(
817
+ db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
818
+ 0, 0
819
+ );
820
+ sqlite3_create_function(
821
+ db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
822
+ 0, 0
743823
);
744824
if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
745825
re_add_sql_func(db);
826
+ foci_register(db);
746827
sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
747828
return db;
748829
}
749830
750831
@@ -877,30 +958,47 @@
877958
g.zConfigDbType = "configdb";
878959
}
879960
g.zConfigDbName = zDbName;
880961
}
881962
963
+/*
964
+** Return TRUE if zTable exists.
965
+*/
966
+int db_table_exists(
967
+ const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
968
+ const char *zTable /* Name of table */
969
+){
970
+ return sqlite3_table_column_metadata(g.db,
971
+ zDb ? db_name(zDb) : 0, zTable, 0,
972
+ 0, 0, 0, 0, 0)==SQLITE_OK;
973
+}
974
+
975
+/*
976
+** Return TRUE if zTable exists and contains column zColumn.
977
+** Return FALSE if zTable does not exist or if zTable exists
978
+** but lacks zColumn.
979
+*/
980
+int db_table_has_column(
981
+ const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
982
+ const char *zTable, /* Name of table */
983
+ const char *zColumn /* Name of column in table */
984
+){
985
+ return sqlite3_table_column_metadata(g.db,
986
+ zDb ? db_name(zDb) : 0, zTable, zColumn,
987
+ 0, 0, 0, 0, 0)==SQLITE_OK;
988
+}
882989
883990
/*
884991
** Returns TRUE if zTable exists in the local database but lacks column
885992
** zColumn
886993
*/
887994
static int db_local_table_exists_but_lacks_column(
888995
const char *zTable,
889996
const char *zColumn
890997
){
891
- char *zDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
892
- " WHERE name==%Q /*scan*/",
893
- db_name("localdb"), zTable);
894
- int rc = 0;
895
- if( zDef ){
896
- char *zPattern = mprintf("* %s *", zColumn);
897
- rc = sqlite3_strglob(zPattern, zDef)!=0;
898
- fossil_free(zPattern);
899
- fossil_free(zDef);
900
- }
901
- return rc;
998
+ return db_table_exists(db_name("localdb"), zTable)
999
+ && !db_table_has_column(db_name("localdb"), zTable, zColumn);
9021000
}
9031001
9041002
/*
9051003
** If zDbName is a valid local database file, open it and return
9061004
** true. If it is not a valid local database file, return 0.
@@ -962,20 +1060,21 @@
9621060
** is found, it is attached to the open database connection too.
9631061
*/
9641062
int db_open_local(const char *zDbName){
9651063
int i, n;
9661064
char zPwd[2000];
967
- static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" };
1065
+ static const char *(aDbName[]) = { "_FOSSIL_", ".fslckout", ".fos" };
9681066
9691067
if( g.localOpen ) return 1;
9701068
file_getcwd(zPwd, sizeof(zPwd)-20);
9711069
n = strlen(zPwd);
9721070
while( n>0 ){
9731071
for(i=0; i<count(aDbName); i++){
9741072
sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
9751073
if( isValidLocalDb(zPwd) ){
9761074
/* Found a valid checkout database file */
1075
+ g.zLocalDbName = mprintf("%s", zPwd);
9771076
zPwd[n] = 0;
9781077
while( n>0 && zPwd[n-1]=='/' ){
9791078
n--;
9801079
zPwd[n] = 0;
9811080
}
@@ -1117,13 +1216,13 @@
11171216
11181217
/*
11191218
** Return TRUE if the schema is out-of-date
11201219
*/
11211220
int db_schema_is_outofdate(void){
1122
- return db_exists("SELECT 1 FROM config"
1123
- " WHERE name='aux-schema'"
1124
- " AND value<>%Q", AUX_SCHEMA);
1221
+ if( g.zAuxSchema==0 ) g.zAuxSchema = db_get("aux-schema","");
1222
+ return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1223
+ || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
11251224
}
11261225
11271226
/*
11281227
** Return true if the database is writeable
11291228
*/
@@ -1138,14 +1237,14 @@
11381237
void db_verify_schema(void){
11391238
if( db_schema_is_outofdate() ){
11401239
#ifdef FOSSIL_ENABLE_JSON
11411240
g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
11421241
#endif
1143
- fossil_warning("incorrect repository schema version");
1144
- fossil_warning("your repository has schema version \"%s\" "
1145
- "but this binary expects version \"%s\"",
1146
- db_get("aux-schema",0), AUX_SCHEMA);
1242
+ fossil_warning("incorrect repository schema version: "
1243
+ "current repository schema version is \"%s\" "
1244
+ "but need versions between \"%s\" and \"%s\".",
1245
+ g.zAuxSchema, AUX_SCHEMA_MIN, AUX_SCHEMA_MAX);
11471246
fossil_fatal("run \"fossil rebuild\" to fix this problem");
11481247
}
11491248
}
11501249
11511250
@@ -1173,10 +1272,11 @@
11731272
fossil_fatal("not in a local checkout");
11741273
return;
11751274
}
11761275
db_open_or_attach(zRepo, "test_repo", 0);
11771276
db_lset("repository", blob_str(&repo));
1277
+ db_record_repository_filename(blob_str(&repo));
11781278
db_close(1);
11791279
}
11801280
11811281
11821282
/*
@@ -1393,11 +1493,11 @@
13931493
char *zDate;
13941494
Blob hash;
13951495
Blob manifest;
13961496
13971497
db_set("content-schema", CONTENT_SCHEMA, 0);
1398
- db_set("aux-schema", AUX_SCHEMA, 0);
1498
+ db_set("aux-schema", AUX_SCHEMA_MAX, 0);
13991499
db_set("rebuilt", get_version(), 0);
14001500
if( makeServerCodes ){
14011501
db_setup_server_and_project_codes(0);
14021502
}
14031503
if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
@@ -1965,31 +2065,10 @@
19652065
}
19662066
void db_lset_int(const char *zName, int value){
19672067
db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
19682068
}
19692069
1970
-/*
1971
-** Returns non-0 if the database (which must be open) table identified
1972
-** by zTableName has a column named zColName (case-sensitive), else
1973
-** returns 0.
1974
-*/
1975
-int db_table_has_column(const char *zTableName, const char *zColName){
1976
- Stmt q = empty_Stmt;
1977
- int rc = 0;
1978
- db_prepare( &q, "PRAGMA table_info(%Q)", zTableName );
1979
- while(SQLITE_ROW == db_step(&q)){
1980
- /* Columns: (cid, name, type, notnull, dflt_value, pk) */
1981
- const char *zCol = db_column_text(&q, 1);
1982
- if( 0==fossil_strcmp(zColName, zCol) ){
1983
- rc = 1;
1984
- break;
1985
- }
1986
- }
1987
- db_finalize(&q);
1988
- return rc;
1989
-}
1990
-
19912070
/*
19922071
** Record the name of a local repository in the global_config() database.
19932072
** The repository filename %s is recorded as an entry with a "name" field
19942073
** of the following form:
19952074
**
@@ -2204,10 +2283,11 @@
22042283
const char *def; /* Default value */
22052284
};
22062285
#endif /* INTERFACE */
22072286
struct stControlSettings const ctrlSettings[] = {
22082287
{ "access-log", 0, 0, 0, 0, "off" },
2288
+ { "admin-log", 0, 0, 0, 0, "off" },
22092289
{ "allow-symlinks", 0, 0, 1, 0, "off" },
22102290
{ "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
22112291
{ "auto-hyperlink", 0, 0, 0, 0, "on", },
22122292
{ "auto-shun", 0, 0, 0, 0, "on" },
22132293
{ "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2364,13 @@
22842364
** The "unset" command clears a property setting.
22852365
**
22862366
**
22872367
** access-log If enabled, record successful and failed login attempts
22882368
** in the "accesslog" table. Default: off
2369
+**
2370
+** admin-log If enabled, record configuration changes in the
2371
+** "admin_log" table. Default: off
22892372
**
22902373
** allow-symlinks If enabled, don't follow symlinks, and instead treat
22912374
** (versionable) them as symlinks on Unix. Has no effect on Windows
22922375
** (existing links in repository created on Unix become
22932376
** plain-text files with link destination path inside).
@@ -2660,21 +2743,63 @@
26602743
"%s WITHOUT ROWID;\n"
26612744
"INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
26622745
"DROP TABLE \"x_%w\";\n",
26632746
zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
26642747
);
2665
- fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
2748
+ fossil_print("Converting table %s of %s to WITHOUT ROWID.\n",
2749
+ zTName, g.argv[i]);
26662750
blob_reset(&newSql);
26672751
}
26682752
blob_append_sql(&allSql, "COMMIT;\n");
26692753
db_finalize(&q);
26702754
if( dryRun ){
26712755
fossil_print("SQL that would have been evaluated:\n");
2672
- fossil_print("-------------------------------------------------------------\n");
2756
+ fossil_print("%.78c\n", '-');
26732757
fossil_print("%s", blob_sql_text(&allSql));
26742758
}else{
26752759
db_multi_exec("%s", blob_sql_text(&allSql));
26762760
}
26772761
blob_reset(&allSql);
26782762
db_close(1);
26792763
}
26802764
}
2765
+
2766
+/*
2767
+** Make sure the adminlog table exists. Create it if it does not
2768
+*/
2769
+void create_admin_log_table(void){
2770
+ static int once = 0;
2771
+ if( once ) return;
2772
+ once = 1;
2773
+ db_multi_exec(
2774
+ "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
2775
+ " id INTEGER PRIMARY KEY,\n"
2776
+ " time INTEGER, -- Seconds since 1970\n"
2777
+ " page TEXT, -- path of page\n"
2778
+ " who TEXT, -- User who made the change\n "
2779
+ " what TEXT -- What changed\n"
2780
+ ")", db_name("repository")
2781
+ );
2782
+}
2783
+
2784
+/*
2785
+** Write a message into the admin_event table, if admin logging is
2786
+** enabled via the admin-log configuration option.
2787
+*/
2788
+void admin_log(const char *zFormat, ...){
2789
+ Blob what = empty_blob;
2790
+ va_list ap;
2791
+ if( !db_get_boolean("admin-log", 0) ){
2792
+ /* Potential leak here (on %z params) but
2793
+ the alternative is to let blob_vappendf()
2794
+ do it below. */
2795
+ return;
2796
+ }
2797
+ create_admin_log_table();
2798
+ va_start(ap,zFormat);
2799
+ blob_vappendf( &what, zFormat, ap );
2800
+ va_end(ap);
2801
+ db_multi_exec("INSERT INTO admin_log(time,page,who,what)"
2802
+ " VALUES(now(), %Q, %Q, %B)",
2803
+ g.zPath, g.zLogin, &what);
2804
+ blob_reset(&what);
2805
+}
26812806
--- src/db.c
+++ src/db.c
@@ -424,10 +424,13 @@
424
425 /*
426 ** Extract text, integer, or blob values from the N-th column of the
427 ** current row.
428 */
 
 
 
429 int db_column_bytes(Stmt *pStmt, int N){
430 return sqlite3_column_bytes(pStmt->pStmt, N);
431 }
432 int db_column_int(Stmt *pStmt, int N){
433 return sqlite3_column_int(pStmt->pStmt, N);
@@ -486,10 +489,50 @@
486 while( (rc = db_step(pStmt))==SQLITE_ROW ){}
487 rc = db_reset(pStmt);
488 db_check_result(rc);
489 return rc;
490 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
492 /*
493 ** Execute multiple SQL statements.
494 */
495 int db_multi_exec(const char *zSql, ...){
@@ -706,10 +749,39 @@
706 if( rc==0 ){
707 sqlite3_result_int64(context, mtime);
708 }
709 }
710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711
712 /*
713 ** Open a database file. Return a pointer to the new database
714 ** connection. An error results in process abort.
715 */
@@ -738,13 +810,22 @@
738 sqlite3_create_function(
739 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
740 );
741 sqlite3_create_function(
742 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
 
 
 
 
 
 
 
 
743 );
744 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
745 re_add_sql_func(db);
 
746 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
747 return db;
748 }
749
750
@@ -877,30 +958,47 @@
877 g.zConfigDbType = "configdb";
878 }
879 g.zConfigDbName = zDbName;
880 }
881
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
882
883 /*
884 ** Returns TRUE if zTable exists in the local database but lacks column
885 ** zColumn
886 */
887 static int db_local_table_exists_but_lacks_column(
888 const char *zTable,
889 const char *zColumn
890 ){
891 char *zDef = db_text(0, "SELECT sql FROM %s.sqlite_master"
892 " WHERE name==%Q /*scan*/",
893 db_name("localdb"), zTable);
894 int rc = 0;
895 if( zDef ){
896 char *zPattern = mprintf("* %s *", zColumn);
897 rc = sqlite3_strglob(zPattern, zDef)!=0;
898 fossil_free(zPattern);
899 fossil_free(zDef);
900 }
901 return rc;
902 }
903
904 /*
905 ** If zDbName is a valid local database file, open it and return
906 ** true. If it is not a valid local database file, return 0.
@@ -962,20 +1060,21 @@
962 ** is found, it is attached to the open database connection too.
963 */
964 int db_open_local(const char *zDbName){
965 int i, n;
966 char zPwd[2000];
967 static const char aDbName[][10] = { "_FOSSIL_", ".fslckout", ".fos" };
968
969 if( g.localOpen ) return 1;
970 file_getcwd(zPwd, sizeof(zPwd)-20);
971 n = strlen(zPwd);
972 while( n>0 ){
973 for(i=0; i<count(aDbName); i++){
974 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
975 if( isValidLocalDb(zPwd) ){
976 /* Found a valid checkout database file */
 
977 zPwd[n] = 0;
978 while( n>0 && zPwd[n-1]=='/' ){
979 n--;
980 zPwd[n] = 0;
981 }
@@ -1117,13 +1216,13 @@
1117
1118 /*
1119 ** Return TRUE if the schema is out-of-date
1120 */
1121 int db_schema_is_outofdate(void){
1122 return db_exists("SELECT 1 FROM config"
1123 " WHERE name='aux-schema'"
1124 " AND value<>%Q", AUX_SCHEMA);
1125 }
1126
1127 /*
1128 ** Return true if the database is writeable
1129 */
@@ -1138,14 +1237,14 @@
1138 void db_verify_schema(void){
1139 if( db_schema_is_outofdate() ){
1140 #ifdef FOSSIL_ENABLE_JSON
1141 g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
1142 #endif
1143 fossil_warning("incorrect repository schema version");
1144 fossil_warning("your repository has schema version \"%s\" "
1145 "but this binary expects version \"%s\"",
1146 db_get("aux-schema",0), AUX_SCHEMA);
1147 fossil_fatal("run \"fossil rebuild\" to fix this problem");
1148 }
1149 }
1150
1151
@@ -1173,10 +1272,11 @@
1173 fossil_fatal("not in a local checkout");
1174 return;
1175 }
1176 db_open_or_attach(zRepo, "test_repo", 0);
1177 db_lset("repository", blob_str(&repo));
 
1178 db_close(1);
1179 }
1180
1181
1182 /*
@@ -1393,11 +1493,11 @@
1393 char *zDate;
1394 Blob hash;
1395 Blob manifest;
1396
1397 db_set("content-schema", CONTENT_SCHEMA, 0);
1398 db_set("aux-schema", AUX_SCHEMA, 0);
1399 db_set("rebuilt", get_version(), 0);
1400 if( makeServerCodes ){
1401 db_setup_server_and_project_codes(0);
1402 }
1403 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
@@ -1965,31 +2065,10 @@
1965 }
1966 void db_lset_int(const char *zName, int value){
1967 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
1968 }
1969
1970 /*
1971 ** Returns non-0 if the database (which must be open) table identified
1972 ** by zTableName has a column named zColName (case-sensitive), else
1973 ** returns 0.
1974 */
1975 int db_table_has_column(const char *zTableName, const char *zColName){
1976 Stmt q = empty_Stmt;
1977 int rc = 0;
1978 db_prepare( &q, "PRAGMA table_info(%Q)", zTableName );
1979 while(SQLITE_ROW == db_step(&q)){
1980 /* Columns: (cid, name, type, notnull, dflt_value, pk) */
1981 const char *zCol = db_column_text(&q, 1);
1982 if( 0==fossil_strcmp(zColName, zCol) ){
1983 rc = 1;
1984 break;
1985 }
1986 }
1987 db_finalize(&q);
1988 return rc;
1989 }
1990
1991 /*
1992 ** Record the name of a local repository in the global_config() database.
1993 ** The repository filename %s is recorded as an entry with a "name" field
1994 ** of the following form:
1995 **
@@ -2204,10 +2283,11 @@
2204 const char *def; /* Default value */
2205 };
2206 #endif /* INTERFACE */
2207 struct stControlSettings const ctrlSettings[] = {
2208 { "access-log", 0, 0, 0, 0, "off" },
 
2209 { "allow-symlinks", 0, 0, 1, 0, "off" },
2210 { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2211 { "auto-hyperlink", 0, 0, 0, 0, "on", },
2212 { "auto-shun", 0, 0, 0, 0, "on" },
2213 { "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2364,13 @@
2284 ** The "unset" command clears a property setting.
2285 **
2286 **
2287 ** access-log If enabled, record successful and failed login attempts
2288 ** in the "accesslog" table. Default: off
 
 
 
2289 **
2290 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
2291 ** (versionable) them as symlinks on Unix. Has no effect on Windows
2292 ** (existing links in repository created on Unix become
2293 ** plain-text files with link destination path inside).
@@ -2660,21 +2743,63 @@
2660 "%s WITHOUT ROWID;\n"
2661 "INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
2662 "DROP TABLE \"x_%w\";\n",
2663 zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
2664 );
2665 fossil_print("Converting table %s of %s to WITHOUT ROWID.\n", zTName, g.argv[i]);
 
2666 blob_reset(&newSql);
2667 }
2668 blob_append_sql(&allSql, "COMMIT;\n");
2669 db_finalize(&q);
2670 if( dryRun ){
2671 fossil_print("SQL that would have been evaluated:\n");
2672 fossil_print("-------------------------------------------------------------\n");
2673 fossil_print("%s", blob_sql_text(&allSql));
2674 }else{
2675 db_multi_exec("%s", blob_sql_text(&allSql));
2676 }
2677 blob_reset(&allSql);
2678 db_close(1);
2679 }
2680 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2681
--- src/db.c
+++ src/db.c
@@ -424,10 +424,13 @@
424
425 /*
426 ** Extract text, integer, or blob values from the N-th column of the
427 ** current row.
428 */
429 int db_column_type(Stmt *pStmt, int N){
430 return sqlite3_column_type(pStmt->pStmt, N);
431 }
432 int db_column_bytes(Stmt *pStmt, int N){
433 return sqlite3_column_bytes(pStmt->pStmt, N);
434 }
435 int db_column_int(Stmt *pStmt, int N){
436 return sqlite3_column_int(pStmt->pStmt, N);
@@ -486,10 +489,50 @@
489 while( (rc = db_step(pStmt))==SQLITE_ROW ){}
490 rc = db_reset(pStmt);
491 db_check_result(rc);
492 return rc;
493 }
494
495 /*
496 ** Print the output of one or more SQL queries on standard output.
497 ** This routine is used for debugging purposes only.
498 */
499 int db_debug(const char *zSql, ...){
500 Blob sql;
501 int rc = SQLITE_OK;
502 va_list ap;
503 const char *z, *zEnd;
504 sqlite3_stmt *pStmt;
505 blob_init(&sql, 0, 0);
506 va_start(ap, zSql);
507 blob_vappendf(&sql, zSql, ap);
508 va_end(ap);
509 z = blob_str(&sql);
510 while( rc==SQLITE_OK && z[0] ){
511 pStmt = 0;
512 rc = sqlite3_prepare_v2(g.db, z, -1, &pStmt, &zEnd);
513 if( rc!=SQLITE_OK ) break;
514 if( pStmt ){
515 int nRow = 0;
516 db.nPrepare++;
517 while( sqlite3_step(pStmt)==SQLITE_ROW ){
518 int i, n;
519 if( nRow++ > 0 ) fossil_print("\n");
520 n = sqlite3_column_count(pStmt);
521 for(i=0; i<n; i++){
522 fossil_print("%s = %s\n", sqlite3_column_name(pStmt, i),
523 sqlite3_column_text(pStmt,i));
524 }
525 }
526 rc = sqlite3_finalize(pStmt);
527 if( rc ) db_err("%s: {%.*s}", sqlite3_errmsg(g.db), (int)(zEnd-z), z);
528 }
529 z = zEnd;
530 }
531 blob_reset(&sql);
532 return rc;
533 }
534
535 /*
536 ** Execute multiple SQL statements.
537 */
538 int db_multi_exec(const char *zSql, ...){
@@ -706,10 +749,39 @@
749 if( rc==0 ){
750 sqlite3_result_int64(context, mtime);
751 }
752 }
753
754 void db_sym2rid_function(
755 sqlite3_context *context,
756 int argc,
757 sqlite3_value **argv
758 ){
759 char const * arg;
760 char const * type;
761 if(1 != argc && 2 != argc){
762 sqlite3_result_error(context, "Expecting one or two arguments", -1);
763 return;
764 }
765 arg = (const char*)sqlite3_value_text(argv[0]);
766 if(!arg){
767 sqlite3_result_error(context, "Expecting a STRING argument", -1);
768 }else{
769 int rid;
770 type = (2==argc) ? (const char*)sqlite3_value_text(argv[1]) : 0;
771 if(!type) type = "ci";
772 rid = symbolic_name_to_rid( arg, type );
773 if(rid<0){
774 sqlite3_result_error(context, "Symbolic name is ambiguous.", -1);
775 }else if(0==rid){
776 sqlite3_result_null(context);
777 }else{
778 sqlite3_result_int64(context, rid);
779 }
780 }
781 }
782
783
784 /*
785 ** Open a database file. Return a pointer to the new database
786 ** connection. An error results in process abort.
787 */
@@ -738,13 +810,22 @@
810 sqlite3_create_function(
811 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
812 );
813 sqlite3_create_function(
814 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
815 );
816 sqlite3_create_function(
817 db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
818 0, 0
819 );
820 sqlite3_create_function(
821 db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
822 0, 0
823 );
824 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
825 re_add_sql_func(db);
826 foci_register(db);
827 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
828 return db;
829 }
830
831
@@ -877,30 +958,47 @@
958 g.zConfigDbType = "configdb";
959 }
960 g.zConfigDbName = zDbName;
961 }
962
963 /*
964 ** Return TRUE if zTable exists.
965 */
966 int db_table_exists(
967 const char *zDb, /* One of: NULL, "configdb", "localdb", "repository" */
968 const char *zTable /* Name of table */
969 ){
970 return sqlite3_table_column_metadata(g.db,
971 zDb ? db_name(zDb) : 0, zTable, 0,
972 0, 0, 0, 0, 0)==SQLITE_OK;
973 }
974
975 /*
976 ** Return TRUE if zTable exists and contains column zColumn.
977 ** Return FALSE if zTable does not exist or if zTable exists
978 ** but lacks zColumn.
979 */
980 int db_table_has_column(
981 const char *zDb, /* One of: NULL, "config", "localdb", "repository" */
982 const char *zTable, /* Name of table */
983 const char *zColumn /* Name of column in table */
984 ){
985 return sqlite3_table_column_metadata(g.db,
986 zDb ? db_name(zDb) : 0, zTable, zColumn,
987 0, 0, 0, 0, 0)==SQLITE_OK;
988 }
989
990 /*
991 ** Returns TRUE if zTable exists in the local database but lacks column
992 ** zColumn
993 */
994 static int db_local_table_exists_but_lacks_column(
995 const char *zTable,
996 const char *zColumn
997 ){
998 return db_table_exists(db_name("localdb"), zTable)
999 && !db_table_has_column(db_name("localdb"), zTable, zColumn);
 
 
 
 
 
 
 
 
 
1000 }
1001
1002 /*
1003 ** If zDbName is a valid local database file, open it and return
1004 ** true. If it is not a valid local database file, return 0.
@@ -962,20 +1060,21 @@
1060 ** is found, it is attached to the open database connection too.
1061 */
1062 int db_open_local(const char *zDbName){
1063 int i, n;
1064 char zPwd[2000];
1065 static const char *(aDbName[]) = { "_FOSSIL_", ".fslckout", ".fos" };
1066
1067 if( g.localOpen ) return 1;
1068 file_getcwd(zPwd, sizeof(zPwd)-20);
1069 n = strlen(zPwd);
1070 while( n>0 ){
1071 for(i=0; i<count(aDbName); i++){
1072 sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "/%s", aDbName[i]);
1073 if( isValidLocalDb(zPwd) ){
1074 /* Found a valid checkout database file */
1075 g.zLocalDbName = mprintf("%s", zPwd);
1076 zPwd[n] = 0;
1077 while( n>0 && zPwd[n-1]=='/' ){
1078 n--;
1079 zPwd[n] = 0;
1080 }
@@ -1117,13 +1216,13 @@
1216
1217 /*
1218 ** Return TRUE if the schema is out-of-date
1219 */
1220 int db_schema_is_outofdate(void){
1221 if( g.zAuxSchema==0 ) g.zAuxSchema = db_get("aux-schema","");
1222 return strcmp(g.zAuxSchema,AUX_SCHEMA_MIN)<0
1223 || strcmp(g.zAuxSchema,AUX_SCHEMA_MAX)>0;
1224 }
1225
1226 /*
1227 ** Return true if the database is writeable
1228 */
@@ -1138,14 +1237,14 @@
1237 void db_verify_schema(void){
1238 if( db_schema_is_outofdate() ){
1239 #ifdef FOSSIL_ENABLE_JSON
1240 g.json.resultCode = FSL_JSON_E_DB_NEEDS_REBUILD;
1241 #endif
1242 fossil_warning("incorrect repository schema version: "
1243 "current repository schema version is \"%s\" "
1244 "but need versions between \"%s\" and \"%s\".",
1245 g.zAuxSchema, AUX_SCHEMA_MIN, AUX_SCHEMA_MAX);
1246 fossil_fatal("run \"fossil rebuild\" to fix this problem");
1247 }
1248 }
1249
1250
@@ -1173,10 +1272,11 @@
1272 fossil_fatal("not in a local checkout");
1273 return;
1274 }
1275 db_open_or_attach(zRepo, "test_repo", 0);
1276 db_lset("repository", blob_str(&repo));
1277 db_record_repository_filename(blob_str(&repo));
1278 db_close(1);
1279 }
1280
1281
1282 /*
@@ -1393,11 +1493,11 @@
1493 char *zDate;
1494 Blob hash;
1495 Blob manifest;
1496
1497 db_set("content-schema", CONTENT_SCHEMA, 0);
1498 db_set("aux-schema", AUX_SCHEMA_MAX, 0);
1499 db_set("rebuilt", get_version(), 0);
1500 if( makeServerCodes ){
1501 db_setup_server_and_project_codes(0);
1502 }
1503 if( !db_is_global("autosync") ) db_set_int("autosync", 1, 0);
@@ -1965,31 +2065,10 @@
2065 }
2066 void db_lset_int(const char *zName, int value){
2067 db_multi_exec("REPLACE INTO vvar(name,value) VALUES(%Q,%d)", zName, value);
2068 }
2069
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2070 /*
2071 ** Record the name of a local repository in the global_config() database.
2072 ** The repository filename %s is recorded as an entry with a "name" field
2073 ** of the following form:
2074 **
@@ -2204,10 +2283,11 @@
2283 const char *def; /* Default value */
2284 };
2285 #endif /* INTERFACE */
2286 struct stControlSettings const ctrlSettings[] = {
2287 { "access-log", 0, 0, 0, 0, "off" },
2288 { "admin-log", 0, 0, 0, 0, "off" },
2289 { "allow-symlinks", 0, 0, 1, 0, "off" },
2290 { "auto-captcha", "autocaptcha", 0, 0, 0, "on" },
2291 { "auto-hyperlink", 0, 0, 0, 0, "on", },
2292 { "auto-shun", 0, 0, 0, 0, "on" },
2293 { "autosync", 0, 0, 0, 0, "on" },
@@ -2284,10 +2364,13 @@
2364 ** The "unset" command clears a property setting.
2365 **
2366 **
2367 ** access-log If enabled, record successful and failed login attempts
2368 ** in the "accesslog" table. Default: off
2369 **
2370 ** admin-log If enabled, record configuration changes in the
2371 ** "admin_log" table. Default: off
2372 **
2373 ** allow-symlinks If enabled, don't follow symlinks, and instead treat
2374 ** (versionable) them as symlinks on Unix. Has no effect on Windows
2375 ** (existing links in repository created on Unix become
2376 ** plain-text files with link destination path inside).
@@ -2660,21 +2743,63 @@
2743 "%s WITHOUT ROWID;\n"
2744 "INSERT INTO \"%w\" SELECT * FROM \"x_%w\";\n"
2745 "DROP TABLE \"x_%w\";\n",
2746 zTName, zTName, blob_sql_text(&newSql), zTName, zTName, zTName
2747 );
2748 fossil_print("Converting table %s of %s to WITHOUT ROWID.\n",
2749 zTName, g.argv[i]);
2750 blob_reset(&newSql);
2751 }
2752 blob_append_sql(&allSql, "COMMIT;\n");
2753 db_finalize(&q);
2754 if( dryRun ){
2755 fossil_print("SQL that would have been evaluated:\n");
2756 fossil_print("%.78c\n", '-');
2757 fossil_print("%s", blob_sql_text(&allSql));
2758 }else{
2759 db_multi_exec("%s", blob_sql_text(&allSql));
2760 }
2761 blob_reset(&allSql);
2762 db_close(1);
2763 }
2764 }
2765
2766 /*
2767 ** Make sure the adminlog table exists. Create it if it does not
2768 */
2769 void create_admin_log_table(void){
2770 static int once = 0;
2771 if( once ) return;
2772 once = 1;
2773 db_multi_exec(
2774 "CREATE TABLE IF NOT EXISTS \"%w\".admin_log(\n"
2775 " id INTEGER PRIMARY KEY,\n"
2776 " time INTEGER, -- Seconds since 1970\n"
2777 " page TEXT, -- path of page\n"
2778 " who TEXT, -- User who made the change\n "
2779 " what TEXT -- What changed\n"
2780 ")", db_name("repository")
2781 );
2782 }
2783
2784 /*
2785 ** Write a message into the admin_event table, if admin logging is
2786 ** enabled via the admin-log configuration option.
2787 */
2788 void admin_log(const char *zFormat, ...){
2789 Blob what = empty_blob;
2790 va_list ap;
2791 if( !db_get_boolean("admin-log", 0) ){
2792 /* Potential leak here (on %z params) but
2793 the alternative is to let blob_vappendf()
2794 do it below. */
2795 return;
2796 }
2797 create_admin_log_table();
2798 va_start(ap,zFormat);
2799 blob_vappendf( &what, zFormat, ap );
2800 va_end(ap);
2801 db_multi_exec("INSERT INTO admin_log(time,page,who,what)"
2802 " VALUES(now(), %Q, %Q, %B)",
2803 g.zPath, g.zLogin, &what);
2804 blob_reset(&what);
2805 }
2806
--- src/descendants.c
+++ src/descendants.c
@@ -289,14 +289,14 @@
289289
}
290290
291291
/*
292292
** COMMAND: descendants*
293293
**
294
-** Usage: %fossil descendants ?BASELINE-ID? ?OPTIONS?
294
+** Usage: %fossil descendants ?CHECKIN? ?OPTIONS?
295295
**
296
-** Find all leaf descendants of the baseline specified or if the argument
297
-** is omitted, of the baseline currently checked out.
296
+** Find all leaf descendants of the checkin specified or if the argument
297
+** is omitted, of the checkin currently checked out.
298298
**
299299
** Options:
300300
** -R|--repository FILE Extract info from repository FILE
301301
** -W|--width <num> Width of lines (default is to auto-detect).
302302
** Must be >20 or 0 (= no limit, resulting in a
@@ -334,11 +334,11 @@
334334
"%s"
335335
" AND event.objid IN (SELECT rid FROM leaves)"
336336
" ORDER BY event.mtime DESC",
337337
timeline_query_for_tty()
338338
);
339
- print_timeline(&q, -20, width, 0);
339
+ print_timeline(&q, 0, width, 0);
340340
db_finalize(&q);
341341
}
342342
343343
/*
344344
** COMMAND: leaves*
345345
--- src/descendants.c
+++ src/descendants.c
@@ -289,14 +289,14 @@
289 }
290
291 /*
292 ** COMMAND: descendants*
293 **
294 ** Usage: %fossil descendants ?BASELINE-ID? ?OPTIONS?
295 **
296 ** Find all leaf descendants of the baseline specified or if the argument
297 ** is omitted, of the baseline currently checked out.
298 **
299 ** Options:
300 ** -R|--repository FILE Extract info from repository FILE
301 ** -W|--width <num> Width of lines (default is to auto-detect).
302 ** Must be >20 or 0 (= no limit, resulting in a
@@ -334,11 +334,11 @@
334 "%s"
335 " AND event.objid IN (SELECT rid FROM leaves)"
336 " ORDER BY event.mtime DESC",
337 timeline_query_for_tty()
338 );
339 print_timeline(&q, -20, width, 0);
340 db_finalize(&q);
341 }
342
343 /*
344 ** COMMAND: leaves*
345
--- src/descendants.c
+++ src/descendants.c
@@ -289,14 +289,14 @@
289 }
290
291 /*
292 ** COMMAND: descendants*
293 **
294 ** Usage: %fossil descendants ?CHECKIN? ?OPTIONS?
295 **
296 ** Find all leaf descendants of the checkin specified or if the argument
297 ** is omitted, of the checkin currently checked out.
298 **
299 ** Options:
300 ** -R|--repository FILE Extract info from repository FILE
301 ** -W|--width <num> Width of lines (default is to auto-detect).
302 ** Must be >20 or 0 (= no limit, resulting in a
@@ -334,11 +334,11 @@
334 "%s"
335 " AND event.objid IN (SELECT rid FROM leaves)"
336 " ORDER BY event.mtime DESC",
337 timeline_query_for_tty()
338 );
339 print_timeline(&q, 0, width, 0);
340 db_finalize(&q);
341 }
342
343 /*
344 ** COMMAND: leaves*
345
+2 -2
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -363,20 +363,20 @@
363363
"SELECT pathname, 0, 0, 1, 0, islink"
364364
" FROM vfile v2"
365365
" WHERE v2.vid=%d"
366366
" AND NOT EXISTS(SELECT 1 FROM vfile v1"
367367
" WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
368
- " ORDER BY 1",
368
+ " ORDER BY 1 /*scan*/",
369369
rid, vid, rid, vid, vid, rid
370370
);
371371
}else{
372372
blob_append_sql(&sql,
373373
"SELECT pathname, deleted, chnged , rid==0, rid, islink"
374374
" FROM vfile"
375375
" WHERE vid=%d"
376376
" AND (deleted OR chnged OR rid==0)"
377
- " ORDER BY pathname",
377
+ " ORDER BY pathname /*scan*/",
378378
vid
379379
);
380380
}
381381
db_prepare(&q, "%s", blob_sql_text(&sql));
382382
while( db_step(&q)==SQLITE_ROW ){
383383
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -363,20 +363,20 @@
363 "SELECT pathname, 0, 0, 1, 0, islink"
364 " FROM vfile v2"
365 " WHERE v2.vid=%d"
366 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
367 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
368 " ORDER BY 1",
369 rid, vid, rid, vid, vid, rid
370 );
371 }else{
372 blob_append_sql(&sql,
373 "SELECT pathname, deleted, chnged , rid==0, rid, islink"
374 " FROM vfile"
375 " WHERE vid=%d"
376 " AND (deleted OR chnged OR rid==0)"
377 " ORDER BY pathname",
378 vid
379 );
380 }
381 db_prepare(&q, "%s", blob_sql_text(&sql));
382 while( db_step(&q)==SQLITE_ROW ){
383
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -363,20 +363,20 @@
363 "SELECT pathname, 0, 0, 1, 0, islink"
364 " FROM vfile v2"
365 " WHERE v2.vid=%d"
366 " AND NOT EXISTS(SELECT 1 FROM vfile v1"
367 " WHERE v1.vid=%d AND v1.pathname=v2.pathname)"
368 " ORDER BY 1 /*scan*/",
369 rid, vid, rid, vid, vid, rid
370 );
371 }else{
372 blob_append_sql(&sql,
373 "SELECT pathname, deleted, chnged , rid==0, rid, islink"
374 " FROM vfile"
375 " WHERE vid=%d"
376 " AND (deleted OR chnged OR rid==0)"
377 " ORDER BY pathname /*scan*/",
378 vid
379 );
380 }
381 db_prepare(&q, "%s", blob_sql_text(&sql));
382 while( db_step(&q)==SQLITE_ROW ){
383
--- src/finfo.c
+++ src/finfo.c
@@ -495,10 +495,11 @@
495495
@ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
496496
if( srcid ){
497497
@ srcid=%d(srcid)
498498
}
499499
}
500
+ tag_private_status(frid);
500501
@ </td></tr>
501502
}
502503
db_finalize(&q);
503504
if( pGraph ){
504505
graph_finish(pGraph, 0);
505506
506507
ADDED src/foci.c
--- src/finfo.c
+++ src/finfo.c
@@ -495,10 +495,11 @@
495 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
496 if( srcid ){
497 @ srcid=%d(srcid)
498 }
499 }
 
500 @ </td></tr>
501 }
502 db_finalize(&q);
503 if( pGraph ){
504 graph_finish(pGraph, 0);
505
506 DDED src/foci.c
--- src/finfo.c
+++ src/finfo.c
@@ -495,10 +495,11 @@
495 @ <br>fid=%d(frid) pid=%d(fpid) mid=%d(fmid) sz=%d(sz)
496 if( srcid ){
497 @ srcid=%d(srcid)
498 }
499 }
500 tag_private_status(frid);
501 @ </td></tr>
502 }
503 db_finalize(&q);
504 if( pGraph ){
505 graph_finish(pGraph, 0);
506
507 DDED src/foci.c
+7
--- a/src/foci.c
+++ b/src/foci.c
@@ -0,0 +1,7 @@
1
+//* The function finds the BLOB.RID value
2
+** corresponding to the 'trunk' tag. Then the
3
+** decodes the manifest defined by that BLOB and returns all files described
4
+** by that manifest. / /an SQLite virtual tabCREATE VIRTUAL TABLE temp.focipCur->iFile = 0;
5
+pCuur->pMan, 0); Then the
6
+** decodes//* The function finds ttion finds the BL//* Of CheckI rem
7
+ sqlite3_context *ctx,
--- a/src/foci.c
+++ b/src/foci.c
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
--- a/src/foci.c
+++ b/src/foci.c
@@ -0,0 +1,7 @@
1 //* The function finds the BLOB.RID value
2 ** corresponding to the 'trunk' tag. Then the
3 ** decodes the manifest defined by that BLOB and returns all files described
4 ** by that manifest. / /an SQLite virtual tabCREATE VIRTUAL TABLE temp.focipCur->iFile = 0;
5 pCuur->pMan, 0); Then the
6 ** decodes//* The function finds ttion finds the BL//* Of CheckI rem
7 sqlite3_context *ctx,
--- src/fusefs.c
+++ src/fusefs.c
@@ -319,11 +319,10 @@
319319
#ifndef FOSSIL_HAVE_FUSEFS
320320
fossil_fatal("this build of fossil does not support the fuse filesystem");
321321
#else
322322
char *zMountPoint;
323323
char *azNewArgv[5];
324
- int i;
325324
int doDebug = find_option("debug","d",0)!=0;
326325
327326
db_find_and_open_repository(0,0);
328327
verify_all_options();
329328
blob_init(&fusefs.content, 0, 0);
330329
--- src/fusefs.c
+++ src/fusefs.c
@@ -319,11 +319,10 @@
319 #ifndef FOSSIL_HAVE_FUSEFS
320 fossil_fatal("this build of fossil does not support the fuse filesystem");
321 #else
322 char *zMountPoint;
323 char *azNewArgv[5];
324 int i;
325 int doDebug = find_option("debug","d",0)!=0;
326
327 db_find_and_open_repository(0,0);
328 verify_all_options();
329 blob_init(&fusefs.content, 0, 0);
330
--- src/fusefs.c
+++ src/fusefs.c
@@ -319,11 +319,10 @@
319 #ifndef FOSSIL_HAVE_FUSEFS
320 fossil_fatal("this build of fossil does not support the fuse filesystem");
321 #else
322 char *zMountPoint;
323 char *azNewArgv[5];
 
324 int doDebug = find_option("debug","d",0)!=0;
325
326 db_find_and_open_repository(0,0);
327 verify_all_options();
328 blob_init(&fusefs.content, 0, 0);
329
+8 -6
--- src/http.c
+++ src/http.c
@@ -285,11 +285,11 @@
285285
g.zHttpAuth = prompt_for_httpauth_creds();
286286
transport_close(&g.url);
287287
return http_exchange(pSend, pReply, useLogin, maxRedirect);
288288
}
289289
}
290
- if( rc!=200 && rc!=302 ){
290
+ if( rc!=200 && rc!=301 && rc!=302 ){
291291
int ii;
292292
for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
293293
while( zLine[ii]==' ' ) ii++;
294294
fossil_warning("server says: %s", &zLine[ii]);
295295
goto write_err;
@@ -299,11 +299,11 @@
299299
}else{
300300
closeConnection = 0;
301301
}
302302
}else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){
303303
if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err;
304
- if( rc!=200 && rc!=302 ){
304
+ if( rc!=200 && rc!=301 && rc!=302 ){
305305
int ii;
306306
for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
307307
while( zLine[ii]==' ' ) ii++;
308308
fossil_warning("server says: %s", &zLine[ii]);
309309
goto write_err;
@@ -319,11 +319,12 @@
319319
if( c=='c' || c=='C' ){
320320
closeConnection = 1;
321321
}else if( c=='k' || c=='K' ){
322322
closeConnection = 0;
323323
}
324
- }else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){
324
+ }else if( ( rc==301 || rc==302 ) &&
325
+ fossil_strnicmp(zLine, "location:", 9)==0 ){
325326
int i, j;
326327
327328
if ( --maxRedirect == 0){
328329
fossil_warning("redirect limit exceeded");
329330
goto write_err;
@@ -336,16 +337,17 @@
336337
j = strlen(zLine) - 1;
337338
while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
338339
j -= 4;
339340
zLine[j] = 0;
340341
}
341
- fossil_print("redirect to %s\n", &zLine[i]);
342
+ transport_close(&g.url);
343
+ transport_global_shutdown(&g.url);
344
+ fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
342345
url_parse(&zLine[i], 0);
343346
fSeenHttpAuth = 0;
344347
if( g.zHttpAuth ) free(g.zHttpAuth);
345348
g.zHttpAuth = get_httpauth();
346
- transport_close(&g.url);
347349
return http_exchange(pSend, pReply, useLogin, maxRedirect);
348350
}else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
349351
if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){
350352
isCompressed = 0;
351353
}else if( fossil_strnicmp(&zLine[14],
@@ -359,11 +361,11 @@
359361
if( iLength<0 ){
360362
fossil_warning("server did not reply");
361363
goto write_err;
362364
}
363365
if( rc!=200 ){
364
- fossil_warning("\"location:\" missing from 302 redirect reply");
366
+ fossil_warning("\"location:\" missing from %d redirect reply", rc);
365367
goto write_err;
366368
}
367369
368370
/*
369371
** Extract the reply payload that follows the header
370372
--- src/http.c
+++ src/http.c
@@ -285,11 +285,11 @@
285 g.zHttpAuth = prompt_for_httpauth_creds();
286 transport_close(&g.url);
287 return http_exchange(pSend, pReply, useLogin, maxRedirect);
288 }
289 }
290 if( rc!=200 && rc!=302 ){
291 int ii;
292 for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
293 while( zLine[ii]==' ' ) ii++;
294 fossil_warning("server says: %s", &zLine[ii]);
295 goto write_err;
@@ -299,11 +299,11 @@
299 }else{
300 closeConnection = 0;
301 }
302 }else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){
303 if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err;
304 if( rc!=200 && rc!=302 ){
305 int ii;
306 for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
307 while( zLine[ii]==' ' ) ii++;
308 fossil_warning("server says: %s", &zLine[ii]);
309 goto write_err;
@@ -319,11 +319,12 @@
319 if( c=='c' || c=='C' ){
320 closeConnection = 1;
321 }else if( c=='k' || c=='K' ){
322 closeConnection = 0;
323 }
324 }else if( rc==302 && fossil_strnicmp(zLine, "location:", 9)==0 ){
 
325 int i, j;
326
327 if ( --maxRedirect == 0){
328 fossil_warning("redirect limit exceeded");
329 goto write_err;
@@ -336,16 +337,17 @@
336 j = strlen(zLine) - 1;
337 while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
338 j -= 4;
339 zLine[j] = 0;
340 }
341 fossil_print("redirect to %s\n", &zLine[i]);
 
 
342 url_parse(&zLine[i], 0);
343 fSeenHttpAuth = 0;
344 if( g.zHttpAuth ) free(g.zHttpAuth);
345 g.zHttpAuth = get_httpauth();
346 transport_close(&g.url);
347 return http_exchange(pSend, pReply, useLogin, maxRedirect);
348 }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
349 if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){
350 isCompressed = 0;
351 }else if( fossil_strnicmp(&zLine[14],
@@ -359,11 +361,11 @@
359 if( iLength<0 ){
360 fossil_warning("server did not reply");
361 goto write_err;
362 }
363 if( rc!=200 ){
364 fossil_warning("\"location:\" missing from 302 redirect reply");
365 goto write_err;
366 }
367
368 /*
369 ** Extract the reply payload that follows the header
370
--- src/http.c
+++ src/http.c
@@ -285,11 +285,11 @@
285 g.zHttpAuth = prompt_for_httpauth_creds();
286 transport_close(&g.url);
287 return http_exchange(pSend, pReply, useLogin, maxRedirect);
288 }
289 }
290 if( rc!=200 && rc!=301 && rc!=302 ){
291 int ii;
292 for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
293 while( zLine[ii]==' ' ) ii++;
294 fossil_warning("server says: %s", &zLine[ii]);
295 goto write_err;
@@ -299,11 +299,11 @@
299 }else{
300 closeConnection = 0;
301 }
302 }else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){
303 if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err;
304 if( rc!=200 && rc!=301 && rc!=302 ){
305 int ii;
306 for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){}
307 while( zLine[ii]==' ' ) ii++;
308 fossil_warning("server says: %s", &zLine[ii]);
309 goto write_err;
@@ -319,11 +319,12 @@
319 if( c=='c' || c=='C' ){
320 closeConnection = 1;
321 }else if( c=='k' || c=='K' ){
322 closeConnection = 0;
323 }
324 }else if( ( rc==301 || rc==302 ) &&
325 fossil_strnicmp(zLine, "location:", 9)==0 ){
326 int i, j;
327
328 if ( --maxRedirect == 0){
329 fossil_warning("redirect limit exceeded");
330 goto write_err;
@@ -336,16 +337,17 @@
337 j = strlen(zLine) - 1;
338 while( j>4 && fossil_strcmp(&zLine[j-4],"/xfer")==0 ){
339 j -= 4;
340 zLine[j] = 0;
341 }
342 transport_close(&g.url);
343 transport_global_shutdown(&g.url);
344 fossil_print("redirect with status %d to %s\n", rc, &zLine[i]);
345 url_parse(&zLine[i], 0);
346 fSeenHttpAuth = 0;
347 if( g.zHttpAuth ) free(g.zHttpAuth);
348 g.zHttpAuth = get_httpauth();
 
349 return http_exchange(pSend, pReply, useLogin, maxRedirect);
350 }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){
351 if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){
352 isCompressed = 0;
353 }else if( fossil_strnicmp(&zLine[14],
@@ -359,11 +361,11 @@
361 if( iLength<0 ){
362 fossil_warning("server did not reply");
363 goto write_err;
364 }
365 if( rc!=200 ){
366 fossil_warning("\"location:\" missing from %d redirect reply", rc);
367 goto write_err;
368 }
369
370 /*
371 ** Extract the reply payload that follows the header
372
--- src/http_socket.c
+++ src/http_socket.c
@@ -45,10 +45,11 @@
4545
** There can only be a single socket connection open at a time.
4646
** State information about that socket is stored in the following
4747
** local variables:
4848
*/
4949
static int socketIsInit = 0; /* True after global initialization */
50
+static int addrIsInit = 0; /* True once addr is initialized */
5051
#if defined(_WIN32)
5152
static WSADATA socketInfo; /* Windows socket initialize data */
5253
#endif
5354
static int iSocket = -1; /* The socket on which we talk to the server */
5455
static char *socketErrMsg = 0; /* Text of most recent socket error */
@@ -105,10 +106,11 @@
105106
WSACleanup();
106107
#endif
107108
socket_clear_errmsg();
108109
socketIsInit = 0;
109110
}
111
+ addrIsInit = 0;
110112
}
111113
112114
/*
113115
** Close the currently open socket. If no socket is open, this routine
114116
** is a no-op.
@@ -133,14 +135,14 @@
133135
**
134136
** Return the number of errors.
135137
*/
136138
int socket_open(UrlData *pUrlData){
137139
static struct sockaddr_in addr; /* The server address */
138
- static int addrIsInit = 0; /* True once addr is initialized */
139140
140141
socket_global_init();
141142
if( !addrIsInit ){
143
+ memset(&addr, 0, sizeof(addr));
142144
addr.sin_family = AF_INET;
143145
addr.sin_port = htons(pUrlData->port);
144146
*(int*)&addr.sin_addr = inet_addr(pUrlData->name);
145147
if( -1 == *(int*)&addr.sin_addr ){
146148
#ifndef FOSSIL_STATIC_LINK
147149
--- src/http_socket.c
+++ src/http_socket.c
@@ -45,10 +45,11 @@
45 ** There can only be a single socket connection open at a time.
46 ** State information about that socket is stored in the following
47 ** local variables:
48 */
49 static int socketIsInit = 0; /* True after global initialization */
 
50 #if defined(_WIN32)
51 static WSADATA socketInfo; /* Windows socket initialize data */
52 #endif
53 static int iSocket = -1; /* The socket on which we talk to the server */
54 static char *socketErrMsg = 0; /* Text of most recent socket error */
@@ -105,10 +106,11 @@
105 WSACleanup();
106 #endif
107 socket_clear_errmsg();
108 socketIsInit = 0;
109 }
 
110 }
111
112 /*
113 ** Close the currently open socket. If no socket is open, this routine
114 ** is a no-op.
@@ -133,14 +135,14 @@
133 **
134 ** Return the number of errors.
135 */
136 int socket_open(UrlData *pUrlData){
137 static struct sockaddr_in addr; /* The server address */
138 static int addrIsInit = 0; /* True once addr is initialized */
139
140 socket_global_init();
141 if( !addrIsInit ){
 
142 addr.sin_family = AF_INET;
143 addr.sin_port = htons(pUrlData->port);
144 *(int*)&addr.sin_addr = inet_addr(pUrlData->name);
145 if( -1 == *(int*)&addr.sin_addr ){
146 #ifndef FOSSIL_STATIC_LINK
147
--- src/http_socket.c
+++ src/http_socket.c
@@ -45,10 +45,11 @@
45 ** There can only be a single socket connection open at a time.
46 ** State information about that socket is stored in the following
47 ** local variables:
48 */
49 static int socketIsInit = 0; /* True after global initialization */
50 static int addrIsInit = 0; /* True once addr is initialized */
51 #if defined(_WIN32)
52 static WSADATA socketInfo; /* Windows socket initialize data */
53 #endif
54 static int iSocket = -1; /* The socket on which we talk to the server */
55 static char *socketErrMsg = 0; /* Text of most recent socket error */
@@ -105,10 +106,11 @@
106 WSACleanup();
107 #endif
108 socket_clear_errmsg();
109 socketIsInit = 0;
110 }
111 addrIsInit = 0;
112 }
113
114 /*
115 ** Close the currently open socket. If no socket is open, this routine
116 ** is a no-op.
@@ -133,14 +135,14 @@
135 **
136 ** Return the number of errors.
137 */
138 int socket_open(UrlData *pUrlData){
139 static struct sockaddr_in addr; /* The server address */
 
140
141 socket_global_init();
142 if( !addrIsInit ){
143 memset(&addr, 0, sizeof(addr));
144 addr.sin_family = AF_INET;
145 addr.sin_port = htons(pUrlData->port);
146 *(int*)&addr.sin_addr = inet_addr(pUrlData->name);
147 if( -1 == *(int*)&addr.sin_addr ){
148 #ifndef FOSSIL_STATIC_LINK
149
+4 -3
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -41,11 +41,11 @@
4141
** There can only be a single OpenSSL IO connection open at a time.
4242
** State information about that IO is stored in the following
4343
** local variables:
4444
*/
4545
static int sslIsInit = 0; /* True after global initialization */
46
-static BIO *iBio; /* OpenSSL I/O abstraction */
46
+static BIO *iBio = 0; /* OpenSSL I/O abstraction */
4747
static char *sslErrMsg = 0; /* Text of most recent OpenSSL error */
4848
static SSL_CTX *sslCtx; /* SSL context */
4949
static SSL *ssl;
5050
5151
@@ -99,12 +99,12 @@
9999
SSL_library_init();
100100
SSL_load_error_strings();
101101
ERR_load_BIO_strings();
102102
OpenSSL_add_all_algorithms();
103103
sslCtx = SSL_CTX_new(SSLv23_client_method());
104
- /* Disable SSLv2 */
105
- SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv2);
104
+ /* Disable SSLv2 and SSLv3 */
105
+ SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
106106
107107
/* Set up acceptable CA root certificates */
108108
zCaSetting = db_get("ssl-ca-location", 0);
109109
if( zCaSetting==0 || zCaSetting[0]=='\0' ){
110110
/* CA location not specified, use platform's default certificate store */
@@ -171,10 +171,11 @@
171171
*/
172172
void ssl_close(void){
173173
if( iBio!=NULL ){
174174
(void)BIO_reset(iBio);
175175
BIO_free_all(iBio);
176
+ iBio = NULL;
176177
}
177178
}
178179
179180
/* See RFC2817 for details */
180181
static int establish_proxy_tunnel(UrlData *pUrlData, BIO *bio){
181182
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -41,11 +41,11 @@
41 ** There can only be a single OpenSSL IO connection open at a time.
42 ** State information about that IO is stored in the following
43 ** local variables:
44 */
45 static int sslIsInit = 0; /* True after global initialization */
46 static BIO *iBio; /* OpenSSL I/O abstraction */
47 static char *sslErrMsg = 0; /* Text of most recent OpenSSL error */
48 static SSL_CTX *sslCtx; /* SSL context */
49 static SSL *ssl;
50
51
@@ -99,12 +99,12 @@
99 SSL_library_init();
100 SSL_load_error_strings();
101 ERR_load_BIO_strings();
102 OpenSSL_add_all_algorithms();
103 sslCtx = SSL_CTX_new(SSLv23_client_method());
104 /* Disable SSLv2 */
105 SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv2);
106
107 /* Set up acceptable CA root certificates */
108 zCaSetting = db_get("ssl-ca-location", 0);
109 if( zCaSetting==0 || zCaSetting[0]=='\0' ){
110 /* CA location not specified, use platform's default certificate store */
@@ -171,10 +171,11 @@
171 */
172 void ssl_close(void){
173 if( iBio!=NULL ){
174 (void)BIO_reset(iBio);
175 BIO_free_all(iBio);
 
176 }
177 }
178
179 /* See RFC2817 for details */
180 static int establish_proxy_tunnel(UrlData *pUrlData, BIO *bio){
181
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -41,11 +41,11 @@
41 ** There can only be a single OpenSSL IO connection open at a time.
42 ** State information about that IO is stored in the following
43 ** local variables:
44 */
45 static int sslIsInit = 0; /* True after global initialization */
46 static BIO *iBio = 0; /* OpenSSL I/O abstraction */
47 static char *sslErrMsg = 0; /* Text of most recent OpenSSL error */
48 static SSL_CTX *sslCtx; /* SSL context */
49 static SSL *ssl;
50
51
@@ -99,12 +99,12 @@
99 SSL_library_init();
100 SSL_load_error_strings();
101 ERR_load_BIO_strings();
102 OpenSSL_add_all_algorithms();
103 sslCtx = SSL_CTX_new(SSLv23_client_method());
104 /* Disable SSLv2 and SSLv3 */
105 SSL_CTX_set_options(sslCtx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
106
107 /* Set up acceptable CA root certificates */
108 zCaSetting = db_get("ssl-ca-location", 0);
109 if( zCaSetting==0 || zCaSetting[0]=='\0' ){
110 /* CA location not specified, use platform's default certificate store */
@@ -171,10 +171,11 @@
171 */
172 void ssl_close(void){
173 if( iBio!=NULL ){
174 (void)BIO_reset(iBio);
175 BIO_free_all(iBio);
176 iBio = NULL;
177 }
178 }
179
180 /* See RFC2817 for details */
181 static int establish_proxy_tunnel(UrlData *pUrlData, BIO *bio){
182
+7 -2
--- src/info.c
+++ src/info.c
@@ -931,10 +931,11 @@
931931
}else{
932932
@ tags: %h(zTagList),
933933
}
934934
@ date:
935935
hyperlink_to_date(zDate, ")");
936
+ tag_private_status(rid);
936937
}
937938
db_finalize(&q);
938939
}
939940
940941
@@ -1203,19 +1204,20 @@
12031204
}else{
12041205
@ <li>File
12051206
}
12061207
objType |= OBJTYPE_CONTENT;
12071208
@ %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
1209
+ tag_private_status(rid);
12081210
if( showDetail ){
12091211
@ <ul>
12101212
}
12111213
prevName = fossil_strdup(zName);
12121214
}
12131215
if( showDetail ){
12141216
@ <li>
12151217
hyperlink_to_date(zDate,"");
1216
- @ &mdash; part of check-in
1218
+ @ &mdash; part of checkin
12171219
hyperlink_to_uuid(zVers);
12181220
}else{
12191221
@ &mdash; part of checkin
12201222
hyperlink_to_uuid(zVers);
12211223
@ at
@@ -1314,10 +1316,11 @@
13141316
hyperlink_to_user(zUser,zDate," on");
13151317
hyperlink_to_date(zDate, ".");
13161318
if( pDownloadName && blob_size(pDownloadName)==0 ){
13171319
blob_appendf(pDownloadName, "%.10s.txt", zUuid);
13181320
}
1321
+ tag_private_status(rid);
13191322
cnt++;
13201323
}
13211324
db_finalize(&q);
13221325
}
13231326
db_prepare(&q,
@@ -1357,17 +1360,19 @@
13571360
hyperlink_to_date(zDate,".");
13581361
cnt++;
13591362
if( pDownloadName && blob_size(pDownloadName)==0 ){
13601363
blob_append(pDownloadName, zFilename, -1);
13611364
}
1365
+ tag_private_status(rid);
13621366
}
13631367
db_finalize(&q);
13641368
if( cnt==0 ){
13651369
@ Control artifact.
13661370
if( pDownloadName && blob_size(pDownloadName)==0 ){
13671371
blob_appendf(pDownloadName, "%.10s.txt", zUuid);
13681372
}
1373
+ tag_private_status(rid);
13691374
}
13701375
return objType;
13711376
}
13721377
13731378
@@ -1914,11 +1919,11 @@
19141919
}
19151920
if( strcmp(zModAction,"approve")==0 ){
19161921
moderation_approve(rid);
19171922
}
19181923
}
1919
- zTktTitle = db_table_has_column( "ticket", "title" )
1924
+ zTktTitle = db_table_has_column("repository", "ticket", "title" )
19201925
? db_text("(No title)", "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
19211926
: 0;
19221927
style_header("Ticket Change Details");
19231928
style_submenu_element("Raw", "Raw", "%R/artifact/%s", zUuid);
19241929
style_submenu_element("History", "History", "%R/tkthistory/%s", zTktName);
19251930
--- src/info.c
+++ src/info.c
@@ -931,10 +931,11 @@
931 }else{
932 @ tags: %h(zTagList),
933 }
934 @ date:
935 hyperlink_to_date(zDate, ")");
 
936 }
937 db_finalize(&q);
938 }
939
940
@@ -1203,19 +1204,20 @@
1203 }else{
1204 @ <li>File
1205 }
1206 objType |= OBJTYPE_CONTENT;
1207 @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
 
1208 if( showDetail ){
1209 @ <ul>
1210 }
1211 prevName = fossil_strdup(zName);
1212 }
1213 if( showDetail ){
1214 @ <li>
1215 hyperlink_to_date(zDate,"");
1216 @ &mdash; part of check-in
1217 hyperlink_to_uuid(zVers);
1218 }else{
1219 @ &mdash; part of checkin
1220 hyperlink_to_uuid(zVers);
1221 @ at
@@ -1314,10 +1316,11 @@
1314 hyperlink_to_user(zUser,zDate," on");
1315 hyperlink_to_date(zDate, ".");
1316 if( pDownloadName && blob_size(pDownloadName)==0 ){
1317 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
1318 }
 
1319 cnt++;
1320 }
1321 db_finalize(&q);
1322 }
1323 db_prepare(&q,
@@ -1357,17 +1360,19 @@
1357 hyperlink_to_date(zDate,".");
1358 cnt++;
1359 if( pDownloadName && blob_size(pDownloadName)==0 ){
1360 blob_append(pDownloadName, zFilename, -1);
1361 }
 
1362 }
1363 db_finalize(&q);
1364 if( cnt==0 ){
1365 @ Control artifact.
1366 if( pDownloadName && blob_size(pDownloadName)==0 ){
1367 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
1368 }
 
1369 }
1370 return objType;
1371 }
1372
1373
@@ -1914,11 +1919,11 @@
1914 }
1915 if( strcmp(zModAction,"approve")==0 ){
1916 moderation_approve(rid);
1917 }
1918 }
1919 zTktTitle = db_table_has_column( "ticket", "title" )
1920 ? db_text("(No title)", "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
1921 : 0;
1922 style_header("Ticket Change Details");
1923 style_submenu_element("Raw", "Raw", "%R/artifact/%s", zUuid);
1924 style_submenu_element("History", "History", "%R/tkthistory/%s", zTktName);
1925
--- src/info.c
+++ src/info.c
@@ -931,10 +931,11 @@
931 }else{
932 @ tags: %h(zTagList),
933 }
934 @ date:
935 hyperlink_to_date(zDate, ")");
936 tag_private_status(rid);
937 }
938 db_finalize(&q);
939 }
940
941
@@ -1203,19 +1204,20 @@
1204 }else{
1205 @ <li>File
1206 }
1207 objType |= OBJTYPE_CONTENT;
1208 @ %z(href("%R/finfo?name=%T",zName))%h(zName)</a>
1209 tag_private_status(rid);
1210 if( showDetail ){
1211 @ <ul>
1212 }
1213 prevName = fossil_strdup(zName);
1214 }
1215 if( showDetail ){
1216 @ <li>
1217 hyperlink_to_date(zDate,"");
1218 @ &mdash; part of checkin
1219 hyperlink_to_uuid(zVers);
1220 }else{
1221 @ &mdash; part of checkin
1222 hyperlink_to_uuid(zVers);
1223 @ at
@@ -1314,10 +1316,11 @@
1316 hyperlink_to_user(zUser,zDate," on");
1317 hyperlink_to_date(zDate, ".");
1318 if( pDownloadName && blob_size(pDownloadName)==0 ){
1319 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
1320 }
1321 tag_private_status(rid);
1322 cnt++;
1323 }
1324 db_finalize(&q);
1325 }
1326 db_prepare(&q,
@@ -1357,17 +1360,19 @@
1360 hyperlink_to_date(zDate,".");
1361 cnt++;
1362 if( pDownloadName && blob_size(pDownloadName)==0 ){
1363 blob_append(pDownloadName, zFilename, -1);
1364 }
1365 tag_private_status(rid);
1366 }
1367 db_finalize(&q);
1368 if( cnt==0 ){
1369 @ Control artifact.
1370 if( pDownloadName && blob_size(pDownloadName)==0 ){
1371 blob_appendf(pDownloadName, "%.10s.txt", zUuid);
1372 }
1373 tag_private_status(rid);
1374 }
1375 return objType;
1376 }
1377
1378
@@ -1914,11 +1919,11 @@
1919 }
1920 if( strcmp(zModAction,"approve")==0 ){
1921 moderation_approve(rid);
1922 }
1923 }
1924 zTktTitle = db_table_has_column("repository", "ticket", "title" )
1925 ? db_text("(No title)", "SELECT title FROM ticket WHERE tkt_uuid=%Q", zTktName)
1926 : 0;
1927 style_header("Ticket Change Details");
1928 style_submenu_element("Raw", "Raw", "%R/artifact/%s", zUuid);
1929 style_submenu_element("History", "History", "%R/tkthistory/%s", zTktName);
1930
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -88,20 +88,21 @@
8888
db_multi_exec("%s", zSql /*safe-for-%s*/);
8989
}
9090
9191
/*
9292
** Return a pointer to a constant string that forms the basis
93
-** for a timeline query for the JSON interface.
93
+** for a timeline query for the JSON interface. It MUST NOT
94
+** be used in a formatted string argument.
9495
*/
9596
char const * json_timeline_query(void){
9697
/* Field order MUST match that from json_timeline_temp_table()!!! */
9798
static const char zBaseSql[] =
9899
@ SELECT
99100
@ NULL,
100101
@ blob.rid,
101102
@ uuid,
102
- @ CAST(strftime('%%s',event.mtime) AS INTEGER),
103
+ @ CAST(strftime('%s',event.mtime) AS INTEGER),
103104
@ datetime(event.mtime),
104105
@ coalesce(ecomment, comment),
105106
@ coalesce(euser, user),
106107
@ blob.rid IN leaf,
107108
@ bgcolor,
@@ -544,12 +545,11 @@
544545
goto error;
545546
}
546547
547548
#if 0
548549
/* only for testing! */
549
- tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql)));
550
- SET("timelineSql");
550
+ cson_object_set(pay, "timelineSql", cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))));
551551
#endif
552552
db_multi_exec("%s", blob_buffer(&sql) /*safe-for-%s*/);
553553
blob_reset(&sql);
554554
db_prepare(&q, "SELECT"
555555
" uuid AS uuid,"
556556
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -88,20 +88,21 @@
88 db_multi_exec("%s", zSql /*safe-for-%s*/);
89 }
90
91 /*
92 ** Return a pointer to a constant string that forms the basis
93 ** for a timeline query for the JSON interface.
 
94 */
95 char const * json_timeline_query(void){
96 /* Field order MUST match that from json_timeline_temp_table()!!! */
97 static const char zBaseSql[] =
98 @ SELECT
99 @ NULL,
100 @ blob.rid,
101 @ uuid,
102 @ CAST(strftime('%%s',event.mtime) AS INTEGER),
103 @ datetime(event.mtime),
104 @ coalesce(ecomment, comment),
105 @ coalesce(euser, user),
106 @ blob.rid IN leaf,
107 @ bgcolor,
@@ -544,12 +545,11 @@
544 goto error;
545 }
546
547 #if 0
548 /* only for testing! */
549 tmp = cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql)));
550 SET("timelineSql");
551 #endif
552 db_multi_exec("%s", blob_buffer(&sql) /*safe-for-%s*/);
553 blob_reset(&sql);
554 db_prepare(&q, "SELECT"
555 " uuid AS uuid,"
556
--- src/json_timeline.c
+++ src/json_timeline.c
@@ -88,20 +88,21 @@
88 db_multi_exec("%s", zSql /*safe-for-%s*/);
89 }
90
91 /*
92 ** Return a pointer to a constant string that forms the basis
93 ** for a timeline query for the JSON interface. It MUST NOT
94 ** be used in a formatted string argument.
95 */
96 char const * json_timeline_query(void){
97 /* Field order MUST match that from json_timeline_temp_table()!!! */
98 static const char zBaseSql[] =
99 @ SELECT
100 @ NULL,
101 @ blob.rid,
102 @ uuid,
103 @ CAST(strftime('%s',event.mtime) AS INTEGER),
104 @ datetime(event.mtime),
105 @ coalesce(ecomment, comment),
106 @ coalesce(euser, user),
107 @ blob.rid IN leaf,
108 @ bgcolor,
@@ -544,12 +545,11 @@
545 goto error;
546 }
547
548 #if 0
549 /* only for testing! */
550 cson_object_set(pay, "timelineSql", cson_value_new_string(blob_buffer(&sql),strlen(blob_buffer(&sql))));
 
551 #endif
552 db_multi_exec("%s", blob_buffer(&sql) /*safe-for-%s*/);
553 blob_reset(&sql);
554 db_prepare(&q, "SELECT"
555 " uuid AS uuid,"
556
+26 -1
--- src/login.c
+++ src/login.c
@@ -475,10 +475,20 @@
475475
char *zSha1Pw;
476476
const char *zIpAddr; /* IP address of requestor */
477477
const char *zReferer;
478478
479479
login_check_credentials();
480
+ if( login_wants_https_redirect() ){
481
+ const char *zQS = P("QUERY_STRING");
482
+ if( zQS==0 ){
483
+ zQS = "";
484
+ }else if( zQS[0]!=0 ){
485
+ zQS = mprintf("?%s", zQS);
486
+ }
487
+ cgi_redirectf("%s%s%s", g.zHttpsURL, P("PATH_INFO"), zQS);
488
+ return;
489
+ }
480490
sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
481491
constant_time_cmp_function, 0, 0);
482492
zUsername = P("u");
483493
zPasswd = P("p");
484494
anonFlag = P("anon")!=0;
@@ -776,10 +786,25 @@
776786
" AND constant_time_cmp(cookie,%Q)=0",
777787
zLogin, zRemoteAddr, zCookie
778788
);
779789
return uid;
780790
}
791
+
792
+/*
793
+** Return true if it is appropriate to redirect login requests to HTTPS.
794
+**
795
+** Redirect to https is appropriate if all of the above are true:
796
+** (1) The redirect-to-https flag is set
797
+** (2) The current connection is http, not https or ssh
798
+** (3) The sslNotAvailable flag is clear
799
+*/
800
+int login_wants_https_redirect(void){
801
+ if( g.sslNotAvailable ) return 0;
802
+ if( db_get_boolean("redirect-to-https",0)==0 ) return 0;
803
+ if( P("HTTPS")!=0 ) return 0;
804
+ return 1;
805
+}
781806
782807
/*
783808
** This routine examines the login cookie to see if it exists and
784809
** is valid. If the login cookie checks out, it then sets global
785810
** variables appropriately.
@@ -812,11 +837,11 @@
812837
** This feature allows the "fossil ui" command to give the user
813838
** full access rights without having to log in.
814839
*/
815840
zRemoteAddr = ipPrefix(zIpAddr = PD("REMOTE_ADDR","nil"));
816841
if( ( fossil_strcmp(zIpAddr, "127.0.0.1")==0 ||
817
- g.fSshClient & CGI_SSH_CLIENT )
842
+ (g.fSshClient & CGI_SSH_CLIENT)!=0 )
818843
&& g.useLocalauth
819844
&& db_get_int("localauth",0)==0
820845
&& P("HTTPS")==0
821846
){
822847
if( g.localOpen ) zLogin = db_lget("default-user",0);
823848
--- src/login.c
+++ src/login.c
@@ -475,10 +475,20 @@
475 char *zSha1Pw;
476 const char *zIpAddr; /* IP address of requestor */
477 const char *zReferer;
478
479 login_check_credentials();
 
 
 
 
 
 
 
 
 
 
480 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
481 constant_time_cmp_function, 0, 0);
482 zUsername = P("u");
483 zPasswd = P("p");
484 anonFlag = P("anon")!=0;
@@ -776,10 +786,25 @@
776 " AND constant_time_cmp(cookie,%Q)=0",
777 zLogin, zRemoteAddr, zCookie
778 );
779 return uid;
780 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
781
782 /*
783 ** This routine examines the login cookie to see if it exists and
784 ** is valid. If the login cookie checks out, it then sets global
785 ** variables appropriately.
@@ -812,11 +837,11 @@
812 ** This feature allows the "fossil ui" command to give the user
813 ** full access rights without having to log in.
814 */
815 zRemoteAddr = ipPrefix(zIpAddr = PD("REMOTE_ADDR","nil"));
816 if( ( fossil_strcmp(zIpAddr, "127.0.0.1")==0 ||
817 g.fSshClient & CGI_SSH_CLIENT )
818 && g.useLocalauth
819 && db_get_int("localauth",0)==0
820 && P("HTTPS")==0
821 ){
822 if( g.localOpen ) zLogin = db_lget("default-user",0);
823
--- src/login.c
+++ src/login.c
@@ -475,10 +475,20 @@
475 char *zSha1Pw;
476 const char *zIpAddr; /* IP address of requestor */
477 const char *zReferer;
478
479 login_check_credentials();
480 if( login_wants_https_redirect() ){
481 const char *zQS = P("QUERY_STRING");
482 if( zQS==0 ){
483 zQS = "";
484 }else if( zQS[0]!=0 ){
485 zQS = mprintf("?%s", zQS);
486 }
487 cgi_redirectf("%s%s%s", g.zHttpsURL, P("PATH_INFO"), zQS);
488 return;
489 }
490 sqlite3_create_function(g.db, "constant_time_cmp", 2, SQLITE_UTF8, 0,
491 constant_time_cmp_function, 0, 0);
492 zUsername = P("u");
493 zPasswd = P("p");
494 anonFlag = P("anon")!=0;
@@ -776,10 +786,25 @@
786 " AND constant_time_cmp(cookie,%Q)=0",
787 zLogin, zRemoteAddr, zCookie
788 );
789 return uid;
790 }
791
792 /*
793 ** Return true if it is appropriate to redirect login requests to HTTPS.
794 **
795 ** Redirect to https is appropriate if all of the above are true:
796 ** (1) The redirect-to-https flag is set
797 ** (2) The current connection is http, not https or ssh
798 ** (3) The sslNotAvailable flag is clear
799 */
800 int login_wants_https_redirect(void){
801 if( g.sslNotAvailable ) return 0;
802 if( db_get_boolean("redirect-to-https",0)==0 ) return 0;
803 if( P("HTTPS")!=0 ) return 0;
804 return 1;
805 }
806
807 /*
808 ** This routine examines the login cookie to see if it exists and
809 ** is valid. If the login cookie checks out, it then sets global
810 ** variables appropriately.
@@ -812,11 +837,11 @@
837 ** This feature allows the "fossil ui" command to give the user
838 ** full access rights without having to log in.
839 */
840 zRemoteAddr = ipPrefix(zIpAddr = PD("REMOTE_ADDR","nil"));
841 if( ( fossil_strcmp(zIpAddr, "127.0.0.1")==0 ||
842 (g.fSshClient & CGI_SSH_CLIENT)!=0 )
843 && g.useLocalauth
844 && db_get_int("localauth",0)==0
845 && P("HTTPS")==0
846 ){
847 if( g.localOpen ) zLogin = db_lget("default-user",0);
848
+6 -1
--- src/main.c
+++ src/main.c
@@ -125,16 +125,18 @@
125125
const char *zErrlog; /* Log errors to this file, if not NULL */
126126
int isConst; /* True if the output is unchanging & cacheable */
127127
const char *zVfsName; /* The VFS to use for database connections */
128128
sqlite3 *db; /* The connection to the databases */
129129
sqlite3 *dbConfig; /* Separate connection for global_config table */
130
+ char *zAuxSchema; /* Main repository aux-schema */
130131
int useAttach; /* True if global_config is attached to repository */
131132
const char *zConfigDbName;/* Path of the config database. NULL if not open */
132133
sqlite3_int64 now; /* Seconds since 1970 */
133134
int repositoryOpen; /* True if the main repository database is open */
134135
char *zRepositoryOption; /* Most recent cached repository option value */
135136
char *zRepositoryName; /* Name of the repository database */
137
+ char *zLocalDbName; /* Name of the local database */
136138
const char *zMainDbType;/* "configdb", "localdb", or "repository" */
137139
const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
138140
int localOpen; /* True if the local database is open */
139141
char *zLocalRoot; /* The directory holding the local database */
140142
int minPrefix; /* Number of digits needed for a distinct UUID */
@@ -150,10 +152,11 @@
150152
char *zSshCmd; /* SSH command string */
151153
int fNoSync; /* Do not do an autosync ever. --nosync */
152154
char *zPath; /* Name of webpage being served */
153155
char *zExtra; /* Extra path information past the webpage name */
154156
char *zBaseURL; /* Full text of the URL being served */
157
+ char *zHttpsURL; /* zBaseURL translated to https: */
155158
char *zTop; /* Parent directory of zPath */
156159
const char *zContentType; /* The content type of the input HTTP request */
157160
int iErrPriority; /* Priority of current error message */
158161
char *zErrMsg; /* Text of an error message */
159162
int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -968,11 +971,11 @@
968971
const char *zRc;
969972
#endif
970973
fossil_print("Compiled on %s %s using %s (%d-bit)\n",
971974
__DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
972975
fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
973
- fossil_print("Schema version %s\n", AUX_SCHEMA);
976
+ fossil_print("Schema version %s\n", AUX_SCHEMA_MAX);
974977
#if defined(FOSSIL_ENABLE_MINIZ)
975978
fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
976979
#else
977980
fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
978981
#endif
@@ -1289,13 +1292,15 @@
12891292
i = strlen(zCur);
12901293
while( i>0 && zCur[i-1]=='/' ) i--;
12911294
if( fossil_stricmp(zMode,"on")==0 ){
12921295
g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
12931296
g.zTop = &g.zBaseURL[8+strlen(zHost)];
1297
+ g.zHttpsURL = g.zBaseURL;
12941298
}else{
12951299
g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
12961300
g.zTop = &g.zBaseURL[7+strlen(zHost)];
1301
+ g.zHttpsURL = mprintf("https://%s%.*s", zHost, i, zCur);
12971302
}
12981303
}
12991304
if( db_is_writeable("repository") ){
13001305
if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL)){
13011306
db_multi_exec("INSERT INTO config(name,value,mtime)"
13021307
--- src/main.c
+++ src/main.c
@@ -125,16 +125,18 @@
125 const char *zErrlog; /* Log errors to this file, if not NULL */
126 int isConst; /* True if the output is unchanging & cacheable */
127 const char *zVfsName; /* The VFS to use for database connections */
128 sqlite3 *db; /* The connection to the databases */
129 sqlite3 *dbConfig; /* Separate connection for global_config table */
 
130 int useAttach; /* True if global_config is attached to repository */
131 const char *zConfigDbName;/* Path of the config database. NULL if not open */
132 sqlite3_int64 now; /* Seconds since 1970 */
133 int repositoryOpen; /* True if the main repository database is open */
134 char *zRepositoryOption; /* Most recent cached repository option value */
135 char *zRepositoryName; /* Name of the repository database */
 
136 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
137 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
138 int localOpen; /* True if the local database is open */
139 char *zLocalRoot; /* The directory holding the local database */
140 int minPrefix; /* Number of digits needed for a distinct UUID */
@@ -150,10 +152,11 @@
150 char *zSshCmd; /* SSH command string */
151 int fNoSync; /* Do not do an autosync ever. --nosync */
152 char *zPath; /* Name of webpage being served */
153 char *zExtra; /* Extra path information past the webpage name */
154 char *zBaseURL; /* Full text of the URL being served */
 
155 char *zTop; /* Parent directory of zPath */
156 const char *zContentType; /* The content type of the input HTTP request */
157 int iErrPriority; /* Priority of current error message */
158 char *zErrMsg; /* Text of an error message */
159 int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -968,11 +971,11 @@
968 const char *zRc;
969 #endif
970 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
971 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
972 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
973 fossil_print("Schema version %s\n", AUX_SCHEMA);
974 #if defined(FOSSIL_ENABLE_MINIZ)
975 fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
976 #else
977 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
978 #endif
@@ -1289,13 +1292,15 @@
1289 i = strlen(zCur);
1290 while( i>0 && zCur[i-1]=='/' ) i--;
1291 if( fossil_stricmp(zMode,"on")==0 ){
1292 g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
1293 g.zTop = &g.zBaseURL[8+strlen(zHost)];
 
1294 }else{
1295 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1296 g.zTop = &g.zBaseURL[7+strlen(zHost)];
 
1297 }
1298 }
1299 if( db_is_writeable("repository") ){
1300 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL)){
1301 db_multi_exec("INSERT INTO config(name,value,mtime)"
1302
--- src/main.c
+++ src/main.c
@@ -125,16 +125,18 @@
125 const char *zErrlog; /* Log errors to this file, if not NULL */
126 int isConst; /* True if the output is unchanging & cacheable */
127 const char *zVfsName; /* The VFS to use for database connections */
128 sqlite3 *db; /* The connection to the databases */
129 sqlite3 *dbConfig; /* Separate connection for global_config table */
130 char *zAuxSchema; /* Main repository aux-schema */
131 int useAttach; /* True if global_config is attached to repository */
132 const char *zConfigDbName;/* Path of the config database. NULL if not open */
133 sqlite3_int64 now; /* Seconds since 1970 */
134 int repositoryOpen; /* True if the main repository database is open */
135 char *zRepositoryOption; /* Most recent cached repository option value */
136 char *zRepositoryName; /* Name of the repository database */
137 char *zLocalDbName; /* Name of the local database */
138 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
139 const char *zConfigDbType; /* "configdb", "localdb", or "repository" */
140 int localOpen; /* True if the local database is open */
141 char *zLocalRoot; /* The directory holding the local database */
142 int minPrefix; /* Number of digits needed for a distinct UUID */
@@ -150,10 +152,11 @@
152 char *zSshCmd; /* SSH command string */
153 int fNoSync; /* Do not do an autosync ever. --nosync */
154 char *zPath; /* Name of webpage being served */
155 char *zExtra; /* Extra path information past the webpage name */
156 char *zBaseURL; /* Full text of the URL being served */
157 char *zHttpsURL; /* zBaseURL translated to https: */
158 char *zTop; /* Parent directory of zPath */
159 const char *zContentType; /* The content type of the input HTTP request */
160 int iErrPriority; /* Priority of current error message */
161 char *zErrMsg; /* Text of an error message */
162 int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -968,11 +971,11 @@
971 const char *zRc;
972 #endif
973 fossil_print("Compiled on %s %s using %s (%d-bit)\n",
974 __DATE__, __TIME__, COMPILER_NAME, sizeof(void*)*8);
975 fossil_print("SQLite %s %.30s\n", sqlite3_libversion(), sqlite3_sourceid());
976 fossil_print("Schema version %s\n", AUX_SCHEMA_MAX);
977 #if defined(FOSSIL_ENABLE_MINIZ)
978 fossil_print("miniz %s, loaded %s\n", MZ_VERSION, mz_version());
979 #else
980 fossil_print("zlib %s, loaded %s\n", ZLIB_VERSION, zlibVersion());
981 #endif
@@ -1289,13 +1292,15 @@
1292 i = strlen(zCur);
1293 while( i>0 && zCur[i-1]=='/' ) i--;
1294 if( fossil_stricmp(zMode,"on")==0 ){
1295 g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
1296 g.zTop = &g.zBaseURL[8+strlen(zHost)];
1297 g.zHttpsURL = g.zBaseURL;
1298 }else{
1299 g.zBaseURL = mprintf("http://%s%.*s", zHost, i, zCur);
1300 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1301 g.zHttpsURL = mprintf("https://%s%.*s", zHost, i, zCur);
1302 }
1303 }
1304 if( db_is_writeable("repository") ){
1305 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL)){
1306 db_multi_exec("INSERT INTO config(name,value,mtime)"
1307
+61 -1
--- src/main.mk
+++ src/main.mk
@@ -8,11 +8,11 @@
88
# to regenerate this file.
99
#
1010
# This file is included by primary Makefile.
1111
#
1212
13
-XTCC = $(TCC) $(CFLAGS) -I. -I$(SRCDIR) -I$(OBJDIR)
13
+XTCC = $(TCC) -I. -I$(SRCDIR) -I$(OBJDIR) $(TCCFLAGS) $(CFLAGS)
1414
1515
1616
SRC = \
1717
$(SRCDIR)/add.c \
1818
$(SRCDIR)/allrepo.c \
@@ -21,10 +21,11 @@
2121
$(SRCDIR)/bisect.c \
2222
$(SRCDIR)/blob.c \
2323
$(SRCDIR)/branch.c \
2424
$(SRCDIR)/browse.c \
2525
$(SRCDIR)/builtin.c \
26
+ $(SRCDIR)/bundle.c \
2627
$(SRCDIR)/cache.c \
2728
$(SRCDIR)/captcha.c \
2829
$(SRCDIR)/cgi.c \
2930
$(SRCDIR)/checkin.c \
3031
$(SRCDIR)/checkout.c \
@@ -43,10 +44,11 @@
4344
$(SRCDIR)/encode.c \
4445
$(SRCDIR)/event.c \
4546
$(SRCDIR)/export.c \
4647
$(SRCDIR)/file.c \
4748
$(SRCDIR)/finfo.c \
49
+ $(SRCDIR)/foci.c \
4850
$(SRCDIR)/fusefs.c \
4951
$(SRCDIR)/glob.c \
5052
$(SRCDIR)/graph.c \
5153
$(SRCDIR)/gzip.c \
5254
$(SRCDIR)/http.c \
@@ -86,19 +88,22 @@
8688
$(SRCDIR)/path.c \
8789
$(SRCDIR)/pivot.c \
8890
$(SRCDIR)/popen.c \
8991
$(SRCDIR)/pqueue.c \
9092
$(SRCDIR)/printf.c \
93
+ $(SRCDIR)/publish.c \
94
+ $(SRCDIR)/purge.c \
9195
$(SRCDIR)/rebuild.c \
9296
$(SRCDIR)/regexp.c \
9397
$(SRCDIR)/report.c \
9498
$(SRCDIR)/rss.c \
9599
$(SRCDIR)/schema.c \
96100
$(SRCDIR)/search.c \
97101
$(SRCDIR)/setup.c \
98102
$(SRCDIR)/sha1.c \
99103
$(SRCDIR)/shun.c \
104
+ $(SRCDIR)/sitemap.c \
100105
$(SRCDIR)/skins.c \
101106
$(SRCDIR)/sqlcmd.c \
102107
$(SRCDIR)/stash.c \
103108
$(SRCDIR)/stat.c \
104109
$(SRCDIR)/style.c \
@@ -138,10 +143,11 @@
138143
$(OBJDIR)/bisect_.c \
139144
$(OBJDIR)/blob_.c \
140145
$(OBJDIR)/branch_.c \
141146
$(OBJDIR)/browse_.c \
142147
$(OBJDIR)/builtin_.c \
148
+ $(OBJDIR)/bundle_.c \
143149
$(OBJDIR)/cache_.c \
144150
$(OBJDIR)/captcha_.c \
145151
$(OBJDIR)/cgi_.c \
146152
$(OBJDIR)/checkin_.c \
147153
$(OBJDIR)/checkout_.c \
@@ -160,10 +166,11 @@
160166
$(OBJDIR)/encode_.c \
161167
$(OBJDIR)/event_.c \
162168
$(OBJDIR)/export_.c \
163169
$(OBJDIR)/file_.c \
164170
$(OBJDIR)/finfo_.c \
171
+ $(OBJDIR)/foci_.c \
165172
$(OBJDIR)/fusefs_.c \
166173
$(OBJDIR)/glob_.c \
167174
$(OBJDIR)/graph_.c \
168175
$(OBJDIR)/gzip_.c \
169176
$(OBJDIR)/http_.c \
@@ -203,19 +210,22 @@
203210
$(OBJDIR)/path_.c \
204211
$(OBJDIR)/pivot_.c \
205212
$(OBJDIR)/popen_.c \
206213
$(OBJDIR)/pqueue_.c \
207214
$(OBJDIR)/printf_.c \
215
+ $(OBJDIR)/publish_.c \
216
+ $(OBJDIR)/purge_.c \
208217
$(OBJDIR)/rebuild_.c \
209218
$(OBJDIR)/regexp_.c \
210219
$(OBJDIR)/report_.c \
211220
$(OBJDIR)/rss_.c \
212221
$(OBJDIR)/schema_.c \
213222
$(OBJDIR)/search_.c \
214223
$(OBJDIR)/setup_.c \
215224
$(OBJDIR)/sha1_.c \
216225
$(OBJDIR)/shun_.c \
226
+ $(OBJDIR)/sitemap_.c \
217227
$(OBJDIR)/skins_.c \
218228
$(OBJDIR)/sqlcmd_.c \
219229
$(OBJDIR)/stash_.c \
220230
$(OBJDIR)/stat_.c \
221231
$(OBJDIR)/style_.c \
@@ -252,10 +262,11 @@
252262
$(OBJDIR)/bisect.o \
253263
$(OBJDIR)/blob.o \
254264
$(OBJDIR)/branch.o \
255265
$(OBJDIR)/browse.o \
256266
$(OBJDIR)/builtin.o \
267
+ $(OBJDIR)/bundle.o \
257268
$(OBJDIR)/cache.o \
258269
$(OBJDIR)/captcha.o \
259270
$(OBJDIR)/cgi.o \
260271
$(OBJDIR)/checkin.o \
261272
$(OBJDIR)/checkout.o \
@@ -274,10 +285,11 @@
274285
$(OBJDIR)/encode.o \
275286
$(OBJDIR)/event.o \
276287
$(OBJDIR)/export.o \
277288
$(OBJDIR)/file.o \
278289
$(OBJDIR)/finfo.o \
290
+ $(OBJDIR)/foci.o \
279291
$(OBJDIR)/fusefs.o \
280292
$(OBJDIR)/glob.o \
281293
$(OBJDIR)/graph.o \
282294
$(OBJDIR)/gzip.o \
283295
$(OBJDIR)/http.o \
@@ -317,19 +329,22 @@
317329
$(OBJDIR)/path.o \
318330
$(OBJDIR)/pivot.o \
319331
$(OBJDIR)/popen.o \
320332
$(OBJDIR)/pqueue.o \
321333
$(OBJDIR)/printf.o \
334
+ $(OBJDIR)/publish.o \
335
+ $(OBJDIR)/purge.o \
322336
$(OBJDIR)/rebuild.o \
323337
$(OBJDIR)/regexp.o \
324338
$(OBJDIR)/report.o \
325339
$(OBJDIR)/rss.o \
326340
$(OBJDIR)/schema.o \
327341
$(OBJDIR)/search.o \
328342
$(OBJDIR)/setup.o \
329343
$(OBJDIR)/sha1.o \
330344
$(OBJDIR)/shun.o \
345
+ $(OBJDIR)/sitemap.o \
331346
$(OBJDIR)/skins.o \
332347
$(OBJDIR)/sqlcmd.o \
333348
$(OBJDIR)/stash.o \
334349
$(OBJDIR)/stat.o \
335350
$(OBJDIR)/style.o \
@@ -475,10 +490,11 @@
475490
$(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
476491
$(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
477492
$(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
478493
$(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
479494
$(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
495
+ $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
480496
$(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
481497
$(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
482498
$(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
483499
$(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
484500
$(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -497,10 +513,11 @@
497513
$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
498514
$(OBJDIR)/event_.c:$(OBJDIR)/event.h \
499515
$(OBJDIR)/export_.c:$(OBJDIR)/export.h \
500516
$(OBJDIR)/file_.c:$(OBJDIR)/file.h \
501517
$(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
518
+ $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
502519
$(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
503520
$(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
504521
$(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
505522
$(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
506523
$(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -540,19 +557,22 @@
540557
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
541558
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
542559
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
543560
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
544561
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
562
+ $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
563
+ $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
545564
$(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
546565
$(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
547566
$(OBJDIR)/report_.c:$(OBJDIR)/report.h \
548567
$(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
549568
$(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
550569
$(OBJDIR)/search_.c:$(OBJDIR)/search.h \
551570
$(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
552571
$(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
553572
$(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
573
+ $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
554574
$(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
555575
$(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
556576
$(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
557577
$(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
558578
$(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -656,10 +676,18 @@
656676
657677
$(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
658678
$(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
659679
660680
$(OBJDIR)/builtin.h: $(OBJDIR)/headers
681
+
682
+$(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(OBJDIR)/translate
683
+ $(OBJDIR)/translate $(SRCDIR)/bundle.c >$@
684
+
685
+$(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
686
+ $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
687
+
688
+$(OBJDIR)/bundle.h: $(OBJDIR)/headers
661689
662690
$(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(OBJDIR)/translate
663691
$(OBJDIR)/translate $(SRCDIR)/cache.c >$@
664692
665693
$(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -832,10 +860,18 @@
832860
833861
$(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
834862
$(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
835863
836864
$(OBJDIR)/finfo.h: $(OBJDIR)/headers
865
+
866
+$(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(OBJDIR)/translate
867
+ $(OBJDIR)/translate $(SRCDIR)/foci.c >$@
868
+
869
+$(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
870
+ $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
871
+
872
+$(OBJDIR)/foci.h: $(OBJDIR)/headers
837873
838874
$(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(OBJDIR)/translate
839875
$(OBJDIR)/translate $(SRCDIR)/fusefs.c >$@
840876
841877
$(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1176,10 +1212,26 @@
11761212
11771213
$(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
11781214
$(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
11791215
11801216
$(OBJDIR)/printf.h: $(OBJDIR)/headers
1217
+
1218
+$(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(OBJDIR)/translate
1219
+ $(OBJDIR)/translate $(SRCDIR)/publish.c >$@
1220
+
1221
+$(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1222
+ $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1223
+
1224
+$(OBJDIR)/publish.h: $(OBJDIR)/headers
1225
+
1226
+$(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(OBJDIR)/translate
1227
+ $(OBJDIR)/translate $(SRCDIR)/purge.c >$@
1228
+
1229
+$(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1230
+ $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1231
+
1232
+$(OBJDIR)/purge.h: $(OBJDIR)/headers
11811233
11821234
$(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(OBJDIR)/translate
11831235
$(OBJDIR)/translate $(SRCDIR)/rebuild.c >$@
11841236
11851237
$(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1248,10 +1300,18 @@
12481300
12491301
$(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
12501302
$(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
12511303
12521304
$(OBJDIR)/shun.h: $(OBJDIR)/headers
1305
+
1306
+$(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(OBJDIR)/translate
1307
+ $(OBJDIR)/translate $(SRCDIR)/sitemap.c >$@
1308
+
1309
+$(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1310
+ $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1311
+
1312
+$(OBJDIR)/sitemap.h: $(OBJDIR)/headers
12531313
12541314
$(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(OBJDIR)/translate
12551315
$(OBJDIR)/translate $(SRCDIR)/skins.c >$@
12561316
12571317
$(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
12581318
--- src/main.mk
+++ src/main.mk
@@ -8,11 +8,11 @@
8 # to regenerate this file.
9 #
10 # This file is included by primary Makefile.
11 #
12
13 XTCC = $(TCC) $(CFLAGS) -I. -I$(SRCDIR) -I$(OBJDIR)
14
15
16 SRC = \
17 $(SRCDIR)/add.c \
18 $(SRCDIR)/allrepo.c \
@@ -21,10 +21,11 @@
21 $(SRCDIR)/bisect.c \
22 $(SRCDIR)/blob.c \
23 $(SRCDIR)/branch.c \
24 $(SRCDIR)/browse.c \
25 $(SRCDIR)/builtin.c \
 
26 $(SRCDIR)/cache.c \
27 $(SRCDIR)/captcha.c \
28 $(SRCDIR)/cgi.c \
29 $(SRCDIR)/checkin.c \
30 $(SRCDIR)/checkout.c \
@@ -43,10 +44,11 @@
43 $(SRCDIR)/encode.c \
44 $(SRCDIR)/event.c \
45 $(SRCDIR)/export.c \
46 $(SRCDIR)/file.c \
47 $(SRCDIR)/finfo.c \
 
48 $(SRCDIR)/fusefs.c \
49 $(SRCDIR)/glob.c \
50 $(SRCDIR)/graph.c \
51 $(SRCDIR)/gzip.c \
52 $(SRCDIR)/http.c \
@@ -86,19 +88,22 @@
86 $(SRCDIR)/path.c \
87 $(SRCDIR)/pivot.c \
88 $(SRCDIR)/popen.c \
89 $(SRCDIR)/pqueue.c \
90 $(SRCDIR)/printf.c \
 
 
91 $(SRCDIR)/rebuild.c \
92 $(SRCDIR)/regexp.c \
93 $(SRCDIR)/report.c \
94 $(SRCDIR)/rss.c \
95 $(SRCDIR)/schema.c \
96 $(SRCDIR)/search.c \
97 $(SRCDIR)/setup.c \
98 $(SRCDIR)/sha1.c \
99 $(SRCDIR)/shun.c \
 
100 $(SRCDIR)/skins.c \
101 $(SRCDIR)/sqlcmd.c \
102 $(SRCDIR)/stash.c \
103 $(SRCDIR)/stat.c \
104 $(SRCDIR)/style.c \
@@ -138,10 +143,11 @@
138 $(OBJDIR)/bisect_.c \
139 $(OBJDIR)/blob_.c \
140 $(OBJDIR)/branch_.c \
141 $(OBJDIR)/browse_.c \
142 $(OBJDIR)/builtin_.c \
 
143 $(OBJDIR)/cache_.c \
144 $(OBJDIR)/captcha_.c \
145 $(OBJDIR)/cgi_.c \
146 $(OBJDIR)/checkin_.c \
147 $(OBJDIR)/checkout_.c \
@@ -160,10 +166,11 @@
160 $(OBJDIR)/encode_.c \
161 $(OBJDIR)/event_.c \
162 $(OBJDIR)/export_.c \
163 $(OBJDIR)/file_.c \
164 $(OBJDIR)/finfo_.c \
 
165 $(OBJDIR)/fusefs_.c \
166 $(OBJDIR)/glob_.c \
167 $(OBJDIR)/graph_.c \
168 $(OBJDIR)/gzip_.c \
169 $(OBJDIR)/http_.c \
@@ -203,19 +210,22 @@
203 $(OBJDIR)/path_.c \
204 $(OBJDIR)/pivot_.c \
205 $(OBJDIR)/popen_.c \
206 $(OBJDIR)/pqueue_.c \
207 $(OBJDIR)/printf_.c \
 
 
208 $(OBJDIR)/rebuild_.c \
209 $(OBJDIR)/regexp_.c \
210 $(OBJDIR)/report_.c \
211 $(OBJDIR)/rss_.c \
212 $(OBJDIR)/schema_.c \
213 $(OBJDIR)/search_.c \
214 $(OBJDIR)/setup_.c \
215 $(OBJDIR)/sha1_.c \
216 $(OBJDIR)/shun_.c \
 
217 $(OBJDIR)/skins_.c \
218 $(OBJDIR)/sqlcmd_.c \
219 $(OBJDIR)/stash_.c \
220 $(OBJDIR)/stat_.c \
221 $(OBJDIR)/style_.c \
@@ -252,10 +262,11 @@
252 $(OBJDIR)/bisect.o \
253 $(OBJDIR)/blob.o \
254 $(OBJDIR)/branch.o \
255 $(OBJDIR)/browse.o \
256 $(OBJDIR)/builtin.o \
 
257 $(OBJDIR)/cache.o \
258 $(OBJDIR)/captcha.o \
259 $(OBJDIR)/cgi.o \
260 $(OBJDIR)/checkin.o \
261 $(OBJDIR)/checkout.o \
@@ -274,10 +285,11 @@
274 $(OBJDIR)/encode.o \
275 $(OBJDIR)/event.o \
276 $(OBJDIR)/export.o \
277 $(OBJDIR)/file.o \
278 $(OBJDIR)/finfo.o \
 
279 $(OBJDIR)/fusefs.o \
280 $(OBJDIR)/glob.o \
281 $(OBJDIR)/graph.o \
282 $(OBJDIR)/gzip.o \
283 $(OBJDIR)/http.o \
@@ -317,19 +329,22 @@
317 $(OBJDIR)/path.o \
318 $(OBJDIR)/pivot.o \
319 $(OBJDIR)/popen.o \
320 $(OBJDIR)/pqueue.o \
321 $(OBJDIR)/printf.o \
 
 
322 $(OBJDIR)/rebuild.o \
323 $(OBJDIR)/regexp.o \
324 $(OBJDIR)/report.o \
325 $(OBJDIR)/rss.o \
326 $(OBJDIR)/schema.o \
327 $(OBJDIR)/search.o \
328 $(OBJDIR)/setup.o \
329 $(OBJDIR)/sha1.o \
330 $(OBJDIR)/shun.o \
 
331 $(OBJDIR)/skins.o \
332 $(OBJDIR)/sqlcmd.o \
333 $(OBJDIR)/stash.o \
334 $(OBJDIR)/stat.o \
335 $(OBJDIR)/style.o \
@@ -475,10 +490,11 @@
475 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
476 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
477 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
478 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
479 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
 
480 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
481 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
482 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
483 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
484 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -497,10 +513,11 @@
497 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
498 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
499 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
500 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
501 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
 
502 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
503 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
504 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
505 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
506 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -540,19 +557,22 @@
540 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
541 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
542 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
543 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
544 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
 
 
545 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
546 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
547 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
548 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
549 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
550 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
551 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
552 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
553 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
 
554 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
555 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
556 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
557 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
558 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -656,10 +676,18 @@
656
657 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
658 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
659
660 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
661
662 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(OBJDIR)/translate
663 $(OBJDIR)/translate $(SRCDIR)/cache.c >$@
664
665 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -832,10 +860,18 @@
832
833 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
834 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
835
836 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
837
838 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(OBJDIR)/translate
839 $(OBJDIR)/translate $(SRCDIR)/fusefs.c >$@
840
841 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1176,10 +1212,26 @@
1176
1177 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1178 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1179
1180 $(OBJDIR)/printf.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1181
1182 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(OBJDIR)/translate
1183 $(OBJDIR)/translate $(SRCDIR)/rebuild.c >$@
1184
1185 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1248,10 +1300,18 @@
1248
1249 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1250 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1251
1252 $(OBJDIR)/shun.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1253
1254 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(OBJDIR)/translate
1255 $(OBJDIR)/translate $(SRCDIR)/skins.c >$@
1256
1257 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1258
--- src/main.mk
+++ src/main.mk
@@ -8,11 +8,11 @@
8 # to regenerate this file.
9 #
10 # This file is included by primary Makefile.
11 #
12
13 XTCC = $(TCC) -I. -I$(SRCDIR) -I$(OBJDIR) $(TCCFLAGS) $(CFLAGS)
14
15
16 SRC = \
17 $(SRCDIR)/add.c \
18 $(SRCDIR)/allrepo.c \
@@ -21,10 +21,11 @@
21 $(SRCDIR)/bisect.c \
22 $(SRCDIR)/blob.c \
23 $(SRCDIR)/branch.c \
24 $(SRCDIR)/browse.c \
25 $(SRCDIR)/builtin.c \
26 $(SRCDIR)/bundle.c \
27 $(SRCDIR)/cache.c \
28 $(SRCDIR)/captcha.c \
29 $(SRCDIR)/cgi.c \
30 $(SRCDIR)/checkin.c \
31 $(SRCDIR)/checkout.c \
@@ -43,10 +44,11 @@
44 $(SRCDIR)/encode.c \
45 $(SRCDIR)/event.c \
46 $(SRCDIR)/export.c \
47 $(SRCDIR)/file.c \
48 $(SRCDIR)/finfo.c \
49 $(SRCDIR)/foci.c \
50 $(SRCDIR)/fusefs.c \
51 $(SRCDIR)/glob.c \
52 $(SRCDIR)/graph.c \
53 $(SRCDIR)/gzip.c \
54 $(SRCDIR)/http.c \
@@ -86,19 +88,22 @@
88 $(SRCDIR)/path.c \
89 $(SRCDIR)/pivot.c \
90 $(SRCDIR)/popen.c \
91 $(SRCDIR)/pqueue.c \
92 $(SRCDIR)/printf.c \
93 $(SRCDIR)/publish.c \
94 $(SRCDIR)/purge.c \
95 $(SRCDIR)/rebuild.c \
96 $(SRCDIR)/regexp.c \
97 $(SRCDIR)/report.c \
98 $(SRCDIR)/rss.c \
99 $(SRCDIR)/schema.c \
100 $(SRCDIR)/search.c \
101 $(SRCDIR)/setup.c \
102 $(SRCDIR)/sha1.c \
103 $(SRCDIR)/shun.c \
104 $(SRCDIR)/sitemap.c \
105 $(SRCDIR)/skins.c \
106 $(SRCDIR)/sqlcmd.c \
107 $(SRCDIR)/stash.c \
108 $(SRCDIR)/stat.c \
109 $(SRCDIR)/style.c \
@@ -138,10 +143,11 @@
143 $(OBJDIR)/bisect_.c \
144 $(OBJDIR)/blob_.c \
145 $(OBJDIR)/branch_.c \
146 $(OBJDIR)/browse_.c \
147 $(OBJDIR)/builtin_.c \
148 $(OBJDIR)/bundle_.c \
149 $(OBJDIR)/cache_.c \
150 $(OBJDIR)/captcha_.c \
151 $(OBJDIR)/cgi_.c \
152 $(OBJDIR)/checkin_.c \
153 $(OBJDIR)/checkout_.c \
@@ -160,10 +166,11 @@
166 $(OBJDIR)/encode_.c \
167 $(OBJDIR)/event_.c \
168 $(OBJDIR)/export_.c \
169 $(OBJDIR)/file_.c \
170 $(OBJDIR)/finfo_.c \
171 $(OBJDIR)/foci_.c \
172 $(OBJDIR)/fusefs_.c \
173 $(OBJDIR)/glob_.c \
174 $(OBJDIR)/graph_.c \
175 $(OBJDIR)/gzip_.c \
176 $(OBJDIR)/http_.c \
@@ -203,19 +210,22 @@
210 $(OBJDIR)/path_.c \
211 $(OBJDIR)/pivot_.c \
212 $(OBJDIR)/popen_.c \
213 $(OBJDIR)/pqueue_.c \
214 $(OBJDIR)/printf_.c \
215 $(OBJDIR)/publish_.c \
216 $(OBJDIR)/purge_.c \
217 $(OBJDIR)/rebuild_.c \
218 $(OBJDIR)/regexp_.c \
219 $(OBJDIR)/report_.c \
220 $(OBJDIR)/rss_.c \
221 $(OBJDIR)/schema_.c \
222 $(OBJDIR)/search_.c \
223 $(OBJDIR)/setup_.c \
224 $(OBJDIR)/sha1_.c \
225 $(OBJDIR)/shun_.c \
226 $(OBJDIR)/sitemap_.c \
227 $(OBJDIR)/skins_.c \
228 $(OBJDIR)/sqlcmd_.c \
229 $(OBJDIR)/stash_.c \
230 $(OBJDIR)/stat_.c \
231 $(OBJDIR)/style_.c \
@@ -252,10 +262,11 @@
262 $(OBJDIR)/bisect.o \
263 $(OBJDIR)/blob.o \
264 $(OBJDIR)/branch.o \
265 $(OBJDIR)/browse.o \
266 $(OBJDIR)/builtin.o \
267 $(OBJDIR)/bundle.o \
268 $(OBJDIR)/cache.o \
269 $(OBJDIR)/captcha.o \
270 $(OBJDIR)/cgi.o \
271 $(OBJDIR)/checkin.o \
272 $(OBJDIR)/checkout.o \
@@ -274,10 +285,11 @@
285 $(OBJDIR)/encode.o \
286 $(OBJDIR)/event.o \
287 $(OBJDIR)/export.o \
288 $(OBJDIR)/file.o \
289 $(OBJDIR)/finfo.o \
290 $(OBJDIR)/foci.o \
291 $(OBJDIR)/fusefs.o \
292 $(OBJDIR)/glob.o \
293 $(OBJDIR)/graph.o \
294 $(OBJDIR)/gzip.o \
295 $(OBJDIR)/http.o \
@@ -317,19 +329,22 @@
329 $(OBJDIR)/path.o \
330 $(OBJDIR)/pivot.o \
331 $(OBJDIR)/popen.o \
332 $(OBJDIR)/pqueue.o \
333 $(OBJDIR)/printf.o \
334 $(OBJDIR)/publish.o \
335 $(OBJDIR)/purge.o \
336 $(OBJDIR)/rebuild.o \
337 $(OBJDIR)/regexp.o \
338 $(OBJDIR)/report.o \
339 $(OBJDIR)/rss.o \
340 $(OBJDIR)/schema.o \
341 $(OBJDIR)/search.o \
342 $(OBJDIR)/setup.o \
343 $(OBJDIR)/sha1.o \
344 $(OBJDIR)/shun.o \
345 $(OBJDIR)/sitemap.o \
346 $(OBJDIR)/skins.o \
347 $(OBJDIR)/sqlcmd.o \
348 $(OBJDIR)/stash.o \
349 $(OBJDIR)/stat.o \
350 $(OBJDIR)/style.o \
@@ -475,10 +490,11 @@
490 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
491 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
492 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
493 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
494 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
495 $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
496 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
497 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
498 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
499 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
500 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -497,10 +513,11 @@
513 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
514 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
515 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
516 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
517 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
518 $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
519 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
520 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
521 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
522 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
523 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -540,19 +557,22 @@
557 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
558 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
559 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
560 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
561 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
562 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
563 $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
564 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
565 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
566 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
567 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
568 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
569 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
570 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
571 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
572 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
573 $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
574 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
575 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
576 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
577 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
578 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -656,10 +676,18 @@
676
677 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
678 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
679
680 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
681
682 $(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(OBJDIR)/translate
683 $(OBJDIR)/translate $(SRCDIR)/bundle.c >$@
684
685 $(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
686 $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
687
688 $(OBJDIR)/bundle.h: $(OBJDIR)/headers
689
690 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(OBJDIR)/translate
691 $(OBJDIR)/translate $(SRCDIR)/cache.c >$@
692
693 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -832,10 +860,18 @@
860
861 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
862 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
863
864 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
865
866 $(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(OBJDIR)/translate
867 $(OBJDIR)/translate $(SRCDIR)/foci.c >$@
868
869 $(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
870 $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
871
872 $(OBJDIR)/foci.h: $(OBJDIR)/headers
873
874 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(OBJDIR)/translate
875 $(OBJDIR)/translate $(SRCDIR)/fusefs.c >$@
876
877 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1176,10 +1212,26 @@
1212
1213 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1214 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1215
1216 $(OBJDIR)/printf.h: $(OBJDIR)/headers
1217
1218 $(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(OBJDIR)/translate
1219 $(OBJDIR)/translate $(SRCDIR)/publish.c >$@
1220
1221 $(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1222 $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1223
1224 $(OBJDIR)/publish.h: $(OBJDIR)/headers
1225
1226 $(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(OBJDIR)/translate
1227 $(OBJDIR)/translate $(SRCDIR)/purge.c >$@
1228
1229 $(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1230 $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1231
1232 $(OBJDIR)/purge.h: $(OBJDIR)/headers
1233
1234 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(OBJDIR)/translate
1235 $(OBJDIR)/translate $(SRCDIR)/rebuild.c >$@
1236
1237 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1248,10 +1300,18 @@
1300
1301 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1302 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1303
1304 $(OBJDIR)/shun.h: $(OBJDIR)/headers
1305
1306 $(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(OBJDIR)/translate
1307 $(OBJDIR)/translate $(SRCDIR)/sitemap.c >$@
1308
1309 $(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1310 $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1311
1312 $(OBJDIR)/sitemap.h: $(OBJDIR)/headers
1313
1314 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(OBJDIR)/translate
1315 $(OBJDIR)/translate $(SRCDIR)/skins.c >$@
1316
1317 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1318
+43 -8
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -28,10 +28,11 @@
2828
bisect
2929
blob
3030
branch
3131
browse
3232
builtin
33
+ bundle
3334
cache
3435
captcha
3536
cgi
3637
checkin
3738
checkout
@@ -50,10 +51,11 @@
5051
encode
5152
event
5253
export
5354
file
5455
finfo
56
+ foci
5557
fusefs
5658
glob
5759
graph
5860
gzip
5961
http
@@ -92,19 +94,22 @@
9294
path
9395
pivot
9496
popen
9597
pqueue
9698
printf
99
+ publish
100
+ purge
97101
rebuild
98102
regexp
99103
report
100104
rss
101105
schema
102106
search
103107
setup
104108
sha1
105109
shun
110
+ sitemap
106111
skins
107112
sqlcmd
108113
stash
109114
stat
110115
style
@@ -220,11 +225,11 @@
220225
# to regenerate this file.
221226
#
222227
# This file is included by primary Makefile.
223228
#
224229
225
-XTCC = $(TCC) $(CFLAGS) -I. -I$(SRCDIR) -I$(OBJDIR)
230
+XTCC = $(TCC) -I. -I$(SRCDIR) -I$(OBJDIR) $(TCCFLAGS) $(CFLAGS)
226231
227232
}
228233
writeln -nonewline "SRC ="
229234
foreach s [lsort $src] {
230235
writeln -nonewline " \\\n \$(SRCDIR)/$s.c"
@@ -509,11 +514,12 @@
509514
# This is useful when Tcl has been compiled statically with MinGW.
510515
#
511516
FOSSIL_TCL_SOURCE = 1
512517
513518
#### Check if the workaround for the MinGW command line handling needs to
514
-# be enabled by default.
519
+# be enabled by default. This check may be somewhat fragile due to the
520
+# use of "findstring".
515521
#
516522
ifndef MINGW_IS_32BIT_ONLY
517523
ifeq (,$(findstring w64-mingw32,$(PREFIX)))
518524
MINGW_IS_32BIT_ONLY = 1
519525
endif
@@ -522,26 +528,46 @@
522528
#### The directories where the zlib include and library files are located.
523529
#
524530
ZINCDIR = $(SRCDIR)/../compat/zlib
525531
ZLIBDIR = $(SRCDIR)/../compat/zlib
526532
533
+#### Make an attempt to detect if Fossil is being built for the x64 processor
534
+# architecture. This check may be somewhat fragile due to "findstring".
535
+#
527536
ifndef X64
528537
ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
529538
X64 = 1
530539
endif
531540
endif
532541
542
+#### Determine if the optimized assembly routines provided with zlib should be
543
+# used, taking into account whether zlib is actually enabled and the target
544
+# processor architecture.
545
+#
533546
ifndef X64
534547
SSLCONFIG = mingw
548
+ifndef FOSSIL_ENABLE_MINIZ
535549
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
536550
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
551
+else
552
+ZLIBCONFIG =
553
+LIBTARGETS =
554
+endif
537555
else
538556
SSLCONFIG = mingw64
539
-ZLIBCONFIG =
557
+ZLIBCONFIG =
540558
LIBTARGETS =
541559
endif
542560
561
+#### Disable creation of the OpenSSL shared libraries. Also, disable support
562
+# for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
563
+#
564
+SSLCONFIG += no-ssl2 no-ssl3 no-shared
565
+
566
+#### When using zlib, make sure that OpenSSL is configured to use the zlib
567
+# that Fossil knows about (i.e. the one within the source tree).
568
+#
543569
ifndef FOSSIL_ENABLE_MINIZ
544570
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
545571
endif
546572
547573
#### The directories where the OpenSSL include and library files are located.
@@ -1286,23 +1312,32 @@
12861312
SSLLIBDIR = $(SSLDIR)\out32
12871313
SSLLFLAGS = /nologo /opt:ref /debug
12881314
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
12891315
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
12901316
!message Using 'x64' platform for OpenSSL...
1291
-SSLCONFIG = VC-WIN64A no-asm
1317
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1318
+# SSLCONFIG = VC-WIN64A no-asm no-ssl2 no-ssl3 no-shared
1319
+SSLCONFIG = VC-WIN64A no-asm no-shared
12921320
SSLSETUP = ms\do_win64a.bat
12931321
SSLNMAKE = ms\nt.mak all
1322
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
12941323
!elseif "$(PLATFORM)"=="ia64"
12951324
!message Using 'ia64' platform for OpenSSL...
1296
-SSLCONFIG = VC-WIN64I no-asm
1325
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1326
+# SSLCONFIG = VC-WIN64I no-asm no-ssl2 no-ssl3 no-shared
1327
+SSLCONFIG = VC-WIN64I no-asm no-shared
12971328
SSLSETUP = ms\do_win64i.bat
12981329
SSLNMAKE = ms\nt.mak all
1330
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
12991331
!else
13001332
!message Assuming 'x86' platform for OpenSSL...
1301
-SSLCONFIG = VC-WIN32 no-asm
1333
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1334
+# SSLCONFIG = VC-WIN32 no-asm no-ssl2 no-ssl3 no-shared
1335
+SSLCONFIG = VC-WIN32 no-asm no-shared
13021336
SSLSETUP = ms\do_ms.bat
13031337
SSLNMAKE = ms\nt.mak all
1338
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
13041339
!endif
13051340
!endif
13061341
13071342
!ifdef FOSSIL_ENABLE_TCL
13081343
TCLDIR = $(B)\compat\tcl-8.6
@@ -1471,13 +1506,13 @@
14711506
@set PATH=$(PERLDIR);$(PATH)
14721507
!endif
14731508
@pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
14741509
@pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
14751510
!ifdef FOSSIL_ENABLE_WINXP
1476
- @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
1511
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS) $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
14771512
!else
1478
- @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
1513
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
14791514
!endif
14801515
!endif
14811516
14821517
!ifndef FOSSIL_ENABLE_MINIZ
14831518
APPTARGETS = $(APPTARGETS) zlib
14841519
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -28,10 +28,11 @@
28 bisect
29 blob
30 branch
31 browse
32 builtin
 
33 cache
34 captcha
35 cgi
36 checkin
37 checkout
@@ -50,10 +51,11 @@
50 encode
51 event
52 export
53 file
54 finfo
 
55 fusefs
56 glob
57 graph
58 gzip
59 http
@@ -92,19 +94,22 @@
92 path
93 pivot
94 popen
95 pqueue
96 printf
 
 
97 rebuild
98 regexp
99 report
100 rss
101 schema
102 search
103 setup
104 sha1
105 shun
 
106 skins
107 sqlcmd
108 stash
109 stat
110 style
@@ -220,11 +225,11 @@
220 # to regenerate this file.
221 #
222 # This file is included by primary Makefile.
223 #
224
225 XTCC = $(TCC) $(CFLAGS) -I. -I$(SRCDIR) -I$(OBJDIR)
226
227 }
228 writeln -nonewline "SRC ="
229 foreach s [lsort $src] {
230 writeln -nonewline " \\\n \$(SRCDIR)/$s.c"
@@ -509,11 +514,12 @@
509 # This is useful when Tcl has been compiled statically with MinGW.
510 #
511 FOSSIL_TCL_SOURCE = 1
512
513 #### Check if the workaround for the MinGW command line handling needs to
514 # be enabled by default.
 
515 #
516 ifndef MINGW_IS_32BIT_ONLY
517 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
518 MINGW_IS_32BIT_ONLY = 1
519 endif
@@ -522,26 +528,46 @@
522 #### The directories where the zlib include and library files are located.
523 #
524 ZINCDIR = $(SRCDIR)/../compat/zlib
525 ZLIBDIR = $(SRCDIR)/../compat/zlib
526
 
 
 
527 ifndef X64
528 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
529 X64 = 1
530 endif
531 endif
532
 
 
 
 
533 ifndef X64
534 SSLCONFIG = mingw
 
535 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
536 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
 
 
 
 
537 else
538 SSLCONFIG = mingw64
539 ZLIBCONFIG =
540 LIBTARGETS =
541 endif
542
 
 
 
 
 
 
 
 
543 ifndef FOSSIL_ENABLE_MINIZ
544 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
545 endif
546
547 #### The directories where the OpenSSL include and library files are located.
@@ -1286,23 +1312,32 @@
1286 SSLLIBDIR = $(SSLDIR)\out32
1287 SSLLFLAGS = /nologo /opt:ref /debug
1288 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1289 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1290 !message Using 'x64' platform for OpenSSL...
1291 SSLCONFIG = VC-WIN64A no-asm
 
 
1292 SSLSETUP = ms\do_win64a.bat
1293 SSLNMAKE = ms\nt.mak all
 
1294 !elseif "$(PLATFORM)"=="ia64"
1295 !message Using 'ia64' platform for OpenSSL...
1296 SSLCONFIG = VC-WIN64I no-asm
 
 
1297 SSLSETUP = ms\do_win64i.bat
1298 SSLNMAKE = ms\nt.mak all
 
1299 !else
1300 !message Assuming 'x86' platform for OpenSSL...
1301 SSLCONFIG = VC-WIN32 no-asm
 
 
1302 SSLSETUP = ms\do_ms.bat
1303 SSLNMAKE = ms\nt.mak all
 
1304 !endif
1305 !endif
1306
1307 !ifdef FOSSIL_ENABLE_TCL
1308 TCLDIR = $(B)\compat\tcl-8.6
@@ -1471,13 +1506,13 @@
1471 @set PATH=$(PERLDIR);$(PATH)
1472 !endif
1473 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
1474 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
1475 !ifdef FOSSIL_ENABLE_WINXP
1476 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
1477 !else
1478 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
1479 !endif
1480 !endif
1481
1482 !ifndef FOSSIL_ENABLE_MINIZ
1483 APPTARGETS = $(APPTARGETS) zlib
1484
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -28,10 +28,11 @@
28 bisect
29 blob
30 branch
31 browse
32 builtin
33 bundle
34 cache
35 captcha
36 cgi
37 checkin
38 checkout
@@ -50,10 +51,11 @@
51 encode
52 event
53 export
54 file
55 finfo
56 foci
57 fusefs
58 glob
59 graph
60 gzip
61 http
@@ -92,19 +94,22 @@
94 path
95 pivot
96 popen
97 pqueue
98 printf
99 publish
100 purge
101 rebuild
102 regexp
103 report
104 rss
105 schema
106 search
107 setup
108 sha1
109 shun
110 sitemap
111 skins
112 sqlcmd
113 stash
114 stat
115 style
@@ -220,11 +225,11 @@
225 # to regenerate this file.
226 #
227 # This file is included by primary Makefile.
228 #
229
230 XTCC = $(TCC) -I. -I$(SRCDIR) -I$(OBJDIR) $(TCCFLAGS) $(CFLAGS)
231
232 }
233 writeln -nonewline "SRC ="
234 foreach s [lsort $src] {
235 writeln -nonewline " \\\n \$(SRCDIR)/$s.c"
@@ -509,11 +514,12 @@
514 # This is useful when Tcl has been compiled statically with MinGW.
515 #
516 FOSSIL_TCL_SOURCE = 1
517
518 #### Check if the workaround for the MinGW command line handling needs to
519 # be enabled by default. This check may be somewhat fragile due to the
520 # use of "findstring".
521 #
522 ifndef MINGW_IS_32BIT_ONLY
523 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
524 MINGW_IS_32BIT_ONLY = 1
525 endif
@@ -522,26 +528,46 @@
528 #### The directories where the zlib include and library files are located.
529 #
530 ZINCDIR = $(SRCDIR)/../compat/zlib
531 ZLIBDIR = $(SRCDIR)/../compat/zlib
532
533 #### Make an attempt to detect if Fossil is being built for the x64 processor
534 # architecture. This check may be somewhat fragile due to "findstring".
535 #
536 ifndef X64
537 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
538 X64 = 1
539 endif
540 endif
541
542 #### Determine if the optimized assembly routines provided with zlib should be
543 # used, taking into account whether zlib is actually enabled and the target
544 # processor architecture.
545 #
546 ifndef X64
547 SSLCONFIG = mingw
548 ifndef FOSSIL_ENABLE_MINIZ
549 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
550 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
551 else
552 ZLIBCONFIG =
553 LIBTARGETS =
554 endif
555 else
556 SSLCONFIG = mingw64
557 ZLIBCONFIG =
558 LIBTARGETS =
559 endif
560
561 #### Disable creation of the OpenSSL shared libraries. Also, disable support
562 # for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
563 #
564 SSLCONFIG += no-ssl2 no-ssl3 no-shared
565
566 #### When using zlib, make sure that OpenSSL is configured to use the zlib
567 # that Fossil knows about (i.e. the one within the source tree).
568 #
569 ifndef FOSSIL_ENABLE_MINIZ
570 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
571 endif
572
573 #### The directories where the OpenSSL include and library files are located.
@@ -1286,23 +1312,32 @@
1312 SSLLIBDIR = $(SSLDIR)\out32
1313 SSLLFLAGS = /nologo /opt:ref /debug
1314 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
1315 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
1316 !message Using 'x64' platform for OpenSSL...
1317 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1318 # SSLCONFIG = VC-WIN64A no-asm no-ssl2 no-ssl3 no-shared
1319 SSLCONFIG = VC-WIN64A no-asm no-shared
1320 SSLSETUP = ms\do_win64a.bat
1321 SSLNMAKE = ms\nt.mak all
1322 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
1323 !elseif "$(PLATFORM)"=="ia64"
1324 !message Using 'ia64' platform for OpenSSL...
1325 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1326 # SSLCONFIG = VC-WIN64I no-asm no-ssl2 no-ssl3 no-shared
1327 SSLCONFIG = VC-WIN64I no-asm no-shared
1328 SSLSETUP = ms\do_win64i.bat
1329 SSLNMAKE = ms\nt.mak all
1330 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
1331 !else
1332 !message Assuming 'x86' platform for OpenSSL...
1333 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
1334 # SSLCONFIG = VC-WIN32 no-asm no-ssl2 no-ssl3 no-shared
1335 SSLCONFIG = VC-WIN32 no-asm no-shared
1336 SSLSETUP = ms\do_ms.bat
1337 SSLNMAKE = ms\nt.mak all
1338 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
1339 !endif
1340 !endif
1341
1342 !ifdef FOSSIL_ENABLE_TCL
1343 TCLDIR = $(B)\compat\tcl-8.6
@@ -1471,13 +1506,13 @@
1506 @set PATH=$(PERLDIR);$(PATH)
1507 !endif
1508 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
1509 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
1510 !ifdef FOSSIL_ENABLE_WINXP
1511 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS) $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
1512 !else
1513 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
1514 !endif
1515 !endif
1516
1517 !ifndef FOSSIL_ENABLE_MINIZ
1518 APPTARGETS = $(APPTARGETS) zlib
1519
+22 -2
--- src/manifest.c
+++ src/manifest.c
@@ -1774,14 +1774,34 @@
17741774
zScript = xfer_commit_code();
17751775
zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
17761776
}
17771777
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
17781778
char *zCom;
1779
+ char zBaseId[30];
1780
+ if( p->zBaseline ){
1781
+ sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
1782
+ uuid_to_rid(p->zBaseline,1));
1783
+ }else{
1784
+ sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1785
+ }
1786
+ (void)db_schema_is_outofdate(); /* Make sure g.zAuxSchema is initialized */
17791787
for(i=0; i<p->nParent; i++){
17801788
int pid = uuid_to_rid(p->azParent[i], 1);
1781
- db_multi_exec("INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1782
- "VALUES(%d, %d, %d, %.17g)", pid, rid, i==0, p->rDate);
1789
+ if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1790
+ /* Support for PLINK.BASEID added on 2014-11-24 */
1791
+ db_multi_exec(
1792
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1793
+ "VALUES(%d, %d, %d, %.17g, %s)",
1794
+ pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1795
+ }else{
1796
+ /* Continue to work with older schema to avoid an unnecessary
1797
+ ** rebuild */
1798
+ db_multi_exec(
1799
+ "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1800
+ "VALUES(%d, %d, %d, %.17g)",
1801
+ pid, rid, i==0, p->rDate);
1802
+ }
17831803
if( i==0 ){
17841804
add_mlink(pid, 0, rid, p);
17851805
parentid = pid;
17861806
}
17871807
}
17881808
--- src/manifest.c
+++ src/manifest.c
@@ -1774,14 +1774,34 @@
1774 zScript = xfer_commit_code();
1775 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1776 }
1777 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1778 char *zCom;
 
 
 
 
 
 
 
 
1779 for(i=0; i<p->nParent; i++){
1780 int pid = uuid_to_rid(p->azParent[i], 1);
1781 db_multi_exec("INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1782 "VALUES(%d, %d, %d, %.17g)", pid, rid, i==0, p->rDate);
 
 
 
 
 
 
 
 
 
 
 
 
1783 if( i==0 ){
1784 add_mlink(pid, 0, rid, p);
1785 parentid = pid;
1786 }
1787 }
1788
--- src/manifest.c
+++ src/manifest.c
@@ -1774,14 +1774,34 @@
1774 zScript = xfer_commit_code();
1775 zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1776 }
1777 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
1778 char *zCom;
1779 char zBaseId[30];
1780 if( p->zBaseline ){
1781 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "%d",
1782 uuid_to_rid(p->zBaseline,1));
1783 }else{
1784 sqlite3_snprintf(sizeof(zBaseId), zBaseId, "NULL");
1785 }
1786 (void)db_schema_is_outofdate(); /* Make sure g.zAuxSchema is initialized */
1787 for(i=0; i<p->nParent; i++){
1788 int pid = uuid_to_rid(p->azParent[i], 1);
1789 if( strcmp(g.zAuxSchema,"2014-11-24 20:35")>=0 ){
1790 /* Support for PLINK.BASEID added on 2014-11-24 */
1791 db_multi_exec(
1792 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime, baseid)"
1793 "VALUES(%d, %d, %d, %.17g, %s)",
1794 pid, rid, i==0, p->rDate, zBaseId/*safe-for-%s*/);
1795 }else{
1796 /* Continue to work with older schema to avoid an unnecessary
1797 ** rebuild */
1798 db_multi_exec(
1799 "INSERT OR IGNORE INTO plink(pid, cid, isprim, mtime)"
1800 "VALUES(%d, %d, %d, %.17g)",
1801 pid, rid, i==0, p->rDate);
1802 }
1803 if( i==0 ){
1804 add_mlink(pid, 0, rid, p);
1805 parentid = pid;
1806 }
1807 }
1808
+1 -1
--- src/markdown.c
+++ src/markdown.c
@@ -2155,11 +2155,11 @@
21552155
struct Blob *ib, /* input blob in markdown */
21562156
const struct mkd_renderer *rndrer /* renderer descriptor (callbacks) */
21572157
){
21582158
struct link_ref *lr;
21592159
struct Blob text = BLOB_INITIALIZER;
2160
- size_t i, beg, end;
2160
+ size_t i, beg, end = 0;
21612161
struct render rndr;
21622162
char *ib_data;
21632163
21642164
/* filling the render structure */
21652165
if( !rndrer ) return;
21662166
--- src/markdown.c
+++ src/markdown.c
@@ -2155,11 +2155,11 @@
2155 struct Blob *ib, /* input blob in markdown */
2156 const struct mkd_renderer *rndrer /* renderer descriptor (callbacks) */
2157 ){
2158 struct link_ref *lr;
2159 struct Blob text = BLOB_INITIALIZER;
2160 size_t i, beg, end;
2161 struct render rndr;
2162 char *ib_data;
2163
2164 /* filling the render structure */
2165 if( !rndrer ) return;
2166
--- src/markdown.c
+++ src/markdown.c
@@ -2155,11 +2155,11 @@
2155 struct Blob *ib, /* input blob in markdown */
2156 const struct mkd_renderer *rndrer /* renderer descriptor (callbacks) */
2157 ){
2158 struct link_ref *lr;
2159 struct Blob text = BLOB_INITIALIZER;
2160 size_t i, beg, end = 0;
2161 struct render rndr;
2162 char *ib_data;
2163
2164 /* filling the render structure */
2165 if( !rndrer ) return;
2166
+9 -2
--- src/mkversion.c
+++ src/mkversion.c
@@ -7,10 +7,11 @@
77
**
88
** Note that the manifest.uuid and manifest files are generated by Fossil.
99
*/
1010
#include <stdio.h>
1111
#include <string.h>
12
+#include <stdlib.h>
1213
1314
int main(int argc, char *argv[]){
1415
FILE *m,*u,*v;
1516
char *z;
1617
int i, x, d;
@@ -17,11 +18,14 @@
1718
char b[1000];
1819
char vx[1000];
1920
memset(b,0,sizeof(b));
2021
memset(vx,0,sizeof(vx));
2122
u = fopen(argv[1],"r");
22
- fgets(b, sizeof(b)-1,u);
23
+ if( fgets(b, sizeof(b)-1,u)==0 ){
24
+ fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]);
25
+ exit(1);
26
+ }
2327
fclose(u);
2428
for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
2529
*z = 0;
2630
printf("#define MANIFEST_UUID \"%s\"\n",b);
2731
printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b);
@@ -32,11 +36,14 @@
3236
printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2);
3337
}
3438
}
3539
fclose(m);
3640
v = fopen(argv[3],"r");
37
- fgets(b, sizeof(b)-1,v);
41
+ if( fgets(b, sizeof(b)-1,v)==0 ){
42
+ fprintf(stderr, "malformed VERSION file: %s\n", argv[3]);
43
+ exit(1);
44
+ }
3845
fclose(v);
3946
for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
4047
*z = 0;
4148
printf("#define RELEASE_VERSION \"%s\"\n", b);
4249
x=0;
4350
--- src/mkversion.c
+++ src/mkversion.c
@@ -7,10 +7,11 @@
7 **
8 ** Note that the manifest.uuid and manifest files are generated by Fossil.
9 */
10 #include <stdio.h>
11 #include <string.h>
 
12
13 int main(int argc, char *argv[]){
14 FILE *m,*u,*v;
15 char *z;
16 int i, x, d;
@@ -17,11 +18,14 @@
17 char b[1000];
18 char vx[1000];
19 memset(b,0,sizeof(b));
20 memset(vx,0,sizeof(vx));
21 u = fopen(argv[1],"r");
22 fgets(b, sizeof(b)-1,u);
 
 
 
23 fclose(u);
24 for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
25 *z = 0;
26 printf("#define MANIFEST_UUID \"%s\"\n",b);
27 printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b);
@@ -32,11 +36,14 @@
32 printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2);
33 }
34 }
35 fclose(m);
36 v = fopen(argv[3],"r");
37 fgets(b, sizeof(b)-1,v);
 
 
 
38 fclose(v);
39 for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
40 *z = 0;
41 printf("#define RELEASE_VERSION \"%s\"\n", b);
42 x=0;
43
--- src/mkversion.c
+++ src/mkversion.c
@@ -7,10 +7,11 @@
7 **
8 ** Note that the manifest.uuid and manifest files are generated by Fossil.
9 */
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 int main(int argc, char *argv[]){
15 FILE *m,*u,*v;
16 char *z;
17 int i, x, d;
@@ -17,11 +18,14 @@
18 char b[1000];
19 char vx[1000];
20 memset(b,0,sizeof(b));
21 memset(vx,0,sizeof(vx));
22 u = fopen(argv[1],"r");
23 if( fgets(b, sizeof(b)-1,u)==0 ){
24 fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]);
25 exit(1);
26 }
27 fclose(u);
28 for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
29 *z = 0;
30 printf("#define MANIFEST_UUID \"%s\"\n",b);
31 printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b);
@@ -32,11 +36,14 @@
36 printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2);
37 }
38 }
39 fclose(m);
40 v = fopen(argv[3],"r");
41 if( fgets(b, sizeof(b)-1,v)==0 ){
42 fprintf(stderr, "malformed VERSION file: %s\n", argv[3]);
43 exit(1);
44 }
45 fclose(v);
46 for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
47 *z = 0;
48 printf("#define RELEASE_VERSION \"%s\"\n", b);
49 x=0;
50
+3 -6
--- src/moderate.c
+++ src/moderate.c
@@ -38,16 +38,11 @@
3838
3939
/*
4040
** Return TRUE if the modreq table exists
4141
*/
4242
int moderation_table_exists(void){
43
- static int modreqExists = -1;
44
- if( modreqExists<0 ){
45
- modreqExists = db_exists("SELECT 1 FROM %s.sqlite_master"
46
- " WHERE name='modreq'", db_name("repository"));
47
- }
48
- return modreqExists;
43
+ return db_table_exists("repository", "modreq");
4944
}
5045
5146
/*
5247
** Return TRUE if the object specified is being held for moderation.
5348
*/
@@ -116,10 +111,11 @@
116111
attachRid = db_int(0, "SELECT attachRid FROM modreq WHERE objid=%d", rid);
117112
if( rid==objid ){
118113
db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
119114
}
120115
if( attachRid && object_used(attachRid) ) attachRid = 0;
116
+ admin_log("Disapproved moderation of rid %d.", rid);
121117
rid = attachRid;
122118
}
123119
db_end_transaction(0);
124120
}
125121
@@ -134,10 +130,11 @@
134130
"INSERT OR IGNORE INTO unclustered VALUES(%d);"
135131
"INSERT OR IGNORE INTO unsent VALUES(%d);",
136132
rid, rid, rid
137133
);
138134
db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
135
+ admin_log("Approved moderation of rid %d.", rid);
139136
db_end_transaction(0);
140137
}
141138
142139
/*
143140
** WEBPAGE: modreq
144141
--- src/moderate.c
+++ src/moderate.c
@@ -38,16 +38,11 @@
38
39 /*
40 ** Return TRUE if the modreq table exists
41 */
42 int moderation_table_exists(void){
43 static int modreqExists = -1;
44 if( modreqExists<0 ){
45 modreqExists = db_exists("SELECT 1 FROM %s.sqlite_master"
46 " WHERE name='modreq'", db_name("repository"));
47 }
48 return modreqExists;
49 }
50
51 /*
52 ** Return TRUE if the object specified is being held for moderation.
53 */
@@ -116,10 +111,11 @@
116 attachRid = db_int(0, "SELECT attachRid FROM modreq WHERE objid=%d", rid);
117 if( rid==objid ){
118 db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
119 }
120 if( attachRid && object_used(attachRid) ) attachRid = 0;
 
121 rid = attachRid;
122 }
123 db_end_transaction(0);
124 }
125
@@ -134,10 +130,11 @@
134 "INSERT OR IGNORE INTO unclustered VALUES(%d);"
135 "INSERT OR IGNORE INTO unsent VALUES(%d);",
136 rid, rid, rid
137 );
138 db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
 
139 db_end_transaction(0);
140 }
141
142 /*
143 ** WEBPAGE: modreq
144
--- src/moderate.c
+++ src/moderate.c
@@ -38,16 +38,11 @@
38
39 /*
40 ** Return TRUE if the modreq table exists
41 */
42 int moderation_table_exists(void){
43 return db_table_exists("repository", "modreq");
 
 
 
 
 
44 }
45
46 /*
47 ** Return TRUE if the object specified is being held for moderation.
48 */
@@ -116,10 +111,11 @@
111 attachRid = db_int(0, "SELECT attachRid FROM modreq WHERE objid=%d", rid);
112 if( rid==objid ){
113 db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
114 }
115 if( attachRid && object_used(attachRid) ) attachRid = 0;
116 admin_log("Disapproved moderation of rid %d.", rid);
117 rid = attachRid;
118 }
119 db_end_transaction(0);
120 }
121
@@ -134,10 +130,11 @@
130 "INSERT OR IGNORE INTO unclustered VALUES(%d);"
131 "INSERT OR IGNORE INTO unsent VALUES(%d);",
132 rid, rid, rid
133 );
134 db_multi_exec("DELETE FROM modreq WHERE objid=%d", rid);
135 admin_log("Approved moderation of rid %d.", rid);
136 db_end_transaction(0);
137 }
138
139 /*
140 ** WEBPAGE: modreq
141
+352 -51
--- src/name.c
+++ src/name.c
@@ -42,10 +42,44 @@
4242
if( z[7]!='-') return 0;
4343
if( !fossil_isdigit(z[8]) ) return 0;
4444
if( !fossil_isdigit(z[9]) ) return 0;
4545
return 1;
4646
}
47
+
48
+/*
49
+** Return the RID that is the "root" of the branch that contains
50
+** check-in "rid" if inBranch==0 or the first check-in in the branch
51
+** if inBranch==1.
52
+*/
53
+int start_of_branch(int rid, int inBranch){
54
+ Stmt q;
55
+ int rc;
56
+ char *zBr;
57
+ zBr = db_text("trunk","SELECT value FROM tagxref"
58
+ " WHERE rid=%d AND tagid=%d"
59
+ " AND tagtype>0",
60
+ rid, TAG_BRANCH);
61
+ db_prepare(&q,
62
+ "SELECT pid, EXISTS(SELECT 1 FROM tagxref"
63
+ " WHERE tagid=%d AND tagtype>0"
64
+ " AND value=%Q AND rid=plink.pid)"
65
+ " FROM plink"
66
+ " WHERE cid=:cid AND isprim",
67
+ TAG_BRANCH, zBr
68
+ );
69
+ fossil_free(zBr);
70
+ do{
71
+ db_reset(&q);
72
+ db_bind_int(&q, ":cid", rid);
73
+ rc = db_step(&q);
74
+ if( rc!=SQLITE_ROW ) break;
75
+ if( inBranch && db_column_int(&q,1)==0 ) break;
76
+ rid = db_column_int(&q, 0);
77
+ }while( db_column_int(&q, 1)==1 && rid>0 );
78
+ db_finalize(&q);
79
+ return rid;
80
+}
4781
4882
/*
4983
** Convert a symbolic name into a RID. Acceptable forms:
5084
**
5185
** * SHA1 hash
@@ -66,20 +100,28 @@
66100
** Return the RID of the matching artifact. Or return 0 if the name does not
67101
** match any known object. Or return -1 if the name is ambiguous.
68102
**
69103
** The zType parameter specifies the type of artifact: ci, t, w, e, g.
70104
** If zType is NULL or "" or "*" then any type of artifact will serve.
105
+** If zType is "br" then find the first check-in of the named branch
106
+** rather than the last.
71107
** zType is "ci" in most use cases since we are usually searching for
72108
** a check-in.
73109
*/
74110
int symbolic_name_to_rid(const char *zTag, const char *zType){
75111
int vid;
76112
int rid = 0;
77113
int nTag;
78114
int i;
115
+ int startOfBranch = 0;
79116
80
- if( zType==0 || zType[0]==0 ) zType = "*";
117
+ if( zType==0 || zType[0]==0 ){
118
+ zType = "*";
119
+ }else if( zType[0]=='b' ){
120
+ zType = "ci";
121
+ startOfBranch = 1;
122
+ }
81123
if( zTag==0 || zTag[0]==0 ) return 0;
82124
83125
/* special keyword: "tip" */
84126
if( fossil_strcmp(zTag, "tip")==0 && (zType[0]=='*' || zType[0]=='c') ){
85127
rid = db_int(0,
@@ -151,41 +193,18 @@
151193
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
152194
" AND event.objid=tagxref.rid "
153195
" AND event.type GLOB '%q'",
154196
&zTag[4], zType
155197
);
198
+ if( startOfBranch ) rid = start_of_branch(rid,1);
156199
return rid;
157200
}
158201
159202
/* root:TAG -> The origin of the branch */
160203
if( memcmp(zTag, "root:", 5)==0 ){
161
- Stmt q;
162
- int rc;
163
- char *zBr;
164204
rid = symbolic_name_to_rid(zTag+5, zType);
165
- zBr = db_text("trunk","SELECT value FROM tagxref"
166
- " WHERE rid=%d AND tagid=%d"
167
- " AND tagtype>0",
168
- rid, TAG_BRANCH);
169
- db_prepare(&q,
170
- "SELECT pid, EXISTS(SELECT 1 FROM tagxref"
171
- " WHERE tagid=%d AND tagtype>0"
172
- " AND value=%Q AND rid=plink.pid)"
173
- " FROM plink"
174
- " WHERE cid=:cid AND isprim",
175
- TAG_BRANCH, zBr
176
- );
177
- fossil_free(zBr);
178
- do{
179
- db_reset(&q);
180
- db_bind_int(&q, ":cid", rid);
181
- rc = db_step(&q);
182
- if( rc!=SQLITE_ROW ) break;
183
- rid = db_column_int(&q, 0);
184
- }while( db_column_int(&q, 1)==1 && rid>0 );
185
- db_finalize(&q);
186
- return rid;
205
+ return start_of_branch(rid, 0);
187206
}
188207
189208
/* symbolic-name ":" date-time */
190209
nTag = strlen(zTag);
191210
for(i=0; i<nTag-10 && zTag[i]!=':'; i++){}
@@ -245,11 +264,14 @@
245264
" AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
246265
" AND event.objid=tagxref.rid "
247266
" AND event.type GLOB '%q'",
248267
zTag, zType
249268
);
250
- if( rid>0 ) return rid;
269
+ if( rid>0 ){
270
+ if( startOfBranch ) rid = start_of_branch(rid,1);
271
+ return rid;
272
+ }
251273
252274
/* Undocumented: numeric tags get translated directly into the RID */
253275
if( memcmp(zTag, "rid:", 4)==0 ){
254276
zTag += 4;
255277
for(i=0; fossil_isdigit(zTag[i]); i++){}
@@ -324,30 +346,25 @@
324346
** name_collisions searches through events, blobs, and tickets for
325347
** collisions of a given UUID based on its length on UUIDs no shorter
326348
** than 4 characters in length.
327349
*/
328350
int name_collisions(const char *zName){
329
- Stmt q;
330351
int c = 0; /* count of collisions for zName */
331352
int nLen; /* length of zName */
332353
nLen = strlen(zName);
333354
if( nLen>=4 && nLen<=UUID_SIZE && validate16(zName, nLen) ){
334
- db_prepare(&q,
335
- "SELECT count(uuid) FROM"
336
- " (SELECT substr(tkt_uuid, 1, %d) AS uuid FROM ticket"
337
- " UNION ALL SELECT * FROM"
338
- " (SELECT substr(tagname, 7, %d) FROM"
339
- " tag WHERE tagname GLOB 'event-*')"
340
- " UNION ALL SELECT * FROM"
341
- " (SELECT substr(uuid, 1, %d) FROM blob))"
342
- " WHERE uuid GLOB '%q*'"
343
- " GROUP BY uuid HAVING count(uuid) > 1;",
344
- nLen, nLen, nLen, zName);
345
- if( db_step(&q)==SQLITE_ROW ){
346
- c = db_column_int(&q, 0);
347
- }
348
- db_finalize(&q);
355
+ c = db_int(0,
356
+ "SELECT"
357
+ " (SELECT count(*) FROM ticket"
358
+ " WHERE tkt_uuid GLOB '%q*') +"
359
+ " (SELECT count(*) FROM tag"
360
+ " WHERE tagname GLOB 'event-%q*') +"
361
+ " (SELECT count(*) FROM blob"
362
+ " WHERE uuid GLOB '%q*');",
363
+ zName, zName, zName
364
+ );
365
+ if( c<2 ) c = 0;
349366
}
350367
return c;
351368
}
352369
353370
/*
@@ -391,18 +408,15 @@
391408
int rid;
392409
393410
if( zName==0 || zName[0]==0 ) return 0;
394411
rid = symbolic_name_to_rid(zName, zType);
395412
if( rid<0 ){
396
- fossil_error(1, "ambiguous name: %s", zName);
397
- return 0;
413
+ fossil_fatal("ambiguous name: %s", zName);
398414
}else if( rid==0 ){
399
- fossil_error(1, "not found: %s", zName);
400
- return 0;
401
- }else{
402
- return rid;
415
+ fossil_fatal("not found: %s", zName);
403416
}
417
+ return rid;
404418
}
405419
int name_to_rid(const char *zName){
406420
return name_to_typed_rid(zName, "*");
407421
}
408422
@@ -505,11 +519,11 @@
505519
}
506520
507521
/*
508522
** Generate a description of artifact "rid"
509523
*/
510
-static void whatis_rid(int rid, int verboseFlag){
524
+void whatis_rid(int rid, int verboseFlag){
511525
Stmt q;
512526
int cnt;
513527
514528
/* Basic information about the object. */
515529
db_prepare(&q,
@@ -657,21 +671,23 @@
657671
void whatis_cmd(void){
658672
int rid;
659673
const char *zName;
660674
int verboseFlag;
661675
int i;
676
+ const char *zType = 0;
662677
db_find_and_open_repository(0,0);
663678
verboseFlag = find_option("verbose","v",0)!=0;
679
+ zType = find_option("type",0,1);
664680
665681
/* We should be done with options.. */
666682
verify_all_options();
667683
668684
if( g.argc<3 ) usage("whatis NAME ...");
669685
for(i=2; i<g.argc; i++){
670686
zName = g.argv[i];
671687
if( i>2 ) fossil_print("%.79c\n",'-');
672
- rid = symbolic_name_to_rid(zName, 0);
688
+ rid = symbolic_name_to_rid(zName, zType);
673689
if( rid<0 ){
674690
Stmt q;
675691
int cnt = 0;
676692
fossil_print("name: %s (ambiguous)\n", zName);
677693
db_prepare(&q,
@@ -757,5 +773,290 @@
757773
while( db_step(&q)==SQLITE_ROW ){
758774
fossil_print("%s\n", db_column_text(&q, 0));
759775
}
760776
db_finalize(&q);
761777
}
778
+
779
+/*
780
+** Schema for the description table
781
+*/
782
+static const char zDescTab[] =
783
+@ CREATE TEMP TABLE IF NOT EXISTS description(
784
+@ rid INTEGER PRIMARY KEY, -- RID of the object
785
+@ uuid TEXT, -- SHA1 hash of the object
786
+@ ctime DATETIME, -- Time of creation
787
+@ isPrivate BOOLEAN DEFAULT 0, -- True for unpublished artifacts
788
+@ type TEXT, -- file, checkin, wiki, ticket, etc.
789
+@ summary TEXT, -- Summary comment for the object
790
+@ detail TEXT -- filename, checkin comment, etc
791
+@ );
792
+;
793
+
794
+/*
795
+** Create the description table if it does not already exists.
796
+** Populate fields of this table with descriptions for all artifacts
797
+** whose RID matches the SQL expression in zWhere.
798
+*/
799
+void describe_artifacts(const char *zWhere){
800
+ db_multi_exec("%s", zDescTab/*safe-for-%s*/);
801
+
802
+ /* Describe checkins */
803
+ db_multi_exec(
804
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
805
+ "SELECT blob.rid, blob.uuid, event.mtime, 'checkin',\n"
806
+ " 'checkin on ' || strftime('%%Y-%%m-%%d %%H:%%M',event.mtime)\n"
807
+ " FROM event, blob\n"
808
+ " WHERE (event.objid %s) AND event.type='ci'\n"
809
+ " AND event.objid=blob.rid;",
810
+ zWhere /*safe-for-%s*/
811
+ );
812
+
813
+ /* Describe files */
814
+ db_multi_exec(
815
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
816
+ "SELECT blob.rid, blob.uuid, event.mtime, 'file', 'file '||filename.name\n"
817
+ " FROM mlink, blob, event, filename\n"
818
+ " WHERE (mlink.fid %s)\n"
819
+ " AND mlink.mid=event.objid\n"
820
+ " AND filename.fnid=mlink.fnid\n"
821
+ " AND mlink.fid=blob.rid;",
822
+ zWhere /*safe-for-%s*/
823
+ );
824
+
825
+ /* Describe tags */
826
+ db_multi_exec(
827
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
828
+ "SELECT blob.rid, blob.uuid, tagxref.mtime, 'tag',\n"
829
+ " 'tag '||substr((SELECT uuid FROM blob WHERE rid=tagxref.rid),1,16)\n"
830
+ " FROM tagxref, blob\n"
831
+ " WHERE (tagxref.srcid %s) AND tagxref.srcid!=tagxref.rid\n"
832
+ " AND tagxref.srcid=blob.rid;",
833
+ zWhere /*safe-for-%s*/
834
+ );
835
+
836
+ /* Cluster artifacts */
837
+ db_multi_exec(
838
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
839
+ "SELECT blob.rid, blob.uuid, tagxref.mtime, 'cluster', 'cluster'\n"
840
+ " FROM tagxref, blob\n"
841
+ " WHERE (tagxref.rid %s)\n"
842
+ " AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='cluster')\n"
843
+ " AND blob.rid=tagxref.rid;",
844
+ zWhere /*safe-for-%s*/
845
+ );
846
+
847
+ /* Ticket change artifacts */
848
+ db_multi_exec(
849
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
850
+ "SELECT blob.rid, blob.uuid, tagxref.mtime, 'ticket',\n"
851
+ " 'ticket '||substr(tag.tagname,5,21)\n"
852
+ " FROM tagxref, tag, blob\n"
853
+ " WHERE (tagxref.rid %s)\n"
854
+ " AND tag.tagid=tagxref.tagid\n"
855
+ " AND tag.tagname GLOB 'tkt-*'"
856
+ " AND blob.rid=tagxref.rid;",
857
+ zWhere /*safe-for-%s*/
858
+ );
859
+
860
+ /* Wiki edit artifacts */
861
+ db_multi_exec(
862
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
863
+ "SELECT blob.rid, blob.uuid, tagxref.mtime, 'wiki',\n"
864
+ " printf('wiki \"%%s\"',substr(tag.tagname,6))\n"
865
+ " FROM tagxref, tag, blob\n"
866
+ " WHERE (tagxref.rid %s)\n"
867
+ " AND tag.tagid=tagxref.tagid\n"
868
+ " AND tag.tagname GLOB 'wiki-*'"
869
+ " AND blob.rid=tagxref.rid;",
870
+ zWhere /*safe-for-%s*/
871
+ );
872
+
873
+ /* Event edit artifacts */
874
+ db_multi_exec(
875
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
876
+ "SELECT blob.rid, blob.uuid, tagxref.mtime, 'event',\n"
877
+ " 'event '||substr(tag.tagname,7)\n"
878
+ " FROM tagxref, tag, blob\n"
879
+ " WHERE (tagxref.rid %s)\n"
880
+ " AND tag.tagid=tagxref.tagid\n"
881
+ " AND tag.tagname GLOB 'event-*'"
882
+ " AND blob.rid=tagxref.rid;",
883
+ zWhere /*safe-for-%s*/
884
+ );
885
+
886
+ /* Attachments */
887
+ db_multi_exec(
888
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
889
+ "SELECT blob.rid, blob.uuid, attachment.mtime, 'attach-control',\n"
890
+ " 'attachment-control for '||attachment.filename\n"
891
+ " FROM attachment, blob\n"
892
+ " WHERE (attachment.attachid %s)\n"
893
+ " AND blob.rid=attachment.attachid",
894
+ zWhere /*safe-for-%s*/
895
+ );
896
+ db_multi_exec(
897
+ "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
898
+ "SELECT blob.rid, blob.uuid, attachment.mtime, 'attachment',\n"
899
+ " 'attachment '||attachment.filename\n"
900
+ " FROM attachment, blob\n"
901
+ " WHERE (blob.rid %s)\n"
902
+ " AND blob.rid NOT IN (SELECT rid FROM description)\n"
903
+ " AND blob.uuid=attachment.src",
904
+ zWhere /*safe-for-%s*/
905
+ );
906
+
907
+ /* Everything else */
908
+ db_multi_exec(
909
+ "INSERT OR IGNORE INTO description(rid,uuid,type,summary)\n"
910
+ "SELECT blob.rid, blob.uuid,"
911
+ " CASE WHEN blob.size<0 THEN 'phantom' ELSE '' END,\n"
912
+ " 'unknown'\n"
913
+ " FROM blob WHERE (blob.rid %s);",
914
+ zWhere /*safe-for-%s*/
915
+ );
916
+
917
+ /* Mark private elements */
918
+ db_multi_exec(
919
+ "UPDATE description SET isPrivate=1 WHERE rid IN private"
920
+ );
921
+}
922
+
923
+/*
924
+** Print the content of the description table on stdout
925
+*/
926
+int describe_artifacts_to_stdout(const char *zWhere, const char *zLabel){
927
+ Stmt q;
928
+ int cnt = 0;
929
+ describe_artifacts(zWhere);
930
+ db_prepare(&q,
931
+ "SELECT uuid, summary, isPrivate\n"
932
+ " FROM description\n"
933
+ " ORDER BY ctime, type;"
934
+ );
935
+ while( db_step(&q)==SQLITE_ROW ){
936
+ if( zLabel ){
937
+ fossil_print("%s\n", zLabel);
938
+ zLabel = 0;
939
+ }
940
+ fossil_print(" %.16s %s", db_column_text(&q,0), db_column_text(&q,1));
941
+ if( db_column_int(&q,2) ) fossil_print(" (unpublished)");
942
+ fossil_print("\n");
943
+ cnt++;
944
+ }
945
+ db_finalize(&q);
946
+ db_multi_exec("DELETE FROM description;");
947
+ return cnt;
948
+}
949
+
950
+/*
951
+** COMMAND: test-describe-artifacts
952
+**
953
+** Usage: %fossil test-describe-artifacts [--from S] [--count N]
954
+**
955
+** Display a one-line description of every artifact.
956
+*/
957
+void test_describe_artifacts_cmd(void){
958
+ int iFrom = 0;
959
+ int iCnt = 1000000;
960
+ const char *z;
961
+ char *zRange;
962
+ db_find_and_open_repository(0,0);
963
+ z = find_option("from",0,1);
964
+ if( z ) iFrom = atoi(z);
965
+ z = find_option("count",0,1);
966
+ if( z ) iCnt = atoi(z);
967
+ zRange = mprintf("BETWEEN %d AND %d", iFrom, iFrom+iCnt-1);
968
+ describe_artifacts_to_stdout(zRange, 0);
969
+}
970
+
971
+/*
972
+** WEBPAGE: bloblist
973
+**
974
+** Return a page showing all artifacts in the repository. Query parameters:
975
+**
976
+** n=N Show N artifacts
977
+** s=S Start with artifact number S
978
+*/
979
+void bloblist_page(void){
980
+ Stmt q;
981
+ int s = atoi(PD("s","0"));
982
+ int n = atoi(PD("n","5000"));
983
+ int mx = db_int(0, "SELECT max(rid) FROM blob");
984
+ char *zRange;
985
+
986
+ login_check_credentials();
987
+ if( !g.perm.Read ){ login_needed(); return; }
988
+ style_header("List Of Artifacts");
989
+ if( mx>n && P("s")==0 ){
990
+ int i;
991
+ @ <p>Select a range of artifacts to view:</p>
992
+ @ <ul>
993
+ for(i=1; i<=mx; i+=n){
994
+ @ <li> %z(href("%R/bloblist?s=%d&n=%d",i,n))
995
+ @ %d(i)..%d(i+n-1<mx?i+n-1:mx)</a>
996
+ }
997
+ @ </ul>
998
+ style_footer();
999
+ return;
1000
+ }
1001
+ if( mx>n ){
1002
+ style_submenu_element("Index", "Index", "bloblist");
1003
+ }
1004
+ zRange = mprintf("BETWEEN %d AND %d", s, s+n-1);
1005
+ describe_artifacts(zRange);
1006
+ db_prepare(&q,
1007
+ "SELECT rid, uuid, summary, isPrivate FROM description ORDER BY rid"
1008
+ );
1009
+ @ <table cellpadding="0" cellspacing="0">
1010
+ while( db_step(&q)==SQLITE_ROW ){
1011
+ int rid = db_column_int(&q,0);
1012
+ const char *zUuid = db_column_text(&q, 1);
1013
+ const char *zDesc = db_column_text(&q, 2);
1014
+ int isPriv = db_column_int(&q,2);
1015
+ @ <tr><td align="right">%d(rid)</td>
1016
+ @ <td>&nbsp;%z(href("%R/info/%s",zUuid))%s(zUuid)</a>&nbsp;</td>
1017
+ @ <td align="left">%h(zDesc)</td>
1018
+ if( isPriv ){
1019
+ @ <td>(unpublished)</td>
1020
+ }
1021
+ @ </tr>
1022
+ }
1023
+ @ </table>
1024
+ db_finalize(&q);
1025
+ style_footer();
1026
+}
1027
+
1028
+/*
1029
+** COMMAND: test-unsent
1030
+**
1031
+** Usage: %fossil test-unsent
1032
+**
1033
+** Show all artifacts in the unsent table
1034
+*/
1035
+void test_unsent_cmd(void){
1036
+ db_find_and_open_repository(0,0);
1037
+ describe_artifacts_to_stdout("IN unsent", 0);
1038
+}
1039
+
1040
+/*
1041
+** COMMAND: test-unclustered
1042
+**
1043
+** Usage: %fossil test-unclustered
1044
+**
1045
+** Show all artifacts in the unclustered table
1046
+*/
1047
+void test_unclusterd_cmd(void){
1048
+ db_find_and_open_repository(0,0);
1049
+ describe_artifacts_to_stdout("IN unclustered", 0);
1050
+}
1051
+
1052
+/*
1053
+** COMMAND: test-phantoms
1054
+**
1055
+** Usage: %fossil test-phantoms
1056
+**
1057
+** Show all phantom artifacts
1058
+*/
1059
+void test_phatoms_cmd(void){
1060
+ db_find_and_open_repository(0,0);
1061
+ describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1062
+}
7621063
7631064
ADDED src/publish.c
7641065
ADDED src/purge.c
--- src/name.c
+++ src/name.c
@@ -42,10 +42,44 @@
42 if( z[7]!='-') return 0;
43 if( !fossil_isdigit(z[8]) ) return 0;
44 if( !fossil_isdigit(z[9]) ) return 0;
45 return 1;
46 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
48 /*
49 ** Convert a symbolic name into a RID. Acceptable forms:
50 **
51 ** * SHA1 hash
@@ -66,20 +100,28 @@
66 ** Return the RID of the matching artifact. Or return 0 if the name does not
67 ** match any known object. Or return -1 if the name is ambiguous.
68 **
69 ** The zType parameter specifies the type of artifact: ci, t, w, e, g.
70 ** If zType is NULL or "" or "*" then any type of artifact will serve.
 
 
71 ** zType is "ci" in most use cases since we are usually searching for
72 ** a check-in.
73 */
74 int symbolic_name_to_rid(const char *zTag, const char *zType){
75 int vid;
76 int rid = 0;
77 int nTag;
78 int i;
 
79
80 if( zType==0 || zType[0]==0 ) zType = "*";
 
 
 
 
 
81 if( zTag==0 || zTag[0]==0 ) return 0;
82
83 /* special keyword: "tip" */
84 if( fossil_strcmp(zTag, "tip")==0 && (zType[0]=='*' || zType[0]=='c') ){
85 rid = db_int(0,
@@ -151,41 +193,18 @@
151 " AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
152 " AND event.objid=tagxref.rid "
153 " AND event.type GLOB '%q'",
154 &zTag[4], zType
155 );
 
156 return rid;
157 }
158
159 /* root:TAG -> The origin of the branch */
160 if( memcmp(zTag, "root:", 5)==0 ){
161 Stmt q;
162 int rc;
163 char *zBr;
164 rid = symbolic_name_to_rid(zTag+5, zType);
165 zBr = db_text("trunk","SELECT value FROM tagxref"
166 " WHERE rid=%d AND tagid=%d"
167 " AND tagtype>0",
168 rid, TAG_BRANCH);
169 db_prepare(&q,
170 "SELECT pid, EXISTS(SELECT 1 FROM tagxref"
171 " WHERE tagid=%d AND tagtype>0"
172 " AND value=%Q AND rid=plink.pid)"
173 " FROM plink"
174 " WHERE cid=:cid AND isprim",
175 TAG_BRANCH, zBr
176 );
177 fossil_free(zBr);
178 do{
179 db_reset(&q);
180 db_bind_int(&q, ":cid", rid);
181 rc = db_step(&q);
182 if( rc!=SQLITE_ROW ) break;
183 rid = db_column_int(&q, 0);
184 }while( db_column_int(&q, 1)==1 && rid>0 );
185 db_finalize(&q);
186 return rid;
187 }
188
189 /* symbolic-name ":" date-time */
190 nTag = strlen(zTag);
191 for(i=0; i<nTag-10 && zTag[i]!=':'; i++){}
@@ -245,11 +264,14 @@
245 " AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
246 " AND event.objid=tagxref.rid "
247 " AND event.type GLOB '%q'",
248 zTag, zType
249 );
250 if( rid>0 ) return rid;
 
 
 
251
252 /* Undocumented: numeric tags get translated directly into the RID */
253 if( memcmp(zTag, "rid:", 4)==0 ){
254 zTag += 4;
255 for(i=0; fossil_isdigit(zTag[i]); i++){}
@@ -324,30 +346,25 @@
324 ** name_collisions searches through events, blobs, and tickets for
325 ** collisions of a given UUID based on its length on UUIDs no shorter
326 ** than 4 characters in length.
327 */
328 int name_collisions(const char *zName){
329 Stmt q;
330 int c = 0; /* count of collisions for zName */
331 int nLen; /* length of zName */
332 nLen = strlen(zName);
333 if( nLen>=4 && nLen<=UUID_SIZE && validate16(zName, nLen) ){
334 db_prepare(&q,
335 "SELECT count(uuid) FROM"
336 " (SELECT substr(tkt_uuid, 1, %d) AS uuid FROM ticket"
337 " UNION ALL SELECT * FROM"
338 " (SELECT substr(tagname, 7, %d) FROM"
339 " tag WHERE tagname GLOB 'event-*')"
340 " UNION ALL SELECT * FROM"
341 " (SELECT substr(uuid, 1, %d) FROM blob))"
342 " WHERE uuid GLOB '%q*'"
343 " GROUP BY uuid HAVING count(uuid) > 1;",
344 nLen, nLen, nLen, zName);
345 if( db_step(&q)==SQLITE_ROW ){
346 c = db_column_int(&q, 0);
347 }
348 db_finalize(&q);
349 }
350 return c;
351 }
352
353 /*
@@ -391,18 +408,15 @@
391 int rid;
392
393 if( zName==0 || zName[0]==0 ) return 0;
394 rid = symbolic_name_to_rid(zName, zType);
395 if( rid<0 ){
396 fossil_error(1, "ambiguous name: %s", zName);
397 return 0;
398 }else if( rid==0 ){
399 fossil_error(1, "not found: %s", zName);
400 return 0;
401 }else{
402 return rid;
403 }
 
404 }
405 int name_to_rid(const char *zName){
406 return name_to_typed_rid(zName, "*");
407 }
408
@@ -505,11 +519,11 @@
505 }
506
507 /*
508 ** Generate a description of artifact "rid"
509 */
510 static void whatis_rid(int rid, int verboseFlag){
511 Stmt q;
512 int cnt;
513
514 /* Basic information about the object. */
515 db_prepare(&q,
@@ -657,21 +671,23 @@
657 void whatis_cmd(void){
658 int rid;
659 const char *zName;
660 int verboseFlag;
661 int i;
 
662 db_find_and_open_repository(0,0);
663 verboseFlag = find_option("verbose","v",0)!=0;
 
664
665 /* We should be done with options.. */
666 verify_all_options();
667
668 if( g.argc<3 ) usage("whatis NAME ...");
669 for(i=2; i<g.argc; i++){
670 zName = g.argv[i];
671 if( i>2 ) fossil_print("%.79c\n",'-');
672 rid = symbolic_name_to_rid(zName, 0);
673 if( rid<0 ){
674 Stmt q;
675 int cnt = 0;
676 fossil_print("name: %s (ambiguous)\n", zName);
677 db_prepare(&q,
@@ -757,5 +773,290 @@
757 while( db_step(&q)==SQLITE_ROW ){
758 fossil_print("%s\n", db_column_text(&q, 0));
759 }
760 db_finalize(&q);
761 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
763 DDED src/publish.c
764 DDED src/purge.c
--- src/name.c
+++ src/name.c
@@ -42,10 +42,44 @@
42 if( z[7]!='-') return 0;
43 if( !fossil_isdigit(z[8]) ) return 0;
44 if( !fossil_isdigit(z[9]) ) return 0;
45 return 1;
46 }
47
48 /*
49 ** Return the RID that is the "root" of the branch that contains
50 ** check-in "rid" if inBranch==0 or the first check-in in the branch
51 ** if inBranch==1.
52 */
53 int start_of_branch(int rid, int inBranch){
54 Stmt q;
55 int rc;
56 char *zBr;
57 zBr = db_text("trunk","SELECT value FROM tagxref"
58 " WHERE rid=%d AND tagid=%d"
59 " AND tagtype>0",
60 rid, TAG_BRANCH);
61 db_prepare(&q,
62 "SELECT pid, EXISTS(SELECT 1 FROM tagxref"
63 " WHERE tagid=%d AND tagtype>0"
64 " AND value=%Q AND rid=plink.pid)"
65 " FROM plink"
66 " WHERE cid=:cid AND isprim",
67 TAG_BRANCH, zBr
68 );
69 fossil_free(zBr);
70 do{
71 db_reset(&q);
72 db_bind_int(&q, ":cid", rid);
73 rc = db_step(&q);
74 if( rc!=SQLITE_ROW ) break;
75 if( inBranch && db_column_int(&q,1)==0 ) break;
76 rid = db_column_int(&q, 0);
77 }while( db_column_int(&q, 1)==1 && rid>0 );
78 db_finalize(&q);
79 return rid;
80 }
81
82 /*
83 ** Convert a symbolic name into a RID. Acceptable forms:
84 **
85 ** * SHA1 hash
@@ -66,20 +100,28 @@
100 ** Return the RID of the matching artifact. Or return 0 if the name does not
101 ** match any known object. Or return -1 if the name is ambiguous.
102 **
103 ** The zType parameter specifies the type of artifact: ci, t, w, e, g.
104 ** If zType is NULL or "" or "*" then any type of artifact will serve.
105 ** If zType is "br" then find the first check-in of the named branch
106 ** rather than the last.
107 ** zType is "ci" in most use cases since we are usually searching for
108 ** a check-in.
109 */
110 int symbolic_name_to_rid(const char *zTag, const char *zType){
111 int vid;
112 int rid = 0;
113 int nTag;
114 int i;
115 int startOfBranch = 0;
116
117 if( zType==0 || zType[0]==0 ){
118 zType = "*";
119 }else if( zType[0]=='b' ){
120 zType = "ci";
121 startOfBranch = 1;
122 }
123 if( zTag==0 || zTag[0]==0 ) return 0;
124
125 /* special keyword: "tip" */
126 if( fossil_strcmp(zTag, "tip")==0 && (zType[0]=='*' || zType[0]=='c') ){
127 rid = db_int(0,
@@ -151,41 +193,18 @@
193 " AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
194 " AND event.objid=tagxref.rid "
195 " AND event.type GLOB '%q'",
196 &zTag[4], zType
197 );
198 if( startOfBranch ) rid = start_of_branch(rid,1);
199 return rid;
200 }
201
202 /* root:TAG -> The origin of the branch */
203 if( memcmp(zTag, "root:", 5)==0 ){
 
 
 
204 rid = symbolic_name_to_rid(zTag+5, zType);
205 return start_of_branch(rid, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206 }
207
208 /* symbolic-name ":" date-time */
209 nTag = strlen(zTag);
210 for(i=0; i<nTag-10 && zTag[i]!=':'; i++){}
@@ -245,11 +264,14 @@
264 " AND tagxref.tagid=tag.tagid AND tagxref.tagtype>0 "
265 " AND event.objid=tagxref.rid "
266 " AND event.type GLOB '%q'",
267 zTag, zType
268 );
269 if( rid>0 ){
270 if( startOfBranch ) rid = start_of_branch(rid,1);
271 return rid;
272 }
273
274 /* Undocumented: numeric tags get translated directly into the RID */
275 if( memcmp(zTag, "rid:", 4)==0 ){
276 zTag += 4;
277 for(i=0; fossil_isdigit(zTag[i]); i++){}
@@ -324,30 +346,25 @@
346 ** name_collisions searches through events, blobs, and tickets for
347 ** collisions of a given UUID based on its length on UUIDs no shorter
348 ** than 4 characters in length.
349 */
350 int name_collisions(const char *zName){
 
351 int c = 0; /* count of collisions for zName */
352 int nLen; /* length of zName */
353 nLen = strlen(zName);
354 if( nLen>=4 && nLen<=UUID_SIZE && validate16(zName, nLen) ){
355 c = db_int(0,
356 "SELECT"
357 " (SELECT count(*) FROM ticket"
358 " WHERE tkt_uuid GLOB '%q*') +"
359 " (SELECT count(*) FROM tag"
360 " WHERE tagname GLOB 'event-%q*') +"
361 " (SELECT count(*) FROM blob"
362 " WHERE uuid GLOB '%q*');",
363 zName, zName, zName
364 );
365 if( c<2 ) c = 0;
 
 
 
 
366 }
367 return c;
368 }
369
370 /*
@@ -391,18 +408,15 @@
408 int rid;
409
410 if( zName==0 || zName[0]==0 ) return 0;
411 rid = symbolic_name_to_rid(zName, zType);
412 if( rid<0 ){
413 fossil_fatal("ambiguous name: %s", zName);
 
414 }else if( rid==0 ){
415 fossil_fatal("not found: %s", zName);
 
 
 
416 }
417 return rid;
418 }
419 int name_to_rid(const char *zName){
420 return name_to_typed_rid(zName, "*");
421 }
422
@@ -505,11 +519,11 @@
519 }
520
521 /*
522 ** Generate a description of artifact "rid"
523 */
524 void whatis_rid(int rid, int verboseFlag){
525 Stmt q;
526 int cnt;
527
528 /* Basic information about the object. */
529 db_prepare(&q,
@@ -657,21 +671,23 @@
671 void whatis_cmd(void){
672 int rid;
673 const char *zName;
674 int verboseFlag;
675 int i;
676 const char *zType = 0;
677 db_find_and_open_repository(0,0);
678 verboseFlag = find_option("verbose","v",0)!=0;
679 zType = find_option("type",0,1);
680
681 /* We should be done with options.. */
682 verify_all_options();
683
684 if( g.argc<3 ) usage("whatis NAME ...");
685 for(i=2; i<g.argc; i++){
686 zName = g.argv[i];
687 if( i>2 ) fossil_print("%.79c\n",'-');
688 rid = symbolic_name_to_rid(zName, zType);
689 if( rid<0 ){
690 Stmt q;
691 int cnt = 0;
692 fossil_print("name: %s (ambiguous)\n", zName);
693 db_prepare(&q,
@@ -757,5 +773,290 @@
773 while( db_step(&q)==SQLITE_ROW ){
774 fossil_print("%s\n", db_column_text(&q, 0));
775 }
776 db_finalize(&q);
777 }
778
779 /*
780 ** Schema for the description table
781 */
782 static const char zDescTab[] =
783 @ CREATE TEMP TABLE IF NOT EXISTS description(
784 @ rid INTEGER PRIMARY KEY, -- RID of the object
785 @ uuid TEXT, -- SHA1 hash of the object
786 @ ctime DATETIME, -- Time of creation
787 @ isPrivate BOOLEAN DEFAULT 0, -- True for unpublished artifacts
788 @ type TEXT, -- file, checkin, wiki, ticket, etc.
789 @ summary TEXT, -- Summary comment for the object
790 @ detail TEXT -- filename, checkin comment, etc
791 @ );
792 ;
793
794 /*
795 ** Create the description table if it does not already exists.
796 ** Populate fields of this table with descriptions for all artifacts
797 ** whose RID matches the SQL expression in zWhere.
798 */
799 void describe_artifacts(const char *zWhere){
800 db_multi_exec("%s", zDescTab/*safe-for-%s*/);
801
802 /* Describe checkins */
803 db_multi_exec(
804 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
805 "SELECT blob.rid, blob.uuid, event.mtime, 'checkin',\n"
806 " 'checkin on ' || strftime('%%Y-%%m-%%d %%H:%%M',event.mtime)\n"
807 " FROM event, blob\n"
808 " WHERE (event.objid %s) AND event.type='ci'\n"
809 " AND event.objid=blob.rid;",
810 zWhere /*safe-for-%s*/
811 );
812
813 /* Describe files */
814 db_multi_exec(
815 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
816 "SELECT blob.rid, blob.uuid, event.mtime, 'file', 'file '||filename.name\n"
817 " FROM mlink, blob, event, filename\n"
818 " WHERE (mlink.fid %s)\n"
819 " AND mlink.mid=event.objid\n"
820 " AND filename.fnid=mlink.fnid\n"
821 " AND mlink.fid=blob.rid;",
822 zWhere /*safe-for-%s*/
823 );
824
825 /* Describe tags */
826 db_multi_exec(
827 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
828 "SELECT blob.rid, blob.uuid, tagxref.mtime, 'tag',\n"
829 " 'tag '||substr((SELECT uuid FROM blob WHERE rid=tagxref.rid),1,16)\n"
830 " FROM tagxref, blob\n"
831 " WHERE (tagxref.srcid %s) AND tagxref.srcid!=tagxref.rid\n"
832 " AND tagxref.srcid=blob.rid;",
833 zWhere /*safe-for-%s*/
834 );
835
836 /* Cluster artifacts */
837 db_multi_exec(
838 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
839 "SELECT blob.rid, blob.uuid, tagxref.mtime, 'cluster', 'cluster'\n"
840 " FROM tagxref, blob\n"
841 " WHERE (tagxref.rid %s)\n"
842 " AND tagxref.tagid=(SELECT tagid FROM tag WHERE tagname='cluster')\n"
843 " AND blob.rid=tagxref.rid;",
844 zWhere /*safe-for-%s*/
845 );
846
847 /* Ticket change artifacts */
848 db_multi_exec(
849 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
850 "SELECT blob.rid, blob.uuid, tagxref.mtime, 'ticket',\n"
851 " 'ticket '||substr(tag.tagname,5,21)\n"
852 " FROM tagxref, tag, blob\n"
853 " WHERE (tagxref.rid %s)\n"
854 " AND tag.tagid=tagxref.tagid\n"
855 " AND tag.tagname GLOB 'tkt-*'"
856 " AND blob.rid=tagxref.rid;",
857 zWhere /*safe-for-%s*/
858 );
859
860 /* Wiki edit artifacts */
861 db_multi_exec(
862 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
863 "SELECT blob.rid, blob.uuid, tagxref.mtime, 'wiki',\n"
864 " printf('wiki \"%%s\"',substr(tag.tagname,6))\n"
865 " FROM tagxref, tag, blob\n"
866 " WHERE (tagxref.rid %s)\n"
867 " AND tag.tagid=tagxref.tagid\n"
868 " AND tag.tagname GLOB 'wiki-*'"
869 " AND blob.rid=tagxref.rid;",
870 zWhere /*safe-for-%s*/
871 );
872
873 /* Event edit artifacts */
874 db_multi_exec(
875 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
876 "SELECT blob.rid, blob.uuid, tagxref.mtime, 'event',\n"
877 " 'event '||substr(tag.tagname,7)\n"
878 " FROM tagxref, tag, blob\n"
879 " WHERE (tagxref.rid %s)\n"
880 " AND tag.tagid=tagxref.tagid\n"
881 " AND tag.tagname GLOB 'event-*'"
882 " AND blob.rid=tagxref.rid;",
883 zWhere /*safe-for-%s*/
884 );
885
886 /* Attachments */
887 db_multi_exec(
888 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
889 "SELECT blob.rid, blob.uuid, attachment.mtime, 'attach-control',\n"
890 " 'attachment-control for '||attachment.filename\n"
891 " FROM attachment, blob\n"
892 " WHERE (attachment.attachid %s)\n"
893 " AND blob.rid=attachment.attachid",
894 zWhere /*safe-for-%s*/
895 );
896 db_multi_exec(
897 "INSERT OR IGNORE INTO description(rid,uuid,ctime,type,summary)\n"
898 "SELECT blob.rid, blob.uuid, attachment.mtime, 'attachment',\n"
899 " 'attachment '||attachment.filename\n"
900 " FROM attachment, blob\n"
901 " WHERE (blob.rid %s)\n"
902 " AND blob.rid NOT IN (SELECT rid FROM description)\n"
903 " AND blob.uuid=attachment.src",
904 zWhere /*safe-for-%s*/
905 );
906
907 /* Everything else */
908 db_multi_exec(
909 "INSERT OR IGNORE INTO description(rid,uuid,type,summary)\n"
910 "SELECT blob.rid, blob.uuid,"
911 " CASE WHEN blob.size<0 THEN 'phantom' ELSE '' END,\n"
912 " 'unknown'\n"
913 " FROM blob WHERE (blob.rid %s);",
914 zWhere /*safe-for-%s*/
915 );
916
917 /* Mark private elements */
918 db_multi_exec(
919 "UPDATE description SET isPrivate=1 WHERE rid IN private"
920 );
921 }
922
923 /*
924 ** Print the content of the description table on stdout
925 */
926 int describe_artifacts_to_stdout(const char *zWhere, const char *zLabel){
927 Stmt q;
928 int cnt = 0;
929 describe_artifacts(zWhere);
930 db_prepare(&q,
931 "SELECT uuid, summary, isPrivate\n"
932 " FROM description\n"
933 " ORDER BY ctime, type;"
934 );
935 while( db_step(&q)==SQLITE_ROW ){
936 if( zLabel ){
937 fossil_print("%s\n", zLabel);
938 zLabel = 0;
939 }
940 fossil_print(" %.16s %s", db_column_text(&q,0), db_column_text(&q,1));
941 if( db_column_int(&q,2) ) fossil_print(" (unpublished)");
942 fossil_print("\n");
943 cnt++;
944 }
945 db_finalize(&q);
946 db_multi_exec("DELETE FROM description;");
947 return cnt;
948 }
949
950 /*
951 ** COMMAND: test-describe-artifacts
952 **
953 ** Usage: %fossil test-describe-artifacts [--from S] [--count N]
954 **
955 ** Display a one-line description of every artifact.
956 */
957 void test_describe_artifacts_cmd(void){
958 int iFrom = 0;
959 int iCnt = 1000000;
960 const char *z;
961 char *zRange;
962 db_find_and_open_repository(0,0);
963 z = find_option("from",0,1);
964 if( z ) iFrom = atoi(z);
965 z = find_option("count",0,1);
966 if( z ) iCnt = atoi(z);
967 zRange = mprintf("BETWEEN %d AND %d", iFrom, iFrom+iCnt-1);
968 describe_artifacts_to_stdout(zRange, 0);
969 }
970
971 /*
972 ** WEBPAGE: bloblist
973 **
974 ** Return a page showing all artifacts in the repository. Query parameters:
975 **
976 ** n=N Show N artifacts
977 ** s=S Start with artifact number S
978 */
979 void bloblist_page(void){
980 Stmt q;
981 int s = atoi(PD("s","0"));
982 int n = atoi(PD("n","5000"));
983 int mx = db_int(0, "SELECT max(rid) FROM blob");
984 char *zRange;
985
986 login_check_credentials();
987 if( !g.perm.Read ){ login_needed(); return; }
988 style_header("List Of Artifacts");
989 if( mx>n && P("s")==0 ){
990 int i;
991 @ <p>Select a range of artifacts to view:</p>
992 @ <ul>
993 for(i=1; i<=mx; i+=n){
994 @ <li> %z(href("%R/bloblist?s=%d&n=%d",i,n))
995 @ %d(i)..%d(i+n-1<mx?i+n-1:mx)</a>
996 }
997 @ </ul>
998 style_footer();
999 return;
1000 }
1001 if( mx>n ){
1002 style_submenu_element("Index", "Index", "bloblist");
1003 }
1004 zRange = mprintf("BETWEEN %d AND %d", s, s+n-1);
1005 describe_artifacts(zRange);
1006 db_prepare(&q,
1007 "SELECT rid, uuid, summary, isPrivate FROM description ORDER BY rid"
1008 );
1009 @ <table cellpadding="0" cellspacing="0">
1010 while( db_step(&q)==SQLITE_ROW ){
1011 int rid = db_column_int(&q,0);
1012 const char *zUuid = db_column_text(&q, 1);
1013 const char *zDesc = db_column_text(&q, 2);
1014 int isPriv = db_column_int(&q,2);
1015 @ <tr><td align="right">%d(rid)</td>
1016 @ <td>&nbsp;%z(href("%R/info/%s",zUuid))%s(zUuid)</a>&nbsp;</td>
1017 @ <td align="left">%h(zDesc)</td>
1018 if( isPriv ){
1019 @ <td>(unpublished)</td>
1020 }
1021 @ </tr>
1022 }
1023 @ </table>
1024 db_finalize(&q);
1025 style_footer();
1026 }
1027
1028 /*
1029 ** COMMAND: test-unsent
1030 **
1031 ** Usage: %fossil test-unsent
1032 **
1033 ** Show all artifacts in the unsent table
1034 */
1035 void test_unsent_cmd(void){
1036 db_find_and_open_repository(0,0);
1037 describe_artifacts_to_stdout("IN unsent", 0);
1038 }
1039
1040 /*
1041 ** COMMAND: test-unclustered
1042 **
1043 ** Usage: %fossil test-unclustered
1044 **
1045 ** Show all artifacts in the unclustered table
1046 */
1047 void test_unclusterd_cmd(void){
1048 db_find_and_open_repository(0,0);
1049 describe_artifacts_to_stdout("IN unclustered", 0);
1050 }
1051
1052 /*
1053 ** COMMAND: test-phantoms
1054 **
1055 ** Usage: %fossil test-phantoms
1056 **
1057 ** Show all phantom artifacts
1058 */
1059 void test_phatoms_cmd(void){
1060 db_find_and_open_repository(0,0);
1061 describe_artifacts_to_stdout("IN (SELECT rid FROM blob WHERE size<0)", 0);
1062 }
1063
1064 DDED src/publish.c
1065 DDED src/purge.c
--- a/src/publish.c
+++ b/src/publish.c
@@ -0,0 +1,2 @@
1
+/*
2
+** Copyright (c) 2014 D. Richardat
--- a/src/publish.c
+++ b/src/publish.c
@@ -0,0 +1,2 @@
 
 
--- a/src/publish.c
+++ b/src/publish.c
@@ -0,0 +1,2 @@
1 /*
2 ** Copyright (c) 2014 D. Richardat
--- a/src/purge.c
+++ b/src/purge.c
@@ -0,0 +1 @@
1
+db_n
--- a/src/purge.c
+++ b/src/purge.c
@@ -0,0 +1 @@
 
--- a/src/purge.c
+++ b/src/purge.c
@@ -0,0 +1 @@
1 db_n
+12 -7
--- src/rebuild.c
+++ src/rebuild.c
@@ -346,13 +346,14 @@
346346
rebuild_update_schema();
347347
for(;;){
348348
zTable = db_text(0,
349349
"SELECT name FROM sqlite_master /*scan*/"
350350
" WHERE type='table'"
351
- " AND name NOT IN ('blob','delta','rcvfrom','user',"
351
+ " AND name NOT IN ('admin_log', 'blob','delta','rcvfrom','user',"
352352
"'config','shun','private','reportfmt',"
353
- "'concealed','accesslog','modreq')"
353
+ "'concealed','accesslog','modreq',"
354
+ "'purgeevent','purgeitem')"
354355
" AND name NOT GLOB 'sqlite_*'"
355356
" AND name NOT GLOB 'fx_*'"
356357
);
357358
if( zTable==0 ) break;
358359
db_multi_exec("DROP TABLE %Q", zTable);
@@ -591,11 +592,11 @@
591592
reconstruct_private_table();
592593
db_multi_exec(
593594
"REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
594595
"REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
595596
"REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
596
- CONTENT_SCHEMA, AUX_SCHEMA, get_version()
597
+ CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
597598
);
598599
if( errCnt && !forceFlag ){
599600
fossil_print(
600601
"%d errors. Rolling back changes. Use --force to force a commit.\n",
601602
errCnt
@@ -829,14 +830,18 @@
829830
"DELETE FROM config WHERE name GLOB 'skin:*';"
830831
"DELETE FROM config WHERE name GLOB 'subrepo:*';"
831832
);
832833
if( bVerily ){
833834
db_multi_exec(
834
- "DELETE FROM concealed;"
835
- "UPDATE rcvfrom SET ipaddr='unknown';"
836
- "DROP TABLE IF EXISTS accesslog;"
837
- "UPDATE user SET photo=NULL, info='';"
835
+ "DELETE FROM concealed;\n"
836
+ "UPDATE rcvfrom SET ipaddr='unknown';\n"
837
+ "DROP TABLE IF EXISTS accesslog;\n"
838
+ "UPDATE user SET photo=NULL, info='';\n"
839
+ "DROP TABLE IF EXISTS purgeevent;\n"
840
+ "DROP TABLE IF EXISTS purgeitem;\n"
841
+ "DROP TABLE IF EXISTS admin_log;\n"
842
+ "DROP TABLE IF EXISTS vcache;\n"
838843
);
839844
}
840845
}
841846
if( !bNeedRebuild ){
842847
db_end_transaction(0);
843848
--- src/rebuild.c
+++ src/rebuild.c
@@ -346,13 +346,14 @@
346 rebuild_update_schema();
347 for(;;){
348 zTable = db_text(0,
349 "SELECT name FROM sqlite_master /*scan*/"
350 " WHERE type='table'"
351 " AND name NOT IN ('blob','delta','rcvfrom','user',"
352 "'config','shun','private','reportfmt',"
353 "'concealed','accesslog','modreq')"
 
354 " AND name NOT GLOB 'sqlite_*'"
355 " AND name NOT GLOB 'fx_*'"
356 );
357 if( zTable==0 ) break;
358 db_multi_exec("DROP TABLE %Q", zTable);
@@ -591,11 +592,11 @@
591 reconstruct_private_table();
592 db_multi_exec(
593 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
594 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
595 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
596 CONTENT_SCHEMA, AUX_SCHEMA, get_version()
597 );
598 if( errCnt && !forceFlag ){
599 fossil_print(
600 "%d errors. Rolling back changes. Use --force to force a commit.\n",
601 errCnt
@@ -829,14 +830,18 @@
829 "DELETE FROM config WHERE name GLOB 'skin:*';"
830 "DELETE FROM config WHERE name GLOB 'subrepo:*';"
831 );
832 if( bVerily ){
833 db_multi_exec(
834 "DELETE FROM concealed;"
835 "UPDATE rcvfrom SET ipaddr='unknown';"
836 "DROP TABLE IF EXISTS accesslog;"
837 "UPDATE user SET photo=NULL, info='';"
 
 
 
 
838 );
839 }
840 }
841 if( !bNeedRebuild ){
842 db_end_transaction(0);
843
--- src/rebuild.c
+++ src/rebuild.c
@@ -346,13 +346,14 @@
346 rebuild_update_schema();
347 for(;;){
348 zTable = db_text(0,
349 "SELECT name FROM sqlite_master /*scan*/"
350 " WHERE type='table'"
351 " AND name NOT IN ('admin_log', 'blob','delta','rcvfrom','user',"
352 "'config','shun','private','reportfmt',"
353 "'concealed','accesslog','modreq',"
354 "'purgeevent','purgeitem')"
355 " AND name NOT GLOB 'sqlite_*'"
356 " AND name NOT GLOB 'fx_*'"
357 );
358 if( zTable==0 ) break;
359 db_multi_exec("DROP TABLE %Q", zTable);
@@ -591,11 +592,11 @@
592 reconstruct_private_table();
593 db_multi_exec(
594 "REPLACE INTO config(name,value,mtime) VALUES('content-schema',%Q,now());"
595 "REPLACE INTO config(name,value,mtime) VALUES('aux-schema',%Q,now());"
596 "REPLACE INTO config(name,value,mtime) VALUES('rebuilt',%Q,now());",
597 CONTENT_SCHEMA, AUX_SCHEMA_MAX, get_version()
598 );
599 if( errCnt && !forceFlag ){
600 fossil_print(
601 "%d errors. Rolling back changes. Use --force to force a commit.\n",
602 errCnt
@@ -829,14 +830,18 @@
830 "DELETE FROM config WHERE name GLOB 'skin:*';"
831 "DELETE FROM config WHERE name GLOB 'subrepo:*';"
832 );
833 if( bVerily ){
834 db_multi_exec(
835 "DELETE FROM concealed;\n"
836 "UPDATE rcvfrom SET ipaddr='unknown';\n"
837 "DROP TABLE IF EXISTS accesslog;\n"
838 "UPDATE user SET photo=NULL, info='';\n"
839 "DROP TABLE IF EXISTS purgeevent;\n"
840 "DROP TABLE IF EXISTS purgeitem;\n"
841 "DROP TABLE IF EXISTS admin_log;\n"
842 "DROP TABLE IF EXISTS vcache;\n"
843 );
844 }
845 }
846 if( !bNeedRebuild ){
847 db_end_transaction(0);
848
+5 -3
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
4444
** a date) which can change frequently. When the content schema changes,
4545
** we have to execute special procedures to update the schema. When
4646
** the aux schema changes, all we need to do is rebuild the database.
4747
*/
4848
#define CONTENT_SCHEMA "2"
49
-#define AUX_SCHEMA "2011-04-25 19:50"
49
+#define AUX_SCHEMA_MIN "2011-04-25 19:50"
50
+#define AUX_SCHEMA_MAX "2014-11-24 20:35"
5051
5152
#endif /* INTERFACE */
5253
5354
5455
/*
@@ -80,12 +81,12 @@
8081
@ uuid TEXT UNIQUE NOT NULL, -- SHA1 hash of the content
8182
@ content BLOB, -- Compressed content of this record
8283
@ CHECK( length(uuid)==40 AND rid>0 )
8384
@ );
8485
@ CREATE TABLE delta(
85
-@ rid INTEGER PRIMARY KEY, -- Record ID
86
-@ srcid INTEGER NOT NULL REFERENCES blob -- Record holding source document
86
+@ rid INTEGER PRIMARY KEY, -- BLOB that is delta-compressed
87
+@ srcid INTEGER NOT NULL REFERENCES blob -- Baseline for delta-compression
8788
@ );
8889
@ CREATE INDEX delta_i1 ON delta(srcid);
8990
@
9091
@ -------------------------------------------------------------------------
9192
@ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
@@ -250,10 +251,11 @@
250251
@ CREATE TABLE plink(
251252
@ pid INTEGER REFERENCES blob, -- Parent manifest
252253
@ cid INTEGER REFERENCES blob, -- Child manifest
253254
@ isprim BOOLEAN, -- pid is the primary parent of cid
254255
@ mtime DATETIME, -- the date/time stamp on cid. Julian day.
256
+@ baseid INTEGER REFERENCES blob, -- Baseline if child is a delta manifest
255257
@ UNIQUE(pid, cid)
256258
@ );
257259
@ CREATE INDEX plink_i2 ON plink(cid,pid);
258260
@
259261
@ -- A "leaf" checkin is a checkin that has no children in the same
260262
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
44 ** a date) which can change frequently. When the content schema changes,
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA "2011-04-25 19:50"
 
50
51 #endif /* INTERFACE */
52
53
54 /*
@@ -80,12 +81,12 @@
80 @ uuid TEXT UNIQUE NOT NULL, -- SHA1 hash of the content
81 @ content BLOB, -- Compressed content of this record
82 @ CHECK( length(uuid)==40 AND rid>0 )
83 @ );
84 @ CREATE TABLE delta(
85 @ rid INTEGER PRIMARY KEY, -- Record ID
86 @ srcid INTEGER NOT NULL REFERENCES blob -- Record holding source document
87 @ );
88 @ CREATE INDEX delta_i1 ON delta(srcid);
89 @
90 @ -------------------------------------------------------------------------
91 @ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
@@ -250,10 +251,11 @@
250 @ CREATE TABLE plink(
251 @ pid INTEGER REFERENCES blob, -- Parent manifest
252 @ cid INTEGER REFERENCES blob, -- Child manifest
253 @ isprim BOOLEAN, -- pid is the primary parent of cid
254 @ mtime DATETIME, -- the date/time stamp on cid. Julian day.
 
255 @ UNIQUE(pid, cid)
256 @ );
257 @ CREATE INDEX plink_i2 ON plink(cid,pid);
258 @
259 @ -- A "leaf" checkin is a checkin that has no children in the same
260
--- src/schema.c
+++ src/schema.c
@@ -44,11 +44,12 @@
44 ** a date) which can change frequently. When the content schema changes,
45 ** we have to execute special procedures to update the schema. When
46 ** the aux schema changes, all we need to do is rebuild the database.
47 */
48 #define CONTENT_SCHEMA "2"
49 #define AUX_SCHEMA_MIN "2011-04-25 19:50"
50 #define AUX_SCHEMA_MAX "2014-11-24 20:35"
51
52 #endif /* INTERFACE */
53
54
55 /*
@@ -80,12 +81,12 @@
81 @ uuid TEXT UNIQUE NOT NULL, -- SHA1 hash of the content
82 @ content BLOB, -- Compressed content of this record
83 @ CHECK( length(uuid)==40 AND rid>0 )
84 @ );
85 @ CREATE TABLE delta(
86 @ rid INTEGER PRIMARY KEY, -- BLOB that is delta-compressed
87 @ srcid INTEGER NOT NULL REFERENCES blob -- Baseline for delta-compression
88 @ );
89 @ CREATE INDEX delta_i1 ON delta(srcid);
90 @
91 @ -------------------------------------------------------------------------
92 @ -- The BLOB and DELTA tables above hold the "global state" of a Fossil
@@ -250,10 +251,11 @@
251 @ CREATE TABLE plink(
252 @ pid INTEGER REFERENCES blob, -- Parent manifest
253 @ cid INTEGER REFERENCES blob, -- Child manifest
254 @ isprim BOOLEAN, -- pid is the primary parent of cid
255 @ mtime DATETIME, -- the date/time stamp on cid. Julian day.
256 @ baseid INTEGER REFERENCES blob, -- Baseline if child is a delta manifest
257 @ UNIQUE(pid, cid)
258 @ );
259 @ CREATE INDEX plink_i2 ON plink(cid,pid);
260 @
261 @ -- A "leaf" checkin is a checkin that has no children in the same
262
+53 -37
--- src/search.c
+++ src/search.c
@@ -13,27 +13,32 @@
1313
** [email protected]
1414
** http://www.hwaci.com/drh/
1515
**
1616
*******************************************************************************
1717
**
18
-** This file contains code to implement the "/doc" web page and related
19
-** pages.
18
+** This file contains code to implement a very simple search function
19
+** against timeline comments, checkin content, wiki pages, and/or tickets.
20
+**
21
+** The search is full-text like in that it is looking for words and ignores
22
+** punctuation and capitalization. But it is more akin to "grep" in that
23
+** it scans the entire corpus for the search, and it does not support the
24
+** full functionality of FTS4.
2025
*/
2126
#include "config.h"
2227
#include "search.h"
2328
#include <assert.h>
2429
2530
#if INTERFACE
2631
/*
27
-** A compiled search patter
32
+** A compiled search pattern
2833
*/
2934
struct Search {
30
- int nTerm;
31
- struct srchTerm {
32
- char *z;
33
- int n;
34
- } a[8];
35
+ int nTerm; /* Number of search terms */
36
+ struct srchTerm { /* For each search term */
37
+ char *z; /* Text */
38
+ int n; /* length */
39
+ } a[8];
3540
};
3641
#endif
3742
3843
/*
3944
** Compile a search pattern
@@ -98,43 +103,47 @@
98103
** * 10 bonus points if the first occurrence is an exact match
99104
** * 1 additional point for each subsequent match of the same word
100105
** * Extra points of two consecutive words of the pattern are consecutive
101106
** in the document
102107
*/
103
-int search_score(Search *p, const char *zDoc){
108
+int search_score(Search *p, int nDoc, const char **azDoc){
104109
int iPrev = 999;
105110
int score = 10;
106111
int iBonus = 0;
107
- int i, j;
112
+ int i, j, k;
113
+ const char *zDoc;
108114
unsigned char seen[8];
109115
110116
memset(seen, 0, sizeof(seen));
111
- if( zDoc==0 ) return score;
112
- for(i=0; zDoc[i]; i++){
113
- char c = zDoc[i];
114
- if( isBoundary[c&0xff] ) continue;
115
- for(j=0; j<p->nTerm; j++){
116
- int n = p->a[j].n;
117
- if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
118
- score += 1;
119
- if( !seen[j] ){
120
- if( isBoundary[zDoc[i+n]&0xff] ) score += 10;
121
- seen[j] = 1;
122
- }
123
- if( j==iPrev+1 ){
124
- score += iBonus;
125
- }
126
- i += n-1;
127
- iPrev = j;
128
- iBonus = 50;
129
- break;
130
- }
131
- }
132
- iBonus /= 2;
133
- while( !isBoundary[zDoc[i]&0xff] ){ i++; }
134
- }
135
-
117
+ for(k=0; k<nDoc; k++){
118
+ zDoc = azDoc[k];
119
+ if( zDoc==0 ) continue;
120
+ for(i=0; zDoc[i]; i++){
121
+ char c = zDoc[i];
122
+ if( isBoundary[c&0xff] ) continue;
123
+ for(j=0; j<p->nTerm; j++){
124
+ int n = p->a[j].n;
125
+ if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
126
+ score += 1;
127
+ if( !seen[j] ){
128
+ if( isBoundary[zDoc[i+n]&0xff] ) score += 10;
129
+ seen[j] = 1;
130
+ }
131
+ if( j==iPrev+1 ){
132
+ score += iBonus;
133
+ }
134
+ i += n-1;
135
+ iPrev = j;
136
+ iBonus = 50;
137
+ break;
138
+ }
139
+ }
140
+ iBonus /= 2;
141
+ while( !isBoundary[zDoc[i]&0xff] ){ i++; }
142
+ }
143
+ }
144
+
136145
/* Every term must be seen or else the score is zero */
137146
for(j=0; j<p->nTerm; j++){
138147
if( !seen[j] ) return 0;
139148
}
140149
@@ -149,21 +158,28 @@
149158
sqlite3_context *context,
150159
int argc,
151160
sqlite3_value **argv
152161
){
153162
Search *p = (Search*)sqlite3_user_data(context);
154
- int score = search_score(p, (const char*)sqlite3_value_text(argv[0]));
163
+ const char **azDoc;
164
+ int score;
165
+ int i;
166
+
167
+ azDoc = fossil_malloc( sizeof(const char*)*(argc+1) );
168
+ for(i=0; i<argc; i++) azDoc[i] = (const char*)sqlite3_value_text(argv[i]);
169
+ score = search_score(p, argc, azDoc);
170
+ fossil_free(azDoc);
155171
sqlite3_result_int(context, score);
156172
}
157173
158174
/*
159175
** Register the "score()" SQL function to score its input text
160176
** using the given Search object. Once this function is registered,
161177
** do not delete the Search object.
162178
*/
163179
void search_sql_setup(Search *p){
164
- sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
180
+ sqlite3_create_function(g.db, "score", -1, SQLITE_UTF8, p,
165181
search_score_sqlfunc, 0, 0);
166182
}
167183
168184
/*
169185
** Testing the search function.
170186
--- src/search.c
+++ src/search.c
@@ -13,27 +13,32 @@
13 ** [email protected]
14 ** http://www.hwaci.com/drh/
15 **
16 *******************************************************************************
17 **
18 ** This file contains code to implement the "/doc" web page and related
19 ** pages.
 
 
 
 
 
20 */
21 #include "config.h"
22 #include "search.h"
23 #include <assert.h>
24
25 #if INTERFACE
26 /*
27 ** A compiled search patter
28 */
29 struct Search {
30 int nTerm;
31 struct srchTerm {
32 char *z;
33 int n;
34 } a[8];
35 };
36 #endif
37
38 /*
39 ** Compile a search pattern
@@ -98,43 +103,47 @@
98 ** * 10 bonus points if the first occurrence is an exact match
99 ** * 1 additional point for each subsequent match of the same word
100 ** * Extra points of two consecutive words of the pattern are consecutive
101 ** in the document
102 */
103 int search_score(Search *p, const char *zDoc){
104 int iPrev = 999;
105 int score = 10;
106 int iBonus = 0;
107 int i, j;
 
108 unsigned char seen[8];
109
110 memset(seen, 0, sizeof(seen));
111 if( zDoc==0 ) return score;
112 for(i=0; zDoc[i]; i++){
113 char c = zDoc[i];
114 if( isBoundary[c&0xff] ) continue;
115 for(j=0; j<p->nTerm; j++){
116 int n = p->a[j].n;
117 if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
118 score += 1;
119 if( !seen[j] ){
120 if( isBoundary[zDoc[i+n]&0xff] ) score += 10;
121 seen[j] = 1;
122 }
123 if( j==iPrev+1 ){
124 score += iBonus;
125 }
126 i += n-1;
127 iPrev = j;
128 iBonus = 50;
129 break;
130 }
131 }
132 iBonus /= 2;
133 while( !isBoundary[zDoc[i]&0xff] ){ i++; }
134 }
135
 
 
 
136 /* Every term must be seen or else the score is zero */
137 for(j=0; j<p->nTerm; j++){
138 if( !seen[j] ) return 0;
139 }
140
@@ -149,21 +158,28 @@
149 sqlite3_context *context,
150 int argc,
151 sqlite3_value **argv
152 ){
153 Search *p = (Search*)sqlite3_user_data(context);
154 int score = search_score(p, (const char*)sqlite3_value_text(argv[0]));
 
 
 
 
 
 
 
155 sqlite3_result_int(context, score);
156 }
157
158 /*
159 ** Register the "score()" SQL function to score its input text
160 ** using the given Search object. Once this function is registered,
161 ** do not delete the Search object.
162 */
163 void search_sql_setup(Search *p){
164 sqlite3_create_function(g.db, "score", 1, SQLITE_UTF8, p,
165 search_score_sqlfunc, 0, 0);
166 }
167
168 /*
169 ** Testing the search function.
170
--- src/search.c
+++ src/search.c
@@ -13,27 +13,32 @@
13 ** [email protected]
14 ** http://www.hwaci.com/drh/
15 **
16 *******************************************************************************
17 **
18 ** This file contains code to implement a very simple search function
19 ** against timeline comments, checkin content, wiki pages, and/or tickets.
20 **
21 ** The search is full-text like in that it is looking for words and ignores
22 ** punctuation and capitalization. But it is more akin to "grep" in that
23 ** it scans the entire corpus for the search, and it does not support the
24 ** full functionality of FTS4.
25 */
26 #include "config.h"
27 #include "search.h"
28 #include <assert.h>
29
30 #if INTERFACE
31 /*
32 ** A compiled search pattern
33 */
34 struct Search {
35 int nTerm; /* Number of search terms */
36 struct srchTerm { /* For each search term */
37 char *z; /* Text */
38 int n; /* length */
39 } a[8];
40 };
41 #endif
42
43 /*
44 ** Compile a search pattern
@@ -98,43 +103,47 @@
103 ** * 10 bonus points if the first occurrence is an exact match
104 ** * 1 additional point for each subsequent match of the same word
105 ** * Extra points of two consecutive words of the pattern are consecutive
106 ** in the document
107 */
108 int search_score(Search *p, int nDoc, const char **azDoc){
109 int iPrev = 999;
110 int score = 10;
111 int iBonus = 0;
112 int i, j, k;
113 const char *zDoc;
114 unsigned char seen[8];
115
116 memset(seen, 0, sizeof(seen));
117 for(k=0; k<nDoc; k++){
118 zDoc = azDoc[k];
119 if( zDoc==0 ) continue;
120 for(i=0; zDoc[i]; i++){
121 char c = zDoc[i];
122 if( isBoundary[c&0xff] ) continue;
123 for(j=0; j<p->nTerm; j++){
124 int n = p->a[j].n;
125 if( sqlite3_strnicmp(p->a[j].z, &zDoc[i], n)==0 ){
126 score += 1;
127 if( !seen[j] ){
128 if( isBoundary[zDoc[i+n]&0xff] ) score += 10;
129 seen[j] = 1;
130 }
131 if( j==iPrev+1 ){
132 score += iBonus;
133 }
134 i += n-1;
135 iPrev = j;
136 iBonus = 50;
137 break;
138 }
139 }
140 iBonus /= 2;
141 while( !isBoundary[zDoc[i]&0xff] ){ i++; }
142 }
143 }
144
145 /* Every term must be seen or else the score is zero */
146 for(j=0; j<p->nTerm; j++){
147 if( !seen[j] ) return 0;
148 }
149
@@ -149,21 +158,28 @@
158 sqlite3_context *context,
159 int argc,
160 sqlite3_value **argv
161 ){
162 Search *p = (Search*)sqlite3_user_data(context);
163 const char **azDoc;
164 int score;
165 int i;
166
167 azDoc = fossil_malloc( sizeof(const char*)*(argc+1) );
168 for(i=0; i<argc; i++) azDoc[i] = (const char*)sqlite3_value_text(argv[i]);
169 score = search_score(p, argc, azDoc);
170 fossil_free(azDoc);
171 sqlite3_result_int(context, score);
172 }
173
174 /*
175 ** Register the "score()" SQL function to score its input text
176 ** using the given Search object. Once this function is registered,
177 ** do not delete the Search object.
178 */
179 void search_sql_setup(Search *p){
180 sqlite3_create_function(g.db, "score", -1, SQLITE_UTF8, p,
181 search_score_sqlfunc, 0, 0);
182 }
183
184 /*
185 ** Testing the search function.
186
+111 -6
--- src/setup.c
+++ src/setup.c
@@ -66,11 +66,11 @@
6666
6767
/* Make sure the header contains <base href="...">. Issue a warning
6868
** if it does not. */
6969
if( !cgi_header_contains("<base href=") ){
7070
@ <p class="generalError"><b>Configuration Error:</b> Please add
71
- @ <tt>&lt;base href="$baseurl/$current_page"&gt;</tt> after
71
+ @ <tt>&lt;base href="$secureurl/$current_page"&gt;</tt> after
7272
@ <tt>&lt;head&gt;</tt> in the <a href="setup_header">HTML header</a>!</p>
7373
}
7474
7575
@ <table border="0" cellspacing="7">
7676
setup_menu_entry("Users", "setup_ulist",
@@ -105,14 +105,16 @@
105105
"Edit HTML text for an ad unit inserted after the menu bar");
106106
setup_menu_entry("Logo", "setup_logo",
107107
"Change the logo and background images for the server");
108108
setup_menu_entry("Shunned", "shun",
109109
"Show artifacts that are shunned by this repository");
110
- setup_menu_entry("Log", "rcvfromlist",
110
+ setup_menu_entry("Artifact Receipts Log", "rcvfromlist",
111111
"A record of received artifacts and their sources");
112
- setup_menu_entry("User-Log", "access_log",
112
+ setup_menu_entry("User Log", "access_log",
113113
"A record of login attempts");
114
+ setup_menu_entry("Administrative Log", "admin_log",
115
+ "View the admin_log entries");
114116
setup_menu_entry("Stats", "stat",
115117
"Display repository statistics");
116118
setup_menu_entry("SQL", "admin_sql",
117119
"Enter raw SQL commands");
118120
setup_menu_entry("TH1", "admin_th1",
@@ -380,12 +382,14 @@
380382
}
381383
login_verify_csrf_secret();
382384
db_multi_exec(
383385
"REPLACE INTO user(uid,login,info,pw,cap,mtime) "
384386
"VALUES(nullif(%d,0),%Q,%Q,%Q,%Q,now())",
385
- uid, P("login"), P("info"), zPw, zCap
387
+ uid, zLogin, P("info"), zPw, zCap
386388
);
389
+ admin_log( "Updated user [%q] with capabilities [%q].",
390
+ zLogin, zCap );
387391
if( atoi(PD("all","0"))>0 ){
388392
Blob sql;
389393
char *zErr = 0;
390394
blob_zero(&sql);
391395
if( zOldLogin==0 ){
@@ -407,12 +411,16 @@
407411
zLogin, P("pw"), zLogin, P("info"), zCap,
408412
zOldLogin
409413
);
410414
login_group_sql(blob_str(&sql), "<li> ", " </li>\n", &zErr);
411415
blob_reset(&sql);
416
+ admin_log( "Updated user [%q] in all login groups "
417
+ "with capabilities [%q].",
418
+ zLogin, zCap );
412419
if( zErr ){
413420
style_header("User Change Error");
421
+ admin_log( "Error updating user '%q': %s'.", zLogin, zErr );
414422
@ <span class="loginError">%s(zErr)</span>
415423
@
416424
@ <p><a href="setup_uedit?id=%d(uid)">[Bummer]</a></p>
417425
style_footer();
418426
return;
@@ -862,10 +870,12 @@
862870
if( zQ ){
863871
int iQ = fossil_strcmp(zQ,"on")==0 || atoi(zQ);
864872
if( iQ!=iVal ){
865873
login_verify_csrf_secret();
866874
db_set(zVar, iQ ? "1" : "0", 0);
875
+ admin_log("Set option [%q] to [%q].",
876
+ zVar, iQ ? "on" : "off");
867877
iVal = iQ;
868878
}
869879
}
870880
@ <input type="checkbox" name="%s(zQParm)"
871881
if( iVal ){
@@ -889,12 +899,15 @@
889899
int disabled /* 1 if disabled */
890900
){
891901
const char *zVal = db_get(zVar, zDflt);
892902
const char *zQ = P(zQParm);
893903
if( zQ && fossil_strcmp(zQ,zVal)!=0 ){
904
+ const int nZQ = (int)strlen(zQ);
894905
login_verify_csrf_secret();
895906
db_set(zVar, zQ, 0);
907
+ admin_log("Set entry_attribute %Q to: %.*s%s",
908
+ zVar, 20, zQ, (nZQ>20 ? "..." : ""));
896909
zVal = zQ;
897910
}
898911
@ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" size="%d(width)"
899912
if( disabled ){
900913
@ disabled="disabled"
@@ -915,12 +928,15 @@
915928
int disabled /* 1 if the textarea should not be editable */
916929
){
917930
const char *z = db_get(zVar, (char*)zDflt);
918931
const char *zQ = P(zQP);
919932
if( zQ && !disabled && fossil_strcmp(zQ,z)!=0){
933
+ const int nZQ = (int)strlen(zQ);
920934
login_verify_csrf_secret();
921935
db_set(zVar, zQ, 0);
936
+ admin_log("Set textarea_attribute %Q to: %.*s%s",
937
+ zVar, 20, zQ, (nZQ>20 ? "..." : ""));
922938
z = zQ;
923939
}
924940
if( rows>0 && cols>0 ){
925941
@ <textarea id="id%s(zQP)" name="%s(zQP)" rows="%d(rows)"
926942
if( disabled ){
@@ -946,12 +962,15 @@
946962
){
947963
const char *z = db_get(zVar, (char*)zDflt);
948964
const char *zQ = P(zQP);
949965
int i;
950966
if( zQ && fossil_strcmp(zQ,z)!=0){
967
+ const int nZQ = (int)strlen(zQ);
951968
login_verify_csrf_secret();
952969
db_set(zVar, zQ, 0);
970
+ admin_log("Set multiple_choice_attribute %Q to: %.*s%s",
971
+ zVar, 20, zQ, (nZQ>20 ? "..." : ""));
953972
z = zQ;
954973
}
955974
@ <select size="1" name="%s(zQP)" id="id%s(zQP)">
956975
for(i=0; i<nChoice*2; i+=2){
957976
const char *zSel = fossil_strcmp(azChoice[i],z)==0 ? " selected" : "";
@@ -972,10 +991,18 @@
972991
973992
style_header("Access Control Settings");
974993
db_begin_transaction();
975994
@ <form action="%s(g.zTop)/setup_access" method="post"><div>
976995
login_insert_csrf_secret();
996
+ @ <hr />
997
+ onoff_attribute("Redirect to HTTPS on the Login page",
998
+ "redirect-to-https", "redirhttps", 0, 0);
999
+ @ <p>When selected, force the use of HTTPS for the Login page.
1000
+ @ <p>Details: When enabled, this option causes the $secureurl TH1
1001
+ @ variable is set to an "https:" variant of $baseurl. Otherwise,
1002
+ @ $secureurl is just an alias for $baseurl. Also when enabled, the
1003
+ @ Login page redirects to https if accessed via http.
9771004
@ <hr />
9781005
onoff_attribute("Require password for local access",
9791006
"localauth", "localauth", 0, 0);
9801007
@ <p>When enabled, the password sign-in is always required for
9811008
@ web access. When disabled, unrestricted web access from 127.0.0.1
@@ -1551,11 +1578,11 @@
15511578
char *zHead = strstr(z, "<head>");
15521579
if( strstr(z, "<base href=")==0 && zHead!=0 ){
15531580
char *zNew;
15541581
char *zTail = &zHead[6];
15551582
while( fossil_isspace(zTail[0]) ) zTail++;
1556
- zNew = mprintf("%.*s\n<base href=\"$baseurl/$current_page\" />\n%s",
1583
+ zNew = mprintf("%.*s\n<base href=\"$secureurl/$current_page\" />\n%s",
15571584
zHead+6-z, z, zTail);
15581585
cgi_replace_parameter("header", zNew);
15591586
db_set("header", zNew, 0);
15601587
}
15611588
}
@@ -1565,11 +1592,11 @@
15651592
15661593
/* Make sure the header contains <base href="...">. Issue a warning
15671594
** if it does not. */
15681595
if( !cgi_header_contains("<base href=") ){
15691596
@ <p class="generalError">Please add
1570
- @ <tt>&lt;base href="$baseurl/$current_page"&gt;</tt> after
1597
+ @ <tt>&lt;base href="$secureurl/$current_page"&gt;</tt> after
15711598
@ <tt>&lt;head&gt;</tt> in the header!
15721599
@ <input type="submit" name="fixbase" value="Add &lt;base&gt; Now"></p>
15731600
}
15741601
15751602
login_insert_csrf_secret();
@@ -2015,5 +2042,83 @@
20152042
@ <pre class="th1error">%h(zR)</pre>
20162043
}
20172044
}
20182045
style_footer();
20192046
}
2047
+
2048
+static void admin_log_render_limits(){
2049
+ int const count = db_int(0,"SELECT COUNT(*) FROM admin_log");
2050
+ int i;
2051
+ int limits[] = {
2052
+ 10, 20, 50, 100, 250, 500, 0
2053
+ };
2054
+ for(i = 0; limits[i]; ++i ){
2055
+ cgi_printf("%s<a href='?n=%d'>%d</a>",
2056
+ i ? " " : "",
2057
+ limits[i], limits[i]);
2058
+ if(limits[i]>count) break;
2059
+ }
2060
+}
2061
+
2062
+/*
2063
+** WEBPAGE: admin_log
2064
+**
2065
+** Shows the contents of the admin_log table, which is only created if
2066
+** the admin-log setting is enabled. Requires Admin or Setup ('a' or
2067
+** 's') permissions.
2068
+*/
2069
+void page_admin_log(){
2070
+ Stmt stLog = empty_Stmt;
2071
+ Blob qLog = empty_blob;
2072
+ int limit;
2073
+ int fLogEnabled;
2074
+ int counter = 0;
2075
+ login_check_credentials();
2076
+ if( !g.perm.Setup && !g.perm.Admin ){
2077
+ login_needed();
2078
+ }
2079
+ style_header("Admin Log");
2080
+ create_admin_log_table();
2081
+ limit = atoi(PD("n","20"));
2082
+ fLogEnabled = db_get_boolean("admin-log", 0);
2083
+ @ <div>Admin logging is %s(fLogEnabled?"on":"off").</div>
2084
+
2085
+
2086
+ @ <div>Limit results to: <span>
2087
+ admin_log_render_limits();
2088
+ @ </span></div>
2089
+
2090
+ blob_append_sql(&qLog,
2091
+ "SELECT datetime(time,'unixepoch'), who, page, what "
2092
+ "FROM admin_log "
2093
+ "ORDER BY time DESC ");
2094
+ if(limit>0){
2095
+ @ %d(limit) Most recent entries:
2096
+ blob_append_sql(&qLog, "LIMIT %d", limit);
2097
+ }
2098
+ db_prepare(&stLog, "%s", blob_sql_text(&qLog));
2099
+ blob_reset(&qLog);
2100
+ @ <table id="adminLogTable" class="adminLogTable" width="100%%">
2101
+ @ <thead>
2102
+ @ <th>Time</th>
2103
+ @ <th>User</th>
2104
+ @ <th>Page</th>
2105
+ @ <th width="60%%">Message</th>
2106
+ @ </thead><tbody>
2107
+ while( SQLITE_ROW == db_step(&stLog) ){
2108
+ char const * zTime = db_column_text(&stLog, 0);
2109
+ char const * zUser = db_column_text(&stLog, 1);
2110
+ char const * zPage = db_column_text(&stLog, 2);
2111
+ char const * zMessage = db_column_text(&stLog, 3);
2112
+ @ <tr class="row%d(counter++%2)">
2113
+ @ <td class="adminTime">%s(zTime)</td>
2114
+ @ <td>%s(zUser)</td>
2115
+ @ <td>%s(zPage)</td>
2116
+ @ <td>%h(zMessage)</td>
2117
+ @ </tr>
2118
+ }
2119
+ @ </tbody></table>
2120
+ if(limit>0 && counter<limit){
2121
+ @ <div>%d(counter) entries shown.</div>
2122
+ }
2123
+ style_footer();
2124
+}
20202125
--- src/setup.c
+++ src/setup.c
@@ -66,11 +66,11 @@
66
67 /* Make sure the header contains <base href="...">. Issue a warning
68 ** if it does not. */
69 if( !cgi_header_contains("<base href=") ){
70 @ <p class="generalError"><b>Configuration Error:</b> Please add
71 @ <tt>&lt;base href="$baseurl/$current_page"&gt;</tt> after
72 @ <tt>&lt;head&gt;</tt> in the <a href="setup_header">HTML header</a>!</p>
73 }
74
75 @ <table border="0" cellspacing="7">
76 setup_menu_entry("Users", "setup_ulist",
@@ -105,14 +105,16 @@
105 "Edit HTML text for an ad unit inserted after the menu bar");
106 setup_menu_entry("Logo", "setup_logo",
107 "Change the logo and background images for the server");
108 setup_menu_entry("Shunned", "shun",
109 "Show artifacts that are shunned by this repository");
110 setup_menu_entry("Log", "rcvfromlist",
111 "A record of received artifacts and their sources");
112 setup_menu_entry("User-Log", "access_log",
113 "A record of login attempts");
 
 
114 setup_menu_entry("Stats", "stat",
115 "Display repository statistics");
116 setup_menu_entry("SQL", "admin_sql",
117 "Enter raw SQL commands");
118 setup_menu_entry("TH1", "admin_th1",
@@ -380,12 +382,14 @@
380 }
381 login_verify_csrf_secret();
382 db_multi_exec(
383 "REPLACE INTO user(uid,login,info,pw,cap,mtime) "
384 "VALUES(nullif(%d,0),%Q,%Q,%Q,%Q,now())",
385 uid, P("login"), P("info"), zPw, zCap
386 );
 
 
387 if( atoi(PD("all","0"))>0 ){
388 Blob sql;
389 char *zErr = 0;
390 blob_zero(&sql);
391 if( zOldLogin==0 ){
@@ -407,12 +411,16 @@
407 zLogin, P("pw"), zLogin, P("info"), zCap,
408 zOldLogin
409 );
410 login_group_sql(blob_str(&sql), "<li> ", " </li>\n", &zErr);
411 blob_reset(&sql);
 
 
 
412 if( zErr ){
413 style_header("User Change Error");
 
414 @ <span class="loginError">%s(zErr)</span>
415 @
416 @ <p><a href="setup_uedit?id=%d(uid)">[Bummer]</a></p>
417 style_footer();
418 return;
@@ -862,10 +870,12 @@
862 if( zQ ){
863 int iQ = fossil_strcmp(zQ,"on")==0 || atoi(zQ);
864 if( iQ!=iVal ){
865 login_verify_csrf_secret();
866 db_set(zVar, iQ ? "1" : "0", 0);
 
 
867 iVal = iQ;
868 }
869 }
870 @ <input type="checkbox" name="%s(zQParm)"
871 if( iVal ){
@@ -889,12 +899,15 @@
889 int disabled /* 1 if disabled */
890 ){
891 const char *zVal = db_get(zVar, zDflt);
892 const char *zQ = P(zQParm);
893 if( zQ && fossil_strcmp(zQ,zVal)!=0 ){
 
894 login_verify_csrf_secret();
895 db_set(zVar, zQ, 0);
 
 
896 zVal = zQ;
897 }
898 @ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" size="%d(width)"
899 if( disabled ){
900 @ disabled="disabled"
@@ -915,12 +928,15 @@
915 int disabled /* 1 if the textarea should not be editable */
916 ){
917 const char *z = db_get(zVar, (char*)zDflt);
918 const char *zQ = P(zQP);
919 if( zQ && !disabled && fossil_strcmp(zQ,z)!=0){
 
920 login_verify_csrf_secret();
921 db_set(zVar, zQ, 0);
 
 
922 z = zQ;
923 }
924 if( rows>0 && cols>0 ){
925 @ <textarea id="id%s(zQP)" name="%s(zQP)" rows="%d(rows)"
926 if( disabled ){
@@ -946,12 +962,15 @@
946 ){
947 const char *z = db_get(zVar, (char*)zDflt);
948 const char *zQ = P(zQP);
949 int i;
950 if( zQ && fossil_strcmp(zQ,z)!=0){
 
951 login_verify_csrf_secret();
952 db_set(zVar, zQ, 0);
 
 
953 z = zQ;
954 }
955 @ <select size="1" name="%s(zQP)" id="id%s(zQP)">
956 for(i=0; i<nChoice*2; i+=2){
957 const char *zSel = fossil_strcmp(azChoice[i],z)==0 ? " selected" : "";
@@ -972,10 +991,18 @@
972
973 style_header("Access Control Settings");
974 db_begin_transaction();
975 @ <form action="%s(g.zTop)/setup_access" method="post"><div>
976 login_insert_csrf_secret();
 
 
 
 
 
 
 
 
977 @ <hr />
978 onoff_attribute("Require password for local access",
979 "localauth", "localauth", 0, 0);
980 @ <p>When enabled, the password sign-in is always required for
981 @ web access. When disabled, unrestricted web access from 127.0.0.1
@@ -1551,11 +1578,11 @@
1551 char *zHead = strstr(z, "<head>");
1552 if( strstr(z, "<base href=")==0 && zHead!=0 ){
1553 char *zNew;
1554 char *zTail = &zHead[6];
1555 while( fossil_isspace(zTail[0]) ) zTail++;
1556 zNew = mprintf("%.*s\n<base href=\"$baseurl/$current_page\" />\n%s",
1557 zHead+6-z, z, zTail);
1558 cgi_replace_parameter("header", zNew);
1559 db_set("header", zNew, 0);
1560 }
1561 }
@@ -1565,11 +1592,11 @@
1565
1566 /* Make sure the header contains <base href="...">. Issue a warning
1567 ** if it does not. */
1568 if( !cgi_header_contains("<base href=") ){
1569 @ <p class="generalError">Please add
1570 @ <tt>&lt;base href="$baseurl/$current_page"&gt;</tt> after
1571 @ <tt>&lt;head&gt;</tt> in the header!
1572 @ <input type="submit" name="fixbase" value="Add &lt;base&gt; Now"></p>
1573 }
1574
1575 login_insert_csrf_secret();
@@ -2015,5 +2042,83 @@
2015 @ <pre class="th1error">%h(zR)</pre>
2016 }
2017 }
2018 style_footer();
2019 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2020
--- src/setup.c
+++ src/setup.c
@@ -66,11 +66,11 @@
66
67 /* Make sure the header contains <base href="...">. Issue a warning
68 ** if it does not. */
69 if( !cgi_header_contains("<base href=") ){
70 @ <p class="generalError"><b>Configuration Error:</b> Please add
71 @ <tt>&lt;base href="$secureurl/$current_page"&gt;</tt> after
72 @ <tt>&lt;head&gt;</tt> in the <a href="setup_header">HTML header</a>!</p>
73 }
74
75 @ <table border="0" cellspacing="7">
76 setup_menu_entry("Users", "setup_ulist",
@@ -105,14 +105,16 @@
105 "Edit HTML text for an ad unit inserted after the menu bar");
106 setup_menu_entry("Logo", "setup_logo",
107 "Change the logo and background images for the server");
108 setup_menu_entry("Shunned", "shun",
109 "Show artifacts that are shunned by this repository");
110 setup_menu_entry("Artifact Receipts Log", "rcvfromlist",
111 "A record of received artifacts and their sources");
112 setup_menu_entry("User Log", "access_log",
113 "A record of login attempts");
114 setup_menu_entry("Administrative Log", "admin_log",
115 "View the admin_log entries");
116 setup_menu_entry("Stats", "stat",
117 "Display repository statistics");
118 setup_menu_entry("SQL", "admin_sql",
119 "Enter raw SQL commands");
120 setup_menu_entry("TH1", "admin_th1",
@@ -380,12 +382,14 @@
382 }
383 login_verify_csrf_secret();
384 db_multi_exec(
385 "REPLACE INTO user(uid,login,info,pw,cap,mtime) "
386 "VALUES(nullif(%d,0),%Q,%Q,%Q,%Q,now())",
387 uid, zLogin, P("info"), zPw, zCap
388 );
389 admin_log( "Updated user [%q] with capabilities [%q].",
390 zLogin, zCap );
391 if( atoi(PD("all","0"))>0 ){
392 Blob sql;
393 char *zErr = 0;
394 blob_zero(&sql);
395 if( zOldLogin==0 ){
@@ -407,12 +411,16 @@
411 zLogin, P("pw"), zLogin, P("info"), zCap,
412 zOldLogin
413 );
414 login_group_sql(blob_str(&sql), "<li> ", " </li>\n", &zErr);
415 blob_reset(&sql);
416 admin_log( "Updated user [%q] in all login groups "
417 "with capabilities [%q].",
418 zLogin, zCap );
419 if( zErr ){
420 style_header("User Change Error");
421 admin_log( "Error updating user '%q': %s'.", zLogin, zErr );
422 @ <span class="loginError">%s(zErr)</span>
423 @
424 @ <p><a href="setup_uedit?id=%d(uid)">[Bummer]</a></p>
425 style_footer();
426 return;
@@ -862,10 +870,12 @@
870 if( zQ ){
871 int iQ = fossil_strcmp(zQ,"on")==0 || atoi(zQ);
872 if( iQ!=iVal ){
873 login_verify_csrf_secret();
874 db_set(zVar, iQ ? "1" : "0", 0);
875 admin_log("Set option [%q] to [%q].",
876 zVar, iQ ? "on" : "off");
877 iVal = iQ;
878 }
879 }
880 @ <input type="checkbox" name="%s(zQParm)"
881 if( iVal ){
@@ -889,12 +899,15 @@
899 int disabled /* 1 if disabled */
900 ){
901 const char *zVal = db_get(zVar, zDflt);
902 const char *zQ = P(zQParm);
903 if( zQ && fossil_strcmp(zQ,zVal)!=0 ){
904 const int nZQ = (int)strlen(zQ);
905 login_verify_csrf_secret();
906 db_set(zVar, zQ, 0);
907 admin_log("Set entry_attribute %Q to: %.*s%s",
908 zVar, 20, zQ, (nZQ>20 ? "..." : ""));
909 zVal = zQ;
910 }
911 @ <input type="text" id="%s(zQParm)" name="%s(zQParm)" value="%h(zVal)" size="%d(width)"
912 if( disabled ){
913 @ disabled="disabled"
@@ -915,12 +928,15 @@
928 int disabled /* 1 if the textarea should not be editable */
929 ){
930 const char *z = db_get(zVar, (char*)zDflt);
931 const char *zQ = P(zQP);
932 if( zQ && !disabled && fossil_strcmp(zQ,z)!=0){
933 const int nZQ = (int)strlen(zQ);
934 login_verify_csrf_secret();
935 db_set(zVar, zQ, 0);
936 admin_log("Set textarea_attribute %Q to: %.*s%s",
937 zVar, 20, zQ, (nZQ>20 ? "..." : ""));
938 z = zQ;
939 }
940 if( rows>0 && cols>0 ){
941 @ <textarea id="id%s(zQP)" name="%s(zQP)" rows="%d(rows)"
942 if( disabled ){
@@ -946,12 +962,15 @@
962 ){
963 const char *z = db_get(zVar, (char*)zDflt);
964 const char *zQ = P(zQP);
965 int i;
966 if( zQ && fossil_strcmp(zQ,z)!=0){
967 const int nZQ = (int)strlen(zQ);
968 login_verify_csrf_secret();
969 db_set(zVar, zQ, 0);
970 admin_log("Set multiple_choice_attribute %Q to: %.*s%s",
971 zVar, 20, zQ, (nZQ>20 ? "..." : ""));
972 z = zQ;
973 }
974 @ <select size="1" name="%s(zQP)" id="id%s(zQP)">
975 for(i=0; i<nChoice*2; i+=2){
976 const char *zSel = fossil_strcmp(azChoice[i],z)==0 ? " selected" : "";
@@ -972,10 +991,18 @@
991
992 style_header("Access Control Settings");
993 db_begin_transaction();
994 @ <form action="%s(g.zTop)/setup_access" method="post"><div>
995 login_insert_csrf_secret();
996 @ <hr />
997 onoff_attribute("Redirect to HTTPS on the Login page",
998 "redirect-to-https", "redirhttps", 0, 0);
999 @ <p>When selected, force the use of HTTPS for the Login page.
1000 @ <p>Details: When enabled, this option causes the $secureurl TH1
1001 @ variable is set to an "https:" variant of $baseurl. Otherwise,
1002 @ $secureurl is just an alias for $baseurl. Also when enabled, the
1003 @ Login page redirects to https if accessed via http.
1004 @ <hr />
1005 onoff_attribute("Require password for local access",
1006 "localauth", "localauth", 0, 0);
1007 @ <p>When enabled, the password sign-in is always required for
1008 @ web access. When disabled, unrestricted web access from 127.0.0.1
@@ -1551,11 +1578,11 @@
1578 char *zHead = strstr(z, "<head>");
1579 if( strstr(z, "<base href=")==0 && zHead!=0 ){
1580 char *zNew;
1581 char *zTail = &zHead[6];
1582 while( fossil_isspace(zTail[0]) ) zTail++;
1583 zNew = mprintf("%.*s\n<base href=\"$secureurl/$current_page\" />\n%s",
1584 zHead+6-z, z, zTail);
1585 cgi_replace_parameter("header", zNew);
1586 db_set("header", zNew, 0);
1587 }
1588 }
@@ -1565,11 +1592,11 @@
1592
1593 /* Make sure the header contains <base href="...">. Issue a warning
1594 ** if it does not. */
1595 if( !cgi_header_contains("<base href=") ){
1596 @ <p class="generalError">Please add
1597 @ <tt>&lt;base href="$secureurl/$current_page"&gt;</tt> after
1598 @ <tt>&lt;head&gt;</tt> in the header!
1599 @ <input type="submit" name="fixbase" value="Add &lt;base&gt; Now"></p>
1600 }
1601
1602 login_insert_csrf_secret();
@@ -2015,5 +2042,83 @@
2042 @ <pre class="th1error">%h(zR)</pre>
2043 }
2044 }
2045 style_footer();
2046 }
2047
2048 static void admin_log_render_limits(){
2049 int const count = db_int(0,"SELECT COUNT(*) FROM admin_log");
2050 int i;
2051 int limits[] = {
2052 10, 20, 50, 100, 250, 500, 0
2053 };
2054 for(i = 0; limits[i]; ++i ){
2055 cgi_printf("%s<a href='?n=%d'>%d</a>",
2056 i ? " " : "",
2057 limits[i], limits[i]);
2058 if(limits[i]>count) break;
2059 }
2060 }
2061
2062 /*
2063 ** WEBPAGE: admin_log
2064 **
2065 ** Shows the contents of the admin_log table, which is only created if
2066 ** the admin-log setting is enabled. Requires Admin or Setup ('a' or
2067 ** 's') permissions.
2068 */
2069 void page_admin_log(){
2070 Stmt stLog = empty_Stmt;
2071 Blob qLog = empty_blob;
2072 int limit;
2073 int fLogEnabled;
2074 int counter = 0;
2075 login_check_credentials();
2076 if( !g.perm.Setup && !g.perm.Admin ){
2077 login_needed();
2078 }
2079 style_header("Admin Log");
2080 create_admin_log_table();
2081 limit = atoi(PD("n","20"));
2082 fLogEnabled = db_get_boolean("admin-log", 0);
2083 @ <div>Admin logging is %s(fLogEnabled?"on":"off").</div>
2084
2085
2086 @ <div>Limit results to: <span>
2087 admin_log_render_limits();
2088 @ </span></div>
2089
2090 blob_append_sql(&qLog,
2091 "SELECT datetime(time,'unixepoch'), who, page, what "
2092 "FROM admin_log "
2093 "ORDER BY time DESC ");
2094 if(limit>0){
2095 @ %d(limit) Most recent entries:
2096 blob_append_sql(&qLog, "LIMIT %d", limit);
2097 }
2098 db_prepare(&stLog, "%s", blob_sql_text(&qLog));
2099 blob_reset(&qLog);
2100 @ <table id="adminLogTable" class="adminLogTable" width="100%%">
2101 @ <thead>
2102 @ <th>Time</th>
2103 @ <th>User</th>
2104 @ <th>Page</th>
2105 @ <th width="60%%">Message</th>
2106 @ </thead><tbody>
2107 while( SQLITE_ROW == db_step(&stLog) ){
2108 char const * zTime = db_column_text(&stLog, 0);
2109 char const * zUser = db_column_text(&stLog, 1);
2110 char const * zPage = db_column_text(&stLog, 2);
2111 char const * zMessage = db_column_text(&stLog, 3);
2112 @ <tr class="row%d(counter++%2)">
2113 @ <td class="adminTime">%s(zTime)</td>
2114 @ <td>%s(zUser)</td>
2115 @ <td>%s(zPage)</td>
2116 @ <td>%h(zMessage)</td>
2117 @ </tr>
2118 }
2119 @ </tbody></table>
2120 if(limit>0 && counter<limit){
2121 @ <div>%d(counter) entries shown.</div>
2122 }
2123 style_footer();
2124 }
2125
+185 -75
--- src/shell.c
+++ src/shell.c
@@ -170,11 +170,12 @@
170170
/* Saved resource information for the beginning of an operation */
171171
static HANDLE hProcess;
172172
static FILETIME ftKernelBegin;
173173
static FILETIME ftUserBegin;
174174
static sqlite3_int64 ftWallBegin;
175
-typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
175
+typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
176
+ LPFILETIME, LPFILETIME);
176177
static GETPROCTIMES getProcessTimesAddr = NULL;
177178
178179
/*
179180
** Check to see if we have timer support. Return 1 if necessary
180181
** support found (or found previously).
@@ -181,19 +182,20 @@
181182
*/
182183
static int hasTimer(void){
183184
if( getProcessTimesAddr ){
184185
return 1;
185186
} else {
186
- /* GetProcessTimes() isn't supported in WIN95 and some other Windows versions.
187
- ** See if the version we are running on has it, and if it does, save off
188
- ** a pointer to it and the current process handle.
187
+ /* GetProcessTimes() isn't supported in WIN95 and some other Windows
188
+ ** versions. See if the version we are running on has it, and if it
189
+ ** does, save off a pointer to it and the current process handle.
189190
*/
190191
hProcess = GetCurrentProcess();
191192
if( hProcess ){
192193
HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
193194
if( NULL != hinstLib ){
194
- getProcessTimesAddr = (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
195
+ getProcessTimesAddr =
196
+ (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
195197
if( NULL != getProcessTimesAddr ){
196198
return 1;
197199
}
198200
FreeLibrary(hinstLib);
199201
}
@@ -206,11 +208,12 @@
206208
** Begin timing an operation
207209
*/
208210
static void beginTimer(void){
209211
if( enableTimer && getProcessTimesAddr ){
210212
FILETIME ftCreation, ftExit;
211
- getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
213
+ getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
214
+ &ftKernelBegin,&ftUserBegin);
212215
ftWallBegin = timeOfDay();
213216
}
214217
}
215218
216219
/* Return the difference of two FILETIME structs in seconds */
@@ -225,11 +228,11 @@
225228
*/
226229
static void endTimer(void){
227230
if( enableTimer && getProcessTimesAddr){
228231
FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
229232
sqlite3_int64 ftWallEnd = timeOfDay();
230
- getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
233
+ getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
231234
printf("Run Time: real %.3f user %f sys %f\n",
232235
(ftWallEnd - ftWallBegin)*0.001,
233236
timeDiff(&ftUserBegin, &ftUserEnd),
234237
timeDiff(&ftKernelBegin, &ftKernelEnd));
235238
}
@@ -455,10 +458,11 @@
455458
struct ShellState {
456459
sqlite3 *db; /* The database */
457460
int echoOn; /* True to echo input commands */
458461
int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
459462
int statsOn; /* True to display memory stats before each finalize */
463
+ int scanstatsOn; /* True to display scan stats before each finalize */
460464
int outCount; /* Revert to stdout when reaching zero */
461465
int cnt; /* Number of records displayed so far */
462466
FILE *out; /* Write results here */
463467
FILE *traceOut; /* Output for sqlite3_trace() */
464468
int nErr; /* Number of errors seen */
@@ -723,11 +727,17 @@
723727
724728
/*
725729
** This is the callback routine that the shell
726730
** invokes for each row of a query result.
727731
*/
728
-static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
732
+static int shell_callback(
733
+ void *pArg,
734
+ int nArg, /* Number of result columns */
735
+ char **azArg, /* Text of each result column */
736
+ char **azCol, /* Column names */
737
+ int *aiType /* Column types */
738
+){
729739
int i;
730740
ShellState *p = (ShellState*)pArg;
731741
732742
switch( p->mode ){
733743
case MODE_Line: {
@@ -1102,61 +1112,81 @@
11021112
11031113
if( pArg && pArg->out ){
11041114
11051115
iHiwtr = iCur = -1;
11061116
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1107
- fprintf(pArg->out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr);
1117
+ fprintf(pArg->out,
1118
+ "Memory Used: %d (max %d) bytes\n",
1119
+ iCur, iHiwtr);
11081120
iHiwtr = iCur = -1;
11091121
sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1110
- fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n", iCur, iHiwtr);
1122
+ fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1123
+ iCur, iHiwtr);
11111124
if( pArg->shellFlgs & SHFLG_Pagecache ){
11121125
iHiwtr = iCur = -1;
11131126
sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1114
- fprintf(pArg->out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr);
1127
+ fprintf(pArg->out,
1128
+ "Number of Pcache Pages Used: %d (max %d) pages\n",
1129
+ iCur, iHiwtr);
11151130
}
11161131
iHiwtr = iCur = -1;
11171132
sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1118
- fprintf(pArg->out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
1133
+ fprintf(pArg->out,
1134
+ "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1135
+ iCur, iHiwtr);
11191136
if( pArg->shellFlgs & SHFLG_Scratch ){
11201137
iHiwtr = iCur = -1;
11211138
sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1122
- fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr);
1139
+ fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
1140
+ iCur, iHiwtr);
11231141
}
11241142
iHiwtr = iCur = -1;
11251143
sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1126
- fprintf(pArg->out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
1144
+ fprintf(pArg->out,
1145
+ "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1146
+ iCur, iHiwtr);
11271147
iHiwtr = iCur = -1;
11281148
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1129
- fprintf(pArg->out, "Largest Allocation: %d bytes\n", iHiwtr);
1149
+ fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1150
+ iHiwtr);
11301151
iHiwtr = iCur = -1;
11311152
sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1132
- fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n", iHiwtr);
1153
+ fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1154
+ iHiwtr);
11331155
iHiwtr = iCur = -1;
11341156
sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1135
- fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n", iHiwtr);
1157
+ fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1158
+ iHiwtr);
11361159
#ifdef YYTRACKMAXSTACKDEPTH
11371160
iHiwtr = iCur = -1;
11381161
sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1139
- fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr);
1162
+ fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1163
+ iCur, iHiwtr);
11401164
#endif
11411165
}
11421166
11431167
if( pArg && pArg->out && db ){
11441168
if( pArg->shellFlgs & SHFLG_Lookaside ){
11451169
iHiwtr = iCur = -1;
1146
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
1147
- fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
1148
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
1170
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1171
+ &iCur, &iHiwtr, bReset);
1172
+ fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
1173
+ iCur, iHiwtr);
1174
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1175
+ &iCur, &iHiwtr, bReset);
11491176
fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1150
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
1177
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1178
+ &iCur, &iHiwtr, bReset);
11511179
fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1152
- sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
1180
+ sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1181
+ &iCur, &iHiwtr, bReset);
11531182
fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
11541183
}
11551184
iHiwtr = iCur = -1;
11561185
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1157
- fprintf(pArg->out, "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1;
1186
+ fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
1187
+ iHiwtr = iCur = -1;
11581188
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
11591189
fprintf(pArg->out, "Page cache hits: %d\n", iCur);
11601190
iHiwtr = iCur = -1;
11611191
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
11621192
fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1163,29 +1193,75 @@
11631193
iHiwtr = iCur = -1;
11641194
sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
11651195
fprintf(pArg->out, "Page cache writes: %d\n", iCur);
11661196
iHiwtr = iCur = -1;
11671197
sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1168
- fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur);
1198
+ fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
11691199
iHiwtr = iCur = -1;
11701200
sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1171
- fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
1201
+ fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
11721202
}
11731203
11741204
if( pArg && pArg->out && db && pArg->pStmt ){
1175
- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
1205
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1206
+ bReset);
11761207
fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
11771208
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
11781209
fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1179
- iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1210
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
11801211
fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
11811212
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
11821213
fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
11831214
}
11841215
11851216
return 0;
11861217
}
1218
+
1219
+/*
1220
+** Display scan stats.
1221
+*/
1222
+static void display_scanstats(
1223
+ sqlite3 *db, /* Database to query */
1224
+ ShellState *pArg /* Pointer to ShellState */
1225
+){
1226
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1227
+ int i, k, n, mx;
1228
+ fprintf(pArg->out, "-------- scanstats --------\n");
1229
+ mx = 0;
1230
+ for(k=0; k<=mx; k++){
1231
+ double rEstLoop = 1.0;
1232
+ for(i=n=0; 1; i++){
1233
+ sqlite3_stmt *p = pArg->pStmt;
1234
+ sqlite3_int64 nLoop, nVisit;
1235
+ double rEst;
1236
+ int iSid;
1237
+ const char *zExplain;
1238
+ if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
1239
+ break;
1240
+ }
1241
+ sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1242
+ if( iSid>mx ) mx = iSid;
1243
+ if( iSid!=k ) continue;
1244
+ if( n==0 ){
1245
+ rEstLoop = (double)nLoop;
1246
+ if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1247
+ }
1248
+ n++;
1249
+ sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1250
+ sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1251
+ sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1252
+ fprintf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1253
+ rEstLoop *= rEst;
1254
+ fprintf(pArg->out,
1255
+ " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1256
+ nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1257
+ );
1258
+ }
1259
+ }
1260
+ fprintf(pArg->out, "---------------------------\n");
1261
+#endif
1262
+}
11871263
11881264
/*
11891265
** Parameter azArray points to a zero-terminated array of strings. zStr
11901266
** points to a single nul-terminated string. Return non-zero if zStr
11911267
** is equal, according to strcmp(), to any of the strings in the array.
@@ -1224,11 +1300,12 @@
12241300
int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
12251301
int iOp; /* Index of operation in p->aiIndent[] */
12261302
12271303
const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
12281304
"NextIfOpen", "PrevIfOpen", 0 };
1229
- const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
1305
+ const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead",
1306
+ "Rewind", 0 };
12301307
const char *azGoto[] = { "Goto", 0 };
12311308
12321309
/* Try to figure out if this is really an EXPLAIN statement. If this
12331310
** cannot be verified, return early. */
12341311
zSql = sqlite3_sql(pSql);
@@ -1337,11 +1414,12 @@
13371414
}
13381415
13391416
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
13401417
if( pArg && pArg->autoEQP ){
13411418
sqlite3_stmt *pExplain;
1342
- char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
1419
+ char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1420
+ sqlite3_sql(pStmt));
13431421
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
13441422
if( rc==SQLITE_OK ){
13451423
while( sqlite3_step(pExplain)==SQLITE_ROW ){
13461424
fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
13471425
fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1351,21 +1429,10 @@
13511429
}
13521430
sqlite3_finalize(pExplain);
13531431
sqlite3_free(zEQP);
13541432
}
13551433
1356
-#if USE_SYSTEM_SQLITE+0==1
1357
- /* Output TESTCTRL_EXPLAIN text of requested */
1358
- if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1359
- const char *zExplain = 0;
1360
- sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1361
- if( zExplain && zExplain[0] ){
1362
- fprintf(pArg->out, "%s", zExplain);
1363
- }
1364
- }
1365
-#endif
1366
-
13671434
/* If the shell is currently in ".explain" mode, gather the extra
13681435
** data required to add indents to the output.*/
13691436
if( pArg && pArg->mode==MODE_Explain ){
13701437
explain_data_prepare(pArg, pStmt);
13711438
}
@@ -1431,10 +1498,15 @@
14311498
14321499
/* print usage stats if stats on */
14331500
if( pArg && pArg->statsOn ){
14341501
display_stats(db, pArg, 0);
14351502
}
1503
+
1504
+ /* print loop-counters if required */
1505
+ if( pArg && pArg->scanstatsOn ){
1506
+ display_scanstats(db, pArg);
1507
+ }
14361508
14371509
/* Finalize the statement just executed. If this fails, save a
14381510
** copy of the error message. Otherwise, set zSql to point to the
14391511
** next statement to execute. */
14401512
rc2 = sqlite3_finalize(pStmt);
@@ -1642,10 +1714,11 @@
16421714
".prompt MAIN CONTINUE Replace the standard prompts\n"
16431715
".quit Exit this program\n"
16441716
".read FILENAME Execute SQL in FILENAME\n"
16451717
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
16461718
".save FILE Write in-memory database into FILE\n"
1719
+ ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
16471720
".schema ?TABLE? Show the CREATE statements\n"
16481721
" If TABLE specified, only show tables matching\n"
16491722
" LIKE pattern TABLE.\n"
16501723
".separator STRING ?NL? Change separator used by output mode and .import\n"
16511724
" NL is the end-of-line mark for CSV\n"
@@ -3023,10 +3096,23 @@
30233096
rc = 1;
30243097
}
30253098
sqlite3_close(pSrc);
30263099
}else
30273100
3101
+
3102
+ if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3103
+ if( nArg==2 ){
3104
+ p->scanstatsOn = booleanValue(azArg[1]);
3105
+#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3106
+ fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3107
+#endif
3108
+ }else{
3109
+ fprintf(stderr, "Usage: .scanstats on|off\n");
3110
+ rc = 1;
3111
+ }
3112
+ }else
3113
+
30283114
if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
30293115
ShellState data;
30303116
char *zErrMsg = 0;
30313117
open_db(p, 0);
30323118
memcpy(&data, p, sizeof(data));
@@ -3280,11 +3366,11 @@
32803366
if( nPrintCol<1 ) nPrintCol = 1;
32813367
nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
32823368
for(i=0; i<nPrintRow; i++){
32833369
for(j=i; j<nRow; j+=nPrintRow){
32843370
char *zSp = j<nPrintRow ? "" : " ";
3285
- fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
3371
+ fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
32863372
}
32873373
fprintf(p->out, "\n");
32883374
}
32893375
}
32903376
for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3750,11 +3836,12 @@
37503836
*/
37513837
static char *find_home_dir(void){
37523838
static char *home_dir = NULL;
37533839
if( home_dir ) return home_dir;
37543840
3755
-#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
3841
+#if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \
3842
+ && !defined(__RTP__) && !defined(_WRS_KERNEL)
37563843
{
37573844
struct passwd *pwent;
37583845
uid_t uid = getuid();
37593846
if( (pwent=getpwuid(uid)) != NULL) {
37603847
home_dir = pwent->pw_dir;
@@ -3949,14 +4036,16 @@
39494036
39504037
int main(int argc, char **argv){
39514038
char *zErrMsg = 0;
39524039
ShellState data;
39534040
const char *zInitFile = 0;
3954
- char *zFirstCmd = 0;
39554041
int i;
39564042
int rc = 0;
39574043
int warnInmemoryDb = 0;
4044
+ int readStdin = 1;
4045
+ int nCmd = 0;
4046
+ char **azCmd = 0;
39584047
39594048
#if USE_SYSTEM_SQLITE+0!=1
39604049
if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
39614050
fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
39624051
sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -3971,10 +4060,22 @@
39714060
** else is done.
39724061
*/
39734062
#ifdef SIGINT
39744063
signal(SIGINT, interrupt_handler);
39754064
#endif
4065
+
4066
+#ifdef SQLITE_SHELL_DBNAME_PROC
4067
+ {
4068
+ /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
4069
+ ** of a C-function that will provide the name of the database file. Use
4070
+ ** this compile-time option to embed this shell program in larger
4071
+ ** applications. */
4072
+ extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4073
+ SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4074
+ warnInmemoryDb = 0;
4075
+ }
4076
+#endif
39764077
39774078
/* Do an initial pass through the command-line argument to locate
39784079
** the name of the database file, the name of the initialization file,
39794080
** the size of the alternative malloc heap,
39804081
** and the first command to execute.
@@ -3983,19 +4084,22 @@
39834084
char *z;
39844085
z = argv[i];
39854086
if( z[0]!='-' ){
39864087
if( data.zDbFilename==0 ){
39874088
data.zDbFilename = z;
3988
- continue;
3989
- }
3990
- if( zFirstCmd==0 ){
3991
- zFirstCmd = z;
3992
- continue;
3993
- }
3994
- fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]);
3995
- fprintf(stderr,"Use -help for a list of options.\n");
3996
- return 1;
4089
+ }else{
4090
+ /* Excesss arguments are interpreted as SQL (or dot-commands) and
4091
+ ** mean that nothing is read from stdin */
4092
+ readStdin = 0;
4093
+ nCmd++;
4094
+ azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4095
+ if( azCmd==0 ){
4096
+ fprintf(stderr, "out of memory\n");
4097
+ exit(1);
4098
+ }
4099
+ azCmd[nCmd-1] = z;
4100
+ }
39974101
}
39984102
if( z[1]=='-' ) z++;
39994103
if( strcmp(z,"-separator")==0
40004104
|| strcmp(z,"-nullvalue")==0
40014105
|| strcmp(z,"-newline")==0
@@ -4082,15 +4186,10 @@
40824186
warnInmemoryDb = argc==1;
40834187
#else
40844188
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
40854189
return 1;
40864190
#endif
4087
-#ifdef SQLITE_SHELL_DBNAME_PROC
4088
- { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4089
- SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4090
- warnInmemoryDb = 0; }
4091
-#endif
40924191
}
40934192
data.out = stdout;
40944193
40954194
/* Go ahead and open the database file if it already exists. If the
40964195
** file does not exist, delay opening it. This prevents empty database
@@ -4149,10 +4248,12 @@
41494248
data.echoOn = 1;
41504249
}else if( strcmp(z,"-eqp")==0 ){
41514250
data.autoEQP = 1;
41524251
}else if( strcmp(z,"-stats")==0 ){
41534252
data.statsOn = 1;
4253
+ }else if( strcmp(z,"-scanstats")==0 ){
4254
+ data.scanstatsOn = 1;
41544255
}else if( strcmp(z,"-bail")==0 ){
41554256
bail_on_error = 1;
41564257
}else if( strcmp(z,"-version")==0 ){
41574258
printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
41584259
return 0;
@@ -4181,10 +4282,14 @@
41814282
i++;
41824283
#endif
41834284
}else if( strcmp(z,"-help")==0 ){
41844285
usage(1);
41854286
}else if( strcmp(z,"-cmd")==0 ){
4287
+ /* Run commands that follow -cmd first and separately from commands
4288
+ ** that simply appear on the command-line. This seems goofy. It would
4289
+ ** be better if all commands ran in the order that they appear. But
4290
+ ** we retain the goofy behavior for historical compatibility. */
41864291
if( i==argc-1 ) break;
41874292
z = cmdline_option_value(argc,argv,++i);
41884293
if( z[0]=='.' ){
41894294
rc = do_meta_command(z, &data);
41904295
if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4204,27 +4309,32 @@
42044309
fprintf(stderr,"Use -help for a list of options.\n");
42054310
return 1;
42064311
}
42074312
}
42084313
4209
- if( zFirstCmd ){
4210
- /* Run just the command that follows the database name
4211
- */
4212
- if( zFirstCmd[0]=='.' ){
4213
- rc = do_meta_command(zFirstCmd, &data);
4214
- if( rc==2 ) rc = 0;
4215
- }else{
4216
- open_db(&data, 0);
4217
- rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
4218
- if( zErrMsg!=0 ){
4219
- fprintf(stderr,"Error: %s\n", zErrMsg);
4220
- return rc!=0 ? rc : 1;
4221
- }else if( rc!=0 ){
4222
- fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
4223
- return rc;
4224
- }
4225
- }
4314
+ if( !readStdin ){
4315
+ /* Run all arguments that do not begin with '-' as if they were separate
4316
+ ** command-line inputs, except for the argToSkip argument which contains
4317
+ ** the database filename.
4318
+ */
4319
+ for(i=0; i<nCmd; i++){
4320
+ if( azCmd[i][0]=='.' ){
4321
+ rc = do_meta_command(azCmd[i], &data);
4322
+ if( rc ) return rc==2 ? 0 : rc;
4323
+ }else{
4324
+ open_db(&data, 0);
4325
+ rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4326
+ if( zErrMsg!=0 ){
4327
+ fprintf(stderr,"Error: %s\n", zErrMsg);
4328
+ return rc!=0 ? rc : 1;
4329
+ }else if( rc!=0 ){
4330
+ fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4331
+ return rc;
4332
+ }
4333
+ }
4334
+ }
4335
+ free(azCmd);
42264336
}else{
42274337
/* Run commands received from standard input
42284338
*/
42294339
if( stdin_is_interactive ){
42304340
char *zHome;
42314341
--- src/shell.c
+++ src/shell.c
@@ -170,11 +170,12 @@
170 /* Saved resource information for the beginning of an operation */
171 static HANDLE hProcess;
172 static FILETIME ftKernelBegin;
173 static FILETIME ftUserBegin;
174 static sqlite3_int64 ftWallBegin;
175 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME);
 
176 static GETPROCTIMES getProcessTimesAddr = NULL;
177
178 /*
179 ** Check to see if we have timer support. Return 1 if necessary
180 ** support found (or found previously).
@@ -181,19 +182,20 @@
181 */
182 static int hasTimer(void){
183 if( getProcessTimesAddr ){
184 return 1;
185 } else {
186 /* GetProcessTimes() isn't supported in WIN95 and some other Windows versions.
187 ** See if the version we are running on has it, and if it does, save off
188 ** a pointer to it and the current process handle.
189 */
190 hProcess = GetCurrentProcess();
191 if( hProcess ){
192 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
193 if( NULL != hinstLib ){
194 getProcessTimesAddr = (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
 
195 if( NULL != getProcessTimesAddr ){
196 return 1;
197 }
198 FreeLibrary(hinstLib);
199 }
@@ -206,11 +208,12 @@
206 ** Begin timing an operation
207 */
208 static void beginTimer(void){
209 if( enableTimer && getProcessTimesAddr ){
210 FILETIME ftCreation, ftExit;
211 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelBegin, &ftUserBegin);
 
212 ftWallBegin = timeOfDay();
213 }
214 }
215
216 /* Return the difference of two FILETIME structs in seconds */
@@ -225,11 +228,11 @@
225 */
226 static void endTimer(void){
227 if( enableTimer && getProcessTimesAddr){
228 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
229 sqlite3_int64 ftWallEnd = timeOfDay();
230 getProcessTimesAddr(hProcess, &ftCreation, &ftExit, &ftKernelEnd, &ftUserEnd);
231 printf("Run Time: real %.3f user %f sys %f\n",
232 (ftWallEnd - ftWallBegin)*0.001,
233 timeDiff(&ftUserBegin, &ftUserEnd),
234 timeDiff(&ftKernelBegin, &ftKernelEnd));
235 }
@@ -455,10 +458,11 @@
455 struct ShellState {
456 sqlite3 *db; /* The database */
457 int echoOn; /* True to echo input commands */
458 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
459 int statsOn; /* True to display memory stats before each finalize */
 
460 int outCount; /* Revert to stdout when reaching zero */
461 int cnt; /* Number of records displayed so far */
462 FILE *out; /* Write results here */
463 FILE *traceOut; /* Output for sqlite3_trace() */
464 int nErr; /* Number of errors seen */
@@ -723,11 +727,17 @@
723
724 /*
725 ** This is the callback routine that the shell
726 ** invokes for each row of a query result.
727 */
728 static int shell_callback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType){
 
 
 
 
 
 
729 int i;
730 ShellState *p = (ShellState*)pArg;
731
732 switch( p->mode ){
733 case MODE_Line: {
@@ -1102,61 +1112,81 @@
1102
1103 if( pArg && pArg->out ){
1104
1105 iHiwtr = iCur = -1;
1106 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1107 fprintf(pArg->out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1108 iHiwtr = iCur = -1;
1109 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1110 fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n", iCur, iHiwtr);
 
1111 if( pArg->shellFlgs & SHFLG_Pagecache ){
1112 iHiwtr = iCur = -1;
1113 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1114 fprintf(pArg->out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr);
 
 
1115 }
1116 iHiwtr = iCur = -1;
1117 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1118 fprintf(pArg->out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1119 if( pArg->shellFlgs & SHFLG_Scratch ){
1120 iHiwtr = iCur = -1;
1121 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1122 fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr);
 
1123 }
1124 iHiwtr = iCur = -1;
1125 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1126 fprintf(pArg->out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
 
 
1127 iHiwtr = iCur = -1;
1128 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1129 fprintf(pArg->out, "Largest Allocation: %d bytes\n", iHiwtr);
 
1130 iHiwtr = iCur = -1;
1131 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1132 fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n", iHiwtr);
 
1133 iHiwtr = iCur = -1;
1134 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1135 fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n", iHiwtr);
 
1136 #ifdef YYTRACKMAXSTACKDEPTH
1137 iHiwtr = iCur = -1;
1138 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1139 fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr);
 
1140 #endif
1141 }
1142
1143 if( pArg && pArg->out && db ){
1144 if( pArg->shellFlgs & SHFLG_Lookaside ){
1145 iHiwtr = iCur = -1;
1146 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset);
1147 fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
1148 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset);
 
 
 
1149 fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1150 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset);
 
1151 fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1152 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset);
 
1153 fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
1154 }
1155 iHiwtr = iCur = -1;
1156 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1157 fprintf(pArg->out, "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1;
 
1158 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1159 fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1160 iHiwtr = iCur = -1;
1161 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1162 fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1163,29 +1193,75 @@
1163 iHiwtr = iCur = -1;
1164 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1165 fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1166 iHiwtr = iCur = -1;
1167 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1168 fprintf(pArg->out, "Schema Heap Usage: %d bytes\n", iCur);
1169 iHiwtr = iCur = -1;
1170 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1171 fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
1172 }
1173
1174 if( pArg && pArg->out && db && pArg->pStmt ){
1175 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
 
1176 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1177 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1178 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1179 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1180 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1181 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1182 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1183 }
1184
1185 return 0;
1186 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
1188 /*
1189 ** Parameter azArray points to a zero-terminated array of strings. zStr
1190 ** points to a single nul-terminated string. Return non-zero if zStr
1191 ** is equal, according to strcmp(), to any of the strings in the array.
@@ -1224,11 +1300,12 @@
1224 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1225 int iOp; /* Index of operation in p->aiIndent[] */
1226
1227 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1228 "NextIfOpen", "PrevIfOpen", 0 };
1229 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead", "Rewind", 0 };
 
1230 const char *azGoto[] = { "Goto", 0 };
1231
1232 /* Try to figure out if this is really an EXPLAIN statement. If this
1233 ** cannot be verified, return early. */
1234 zSql = sqlite3_sql(pSql);
@@ -1337,11 +1414,12 @@
1337 }
1338
1339 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1340 if( pArg && pArg->autoEQP ){
1341 sqlite3_stmt *pExplain;
1342 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
 
1343 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1344 if( rc==SQLITE_OK ){
1345 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1346 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1347 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1351,21 +1429,10 @@
1351 }
1352 sqlite3_finalize(pExplain);
1353 sqlite3_free(zEQP);
1354 }
1355
1356 #if USE_SYSTEM_SQLITE+0==1
1357 /* Output TESTCTRL_EXPLAIN text of requested */
1358 if( pArg && pArg->mode==MODE_Explain && sqlite3_libversion_number()<3008007 ){
1359 const char *zExplain = 0;
1360 sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
1361 if( zExplain && zExplain[0] ){
1362 fprintf(pArg->out, "%s", zExplain);
1363 }
1364 }
1365 #endif
1366
1367 /* If the shell is currently in ".explain" mode, gather the extra
1368 ** data required to add indents to the output.*/
1369 if( pArg && pArg->mode==MODE_Explain ){
1370 explain_data_prepare(pArg, pStmt);
1371 }
@@ -1431,10 +1498,15 @@
1431
1432 /* print usage stats if stats on */
1433 if( pArg && pArg->statsOn ){
1434 display_stats(db, pArg, 0);
1435 }
 
 
 
 
 
1436
1437 /* Finalize the statement just executed. If this fails, save a
1438 ** copy of the error message. Otherwise, set zSql to point to the
1439 ** next statement to execute. */
1440 rc2 = sqlite3_finalize(pStmt);
@@ -1642,10 +1714,11 @@
1642 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1643 ".quit Exit this program\n"
1644 ".read FILENAME Execute SQL in FILENAME\n"
1645 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1646 ".save FILE Write in-memory database into FILE\n"
 
1647 ".schema ?TABLE? Show the CREATE statements\n"
1648 " If TABLE specified, only show tables matching\n"
1649 " LIKE pattern TABLE.\n"
1650 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1651 " NL is the end-of-line mark for CSV\n"
@@ -3023,10 +3096,23 @@
3023 rc = 1;
3024 }
3025 sqlite3_close(pSrc);
3026 }else
3027
 
 
 
 
 
 
 
 
 
 
 
 
 
3028 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
3029 ShellState data;
3030 char *zErrMsg = 0;
3031 open_db(p, 0);
3032 memcpy(&data, p, sizeof(data));
@@ -3280,11 +3366,11 @@
3280 if( nPrintCol<1 ) nPrintCol = 1;
3281 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
3282 for(i=0; i<nPrintRow; i++){
3283 for(j=i; j<nRow; j+=nPrintRow){
3284 char *zSp = j<nPrintRow ? "" : " ";
3285 fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j] : "");
3286 }
3287 fprintf(p->out, "\n");
3288 }
3289 }
3290 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3750,11 +3836,12 @@
3750 */
3751 static char *find_home_dir(void){
3752 static char *home_dir = NULL;
3753 if( home_dir ) return home_dir;
3754
3755 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) && !defined(__RTP__) && !defined(_WRS_KERNEL)
 
3756 {
3757 struct passwd *pwent;
3758 uid_t uid = getuid();
3759 if( (pwent=getpwuid(uid)) != NULL) {
3760 home_dir = pwent->pw_dir;
@@ -3949,14 +4036,16 @@
3949
3950 int main(int argc, char **argv){
3951 char *zErrMsg = 0;
3952 ShellState data;
3953 const char *zInitFile = 0;
3954 char *zFirstCmd = 0;
3955 int i;
3956 int rc = 0;
3957 int warnInmemoryDb = 0;
 
 
 
3958
3959 #if USE_SYSTEM_SQLITE+0!=1
3960 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
3961 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
3962 sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -3971,10 +4060,22 @@
3971 ** else is done.
3972 */
3973 #ifdef SIGINT
3974 signal(SIGINT, interrupt_handler);
3975 #endif
 
 
 
 
 
 
 
 
 
 
 
 
3976
3977 /* Do an initial pass through the command-line argument to locate
3978 ** the name of the database file, the name of the initialization file,
3979 ** the size of the alternative malloc heap,
3980 ** and the first command to execute.
@@ -3983,19 +4084,22 @@
3983 char *z;
3984 z = argv[i];
3985 if( z[0]!='-' ){
3986 if( data.zDbFilename==0 ){
3987 data.zDbFilename = z;
3988 continue;
3989 }
3990 if( zFirstCmd==0 ){
3991 zFirstCmd = z;
3992 continue;
3993 }
3994 fprintf(stderr,"%s: Error: too many options: \"%s\"\n", Argv0, argv[i]);
3995 fprintf(stderr,"Use -help for a list of options.\n");
3996 return 1;
 
 
 
3997 }
3998 if( z[1]=='-' ) z++;
3999 if( strcmp(z,"-separator")==0
4000 || strcmp(z,"-nullvalue")==0
4001 || strcmp(z,"-newline")==0
@@ -4082,15 +4186,10 @@
4082 warnInmemoryDb = argc==1;
4083 #else
4084 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4085 return 1;
4086 #endif
4087 #ifdef SQLITE_SHELL_DBNAME_PROC
4088 { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4089 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4090 warnInmemoryDb = 0; }
4091 #endif
4092 }
4093 data.out = stdout;
4094
4095 /* Go ahead and open the database file if it already exists. If the
4096 ** file does not exist, delay opening it. This prevents empty database
@@ -4149,10 +4248,12 @@
4149 data.echoOn = 1;
4150 }else if( strcmp(z,"-eqp")==0 ){
4151 data.autoEQP = 1;
4152 }else if( strcmp(z,"-stats")==0 ){
4153 data.statsOn = 1;
 
 
4154 }else if( strcmp(z,"-bail")==0 ){
4155 bail_on_error = 1;
4156 }else if( strcmp(z,"-version")==0 ){
4157 printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
4158 return 0;
@@ -4181,10 +4282,14 @@
4181 i++;
4182 #endif
4183 }else if( strcmp(z,"-help")==0 ){
4184 usage(1);
4185 }else if( strcmp(z,"-cmd")==0 ){
 
 
 
 
4186 if( i==argc-1 ) break;
4187 z = cmdline_option_value(argc,argv,++i);
4188 if( z[0]=='.' ){
4189 rc = do_meta_command(z, &data);
4190 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4204,27 +4309,32 @@
4204 fprintf(stderr,"Use -help for a list of options.\n");
4205 return 1;
4206 }
4207 }
4208
4209 if( zFirstCmd ){
4210 /* Run just the command that follows the database name
4211 */
4212 if( zFirstCmd[0]=='.' ){
4213 rc = do_meta_command(zFirstCmd, &data);
4214 if( rc==2 ) rc = 0;
4215 }else{
4216 open_db(&data, 0);
4217 rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
4218 if( zErrMsg!=0 ){
4219 fprintf(stderr,"Error: %s\n", zErrMsg);
4220 return rc!=0 ? rc : 1;
4221 }else if( rc!=0 ){
4222 fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
4223 return rc;
4224 }
4225 }
 
 
 
 
 
4226 }else{
4227 /* Run commands received from standard input
4228 */
4229 if( stdin_is_interactive ){
4230 char *zHome;
4231
--- src/shell.c
+++ src/shell.c
@@ -170,11 +170,12 @@
170 /* Saved resource information for the beginning of an operation */
171 static HANDLE hProcess;
172 static FILETIME ftKernelBegin;
173 static FILETIME ftUserBegin;
174 static sqlite3_int64 ftWallBegin;
175 typedef BOOL (WINAPI *GETPROCTIMES)(HANDLE, LPFILETIME, LPFILETIME,
176 LPFILETIME, LPFILETIME);
177 static GETPROCTIMES getProcessTimesAddr = NULL;
178
179 /*
180 ** Check to see if we have timer support. Return 1 if necessary
181 ** support found (or found previously).
@@ -181,19 +182,20 @@
182 */
183 static int hasTimer(void){
184 if( getProcessTimesAddr ){
185 return 1;
186 } else {
187 /* GetProcessTimes() isn't supported in WIN95 and some other Windows
188 ** versions. See if the version we are running on has it, and if it
189 ** does, save off a pointer to it and the current process handle.
190 */
191 hProcess = GetCurrentProcess();
192 if( hProcess ){
193 HINSTANCE hinstLib = LoadLibrary(TEXT("Kernel32.dll"));
194 if( NULL != hinstLib ){
195 getProcessTimesAddr =
196 (GETPROCTIMES) GetProcAddress(hinstLib, "GetProcessTimes");
197 if( NULL != getProcessTimesAddr ){
198 return 1;
199 }
200 FreeLibrary(hinstLib);
201 }
@@ -206,11 +208,12 @@
208 ** Begin timing an operation
209 */
210 static void beginTimer(void){
211 if( enableTimer && getProcessTimesAddr ){
212 FILETIME ftCreation, ftExit;
213 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,
214 &ftKernelBegin,&ftUserBegin);
215 ftWallBegin = timeOfDay();
216 }
217 }
218
219 /* Return the difference of two FILETIME structs in seconds */
@@ -225,11 +228,11 @@
228 */
229 static void endTimer(void){
230 if( enableTimer && getProcessTimesAddr){
231 FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd;
232 sqlite3_int64 ftWallEnd = timeOfDay();
233 getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd);
234 printf("Run Time: real %.3f user %f sys %f\n",
235 (ftWallEnd - ftWallBegin)*0.001,
236 timeDiff(&ftUserBegin, &ftUserEnd),
237 timeDiff(&ftKernelBegin, &ftKernelEnd));
238 }
@@ -455,10 +458,11 @@
458 struct ShellState {
459 sqlite3 *db; /* The database */
460 int echoOn; /* True to echo input commands */
461 int autoEQP; /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
462 int statsOn; /* True to display memory stats before each finalize */
463 int scanstatsOn; /* True to display scan stats before each finalize */
464 int outCount; /* Revert to stdout when reaching zero */
465 int cnt; /* Number of records displayed so far */
466 FILE *out; /* Write results here */
467 FILE *traceOut; /* Output for sqlite3_trace() */
468 int nErr; /* Number of errors seen */
@@ -723,11 +727,17 @@
727
728 /*
729 ** This is the callback routine that the shell
730 ** invokes for each row of a query result.
731 */
732 static int shell_callback(
733 void *pArg,
734 int nArg, /* Number of result columns */
735 char **azArg, /* Text of each result column */
736 char **azCol, /* Column names */
737 int *aiType /* Column types */
738 ){
739 int i;
740 ShellState *p = (ShellState*)pArg;
741
742 switch( p->mode ){
743 case MODE_Line: {
@@ -1102,61 +1112,81 @@
1112
1113 if( pArg && pArg->out ){
1114
1115 iHiwtr = iCur = -1;
1116 sqlite3_status(SQLITE_STATUS_MEMORY_USED, &iCur, &iHiwtr, bReset);
1117 fprintf(pArg->out,
1118 "Memory Used: %d (max %d) bytes\n",
1119 iCur, iHiwtr);
1120 iHiwtr = iCur = -1;
1121 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &iCur, &iHiwtr, bReset);
1122 fprintf(pArg->out, "Number of Outstanding Allocations: %d (max %d)\n",
1123 iCur, iHiwtr);
1124 if( pArg->shellFlgs & SHFLG_Pagecache ){
1125 iHiwtr = iCur = -1;
1126 sqlite3_status(SQLITE_STATUS_PAGECACHE_USED, &iCur, &iHiwtr, bReset);
1127 fprintf(pArg->out,
1128 "Number of Pcache Pages Used: %d (max %d) pages\n",
1129 iCur, iHiwtr);
1130 }
1131 iHiwtr = iCur = -1;
1132 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &iCur, &iHiwtr, bReset);
1133 fprintf(pArg->out,
1134 "Number of Pcache Overflow Bytes: %d (max %d) bytes\n",
1135 iCur, iHiwtr);
1136 if( pArg->shellFlgs & SHFLG_Scratch ){
1137 iHiwtr = iCur = -1;
1138 sqlite3_status(SQLITE_STATUS_SCRATCH_USED, &iCur, &iHiwtr, bReset);
1139 fprintf(pArg->out, "Number of Scratch Allocations Used: %d (max %d)\n",
1140 iCur, iHiwtr);
1141 }
1142 iHiwtr = iCur = -1;
1143 sqlite3_status(SQLITE_STATUS_SCRATCH_OVERFLOW, &iCur, &iHiwtr, bReset);
1144 fprintf(pArg->out,
1145 "Number of Scratch Overflow Bytes: %d (max %d) bytes\n",
1146 iCur, iHiwtr);
1147 iHiwtr = iCur = -1;
1148 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &iCur, &iHiwtr, bReset);
1149 fprintf(pArg->out, "Largest Allocation: %d bytes\n",
1150 iHiwtr);
1151 iHiwtr = iCur = -1;
1152 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE, &iCur, &iHiwtr, bReset);
1153 fprintf(pArg->out, "Largest Pcache Allocation: %d bytes\n",
1154 iHiwtr);
1155 iHiwtr = iCur = -1;
1156 sqlite3_status(SQLITE_STATUS_SCRATCH_SIZE, &iCur, &iHiwtr, bReset);
1157 fprintf(pArg->out, "Largest Scratch Allocation: %d bytes\n",
1158 iHiwtr);
1159 #ifdef YYTRACKMAXSTACKDEPTH
1160 iHiwtr = iCur = -1;
1161 sqlite3_status(SQLITE_STATUS_PARSER_STACK, &iCur, &iHiwtr, bReset);
1162 fprintf(pArg->out, "Deepest Parser Stack: %d (max %d)\n",
1163 iCur, iHiwtr);
1164 #endif
1165 }
1166
1167 if( pArg && pArg->out && db ){
1168 if( pArg->shellFlgs & SHFLG_Lookaside ){
1169 iHiwtr = iCur = -1;
1170 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED,
1171 &iCur, &iHiwtr, bReset);
1172 fprintf(pArg->out, "Lookaside Slots Used: %d (max %d)\n",
1173 iCur, iHiwtr);
1174 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT,
1175 &iCur, &iHiwtr, bReset);
1176 fprintf(pArg->out, "Successful lookaside attempts: %d\n", iHiwtr);
1177 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE,
1178 &iCur, &iHiwtr, bReset);
1179 fprintf(pArg->out, "Lookaside failures due to size: %d\n", iHiwtr);
1180 sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL,
1181 &iCur, &iHiwtr, bReset);
1182 fprintf(pArg->out, "Lookaside failures due to OOM: %d\n", iHiwtr);
1183 }
1184 iHiwtr = iCur = -1;
1185 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset);
1186 fprintf(pArg->out, "Pager Heap Usage: %d bytes\n",iCur);
1187 iHiwtr = iCur = -1;
1188 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1);
1189 fprintf(pArg->out, "Page cache hits: %d\n", iCur);
1190 iHiwtr = iCur = -1;
1191 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1);
1192 fprintf(pArg->out, "Page cache misses: %d\n", iCur);
@@ -1163,29 +1193,75 @@
1193 iHiwtr = iCur = -1;
1194 sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1);
1195 fprintf(pArg->out, "Page cache writes: %d\n", iCur);
1196 iHiwtr = iCur = -1;
1197 sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset);
1198 fprintf(pArg->out, "Schema Heap Usage: %d bytes\n",iCur);
1199 iHiwtr = iCur = -1;
1200 sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset);
1201 fprintf(pArg->out, "Statement Heap/Lookaside Usage: %d bytes\n",iCur);
1202 }
1203
1204 if( pArg && pArg->out && db && pArg->pStmt ){
1205 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP,
1206 bReset);
1207 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1208 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1209 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1210 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset);
1211 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1212 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1213 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1214 }
1215
1216 return 0;
1217 }
1218
1219 /*
1220 ** Display scan stats.
1221 */
1222 static void display_scanstats(
1223 sqlite3 *db, /* Database to query */
1224 ShellState *pArg /* Pointer to ShellState */
1225 ){
1226 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1227 int i, k, n, mx;
1228 fprintf(pArg->out, "-------- scanstats --------\n");
1229 mx = 0;
1230 for(k=0; k<=mx; k++){
1231 double rEstLoop = 1.0;
1232 for(i=n=0; 1; i++){
1233 sqlite3_stmt *p = pArg->pStmt;
1234 sqlite3_int64 nLoop, nVisit;
1235 double rEst;
1236 int iSid;
1237 const char *zExplain;
1238 if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
1239 break;
1240 }
1241 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
1242 if( iSid>mx ) mx = iSid;
1243 if( iSid!=k ) continue;
1244 if( n==0 ){
1245 rEstLoop = (double)nLoop;
1246 if( k>0 ) fprintf(pArg->out, "-------- subquery %d -------\n", k);
1247 }
1248 n++;
1249 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
1250 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
1251 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
1252 fprintf(pArg->out, "Loop %2d: %s\n", n, zExplain);
1253 rEstLoop *= rEst;
1254 fprintf(pArg->out,
1255 " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
1256 nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
1257 );
1258 }
1259 }
1260 fprintf(pArg->out, "---------------------------\n");
1261 #endif
1262 }
1263
1264 /*
1265 ** Parameter azArray points to a zero-terminated array of strings. zStr
1266 ** points to a single nul-terminated string. Return non-zero if zStr
1267 ** is equal, according to strcmp(), to any of the strings in the array.
@@ -1224,11 +1300,12 @@
1300 int nAlloc = 0; /* Allocated size of p->aiIndent[], abYield */
1301 int iOp; /* Index of operation in p->aiIndent[] */
1302
1303 const char *azNext[] = { "Next", "Prev", "VPrev", "VNext", "SorterNext",
1304 "NextIfOpen", "PrevIfOpen", 0 };
1305 const char *azYield[] = { "Yield", "SeekLT", "SeekGT", "RowSetRead",
1306 "Rewind", 0 };
1307 const char *azGoto[] = { "Goto", 0 };
1308
1309 /* Try to figure out if this is really an EXPLAIN statement. If this
1310 ** cannot be verified, return early. */
1311 zSql = sqlite3_sql(pSql);
@@ -1337,11 +1414,12 @@
1414 }
1415
1416 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1417 if( pArg && pArg->autoEQP ){
1418 sqlite3_stmt *pExplain;
1419 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1420 sqlite3_sql(pStmt));
1421 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1422 if( rc==SQLITE_OK ){
1423 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1424 fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
1425 fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1351,21 +1429,10 @@
1429 }
1430 sqlite3_finalize(pExplain);
1431 sqlite3_free(zEQP);
1432 }
1433
 
 
 
 
 
 
 
 
 
 
 
1434 /* If the shell is currently in ".explain" mode, gather the extra
1435 ** data required to add indents to the output.*/
1436 if( pArg && pArg->mode==MODE_Explain ){
1437 explain_data_prepare(pArg, pStmt);
1438 }
@@ -1431,10 +1498,15 @@
1498
1499 /* print usage stats if stats on */
1500 if( pArg && pArg->statsOn ){
1501 display_stats(db, pArg, 0);
1502 }
1503
1504 /* print loop-counters if required */
1505 if( pArg && pArg->scanstatsOn ){
1506 display_scanstats(db, pArg);
1507 }
1508
1509 /* Finalize the statement just executed. If this fails, save a
1510 ** copy of the error message. Otherwise, set zSql to point to the
1511 ** next statement to execute. */
1512 rc2 = sqlite3_finalize(pStmt);
@@ -1642,10 +1714,11 @@
1714 ".prompt MAIN CONTINUE Replace the standard prompts\n"
1715 ".quit Exit this program\n"
1716 ".read FILENAME Execute SQL in FILENAME\n"
1717 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
1718 ".save FILE Write in-memory database into FILE\n"
1719 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
1720 ".schema ?TABLE? Show the CREATE statements\n"
1721 " If TABLE specified, only show tables matching\n"
1722 " LIKE pattern TABLE.\n"
1723 ".separator STRING ?NL? Change separator used by output mode and .import\n"
1724 " NL is the end-of-line mark for CSV\n"
@@ -3023,10 +3096,23 @@
3096 rc = 1;
3097 }
3098 sqlite3_close(pSrc);
3099 }else
3100
3101
3102 if( c=='s' && strncmp(azArg[0], "scanstats", n)==0 ){
3103 if( nArg==2 ){
3104 p->scanstatsOn = booleanValue(azArg[1]);
3105 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
3106 fprintf(stderr, "Warning: .scanstats not available in this build.\n");
3107 #endif
3108 }else{
3109 fprintf(stderr, "Usage: .scanstats on|off\n");
3110 rc = 1;
3111 }
3112 }else
3113
3114 if( c=='s' && strncmp(azArg[0], "schema", n)==0 ){
3115 ShellState data;
3116 char *zErrMsg = 0;
3117 open_db(p, 0);
3118 memcpy(&data, p, sizeof(data));
@@ -3280,11 +3366,11 @@
3366 if( nPrintCol<1 ) nPrintCol = 1;
3367 nPrintRow = (nRow + nPrintCol - 1)/nPrintCol;
3368 for(i=0; i<nPrintRow; i++){
3369 for(j=i; j<nRow; j+=nPrintRow){
3370 char *zSp = j<nPrintRow ? "" : " ";
3371 fprintf(p->out, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:"");
3372 }
3373 fprintf(p->out, "\n");
3374 }
3375 }
3376 for(ii=0; ii<nRow; ii++) sqlite3_free(azResult[ii]);
@@ -3750,11 +3836,12 @@
3836 */
3837 static char *find_home_dir(void){
3838 static char *home_dir = NULL;
3839 if( home_dir ) return home_dir;
3840
3841 #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \
3842 && !defined(__RTP__) && !defined(_WRS_KERNEL)
3843 {
3844 struct passwd *pwent;
3845 uid_t uid = getuid();
3846 if( (pwent=getpwuid(uid)) != NULL) {
3847 home_dir = pwent->pw_dir;
@@ -3949,14 +4036,16 @@
4036
4037 int main(int argc, char **argv){
4038 char *zErrMsg = 0;
4039 ShellState data;
4040 const char *zInitFile = 0;
 
4041 int i;
4042 int rc = 0;
4043 int warnInmemoryDb = 0;
4044 int readStdin = 1;
4045 int nCmd = 0;
4046 char **azCmd = 0;
4047
4048 #if USE_SYSTEM_SQLITE+0!=1
4049 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
4050 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
4051 sqlite3_sourceid(), SQLITE_SOURCE_ID);
@@ -3971,10 +4060,22 @@
4060 ** else is done.
4061 */
4062 #ifdef SIGINT
4063 signal(SIGINT, interrupt_handler);
4064 #endif
4065
4066 #ifdef SQLITE_SHELL_DBNAME_PROC
4067 {
4068 /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name
4069 ** of a C-function that will provide the name of the database file. Use
4070 ** this compile-time option to embed this shell program in larger
4071 ** applications. */
4072 extern void SQLITE_SHELL_DBNAME_PROC(const char**);
4073 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
4074 warnInmemoryDb = 0;
4075 }
4076 #endif
4077
4078 /* Do an initial pass through the command-line argument to locate
4079 ** the name of the database file, the name of the initialization file,
4080 ** the size of the alternative malloc heap,
4081 ** and the first command to execute.
@@ -3983,19 +4084,22 @@
4084 char *z;
4085 z = argv[i];
4086 if( z[0]!='-' ){
4087 if( data.zDbFilename==0 ){
4088 data.zDbFilename = z;
4089 }else{
4090 /* Excesss arguments are interpreted as SQL (or dot-commands) and
4091 ** mean that nothing is read from stdin */
4092 readStdin = 0;
4093 nCmd++;
4094 azCmd = realloc(azCmd, sizeof(azCmd[0])*nCmd);
4095 if( azCmd==0 ){
4096 fprintf(stderr, "out of memory\n");
4097 exit(1);
4098 }
4099 azCmd[nCmd-1] = z;
4100 }
4101 }
4102 if( z[1]=='-' ) z++;
4103 if( strcmp(z,"-separator")==0
4104 || strcmp(z,"-nullvalue")==0
4105 || strcmp(z,"-newline")==0
@@ -4082,15 +4186,10 @@
4186 warnInmemoryDb = argc==1;
4187 #else
4188 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
4189 return 1;
4190 #endif
 
 
 
 
 
4191 }
4192 data.out = stdout;
4193
4194 /* Go ahead and open the database file if it already exists. If the
4195 ** file does not exist, delay opening it. This prevents empty database
@@ -4149,10 +4248,12 @@
4248 data.echoOn = 1;
4249 }else if( strcmp(z,"-eqp")==0 ){
4250 data.autoEQP = 1;
4251 }else if( strcmp(z,"-stats")==0 ){
4252 data.statsOn = 1;
4253 }else if( strcmp(z,"-scanstats")==0 ){
4254 data.scanstatsOn = 1;
4255 }else if( strcmp(z,"-bail")==0 ){
4256 bail_on_error = 1;
4257 }else if( strcmp(z,"-version")==0 ){
4258 printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
4259 return 0;
@@ -4181,10 +4282,14 @@
4282 i++;
4283 #endif
4284 }else if( strcmp(z,"-help")==0 ){
4285 usage(1);
4286 }else if( strcmp(z,"-cmd")==0 ){
4287 /* Run commands that follow -cmd first and separately from commands
4288 ** that simply appear on the command-line. This seems goofy. It would
4289 ** be better if all commands ran in the order that they appear. But
4290 ** we retain the goofy behavior for historical compatibility. */
4291 if( i==argc-1 ) break;
4292 z = cmdline_option_value(argc,argv,++i);
4293 if( z[0]=='.' ){
4294 rc = do_meta_command(z, &data);
4295 if( rc && bail_on_error ) return rc==2 ? 0 : rc;
@@ -4204,27 +4309,32 @@
4309 fprintf(stderr,"Use -help for a list of options.\n");
4310 return 1;
4311 }
4312 }
4313
4314 if( !readStdin ){
4315 /* Run all arguments that do not begin with '-' as if they were separate
4316 ** command-line inputs, except for the argToSkip argument which contains
4317 ** the database filename.
4318 */
4319 for(i=0; i<nCmd; i++){
4320 if( azCmd[i][0]=='.' ){
4321 rc = do_meta_command(azCmd[i], &data);
4322 if( rc ) return rc==2 ? 0 : rc;
4323 }else{
4324 open_db(&data, 0);
4325 rc = shell_exec(data.db, azCmd[i], shell_callback, &data, &zErrMsg);
4326 if( zErrMsg!=0 ){
4327 fprintf(stderr,"Error: %s\n", zErrMsg);
4328 return rc!=0 ? rc : 1;
4329 }else if( rc!=0 ){
4330 fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]);
4331 return rc;
4332 }
4333 }
4334 }
4335 free(azCmd);
4336 }else{
4337 /* Run commands received from standard input
4338 */
4339 if( stdin_is_interactive ){
4340 char *zHome;
4341
+44 -13
--- src/shun.c
+++ src/shun.c
@@ -56,10 +56,11 @@
5656
if( P("rebuild") ){
5757
db_close(1);
5858
db_open_repository(g.zRepositoryName);
5959
db_begin_transaction();
6060
rebuild_db(0, 0, 0);
61
+ admin_log("Rebuilt database.");
6162
db_end_transaction(0);
6263
}
6364
if( zUuid ){
6465
char *p;
6566
int i = 0;
@@ -101,10 +102,11 @@
101102
while( *p ){
102103
db_multi_exec("DELETE FROM shun WHERE uuid=%Q", p);
103104
if( !db_exists("SELECT 1 FROM blob WHERE uuid=%Q", p) ){
104105
allExist = 0;
105106
}
107
+ admin_log("Unshunned %Q", p);
106108
p += UUID_SIZE+1;
107109
}
108110
if( allExist ){
109111
@ <p class="noMoreShun">Artifact(s)<br />
110112
for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
@@ -139,10 +141,11 @@
139141
if( tagid ){
140142
db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", p);
141143
db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
142144
db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
143145
}
146
+ admin_log("Shunned %Q", p);
144147
p += UUID_SIZE+1;
145148
}
146149
@ <p class="shunned">Artifact(s)<br />
147150
for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
148151
@ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
@@ -292,37 +295,50 @@
292295
**
293296
** Show a listing of RCVFROM table entries.
294297
*/
295298
void rcvfromlist_page(void){
296299
int ofst = atoi(PD("ofst","0"));
300
+ int showAll = P("all")!=0;
297301
int cnt;
298302
Stmt q;
299303
300304
login_check_credentials();
301305
if( !g.perm.Admin ){
302306
login_needed();
303307
}
304
- style_header("Content Sources");
308
+ style_header("Artifact Receipts");
309
+ if( showAll ){
310
+ ofst = 0;
311
+ }else{
312
+ style_submenu_element("All", "All", "rcvfromlist?all=1");
313
+ }
305314
if( ofst>0 ){
306315
style_submenu_element("Newer", "Newer", "rcvfromlist?ofst=%d",
307316
ofst>30 ? ofst-30 : 0);
308317
}
318
+ db_multi_exec(
319
+ "CREATE TEMP TABLE rcvidUsed(x INTEGER PRIMARY KEY);"
320
+ "INSERT OR IGNORE INTO rcvidUsed(x) SELECT rcvid FROM blob;"
321
+ );
309322
db_prepare(&q,
310
- "SELECT rcvid, login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
323
+ "SELECT rcvid, login, datetime(rcvfrom.mtime), rcvfrom.ipaddr,"
324
+ " EXISTS(SELECT 1 FROM rcvidUsed WHERE x=rcvfrom.rcvid)"
311325
" FROM rcvfrom LEFT JOIN user USING(uid)"
312
- " ORDER BY rcvid DESC LIMIT 31 OFFSET %d",
313
- ofst
326
+ " ORDER BY rcvid DESC LIMIT %d OFFSET %d",
327
+ showAll ? -1 : 31, ofst
314328
);
315329
@ <p>Whenever new artifacts are added to the repository, either by
316330
@ push or using the web interface, an entry is made in the RCVFROM table
317331
@ to record the source of that artifact. This log facilitates
318332
@ finding and fixing attempts to inject illicit content into the
319333
@ repository.</p>
320334
@
321335
@ <p>Click on the "rcvid" to show a list of specific artifacts received
322336
@ by a transaction. After identifying illicit artifacts, remove them
323
- @ using the "Shun" feature.</p>
337
+ @ using the "Shun" button. If an "rcvid" is not hyperlinked, that means
338
+ @ all artifacts associated with that rcvid have already been shunned
339
+ @ or purged.</p>
324340
@
325341
@ <table cellpadding="0" cellspacing="0" border="0">
326342
@ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th>
327343
@ <th style="padding-right: 15px;text-align: left;">Date</th>
328344
@ <th style="padding-right: 15px;text-align: left;">User</th>
@@ -331,17 +347,22 @@
331347
while( db_step(&q)==SQLITE_ROW ){
332348
int rcvid = db_column_int(&q, 0);
333349
const char *zUser = db_column_text(&q, 1);
334350
const char *zDate = db_column_text(&q, 2);
335351
const char *zIpAddr = db_column_text(&q, 3);
336
- if( cnt==30 ){
352
+ if( cnt==30 && !showAll ){
337353
style_submenu_element("Older", "Older",
338354
"rcvfromlist?ofst=%d", ofst+30);
339355
}else{
340356
cnt++;
341357
@ <tr>
342
- @ <td style="padding-right: 15px;text-align: right;"><a href="rcvfrom?rcvid=%d(rcvid)">%d(rcvid)</a></td>
358
+ if( db_column_int(&q,4) ){
359
+ @ <td style="padding-right: 15px;text-align: right;">
360
+ @ <a href="rcvfrom?rcvid=%d(rcvid)">%d(rcvid)</a></td>
361
+ }else{
362
+ @ <td style="padding-right: 15px;text-align: right;">%d(rcvid)</td>
363
+ }
343364
@ <td style="padding-right: 15px;text-align: left;">%s(zDate)</td>
344365
@ <td style="padding-right: 15px;text-align: left;">%h(zUser)</td>
345366
@ <td style="text-align: left;">%s(zIpAddr)</td>
346367
@ </tr>
347368
}
@@ -362,22 +383,24 @@
362383
363384
login_check_credentials();
364385
if( !g.perm.Admin ){
365386
login_needed();
366387
}
367
- style_header("Content Source %d", rcvid);
388
+ style_header("Artifact Receipt %d", rcvid);
368389
if( db_exists(
369390
"SELECT 1 FROM blob WHERE rcvid=%d AND"
370391
" NOT EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
371392
){
372
- style_submenu_element("Shun All", "Shun All", "shun?shun&rcvid=%d#addshun", rcvid);
393
+ style_submenu_element("Shun All", "Shun All",
394
+ "shun?shun&rcvid=%d#addshun", rcvid);
373395
}
374396
if( db_exists(
375397
"SELECT 1 FROM blob WHERE rcvid=%d AND"
376398
" EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
377399
){
378
- style_submenu_element("Unshun All", "Unshun All", "shun?accept&rcvid=%d#delshun", rcvid);
400
+ style_submenu_element("Unshun All", "Unshun All",
401
+ "shun?accept&rcvid=%d#delshun", rcvid);
379402
}
380403
db_prepare(&q,
381404
"SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
382405
" FROM rcvfrom LEFT JOIN user USING(uid)"
383406
" WHERE rcvid=%d",
@@ -396,22 +419,30 @@
396419
@ <td valign="top">%s(zDate)</td></tr>
397420
@ <tr><th valign="top" align="right">IP&nbsp;Address:</th>
398421
@ <td valign="top">%s(zIpAddr)</td></tr>
399422
}
400423
db_finalize(&q);
424
+ db_multi_exec(
425
+ "CREATE TEMP TABLE toshow(rid INTEGER PRIMARY KEY);"
426
+ "INSERT INTO toshow SELECT rid FROM blob WHERE rcvid=%d", rcvid
427
+ );
428
+ describe_artifacts("IN toshow");
401429
db_prepare(&q,
402
- "SELECT rid, uuid, size FROM blob WHERE rcvid=%d", rcvid
430
+ "SELECT blob.rid, blob.uuid, blob.size, description.summary\n"
431
+ " FROM blob LEFT JOIN description ON (blob.rid=description.rid)"
432
+ " WHERE blob.rcvid=%d", rcvid
403433
);
404434
@ <tr><th valign="top" align="right">Artifacts:</th>
405435
@ <td valign="top">
406436
while( db_step(&q)==SQLITE_ROW ){
407
- int rid = db_column_int(&q, 0);
408437
const char *zUuid = db_column_text(&q, 1);
409438
int size = db_column_int(&q, 2);
439
+ const char *zDesc = db_column_text(&q, 3);
440
+ if( zDesc==0 ) zDesc = "";
410441
@ <a href="%s(g.zTop)/info/%s(zUuid)">%s(zUuid)</a>
411
- @ (rid: %d(rid), size: %d(size))<br />
442
+ @ %h(zDesc) (size: %d(size))<br />
412443
}
413444
@ </td></tr>
414445
@ </table>
415446
db_finalize(&q);
416447
style_footer();
417448
}
418449
419450
ADDED src/sitemap.c
--- src/shun.c
+++ src/shun.c
@@ -56,10 +56,11 @@
56 if( P("rebuild") ){
57 db_close(1);
58 db_open_repository(g.zRepositoryName);
59 db_begin_transaction();
60 rebuild_db(0, 0, 0);
 
61 db_end_transaction(0);
62 }
63 if( zUuid ){
64 char *p;
65 int i = 0;
@@ -101,10 +102,11 @@
101 while( *p ){
102 db_multi_exec("DELETE FROM shun WHERE uuid=%Q", p);
103 if( !db_exists("SELECT 1 FROM blob WHERE uuid=%Q", p) ){
104 allExist = 0;
105 }
 
106 p += UUID_SIZE+1;
107 }
108 if( allExist ){
109 @ <p class="noMoreShun">Artifact(s)<br />
110 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
@@ -139,10 +141,11 @@
139 if( tagid ){
140 db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", p);
141 db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
142 db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
143 }
 
144 p += UUID_SIZE+1;
145 }
146 @ <p class="shunned">Artifact(s)<br />
147 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
148 @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
@@ -292,37 +295,50 @@
292 **
293 ** Show a listing of RCVFROM table entries.
294 */
295 void rcvfromlist_page(void){
296 int ofst = atoi(PD("ofst","0"));
 
297 int cnt;
298 Stmt q;
299
300 login_check_credentials();
301 if( !g.perm.Admin ){
302 login_needed();
303 }
304 style_header("Content Sources");
 
 
 
 
 
305 if( ofst>0 ){
306 style_submenu_element("Newer", "Newer", "rcvfromlist?ofst=%d",
307 ofst>30 ? ofst-30 : 0);
308 }
 
 
 
 
309 db_prepare(&q,
310 "SELECT rcvid, login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
 
311 " FROM rcvfrom LEFT JOIN user USING(uid)"
312 " ORDER BY rcvid DESC LIMIT 31 OFFSET %d",
313 ofst
314 );
315 @ <p>Whenever new artifacts are added to the repository, either by
316 @ push or using the web interface, an entry is made in the RCVFROM table
317 @ to record the source of that artifact. This log facilitates
318 @ finding and fixing attempts to inject illicit content into the
319 @ repository.</p>
320 @
321 @ <p>Click on the "rcvid" to show a list of specific artifacts received
322 @ by a transaction. After identifying illicit artifacts, remove them
323 @ using the "Shun" feature.</p>
 
 
324 @
325 @ <table cellpadding="0" cellspacing="0" border="0">
326 @ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th>
327 @ <th style="padding-right: 15px;text-align: left;">Date</th>
328 @ <th style="padding-right: 15px;text-align: left;">User</th>
@@ -331,17 +347,22 @@
331 while( db_step(&q)==SQLITE_ROW ){
332 int rcvid = db_column_int(&q, 0);
333 const char *zUser = db_column_text(&q, 1);
334 const char *zDate = db_column_text(&q, 2);
335 const char *zIpAddr = db_column_text(&q, 3);
336 if( cnt==30 ){
337 style_submenu_element("Older", "Older",
338 "rcvfromlist?ofst=%d", ofst+30);
339 }else{
340 cnt++;
341 @ <tr>
342 @ <td style="padding-right: 15px;text-align: right;"><a href="rcvfrom?rcvid=%d(rcvid)">%d(rcvid)</a></td>
 
 
 
 
 
343 @ <td style="padding-right: 15px;text-align: left;">%s(zDate)</td>
344 @ <td style="padding-right: 15px;text-align: left;">%h(zUser)</td>
345 @ <td style="text-align: left;">%s(zIpAddr)</td>
346 @ </tr>
347 }
@@ -362,22 +383,24 @@
362
363 login_check_credentials();
364 if( !g.perm.Admin ){
365 login_needed();
366 }
367 style_header("Content Source %d", rcvid);
368 if( db_exists(
369 "SELECT 1 FROM blob WHERE rcvid=%d AND"
370 " NOT EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
371 ){
372 style_submenu_element("Shun All", "Shun All", "shun?shun&rcvid=%d#addshun", rcvid);
 
373 }
374 if( db_exists(
375 "SELECT 1 FROM blob WHERE rcvid=%d AND"
376 " EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
377 ){
378 style_submenu_element("Unshun All", "Unshun All", "shun?accept&rcvid=%d#delshun", rcvid);
 
379 }
380 db_prepare(&q,
381 "SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
382 " FROM rcvfrom LEFT JOIN user USING(uid)"
383 " WHERE rcvid=%d",
@@ -396,22 +419,30 @@
396 @ <td valign="top">%s(zDate)</td></tr>
397 @ <tr><th valign="top" align="right">IP&nbsp;Address:</th>
398 @ <td valign="top">%s(zIpAddr)</td></tr>
399 }
400 db_finalize(&q);
 
 
 
 
 
401 db_prepare(&q,
402 "SELECT rid, uuid, size FROM blob WHERE rcvid=%d", rcvid
 
 
403 );
404 @ <tr><th valign="top" align="right">Artifacts:</th>
405 @ <td valign="top">
406 while( db_step(&q)==SQLITE_ROW ){
407 int rid = db_column_int(&q, 0);
408 const char *zUuid = db_column_text(&q, 1);
409 int size = db_column_int(&q, 2);
 
 
410 @ <a href="%s(g.zTop)/info/%s(zUuid)">%s(zUuid)</a>
411 @ (rid: %d(rid), size: %d(size))<br />
412 }
413 @ </td></tr>
414 @ </table>
415 db_finalize(&q);
416 style_footer();
417 }
418
419 DDED src/sitemap.c
--- src/shun.c
+++ src/shun.c
@@ -56,10 +56,11 @@
56 if( P("rebuild") ){
57 db_close(1);
58 db_open_repository(g.zRepositoryName);
59 db_begin_transaction();
60 rebuild_db(0, 0, 0);
61 admin_log("Rebuilt database.");
62 db_end_transaction(0);
63 }
64 if( zUuid ){
65 char *p;
66 int i = 0;
@@ -101,10 +102,11 @@
102 while( *p ){
103 db_multi_exec("DELETE FROM shun WHERE uuid=%Q", p);
104 if( !db_exists("SELECT 1 FROM blob WHERE uuid=%Q", p) ){
105 allExist = 0;
106 }
107 admin_log("Unshunned %Q", p);
108 p += UUID_SIZE+1;
109 }
110 if( allExist ){
111 @ <p class="noMoreShun">Artifact(s)<br />
112 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
@@ -139,10 +141,11 @@
141 if( tagid ){
142 db_multi_exec("DELETE FROM ticket WHERE tkt_uuid=%Q", p);
143 db_multi_exec("DELETE FROM tag WHERE tagid=%d", tagid);
144 db_multi_exec("DELETE FROM tagxref WHERE tagid=%d", tagid);
145 }
146 admin_log("Shunned %Q", p);
147 p += UUID_SIZE+1;
148 }
149 @ <p class="shunned">Artifact(s)<br />
150 for( p = zUuid ; *p ; p += UUID_SIZE+1 ){
151 @ <a href="%s(g.zTop)/artifact/%s(p)">%s(p)</a><br />
@@ -292,37 +295,50 @@
295 **
296 ** Show a listing of RCVFROM table entries.
297 */
298 void rcvfromlist_page(void){
299 int ofst = atoi(PD("ofst","0"));
300 int showAll = P("all")!=0;
301 int cnt;
302 Stmt q;
303
304 login_check_credentials();
305 if( !g.perm.Admin ){
306 login_needed();
307 }
308 style_header("Artifact Receipts");
309 if( showAll ){
310 ofst = 0;
311 }else{
312 style_submenu_element("All", "All", "rcvfromlist?all=1");
313 }
314 if( ofst>0 ){
315 style_submenu_element("Newer", "Newer", "rcvfromlist?ofst=%d",
316 ofst>30 ? ofst-30 : 0);
317 }
318 db_multi_exec(
319 "CREATE TEMP TABLE rcvidUsed(x INTEGER PRIMARY KEY);"
320 "INSERT OR IGNORE INTO rcvidUsed(x) SELECT rcvid FROM blob;"
321 );
322 db_prepare(&q,
323 "SELECT rcvid, login, datetime(rcvfrom.mtime), rcvfrom.ipaddr,"
324 " EXISTS(SELECT 1 FROM rcvidUsed WHERE x=rcvfrom.rcvid)"
325 " FROM rcvfrom LEFT JOIN user USING(uid)"
326 " ORDER BY rcvid DESC LIMIT %d OFFSET %d",
327 showAll ? -1 : 31, ofst
328 );
329 @ <p>Whenever new artifacts are added to the repository, either by
330 @ push or using the web interface, an entry is made in the RCVFROM table
331 @ to record the source of that artifact. This log facilitates
332 @ finding and fixing attempts to inject illicit content into the
333 @ repository.</p>
334 @
335 @ <p>Click on the "rcvid" to show a list of specific artifacts received
336 @ by a transaction. After identifying illicit artifacts, remove them
337 @ using the "Shun" button. If an "rcvid" is not hyperlinked, that means
338 @ all artifacts associated with that rcvid have already been shunned
339 @ or purged.</p>
340 @
341 @ <table cellpadding="0" cellspacing="0" border="0">
342 @ <tr><th style="padding-right: 15px;text-align: right;">rcvid</th>
343 @ <th style="padding-right: 15px;text-align: left;">Date</th>
344 @ <th style="padding-right: 15px;text-align: left;">User</th>
@@ -331,17 +347,22 @@
347 while( db_step(&q)==SQLITE_ROW ){
348 int rcvid = db_column_int(&q, 0);
349 const char *zUser = db_column_text(&q, 1);
350 const char *zDate = db_column_text(&q, 2);
351 const char *zIpAddr = db_column_text(&q, 3);
352 if( cnt==30 && !showAll ){
353 style_submenu_element("Older", "Older",
354 "rcvfromlist?ofst=%d", ofst+30);
355 }else{
356 cnt++;
357 @ <tr>
358 if( db_column_int(&q,4) ){
359 @ <td style="padding-right: 15px;text-align: right;">
360 @ <a href="rcvfrom?rcvid=%d(rcvid)">%d(rcvid)</a></td>
361 }else{
362 @ <td style="padding-right: 15px;text-align: right;">%d(rcvid)</td>
363 }
364 @ <td style="padding-right: 15px;text-align: left;">%s(zDate)</td>
365 @ <td style="padding-right: 15px;text-align: left;">%h(zUser)</td>
366 @ <td style="text-align: left;">%s(zIpAddr)</td>
367 @ </tr>
368 }
@@ -362,22 +383,24 @@
383
384 login_check_credentials();
385 if( !g.perm.Admin ){
386 login_needed();
387 }
388 style_header("Artifact Receipt %d", rcvid);
389 if( db_exists(
390 "SELECT 1 FROM blob WHERE rcvid=%d AND"
391 " NOT EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
392 ){
393 style_submenu_element("Shun All", "Shun All",
394 "shun?shun&rcvid=%d#addshun", rcvid);
395 }
396 if( db_exists(
397 "SELECT 1 FROM blob WHERE rcvid=%d AND"
398 " EXISTS (SELECT 1 FROM shun WHERE shun.uuid=blob.uuid)", rcvid)
399 ){
400 style_submenu_element("Unshun All", "Unshun All",
401 "shun?accept&rcvid=%d#delshun", rcvid);
402 }
403 db_prepare(&q,
404 "SELECT login, datetime(rcvfrom.mtime), rcvfrom.ipaddr"
405 " FROM rcvfrom LEFT JOIN user USING(uid)"
406 " WHERE rcvid=%d",
@@ -396,22 +419,30 @@
419 @ <td valign="top">%s(zDate)</td></tr>
420 @ <tr><th valign="top" align="right">IP&nbsp;Address:</th>
421 @ <td valign="top">%s(zIpAddr)</td></tr>
422 }
423 db_finalize(&q);
424 db_multi_exec(
425 "CREATE TEMP TABLE toshow(rid INTEGER PRIMARY KEY);"
426 "INSERT INTO toshow SELECT rid FROM blob WHERE rcvid=%d", rcvid
427 );
428 describe_artifacts("IN toshow");
429 db_prepare(&q,
430 "SELECT blob.rid, blob.uuid, blob.size, description.summary\n"
431 " FROM blob LEFT JOIN description ON (blob.rid=description.rid)"
432 " WHERE blob.rcvid=%d", rcvid
433 );
434 @ <tr><th valign="top" align="right">Artifacts:</th>
435 @ <td valign="top">
436 while( db_step(&q)==SQLITE_ROW ){
 
437 const char *zUuid = db_column_text(&q, 1);
438 int size = db_column_int(&q, 2);
439 const char *zDesc = db_column_text(&q, 3);
440 if( zDesc==0 ) zDesc = "";
441 @ <a href="%s(g.zTop)/info/%s(zUuid)">%s(zUuid)</a>
442 @ %h(zDesc) (size: %d(size))<br />
443 }
444 @ </td></tr>
445 @ </table>
446 db_finalize(&q);
447 style_footer();
448 }
449
450 DDED src/sitemap.c
--- a/src/sitemap.c
+++ b/src/sitemap.c
@@ -0,0 +1,43 @@
1
+avtimeline?n=all&imeline?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
2
+ }
3
+}
4
+footer();
5
+ }
6
+}
7
+?name=Sandbox"))SandboxHelphelp"))List of All Commands and Web@mimetype map1style_header("Site Map");
8
+style_footer();
9
+}
10
+divul id="sitemap">
11
+</div>
12
+ style_footer();
13
+}
14
+</librlist"))Branchesaglist"))TagsdTktli>
15
+ style_footer();
16
+}
17
+?n=200}
18
+line?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
19
+ }
20
+}
21
+footer();
22
+ }
23
+}
24
+?name=Sandboxavtimeline?n=all&imeline?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
25
+ }
26
+}
27
+footer();
28
+ @ </p>
29
+ @
30
+#endifq@N6,W@Rh,X@1B~,b:docsrch"))Search Project DocumeShow an incomplete list of@Uy,q@gW,7O@aw,c@linkest_li>
31
+ @ <ul>docsrc@ </@@ @ warps"))List of "Timewaavtimeline?n=all&imeline?n=aln=all&namechng"))All check-in@ </@@ </ul>
32
+ @ </liwi</a>
33
+ @ <ul>
34
+q@N6,W@Rh,X@1B~,b:docsrch"))Se@ omplete list o@ @ warps"))List of "avtimelinew@ @ @ @ @ </ul>
35
+ @ </li@ </ul>
36
+ @ </liblobrtifacts</a></li>
37
+ in<ultree?Branches and Tags</a>
38
+ @ <uls"))List of "avtimelinew@ @ @ @ @ </ul>
39
+ @ </li@ </ul>
40
+ @ </liblobrtifactseline?n=aln=all&namechng"))All cul>
41
+q@N6,W@Rh,X@1B~,b:docsrch"))Se@ omplete list o@ @ warps"))List of "avtimelinew@ @ @ @ @ </ul>
42
+ @ </li@ </ul>
43
+ @ </liblobrtifactsstat"))Status SummaAdministration0
--- a/src/sitemap.c
+++ b/src/sitemap.c
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/src/sitemap.c
+++ b/src/sitemap.c
@@ -0,0 +1,43 @@
1 avtimeline?n=all&imeline?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
2 }
3 }
4 footer();
5 }
6 }
7 ?name=Sandbox"))SandboxHelphelp"))List of All Commands and Web@mimetype map1style_header("Site Map");
8 style_footer();
9 }
10 divul id="sitemap">
11 </div>
12 style_footer();
13 }
14 </librlist"))Branchesaglist"))TagsdTktli>
15 style_footer();
16 }
17 ?n=200}
18 line?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
19 }
20 }
21 footer();
22 }
23 }
24 ?name=Sandboxavtimeline?n=all&imeline?n=all& @ warps"))List of "Timewarp" Check-inTest Pages </ul></li>body_and_footer("sitemap");
25 }
26 }
27 footer();
28 @ </p>
29 @
30 #endifq@N6,W@Rh,X@1B~,b:docsrch"))Search Project DocumeShow an incomplete list of@Uy,q@gW,7O@aw,c@linkest_li>
31 @ <ul>docsrc@ </@@ @ warps"))List of "Timewaavtimeline?n=all&imeline?n=aln=all&namechng"))All check-in@ </@@ </ul>
32 @ </liwi</a>
33 @ <ul>
34 q@N6,W@Rh,X@1B~,b:docsrch"))Se@ omplete list o@ @ warps"))List of "avtimelinew@ @ @ @ @ </ul>
35 @ </li@ </ul>
36 @ </liblobrtifacts</a></li>
37 in<ultree?Branches and Tags</a>
38 @ <uls"))List of "avtimelinew@ @ @ @ @ </ul>
39 @ </li@ </ul>
40 @ </liblobrtifactseline?n=aln=all&namechng"))All cul>
41 q@N6,W@Rh,X@1B~,b:docsrch"))Se@ omplete list o@ @ warps"))List of "avtimelinew@ @ @ @ @ </ul>
42 @ </li@ </ul>
43 @ </liblobrtifactsstat"))Status SummaAdministration0
+17 -6
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -106,10 +106,24 @@
106106
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
107107
}else{
108108
sqlite3_result_error(context, "input is not zlib compressed", -1);
109109
}
110110
}
111
+
112
+/*
113
+** Add the content(), compress(), and decompress() SQL functions to
114
+** database connection db.
115
+*/
116
+int add_content_sql_commands(sqlite3 *db){
117
+ sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
118
+ sqlcmd_content, 0, 0);
119
+ sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
120
+ sqlcmd_compress, 0, 0);
121
+ sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
122
+ sqlcmd_decompress, 0, 0);
123
+ return SQLITE_OK;
124
+}
111125
112126
/*
113127
** This is the "automatic extension" initializer that runs right after
114128
** the connection to the repository database is opened. Set up the
115129
** database connection to be more useful to the human operator.
@@ -117,17 +131,14 @@
117131
static int sqlcmd_autoinit(
118132
sqlite3 *db,
119133
const char **pzErrMsg,
120134
const void *notUsed
121135
){
122
- sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
123
- sqlcmd_content, 0, 0);
124
- sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
125
- sqlcmd_compress, 0, 0);
126
- sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
127
- sqlcmd_decompress, 0, 0);
136
+ add_content_sql_commands(db);
128137
re_add_sql_func(db);
138
+ g.zMainDbType = "repository";
139
+ foci_register(db);
129140
g.repositoryOpen = 1;
130141
g.db = db;
131142
return SQLITE_OK;
132143
}
133144
134145
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -106,10 +106,24 @@
106 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
107 }else{
108 sqlite3_result_error(context, "input is not zlib compressed", -1);
109 }
110 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
112 /*
113 ** This is the "automatic extension" initializer that runs right after
114 ** the connection to the repository database is opened. Set up the
115 ** database connection to be more useful to the human operator.
@@ -117,17 +131,14 @@
117 static int sqlcmd_autoinit(
118 sqlite3 *db,
119 const char **pzErrMsg,
120 const void *notUsed
121 ){
122 sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
123 sqlcmd_content, 0, 0);
124 sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
125 sqlcmd_compress, 0, 0);
126 sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
127 sqlcmd_decompress, 0, 0);
128 re_add_sql_func(db);
 
 
129 g.repositoryOpen = 1;
130 g.db = db;
131 return SQLITE_OK;
132 }
133
134
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -106,10 +106,24 @@
106 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
107 }else{
108 sqlite3_result_error(context, "input is not zlib compressed", -1);
109 }
110 }
111
112 /*
113 ** Add the content(), compress(), and decompress() SQL functions to
114 ** database connection db.
115 */
116 int add_content_sql_commands(sqlite3 *db){
117 sqlite3_create_function(db, "content", 1, SQLITE_UTF8, 0,
118 sqlcmd_content, 0, 0);
119 sqlite3_create_function(db, "compress", 1, SQLITE_UTF8, 0,
120 sqlcmd_compress, 0, 0);
121 sqlite3_create_function(db, "decompress", 1, SQLITE_UTF8, 0,
122 sqlcmd_decompress, 0, 0);
123 return SQLITE_OK;
124 }
125
126 /*
127 ** This is the "automatic extension" initializer that runs right after
128 ** the connection to the repository database is opened. Set up the
129 ** database connection to be more useful to the human operator.
@@ -117,17 +131,14 @@
131 static int sqlcmd_autoinit(
132 sqlite3 *db,
133 const char **pzErrMsg,
134 const void *notUsed
135 ){
136 add_content_sql_commands(db);
 
 
 
 
 
137 re_add_sql_func(db);
138 g.zMainDbType = "repository";
139 foci_register(db);
140 g.repositoryOpen = 1;
141 g.db = db;
142 return SQLITE_OK;
143 }
144
145
+2611 -1119
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.7.1. By combining all the individual C code files into this
3
+** version 3.8.8. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -179,11 +179,11 @@
179179
180180
181181
/*
182182
** These no-op macros are used in front of interfaces to mark those
183183
** interfaces as either deprecated or experimental. New applications
184
-** should not use deprecated interfaces - they are support for backwards
184
+** should not use deprecated interfaces - they are supported for backwards
185185
** compatibility only. Application writers should be aware that
186186
** experimental interfaces are subject to change in point releases.
187187
**
188188
** These macros used to resolve to various kinds of compiler magic that
189189
** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229229
**
230230
** See also: [sqlite3_libversion()],
231231
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232232
** [sqlite_version()] and [sqlite_source_id()].
233233
*/
234
-#define SQLITE_VERSION "3.8.7.1"
235
-#define SQLITE_VERSION_NUMBER 3008007
236
-#define SQLITE_SOURCE_ID "2014-10-29 01:27:43 83afe23e553e802c0947c80d0ffdd120423e7c52"
234
+#define SQLITE_VERSION "3.8.8"
235
+#define SQLITE_VERSION_NUMBER 3008008
236
+#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
237237
238238
/*
239239
** CAPI3REF: Run-Time Library Version Numbers
240240
** KEYWORDS: sqlite3_version, sqlite3_sourceid
241241
**
@@ -1343,11 +1343,11 @@
13431343
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
13441344
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
13451345
** </ul>
13461346
**
13471347
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1348
-** was given no the corresponding lock.
1348
+** was given on the corresponding lock.
13491349
**
13501350
** The xShmLock method can transition between unlocked and SHARED or
13511351
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
13521352
** and EXCLUSIVE.
13531353
*/
@@ -1626,30 +1626,32 @@
16261626
** it is not possible to set the Serialized [threading mode] and
16271627
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
16281628
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
16291629
**
16301630
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631
-** <dd> ^(This option takes a single argument which is a pointer to an
1632
-** instance of the [sqlite3_mem_methods] structure. The argument specifies
1631
+** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1632
+** a pointer to an instance of the [sqlite3_mem_methods] structure.
1633
+** The argument specifies
16331634
** alternative low-level memory allocation routines to be used in place of
16341635
** the memory allocation routines built into SQLite.)^ ^SQLite makes
16351636
** its own private copy of the content of the [sqlite3_mem_methods] structure
16361637
** before the [sqlite3_config()] call returns.</dd>
16371638
**
16381639
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1639
-** <dd> ^(This option takes a single argument which is a pointer to an
1640
-** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1640
+** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1641
+** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1642
+** The [sqlite3_mem_methods]
16411643
** structure is filled with the currently defined memory allocation routines.)^
16421644
** This option can be used to overload the default memory allocation
16431645
** routines with a wrapper that simulations memory allocation failure or
16441646
** tracks memory usage, for example. </dd>
16451647
**
16461648
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1647
-** <dd> ^This option takes single argument of type int, interpreted as a
1648
-** boolean, which enables or disables the collection of memory allocation
1649
-** statistics. ^(When memory allocation statistics are disabled, the
1650
-** following SQLite interfaces become non-operational:
1649
+** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1650
+** interpreted as a boolean, which enables or disables the collection of
1651
+** memory allocation statistics. ^(When memory allocation statistics are
1652
+** disabled, the following SQLite interfaces become non-operational:
16511653
** <ul>
16521654
** <li> [sqlite3_memory_used()]
16531655
** <li> [sqlite3_memory_highwater()]
16541656
** <li> [sqlite3_soft_heap_limit64()]
16551657
** <li> [sqlite3_status()]
@@ -1658,78 +1660,92 @@
16581660
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
16591661
** allocation statistics are disabled by default.
16601662
** </dd>
16611663
**
16621664
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1663
-** <dd> ^This option specifies a static memory buffer that SQLite can use for
1664
-** scratch memory. There are three arguments: A pointer an 8-byte
1665
+** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1666
+** that SQLite can use for scratch memory. ^(There are three arguments
1667
+** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
16651668
** aligned memory buffer from which the scratch allocations will be
16661669
** drawn, the size of each scratch allocation (sz),
1667
-** and the maximum number of scratch allocations (N). The sz
1668
-** argument must be a multiple of 16.
1670
+** and the maximum number of scratch allocations (N).)^
16691671
** The first argument must be a pointer to an 8-byte aligned buffer
16701672
** of at least sz*N bytes of memory.
1671
-** ^SQLite will use no more than two scratch buffers per thread. So
1672
-** N should be set to twice the expected maximum number of threads.
1673
-** ^SQLite will never require a scratch buffer that is more than 6
1674
-** times the database page size. ^If SQLite needs needs additional
1673
+** ^SQLite will not use more than one scratch buffers per thread.
1674
+** ^SQLite will never request a scratch buffer that is more than 6
1675
+** times the database page size.
1676
+** ^If SQLite needs needs additional
16751677
** scratch memory beyond what is provided by this configuration option, then
1676
-** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1678
+** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1679
+** ^When the application provides any amount of scratch memory using
1680
+** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1681
+** [sqlite3_malloc|heap allocations].
1682
+** This can help [Robson proof|prevent memory allocation failures] due to heap
1683
+** fragmentation in low-memory embedded systems.
1684
+** </dd>
16771685
**
16781686
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1679
-** <dd> ^This option specifies a static memory buffer that SQLite can use for
1680
-** the database page cache with the default page cache implementation.
1687
+** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1688
+** that SQLite can use for the database page cache with the default page
1689
+** cache implementation.
16811690
** This configuration should not be used if an application-define page
1682
-** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1683
-** There are three arguments to this option: A pointer to 8-byte aligned
1691
+** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1692
+** configuration option.
1693
+** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1694
+** 8-byte aligned
16841695
** memory, the size of each page buffer (sz), and the number of pages (N).
16851696
** The sz argument should be the size of the largest database page
1686
-** (a power of two between 512 and 32768) plus a little extra for each
1687
-** page header. ^The page header size is 20 to 40 bytes depending on
1688
-** the host architecture. ^It is harmless, apart from the wasted memory,
1689
-** to make sz a little too large. The first
1690
-** argument should point to an allocation of at least sz*N bytes of memory.
1697
+** (a power of two between 512 and 32768) plus some extra bytes for each
1698
+** page header. ^The number of extra bytes needed by the page header
1699
+** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1700
+** to [sqlite3_config()].
1701
+** ^It is harmless, apart from the wasted memory,
1702
+** for the sz parameter to be larger than necessary. The first
1703
+** argument should pointer to an 8-byte aligned block of memory that
1704
+** is at least sz*N bytes of memory, otherwise subsequent behavior is
1705
+** undefined.
16911706
** ^SQLite will use the memory provided by the first argument to satisfy its
16921707
** memory needs for the first N pages that it adds to cache. ^If additional
16931708
** page cache memory is needed beyond what is provided by this option, then
1694
-** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1695
-** The pointer in the first argument must
1696
-** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1697
-** will be undefined.</dd>
1709
+** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
16981710
**
16991711
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1700
-** <dd> ^This option specifies a static memory buffer that SQLite will use
1701
-** for all of its dynamic memory allocation needs beyond those provided
1702
-** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1703
-** There are three arguments: An 8-byte aligned pointer to the memory,
1712
+** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1713
+** that SQLite will use for all of its dynamic memory allocation needs
1714
+** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1715
+** [SQLITE_CONFIG_PAGECACHE].
1716
+** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1717
+** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1718
+** [SQLITE_ERROR] if invoked otherwise.
1719
+** ^There are three arguments to SQLITE_CONFIG_HEAP:
1720
+** An 8-byte aligned pointer to the memory,
17041721
** the number of bytes in the memory buffer, and the minimum allocation size.
17051722
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
17061723
** to using its default memory allocator (the system malloc() implementation),
17071724
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1708
-** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1709
-** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1725
+** memory pointer is not NULL then the alternative memory
17101726
** allocator is engaged to handle all of SQLites memory allocation needs.
17111727
** The first pointer (the memory pointer) must be aligned to an 8-byte
17121728
** boundary or subsequent behavior of SQLite will be undefined.
17131729
** The minimum allocation size is capped at 2**12. Reasonable values
17141730
** for the minimum allocation size are 2**5 through 2**8.</dd>
17151731
**
17161732
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1717
-** <dd> ^(This option takes a single argument which is a pointer to an
1718
-** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1719
-** alternative low-level mutex routines to be used in place
1720
-** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1721
-** content of the [sqlite3_mutex_methods] structure before the call to
1733
+** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1734
+** pointer to an instance of the [sqlite3_mutex_methods] structure.
1735
+** The argument specifies alternative low-level mutex routines to be used
1736
+** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1737
+** the content of the [sqlite3_mutex_methods] structure before the call to
17221738
** [sqlite3_config()] returns. ^If SQLite is compiled with
17231739
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
17241740
** the entire mutexing subsystem is omitted from the build and hence calls to
17251741
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
17261742
** return [SQLITE_ERROR].</dd>
17271743
**
17281744
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1729
-** <dd> ^(This option takes a single argument which is a pointer to an
1730
-** instance of the [sqlite3_mutex_methods] structure. The
1745
+** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1746
+** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
17311747
** [sqlite3_mutex_methods]
17321748
** structure is filled with the currently defined mutex routines.)^
17331749
** This option can be used to overload the default mutex allocation
17341750
** routines with a wrapper used to track mutex usage for performance
17351751
** profiling or testing, for example. ^If SQLite is compiled with
@@ -1737,29 +1753,29 @@
17371753
** the entire mutexing subsystem is omitted from the build and hence calls to
17381754
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
17391755
** return [SQLITE_ERROR].</dd>
17401756
**
17411757
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1742
-** <dd> ^(This option takes two arguments that determine the default
1743
-** memory allocation for the lookaside memory allocator on each
1744
-** [database connection]. The first argument is the
1758
+** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1759
+** the default size of lookaside memory on each [database connection].
1760
+** The first argument is the
17451761
** size of each lookaside buffer slot and the second is the number of
1746
-** slots allocated to each database connection.)^ ^(This option sets the
1747
-** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1748
-** verb to [sqlite3_db_config()] can be used to change the lookaside
1762
+** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1763
+** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1764
+** option to [sqlite3_db_config()] can be used to change the lookaside
17491765
** configuration on individual connections.)^ </dd>
17501766
**
17511767
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1752
-** <dd> ^(This option takes a single argument which is a pointer to
1753
-** an [sqlite3_pcache_methods2] object. This object specifies the interface
1754
-** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1755
-** object and uses it for page cache memory allocations.</dd>
1768
+** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1769
+** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1770
+** the interface to a custom page cache implementation.)^
1771
+** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
17561772
**
17571773
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1758
-** <dd> ^(This option takes a single argument which is a pointer to an
1759
-** [sqlite3_pcache_methods2] object. SQLite copies of the current
1760
-** page cache implementation into that object.)^ </dd>
1774
+** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1775
+** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
1776
+** the current page cache implementation into that object.)^ </dd>
17611777
**
17621778
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
17631779
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
17641780
** global [error log].
17651781
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1778,26 +1794,28 @@
17781794
** supplied by the application must not invoke any SQLite interface.
17791795
** In a multi-threaded application, the application-defined logger
17801796
** function must be threadsafe. </dd>
17811797
**
17821798
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1783
-** <dd>^(This option takes a single argument of type int. If non-zero, then
1784
-** URI handling is globally enabled. If the parameter is zero, then URI handling
1785
-** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1786
-** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1799
+** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1800
+** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1801
+** then URI handling is globally disabled.)^ ^If URI handling is globally
1802
+** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1803
+** [sqlite3_open16()] or
17871804
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
17881805
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
17891806
** connection is opened. ^If it is globally disabled, filenames are
17901807
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
17911808
** database connection is opened. ^(By default, URI handling is globally
17921809
** disabled. The default value may be changed by compiling with the
17931810
** [SQLITE_USE_URI] symbol defined.)^
17941811
**
17951812
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1796
-** <dd>^This option takes a single integer argument which is interpreted as
1797
-** a boolean in order to enable or disable the use of covering indices for
1798
-** full table scans in the query optimizer. ^The default setting is determined
1813
+** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1814
+** argument which is interpreted as a boolean in order to enable or disable
1815
+** the use of covering indices for full table scans in the query optimizer.
1816
+** ^The default setting is determined
17991817
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
18001818
** if that compile-time option is omitted.
18011819
** The ability to disable the use of covering indices for full table scans
18021820
** is because some incorrectly coded legacy applications might malfunction
18031821
** when the optimization is enabled. Providing the ability to
@@ -1833,23 +1851,32 @@
18331851
** that are the default mmap size limit (the default setting for
18341852
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
18351853
** ^The default setting can be overridden by each database connection using
18361854
** either the [PRAGMA mmap_size] command, or by using the
18371855
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1838
-** cannot be changed at run-time. Nor may the maximum allowed mmap size
1839
-** exceed the compile-time maximum mmap size set by the
1856
+** will be silently truncated if necessary so that it does not exceed the
1857
+** compile-time maximum mmap size set by the
18401858
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
18411859
** ^If either argument to this option is negative, then that argument is
18421860
** changed to its compile-time default.
18431861
**
18441862
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
18451863
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1846
-** <dd>^This option is only available if SQLite is compiled for Windows
1847
-** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1848
-** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1864
+** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1865
+** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1866
+** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
18491867
** that specifies the maximum size of the created heap.
18501868
** </dl>
1869
+**
1870
+** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1871
+** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1872
+** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1873
+** is a pointer to an integer and writes into that integer the number of extra
1874
+** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1875
+** The amount of extra space required can change depending on the compiler,
1876
+** target platform, and SQLite version.
1877
+** </dl>
18511878
*/
18521879
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18531880
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
18541881
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
18551882
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1870,10 +1897,11 @@
18701897
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
18711898
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
18721899
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
18731900
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
18741901
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1902
+#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
18751903
18761904
/*
18771905
** CAPI3REF: Database Connection Configuration Options
18781906
**
18791907
** These constants are the available integer configuration options that
@@ -1997,51 +2025,49 @@
19972025
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
19982026
19992027
/*
20002028
** CAPI3REF: Count The Number Of Rows Modified
20012029
**
2002
-** ^This function returns the number of database rows that were changed
2003
-** or inserted or deleted by the most recently completed SQL statement
2004
-** on the [database connection] specified by the first parameter.
2005
-** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
2006
-** or [DELETE] statement are counted. Auxiliary changes caused by
2007
-** triggers or [foreign key actions] are not counted.)^ Use the
2008
-** [sqlite3_total_changes()] function to find the total number of changes
2009
-** including changes caused by triggers and foreign key actions.
2010
-**
2011
-** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2012
-** are not counted. Only real table changes are counted.
2013
-**
2014
-** ^(A "row change" is a change to a single row of a single table
2015
-** caused by an INSERT, DELETE, or UPDATE statement. Rows that
2016
-** are changed as side effects of [REPLACE] constraint resolution,
2017
-** rollback, ABORT processing, [DROP TABLE], or by any other
2018
-** mechanisms do not count as direct row changes.)^
2019
-**
2020
-** A "trigger context" is a scope of execution that begins and
2021
-** ends with the script of a [CREATE TRIGGER | trigger].
2022
-** Most SQL statements are
2023
-** evaluated outside of any trigger. This is the "top level"
2024
-** trigger context. If a trigger fires from the top level, a
2025
-** new trigger context is entered for the duration of that one
2026
-** trigger. Subtriggers create subcontexts for their duration.
2027
-**
2028
-** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
2029
-** not create a new trigger context.
2030
-**
2031
-** ^This function returns the number of direct row changes in the
2032
-** most recent INSERT, UPDATE, or DELETE statement within the same
2033
-** trigger context.
2034
-**
2035
-** ^Thus, when called from the top level, this function returns the
2036
-** number of changes in the most recent INSERT, UPDATE, or DELETE
2037
-** that also occurred at the top level. ^(Within the body of a trigger,
2038
-** the sqlite3_changes() interface can be called to find the number of
2039
-** changes in the most recently completed INSERT, UPDATE, or DELETE
2040
-** statement within the body of the same trigger.
2041
-** However, the number returned does not include changes
2042
-** caused by subtriggers since those have their own context.)^
2030
+** ^This function returns the number of rows modified, inserted or
2031
+** deleted by the most recently completed INSERT, UPDATE or DELETE
2032
+** statement on the database connection specified by the only parameter.
2033
+** ^Executing any other type of SQL statement does not modify the value
2034
+** returned by this function.
2035
+**
2036
+** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2037
+** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2038
+** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2039
+**
2040
+** Changes to a view that are intercepted by
2041
+** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2042
+** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2043
+** DELETE statement run on a view is always zero. Only changes made to real
2044
+** tables are counted.
2045
+**
2046
+** Things are more complicated if the sqlite3_changes() function is
2047
+** executed while a trigger program is running. This may happen if the
2048
+** program uses the [changes() SQL function], or if some other callback
2049
+** function invokes sqlite3_changes() directly. Essentially:
2050
+**
2051
+** <ul>
2052
+** <li> ^(Before entering a trigger program the value returned by
2053
+** sqlite3_changes() function is saved. After the trigger program
2054
+** has finished, the original value is restored.)^
2055
+**
2056
+** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2057
+** statement sets the value returned by sqlite3_changes()
2058
+** upon completion as normal. Of course, this value will not include
2059
+** any changes performed by sub-triggers, as the sqlite3_changes()
2060
+** value will be saved and restored after each sub-trigger has run.)^
2061
+** </ul>
2062
+**
2063
+** ^This means that if the changes() SQL function (or similar) is used
2064
+** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2065
+** returns the value as set when the calling statement began executing.
2066
+** ^If it is used by the second or subsequent such statement within a trigger
2067
+** program, the value returned reflects the number of rows modified by the
2068
+** previous INSERT, UPDATE or DELETE statement within the same trigger.
20432069
**
20442070
** See also the [sqlite3_total_changes()] interface, the
20452071
** [count_changes pragma], and the [changes() SQL function].
20462072
**
20472073
** If a separate thread makes changes on the same database connection
@@ -2051,24 +2077,21 @@
20512077
SQLITE_API int sqlite3_changes(sqlite3*);
20522078
20532079
/*
20542080
** CAPI3REF: Total Number Of Rows Modified
20552081
**
2056
-** ^This function returns the number of row changes caused by [INSERT],
2057
-** [UPDATE] or [DELETE] statements since the [database connection] was opened.
2058
-** ^(The count returned by sqlite3_total_changes() includes all changes
2059
-** from all [CREATE TRIGGER | trigger] contexts and changes made by
2060
-** [foreign key actions]. However,
2061
-** the count does not include changes used to implement [REPLACE] constraints,
2062
-** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
2063
-** count does not include rows of views that fire an [INSTEAD OF trigger],
2064
-** though if the INSTEAD OF trigger makes changes of its own, those changes
2065
-** are counted.)^
2066
-** ^The sqlite3_total_changes() function counts the changes as soon as
2067
-** the statement that makes them is completed (when the statement handle
2068
-** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
2069
-**
2082
+** ^This function returns the total number of rows inserted, modified or
2083
+** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2084
+** since the database connection was opened, including those executed as
2085
+** part of trigger programs. ^Executing any other type of SQL statement
2086
+** does not affect the value returned by sqlite3_total_changes().
2087
+**
2088
+** ^Changes made as part of [foreign key actions] are included in the
2089
+** count, but those made as part of REPLACE constraint resolution are
2090
+** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2091
+** are not counted.
2092
+**
20702093
** See also the [sqlite3_changes()] interface, the
20712094
** [count_changes pragma], and the [total_changes() SQL function].
20722095
**
20732096
** If a separate thread makes changes on the same database connection
20742097
** while [sqlite3_total_changes()] is running then the value
@@ -2151,10 +2174,11 @@
21512174
SQLITE_API int sqlite3_complete(const char *sql);
21522175
SQLITE_API int sqlite3_complete16(const void *sql);
21532176
21542177
/*
21552178
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2179
+** KEYWORDS: {busy-handler callback} {busy handler}
21562180
**
21572181
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
21582182
** that might be invoked with argument P whenever
21592183
** an attempt is made to access a database table associated with
21602184
** [database connection] D when another thread
@@ -2167,11 +2191,11 @@
21672191
** is not NULL, then the callback might be invoked with two arguments.
21682192
**
21692193
** ^The first argument to the busy handler is a copy of the void* pointer which
21702194
** is the third argument to sqlite3_busy_handler(). ^The second argument to
21712195
** the busy handler callback is the number of times that the busy handler has
2172
-** been invoked for the same locking event. ^If the
2196
+** been invoked previously for the same locking event. ^If the
21732197
** busy callback returns 0, then no additional attempts are made to
21742198
** access the database and [SQLITE_BUSY] is returned
21752199
** to the application.
21762200
** ^If the callback returns non-zero, then another attempt
21772201
** is made to access the database and the cycle repeats.
@@ -2542,17 +2566,18 @@
25422566
** already uses the largest possible [ROWID]. The PRNG is also used for
25432567
** the build-in random() and randomblob() SQL functions. This interface allows
25442568
** applications to access the same PRNG for other purposes.
25452569
**
25462570
** ^A call to this routine stores N bytes of randomness into buffer P.
2547
-** ^If N is less than one, then P can be a NULL pointer.
2571
+** ^The P parameter can be a NULL pointer.
25482572
**
25492573
** ^If this routine has not been previously called or if the previous
2550
-** call had N less than one, then the PRNG is seeded using randomness
2551
-** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2552
-** ^If the previous call to this routine had an N of 1 or more then
2553
-** the pseudo-randomness is generated
2574
+** call had N less than one or a NULL pointer for P, then the PRNG is
2575
+** seeded using randomness obtained from the xRandomness method of
2576
+** the default [sqlite3_vfs] object.
2577
+** ^If the previous call to this routine had an N of 1 or more and a
2578
+** non-NULL P then the pseudo-randomness is generated
25542579
** internally and without recourse to the [sqlite3_vfs] xRandomness
25552580
** method.
25562581
*/
25572582
SQLITE_API void sqlite3_randomness(int N, void *P);
25582583
@@ -4270,13 +4295,13 @@
42704295
** CAPI3REF: Text Encodings
42714296
**
42724297
** These constant define integer codes that represent the various
42734298
** text encodings supported by SQLite.
42744299
*/
4275
-#define SQLITE_UTF8 1
4276
-#define SQLITE_UTF16LE 2
4277
-#define SQLITE_UTF16BE 3
4300
+#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
4301
+#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
4302
+#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
42784303
#define SQLITE_UTF16 4 /* Use native byte order */
42794304
#define SQLITE_ANY 5 /* Deprecated */
42804305
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
42814306
42824307
/*
@@ -4621,11 +4646,12 @@
46214646
** If these routines are called from within the different thread
46224647
** than the one containing the application-defined function that received
46234648
** the [sqlite3_context] pointer, the results are undefined.
46244649
*/
46254650
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4626
-SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
4651
+SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
4652
+ sqlite3_uint64,void(*)(void*));
46274653
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
46284654
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
46294655
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
46304656
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
46314657
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5253,24 +5279,31 @@
52535279
52545280
52555281
/*
52565282
** CAPI3REF: Extract Metadata About A Column Of A Table
52575283
**
5258
-** ^This routine returns metadata about a specific column of a specific
5259
-** database table accessible using the [database connection] handle
5260
-** passed as the first function argument.
5284
+** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5285
+** information about column C of table T in database D
5286
+** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5287
+** interface returns SQLITE_OK and fills in the non-NULL pointers in
5288
+** the final five arguments with appropriate values if the specified
5289
+** column exists. ^The sqlite3_table_column_metadata() interface returns
5290
+** SQLITE_ERROR and if the specified column does not exist.
5291
+** ^If the column-name parameter to sqlite3_table_column_metadata() is a
5292
+** NULL pointer, then this routine simply checks for the existance of the
5293
+** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5294
+** does not.
52615295
**
52625296
** ^The column is identified by the second, third and fourth parameters to
5263
-** this function. ^The second parameter is either the name of the database
5297
+** this function. ^(The second parameter is either the name of the database
52645298
** (i.e. "main", "temp", or an attached database) containing the specified
5265
-** table or NULL. ^If it is NULL, then all attached databases are searched
5299
+** table or NULL.)^ ^If it is NULL, then all attached databases are searched
52665300
** for the table using the same algorithm used by the database engine to
52675301
** resolve unqualified table references.
52685302
**
52695303
** ^The third and fourth parameters to this function are the table and column
5270
-** name of the desired column, respectively. Neither of these parameters
5271
-** may be NULL.
5304
+** name of the desired column, respectively.
52725305
**
52735306
** ^Metadata is returned by writing to the memory locations passed as the 5th
52745307
** and subsequent parameters to this function. ^Any of these arguments may be
52755308
** NULL, in which case the corresponding element of metadata is omitted.
52765309
**
@@ -5285,36 +5318,33 @@
52855318
** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
52865319
** </table>
52875320
** </blockquote>)^
52885321
**
52895322
** ^The memory pointed to by the character pointers returned for the
5290
-** declaration type and collation sequence is valid only until the next
5323
+** declaration type and collation sequence is valid until the next
52915324
** call to any SQLite API function.
52925325
**
52935326
** ^If the specified table is actually a view, an [error code] is returned.
52945327
**
5295
-** ^If the specified column is "rowid", "oid" or "_rowid_" and an
5328
+** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5329
+** is not a [WITHOUT ROWID] table and an
52965330
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
52975331
** parameters are set for the explicitly declared column. ^(If there is no
5298
-** explicitly declared [INTEGER PRIMARY KEY] column, then the output
5299
-** parameters are set as follows:
5332
+** [INTEGER PRIMARY KEY] column, then the outputs
5333
+** for the [rowid] are set as follows:
53005334
**
53015335
** <pre>
53025336
** data type: "INTEGER"
53035337
** collation sequence: "BINARY"
53045338
** not null: 0
53055339
** primary key: 1
53065340
** auto increment: 0
53075341
** </pre>)^
53085342
**
5309
-** ^(This function may load one or more schemas from database files. If an
5310
-** error occurs during this process, or if the requested table or column
5311
-** cannot be found, an [error code] is returned and an error message left
5312
-** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
5313
-**
5314
-** ^This API is only available if the library was compiled with the
5315
-** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
5343
+** ^This function causes all database schemas to be read from disk and
5344
+** parsed, if that has not already been done, and returns an error if
5345
+** any errors are encountered while loading the schema.
53165346
*/
53175347
SQLITE_API int sqlite3_table_column_metadata(
53185348
sqlite3 *db, /* Connection handle */
53195349
const char *zDbName, /* Database name or NULL */
53205350
const char *zTableName, /* Table name */
@@ -5762,31 +5792,47 @@
57625792
** in other words, the same BLOB that would be selected by:
57635793
**
57645794
** <pre>
57655795
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
57665796
** </pre>)^
5797
+**
5798
+** ^(Parameter zDb is not the filename that contains the database, but
5799
+** rather the symbolic name of the database. For attached databases, this is
5800
+** the name that appears after the AS keyword in the [ATTACH] statement.
5801
+** For the main database file, the database name is "main". For TEMP
5802
+** tables, the database name is "temp".)^
57675803
**
57685804
** ^If the flags parameter is non-zero, then the BLOB is opened for read
5769
-** and write access. ^If it is zero, the BLOB is opened for read access.
5770
-** ^It is not possible to open a column that is part of an index or primary
5771
-** key for writing. ^If [foreign key constraints] are enabled, it is
5772
-** not possible to open a column that is part of a [child key] for writing.
5773
-**
5774
-** ^Note that the database name is not the filename that contains
5775
-** the database but rather the symbolic name of the database that
5776
-** appears after the AS keyword when the database is connected using [ATTACH].
5777
-** ^For the main database file, the database name is "main".
5778
-** ^For TEMP tables, the database name is "temp".
5779
-**
5780
-** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5781
-** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5782
-** to be a null pointer.)^
5783
-** ^This function sets the [database connection] error code and message
5784
-** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5785
-** functions. ^Note that the *ppBlob variable is always initialized in a
5786
-** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5787
-** regardless of the success or failure of this routine.
5805
+** and write access. ^If the flags parameter is zero, the BLOB is opened for
5806
+** read-only access.
5807
+**
5808
+** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5809
+** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5810
+** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5811
+** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5812
+** on *ppBlob after this function it returns.
5813
+**
5814
+** This function fails with SQLITE_ERROR if any of the following are true:
5815
+** <ul>
5816
+** <li> ^(Database zDb does not exist)^,
5817
+** <li> ^(Table zTable does not exist within database zDb)^,
5818
+** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5819
+** <li> ^(Column zColumn does not exist)^,
5820
+** <li> ^(Row iRow is not present in the table)^,
5821
+** <li> ^(The specified column of row iRow contains a value that is not
5822
+** a TEXT or BLOB value)^,
5823
+** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5824
+** constraint and the blob is being opened for read/write access)^,
5825
+** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5826
+** column zColumn is part of a [child key] definition and the blob is
5827
+** being opened for read/write access)^.
5828
+** </ul>
5829
+**
5830
+** ^Unless it returns SQLITE_MISUSE, this function sets the
5831
+** [database connection] error code and message accessible via
5832
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5833
+**
57885834
**
57895835
** ^(If the row that a BLOB handle points to is modified by an
57905836
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
57915837
** then the BLOB handle is marked as "expired".
57925838
** This is true if any column of the row is changed, even a column
@@ -5800,17 +5846,13 @@
58005846
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
58015847
** the opened blob. ^The size of a blob may not be changed by this
58025848
** interface. Use the [UPDATE] SQL command to change the size of a
58035849
** blob.
58045850
**
5805
-** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5806
-** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5807
-**
58085851
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5809
-** and the built-in [zeroblob] SQL function can be used, if desired,
5810
-** to create an empty, zero-filled blob in which to read or write using
5811
-** this interface.
5852
+** and the built-in [zeroblob] SQL function may be used to create a
5853
+** zero-filled blob to read or write using the incremental-blob interface.
58125854
**
58135855
** To avoid a resource leak, every open [BLOB handle] should eventually
58145856
** be released by a call to [sqlite3_blob_close()].
58155857
*/
58165858
SQLITE_API int sqlite3_blob_open(
@@ -5848,28 +5890,26 @@
58485890
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
58495891
58505892
/*
58515893
** CAPI3REF: Close A BLOB Handle
58525894
**
5853
-** ^Closes an open [BLOB handle].
5854
-**
5855
-** ^Closing a BLOB shall cause the current transaction to commit
5856
-** if there are no other BLOBs, no pending prepared statements, and the
5857
-** database connection is in [autocommit mode].
5858
-** ^If any writes were made to the BLOB, they might be held in cache
5859
-** until the close operation if they will fit.
5860
-**
5861
-** ^(Closing the BLOB often forces the changes
5862
-** out to disk and so if any I/O errors occur, they will likely occur
5863
-** at the time when the BLOB is closed. Any errors that occur during
5864
-** closing are reported as a non-zero return value.)^
5865
-**
5866
-** ^(The BLOB is closed unconditionally. Even if this routine returns
5867
-** an error code, the BLOB is still closed.)^
5868
-**
5869
-** ^Calling this routine with a null pointer (such as would be returned
5870
-** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5895
+** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5896
+** unconditionally. Even if this routine returns an error code, the
5897
+** handle is still closed.)^
5898
+**
5899
+** ^If the blob handle being closed was opened for read-write access, and if
5900
+** the database is in auto-commit mode and there are no other open read-write
5901
+** blob handles or active write statements, the current transaction is
5902
+** committed. ^If an error occurs while committing the transaction, an error
5903
+** code is returned and the transaction rolled back.
5904
+**
5905
+** Calling this function with an argument that is not a NULL pointer or an
5906
+** open blob handle results in undefined behaviour. ^Calling this routine
5907
+** with a null pointer (such as would be returned by a failed call to
5908
+** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5909
+** is passed a valid open blob handle, the values returned by the
5910
+** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
58715911
*/
58725912
SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
58735913
58745914
/*
58755915
** CAPI3REF: Return The Size Of An Open BLOB
@@ -5915,36 +5955,39 @@
59155955
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
59165956
59175957
/*
59185958
** CAPI3REF: Write Data Into A BLOB Incrementally
59195959
**
5920
-** ^This function is used to write data into an open [BLOB handle] from a
5921
-** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5922
-** into the open BLOB, starting at offset iOffset.
5960
+** ^(This function is used to write data into an open [BLOB handle] from a
5961
+** caller-supplied buffer. N bytes of data are copied from the buffer Z
5962
+** into the open BLOB, starting at offset iOffset.)^
5963
+**
5964
+** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5965
+** Otherwise, an [error code] or an [extended error code] is returned.)^
5966
+** ^Unless SQLITE_MISUSE is returned, this function sets the
5967
+** [database connection] error code and message accessible via
5968
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
59235969
**
59245970
** ^If the [BLOB handle] passed as the first argument was not opened for
59255971
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
59265972
** this function returns [SQLITE_READONLY].
59275973
**
5928
-** ^This function may only modify the contents of the BLOB; it is
5974
+** This function may only modify the contents of the BLOB; it is
59295975
** not possible to increase the size of a BLOB using this API.
59305976
** ^If offset iOffset is less than N bytes from the end of the BLOB,
5931
-** [SQLITE_ERROR] is returned and no data is written. ^If N is
5932
-** less than zero [SQLITE_ERROR] is returned and no data is written.
5933
-** The size of the BLOB (and hence the maximum value of N+iOffset)
5934
-** can be determined using the [sqlite3_blob_bytes()] interface.
5977
+** [SQLITE_ERROR] is returned and no data is written. The size of the
5978
+** BLOB (and hence the maximum value of N+iOffset) can be determined
5979
+** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5980
+** than zero [SQLITE_ERROR] is returned and no data is written.
59355981
**
59365982
** ^An attempt to write to an expired [BLOB handle] fails with an
59375983
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
59385984
** before the [BLOB handle] expired are not rolled back by the
59395985
** expiration of the handle, though of course those changes might
59405986
** have been overwritten by the statement that expired the BLOB handle
59415987
** or by other independent statements.
59425988
**
5943
-** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5944
-** Otherwise, an [error code] or an [extended error code] is returned.)^
5945
-**
59465989
** This routine only works on a [BLOB handle] which has been created
59475990
** by a prior successful call to [sqlite3_blob_open()] and which has not
59485991
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
59495992
** to this routine results in undefined and probably undesirable behavior.
59505993
**
@@ -5993,38 +6036,38 @@
59936036
** use by SQLite, code that links against SQLite is
59946037
** permitted to use any of these routines.
59956038
**
59966039
** The SQLite source code contains multiple implementations
59976040
** of these mutex routines. An appropriate implementation
5998
-** is selected automatically at compile-time. ^(The following
6041
+** is selected automatically at compile-time. The following
59996042
** implementations are available in the SQLite core:
60006043
**
60016044
** <ul>
60026045
** <li> SQLITE_MUTEX_PTHREADS
60036046
** <li> SQLITE_MUTEX_W32
60046047
** <li> SQLITE_MUTEX_NOOP
6005
-** </ul>)^
6048
+** </ul>
60066049
**
6007
-** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
6050
+** The SQLITE_MUTEX_NOOP implementation is a set of routines
60086051
** that does no real locking and is appropriate for use in
6009
-** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
6052
+** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
60106053
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
60116054
** and Windows.
60126055
**
6013
-** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
6056
+** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
60146057
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
60156058
** implementation is included with the library. In this case the
60166059
** application must supply a custom mutex implementation using the
60176060
** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
60186061
** before calling sqlite3_initialize() or any other public sqlite3_
6019
-** function that calls sqlite3_initialize().)^
6062
+** function that calls sqlite3_initialize().
60206063
**
60216064
** ^The sqlite3_mutex_alloc() routine allocates a new
6022
-** mutex and returns a pointer to it. ^If it returns NULL
6023
-** that means that a mutex could not be allocated. ^SQLite
6024
-** will unwind its stack and return an error. ^(The argument
6025
-** to sqlite3_mutex_alloc() is one of these integer constants:
6065
+** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
6066
+** routine returns NULL if it is unable to allocate the requested
6067
+** mutex. The argument to sqlite3_mutex_alloc() must one of these
6068
+** integer constants:
60266069
**
60276070
** <ul>
60286071
** <li> SQLITE_MUTEX_FAST
60296072
** <li> SQLITE_MUTEX_RECURSIVE
60306073
** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -6033,68 +6076,64 @@
60336076
** <li> SQLITE_MUTEX_STATIC_PRNG
60346077
** <li> SQLITE_MUTEX_STATIC_LRU
60356078
** <li> SQLITE_MUTEX_STATIC_PMEM
60366079
** <li> SQLITE_MUTEX_STATIC_APP1
60376080
** <li> SQLITE_MUTEX_STATIC_APP2
6038
-** </ul>)^
6081
+** <li> SQLITE_MUTEX_STATIC_APP3
6082
+** </ul>
60396083
**
60406084
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
60416085
** cause sqlite3_mutex_alloc() to create
60426086
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
60436087
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
60446088
** The mutex implementation does not need to make a distinction
60456089
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
6046
-** not want to. ^SQLite will only request a recursive mutex in
6047
-** cases where it really needs one. ^If a faster non-recursive mutex
6090
+** not want to. SQLite will only request a recursive mutex in
6091
+** cases where it really needs one. If a faster non-recursive mutex
60486092
** implementation is available on the host platform, the mutex subsystem
60496093
** might return such a mutex in response to SQLITE_MUTEX_FAST.
60506094
**
60516095
** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
60526096
** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
6053
-** a pointer to a static preexisting mutex. ^Six static mutexes are
6097
+** a pointer to a static preexisting mutex. ^Nine static mutexes are
60546098
** used by the current version of SQLite. Future versions of SQLite
60556099
** may add additional static mutexes. Static mutexes are for internal
60566100
** use by SQLite only. Applications that use SQLite mutexes should
60576101
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
60586102
** SQLITE_MUTEX_RECURSIVE.
60596103
**
60606104
** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
60616105
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
6062
-** returns a different mutex on every call. ^But for the static
6106
+** returns a different mutex on every call. ^For the static
60636107
** mutex types, the same mutex is returned on every call that has
60646108
** the same type number.
60656109
**
60666110
** ^The sqlite3_mutex_free() routine deallocates a previously
6067
-** allocated dynamic mutex. ^SQLite is careful to deallocate every
6068
-** dynamic mutex that it allocates. The dynamic mutexes must not be in
6069
-** use when they are deallocated. Attempting to deallocate a static
6070
-** mutex results in undefined behavior. ^SQLite never deallocates
6071
-** a static mutex.
6111
+** allocated dynamic mutex. Attempting to deallocate a static
6112
+** mutex results in undefined behavior.
60726113
**
60736114
** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
60746115
** to enter a mutex. ^If another thread is already within the mutex,
60756116
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
60766117
** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
60776118
** upon successful entry. ^(Mutexes created using
60786119
** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
6079
-** In such cases the,
6120
+** In such cases, the
60806121
** mutex must be exited an equal number of times before another thread
6081
-** can enter.)^ ^(If the same thread tries to enter any other
6082
-** kind of mutex more than once, the behavior is undefined.
6083
-** SQLite will never exhibit
6084
-** such behavior in its own use of mutexes.)^
6122
+** can enter.)^ If the same thread tries to enter any mutex other
6123
+** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
60856124
**
60866125
** ^(Some systems (for example, Windows 95) do not support the operation
60876126
** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
6088
-** will always return SQLITE_BUSY. The SQLite core only ever uses
6089
-** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
6127
+** will always return SQLITE_BUSY. The SQLite core only ever uses
6128
+** sqlite3_mutex_try() as an optimization so this is acceptable
6129
+** behavior.)^
60906130
**
60916131
** ^The sqlite3_mutex_leave() routine exits a mutex that was
6092
-** previously entered by the same thread. ^(The behavior
6132
+** previously entered by the same thread. The behavior
60936133
** is undefined if the mutex is not currently entered by the
6094
-** calling thread or is not currently allocated. SQLite will
6095
-** never do either.)^
6134
+** calling thread or is not currently allocated.
60966135
**
60976136
** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
60986137
** sqlite3_mutex_leave() is a NULL pointer, then all three routines
60996138
** behave as no-ops.
61006139
**
@@ -6111,13 +6150,13 @@
61116150
**
61126151
** An instance of this structure defines the low-level routines
61136152
** used to allocate and use mutexes.
61146153
**
61156154
** Usually, the default mutex implementations provided by SQLite are
6116
-** sufficient, however the user has the option of substituting a custom
6155
+** sufficient, however the application has the option of substituting a custom
61176156
** implementation for specialized deployments or systems for which SQLite
6118
-** does not provide a suitable implementation. In this case, the user
6157
+** does not provide a suitable implementation. In this case, the application
61196158
** creates and populates an instance of this structure to pass
61206159
** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
61216160
** Additionally, an instance of this structure can be used as an
61226161
** output variable when querying the system for the current mutex
61236162
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6154,17 +6193,17 @@
61546193
** by this structure are not required to handle this case, the results
61556194
** of passing a NULL pointer instead of a valid mutex handle are undefined
61566195
** (i.e. it is acceptable to provide an implementation that segfaults if
61576196
** it is passed a NULL pointer).
61586197
**
6159
-** The xMutexInit() method must be threadsafe. ^It must be harmless to
6198
+** The xMutexInit() method must be threadsafe. It must be harmless to
61606199
** invoke xMutexInit() multiple times within the same process and without
61616200
** intervening calls to xMutexEnd(). Second and subsequent calls to
61626201
** xMutexInit() must be no-ops.
61636202
**
6164
-** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6165
-** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
6203
+** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6204
+** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
61666205
** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
61676206
** memory allocation for a fast or recursive mutex.
61686207
**
61696208
** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
61706209
** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6186,33 +6225,33 @@
61866225
61876226
/*
61886227
** CAPI3REF: Mutex Verification Routines
61896228
**
61906229
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6191
-** are intended for use inside assert() statements. ^The SQLite core
6230
+** are intended for use inside assert() statements. The SQLite core
61926231
** never uses these routines except inside an assert() and applications
6193
-** are advised to follow the lead of the core. ^The SQLite core only
6232
+** are advised to follow the lead of the core. The SQLite core only
61946233
** provides implementations for these routines when it is compiled
6195
-** with the SQLITE_DEBUG flag. ^External mutex implementations
6234
+** with the SQLITE_DEBUG flag. External mutex implementations
61966235
** are only required to provide these routines if SQLITE_DEBUG is
61976236
** defined and if NDEBUG is not defined.
61986237
**
6199
-** ^These routines should return true if the mutex in their argument
6238
+** These routines should return true if the mutex in their argument
62006239
** is held or not held, respectively, by the calling thread.
62016240
**
6202
-** ^The implementation is not required to provide versions of these
6241
+** The implementation is not required to provide versions of these
62036242
** routines that actually work. If the implementation does not provide working
62046243
** versions of these routines, it should at least provide stubs that always
62056244
** return true so that one does not get spurious assertion failures.
62066245
**
6207
-** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
6246
+** If the argument to sqlite3_mutex_held() is a NULL pointer then
62086247
** the routine should return 1. This seems counter-intuitive since
62096248
** clearly the mutex cannot be held if it does not exist. But
62106249
** the reason the mutex does not exist is because the build is not
62116250
** using mutexes. And we do not want the assert() containing the
62126251
** call to sqlite3_mutex_held() to fail, so a non-zero return is
6213
-** the appropriate thing to do. ^The sqlite3_mutex_notheld()
6252
+** the appropriate thing to do. The sqlite3_mutex_notheld()
62146253
** interface should also return 1 when given a NULL pointer.
62156254
*/
62166255
#ifndef NDEBUG
62176256
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
62186257
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6940,10 +6979,14 @@
69406979
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
69416980
** and database name of the source database, respectively.
69426981
** ^The source and destination [database connections] (parameters S and D)
69436982
** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
69446983
** an error.
6984
+**
6985
+** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
6986
+** there is already a read or read-write transaction open on the
6987
+** destination database.
69456988
**
69466989
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
69476990
** returned and an error code and error message are stored in the
69486991
** destination [database connection] D.
69496992
** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7334,101 +7377,118 @@
73347377
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
73357378
73367379
/*
73377380
** CAPI3REF: Checkpoint a database
73387381
**
7339
-** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7340
-** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7341
-** empty string, then a checkpoint is run on all databases of
7342
-** connection D. ^If the database connection D is not in
7343
-** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7344
-** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7345
-** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7346
-** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7347
-** or RESET checkpoint.
7348
-**
7349
-** ^The [wal_checkpoint pragma] can be used to invoke this interface
7350
-** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7351
-** [wal_autocheckpoint pragma] can be used to cause this interface to be
7352
-** run whenever the WAL reaches a certain size threshold.
7353
-**
7354
-** See also: [sqlite3_wal_checkpoint_v2()]
7382
+** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7383
+** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7384
+**
7385
+** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
7386
+** [write-ahead log] for database X on [database connection] D to be
7387
+** transferred into the database file and for the write-ahead log to
7388
+** be reset. See the [checkpointing] documentation for addition
7389
+** information.
7390
+**
7391
+** This interface used to be the only way to cause a checkpoint to
7392
+** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
7393
+** interface was added. This interface is retained for backwards
7394
+** compatibility and as a convenience for applications that need to manually
7395
+** start a callback but which do not need the full power (and corresponding
7396
+** complication) of [sqlite3_wal_checkpoint_v2()].
73557397
*/
73567398
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
73577399
73587400
/*
73597401
** CAPI3REF: Checkpoint a database
73607402
**
7361
-** Run a checkpoint operation on WAL database zDb attached to database
7362
-** handle db. The specific operation is determined by the value of the
7363
-** eMode parameter:
7403
+** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7404
+** operation on database X of [database connection] D in mode M. Status
7405
+** information is written back into integers pointed to by L and C.)^
7406
+** ^(The M parameter must be a valid [checkpoint mode]:)^
73647407
**
73657408
** <dl>
73667409
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7367
-** Checkpoint as many frames as possible without waiting for any database
7368
-** readers or writers to finish. Sync the db file if all frames in the log
7369
-** are checkpointed. This mode is the same as calling
7370
-** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7371
-** is never invoked.
7410
+** ^Checkpoint as many frames as possible without waiting for any database
7411
+** readers or writers to finish, then sync the database file if all frames
7412
+** in the log were checkpointed. ^The [busy-handler callback]
7413
+** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
7414
+** ^On the other hand, passive mode might leave the checkpoint unfinished
7415
+** if there are concurrent readers or writers.
73727416
**
73737417
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7374
-** This mode blocks (it invokes the
7418
+** ^This mode blocks (it invokes the
73757419
** [sqlite3_busy_handler|busy-handler callback]) until there is no
73767420
** database writer and all readers are reading from the most recent database
7377
-** snapshot. It then checkpoints all frames in the log file and syncs the
7378
-** database file. This call blocks database writers while it is running,
7379
-** but not database readers.
7421
+** snapshot. ^It then checkpoints all frames in the log file and syncs the
7422
+** database file. ^This mode blocks new database writers while it is pending,
7423
+** but new database readers are allowed to continue unimpeded.
73807424
**
73817425
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7382
-** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7383
-** checkpointing the log file it blocks (calls the
7384
-** [sqlite3_busy_handler|busy-handler callback])
7385
-** until all readers are reading from the database file only. This ensures
7386
-** that the next client to write to the database file restarts the log file
7387
-** from the beginning. This call blocks database writers while it is running,
7388
-** but not database readers.
7426
+** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
7427
+** that after checkpointing the log file it blocks (calls the
7428
+** [busy-handler callback])
7429
+** until all readers are reading from the database file only. ^This ensures
7430
+** that the next writer will restart the log file from the beginning.
7431
+** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
7432
+** database writer attempts while it is pending, but does not impede readers.
7433
+**
7434
+** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
7435
+** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
7436
+** addition that it also truncates the log file to zero bytes just prior
7437
+** to a successful return.
73897438
** </dl>
73907439
**
7391
-** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7392
-** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7393
-** the total number of checkpointed frames (including any that were already
7394
-** checkpointed when this function is called). *pnLog and *pnCkpt may be
7395
-** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
7396
-** If no values are available because of an error, they are both set to -1
7397
-** before returning to communicate this to the caller.
7440
+** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
7441
+** the log file or to -1 if the checkpoint could not run because
7442
+** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
7443
+** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
7444
+** log file (including any that were already checkpointed before the function
7445
+** was called) or to -1 if the checkpoint could not run due to an error or
7446
+** because the database is not in WAL mode. ^Note that upon successful
7447
+** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
7448
+** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
73987449
**
7399
-** All calls obtain an exclusive "checkpoint" lock on the database file. If
7450
+** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
74007451
** any other process is running a checkpoint operation at the same time, the
7401
-** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
7452
+** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
74027453
** busy-handler configured, it will not be invoked in this case.
74037454
**
7404
-** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
7405
-** "writer" lock on the database file. If the writer lock cannot be obtained
7406
-** immediately, and a busy-handler is configured, it is invoked and the writer
7407
-** lock retried until either the busy-handler returns 0 or the lock is
7408
-** successfully obtained. The busy-handler is also invoked while waiting for
7409
-** database readers as described above. If the busy-handler returns 0 before
7455
+** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
7456
+** exclusive "writer" lock on the database file. ^If the writer lock cannot be
7457
+** obtained immediately, and a busy-handler is configured, it is invoked and
7458
+** the writer lock retried until either the busy-handler returns 0 or the lock
7459
+** is successfully obtained. ^The busy-handler is also invoked while waiting for
7460
+** database readers as described above. ^If the busy-handler returns 0 before
74107461
** the writer lock is obtained or while waiting for database readers, the
74117462
** checkpoint operation proceeds from that point in the same way as
74127463
** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7413
-** without blocking any further. SQLITE_BUSY is returned in this case.
7464
+** without blocking any further. ^SQLITE_BUSY is returned in this case.
74147465
**
7415
-** If parameter zDb is NULL or points to a zero length string, then the
7416
-** specified operation is attempted on all WAL databases. In this case the
7417
-** values written to output parameters *pnLog and *pnCkpt are undefined. If
7466
+** ^If parameter zDb is NULL or points to a zero length string, then the
7467
+** specified operation is attempted on all WAL databases [attached] to
7468
+** [database connection] db. In this case the
7469
+** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
74187470
** an SQLITE_BUSY error is encountered when processing one or more of the
74197471
** attached WAL databases, the operation is still attempted on any remaining
7420
-** attached databases and SQLITE_BUSY is returned to the caller. If any other
7472
+** attached databases and SQLITE_BUSY is returned at the end. ^If any other
74217473
** error occurs while processing an attached database, processing is abandoned
7422
-** and the error code returned to the caller immediately. If no error
7474
+** and the error code is returned to the caller immediately. ^If no error
74237475
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
74247476
** databases, SQLITE_OK is returned.
74257477
**
7426
-** If database zDb is the name of an attached database that is not in WAL
7427
-** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
7478
+** ^If database zDb is the name of an attached database that is not in WAL
7479
+** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
74287480
** zDb is not NULL (or a zero length string) and is not the name of any
74297481
** attached database, SQLITE_ERROR is returned to the caller.
7482
+**
7483
+** ^Unless it returns SQLITE_MISUSE,
7484
+** the sqlite3_wal_checkpoint_v2() interface
7485
+** sets the error information that is queried by
7486
+** [sqlite3_errcode()] and [sqlite3_errmsg()].
7487
+**
7488
+** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
7489
+** from SQL.
74307490
*/
74317491
SQLITE_API int sqlite3_wal_checkpoint_v2(
74327492
sqlite3 *db, /* Database handle */
74337493
const char *zDb, /* Name of attached database (or NULL) */
74347494
int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7435,20 +7495,22 @@
74357495
int *pnLog, /* OUT: Size of WAL log in frames */
74367496
int *pnCkpt /* OUT: Total number of frames checkpointed */
74377497
);
74387498
74397499
/*
7440
-** CAPI3REF: Checkpoint operation parameters
7500
+** CAPI3REF: Checkpoint Mode Values
7501
+** KEYWORDS: {checkpoint mode}
74417502
**
7442
-** These constants can be used as the 3rd parameter to
7443
-** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
7444
-** documentation for additional information about the meaning and use of
7445
-** each of these values.
7503
+** These constants define all valid values for the "checkpoint mode" passed
7504
+** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
7505
+** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
7506
+** meaning of each of these checkpoint modes.
74467507
*/
7447
-#define SQLITE_CHECKPOINT_PASSIVE 0
7448
-#define SQLITE_CHECKPOINT_FULL 1
7449
-#define SQLITE_CHECKPOINT_RESTART 2
7508
+#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
7509
+#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
7510
+#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
7511
+#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
74507512
74517513
/*
74527514
** CAPI3REF: Virtual Table Interface Configuration
74537515
**
74547516
** This function may be called by either the [xConnect] or [xCreate] method
@@ -7533,10 +7595,102 @@
75337595
/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
75347596
#define SQLITE_FAIL 3
75357597
/* #define SQLITE_ABORT 4 // Also an error code */
75367598
#define SQLITE_REPLACE 5
75377599
7600
+/*
7601
+** CAPI3REF: Prepared Statement Scan Status Opcodes
7602
+** KEYWORDS: {scanstatus options}
7603
+**
7604
+** The following constants can be used for the T parameter to the
7605
+** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7606
+** different metric for sqlite3_stmt_scanstatus() to return.
7607
+**
7608
+** <dl>
7609
+** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7610
+** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7611
+** set to the total number of times that the X-th loop has run.</dd>
7612
+**
7613
+** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7614
+** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
7615
+** to the total number of rows examined by all iterations of the X-th loop.</dd>
7616
+**
7617
+** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7618
+** <dd>^The "double" variable pointed to by the T parameter will be set to the
7619
+** query planner's estimate for the average number of rows output from each
7620
+** iteration of the X-th loop. If the query planner's estimates was accurate,
7621
+** then this value will approximate the quotient NVISIT/NLOOP and the
7622
+** product of this value for all prior loops with the same SELECTID will
7623
+** be the NLOOP value for the current loop.
7624
+**
7625
+** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7626
+** <dd>^The "const char *" variable pointed to by the T parameter will be set
7627
+** to a zero-terminated UTF-8 string containing the name of the index or table
7628
+** used for the X-th loop.
7629
+**
7630
+** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7631
+** <dd>^The "const char *" variable pointed to by the T parameter will be set
7632
+** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
7633
+** description for the X-th loop.
7634
+**
7635
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7636
+** <dd>^The "int" variable pointed to by the T parameter will be set to the
7637
+** "select-id" for the X-th loop. The select-id identifies which query or
7638
+** subquery the loop is part of. The main query has a select-id of zero.
7639
+** The select-id is the same value as is output in the first column
7640
+** of an [EXPLAIN QUERY PLAN] query.
7641
+** </dl>
7642
+*/
7643
+#define SQLITE_SCANSTAT_NLOOP 0
7644
+#define SQLITE_SCANSTAT_NVISIT 1
7645
+#define SQLITE_SCANSTAT_EST 2
7646
+#define SQLITE_SCANSTAT_NAME 3
7647
+#define SQLITE_SCANSTAT_EXPLAIN 4
7648
+#define SQLITE_SCANSTAT_SELECTID 5
7649
+
7650
+/*
7651
+** CAPI3REF: Prepared Statement Scan Status
7652
+**
7653
+** Return status data for a single loop within query pStmt.
7654
+**
7655
+** The "iScanStatusOp" parameter determines which status information to return.
7656
+** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7657
+** of this interface is undefined.
7658
+** ^The requested measurement is written into a variable pointed to by
7659
+** the "pOut" parameter.
7660
+** Parameter "idx" identifies the specific loop to retrieve statistics for.
7661
+** Loops are numbered starting from zero. ^If idx is out of range - less than
7662
+** zero or greater than or equal to the total number of loops used to implement
7663
+** the statement - a non-zero value is returned and the variable that pOut
7664
+** points to is unchanged.
7665
+**
7666
+** ^Statistics might not be available for all loops in all statements. ^In cases
7667
+** where there exist loops with no available statistics, this function behaves
7668
+** as if the loop did not exist - it returns non-zero and leave the variable
7669
+** that pOut points to unchanged.
7670
+**
7671
+** This API is only available if the library is built with pre-processor
7672
+** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7673
+**
7674
+** See also: [sqlite3_stmt_scanstatus_reset()]
7675
+*/
7676
+SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7677
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7678
+ int idx, /* Index of loop to report on */
7679
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7680
+ void *pOut /* Result written here */
7681
+);
7682
+
7683
+/*
7684
+** CAPI3REF: Zero Scan-Status Counters
7685
+**
7686
+** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7687
+**
7688
+** This API is only available if the library is built with pre-processor
7689
+** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7690
+*/
7691
+SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
75387692
75397693
75407694
/*
75417695
** Undo the hack that converts floating point types to integer for
75427696
** builds on processors without floating point support.
@@ -7978,14 +8132,13 @@
79788132
#ifndef SQLITE_POWERSAFE_OVERWRITE
79798133
# define SQLITE_POWERSAFE_OVERWRITE 1
79808134
#endif
79818135
79828136
/*
7983
-** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
7984
-** It determines whether or not the features related to
7985
-** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
7986
-** be overridden at runtime using the sqlite3_config() API.
8137
+** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
8138
+** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
8139
+** which case memory allocation statistics are disabled by default.
79878140
*/
79888141
#if !defined(SQLITE_DEFAULT_MEMSTATUS)
79898142
# define SQLITE_DEFAULT_MEMSTATUS 1
79908143
#endif
79918144
@@ -8611,11 +8764,11 @@
86118764
** Estimated quantities used for query planning are stored as 16-bit
86128765
** logarithms. For quantity X, the value stored is 10*log2(X). This
86138766
** gives a possible range of values of approximately 1.0e986 to 1e-986.
86148767
** But the allowed values are "grainy". Not every value is representable.
86158768
** For example, quantities 16 and 17 are both represented by a LogEst
8616
-** of 40. However, since LogEst quantaties are suppose to be estimates,
8769
+** of 40. However, since LogEst quantities are suppose to be estimates,
86178770
** not exact values, this imprecision is not a problem.
86188771
**
86198772
** "LogEst" is short for "Logarithmic Estimate".
86208773
**
86218774
** Examples:
@@ -9011,11 +9164,11 @@
90119164
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
90129165
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
90139166
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
90149167
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
90159168
SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
9016
-SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int);
9169
+SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
90179170
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
90189171
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
90199172
SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
90209173
SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
90219174
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
@@ -9044,11 +9197,11 @@
90449197
#define BTREE_BLOBKEY 2 /* Table has keys only - no data */
90459198
90469199
SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
90479200
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
90489201
SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9049
-SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
9202
+SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int);
90509203
90519204
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
90529205
SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
90539206
90549207
SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9124,10 +9277,11 @@
91249277
SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
91259278
SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
91269279
SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
91279280
SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
91289281
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9282
+SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
91299283
91309284
#ifndef NDEBUG
91319285
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
91329286
#endif
91339287
@@ -9666,10 +9820,16 @@
96669820
# define VdbeCoverageAlwaysTaken(v)
96679821
# define VdbeCoverageNeverTaken(v)
96689822
# define VDBE_OFFSET_LINENO(x) 0
96699823
#endif
96709824
9825
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9826
+SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
9827
+#else
9828
+# define sqlite3VdbeScanStatus(a,b,c,d,e)
9829
+#endif
9830
+
96719831
#endif
96729832
96739833
/************** End of vdbe.h ************************************************/
96749834
/************** Continuing where we left off in sqliteInt.h ******************/
96759835
/************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9862,10 +10022,12 @@
986210022
SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
986310023
986410024
/* Functions used to truncate the database file. */
986510025
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
986610026
10027
+SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
10028
+
986710029
#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
986810030
SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
986910031
#endif
987010032
987110033
/* Functions to support testing and debugging. */
@@ -10049,10 +10211,14 @@
1004910211
SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
1005010212
#endif
1005110213
1005210214
SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
1005310215
10216
+/* Return the header size */
10217
+SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
10218
+SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
10219
+
1005410220
#endif /* _PCACHE_H_ */
1005510221
1005610222
/************** End of pcache.h **********************************************/
1005710223
/************** Continuing where we left off in sqliteInt.h ******************/
1005810224
@@ -10735,11 +10901,11 @@
1073510901
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1073610902
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1073710903
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1073810904
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
1073910905
#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10740
-#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10906
+#define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
1074110907
#define SQLITE_AllOpts 0xffff /* All optimizations */
1074210908
1074310909
/*
1074410910
** Macros for testing whether or not optimizations are enabled or disabled.
1074510911
*/
@@ -11317,16 +11483,18 @@
1131711483
unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
1131811484
unsigned bUnordered:1; /* Use this index for == or IN queries only */
1131911485
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
1132011486
unsigned isResized:1; /* True if resizeIndexObject() has been called */
1132111487
unsigned isCovering:1; /* True if this is a covering index */
11488
+ unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
1132211489
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
1132311490
int nSample; /* Number of elements in aSample[] */
1132411491
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
1132511492
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
1132611493
IndexSample *aSample; /* Samples of the left-most key */
11327
- tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
11494
+ tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
11495
+ tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
1132811496
#endif
1132911497
};
1133011498
1133111499
/*
1133211500
** Allowed values for Index.idxType
@@ -11520,11 +11688,11 @@
1152011688
int nHeight; /* Height of the tree headed by this node */
1152111689
#endif
1152211690
int iTable; /* TK_COLUMN: cursor number of table holding column
1152311691
** TK_REGISTER: register number
1152411692
** TK_TRIGGER: 1 -> new, 0 -> old
11525
- ** EP_Unlikely: 1000 times likelihood */
11693
+ ** EP_Unlikely: 134217728 times likelihood */
1152611694
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
1152711695
** TK_VARIABLE: variable number (always >= 1). */
1152811696
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
1152911697
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
1153011698
u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -11535,11 +11703,11 @@
1153511703
};
1153611704
1153711705
/*
1153811706
** The following are the meanings of bits in the Expr.flags field.
1153911707
*/
11540
-#define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
11708
+#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
1154111709
#define EP_Agg 0x000002 /* Contains one or more aggregate functions */
1154211710
#define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
1154311711
#define EP_Error 0x000008 /* Expression contains one or more errors */
1154411712
#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
1154511713
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
@@ -11555,10 +11723,11 @@
1155511723
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1155611724
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1155711725
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1155811726
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1155911727
#define EP_Constant 0x080000 /* Node is a constant */
11728
+#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
1156011729
1156111730
/*
1156211731
** These macros can be used to test, set, or clear bits in the
1156311732
** Expr.flags field.
1156411733
*/
@@ -12412,13 +12581,15 @@
1241212581
int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
1241312582
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1241412583
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1241512584
Parse *pParse; /* Parser context. */
1241612585
int walkerDepth; /* Number of subqueries */
12586
+ u8 eCode; /* A small processing code */
1241712587
union { /* Extra data for callback */
1241812588
NameContext *pNC; /* Naming context */
12419
- int i; /* Integer value */
12589
+ int n; /* A counter */
12590
+ int iCur; /* A cursor number */
1242012591
SrcList *pSrcList; /* FROM clause */
1242112592
struct SrcCount *pSrcCount; /* Counting column references */
1242212593
} u;
1242312594
};
1242412595
@@ -12815,10 +12986,11 @@
1281512986
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1281612987
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
1281712988
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1281812989
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1281912990
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
12991
+SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
1282012992
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1282112993
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
1282212994
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1282312995
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
1282412996
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13060,11 +13232,11 @@
1306013232
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1306113233
1306213234
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
1306313235
SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
1306413236
SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13065
-SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
13237
+SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
1306613238
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
1306713239
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
1306813240
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
1306913241
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
1307013242
@@ -13472,15 +13644,23 @@
1347213644
** compatibility for legacy applications, the URI filename capability is
1347313645
** disabled by default.
1347413646
**
1347513647
** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
1347613648
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13649
+**
13650
+** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
13651
+** disabled. The default value may be changed by compiling with the
13652
+** SQLITE_USE_URI symbol defined.
1347713653
*/
1347813654
#ifndef SQLITE_USE_URI
1347913655
# define SQLITE_USE_URI 0
1348013656
#endif
1348113657
13658
+/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
13659
+** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
13660
+** that compile-time option is omitted.
13661
+*/
1348213662
#ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
1348313663
# define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
1348413664
#endif
1348513665
1348613666
/*
@@ -13566,12 +13746,12 @@
1356613746
** than 1 GiB. The sqlite3_test_control() interface can be used to
1356713747
** move the pending byte.
1356813748
**
1356913749
** IMPORTANT: Changing the pending byte to any value other than
1357013750
** 0x40000000 results in an incompatible database file format!
13571
-** Changing the pending byte during operating results in undefined
13572
-** and dileterious behavior.
13751
+** Changing the pending byte during operation will result in undefined
13752
+** and incorrect behavior.
1357313753
*/
1357413754
#ifndef SQLITE_OMIT_WSD
1357513755
SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
1357613756
#endif
1357713757
@@ -13646,10 +13826,13 @@
1364613826
#ifdef SQLITE_DISABLE_DIRSYNC
1364713827
"DISABLE_DIRSYNC",
1364813828
#endif
1364913829
#ifdef SQLITE_DISABLE_LFS
1365013830
"DISABLE_LFS",
13831
+#endif
13832
+#ifdef SQLITE_ENABLE_API_ARMOR
13833
+ "ENABLE_API_ARMOR",
1365113834
#endif
1365213835
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
1365313836
"ENABLE_ATOMIC_WRITE",
1365413837
#endif
1365513838
#ifdef SQLITE_ENABLE_CEROD
@@ -13972,10 +14155,17 @@
1397214155
** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
1397314156
** is not required for a match.
1397414157
*/
1397514158
SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
1397614159
int i, n;
14160
+
14161
+#ifdef SQLITE_ENABLE_API_ARMOR
14162
+ if( zOptName==0 ){
14163
+ (void)SQLITE_MISUSE_BKPT;
14164
+ return 0;
14165
+ }
14166
+#endif
1397714167
if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
1397814168
n = sqlite3Strlen30(zOptName);
1397914169
1398014170
/* Since ArraySize(azCompileOpt) is normally in single digits, a
1398114171
** linear search is adequate. No need for a binary search. */
@@ -14153,10 +14343,11 @@
1415314343
typedef struct VdbeFrame VdbeFrame;
1415414344
struct VdbeFrame {
1415514345
Vdbe *v; /* VM this frame belongs to */
1415614346
VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
1415714347
Op *aOp; /* Program instructions for parent frame */
14348
+ i64 *anExec; /* Event counters from parent frame */
1415814349
Mem *aMem; /* Array of memory cells for parent frame */
1415914350
u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
1416014351
VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
1416114352
void *token; /* Copy of SubProgram.token */
1416214353
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14165,11 +14356,12 @@
1416514356
int nOp; /* Size of aOp array */
1416614357
int nMem; /* Number of entries in aMem */
1416714358
int nOnceFlag; /* Number of entries in aOnceFlag */
1416814359
int nChildMem; /* Number of memory cells for child frame */
1416914360
int nChildCsr; /* Number of cursors for child frame */
14170
- int nChange; /* Statement changes (Vdbe.nChanges) */
14361
+ int nChange; /* Statement changes (Vdbe.nChange) */
14362
+ int nDbChange; /* Value of db->nChange */
1417114363
};
1417214364
1417314365
#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
1417414366
1417514367
/*
@@ -14316,10 +14508,20 @@
1431614508
/* A bitfield type for use inside of structures. Always follow with :N where
1431714509
** N is the number of bits.
1431814510
*/
1431914511
typedef unsigned bft; /* Bit Field Type */
1432014512
14513
+typedef struct ScanStatus ScanStatus;
14514
+struct ScanStatus {
14515
+ int addrExplain; /* OP_Explain for loop */
14516
+ int addrLoop; /* Address of "loops" counter */
14517
+ int addrVisit; /* Address of "rows visited" counter */
14518
+ int iSelectID; /* The "Select-ID" for this loop */
14519
+ LogEst nEst; /* Estimated output rows per loop */
14520
+ char *zName; /* Name of table or index */
14521
+};
14522
+
1432114523
/*
1432214524
** An instance of the virtual machine. This structure contains the complete
1432314525
** state of the virtual machine.
1432414526
**
1432514527
** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14388,10 +14590,15 @@
1438814590
u32 expmask; /* Binding to these vars invalidates VM */
1438914591
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
1439014592
int nOnceFlag; /* Size of array aOnceFlag[] */
1439114593
u8 *aOnceFlag; /* Flags for OP_Once */
1439214594
AuxData *pAuxData; /* Linked list of auxdata allocations */
14595
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
14596
+ i64 *anExec; /* Number of times each op has been executed */
14597
+ int nScan; /* Entries in aScan[] */
14598
+ ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
14599
+#endif
1439314600
};
1439414601
1439514602
/*
1439614603
** The following are allowed values for Vdbe.magic
1439714604
*/
@@ -14577,10 +14784,13 @@
1457714784
SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
1457814785
wsdStatInit;
1457914786
if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
1458014787
return SQLITE_MISUSE_BKPT;
1458114788
}
14789
+#ifdef SQLITE_ENABLE_API_ARMOR
14790
+ if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
14791
+#endif
1458214792
*pCurrent = wsdStat.nowValue[op];
1458314793
*pHighwater = wsdStat.mxValue[op];
1458414794
if( resetFlag ){
1458514795
wsdStat.mxValue[op] = wsdStat.nowValue[op];
1458614796
}
@@ -14596,10 +14806,15 @@
1459614806
int *pCurrent, /* Write current value here */
1459714807
int *pHighwater, /* Write high-water mark here */
1459814808
int resetFlag /* Reset high-water mark if true */
1459914809
){
1460014810
int rc = SQLITE_OK; /* Return code */
14811
+#ifdef SQLITE_ENABLE_API_ARMOR
14812
+ if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
14813
+ return SQLITE_MISUSE_BKPT;
14814
+ }
14815
+#endif
1460114816
sqlite3_mutex_enter(db->mutex);
1460214817
switch( op ){
1460314818
case SQLITE_DBSTATUS_LOOKASIDE_USED: {
1460414819
*pCurrent = db->lookaside.nOut;
1460514820
*pHighwater = db->lookaside.mxOut;
@@ -14774,11 +14989,11 @@
1477414989
**
1477514990
** There is only one exported symbol in this file - the function
1477614991
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
1477714992
** All other code has file scope.
1477814993
**
14779
-** SQLite processes all times and dates as Julian Day numbers. The
14994
+** SQLite processes all times and dates as julian day numbers. The
1478014995
** dates and times are stored as the number of days since noon
1478114996
** in Greenwich on November 24, 4714 B.C. according to the Gregorian
1478214997
** calendar system.
1478314998
**
1478414999
** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14789,11 +15004,11 @@
1478915004
** be represented, even though julian day numbers allow a much wider
1479015005
** range of dates.
1479115006
**
1479215007
** The Gregorian calendar system is used for all dates and times,
1479315008
** even those that predate the Gregorian calendar. Historians usually
14794
-** use the Julian calendar for dates prior to 1582-10-15 and for some
15009
+** use the julian calendar for dates prior to 1582-10-15 and for some
1479515010
** dates afterwards, depending on locale. Beware of this difference.
1479615011
**
1479715012
** The conversion algorithms are implemented based on descriptions
1479815013
** in the following text:
1479915014
**
@@ -15061,11 +15276,11 @@
1506115276
return 1;
1506215277
}
1506315278
}
1506415279
1506515280
/*
15066
-** Attempt to parse the given string into a Julian Day Number. Return
15281
+** Attempt to parse the given string into a julian day number. Return
1506715282
** the number of errors.
1506815283
**
1506915284
** The following are acceptable forms for the input string:
1507015285
**
1507115286
** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15632,11 +15847,11 @@
1563215847
**
1563315848
** %d day of month
1563415849
** %f ** fractional seconds SS.SSS
1563515850
** %H hour 00-24
1563615851
** %j day of year 000-366
15637
-** %J ** Julian day number
15852
+** %J ** julian day number
1563815853
** %m month 01-12
1563915854
** %M minute 00-59
1564015855
** %s seconds since 1970-01-01
1564115856
** %S seconds 00-59
1564215857
** %w day of week 0-6 sunday==0
@@ -16257,10 +16472,14 @@
1625716472
MUTEX_LOGIC(sqlite3_mutex *mutex;)
1625816473
#ifndef SQLITE_OMIT_AUTOINIT
1625916474
int rc = sqlite3_initialize();
1626016475
if( rc ) return rc;
1626116476
#endif
16477
+#ifdef SQLITE_ENABLE_API_ARMOR
16478
+ if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
16479
+#endif
16480
+
1626216481
MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
1626316482
sqlite3_mutex_enter(mutex);
1626416483
vfsUnlink(pVfs);
1626516484
if( makeDflt || vfsList==0 ){
1626616485
pVfs->pNext = vfsList;
@@ -18614,10 +18833,11 @@
1861418833
** Retrieve a pointer to a static mutex or allocate a new dynamic one.
1861518834
*/
1861618835
SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
1861718836
#ifndef SQLITE_OMIT_AUTOINIT
1861818837
if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
18838
+ if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
1861918839
#endif
1862018840
return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
1862118841
}
1862218842
1862318843
SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19070,12 +19290,16 @@
1907019290
pthread_mutex_init(&p->mutex, 0);
1907119291
}
1907219292
break;
1907319293
}
1907419294
default: {
19075
- assert( iType-2 >= 0 );
19076
- assert( iType-2 < ArraySize(staticMutexes) );
19295
+#ifdef SQLITE_ENABLE_API_ARMOR
19296
+ if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){
19297
+ (void)SQLITE_MISUSE_BKPT;
19298
+ return 0;
19299
+ }
19300
+#endif
1907719301
p = &staticMutexes[iType-2];
1907819302
#if SQLITE_MUTEX_NREF
1907919303
p->id = iType;
1908019304
#endif
1908119305
break;
@@ -20293,15 +20517,16 @@
2029320517
}
2029420518
assert( sqlite3_mutex_notheld(mem0.mutex) );
2029520519
2029620520
2029720521
#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20298
- /* Verify that no more than two scratch allocations per thread
20299
- ** are outstanding at one time. (This is only checked in the
20300
- ** single-threaded case since checking in the multi-threaded case
20301
- ** would be much more complicated.) */
20302
- assert( scratchAllocOut<=1 );
20522
+ /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
20523
+ ** buffers per thread.
20524
+ **
20525
+ ** This can only be checked in single-threaded mode.
20526
+ */
20527
+ assert( scratchAllocOut==0 );
2030320528
if( p ) scratchAllocOut++;
2030420529
#endif
2030520530
2030620531
return p;
2030720532
}
@@ -20945,11 +21170,11 @@
2094521170
sqlite_uint64 longvalue; /* Value for integer types */
2094621171
LONGDOUBLE_TYPE realvalue; /* Value for real types */
2094721172
const et_info *infop; /* Pointer to the appropriate info structure */
2094821173
char *zOut; /* Rendering buffer */
2094921174
int nOut; /* Size of the rendering buffer */
20950
- char *zExtra; /* Malloced memory used by some conversion */
21175
+ char *zExtra = 0; /* Malloced memory used by some conversion */
2095121176
#ifndef SQLITE_OMIT_FLOATING_POINT
2095221177
int exp, e2; /* exponent of real numbers */
2095321178
int nsd; /* Number of significant digits returned */
2095421179
double rounder; /* Used for rounding floating point values */
2095521180
etByte flag_dp; /* True if decimal point should be shown */
@@ -20956,10 +21181,17 @@
2095621181
etByte flag_rtz; /* True if trailing zeros should be removed */
2095721182
#endif
2095821183
PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
2095921184
char buf[etBUFSIZE]; /* Conversion buffer */
2096021185
21186
+#ifdef SQLITE_ENABLE_API_ARMOR
21187
+ if( ap==0 ){
21188
+ (void)SQLITE_MISUSE_BKPT;
21189
+ sqlite3StrAccumReset(pAccum);
21190
+ return;
21191
+ }
21192
+#endif
2096121193
bufpt = 0;
2096221194
if( bFlags ){
2096321195
if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
2096421196
pArgList = va_arg(ap, PrintfArguments*);
2096521197
}
@@ -21062,11 +21294,10 @@
2106221294
return;
2106321295
}
2106421296
break;
2106521297
}
2106621298
}
21067
- zExtra = 0;
2106821299
2106921300
/*
2107021301
** At this point, variables are initialized as follows:
2107121302
**
2107221303
** flag_alternateform TRUE if a '#' is present.
@@ -21353,17 +21584,20 @@
2135321584
bufpt = getTextArg(pArgList);
2135421585
c = bufpt ? bufpt[0] : 0;
2135521586
}else{
2135621587
c = va_arg(ap,int);
2135721588
}
21358
- buf[0] = (char)c;
21359
- if( precision>=0 ){
21360
- for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
21361
- length = precision;
21362
- }else{
21363
- length =1;
21589
+ if( precision>1 ){
21590
+ width -= precision-1;
21591
+ if( width>1 && !flag_leftjustify ){
21592
+ sqlite3AppendChar(pAccum, width-1, ' ');
21593
+ width = 0;
21594
+ }
21595
+ sqlite3AppendChar(pAccum, precision-1, c);
2136421596
}
21597
+ length = 1;
21598
+ buf[0] = c;
2136521599
bufpt = buf;
2136621600
break;
2136721601
case etSTRING:
2136821602
case etDYNSTRING:
2136921603
if( bArgList ){
@@ -21460,15 +21694,18 @@
2146021694
** The text of the conversion is pointed to by "bufpt" and is
2146121695
** "length" characters long. The field width is "width". Do
2146221696
** the output.
2146321697
*/
2146421698
width -= length;
21465
- if( width>0 && !flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
21699
+ if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
2146621700
sqlite3StrAccumAppend(pAccum, bufpt, length);
21467
- if( width>0 && flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
21701
+ if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
2146821702
21469
- if( zExtra ) sqlite3_free(zExtra);
21703
+ if( zExtra ){
21704
+ sqlite3_free(zExtra);
21705
+ zExtra = 0;
21706
+ }
2147021707
}/* End for loop over the format string */
2147121708
} /* End of function */
2147221709
2147321710
/*
2147421711
** Enlarge the memory allocation on a StrAccum object so that it is
@@ -21491,10 +21728,15 @@
2149121728
return N;
2149221729
}else{
2149321730
char *zOld = (p->zText==p->zBase ? 0 : p->zText);
2149421731
i64 szNew = p->nChar;
2149521732
szNew += N + 1;
21733
+ if( szNew+p->nChar<=p->mxAlloc ){
21734
+ /* Force exponential buffer size growth as long as it does not overflow,
21735
+ ** to avoid having to call this routine too often */
21736
+ szNew += p->nChar;
21737
+ }
2149621738
if( szNew > p->mxAlloc ){
2149721739
sqlite3StrAccumReset(p);
2149821740
setStrAccumError(p, STRACCUM_TOOBIG);
2149921741
return 0;
2150021742
}else{
@@ -21507,10 +21749,11 @@
2150721749
}
2150821750
if( zNew ){
2150921751
assert( p->zText!=0 || p->nChar==0 );
2151021752
if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2151121753
p->zText = zNew;
21754
+ p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
2151221755
}else{
2151321756
sqlite3StrAccumReset(p);
2151421757
setStrAccumError(p, STRACCUM_NOMEM);
2151521758
return 0;
2151621759
}
@@ -21517,15 +21760,15 @@
2151721760
}
2151821761
return N;
2151921762
}
2152021763
2152121764
/*
21522
-** Append N space characters to the given string buffer.
21765
+** Append N copies of character c to the given string buffer.
2152321766
*/
21524
-SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum *p, int N){
21767
+SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
2152521768
if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return;
21526
- while( (N--)>0 ) p->zText[p->nChar++] = ' ';
21769
+ while( (N--)>0 ) p->zText[p->nChar++] = c;
2152721770
}
2152821771
2152921772
/*
2153021773
** The StrAccum "p" is not large enough to accept N new bytes of z[].
2153121774
** So enlarge if first, then do the append.
@@ -21676,10 +21919,17 @@
2167621919
*/
2167721920
SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
2167821921
char *z;
2167921922
char zBase[SQLITE_PRINT_BUF_SIZE];
2168021923
StrAccum acc;
21924
+
21925
+#ifdef SQLITE_ENABLE_API_ARMOR
21926
+ if( zFormat==0 ){
21927
+ (void)SQLITE_MISUSE_BKPT;
21928
+ return 0;
21929
+ }
21930
+#endif
2168121931
#ifndef SQLITE_OMIT_AUTOINIT
2168221932
if( sqlite3_initialize() ) return 0;
2168321933
#endif
2168421934
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
2168521935
acc.useMalloc = 2;
@@ -21718,10 +21968,17 @@
2171821968
** sqlite3_vsnprintf() is the varargs version.
2171921969
*/
2172021970
SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
2172121971
StrAccum acc;
2172221972
if( n<=0 ) return zBuf;
21973
+#ifdef SQLITE_ENABLE_API_ARMOR
21974
+ if( zBuf==0 || zFormat==0 ) {
21975
+ (void)SQLITE_MISUSE_BKPT;
21976
+ if( zBuf && n>0 ) zBuf[0] = 0;
21977
+ return zBuf;
21978
+ }
21979
+#endif
2172321980
sqlite3StrAccumInit(&acc, zBuf, n, 0);
2172421981
acc.useMalloc = 0;
2172521982
sqlite3VXPrintf(&acc, 0, zFormat, ap);
2172621983
return sqlite3StrAccumFinish(&acc);
2172721984
}
@@ -21909,15 +22166,23 @@
2190922166
#else
2191022167
# define wsdPrng sqlite3Prng
2191122168
#endif
2191222169
2191322170
#if SQLITE_THREADSAFE
21914
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
22171
+ sqlite3_mutex *mutex;
22172
+#endif
22173
+
22174
+#ifndef SQLITE_OMIT_AUTOINIT
22175
+ if( sqlite3_initialize() ) return;
22176
+#endif
22177
+
22178
+#if SQLITE_THREADSAFE
22179
+ mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
22180
+#endif
22181
+
2191522182
sqlite3_mutex_enter(mutex);
21916
-#endif
21917
-
21918
- if( N<=0 ){
22183
+ if( N<=0 || pBuf==0 ){
2191922184
wsdPrng.isInit = 0;
2192022185
sqlite3_mutex_leave(mutex);
2192122186
return;
2192222187
}
2192322188
@@ -23035,17 +23300,27 @@
2303523300
** case-independent fashion, using the same definition of "case
2303623301
** independence" that SQLite uses internally when comparing identifiers.
2303723302
*/
2303823303
SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
2303923304
register unsigned char *a, *b;
23305
+ if( zLeft==0 ){
23306
+ return zRight ? -1 : 0;
23307
+ }else if( zRight==0 ){
23308
+ return 1;
23309
+ }
2304023310
a = (unsigned char *)zLeft;
2304123311
b = (unsigned char *)zRight;
2304223312
while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
2304323313
return UpperToLower[*a] - UpperToLower[*b];
2304423314
}
2304523315
SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
2304623316
register unsigned char *a, *b;
23317
+ if( zLeft==0 ){
23318
+ return zRight ? -1 : 0;
23319
+ }else if( zRight==0 ){
23320
+ return 1;
23321
+ }
2304723322
a = (unsigned char *)zLeft;
2304823323
b = (unsigned char *)zRight;
2304923324
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
2305023325
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
2305123326
}
@@ -32574,10 +32849,15 @@
3257432849
#if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
3257532850
# error "WAL mode requires support from the Windows NT kernel, compile\
3257632851
with SQLITE_OMIT_WAL."
3257732852
#endif
3257832853
32854
+#if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
32855
+# error "Memory mapped files require support from the Windows NT kernel,\
32856
+ compile with SQLITE_MAX_MMAP_SIZE=0."
32857
+#endif
32858
+
3257932859
/*
3258032860
** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
3258132861
** based on the sub-platform)?
3258232862
*/
3258332863
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32703,14 +32983,15 @@
3270332983
# define winGetDirSep() '\\'
3270432984
#endif
3270532985
3270632986
/*
3270732987
** Do we need to manually define the Win32 file mapping APIs for use with WAL
32708
-** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32709
-** are not present in the header file)?
32988
+** mode or memory mapped files (e.g. these APIs are available in the Windows
32989
+** CE SDK; however, they are not present in the header file)?
3271032990
*/
32711
-#if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL)
32991
+#if SQLITE_WIN32_FILEMAPPING_API && \
32992
+ (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
3271232993
/*
3271332994
** Two of the file mapping APIs are different under WinRT. Figure out which
3271432995
** set we need.
3271532996
*/
3271632997
#if SQLITE_OS_WINRT
@@ -32734,11 +33015,11 @@
3273433015
3273533016
/*
3273633017
** This file mapping API is common to both Win32 and WinRT.
3273733018
*/
3273833019
WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
32739
-#endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */
33020
+#endif /* SQLITE_WIN32_FILEMAPPING_API */
3274033021
3274133022
/*
3274233023
** Some Microsoft compilers lack this definition.
3274333024
*/
3274433025
#ifndef INVALID_FILE_ATTRIBUTES
@@ -33027,21 +33308,21 @@
3302733308
3302833309
#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
3302933310
LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
3303033311
3303133312
#if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33032
- !defined(SQLITE_OMIT_WAL))
33313
+ (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
3303333314
{ "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
3303433315
#else
3303533316
{ "CreateFileMappingA", (SYSCALL)0, 0 },
3303633317
#endif
3303733318
3303833319
#define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
3303933320
DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
3304033321
3304133322
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33042
- !defined(SQLITE_OMIT_WAL))
33323
+ (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
3304333324
{ "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
3304433325
#else
3304533326
{ "CreateFileMappingW", (SYSCALL)0, 0 },
3304633327
#endif
3304733328
@@ -33377,11 +33658,12 @@
3337733658
#ifndef osLockFileEx
3337833659
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
3337933660
LPOVERLAPPED))aSyscall[48].pCurrent)
3338033661
#endif
3338133662
33382
-#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
33663
+#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \
33664
+ (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
3338333665
{ "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
3338433666
#else
3338533667
{ "MapViewOfFile", (SYSCALL)0, 0 },
3338633668
#endif
3338733669
@@ -33447,11 +33729,11 @@
3344733729
#endif
3344833730
3344933731
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
3345033732
LPOVERLAPPED))aSyscall[58].pCurrent)
3345133733
33452
-#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
33734
+#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
3345333735
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
3345433736
#else
3345533737
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
3345633738
#endif
3345733739
@@ -33510,11 +33792,11 @@
3351033792
#endif
3351133793
3351233794
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
3351333795
FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
3351433796
33515
-#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33797
+#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
3351633798
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
3351733799
#else
3351833800
{ "MapViewOfFileFromApp", (SYSCALL)0, 0 },
3351933801
#endif
3352033802
@@ -33574,11 +33856,11 @@
3357433856
3357533857
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
3357633858
3357733859
#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
3357833860
33579
-#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33861
+#if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
3358033862
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
3358133863
#else
3358233864
{ "CreateFileMappingFromApp", (SYSCALL)0, 0 },
3358333865
#endif
3358433866
@@ -39150,10 +39432,17 @@
3915039432
*/
3915139433
SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
3915239434
assert( pCache->pCache!=0 );
3915339435
sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
3915439436
}
39437
+
39438
+/*
39439
+** Return the size of the header added by this middleware layer
39440
+** in the page-cache hierarchy.
39441
+*/
39442
+SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39443
+
3915539444
3915639445
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
3915739446
/*
3915839447
** For all dirty pages currently in the cache, invoke the specified
3915939448
** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40149,10 +40438,15 @@
4014940438
pcache1Shrink /* xShrink */
4015040439
};
4015140440
sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
4015240441
}
4015340442
40443
+/*
40444
+** Return the size of the header on each page of this PCACHE implementation.
40445
+*/
40446
+SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40447
+
4015440448
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
4015540449
/*
4015640450
** This function is called to free superfluous dynamically allocated memory
4015740451
** held by the pager system. Memory in use by any SQLite pager allocated
4015840452
** by the current thread may be sqlite3_free()ed.
@@ -43758,11 +44052,11 @@
4375844052
** should be page numbers which are never 0xffffffff. So filling
4375944053
** pPager->dbFileVers[] with all 0xff bytes should suffice.
4376044054
**
4376144055
** For an encrypted database, the situation is more complex: bytes
4376244056
** 24..39 of the database are white noise. But the probability of
43763
- ** white noising equaling 16 bytes of 0xff is vanishingly small so
44057
+ ** white noise equaling 16 bytes of 0xff is vanishingly small so
4376444058
** we should still be ok.
4376544059
*/
4376644060
memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
4376744061
}else{
4376844062
u8 *dbFileVers = &((u8*)pPg->pData)[24];
@@ -47705,10 +47999,22 @@
4770547999
}
4770648000
4770748001
return SQLITE_OK;
4770848002
}
4770948003
#endif
48004
+
48005
+/*
48006
+** The page handle passed as the first argument refers to a dirty page
48007
+** with a page number other than iNew. This function changes the page's
48008
+** page number to iNew and sets the value of the PgHdr.flags field to
48009
+** the value passed as the third parameter.
48010
+*/
48011
+SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
48012
+ assert( pPg->pgno!=iNew );
48013
+ pPg->flags = flags;
48014
+ sqlite3PcacheMove(pPg, iNew);
48015
+}
4771048016
4771148017
/*
4771248018
** Return a pointer to the data for the specified page.
4771348019
*/
4771448020
SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
@@ -47922,11 +48228,12 @@
4792248228
*/
4792348229
SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){
4792448230
int rc = SQLITE_OK;
4792548231
if( pPager->pWal ){
4792648232
rc = sqlite3WalCheckpoint(pPager->pWal, eMode,
47927
- pPager->xBusyHandler, pPager->pBusyHandlerArg,
48233
+ (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
48234
+ pPager->pBusyHandlerArg,
4792848235
pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
4792948236
pnLog, pnCkpt
4793048237
);
4793148238
}
4793248239
return rc;
@@ -48103,10 +48410,11 @@
4810348410
SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
4810448411
assert( pPager->eState>=PAGER_READER );
4810548412
return sqlite3WalFramesize(pPager->pWal);
4810648413
}
4810748414
#endif
48415
+
4810848416
4810948417
#endif /* SQLITE_OMIT_DISKIO */
4811048418
4811148419
/************** End of pager.c ***********************************************/
4811248420
/************** Begin file wal.c *********************************************/
@@ -49613,11 +49921,11 @@
4961349921
4961449922
/*
4961549923
** Free an iterator allocated by walIteratorInit().
4961649924
*/
4961749925
static void walIteratorFree(WalIterator *p){
49618
- sqlite3ScratchFree(p);
49926
+ sqlite3_free(p);
4961949927
}
4962049928
4962149929
/*
4962249930
** Construct a WalInterator object that can be used to loop over all
4962349931
** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49648,21 +49956,21 @@
4964849956
/* Allocate space for the WalIterator object. */
4964949957
nSegment = walFramePage(iLast) + 1;
4965049958
nByte = sizeof(WalIterator)
4965149959
+ (nSegment-1)*sizeof(struct WalSegment)
4965249960
+ iLast*sizeof(ht_slot);
49653
- p = (WalIterator *)sqlite3ScratchMalloc(nByte);
49961
+ p = (WalIterator *)sqlite3_malloc(nByte);
4965449962
if( !p ){
4965549963
return SQLITE_NOMEM;
4965649964
}
4965749965
memset(p, 0, nByte);
4965849966
p->nSegment = nSegment;
4965949967
4966049968
/* Allocate temporary space used by the merge-sort routine. This block
4966149969
** of memory will be freed before this function returns.
4966249970
*/
49663
- aTmp = (ht_slot *)sqlite3ScratchMalloc(
49971
+ aTmp = (ht_slot *)sqlite3_malloc(
4966449972
sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
4966549973
);
4966649974
if( !aTmp ){
4966749975
rc = SQLITE_NOMEM;
4966849976
}
@@ -49695,11 +50003,11 @@
4969550003
p->aSegment[i].nEntry = nEntry;
4969650004
p->aSegment[i].aIndex = aIndex;
4969750005
p->aSegment[i].aPgno = (u32 *)aPgno;
4969850006
}
4969950007
}
49700
- sqlite3ScratchFree(aTmp);
50008
+ sqlite3_free(aTmp);
4970150009
4970250010
if( rc!=SQLITE_OK ){
4970350011
walIteratorFree(p);
4970450012
}
4970550013
*pp = p;
@@ -49731,10 +50039,42 @@
4973150039
** Return the page-size in bytes used by the database.
4973250040
*/
4973350041
static int walPagesize(Wal *pWal){
4973450042
return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
4973550043
}
50044
+
50045
+/*
50046
+** The following is guaranteed when this function is called:
50047
+**
50048
+** a) the WRITER lock is held,
50049
+** b) the entire log file has been checkpointed, and
50050
+** c) any existing readers are reading exclusively from the database
50051
+** file - there are no readers that may attempt to read a frame from
50052
+** the log file.
50053
+**
50054
+** This function updates the shared-memory structures so that the next
50055
+** client to write to the database (which may be this one) does so by
50056
+** writing frames into the start of the log file.
50057
+**
50058
+** The value of parameter salt1 is used as the aSalt[1] value in the
50059
+** new wal-index header. It should be passed a pseudo-random value (i.e.
50060
+** one obtained from sqlite3_randomness()).
50061
+*/
50062
+static void walRestartHdr(Wal *pWal, u32 salt1){
50063
+ volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
50064
+ int i; /* Loop counter */
50065
+ u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
50066
+ pWal->nCkpt++;
50067
+ pWal->hdr.mxFrame = 0;
50068
+ sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
50069
+ memcpy(&pWal->hdr.aSalt[1], &salt1, 4);
50070
+ walIndexWriteHdr(pWal);
50071
+ pInfo->nBackfill = 0;
50072
+ pInfo->aReadMark[1] = 0;
50073
+ for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
50074
+ assert( pInfo->aReadMark[0]==0 );
50075
+}
4973650076
4973750077
/*
4973850078
** Copy as much content as we can from the WAL back into the database file
4973950079
** in response to an sqlite3_wal_checkpoint() request or the equivalent.
4974050080
**
@@ -49766,11 +50106,11 @@
4976650106
** time.
4976750107
*/
4976850108
static int walCheckpoint(
4976950109
Wal *pWal, /* Wal connection */
4977050110
int eMode, /* One of PASSIVE, FULL or RESTART */
49771
- int (*xBusyCall)(void*), /* Function to call when busy */
50111
+ int (*xBusy)(void*), /* Function to call when busy */
4977250112
void *pBusyArg, /* Context argument for xBusyHandler */
4977350113
int sync_flags, /* Flags for OsSync() (or 0) */
4977450114
u8 *zBuf /* Temporary buffer to use */
4977550115
){
4977650116
int rc; /* Return code */
@@ -49780,11 +50120,10 @@
4978050120
u32 iFrame = 0; /* Wal frame containing data for iDbpage */
4978150121
u32 mxSafeFrame; /* Max frame that can be backfilled */
4978250122
u32 mxPage; /* Max database page to write */
4978350123
int i; /* Loop counter */
4978450124
volatile WalCkptInfo *pInfo; /* The checkpoint status information */
49785
- int (*xBusy)(void*) = 0; /* Function to call when waiting for locks */
4978650125
4978750126
szPage = walPagesize(pWal);
4978850127
testcase( szPage<=32768 );
4978950128
testcase( szPage>=65536 );
4979050129
pInfo = walCkptInfo(pWal);
@@ -49795,11 +50134,13 @@
4979550134
if( rc!=SQLITE_OK ){
4979650135
return rc;
4979750136
}
4979850137
assert( pIter );
4979950138
49800
- if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall;
50139
+ /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
50140
+ ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
50141
+ assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
4980150142
4980250143
/* Compute in mxSafeFrame the index of the last frame of the WAL that is
4980350144
** safe to write into the database. Frames beyond mxSafeFrame might
4980450145
** overwrite database pages that are in use by active readers and thus
4980550146
** cannot be backfilled from the WAL.
@@ -49884,23 +50225,42 @@
4988450225
/* Reset the return code so as not to report a checkpoint failure
4988550226
** just because there are active readers. */
4988650227
rc = SQLITE_OK;
4988750228
}
4988850229
49889
- /* If this is an SQLITE_CHECKPOINT_RESTART operation, and the entire wal
49890
- ** file has been copied into the database file, then block until all
49891
- ** readers have finished using the wal file. This ensures that the next
49892
- ** process to write to the database restarts the wal file.
50230
+ /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
50231
+ ** entire wal file has been copied into the database file, then block
50232
+ ** until all readers have finished using the wal file. This ensures that
50233
+ ** the next process to write to the database restarts the wal file.
4989350234
*/
4989450235
if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){
4989550236
assert( pWal->writeLock );
4989650237
if( pInfo->nBackfill<pWal->hdr.mxFrame ){
4989750238
rc = SQLITE_BUSY;
49898
- }else if( eMode==SQLITE_CHECKPOINT_RESTART ){
50239
+ }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){
50240
+ u32 salt1;
50241
+ sqlite3_randomness(4, &salt1);
4989950242
assert( mxSafeFrame==pWal->hdr.mxFrame );
4990050243
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
4990150244
if( rc==SQLITE_OK ){
50245
+ if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){
50246
+ /* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as
50247
+ ** SQLITE_CHECKPOINT_RESTART with the addition that it also
50248
+ ** truncates the log file to zero bytes just prior to a
50249
+ ** successful return.
50250
+ **
50251
+ ** In theory, it might be safe to do this without updating the
50252
+ ** wal-index header in shared memory, as all subsequent reader or
50253
+ ** writer clients should see that the entire log file has been
50254
+ ** checkpointed and behave accordingly. This seems unsafe though,
50255
+ ** as it would leave the system in a state where the contents of
50256
+ ** the wal-index header do not match the contents of the
50257
+ ** file-system. To avoid this, update the wal-index header to
50258
+ ** indicate that the log file contains zero valid frames. */
50259
+ walRestartHdr(pWal, salt1);
50260
+ rc = sqlite3OsTruncate(pWal->pWalFd, 0);
50261
+ }
4990250262
walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
4990350263
}
4990450264
}
4990550265
}
4990650266
@@ -50634,11 +50994,10 @@
5063450994
assert( walFramePgno(pWal, iFrame)!=1 );
5063550995
rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
5063650996
}
5063750997
if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
5063850998
}
50639
- assert( rc==SQLITE_OK );
5064050999
return rc;
5064151000
}
5064251001
5064351002
/*
5064451003
** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
@@ -50683,11 +51042,10 @@
5068351042
}
5068451043
5068551044
return rc;
5068651045
}
5068751046
50688
-
5068951047
/*
5069051048
** This function is called just before writing a set of frames to the log
5069151049
** file (see sqlite3WalFrames()). It checks to see if, instead of appending
5069251050
** to the current log file, it is possible to overwrite the start of the
5069351051
** existing log file with the new frames (i.e. "reset" the log). If so,
@@ -50716,24 +51074,12 @@
5071651074
** wal-index header to reflect this.
5071751075
**
5071851076
** In theory it would be Ok to update the cache of the header only
5071951077
** at this point. But updating the actual wal-index header is also
5072051078
** safe and means there is no special case for sqlite3WalUndo()
50721
- ** to handle if this transaction is rolled back.
50722
- */
50723
- int i; /* Loop counter */
50724
- u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
50725
-
50726
- pWal->nCkpt++;
50727
- pWal->hdr.mxFrame = 0;
50728
- sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
50729
- aSalt[1] = salt1;
50730
- walIndexWriteHdr(pWal);
50731
- pInfo->nBackfill = 0;
50732
- pInfo->aReadMark[1] = 0;
50733
- for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
50734
- assert( pInfo->aReadMark[0]==0 );
51079
+ ** to handle if this transaction is rolled back. */
51080
+ walRestartHdr(pWal, salt1);
5073551081
walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
5073651082
}else if( rc!=SQLITE_BUSY ){
5073751083
return rc;
5073851084
}
5073951085
}
@@ -51017,11 +51363,11 @@
5101751363
** If parameter xBusy is not NULL, it is a pointer to a busy-handler
5101851364
** callback. In this case this function runs a blocking checkpoint.
5101951365
*/
5102051366
SQLITE_PRIVATE int sqlite3WalCheckpoint(
5102151367
Wal *pWal, /* Wal connection */
51022
- int eMode, /* PASSIVE, FULL or RESTART */
51368
+ int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */
5102351369
int (*xBusy)(void*), /* Function to call when busy */
5102451370
void *pBusyArg, /* Context argument for xBusyHandler */
5102551371
int sync_flags, /* Flags to sync db file with (or 0) */
5102651372
int nBuf, /* Size of temporary buffer */
5102751373
u8 *zBuf, /* Temporary buffer to use */
@@ -51029,40 +51375,54 @@
5102951375
int *pnCkpt /* OUT: Number of backfilled frames in WAL */
5103051376
){
5103151377
int rc; /* Return code */
5103251378
int isChanged = 0; /* True if a new wal-index header is loaded */
5103351379
int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
51380
+ int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */
5103451381
5103551382
assert( pWal->ckptLock==0 );
5103651383
assert( pWal->writeLock==0 );
5103751384
51385
+ /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
51386
+ ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
51387
+ assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
51388
+
5103851389
if( pWal->readOnly ) return SQLITE_READONLY;
5103951390
WALTRACE(("WAL%p: checkpoint begins\n", pWal));
51391
+
51392
+ /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
51393
+ ** "checkpoint" lock on the database file. */
5104051394
rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
5104151395
if( rc ){
51042
- /* Usually this is SQLITE_BUSY meaning that another thread or process
51043
- ** is already running a checkpoint, or maybe a recovery. But it might
51044
- ** also be SQLITE_IOERR. */
51396
+ /* EVIDENCE-OF: R-10421-19736 If any other process is running a
51397
+ ** checkpoint operation at the same time, the lock cannot be obtained and
51398
+ ** SQLITE_BUSY is returned.
51399
+ ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
51400
+ ** it will not be invoked in this case.
51401
+ */
51402
+ testcase( rc==SQLITE_BUSY );
51403
+ testcase( xBusy!=0 );
5104551404
return rc;
5104651405
}
5104751406
pWal->ckptLock = 1;
5104851407
51049
- /* If this is a blocking-checkpoint, then obtain the write-lock as well
51050
- ** to prevent any writers from running while the checkpoint is underway.
51051
- ** This has to be done before the call to walIndexReadHdr() below.
51408
+ /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
51409
+ ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
51410
+ ** file.
5105251411
**
51053
- ** If the writer lock cannot be obtained, then a passive checkpoint is
51054
- ** run instead. Since the checkpointer is not holding the writer lock,
51055
- ** there is no point in blocking waiting for any readers. Assuming no
51056
- ** other error occurs, this function will return SQLITE_BUSY to the caller.
51412
+ ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
51413
+ ** immediately, and a busy-handler is configured, it is invoked and the
51414
+ ** writer lock retried until either the busy-handler returns 0 or the
51415
+ ** lock is successfully obtained.
5105751416
*/
5105851417
if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
5105951418
rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1);
5106051419
if( rc==SQLITE_OK ){
5106151420
pWal->writeLock = 1;
5106251421
}else if( rc==SQLITE_BUSY ){
5106351422
eMode2 = SQLITE_CHECKPOINT_PASSIVE;
51423
+ xBusy2 = 0;
5106451424
rc = SQLITE_OK;
5106551425
}
5106651426
}
5106751427
5106851428
/* Read the wal-index header. */
@@ -51076,11 +51436,11 @@
5107651436
/* Copy data from the log to the database file. */
5107751437
if( rc==SQLITE_OK ){
5107851438
if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
5107951439
rc = SQLITE_CORRUPT_BKPT;
5108051440
}else{
51081
- rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf);
51441
+ rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf);
5108251442
}
5108351443
5108451444
/* If no error occurred, set the output variables. */
5108551445
if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
5108651446
if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
@@ -51713,10 +52073,15 @@
5171352073
** but cursors cannot be shared. Each cursor is associated with a
5171452074
** particular database connection identified BtCursor.pBtree.db.
5171552075
**
5171652076
** Fields in this structure are accessed under the BtShared.mutex
5171752077
** found at self->pBt->mutex.
52078
+**
52079
+** skipNext meaning:
52080
+** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
52081
+** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
52082
+** eState==FAULT: Cursor fault with skipNext as error code.
5171852083
*/
5171952084
struct BtCursor {
5172052085
Btree *pBtree; /* The Btree to which this cursor belongs */
5172152086
BtShared *pBt; /* The BtShared this cursor points to */
5172252087
BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -51725,11 +52090,12 @@
5172552090
CellInfo info; /* A parse of the cell we are pointing at */
5172652091
i64 nKey; /* Size of pKey, or last integer key */
5172752092
void *pKey; /* Saved key that was cursor last known position */
5172852093
Pgno pgnoRoot; /* The root page of this tree */
5172952094
int nOvflAlloc; /* Allocated size of aOverflow[] array */
51730
- int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
52095
+ int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
52096
+ ** Error code if eState==CURSOR_FAULT */
5173152097
u8 curFlags; /* zero or more BTCF_* flags defined below */
5173252098
u8 eState; /* One of the CURSOR_XXX constants (see below) */
5173352099
u8 hints; /* As configured by CursorSetHints() */
5173452100
i16 iPage; /* Index of current page in apPage */
5173552101
u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -51771,11 +52137,11 @@
5177152137
** CURSOR_FAULT:
5177252138
** An unrecoverable error (an I/O error or a malloc failure) has occurred
5177352139
** on a different connection that shares the BtShared cache with this
5177452140
** cursor. The error has left the cache in an inconsistent state.
5177552141
** Do nothing else with this cursor. Any attempt to use the cursor
51776
-** should return the error code stored in BtCursor.skip
52142
+** should return the error code stored in BtCursor.skipNext
5177752143
*/
5177852144
#define CURSOR_INVALID 0
5177952145
#define CURSOR_VALID 1
5178052146
#define CURSOR_SKIPNEXT 2
5178152147
#define CURSOR_REQUIRESEEK 3
@@ -53321,10 +53687,15 @@
5332153687
/*
5332253688
** Defragment the page given. All Cells are moved to the
5332353689
** end of the page and all free space is collected into one
5332453690
** big FreeBlk that occurs in between the header and cell
5332553691
** pointer array and the cell content area.
53692
+**
53693
+** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
53694
+** b-tree page so that there are no freeblocks or fragment bytes, all
53695
+** unused bytes are contained in the unallocated space region, and all
53696
+** cells are packed tightly at the end of the page.
5332653697
*/
5332753698
static int defragmentPage(MemPage *pPage){
5332853699
int i; /* Loop counter */
5332953700
int pc; /* Address of the i-th cell */
5333053701
int hdr; /* Offset to the page header */
@@ -53333,28 +53704,27 @@
5333353704
int cellOffset; /* Offset to the cell pointer array */
5333453705
int cbrk; /* Offset to the cell content area */
5333553706
int nCell; /* Number of cells on the page */
5333653707
unsigned char *data; /* The page data */
5333753708
unsigned char *temp; /* Temp area for cell content */
53709
+ unsigned char *src; /* Source of content */
5333853710
int iCellFirst; /* First allowable cell index */
5333953711
int iCellLast; /* Last possible cell index */
5334053712
5334153713
5334253714
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5334353715
assert( pPage->pBt!=0 );
5334453716
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
5334553717
assert( pPage->nOverflow==0 );
5334653718
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53347
- temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53348
- data = pPage->aData;
53719
+ temp = 0;
53720
+ src = data = pPage->aData;
5334953721
hdr = pPage->hdrOffset;
5335053722
cellOffset = pPage->cellOffset;
5335153723
nCell = pPage->nCell;
5335253724
assert( nCell==get2byte(&data[hdr+3]) );
5335353725
usableSize = pPage->pBt->usableSize;
53354
- cbrk = get2byte(&data[hdr+5]);
53355
- memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
5335653726
cbrk = usableSize;
5335753727
iCellFirst = cellOffset + 2*nCell;
5335853728
iCellLast = usableSize - 4;
5335953729
for(i=0; i<nCell; i++){
5336053730
u8 *pAddr; /* The i-th cell pointer */
@@ -53369,11 +53739,11 @@
5336953739
if( pc<iCellFirst || pc>iCellLast ){
5337053740
return SQLITE_CORRUPT_BKPT;
5337153741
}
5337253742
#endif
5337353743
assert( pc>=iCellFirst && pc<=iCellLast );
53374
- size = cellSizePtr(pPage, &temp[pc]);
53744
+ size = cellSizePtr(pPage, &src[pc]);
5337553745
cbrk -= size;
5337653746
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
5337753747
if( cbrk<iCellFirst ){
5337853748
return SQLITE_CORRUPT_BKPT;
5337953749
}
@@ -53383,12 +53753,20 @@
5338353753
}
5338453754
#endif
5338553755
assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
5338653756
testcase( cbrk+size==usableSize );
5338753757
testcase( pc+size==usableSize );
53388
- memcpy(&data[cbrk], &temp[pc], size);
5338953758
put2byte(pAddr, cbrk);
53759
+ if( temp==0 ){
53760
+ int x;
53761
+ if( cbrk==pc ) continue;
53762
+ temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53763
+ x = get2byte(&data[hdr+5]);
53764
+ memcpy(&temp[x], &data[x], (cbrk+size) - x);
53765
+ src = temp;
53766
+ }
53767
+ memcpy(&data[cbrk], &src[pc], size);
5339053768
}
5339153769
assert( cbrk>=iCellFirst );
5339253770
put2byte(&data[hdr+5], cbrk);
5339353771
data[hdr+1] = 0;
5339453772
data[hdr+2] = 0;
@@ -53398,10 +53776,73 @@
5339853776
if( cbrk-iCellFirst!=pPage->nFree ){
5339953777
return SQLITE_CORRUPT_BKPT;
5340053778
}
5340153779
return SQLITE_OK;
5340253780
}
53781
+
53782
+/*
53783
+** Search the free-list on page pPg for space to store a cell nByte bytes in
53784
+** size. If one can be found, return a pointer to the space and remove it
53785
+** from the free-list.
53786
+**
53787
+** If no suitable space can be found on the free-list, return NULL.
53788
+**
53789
+** This function may detect corruption within pPg. If corruption is
53790
+** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
53791
+**
53792
+** If a slot of at least nByte bytes is found but cannot be used because
53793
+** there are already at least 60 fragmented bytes on the page, return NULL.
53794
+** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true.
53795
+*/
53796
+static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){
53797
+ const int hdr = pPg->hdrOffset;
53798
+ u8 * const aData = pPg->aData;
53799
+ int iAddr;
53800
+ int pc;
53801
+ int usableSize = pPg->pBt->usableSize;
53802
+
53803
+ for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){
53804
+ int size; /* Size of the free slot */
53805
+ /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
53806
+ ** increasing offset. */
53807
+ if( pc>usableSize-4 || pc<iAddr+4 ){
53808
+ *pRc = SQLITE_CORRUPT_BKPT;
53809
+ return 0;
53810
+ }
53811
+ /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
53812
+ ** freeblock form a big-endian integer which is the size of the freeblock
53813
+ ** in bytes, including the 4-byte header. */
53814
+ size = get2byte(&aData[pc+2]);
53815
+ if( size>=nByte ){
53816
+ int x = size - nByte;
53817
+ testcase( x==4 );
53818
+ testcase( x==3 );
53819
+ if( x<4 ){
53820
+ /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
53821
+ ** number of bytes in fragments may not exceed 60. */
53822
+ if( aData[hdr+7]>=60 ){
53823
+ if( pbDefrag ) *pbDefrag = 1;
53824
+ return 0;
53825
+ }
53826
+ /* Remove the slot from the free-list. Update the number of
53827
+ ** fragmented bytes within the page. */
53828
+ memcpy(&aData[iAddr], &aData[pc], 2);
53829
+ aData[hdr+7] += (u8)x;
53830
+ }else if( size+pc > usableSize ){
53831
+ *pRc = SQLITE_CORRUPT_BKPT;
53832
+ return 0;
53833
+ }else{
53834
+ /* The slot remains on the free-list. Reduce its size to account
53835
+ ** for the portion used by the new allocation. */
53836
+ put2byte(&aData[pc+2], x);
53837
+ }
53838
+ return &aData[pc + x];
53839
+ }
53840
+ }
53841
+
53842
+ return 0;
53843
+}
5340353844
5340453845
/*
5340553846
** Allocate nByte bytes of space from within the B-Tree page passed
5340653847
** as the first argument. Write into *pIdx the index into pPage->aData[]
5340753848
** of the first byte of allocated space. Return either SQLITE_OK or
@@ -53416,80 +53857,58 @@
5341653857
*/
5341753858
static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
5341853859
const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
5341953860
u8 * const data = pPage->aData; /* Local cache of pPage->aData */
5342053861
int top; /* First byte of cell content area */
53862
+ int rc = SQLITE_OK; /* Integer return code */
5342153863
int gap; /* First byte of gap between cell pointers and cell content */
53422
- int rc; /* Integer return code */
53423
- int usableSize; /* Usable size of the page */
5342453864
5342553865
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5342653866
assert( pPage->pBt );
5342753867
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5342853868
assert( nByte>=0 ); /* Minimum cell size is 4 */
5342953869
assert( pPage->nFree>=nByte );
5343053870
assert( pPage->nOverflow==0 );
53431
- usableSize = pPage->pBt->usableSize;
53432
- assert( nByte < usableSize-8 );
53871
+ assert( nByte < (int)(pPage->pBt->usableSize-8) );
5343353872
5343453873
assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
5343553874
gap = pPage->cellOffset + 2*pPage->nCell;
5343653875
assert( gap<=65536 );
53437
- top = get2byte(&data[hdr+5]);
53438
- if( gap>top ){
53439
- if( top==0 ){
53440
- top = 65536;
53441
- }else{
53442
- return SQLITE_CORRUPT_BKPT;
53443
- }
53444
- }
53876
+ /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
53877
+ ** and the reserved space is zero (the usual value for reserved space)
53878
+ ** then the cell content offset of an empty page wants to be 65536.
53879
+ ** However, that integer is too large to be stored in a 2-byte unsigned
53880
+ ** integer, so a value of 0 is used in its place. */
53881
+ top = get2byteNotZero(&data[hdr+5]);
53882
+ if( gap>top ) return SQLITE_CORRUPT_BKPT;
5344553883
5344653884
/* If there is enough space between gap and top for one more cell pointer
5344753885
** array entry offset, and if the freelist is not empty, then search the
5344853886
** freelist looking for a free slot big enough to satisfy the request.
5344953887
*/
5345053888
testcase( gap+2==top );
5345153889
testcase( gap+1==top );
5345253890
testcase( gap==top );
5345353891
if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53454
- int pc, addr;
53455
- for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){
53456
- int size; /* Size of the free slot */
53457
- if( pc>usableSize-4 || pc<addr+4 ){
53458
- return SQLITE_CORRUPT_BKPT;
53459
- }
53460
- size = get2byte(&data[pc+2]);
53461
- if( size>=nByte ){
53462
- int x = size - nByte;
53463
- testcase( x==4 );
53464
- testcase( x==3 );
53465
- if( x<4 ){
53466
- if( data[hdr+7]>=60 ) goto defragment_page;
53467
- /* Remove the slot from the free-list. Update the number of
53468
- ** fragmented bytes within the page. */
53469
- memcpy(&data[addr], &data[pc], 2);
53470
- data[hdr+7] += (u8)x;
53471
- }else if( size+pc > usableSize ){
53472
- return SQLITE_CORRUPT_BKPT;
53473
- }else{
53474
- /* The slot remains on the free-list. Reduce its size to account
53475
- ** for the portion used by the new allocation. */
53476
- put2byte(&data[pc+2], x);
53477
- }
53478
- *pIdx = pc + x;
53479
- return SQLITE_OK;
53480
- }
53892
+ int bDefrag = 0;
53893
+ u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag);
53894
+ if( rc ) return rc;
53895
+ if( bDefrag ) goto defragment_page;
53896
+ if( pSpace ){
53897
+ assert( pSpace>=data && (pSpace - data)<65536 );
53898
+ *pIdx = (int)(pSpace - data);
53899
+ return SQLITE_OK;
5348153900
}
5348253901
}
5348353902
5348453903
/* The request could not be fulfilled using a freelist slot. Check
5348553904
** to see if defragmentation is necessary.
5348653905
*/
5348753906
testcase( gap+2+nByte==top );
5348853907
if( gap+2+nByte>top ){
53489
-defragment_page:
53490
- testcase( pPage->nCell==0 );
53908
+ defragment_page:
53909
+ assert( pPage->nCell>0 || CORRUPT_DB );
5349153910
rc = defragmentPage(pPage);
5349253911
if( rc ) return rc;
5349353912
top = get2byteNotZero(&data[hdr+5]);
5349453913
assert( gap+nByte<=top );
5349553914
}
@@ -53532,11 +53951,11 @@
5353253951
unsigned char *data = pPage->aData; /* Page content */
5353353952
5353453953
assert( pPage->pBt!=0 );
5353553954
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
5353653955
assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53537
- assert( iEnd <= pPage->pBt->usableSize );
53956
+ assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
5353853957
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5353953958
assert( iSize>=4 ); /* Minimum cell size is 4 */
5354053959
assert( iStart<=iLast );
5354153960
5354253961
/* Overwrite deleted information with zeros when the secure_delete
@@ -53627,22 +54046,36 @@
5362754046
pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
5362854047
flagByte &= ~PTF_LEAF;
5362954048
pPage->childPtrSize = 4-4*pPage->leaf;
5363054049
pBt = pPage->pBt;
5363154050
if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
54051
+ /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
54052
+ ** table b-tree page. */
54053
+ assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
54054
+ /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
54055
+ ** table b-tree page. */
54056
+ assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
5363254057
pPage->intKey = 1;
5363354058
pPage->intKeyLeaf = pPage->leaf;
5363454059
pPage->noPayload = !pPage->leaf;
5363554060
pPage->maxLocal = pBt->maxLeaf;
5363654061
pPage->minLocal = pBt->minLeaf;
5363754062
}else if( flagByte==PTF_ZERODATA ){
54063
+ /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
54064
+ ** index b-tree page. */
54065
+ assert( (PTF_ZERODATA)==2 );
54066
+ /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
54067
+ ** index b-tree page. */
54068
+ assert( (PTF_ZERODATA|PTF_LEAF)==10 );
5363854069
pPage->intKey = 0;
5363954070
pPage->intKeyLeaf = 0;
5364054071
pPage->noPayload = 0;
5364154072
pPage->maxLocal = pBt->maxLocal;
5364254073
pPage->minLocal = pBt->minLocal;
5364354074
}else{
54075
+ /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
54076
+ ** an error. */
5364454077
return SQLITE_CORRUPT_BKPT;
5364554078
}
5364654079
pPage->max1bytePayload = pBt->max1bytePayload;
5364754080
return SQLITE_OK;
5364854081
}
@@ -53678,25 +54111,37 @@
5367854111
5367954112
pBt = pPage->pBt;
5368054113
5368154114
hdr = pPage->hdrOffset;
5368254115
data = pPage->aData;
54116
+ /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
54117
+ ** the b-tree page type. */
5368354118
if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
5368454119
assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
5368554120
pPage->maskPage = (u16)(pBt->pageSize - 1);
5368654121
pPage->nOverflow = 0;
5368754122
usableSize = pBt->usableSize;
53688
- pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf;
54123
+ pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
5368954124
pPage->aDataEnd = &data[usableSize];
5369054125
pPage->aCellIdx = &data[cellOffset];
54126
+ /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
54127
+ ** the start of the cell content area. A zero value for this integer is
54128
+ ** interpreted as 65536. */
5369154129
top = get2byteNotZero(&data[hdr+5]);
54130
+ /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
54131
+ ** number of cells on the page. */
5369254132
pPage->nCell = get2byte(&data[hdr+3]);
5369354133
if( pPage->nCell>MX_CELL(pBt) ){
5369454134
/* To many cells for a single page. The page must be corrupt */
5369554135
return SQLITE_CORRUPT_BKPT;
5369654136
}
5369754137
testcase( pPage->nCell==MX_CELL(pBt) );
54138
+ /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
54139
+ ** possible for a root page of a table that contains no rows) then the
54140
+ ** offset to the cell content area will equal the page size minus the
54141
+ ** bytes of reserved space. */
54142
+ assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
5369854143
5369954144
/* A malformed database page might cause us to read past the end
5370054145
** of page when parsing a cell.
5370154146
**
5370254147
** The following block of code checks early to see if a cell extends
@@ -53726,17 +54171,24 @@
5372654171
}
5372754172
if( !pPage->leaf ) iCellLast++;
5372854173
}
5372954174
#endif
5373054175
53731
- /* Compute the total free space on the page */
54176
+ /* Compute the total free space on the page
54177
+ ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
54178
+ ** start of the first freeblock on the page, or is zero if there are no
54179
+ ** freeblocks. */
5373254180
pc = get2byte(&data[hdr+1]);
53733
- nFree = data[hdr+7] + top;
54181
+ nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
5373454182
while( pc>0 ){
5373554183
u16 next, size;
5373654184
if( pc<iCellFirst || pc>iCellLast ){
53737
- /* Start of free block is off the page */
54185
+ /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
54186
+ ** always be at least one cell before the first freeblock.
54187
+ **
54188
+ ** Or, the freeblock is off the end of the page
54189
+ */
5373854190
return SQLITE_CORRUPT_BKPT;
5373954191
}
5374054192
next = get2byte(&data[pc]);
5374154193
size = get2byte(&data[pc+2]);
5374254194
if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
@@ -54138,10 +54590,13 @@
5413854590
pBt->pPage1 = 0;
5413954591
if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
5414054592
#ifdef SQLITE_SECURE_DELETE
5414154593
pBt->btsFlags |= BTS_SECURE_DELETE;
5414254594
#endif
54595
+ /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
54596
+ ** determined by the 2-byte integer located at an offset of 16 bytes from
54597
+ ** the beginning of the database file. */
5414354598
pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
5414454599
if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
5414554600
|| ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
5414654601
pBt->pageSize = 0;
5414754602
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -54156,10 +54611,13 @@
5415654611
pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
5415754612
}
5415854613
#endif
5415954614
nReserve = 0;
5416054615
}else{
54616
+ /* EVIDENCE-OF: R-37497-42412 The size of the reserved region is
54617
+ ** determined by the one-byte unsigned integer found at an offset of 20
54618
+ ** into the database file header. */
5416154619
nReserve = zDbHeader[20];
5416254620
pBt->btsFlags |= BTS_PAGESIZE_FIXED;
5416354621
#ifndef SQLITE_OMIT_AUTOVACUUM
5416454622
pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
5416554623
pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
@@ -54353,11 +54811,11 @@
5435354811
5435454812
/* Rollback any active transaction and free the handle structure.
5435554813
** The call to sqlite3BtreeRollback() drops any table-locks held by
5435654814
** this handle.
5435754815
*/
54358
- sqlite3BtreeRollback(p, SQLITE_OK);
54816
+ sqlite3BtreeRollback(p, SQLITE_OK, 0);
5435954817
sqlite3BtreeLeave(p);
5436054818
5436154819
/* If there are still other outstanding references to the shared-btree
5436254820
** structure, return now. The remainder of this procedure cleans
5436354821
** up the shared-btree.
@@ -54665,10 +55123,13 @@
5466555123
if( nPage>0 ){
5466655124
u32 pageSize;
5466755125
u32 usableSize;
5466855126
u8 *page1 = pPage1->aData;
5466955127
rc = SQLITE_NOTADB;
55128
+ /* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
55129
+ ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
55130
+ ** 61 74 20 33 00. */
5467055131
if( memcmp(page1, zMagicHeader, 16)!=0 ){
5467155132
goto page1_init_failed;
5467255133
}
5467355134
5467455135
#ifdef SQLITE_OMIT_WAL
@@ -54705,26 +55166,39 @@
5470555166
}
5470655167
rc = SQLITE_NOTADB;
5470755168
}
5470855169
#endif
5470955170
54710
- /* The maximum embedded fraction must be exactly 25%. And the minimum
54711
- ** embedded fraction must be 12.5% for both leaf-data and non-leaf-data.
55171
+ /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
55172
+ ** fractions and the leaf payload fraction values must be 64, 32, and 32.
55173
+ **
5471255174
** The original design allowed these amounts to vary, but as of
5471355175
** version 3.6.0, we require them to be fixed.
5471455176
*/
5471555177
if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
5471655178
goto page1_init_failed;
5471755179
}
55180
+ /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
55181
+ ** determined by the 2-byte integer located at an offset of 16 bytes from
55182
+ ** the beginning of the database file. */
5471855183
pageSize = (page1[16]<<8) | (page1[17]<<16);
55184
+ /* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
55185
+ ** between 512 and 65536 inclusive. */
5471955186
if( ((pageSize-1)&pageSize)!=0
5472055187
|| pageSize>SQLITE_MAX_PAGE_SIZE
5472155188
|| pageSize<=256
5472255189
){
5472355190
goto page1_init_failed;
5472455191
}
5472555192
assert( (pageSize & 7)==0 );
55193
+ /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
55194
+ ** integer at offset 20 is the number of bytes of space at the end of
55195
+ ** each page to reserve for extensions.
55196
+ **
55197
+ ** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
55198
+ ** determined by the one-byte unsigned integer found at an offset of 20
55199
+ ** into the database file header. */
5472655200
usableSize = pageSize - page1[20];
5472755201
if( (u32)pageSize!=pBt->pageSize ){
5472855202
/* After reading the first page of the database assuming a page size
5472955203
** of BtShared.pageSize, we have discovered that the page-size is
5473055204
** actually pageSize. Unlock the database, leave pBt->pPage1 at
@@ -54741,10 +55215,13 @@
5474155215
}
5474255216
if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
5474355217
rc = SQLITE_CORRUPT_BKPT;
5474455218
goto page1_init_failed;
5474555219
}
55220
+ /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
55221
+ ** be less than 480. In other words, if the page size is 512, then the
55222
+ ** reserved space size cannot exceed 32. */
5474655223
if( usableSize<480 ){
5474755224
goto page1_init_failed;
5474855225
}
5474955226
pBt->pageSize = pageSize;
5475055227
pBt->usableSize = usableSize;
@@ -55646,64 +56123,95 @@
5564656123
return rc;
5564756124
}
5564856125
5564956126
/*
5565056127
** This routine sets the state to CURSOR_FAULT and the error
55651
-** code to errCode for every cursor on BtShared that pBtree
55652
-** references.
55653
-**
55654
-** Every cursor is tripped, including cursors that belong
55655
-** to other database connections that happen to be sharing
55656
-** the cache with pBtree.
55657
-**
55658
-** This routine gets called when a rollback occurs.
55659
-** All cursors using the same cache must be tripped
55660
-** to prevent them from trying to use the btree after
55661
-** the rollback. The rollback may have deleted tables
55662
-** or moved root pages, so it is not sufficient to
55663
-** save the state of the cursor. The cursor must be
55664
-** invalidated.
55665
-*/
55666
-SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
56128
+** code to errCode for every cursor on any BtShared that pBtree
56129
+** references. Or if the writeOnly flag is set to 1, then only
56130
+** trip write cursors and leave read cursors unchanged.
56131
+**
56132
+** Every cursor is a candidate to be tripped, including cursors
56133
+** that belong to other database connections that happen to be
56134
+** sharing the cache with pBtree.
56135
+**
56136
+** This routine gets called when a rollback occurs. If the writeOnly
56137
+** flag is true, then only write-cursors need be tripped - read-only
56138
+** cursors save their current positions so that they may continue
56139
+** following the rollback. Or, if writeOnly is false, all cursors are
56140
+** tripped. In general, writeOnly is false if the transaction being
56141
+** rolled back modified the database schema. In this case b-tree root
56142
+** pages may be moved or deleted from the database altogether, making
56143
+** it unsafe for read cursors to continue.
56144
+**
56145
+** If the writeOnly flag is true and an error is encountered while
56146
+** saving the current position of a read-only cursor, all cursors,
56147
+** including all read-cursors are tripped.
56148
+**
56149
+** SQLITE_OK is returned if successful, or if an error occurs while
56150
+** saving a cursor position, an SQLite error code.
56151
+*/
56152
+SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
5566756153
BtCursor *p;
55668
- if( pBtree==0 ) return;
55669
- sqlite3BtreeEnter(pBtree);
55670
- for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55671
- int i;
55672
- sqlite3BtreeClearCursor(p);
55673
- p->eState = CURSOR_FAULT;
55674
- p->skipNext = errCode;
55675
- for(i=0; i<=p->iPage; i++){
55676
- releasePage(p->apPage[i]);
55677
- p->apPage[i] = 0;
55678
- }
55679
- }
55680
- sqlite3BtreeLeave(pBtree);
56154
+ int rc = SQLITE_OK;
56155
+
56156
+ assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
56157
+ if( pBtree ){
56158
+ sqlite3BtreeEnter(pBtree);
56159
+ for(p=pBtree->pBt->pCursor; p; p=p->pNext){
56160
+ int i;
56161
+ if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
56162
+ if( p->eState==CURSOR_VALID ){
56163
+ rc = saveCursorPosition(p);
56164
+ if( rc!=SQLITE_OK ){
56165
+ (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
56166
+ break;
56167
+ }
56168
+ }
56169
+ }else{
56170
+ sqlite3BtreeClearCursor(p);
56171
+ p->eState = CURSOR_FAULT;
56172
+ p->skipNext = errCode;
56173
+ }
56174
+ for(i=0; i<=p->iPage; i++){
56175
+ releasePage(p->apPage[i]);
56176
+ p->apPage[i] = 0;
56177
+ }
56178
+ }
56179
+ sqlite3BtreeLeave(pBtree);
56180
+ }
56181
+ return rc;
5568156182
}
5568256183
5568356184
/*
55684
-** Rollback the transaction in progress. All cursors will be
55685
-** invalided by this operation. Any attempt to use a cursor
55686
-** that was open at the beginning of this operation will result
55687
-** in an error.
56185
+** Rollback the transaction in progress.
56186
+**
56187
+** If tripCode is not SQLITE_OK then cursors will be invalidated (tripped).
56188
+** Only write cursors are tripped if writeOnly is true but all cursors are
56189
+** tripped if writeOnly is false. Any attempt to use
56190
+** a tripped cursor will result in an error.
5568856191
**
5568956192
** This will release the write lock on the database file. If there
5569056193
** are no active cursors, it also releases the read lock.
5569156194
*/
55692
-SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode){
56195
+SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode, int writeOnly){
5569356196
int rc;
5569456197
BtShared *pBt = p->pBt;
5569556198
MemPage *pPage1;
5569656199
56200
+ assert( writeOnly==1 || writeOnly==0 );
56201
+ assert( tripCode==SQLITE_ABORT_ROLLBACK || tripCode==SQLITE_OK );
5569756202
sqlite3BtreeEnter(p);
5569856203
if( tripCode==SQLITE_OK ){
5569956204
rc = tripCode = saveAllCursors(pBt, 0, 0);
56205
+ if( rc ) writeOnly = 0;
5570056206
}else{
5570156207
rc = SQLITE_OK;
5570256208
}
5570356209
if( tripCode ){
55704
- sqlite3BtreeTripAllCursors(p, tripCode);
56210
+ int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
56211
+ assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
56212
+ if( rc2!=SQLITE_OK ) rc = rc2;
5570556213
}
5570656214
btreeIntegrity(p);
5570756215
5570856216
if( p->inTrans==TRANS_WRITE ){
5570956217
int rc2;
@@ -56034,17 +56542,13 @@
5603456542
**
5603556543
** This routine cannot fail. It always returns SQLITE_OK.
5603656544
*/
5603756545
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
5603856546
assert( cursorHoldsMutex(pCur) );
56039
- assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
56040
- if( pCur->eState!=CURSOR_VALID ){
56041
- *pSize = 0;
56042
- }else{
56043
- getCellInfo(pCur);
56044
- *pSize = pCur->info.nKey;
56045
- }
56547
+ assert( pCur->eState==CURSOR_VALID );
56548
+ getCellInfo(pCur);
56549
+ *pSize = pCur->info.nKey;
5604656550
return SQLITE_OK;
5604756551
}
5604856552
5604956553
/*
5605056554
** Set *pSize to the number of bytes of data in the entry the
@@ -57291,10 +57795,12 @@
5729157795
5729257796
assert( sqlite3_mutex_held(pBt->mutex) );
5729357797
assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
5729457798
pPage1 = pBt->pPage1;
5729557799
mxPage = btreePagecount(pBt);
57800
+ /* EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36
57801
+ ** stores stores the total number of pages on the freelist. */
5729657802
n = get4byte(&pPage1->aData[36]);
5729757803
testcase( n==mxPage-1 );
5729857804
if( n>=mxPage ){
5729957805
return SQLITE_CORRUPT_BKPT;
5730057806
}
@@ -57337,12 +57843,18 @@
5733757843
** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
5733857844
*/
5733957845
do {
5734057846
pPrevTrunk = pTrunk;
5734157847
if( pPrevTrunk ){
57848
+ /* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
57849
+ ** is the page number of the next freelist trunk page in the list or
57850
+ ** zero if this is the last freelist trunk page. */
5734257851
iTrunk = get4byte(&pPrevTrunk->aData[0]);
5734357852
}else{
57853
+ /* EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
57854
+ ** stores the page number of the first page of the freelist, or zero if
57855
+ ** the freelist is empty. */
5734457856
iTrunk = get4byte(&pPage1->aData[32]);
5734557857
}
5734657858
testcase( iTrunk==mxPage );
5734757859
if( iTrunk>mxPage ){
5734857860
rc = SQLITE_CORRUPT_BKPT;
@@ -57353,12 +57865,13 @@
5735357865
pTrunk = 0;
5735457866
goto end_allocate_page;
5735557867
}
5735657868
assert( pTrunk!=0 );
5735757869
assert( pTrunk->aData!=0 );
57358
-
57359
- k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
57870
+ /* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
57871
+ ** is the number of leaf page pointers to follow. */
57872
+ k = get4byte(&pTrunk->aData[4]);
5736057873
if( k==0 && !searchList ){
5736157874
/* The trunk has no leaves and the list is not being searched.
5736257875
** So extract the trunk page itself and use it as the newly
5736357876
** allocated page */
5736457877
assert( pPrevTrunk==0 );
@@ -57672,10 +58185,15 @@
5767258185
** to maintain backwards compatibility with older versions of SQLite,
5767358186
** we will continue to restrict the number of entries to usableSize/4 - 8
5767458187
** for now. At some point in the future (once everyone has upgraded
5767558188
** to 3.6.0 or later) we should consider fixing the conditional above
5767658189
** to read "usableSize/4-2" instead of "usableSize/4-8".
58190
+ **
58191
+ ** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
58192
+ ** avoid using the last six entries in the freelist trunk page array in
58193
+ ** order that database files created by newer versions of SQLite can be
58194
+ ** read by older versions of SQLite.
5767758195
*/
5767858196
rc = sqlite3PagerWrite(pTrunk->pDbPage);
5767958197
if( rc==SQLITE_OK ){
5768058198
put4byte(&pTrunk->aData[4], nLeaf+1);
5768158199
put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
@@ -58023,13 +58541,21 @@
5802358541
if( rc ){
5802458542
*pRC = rc;
5802558543
return;
5802658544
}
5802758545
pPage->nCell--;
58028
- memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
58029
- put2byte(&data[hdr+3], pPage->nCell);
58030
- pPage->nFree += 2;
58546
+ if( pPage->nCell==0 ){
58547
+ memset(&data[hdr+1], 0, 4);
58548
+ data[hdr+7] = 0;
58549
+ put2byte(&data[hdr+5], pPage->pBt->usableSize);
58550
+ pPage->nFree = pPage->pBt->usableSize - pPage->hdrOffset
58551
+ - pPage->childPtrSize - 8;
58552
+ }else{
58553
+ memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
58554
+ put2byte(&data[hdr+3], pPage->nCell);
58555
+ pPage->nFree += 2;
58556
+ }
5803158557
}
5803258558
5803358559
/*
5803458560
** Insert a new cell on pPage at cell index "i". pCell points to the
5803558561
** content of the cell.
@@ -58120,49 +58646,275 @@
5812058646
#endif
5812158647
}
5812258648
}
5812358649
5812458650
/*
58125
-** Add a list of cells to a page. The page should be initially empty.
58126
-** The cells are guaranteed to fit on the page.
58127
-*/
58128
-static void assemblePage(
58129
- MemPage *pPage, /* The page to be assembled */
58130
- int nCell, /* The number of cells to add to this page */
58131
- u8 **apCell, /* Pointers to cell bodies */
58132
- u16 *aSize /* Sizes of the cells */
58133
-){
58134
- int i; /* Loop counter */
58135
- u8 *pCellptr; /* Address of next cell pointer */
58136
- int cellbody; /* Address of next cell body */
58137
- u8 * const data = pPage->aData; /* Pointer to data for pPage */
58138
- const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
58139
- const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
58140
-
58141
- assert( pPage->nOverflow==0 );
58142
- assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58143
- assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
58144
- && (int)MX_CELL(pPage->pBt)<=10921);
58145
- assert( sqlite3PagerIswriteable(pPage->pDbPage) );
58146
-
58147
- /* Check that the page has just been zeroed by zeroPage() */
58148
- assert( pPage->nCell==0 );
58149
- assert( get2byteNotZero(&data[hdr+5])==nUsable );
58150
-
58151
- pCellptr = &pPage->aCellIdx[nCell*2];
58152
- cellbody = nUsable;
58153
- for(i=nCell-1; i>=0; i--){
58154
- u16 sz = aSize[i];
58155
- pCellptr -= 2;
58156
- cellbody -= sz;
58157
- put2byte(pCellptr, cellbody);
58158
- memcpy(&data[cellbody], apCell[i], sz);
58159
- }
58160
- put2byte(&data[hdr+3], nCell);
58161
- put2byte(&data[hdr+5], cellbody);
58162
- pPage->nFree -= (nCell*2 + nUsable - cellbody);
58163
- pPage->nCell = (u16)nCell;
58651
+** Array apCell[] contains pointers to nCell b-tree page cells. The
58652
+** szCell[] array contains the size in bytes of each cell. This function
58653
+** replaces the current contents of page pPg with the contents of the cell
58654
+** array.
58655
+**
58656
+** Some of the cells in apCell[] may currently be stored in pPg. This
58657
+** function works around problems caused by this by making a copy of any
58658
+** such cells before overwriting the page data.
58659
+**
58660
+** The MemPage.nFree field is invalidated by this function. It is the
58661
+** responsibility of the caller to set it correctly.
58662
+*/
58663
+static void rebuildPage(
58664
+ MemPage *pPg, /* Edit this page */
58665
+ int nCell, /* Final number of cells on page */
58666
+ u8 **apCell, /* Array of cells */
58667
+ u16 *szCell /* Array of cell sizes */
58668
+){
58669
+ const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
58670
+ u8 * const aData = pPg->aData; /* Pointer to data for pPg */
58671
+ const int usableSize = pPg->pBt->usableSize;
58672
+ u8 * const pEnd = &aData[usableSize];
58673
+ int i;
58674
+ u8 *pCellptr = pPg->aCellIdx;
58675
+ u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58676
+ u8 *pData;
58677
+
58678
+ i = get2byte(&aData[hdr+5]);
58679
+ memcpy(&pTmp[i], &aData[i], usableSize - i);
58680
+
58681
+ pData = pEnd;
58682
+ for(i=0; i<nCell; i++){
58683
+ u8 *pCell = apCell[i];
58684
+ if( pCell>aData && pCell<pEnd ){
58685
+ pCell = &pTmp[pCell - aData];
58686
+ }
58687
+ pData -= szCell[i];
58688
+ memcpy(pData, pCell, szCell[i]);
58689
+ put2byte(pCellptr, (pData - aData));
58690
+ pCellptr += 2;
58691
+ assert( szCell[i]==cellSizePtr(pPg, pCell) );
58692
+ }
58693
+
58694
+ /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
58695
+ pPg->nCell = nCell;
58696
+ pPg->nOverflow = 0;
58697
+
58698
+ put2byte(&aData[hdr+1], 0);
58699
+ put2byte(&aData[hdr+3], pPg->nCell);
58700
+ put2byte(&aData[hdr+5], pData - aData);
58701
+ aData[hdr+7] = 0x00;
58702
+}
58703
+
58704
+/*
58705
+** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58706
+** contains the size in bytes of each such cell. This function attempts to
58707
+** add the cells stored in the array to page pPg. If it cannot (because
58708
+** the page needs to be defragmented before the cells will fit), non-zero
58709
+** is returned. Otherwise, if the cells are added successfully, zero is
58710
+** returned.
58711
+**
58712
+** Argument pCellptr points to the first entry in the cell-pointer array
58713
+** (part of page pPg) to populate. After cell apCell[0] is written to the
58714
+** page body, a 16-bit offset is written to pCellptr. And so on, for each
58715
+** cell in the array. It is the responsibility of the caller to ensure
58716
+** that it is safe to overwrite this part of the cell-pointer array.
58717
+**
58718
+** When this function is called, *ppData points to the start of the
58719
+** content area on page pPg. If the size of the content area is extended,
58720
+** *ppData is updated to point to the new start of the content area
58721
+** before returning.
58722
+**
58723
+** Finally, argument pBegin points to the byte immediately following the
58724
+** end of the space required by this page for the cell-pointer area (for
58725
+** all cells - not just those inserted by the current call). If the content
58726
+** area must be extended to before this point in order to accomodate all
58727
+** cells in apCell[], then the cells do not fit and non-zero is returned.
58728
+*/
58729
+static int pageInsertArray(
58730
+ MemPage *pPg, /* Page to add cells to */
58731
+ u8 *pBegin, /* End of cell-pointer array */
58732
+ u8 **ppData, /* IN/OUT: Page content -area pointer */
58733
+ u8 *pCellptr, /* Pointer to cell-pointer area */
58734
+ int nCell, /* Number of cells to add to pPg */
58735
+ u8 **apCell, /* Array of cells */
58736
+ u16 *szCell /* Array of cell sizes */
58737
+){
58738
+ int i;
58739
+ u8 *aData = pPg->aData;
58740
+ u8 *pData = *ppData;
58741
+ const int bFreelist = aData[1] || aData[2];
58742
+ assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
58743
+ for(i=0; i<nCell; i++){
58744
+ int sz = szCell[i];
58745
+ int rc;
58746
+ u8 *pSlot;
58747
+ if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
58748
+ pData -= sz;
58749
+ if( pData<pBegin ) return 1;
58750
+ pSlot = pData;
58751
+ }
58752
+ memcpy(pSlot, apCell[i], sz);
58753
+ put2byte(pCellptr, (pSlot - aData));
58754
+ pCellptr += 2;
58755
+ }
58756
+ *ppData = pData;
58757
+ return 0;
58758
+}
58759
+
58760
+/*
58761
+** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58762
+** contains the size in bytes of each such cell. This function adds the
58763
+** space associated with each cell in the array that is currently stored
58764
+** within the body of pPg to the pPg free-list. The cell-pointers and other
58765
+** fields of the page are not updated.
58766
+**
58767
+** This function returns the total number of cells added to the free-list.
58768
+*/
58769
+static int pageFreeArray(
58770
+ MemPage *pPg, /* Page to edit */
58771
+ int nCell, /* Cells to delete */
58772
+ u8 **apCell, /* Array of cells */
58773
+ u16 *szCell /* Array of cell sizes */
58774
+){
58775
+ u8 * const aData = pPg->aData;
58776
+ u8 * const pEnd = &aData[pPg->pBt->usableSize];
58777
+ u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
58778
+ int nRet = 0;
58779
+ int i;
58780
+ u8 *pFree = 0;
58781
+ int szFree = 0;
58782
+
58783
+ for(i=0; i<nCell; i++){
58784
+ u8 *pCell = apCell[i];
58785
+ if( pCell>=pStart && pCell<pEnd ){
58786
+ int sz = szCell[i];
58787
+ if( pFree!=(pCell + sz) ){
58788
+ if( pFree ){
58789
+ assert( pFree>aData && (pFree - aData)<65536 );
58790
+ freeSpace(pPg, (u16)(pFree - aData), szFree);
58791
+ }
58792
+ pFree = pCell;
58793
+ szFree = sz;
58794
+ if( pFree+sz>pEnd ) return 0;
58795
+ }else{
58796
+ pFree = pCell;
58797
+ szFree += sz;
58798
+ }
58799
+ nRet++;
58800
+ }
58801
+ }
58802
+ if( pFree ){
58803
+ assert( pFree>aData && (pFree - aData)<65536 );
58804
+ freeSpace(pPg, (u16)(pFree - aData), szFree);
58805
+ }
58806
+ return nRet;
58807
+}
58808
+
58809
+/*
58810
+** apCell[] and szCell[] contains pointers to and sizes of all cells in the
58811
+** pages being balanced. The current page, pPg, has pPg->nCell cells starting
58812
+** with apCell[iOld]. After balancing, this page should hold nNew cells
58813
+** starting at apCell[iNew].
58814
+**
58815
+** This routine makes the necessary adjustments to pPg so that it contains
58816
+** the correct cells after being balanced.
58817
+**
58818
+** The pPg->nFree field is invalid when this function returns. It is the
58819
+** responsibility of the caller to set it correctly.
58820
+*/
58821
+static void editPage(
58822
+ MemPage *pPg, /* Edit this page */
58823
+ int iOld, /* Index of first cell currently on page */
58824
+ int iNew, /* Index of new first cell on page */
58825
+ int nNew, /* Final number of cells on page */
58826
+ u8 **apCell, /* Array of cells */
58827
+ u16 *szCell /* Array of cell sizes */
58828
+){
58829
+ u8 * const aData = pPg->aData;
58830
+ const int hdr = pPg->hdrOffset;
58831
+ u8 *pBegin = &pPg->aCellIdx[nNew * 2];
58832
+ int nCell = pPg->nCell; /* Cells stored on pPg */
58833
+ u8 *pData;
58834
+ u8 *pCellptr;
58835
+ int i;
58836
+ int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
58837
+ int iNewEnd = iNew + nNew;
58838
+
58839
+#ifdef SQLITE_DEBUG
58840
+ u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58841
+ memcpy(pTmp, aData, pPg->pBt->usableSize);
58842
+#endif
58843
+
58844
+ /* Remove cells from the start and end of the page */
58845
+ if( iOld<iNew ){
58846
+ int nShift = pageFreeArray(
58847
+ pPg, iNew-iOld, &apCell[iOld], &szCell[iOld]
58848
+ );
58849
+ memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
58850
+ nCell -= nShift;
58851
+ }
58852
+ if( iNewEnd < iOldEnd ){
58853
+ nCell -= pageFreeArray(
58854
+ pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd]
58855
+ );
58856
+ }
58857
+
58858
+ pData = &aData[get2byteNotZero(&aData[hdr+5])];
58859
+ if( pData<pBegin ) goto editpage_fail;
58860
+
58861
+ /* Add cells to the start of the page */
58862
+ if( iNew<iOld ){
58863
+ int nAdd = MIN(nNew,iOld-iNew);
58864
+ assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
58865
+ pCellptr = pPg->aCellIdx;
58866
+ memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
58867
+ if( pageInsertArray(
58868
+ pPg, pBegin, &pData, pCellptr,
58869
+ nAdd, &apCell[iNew], &szCell[iNew]
58870
+ ) ) goto editpage_fail;
58871
+ nCell += nAdd;
58872
+ }
58873
+
58874
+ /* Add any overflow cells */
58875
+ for(i=0; i<pPg->nOverflow; i++){
58876
+ int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
58877
+ if( iCell>=0 && iCell<nNew ){
58878
+ pCellptr = &pPg->aCellIdx[iCell * 2];
58879
+ memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
58880
+ nCell++;
58881
+ if( pageInsertArray(
58882
+ pPg, pBegin, &pData, pCellptr,
58883
+ 1, &apCell[iCell + iNew], &szCell[iCell + iNew]
58884
+ ) ) goto editpage_fail;
58885
+ }
58886
+ }
58887
+
58888
+ /* Append cells to the end of the page */
58889
+ pCellptr = &pPg->aCellIdx[nCell*2];
58890
+ if( pageInsertArray(
58891
+ pPg, pBegin, &pData, pCellptr,
58892
+ nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell]
58893
+ ) ) goto editpage_fail;
58894
+
58895
+ pPg->nCell = nNew;
58896
+ pPg->nOverflow = 0;
58897
+
58898
+ put2byte(&aData[hdr+3], pPg->nCell);
58899
+ put2byte(&aData[hdr+5], pData - aData);
58900
+
58901
+#ifdef SQLITE_DEBUG
58902
+ for(i=0; i<nNew && !CORRUPT_DB; i++){
58903
+ u8 *pCell = apCell[i+iNew];
58904
+ int iOff = get2byte(&pPg->aCellIdx[i*2]);
58905
+ if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){
58906
+ pCell = &pTmp[pCell - aData];
58907
+ }
58908
+ assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) );
58909
+ }
58910
+#endif
58911
+
58912
+ return;
58913
+ editpage_fail:
58914
+ /* Unable to edit this page. Rebuild it from scratch instead. */
58915
+ rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]);
5816458916
}
5816558917
5816658918
/*
5816758919
** The following parameters determine how many adjacent pages get involved
5816858920
** in a balancing operation. NN is the number of neighbors on either side
@@ -58212,11 +58964,11 @@
5821258964
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
5821358965
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5821458966
assert( pPage->nOverflow==1 );
5821558967
5821658968
/* This error condition is now caught prior to reaching this function */
58217
- if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;
58969
+ if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT;
5821858970
5821958971
/* Allocate a new page. This page will become the right-sibling of
5822058972
** pPage. Make the parent page writable, so that the new divider cell
5822158973
** may be inserted. If both these operations are successful, proceed.
5822258974
*/
@@ -58230,11 +58982,12 @@
5823058982
u8 *pStop;
5823158983
5823258984
assert( sqlite3PagerIswriteable(pNew->pDbPage) );
5823358985
assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
5823458986
zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58235
- assemblePage(pNew, 1, &pCell, &szCell);
58987
+ rebuildPage(pNew, 1, &pCell, &szCell);
58988
+ pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
5823658989
5823758990
/* If this is an auto-vacuum database, update the pointer map
5823858991
** with entries for the new page, and any pointer from the
5823958992
** cell on the page to an overflow page. If either of these
5824058993
** operations fails, the return code is set, but the contents
@@ -58449,21 +59202,26 @@
5844959202
int subtotal; /* Subtotal of bytes in cells on one page */
5845059203
int iSpace1 = 0; /* First unused byte of aSpace1[] */
5845159204
int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
5845259205
int szScratch; /* Size of scratch memory requested */
5845359206
MemPage *apOld[NB]; /* pPage and up to two siblings */
58454
- MemPage *apCopy[NB]; /* Private copies of apOld[] pages */
5845559207
MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
5845659208
u8 *pRight; /* Location in parent of right-sibling pointer */
5845759209
u8 *apDiv[NB-1]; /* Divider cells in pParent */
5845859210
int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
58459
- int szNew[NB+2]; /* Combined size of cells place on i-th page */
59211
+ int cntOld[NB+2]; /* Old index in aCell[] after i-th page */
59212
+ int szNew[NB+2]; /* Combined size of cells placed on i-th page */
5846059213
u8 **apCell = 0; /* All cells begin balanced */
5846159214
u16 *szCell; /* Local size of all cells in apCell[] */
5846259215
u8 *aSpace1; /* Space for copies of dividers cells */
5846359216
Pgno pgno; /* Temp var to store a page number in */
59217
+ u8 abDone[NB+2]; /* True after i'th new page is populated */
59218
+ Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
59219
+ Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
59220
+ u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
5846459221
59222
+ memset(abDone, 0, sizeof(abDone));
5846559223
pBt = pParent->pBt;
5846659224
assert( sqlite3_mutex_held(pBt->mutex) );
5846759225
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5846859226
5846959227
#if 0
@@ -58568,16 +59326,18 @@
5856859326
nMaxCells = (nMaxCells + 3)&~3;
5856959327
5857059328
/*
5857159329
** Allocate space for memory structures
5857259330
*/
58573
- k = pBt->pageSize + ROUND8(sizeof(MemPage));
5857459331
szScratch =
5857559332
nMaxCells*sizeof(u8*) /* apCell */
5857659333
+ nMaxCells*sizeof(u16) /* szCell */
58577
- + pBt->pageSize /* aSpace1 */
58578
- + k*nOld; /* Page copies (apCopy) */
59334
+ + pBt->pageSize; /* aSpace1 */
59335
+
59336
+ /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
59337
+ ** that is more than 6 times the database page size. */
59338
+ assert( szScratch<=6*(int)pBt->pageSize );
5857959339
apCell = sqlite3ScratchMalloc( szScratch );
5858059340
if( apCell==0 ){
5858159341
rc = SQLITE_NOMEM;
5858259342
goto balance_cleanup;
5858359343
}
@@ -58586,12 +59346,12 @@
5858659346
assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
5858759347
5858859348
/*
5858959349
** Load pointers to all cells on sibling pages and the divider cells
5859059350
** into the local apCell[] array. Make copies of the divider cells
58591
- ** into space obtained from aSpace1[] and remove the divider cells
58592
- ** from pParent.
59351
+ ** into space obtained from aSpace1[]. The divider cells have already
59352
+ ** been removed from pParent.
5859359353
**
5859459354
** If the siblings are on leaf pages, then the child pointers of the
5859559355
** divider cells are stripped from the cells before they are copied
5859659356
** into aSpace1[]. In this way, all cells in apCell[] are without
5859759357
** child pointers. If siblings are not leaves, then all cell in
@@ -58603,19 +59363,11 @@
5860359363
*/
5860459364
leafCorrection = apOld[0]->leaf*4;
5860559365
leafData = apOld[0]->intKeyLeaf;
5860659366
for(i=0; i<nOld; i++){
5860759367
int limit;
58608
-
58609
- /* Before doing anything else, take a copy of the i'th original sibling
58610
- ** The rest of this function will use data from the copies rather
58611
- ** that the original pages since the original pages will be in the
58612
- ** process of being overwritten. */
58613
- MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
58614
- memcpy(pOld, apOld[i], sizeof(MemPage));
58615
- pOld->aData = (void*)&pOld[1];
58616
- memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
59368
+ MemPage *pOld = apOld[i];
5861759369
5861859370
limit = pOld->nCell+pOld->nOverflow;
5861959371
if( pOld->nOverflow>0 ){
5862059372
for(j=0; j<limit; j++){
5862159373
assert( nCell<nMaxCells );
@@ -58632,10 +59384,11 @@
5863259384
apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
5863359385
szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
5863459386
nCell++;
5863559387
}
5863659388
}
59389
+ cntOld[i] = nCell;
5863759390
if( i<nOld-1 && !leafData){
5863859391
u16 sz = (u16)szNew[i];
5863959392
u8 *pTemp;
5864059393
assert( nCell<nMaxCells );
5864159394
szCell[nCell] = sz;
@@ -58654,11 +59407,15 @@
5865459407
** pointer of the divider cell */
5865559408
memcpy(apCell[nCell], &pOld->aData[8], 4);
5865659409
}else{
5865759410
assert( leafCorrection==4 );
5865859411
if( szCell[nCell]<4 ){
58659
- /* Do not allow any cells smaller than 4 bytes. */
59412
+ /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59413
+ ** does exist, pad it with 0x00 bytes. */
59414
+ assert( szCell[nCell]==3 );
59415
+ assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416
+ pTemp[iSpace1++] = 0x00;
5866059417
szCell[nCell] = 4;
5866159418
}
5866259419
}
5866359420
nCell++;
5866459421
}
@@ -58683,11 +59440,11 @@
5868359440
usableSpace = pBt->usableSize - 12 + leafCorrection;
5868459441
for(subtotal=k=i=0; i<nCell; i++){
5868559442
assert( i<nMaxCells );
5868659443
subtotal += szCell[i] + 2;
5868759444
if( subtotal > usableSpace ){
58688
- szNew[k] = subtotal - szCell[i];
59445
+ szNew[k] = subtotal - szCell[i] - 2;
5868959446
cntNew[k] = i;
5869059447
if( leafData ){ i--; }
5869159448
subtotal = 0;
5869259449
k++;
5869359450
if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -58697,13 +59454,14 @@
5869759454
cntNew[k] = nCell;
5869859455
k++;
5869959456
5870059457
/*
5870159458
** The packing computed by the previous block is biased toward the siblings
58702
- ** on the left side. The left siblings are always nearly full, while the
58703
- ** right-most sibling might be nearly empty. This block of code attempts
58704
- ** to adjust the packing of siblings to get a better balance.
59459
+ ** on the left side (siblings with smaller keys). The left siblings are
59460
+ ** always nearly full, while the right-most sibling might be nearly empty.
59461
+ ** The next block of code attempts to adjust the packing of siblings to
59462
+ ** get a better balance.
5870559463
**
5870659464
** This adjustment is more than an optimization. The packing above might
5870759465
** be so out of balance as to be illegal. For example, the right-most
5870859466
** sibling might be completely empty. This adjustment is not optional.
5870959467
*/
@@ -58728,26 +59486,22 @@
5872859486
}
5872959487
szNew[i] = szRight;
5873059488
szNew[i-1] = szLeft;
5873159489
}
5873259490
58733
- /* Either we found one or more cells (cntnew[0])>0) or pPage is
58734
- ** a virtual root page. A virtual root page is when the real root
58735
- ** page is page 1 and we are the only child of that page.
58736
- **
58737
- ** UPDATE: The assert() below is not necessarily true if the database
58738
- ** file is corrupt. The corruption will be detected and reported later
58739
- ** in this procedure so there is no need to act upon it now.
59491
+ /* Sanity check: For a non-corrupt database file one of the follwing
59492
+ ** must be true:
59493
+ ** (1) We found one or more cells (cntNew[0])>0), or
59494
+ ** (2) pPage is a virtual root page. A virtual root page is when
59495
+ ** the real root page is page 1 and we are the only child of
59496
+ ** that page.
5874059497
*/
58741
-#if 0
58742
- assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) );
58743
-#endif
58744
-
58745
- TRACE(("BALANCE: old: %d %d %d ",
58746
- apOld[0]->pgno,
58747
- nOld>=2 ? apOld[1]->pgno : 0,
58748
- nOld>=3 ? apOld[2]->pgno : 0
59498
+ assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
59499
+ TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n",
59500
+ apOld[0]->pgno, apOld[0]->nCell,
59501
+ nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
59502
+ nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
5874959503
));
5875059504
5875159505
/*
5875259506
** Allocate k new pages. Reuse old pages where possible.
5875359507
*/
@@ -58766,12 +59520,14 @@
5876659520
if( rc ) goto balance_cleanup;
5876759521
}else{
5876859522
assert( i>0 );
5876959523
rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
5877059524
if( rc ) goto balance_cleanup;
59525
+ zeroPage(pNew, pageFlags);
5877159526
apNew[i] = pNew;
5877259527
nNew++;
59528
+ cntOld[i] = nCell;
5877359529
5877459530
/* Set the pointer-map entry for the new sibling page. */
5877559531
if( ISAUTOVACUUM ){
5877659532
ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
5877759533
if( rc!=SQLITE_OK ){
@@ -58779,139 +59535,251 @@
5877959535
}
5878059536
}
5878159537
}
5878259538
}
5878359539
58784
- /* Free any old pages that were not reused as new pages.
58785
- */
58786
- while( i<nOld ){
58787
- freePage(apOld[i], &rc);
58788
- if( rc ) goto balance_cleanup;
58789
- releasePage(apOld[i]);
58790
- apOld[i] = 0;
58791
- i++;
58792
- }
58793
-
5879459540
/*
58795
- ** Put the new pages in ascending order. This helps to
58796
- ** keep entries in the disk file in order so that a scan
58797
- ** of the table is a linear scan through the file. That
58798
- ** in turn helps the operating system to deliver pages
58799
- ** from the disk more rapidly.
58800
- **
58801
- ** An O(n^2) insertion sort algorithm is used, but since
58802
- ** n is never more than NB (a small constant), that should
58803
- ** not be a problem.
58804
- **
58805
- ** When NB==3, this one optimization makes the database
58806
- ** about 25% faster for large insertions and deletions.
58807
- */
58808
- for(i=0; i<k-1; i++){
58809
- int minV = apNew[i]->pgno;
58810
- int minI = i;
58811
- for(j=i+1; j<k; j++){
58812
- if( apNew[j]->pgno<(unsigned)minV ){
58813
- minI = j;
58814
- minV = apNew[j]->pgno;
58815
- }
58816
- }
58817
- if( minI>i ){
58818
- MemPage *pT;
58819
- pT = apNew[i];
58820
- apNew[i] = apNew[minI];
58821
- apNew[minI] = pT;
58822
- }
58823
- }
58824
- TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n",
58825
- apNew[0]->pgno, szNew[0],
59541
+ ** Reassign page numbers so that the new pages are in ascending order.
59542
+ ** This helps to keep entries in the disk file in order so that a scan
59543
+ ** of the table is closer to a linear scan through the file. That in turn
59544
+ ** helps the operating system to deliver pages from the disk more rapidly.
59545
+ **
59546
+ ** An O(n^2) insertion sort algorithm is used, but since n is never more
59547
+ ** than (NB+2) (a small constant), that should not be a problem.
59548
+ **
59549
+ ** When NB==3, this one optimization makes the database about 25% faster
59550
+ ** for large insertions and deletions.
59551
+ */
59552
+ for(i=0; i<nNew; i++){
59553
+ aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
59554
+ aPgFlags[i] = apNew[i]->pDbPage->flags;
59555
+ for(j=0; j<i; j++){
59556
+ if( aPgno[j]==aPgno[i] ){
59557
+ /* This branch is taken if the set of sibling pages somehow contains
59558
+ ** duplicate entries. This can happen if the database is corrupt.
59559
+ ** It would be simpler to detect this as part of the loop below, but
59560
+ ** we do the detection here in order to avoid populating the pager
59561
+ ** cache with two separate objects associated with the same
59562
+ ** page number. */
59563
+ assert( CORRUPT_DB );
59564
+ rc = SQLITE_CORRUPT_BKPT;
59565
+ goto balance_cleanup;
59566
+ }
59567
+ }
59568
+ }
59569
+ for(i=0; i<nNew; i++){
59570
+ int iBest = 0; /* aPgno[] index of page number to use */
59571
+ for(j=1; j<nNew; j++){
59572
+ if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
59573
+ }
59574
+ pgno = aPgOrder[iBest];
59575
+ aPgOrder[iBest] = 0xffffffff;
59576
+ if( iBest!=i ){
59577
+ if( iBest>i ){
59578
+ sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
59579
+ }
59580
+ sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
59581
+ apNew[i]->pgno = pgno;
59582
+ }
59583
+ }
59584
+
59585
+ TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
59586
+ "%d(%d nc=%d) %d(%d nc=%d)\n",
59587
+ apNew[0]->pgno, szNew[0], cntNew[0],
5882659588
nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
59589
+ nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
5882759590
nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
59591
+ nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
5882859592
nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
58829
- nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0));
59593
+ nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
59594
+ nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
59595
+ nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
59596
+ ));
5883059597
5883159598
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
5883259599
put4byte(pRight, apNew[nNew-1]->pgno);
5883359600
58834
- /*
58835
- ** Evenly distribute the data in apCell[] across the new pages.
58836
- ** Insert divider cells into pParent as necessary.
59601
+ /* If the sibling pages are not leaves, ensure that the right-child pointer
59602
+ ** of the right-most new sibling page is set to the value that was
59603
+ ** originally in the same field of the right-most old sibling page. */
59604
+ if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
59605
+ MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
59606
+ memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
59607
+ }
59608
+
59609
+ /* Make any required updates to pointer map entries associated with
59610
+ ** cells stored on sibling pages following the balance operation. Pointer
59611
+ ** map entries associated with divider cells are set by the insertCell()
59612
+ ** routine. The associated pointer map entries are:
59613
+ **
59614
+ ** a) if the cell contains a reference to an overflow chain, the
59615
+ ** entry associated with the first page in the overflow chain, and
59616
+ **
59617
+ ** b) if the sibling pages are not leaves, the child page associated
59618
+ ** with the cell.
59619
+ **
59620
+ ** If the sibling pages are not leaves, then the pointer map entry
59621
+ ** associated with the right-child of each sibling may also need to be
59622
+ ** updated. This happens below, after the sibling pages have been
59623
+ ** populated, not here.
5883759624
*/
58838
- j = 0;
58839
- for(i=0; i<nNew; i++){
58840
- /* Assemble the new sibling page. */
59625
+ if( ISAUTOVACUUM ){
59626
+ MemPage *pNew = apNew[0];
59627
+ u8 *aOld = pNew->aData;
59628
+ int cntOldNext = pNew->nCell + pNew->nOverflow;
59629
+ int usableSize = pBt->usableSize;
59630
+ int iNew = 0;
59631
+ int iOld = 0;
59632
+
59633
+ for(i=0; i<nCell; i++){
59634
+ u8 *pCell = apCell[i];
59635
+ if( i==cntOldNext ){
59636
+ MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
59637
+ cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
59638
+ aOld = pOld->aData;
59639
+ }
59640
+ if( i==cntNew[iNew] ){
59641
+ pNew = apNew[++iNew];
59642
+ if( !leafData ) continue;
59643
+ }
59644
+
59645
+ /* Cell pCell is destined for new sibling page pNew. Originally, it
59646
+ ** was either part of sibling page iOld (possibly an overflow cell),
59647
+ ** or else the divider cell to the left of sibling page iOld. So,
59648
+ ** if sibling page iOld had the same page number as pNew, and if
59649
+ ** pCell really was a part of sibling page iOld (not a divider or
59650
+ ** overflow cell), we can skip updating the pointer map entries. */
59651
+ if( iOld>=nNew
59652
+ || pNew->pgno!=aPgno[iOld]
59653
+ || pCell<aOld
59654
+ || pCell>=&aOld[usableSize]
59655
+ ){
59656
+ if( !leafCorrection ){
59657
+ ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
59658
+ }
59659
+ if( szCell[i]>pNew->minLocal ){
59660
+ ptrmapPutOvflPtr(pNew, pCell, &rc);
59661
+ }
59662
+ }
59663
+ }
59664
+ }
59665
+
59666
+ /* Insert new divider cells into pParent. */
59667
+ for(i=0; i<nNew-1; i++){
59668
+ u8 *pCell;
59669
+ u8 *pTemp;
59670
+ int sz;
5884159671
MemPage *pNew = apNew[i];
58842
- assert( j<nMaxCells );
58843
- zeroPage(pNew, pageFlags);
58844
- assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]);
58845
- assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) );
58846
- assert( pNew->nOverflow==0 );
58847
-
5884859672
j = cntNew[i];
5884959673
58850
- /* If the sibling page assembled above was not the right-most sibling,
58851
- ** insert a divider cell into the parent page.
58852
- */
58853
- assert( i<nNew-1 || j==nCell );
58854
- if( j<nCell ){
58855
- u8 *pCell;
58856
- u8 *pTemp;
58857
- int sz;
58858
-
58859
- assert( j<nMaxCells );
58860
- pCell = apCell[j];
58861
- sz = szCell[j] + leafCorrection;
58862
- pTemp = &aOvflSpace[iOvflSpace];
58863
- if( !pNew->leaf ){
58864
- memcpy(&pNew->aData[8], pCell, 4);
58865
- }else if( leafData ){
58866
- /* If the tree is a leaf-data tree, and the siblings are leaves,
58867
- ** then there is no divider cell in apCell[]. Instead, the divider
58868
- ** cell consists of the integer key for the right-most cell of
58869
- ** the sibling-page assembled above only.
58870
- */
58871
- CellInfo info;
58872
- j--;
58873
- btreeParseCellPtr(pNew, apCell[j], &info);
58874
- pCell = pTemp;
58875
- sz = 4 + putVarint(&pCell[4], info.nKey);
58876
- pTemp = 0;
58877
- }else{
58878
- pCell -= 4;
58879
- /* Obscure case for non-leaf-data trees: If the cell at pCell was
58880
- ** previously stored on a leaf node, and its reported size was 4
58881
- ** bytes, then it may actually be smaller than this
58882
- ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
58883
- ** any cell). But it is important to pass the correct size to
58884
- ** insertCell(), so reparse the cell now.
58885
- **
58886
- ** Note that this can never happen in an SQLite data file, as all
58887
- ** cells are at least 4 bytes. It only happens in b-trees used
58888
- ** to evaluate "IN (SELECT ...)" and similar clauses.
58889
- */
58890
- if( szCell[j]==4 ){
58891
- assert(leafCorrection==4);
58892
- sz = cellSizePtr(pParent, pCell);
58893
- }
58894
- }
58895
- iOvflSpace += sz;
58896
- assert( sz<=pBt->maxLocal+23 );
58897
- assert( iOvflSpace <= (int)pBt->pageSize );
58898
- insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
58899
- if( rc!=SQLITE_OK ) goto balance_cleanup;
58900
- assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58901
-
58902
- j++;
58903
- nxDiv++;
58904
- }
58905
- }
58906
- assert( j==nCell );
59674
+ assert( j<nMaxCells );
59675
+ pCell = apCell[j];
59676
+ sz = szCell[j] + leafCorrection;
59677
+ pTemp = &aOvflSpace[iOvflSpace];
59678
+ if( !pNew->leaf ){
59679
+ memcpy(&pNew->aData[8], pCell, 4);
59680
+ }else if( leafData ){
59681
+ /* If the tree is a leaf-data tree, and the siblings are leaves,
59682
+ ** then there is no divider cell in apCell[]. Instead, the divider
59683
+ ** cell consists of the integer key for the right-most cell of
59684
+ ** the sibling-page assembled above only.
59685
+ */
59686
+ CellInfo info;
59687
+ j--;
59688
+ btreeParseCellPtr(pNew, apCell[j], &info);
59689
+ pCell = pTemp;
59690
+ sz = 4 + putVarint(&pCell[4], info.nKey);
59691
+ pTemp = 0;
59692
+ }else{
59693
+ pCell -= 4;
59694
+ /* Obscure case for non-leaf-data trees: If the cell at pCell was
59695
+ ** previously stored on a leaf node, and its reported size was 4
59696
+ ** bytes, then it may actually be smaller than this
59697
+ ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
59698
+ ** any cell). But it is important to pass the correct size to
59699
+ ** insertCell(), so reparse the cell now.
59700
+ **
59701
+ ** Note that this can never happen in an SQLite data file, as all
59702
+ ** cells are at least 4 bytes. It only happens in b-trees used
59703
+ ** to evaluate "IN (SELECT ...)" and similar clauses.
59704
+ */
59705
+ if( szCell[j]==4 ){
59706
+ assert(leafCorrection==4);
59707
+ sz = cellSizePtr(pParent, pCell);
59708
+ }
59709
+ }
59710
+ iOvflSpace += sz;
59711
+ assert( sz<=pBt->maxLocal+23 );
59712
+ assert( iOvflSpace <= (int)pBt->pageSize );
59713
+ insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
59714
+ if( rc!=SQLITE_OK ) goto balance_cleanup;
59715
+ assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59716
+ }
59717
+
59718
+ /* Now update the actual sibling pages. The order in which they are updated
59719
+ ** is important, as this code needs to avoid disrupting any page from which
59720
+ ** cells may still to be read. In practice, this means:
59721
+ **
59722
+ ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
59723
+ ** then it is not safe to update page apNew[iPg] until after
59724
+ ** the left-hand sibling apNew[iPg-1] has been updated.
59725
+ **
59726
+ ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
59727
+ ** then it is not safe to update page apNew[iPg] until after
59728
+ ** the right-hand sibling apNew[iPg+1] has been updated.
59729
+ **
59730
+ ** If neither of the above apply, the page is safe to update.
59731
+ **
59732
+ ** The iPg value in the following loop starts at nNew-1 goes down
59733
+ ** to 0, then back up to nNew-1 again, thus making two passes over
59734
+ ** the pages. On the initial downward pass, only condition (1) above
59735
+ ** needs to be tested because (2) will always be true from the previous
59736
+ ** step. On the upward pass, both conditions are always true, so the
59737
+ ** upwards pass simply processes pages that were missed on the downward
59738
+ ** pass.
59739
+ */
59740
+ for(i=1-nNew; i<nNew; i++){
59741
+ int iPg = i<0 ? -i : i;
59742
+ assert( iPg>=0 && iPg<nNew );
59743
+ if( abDone[iPg] ) continue; /* Skip pages already processed */
59744
+ if( i>=0 /* On the upwards pass, or... */
59745
+ || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */
59746
+ ){
59747
+ int iNew;
59748
+ int iOld;
59749
+ int nNewCell;
59750
+
59751
+ /* Verify condition (1): If cells are moving left, update iPg
59752
+ ** only after iPg-1 has already been updated. */
59753
+ assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
59754
+
59755
+ /* Verify condition (2): If cells are moving right, update iPg
59756
+ ** only after iPg+1 has already been updated. */
59757
+ assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] );
59758
+
59759
+ if( iPg==0 ){
59760
+ iNew = iOld = 0;
59761
+ nNewCell = cntNew[0];
59762
+ }else{
59763
+ iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell;
59764
+ iNew = cntNew[iPg-1] + !leafData;
59765
+ nNewCell = cntNew[iPg] - iNew;
59766
+ }
59767
+
59768
+ editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell);
59769
+ abDone[iPg]++;
59770
+ apNew[iPg]->nFree = usableSpace-szNew[iPg];
59771
+ assert( apNew[iPg]->nOverflow==0 );
59772
+ assert( apNew[iPg]->nCell==nNewCell );
59773
+ }
59774
+ }
59775
+
59776
+ /* All pages have been processed exactly once */
59777
+ assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
59778
+
5890759779
assert( nOld>0 );
5890859780
assert( nNew>0 );
58909
- if( (pageFlags & PTF_LEAF)==0 ){
58910
- u8 *zChild = &apCopy[nOld-1]->aData[8];
58911
- memcpy(&apNew[nNew-1]->aData[8], zChild, 4);
58912
- }
5891359781
5891459782
if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
5891559783
/* The root page of the b-tree now contains no cells. The only sibling
5891659784
** page is the right-child of the parent. Copy the contents of the
5891759785
** child page into the parent, decreasing the overall height of the
@@ -58920,130 +59788,54 @@
5892059788
**
5892159789
** If this is an auto-vacuum database, the call to copyNodeContent()
5892259790
** sets all pointer-map entries corresponding to database image pages
5892359791
** for which the pointer is stored within the content being copied.
5892459792
**
58925
- ** The second assert below verifies that the child page is defragmented
58926
- ** (it must be, as it was just reconstructed using assemblePage()). This
58927
- ** is important if the parent page happens to be page 1 of the database
58928
- ** image. */
59793
+ ** It is critical that the child page be defragmented before being
59794
+ ** copied into the parent, because if the parent is page 1 then it will
59795
+ ** by smaller than the child due to the database header, and so all the
59796
+ ** free space needs to be up front.
59797
+ */
5892959798
assert( nNew==1 );
59799
+ rc = defragmentPage(apNew[0]);
59800
+ testcase( rc!=SQLITE_OK );
5893059801
assert( apNew[0]->nFree ==
58931
- (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
59802
+ (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
59803
+ || rc!=SQLITE_OK
5893259804
);
5893359805
copyNodeContent(apNew[0], pParent, &rc);
5893459806
freePage(apNew[0], &rc);
58935
- }else if( ISAUTOVACUUM ){
58936
- /* Fix the pointer-map entries for all the cells that were shifted around.
58937
- ** There are several different types of pointer-map entries that need to
58938
- ** be dealt with by this routine. Some of these have been set already, but
58939
- ** many have not. The following is a summary:
58940
- **
58941
- ** 1) The entries associated with new sibling pages that were not
58942
- ** siblings when this function was called. These have already
58943
- ** been set. We don't need to worry about old siblings that were
58944
- ** moved to the free-list - the freePage() code has taken care
58945
- ** of those.
58946
- **
58947
- ** 2) The pointer-map entries associated with the first overflow
58948
- ** page in any overflow chains used by new divider cells. These
58949
- ** have also already been taken care of by the insertCell() code.
58950
- **
58951
- ** 3) If the sibling pages are not leaves, then the child pages of
58952
- ** cells stored on the sibling pages may need to be updated.
58953
- **
58954
- ** 4) If the sibling pages are not internal intkey nodes, then any
58955
- ** overflow pages used by these cells may need to be updated
58956
- ** (internal intkey nodes never contain pointers to overflow pages).
58957
- **
58958
- ** 5) If the sibling pages are not leaves, then the pointer-map
58959
- ** entries for the right-child pages of each sibling may need
58960
- ** to be updated.
58961
- **
58962
- ** Cases 1 and 2 are dealt with above by other code. The next
58963
- ** block deals with cases 3 and 4 and the one after that, case 5. Since
58964
- ** setting a pointer map entry is a relatively expensive operation, this
58965
- ** code only sets pointer map entries for child or overflow pages that have
58966
- ** actually moved between pages. */
58967
- MemPage *pNew = apNew[0];
58968
- MemPage *pOld = apCopy[0];
58969
- int nOverflow = pOld->nOverflow;
58970
- int iNextOld = pOld->nCell + nOverflow;
58971
- int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1);
58972
- j = 0; /* Current 'old' sibling page */
58973
- k = 0; /* Current 'new' sibling page */
58974
- for(i=0; i<nCell; i++){
58975
- int isDivider = 0;
58976
- while( i==iNextOld ){
58977
- /* Cell i is the cell immediately following the last cell on old
58978
- ** sibling page j. If the siblings are not leaf pages of an
58979
- ** intkey b-tree, then cell i was a divider cell. */
58980
- assert( j+1 < ArraySize(apCopy) );
58981
- assert( j+1 < nOld );
58982
- pOld = apCopy[++j];
58983
- iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
58984
- if( pOld->nOverflow ){
58985
- nOverflow = pOld->nOverflow;
58986
- iOverflow = i + !leafData + pOld->aiOvfl[0];
58987
- }
58988
- isDivider = !leafData;
58989
- }
58990
-
58991
- assert(nOverflow>0 || iOverflow<i );
58992
- assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1);
58993
- assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1);
58994
- if( i==iOverflow ){
58995
- isDivider = 1;
58996
- if( (--nOverflow)>0 ){
58997
- iOverflow++;
58998
- }
58999
- }
59000
-
59001
- if( i==cntNew[k] ){
59002
- /* Cell i is the cell immediately following the last cell on new
59003
- ** sibling page k. If the siblings are not leaf pages of an
59004
- ** intkey b-tree, then cell i is a divider cell. */
59005
- pNew = apNew[++k];
59006
- if( !leafData ) continue;
59007
- }
59008
- assert( j<nOld );
59009
- assert( k<nNew );
59010
-
59011
- /* If the cell was originally divider cell (and is not now) or
59012
- ** an overflow cell, or if the cell was located on a different sibling
59013
- ** page before the balancing, then the pointer map entries associated
59014
- ** with any child or overflow pages need to be updated. */
59015
- if( isDivider || pOld->pgno!=pNew->pgno ){
59016
- if( !leafCorrection ){
59017
- ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
59018
- }
59019
- if( szCell[i]>pNew->minLocal ){
59020
- ptrmapPutOvflPtr(pNew, apCell[i], &rc);
59021
- }
59022
- }
59023
- }
59024
-
59025
- if( !leafCorrection ){
59026
- for(i=0; i<nNew; i++){
59027
- u32 key = get4byte(&apNew[i]->aData[8]);
59028
- ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59029
- }
59030
- }
59807
+ }else if( ISAUTOVACUUM && !leafCorrection ){
59808
+ /* Fix the pointer map entries associated with the right-child of each
59809
+ ** sibling page. All other pointer map entries have already been taken
59810
+ ** care of. */
59811
+ for(i=0; i<nNew; i++){
59812
+ u32 key = get4byte(&apNew[i]->aData[8]);
59813
+ ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59814
+ }
59815
+ }
59816
+
59817
+ assert( pParent->isInit );
59818
+ TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59819
+ nOld, nNew, nCell));
59820
+
59821
+ /* Free any old pages that were not reused as new pages.
59822
+ */
59823
+ for(i=nNew; i<nOld; i++){
59824
+ freePage(apOld[i], &rc);
59825
+ }
5903159826
5903259827
#if 0
59828
+ if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
5903359829
/* The ptrmapCheckPages() contains assert() statements that verify that
5903459830
** all pointer map pages are set correctly. This is helpful while
5903559831
** debugging. This is usually disabled because a corrupt database may
5903659832
** cause an assert() statement to fail. */
5903759833
ptrmapCheckPages(apNew, nNew);
5903859834
ptrmapCheckPages(&pParent, 1);
59835
+ }
5903959836
#endif
59040
- }
59041
-
59042
- assert( pParent->isInit );
59043
- TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59044
- nOld, nNew, nCell));
5904559837
5904659838
/*
5904759839
** Cleanup before returning.
5904859840
*/
5904959841
balance_cleanup:
@@ -60424,12 +61216,18 @@
6042461216
}else{
6042561217
int contentOffset = get2byteNotZero(&data[hdr+5]);
6042661218
assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
6042761219
memset(hit+contentOffset, 0, usableSize-contentOffset);
6042861220
memset(hit, 1, contentOffset);
61221
+ /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61222
+ ** number of cells on the page. */
6042961223
nCell = get2byte(&data[hdr+3]);
61224
+ /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61225
+ ** immediately follows the b-tree page header. */
6043061226
cellStart = hdr + 12 - 4*pPage->leaf;
61227
+ /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61228
+ ** integer offsets to the cell contents. */
6043161229
for(i=0; i<nCell; i++){
6043261230
int pc = get2byte(&data[cellStart+i*2]);
6043361231
u32 size = 65536;
6043461232
int j;
6043561233
if( pc<=usableSize-4 ){
@@ -60441,18 +61239,27 @@
6044161239
"Corruption detected in cell %d on page %d",i,iPage);
6044261240
}else{
6044361241
for(j=pc+size-1; j>=pc; j--) hit[j]++;
6044461242
}
6044561243
}
61244
+ /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61245
+ ** is the offset of the first freeblock, or zero if there are no
61246
+ ** freeblocks on the page. */
6044661247
i = get2byte(&data[hdr+1]);
6044761248
while( i>0 ){
6044861249
int size, j;
6044961250
assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
6045061251
size = get2byte(&data[i+2]);
6045161252
assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
6045261253
for(j=i+size-1; j>=i; j--) hit[j]++;
61254
+ /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61255
+ ** big-endian integer which is the offset in the b-tree page of the next
61256
+ ** freeblock in the chain, or zero if the freeblock is the last on the
61257
+ ** chain. */
6045361258
j = get2byte(&data[i]);
61259
+ /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
61260
+ ** increasing offset. */
6045461261
assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
6045561262
assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
6045661263
i = j;
6045761264
}
6045861265
for(i=cnt=0; i<usableSize; i++){
@@ -60462,10 +61269,15 @@
6046261269
checkAppendMsg(pCheck,
6046361270
"Multiple uses for byte %d of page %d", i, iPage);
6046461271
break;
6046561272
}
6046661273
}
61274
+ /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61275
+ ** is stored in the fifth field of the b-tree page header.
61276
+ ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61277
+ ** number of fragmented free bytes within the cell content area.
61278
+ */
6046761279
if( cnt!=data[hdr+7] ){
6046861280
checkAppendMsg(pCheck,
6046961281
"Fragmentation of %d bytes reported as %d on page %d",
6047061282
cnt, data[hdr+7], iPage);
6047161283
}
@@ -60865,10 +61677,15 @@
6086561677
*/
6086661678
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
6086761679
return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
6086861680
}
6086961681
61682
+/*
61683
+** Return the size of the header added to each page by this module.
61684
+*/
61685
+SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61686
+
6087061687
/************** End of btree.c ***********************************************/
6087161688
/************** Begin file backup.c ******************************************/
6087261689
/*
6087361690
** 2009 January 28
6087461691
**
@@ -60988,10 +61805,24 @@
6098861805
static int setDestPgsz(sqlite3_backup *p){
6098961806
int rc;
6099061807
rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
6099161808
return rc;
6099261809
}
61810
+
61811
+/*
61812
+** Check that there is no open read-transaction on the b-tree passed as the
61813
+** second argument. If there is not, return SQLITE_OK. Otherwise, if there
61814
+** is an open read-transaction, return SQLITE_ERROR and leave an error
61815
+** message in database handle db.
61816
+*/
61817
+static int checkReadTransaction(sqlite3 *db, Btree *p){
61818
+ if( sqlite3BtreeIsInReadTrans(p) ){
61819
+ sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
61820
+ return SQLITE_ERROR;
61821
+ }
61822
+ return SQLITE_OK;
61823
+}
6099361824
6099461825
/*
6099561826
** Create an sqlite3_backup process to copy the contents of zSrcDb from
6099661827
** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
6099761828
** a pointer to the new sqlite3_backup object.
@@ -61004,10 +61835,17 @@
6100461835
const char *zDestDb, /* Name of database within pDestDb */
6100561836
sqlite3* pSrcDb, /* Database connection to read from */
6100661837
const char *zSrcDb /* Name of database within pSrcDb */
6100761838
){
6100861839
sqlite3_backup *p; /* Value to return */
61840
+
61841
+#ifdef SQLITE_ENABLE_API_ARMOR
61842
+ if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){
61843
+ (void)SQLITE_MISUSE_BKPT;
61844
+ return 0;
61845
+ }
61846
+#endif
6100961847
6101061848
/* Lock the source database handle. The destination database
6101161849
** handle is not locked in this routine, but it is locked in
6101261850
** sqlite3_backup_step(). The user is required to ensure that no
6101361851
** other thread accesses the destination handle for the duration
@@ -61041,16 +61879,19 @@
6104161879
p->pDestDb = pDestDb;
6104261880
p->pSrcDb = pSrcDb;
6104361881
p->iNext = 1;
6104461882
p->isAttached = 0;
6104561883
61046
- if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){
61884
+ if( 0==p->pSrc || 0==p->pDest
61885
+ || setDestPgsz(p)==SQLITE_NOMEM
61886
+ || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
61887
+ ){
6104761888
/* One (or both) of the named databases did not exist or an OOM
61048
- ** error was hit. The error has already been written into the
61049
- ** pDestDb handle. All that is left to do here is free the
61050
- ** sqlite3_backup structure.
61051
- */
61889
+ ** error was hit. Or there is a transaction open on the destination
61890
+ ** database. The error has already been written into the pDestDb
61891
+ ** handle. All that is left to do here is free the sqlite3_backup
61892
+ ** structure. */
6105261893
sqlite3_free(p);
6105361894
p = 0;
6105461895
}
6105561896
}
6105661897
if( p ){
@@ -61201,10 +62042,13 @@
6120162042
int rc;
6120262043
int destMode; /* Destination journal mode */
6120362044
int pgszSrc = 0; /* Source page size */
6120462045
int pgszDest = 0; /* Destination page size */
6120562046
62047
+#ifdef SQLITE_ENABLE_API_ARMOR
62048
+ if( p==0 ) return SQLITE_MISUSE_BKPT;
62049
+#endif
6120662050
sqlite3_mutex_enter(p->pSrcDb->mutex);
6120762051
sqlite3BtreeEnter(p->pSrc);
6120862052
if( p->pDestDb ){
6120962053
sqlite3_mutex_enter(p->pDestDb->mutex);
6121062054
}
@@ -61464,11 +62308,11 @@
6146462308
}
6146562309
*pp = p->pNext;
6146662310
}
6146762311
6146862312
/* If a transaction is still open on the Btree, roll it back. */
61469
- sqlite3BtreeRollback(p->pDest, SQLITE_OK);
62313
+ sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
6147062314
6147162315
/* Set the error code of the destination database handle. */
6147262316
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
6147362317
if( p->pDestDb ){
6147462318
sqlite3Error(p->pDestDb, rc);
@@ -61490,18 +62334,30 @@
6149062334
/*
6149162335
** Return the number of pages still to be backed up as of the most recent
6149262336
** call to sqlite3_backup_step().
6149362337
*/
6149462338
SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
62339
+#ifdef SQLITE_ENABLE_API_ARMOR
62340
+ if( p==0 ){
62341
+ (void)SQLITE_MISUSE_BKPT;
62342
+ return 0;
62343
+ }
62344
+#endif
6149562345
return p->nRemaining;
6149662346
}
6149762347
6149862348
/*
6149962349
** Return the total number of pages in the source database as of the most
6150062350
** recent call to sqlite3_backup_step().
6150162351
*/
6150262352
SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
62353
+#ifdef SQLITE_ENABLE_API_ARMOR
62354
+ if( p==0 ){
62355
+ (void)SQLITE_MISUSE_BKPT;
62356
+ return 0;
62357
+ }
62358
+#endif
6150362359
return p->nPagecount;
6150462360
}
6150562361
6150662362
/*
6150762363
** This function is called after the contents of page iPage of the
@@ -63788,10 +64644,38 @@
6378864644
}
6378964645
p->nOp += nOp;
6379064646
}
6379164647
return addr;
6379264648
}
64649
+
64650
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
64651
+/*
64652
+** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
64653
+*/
64654
+SQLITE_PRIVATE void sqlite3VdbeScanStatus(
64655
+ Vdbe *p, /* VM to add scanstatus() to */
64656
+ int addrExplain, /* Address of OP_Explain (or 0) */
64657
+ int addrLoop, /* Address of loop counter */
64658
+ int addrVisit, /* Address of rows visited counter */
64659
+ LogEst nEst, /* Estimated number of output rows */
64660
+ const char *zName /* Name of table or index being scanned */
64661
+){
64662
+ int nByte = (p->nScan+1) * sizeof(ScanStatus);
64663
+ ScanStatus *aNew;
64664
+ aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
64665
+ if( aNew ){
64666
+ ScanStatus *pNew = &aNew[p->nScan++];
64667
+ pNew->addrExplain = addrExplain;
64668
+ pNew->addrLoop = addrLoop;
64669
+ pNew->addrVisit = addrVisit;
64670
+ pNew->nEst = nEst;
64671
+ pNew->zName = sqlite3DbStrDup(p->db, zName);
64672
+ p->aScan = aNew;
64673
+ }
64674
+}
64675
+#endif
64676
+
6379364677
6379464678
/*
6379564679
** Change the value of the P1 operand for a specific instruction.
6379664680
** This routine is useful when a large program is loaded from a
6379764681
** static array using sqlite3VdbeAddOpList but we want to make a
@@ -64887,10 +65771,13 @@
6488765771
p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
6488865772
p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
6488965773
p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
6489065774
&zCsr, zEnd, &nByte);
6489165775
p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
65776
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65777
+ p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte);
65778
+#endif
6489265779
if( nByte ){
6489365780
p->pFree = sqlite3DbMallocZero(db, nByte);
6489465781
}
6489565782
zCsr = p->pFree;
6489665783
zEnd = &zCsr[nByte];
@@ -64903,11 +65790,11 @@
6490365790
for(n=0; n<nVar; n++){
6490465791
p->aVar[n].flags = MEM_Null;
6490565792
p->aVar[n].db = db;
6490665793
}
6490765794
}
64908
- if( p->azVar ){
65795
+ if( p->azVar && pParse->nzVar>0 ){
6490965796
p->nzVar = pParse->nzVar;
6491065797
memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
6491165798
memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
6491265799
}
6491365800
if( p->aMem ){
@@ -64954,10 +65841,13 @@
6495465841
** is used, for example, when a trigger sub-program is halted to restore
6495565842
** control to the main program.
6495665843
*/
6495765844
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
6495865845
Vdbe *v = pFrame->v;
65846
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65847
+ v->anExec = pFrame->anExec;
65848
+#endif
6495965849
v->aOnceFlag = pFrame->aOnceFlag;
6496065850
v->nOnceFlag = pFrame->nOnceFlag;
6496165851
v->aOp = pFrame->aOp;
6496265852
v->nOp = pFrame->nOp;
6496365853
v->aMem = pFrame->aMem;
@@ -64964,10 +65854,11 @@
6496465854
v->nMem = pFrame->nMem;
6496565855
v->apCsr = pFrame->apCsr;
6496665856
v->nCursor = pFrame->nCursor;
6496765857
v->db->lastRowid = pFrame->lastRowid;
6496865858
v->nChange = pFrame->nChange;
65859
+ v->db->nChange = pFrame->nDbChange;
6496965860
return pFrame->pc;
6497065861
}
6497165862
6497265863
/*
6497365864
** Close all cursors.
@@ -65531,10 +66422,11 @@
6553166422
** so, abort any other statements this handle currently has active.
6553266423
*/
6553366424
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6553466425
sqlite3CloseSavepoints(db);
6553566426
db->autoCommit = 1;
66427
+ p->nChange = 0;
6553666428
}
6553766429
}
6553866430
}
6553966431
6554066432
/* Check for immediate foreign key violations. */
@@ -65571,18 +66463,20 @@
6557166463
sqlite3VdbeLeave(p);
6557266464
return SQLITE_BUSY;
6557366465
}else if( rc!=SQLITE_OK ){
6557466466
p->rc = rc;
6557566467
sqlite3RollbackAll(db, SQLITE_OK);
66468
+ p->nChange = 0;
6557666469
}else{
6557766470
db->nDeferredCons = 0;
6557866471
db->nDeferredImmCons = 0;
6557966472
db->flags &= ~SQLITE_DeferFKs;
6558066473
sqlite3CommitInternalChanges(db);
6558166474
}
6558266475
}else{
6558366476
sqlite3RollbackAll(db, SQLITE_OK);
66477
+ p->nChange = 0;
6558466478
}
6558566479
db->nStatement = 0;
6558666480
}else if( eStatementOp==0 ){
6558766481
if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
6558866482
eStatementOp = SAVEPOINT_RELEASE;
@@ -65590,10 +66484,11 @@
6559066484
eStatementOp = SAVEPOINT_ROLLBACK;
6559166485
}else{
6559266486
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6559366487
sqlite3CloseSavepoints(db);
6559466488
db->autoCommit = 1;
66489
+ p->nChange = 0;
6559566490
}
6559666491
}
6559766492
6559866493
/* If eStatementOp is non-zero, then a statement transaction needs to
6559966494
** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -65610,10 +66505,11 @@
6561066505
p->zErrMsg = 0;
6561166506
}
6561266507
sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
6561366508
sqlite3CloseSavepoints(db);
6561466509
db->autoCommit = 1;
66510
+ p->nChange = 0;
6561566511
}
6561666512
}
6561766513
6561866514
/* If this was an INSERT, UPDATE or DELETE and no statement transaction
6561966515
** has been rolled back, update the database connection change-counter.
@@ -65871,10 +66767,16 @@
6587166767
for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
6587266768
vdbeFreeOpArray(db, p->aOp, p->nOp);
6587366769
sqlite3DbFree(db, p->aColName);
6587466770
sqlite3DbFree(db, p->zSql);
6587566771
sqlite3DbFree(db, p->pFree);
66772
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66773
+ for(i=0; i<p->nScan; i++){
66774
+ sqlite3DbFree(db, p->aScan[i].zName);
66775
+ }
66776
+ sqlite3DbFree(db, p->aScan);
66777
+#endif
6587666778
}
6587766779
6587866780
/*
6587966781
** Delete an entire VDBE.
6588066782
*/
@@ -66029,13 +66931,11 @@
6602966931
/* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
6603066932
# define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
6603166933
i64 i = pMem->u.i;
6603266934
u64 u;
6603366935
if( i<0 ){
66034
- if( i<(-MAX_6BYTE) ) return 6;
66035
- /* Previous test prevents: u = -(-9223372036854775808) */
66036
- u = -i;
66936
+ u = ~i;
6603766937
}else{
6603866938
u = i;
6603966939
}
6604066940
if( u<=127 ){
6604166941
return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
@@ -66197,14 +67097,18 @@
6619767097
){
6619867098
u64 x = FOUR_BYTE_UINT(buf);
6619967099
u32 y = FOUR_BYTE_UINT(buf+4);
6620067100
x = (x<<32) + y;
6620167101
if( serial_type==6 ){
67102
+ /* EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit
67103
+ ** twos-complement integer. */
6620267104
pMem->u.i = *(i64*)&x;
6620367105
pMem->flags = MEM_Int;
6620467106
testcase( pMem->u.i<0 );
6620567107
}else{
67108
+ /* EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit
67109
+ ** floating point number. */
6620667110
#if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
6620767111
/* Verify that integers and floating point values use the same
6620867112
** byte order. Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
6620967113
** defined that 64-bit floating point values really are mixed
6621067114
** endian.
@@ -66228,39 +67132,50 @@
6622867132
Mem *pMem /* Memory cell to write value into */
6622967133
){
6623067134
switch( serial_type ){
6623167135
case 10: /* Reserved for future use */
6623267136
case 11: /* Reserved for future use */
66233
- case 0: { /* NULL */
67137
+ case 0: { /* Null */
67138
+ /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
6623467139
pMem->flags = MEM_Null;
6623567140
break;
6623667141
}
66237
- case 1: { /* 1-byte signed integer */
67142
+ case 1: {
67143
+ /* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
67144
+ ** integer. */
6623867145
pMem->u.i = ONE_BYTE_INT(buf);
6623967146
pMem->flags = MEM_Int;
6624067147
testcase( pMem->u.i<0 );
6624167148
return 1;
6624267149
}
6624367150
case 2: { /* 2-byte signed integer */
67151
+ /* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
67152
+ ** twos-complement integer. */
6624467153
pMem->u.i = TWO_BYTE_INT(buf);
6624567154
pMem->flags = MEM_Int;
6624667155
testcase( pMem->u.i<0 );
6624767156
return 2;
6624867157
}
6624967158
case 3: { /* 3-byte signed integer */
67159
+ /* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
67160
+ ** twos-complement integer. */
6625067161
pMem->u.i = THREE_BYTE_INT(buf);
6625167162
pMem->flags = MEM_Int;
6625267163
testcase( pMem->u.i<0 );
6625367164
return 3;
6625467165
}
6625567166
case 4: { /* 4-byte signed integer */
67167
+ /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
67168
+ ** twos-complement integer. */
6625667169
pMem->u.i = FOUR_BYTE_INT(buf);
6625767170
pMem->flags = MEM_Int;
6625867171
testcase( pMem->u.i<0 );
6625967172
return 4;
6626067173
}
6626167174
case 5: { /* 6-byte signed integer */
67175
+ /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
67176
+ ** twos-complement integer. */
6626267177
pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
6626367178
pMem->flags = MEM_Int;
6626467179
testcase( pMem->u.i<0 );
6626567180
return 6;
6626667181
}
@@ -66270,15 +67185,21 @@
6627067185
** to avoid having to move the frame pointer in the common case */
6627167186
return serialGet(buf,serial_type,pMem);
6627267187
}
6627367188
case 8: /* Integer 0 */
6627467189
case 9: { /* Integer 1 */
67190
+ /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
67191
+ /* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */
6627567192
pMem->u.i = serial_type-8;
6627667193
pMem->flags = MEM_Int;
6627767194
return 0;
6627867195
}
6627967196
default: {
67197
+ /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
67198
+ ** length.
67199
+ ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
67200
+ ** (N-13)/2 bytes in length. */
6628067201
static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
6628167202
pMem->z = (char *)buf;
6628267203
pMem->n = (serial_type-12)/2;
6628367204
pMem->flags = aFlag[serial_type&1];
6628467205
return pMem->n;
@@ -68238,15 +69159,23 @@
6823869159
sqlite3_stmt *pStmt,
6823969160
int N,
6824069161
const void *(*xFunc)(Mem*),
6824169162
int useType
6824269163
){
68243
- const void *ret = 0;
68244
- Vdbe *p = (Vdbe *)pStmt;
69164
+ const void *ret;
69165
+ Vdbe *p;
6824569166
int n;
68246
- sqlite3 *db = p->db;
68247
-
69167
+ sqlite3 *db;
69168
+#ifdef SQLITE_ENABLE_API_ARMOR
69169
+ if( pStmt==0 ){
69170
+ (void)SQLITE_MISUSE_BKPT;
69171
+ return 0;
69172
+ }
69173
+#endif
69174
+ ret = 0;
69175
+ p = (Vdbe *)pStmt;
69176
+ db = p->db;
6824869177
assert( db!=0 );
6824969178
n = sqlite3_column_count(pStmt);
6825069179
if( N<n && N>=0 ){
6825169180
N += useType*n;
6825269181
sqlite3_mutex_enter(db->mutex);
@@ -68707,10 +69636,16 @@
6870769636
** prepared statement for the database connection. Return NULL if there
6870869637
** are no more.
6870969638
*/
6871069639
SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
6871169640
sqlite3_stmt *pNext;
69641
+#ifdef SQLITE_ENABLE_API_ARMOR
69642
+ if( !sqlite3SafetyCheckOk(pDb) ){
69643
+ (void)SQLITE_MISUSE_BKPT;
69644
+ return 0;
69645
+ }
69646
+#endif
6871269647
sqlite3_mutex_enter(pDb->mutex);
6871369648
if( pStmt==0 ){
6871469649
pNext = (sqlite3_stmt*)pDb->pVdbe;
6871569650
}else{
6871669651
pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -68722,15 +69657,91 @@
6872269657
/*
6872369658
** Return the value of a status counter for a prepared statement
6872469659
*/
6872569660
SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
6872669661
Vdbe *pVdbe = (Vdbe*)pStmt;
68727
- u32 v = pVdbe->aCounter[op];
69662
+ u32 v;
69663
+#ifdef SQLITE_ENABLE_API_ARMOR
69664
+ if( !pStmt ){
69665
+ (void)SQLITE_MISUSE_BKPT;
69666
+ return 0;
69667
+ }
69668
+#endif
69669
+ v = pVdbe->aCounter[op];
6872869670
if( resetFlag ) pVdbe->aCounter[op] = 0;
6872969671
return (int)v;
6873069672
}
6873169673
69674
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
69675
+/*
69676
+** Return status data for a single loop within query pStmt.
69677
+*/
69678
+SQLITE_API int sqlite3_stmt_scanstatus(
69679
+ sqlite3_stmt *pStmt, /* Prepared statement being queried */
69680
+ int idx, /* Index of loop to report on */
69681
+ int iScanStatusOp, /* Which metric to return */
69682
+ void *pOut /* OUT: Write the answer here */
69683
+){
69684
+ Vdbe *p = (Vdbe*)pStmt;
69685
+ ScanStatus *pScan;
69686
+ if( idx<0 || idx>=p->nScan ) return 1;
69687
+ pScan = &p->aScan[idx];
69688
+ switch( iScanStatusOp ){
69689
+ case SQLITE_SCANSTAT_NLOOP: {
69690
+ *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
69691
+ break;
69692
+ }
69693
+ case SQLITE_SCANSTAT_NVISIT: {
69694
+ *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
69695
+ break;
69696
+ }
69697
+ case SQLITE_SCANSTAT_EST: {
69698
+ double r = 1.0;
69699
+ LogEst x = pScan->nEst;
69700
+ while( x<100 ){
69701
+ x += 10;
69702
+ r *= 0.5;
69703
+ }
69704
+ *(double*)pOut = r*sqlite3LogEstToInt(x);
69705
+ break;
69706
+ }
69707
+ case SQLITE_SCANSTAT_NAME: {
69708
+ *(const char**)pOut = pScan->zName;
69709
+ break;
69710
+ }
69711
+ case SQLITE_SCANSTAT_EXPLAIN: {
69712
+ if( pScan->addrExplain ){
69713
+ *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z;
69714
+ }else{
69715
+ *(const char**)pOut = 0;
69716
+ }
69717
+ break;
69718
+ }
69719
+ case SQLITE_SCANSTAT_SELECTID: {
69720
+ if( pScan->addrExplain ){
69721
+ *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
69722
+ }else{
69723
+ *(int*)pOut = -1;
69724
+ }
69725
+ break;
69726
+ }
69727
+ default: {
69728
+ return 1;
69729
+ }
69730
+ }
69731
+ return 0;
69732
+}
69733
+
69734
+/*
69735
+** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
69736
+*/
69737
+SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
69738
+ Vdbe *p = (Vdbe*)pStmt;
69739
+ memset(p->anExec, 0, p->nOp * sizeof(i64));
69740
+}
69741
+#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
69742
+
6873269743
/************** End of vdbeapi.c *********************************************/
6873369744
/************** Begin file vdbetrace.c ***************************************/
6873469745
/*
6873569746
** 2009 November 25
6873669747
**
@@ -69612,10 +70623,13 @@
6961270623
#ifdef VDBE_PROFILE
6961370624
start = sqlite3Hwtime();
6961470625
#endif
6961570626
nVmStep++;
6961670627
pOp = &aOp[pc];
70628
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
70629
+ if( p->anExec ) p->anExec[pc]++;
70630
+#endif
6961770631
6961870632
/* Only allow tracing if SQLITE_DEBUG is defined.
6961970633
*/
6962070634
#ifdef SQLITE_DEBUG
6962170635
if( db->flags & SQLITE_VdbeTrace ){
@@ -71302,11 +72316,11 @@
7130272316
assert( pReg->flags & MEM_Blob );
7130372317
assert( memIsValid(pReg) );
7130472318
pC->payloadSize = pC->szRow = avail = pReg->n;
7130572319
pC->aRow = (u8*)pReg->z;
7130672320
}else{
71307
- MemSetTypeFlag(pDest, MEM_Null);
72321
+ sqlite3VdbeMemSetNull(pDest);
7130872322
goto op_column_out;
7130972323
}
7131072324
}else{
7131172325
assert( pCrsr );
7131272326
if( pC->isTable==0 ){
@@ -71637,11 +72651,14 @@
7163772651
testcase( serial_type==127 );
7163872652
testcase( serial_type==128 );
7163972653
nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
7164072654
}while( (--pRec)>=pData0 );
7164172655
71642
- /* Add the initial header varint and total the size */
72656
+ /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
72657
+ ** which determines the total number of bytes in the header. The varint
72658
+ ** value is the size of the header in bytes including the size varint
72659
+ ** itself. */
7164372660
testcase( nHdr==126 );
7164472661
testcase( nHdr==127 );
7164572662
if( nHdr<=126 ){
7164672663
/* The common case */
7164772664
nHdr += 1;
@@ -71671,11 +72688,15 @@
7167172688
j = nHdr;
7167272689
assert( pData0<=pLast );
7167372690
pRec = pData0;
7167472691
do{
7167572692
serial_type = pRec->uTemp;
72693
+ /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
72694
+ ** additional varints, one per column. */
7167672695
i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
72696
+ /* EVIDENCE-OF: R-64536-51728 The values for each column in the record
72697
+ ** immediately follow the header. */
7167772698
j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
7167872699
}while( (++pRec)<=pLast );
7167972700
assert( i==nHdr );
7168072701
assert( j==nByte );
7168172702
@@ -71826,23 +72847,30 @@
7182672847
goto vdbe_return;
7182772848
}
7182872849
db->isTransactionSavepoint = 0;
7182972850
rc = p->rc;
7183072851
}else{
72852
+ int isSchemaChange;
7183172853
iSavepoint = db->nSavepoint - iSavepoint - 1;
7183272854
if( p1==SAVEPOINT_ROLLBACK ){
72855
+ isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
7183372856
for(ii=0; ii<db->nDb; ii++){
71834
- sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
72857
+ rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
72858
+ SQLITE_ABORT_ROLLBACK,
72859
+ isSchemaChange==0);
72860
+ if( rc!=SQLITE_OK ) goto abort_due_to_error;
7183572861
}
72862
+ }else{
72863
+ isSchemaChange = 0;
7183672864
}
7183772865
for(ii=0; ii<db->nDb; ii++){
7183872866
rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
7183972867
if( rc!=SQLITE_OK ){
7184072868
goto abort_due_to_error;
7184172869
}
7184272870
}
71843
- if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
72871
+ if( isSchemaChange ){
7184472872
sqlite3ExpirePreparedStatements(db);
7184572873
sqlite3ResetAllSchemasOfConnection(db);
7184672874
db->flags = (db->flags | SQLITE_InternChanges);
7184772875
}
7184872876
}
@@ -72235,11 +73263,11 @@
7223573263
assert( p->bIsReader );
7223673264
assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
7223773265
|| p->readOnly==0 );
7223873266
7223973267
if( p->expired ){
72240
- rc = SQLITE_ABORT;
73268
+ rc = SQLITE_ABORT_ROLLBACK;
7224173269
break;
7224273270
}
7224373271
7224473272
nField = 0;
7224573273
pKeyInfo = 0;
@@ -72799,14 +73827,14 @@
7279973827
}
7280073828
pIdxKey = &r;
7280173829
}else{
7280273830
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7280373831
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
72804
- );
73832
+ );
7280573833
if( pIdxKey==0 ) goto no_mem;
7280673834
assert( pIn3->flags & MEM_Blob );
72807
- assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
73835
+ ExpandBlob(pIn3);
7280873836
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
7280973837
}
7281073838
pIdxKey->default_rc = 0;
7281173839
if( pOp->opcode==OP_NoConflict ){
7281273840
/* For the OP_NoConflict opcode, take the jump if any of the
@@ -73402,10 +74430,14 @@
7340274430
#endif /* SQLITE_OMIT_VIRTUALTABLE */
7340374431
}else{
7340474432
assert( pC->pCursor!=0 );
7340574433
rc = sqlite3VdbeCursorRestore(pC);
7340674434
if( rc ) goto abort_due_to_error;
74435
+ if( pC->nullRow ){
74436
+ pOut->flags = MEM_Null;
74437
+ break;
74438
+ }
7340774439
rc = sqlite3BtreeKeySize(pC->pCursor, &v);
7340874440
assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
7340974441
}
7341074442
pOut->u.i = v;
7341174443
break;
@@ -73492,13 +74524,13 @@
7349274524
}
7349374525
/* Opcode: Rewind P1 P2 * * *
7349474526
**
7349574527
** The next use of the Rowid or Column or Next instruction for P1
7349674528
** will refer to the first entry in the database table or index.
73497
-** If the table or index is empty and P2>0, then jump immediately to P2.
73498
-** If P2 is 0 or if the table or index is not empty, fall through
73499
-** to the following instruction.
74529
+** If the table or index is empty, jump immediately to P2.
74530
+** If the table or index is not empty, fall through to the following
74531
+** instruction.
7350074532
**
7350174533
** This opcode leaves the cursor configured to move in forward order,
7350274534
** from the beginning toward the end. In other words, the cursor is
7350374535
** configured to use Next, not Prev.
7350474536
*/
@@ -74410,10 +75442,13 @@
7441075442
pFrame->aOp = p->aOp;
7441175443
pFrame->nOp = p->nOp;
7441275444
pFrame->token = pProgram->token;
7441375445
pFrame->aOnceFlag = p->aOnceFlag;
7441475446
pFrame->nOnceFlag = p->nOnceFlag;
75447
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75448
+ pFrame->anExec = p->anExec;
75449
+#endif
7441575450
7441675451
pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
7441775452
for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
7441875453
pMem->flags = MEM_Undefined;
7441975454
pMem->db = db;
@@ -74427,10 +75462,11 @@
7442775462
7442875463
p->nFrame++;
7442975464
pFrame->pParent = p->pFrame;
7443075465
pFrame->lastRowid = lastRowid;
7443175466
pFrame->nChange = p->nChange;
75467
+ pFrame->nDbChange = p->db->nChange;
7443275468
p->nChange = 0;
7443375469
p->pFrame = pFrame;
7443475470
p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
7443575471
p->nMem = pFrame->nChildMem;
7443675472
p->nCursor = (u16)pFrame->nChildCsr;
@@ -74437,10 +75473,13 @@
7443775473
p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
7443875474
p->aOp = aOp = pProgram->aOp;
7443975475
p->nOp = pProgram->nOp;
7444075476
p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
7444175477
p->nOnceFlag = pProgram->nOnce;
75478
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75479
+ p->anExec = 0;
75480
+#endif
7444275481
pc = -1;
7444375482
memset(p->aOnceFlag, 0, p->nOnceFlag);
7444475483
7444575484
break;
7444675485
}
@@ -74681,12 +75720,12 @@
7468175720
7468275721
#ifndef SQLITE_OMIT_WAL
7468375722
/* Opcode: Checkpoint P1 P2 P3 * *
7468475723
**
7468575724
** Checkpoint database P1. This is a no-op if P1 is not currently in
74686
-** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL
74687
-** or RESTART. Write 1 or 0 into mem[P3] if the checkpoint returns
75725
+** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
75726
+** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
7468875727
** SQLITE_BUSY or not, respectively. Write the number of pages in the
7468975728
** WAL after the checkpoint into mem[P3+1] and the number of pages
7469075729
** in the WAL that have been checkpointed after the checkpoint
7469175730
** completes into mem[P3+2]. However on an error, mem[P3+1] and
7469275731
** mem[P3+2] are initialized to -1.
@@ -74700,10 +75739,11 @@
7470075739
aRes[0] = 0;
7470175740
aRes[1] = aRes[2] = -1;
7470275741
assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
7470375742
|| pOp->p2==SQLITE_CHECKPOINT_FULL
7470475743
|| pOp->p2==SQLITE_CHECKPOINT_RESTART
75744
+ || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
7470575745
);
7470675746
rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
7470775747
if( rc==SQLITE_BUSY ){
7470875748
rc = SQLITE_OK;
7470975749
aRes[0] = 1;
@@ -75625,10 +76665,15 @@
7562576665
char *zErr = 0;
7562676666
Table *pTab;
7562776667
Parse *pParse = 0;
7562876668
Incrblob *pBlob = 0;
7562976669
76670
+#ifdef SQLITE_ENABLE_API_ARMOR
76671
+ if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76672
+ return SQLITE_MISUSE_BKPT;
76673
+ }
76674
+#endif
7563076675
flags = !!flags; /* flags = (flags ? 1 : 0); */
7563176676
*ppBlob = 0;
7563276677
7563376678
sqlite3_mutex_enter(db->mutex);
7563476679
@@ -75843,11 +76888,10 @@
7584376888
v = (Vdbe*)p->pStmt;
7584476889
7584576890
if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
7584676891
/* Request is out of range. Return a transient error. */
7584776892
rc = SQLITE_ERROR;
75848
- sqlite3Error(db, SQLITE_ERROR);
7584976893
}else if( v==0 ){
7585076894
/* If there is no statement handle, then the blob-handle has
7585176895
** already been invalidated. Return SQLITE_ABORT in this case.
7585276896
*/
7585376897
rc = SQLITE_ABORT;
@@ -75861,14 +76905,14 @@
7586176905
sqlite3BtreeLeaveCursor(p->pCsr);
7586276906
if( rc==SQLITE_ABORT ){
7586376907
sqlite3VdbeFinalize(v);
7586476908
p->pStmt = 0;
7586576909
}else{
75866
- db->errCode = rc;
7586776910
v->rc = rc;
7586876911
}
7586976912
}
76913
+ sqlite3Error(db, rc);
7587076914
rc = sqlite3ApiExit(db, rc);
7587176915
sqlite3_mutex_leave(db->mutex);
7587276916
return rc;
7587376917
}
7587476918
@@ -76041,11 +77085,11 @@
7604177085
** itself.
7604277086
**
7604377087
** The sorter is running in multi-threaded mode if (a) the library was built
7604477088
** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
7604577089
** than zero, and (b) worker threads have been enabled at runtime by calling
76046
-** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...).
77090
+** "PRAGMA threads=N" with some value of N greater than 0.
7604777091
**
7604877092
** When Rewind() is called, any data remaining in memory is flushed to a
7604977093
** final PMA. So at this point the data is stored in some number of sorted
7605077094
** PMAs within temporary files on disk.
7605177095
**
@@ -76086,10 +77130,17 @@
7608677130
*/
7608777131
#if 0
7608877132
# define SQLITE_DEBUG_SORTER_THREADS 1
7608977133
#endif
7609077134
77135
+/*
77136
+** Hard-coded maximum amount of data to accumulate in memory before flushing
77137
+** to a level 0 PMA. The purpose of this limit is to prevent various integer
77138
+** overflows. 512MiB.
77139
+*/
77140
+#define SQLITE_MAX_MXPMASIZE (1<<29)
77141
+
7609177142
/*
7609277143
** Private objects used by the sorter
7609377144
*/
7609477145
typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
7609577146
typedef struct PmaReader PmaReader; /* Incrementally read one PMA */
@@ -76382,11 +77433,13 @@
7638277433
*/
7638377434
#define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
7638477435
7638577436
/* The minimum PMA size is set to this value multiplied by the database
7638677437
** page size in bytes. */
76387
-#define SORTER_MIN_WORKING 10
77438
+#ifndef SQLITE_SORTER_PMASZ
77439
+# define SQLITE_SORTER_PMASZ 10
77440
+#endif
7638877441
7638977442
/* Maximum number of PMAs that a single MergeEngine can merge */
7639077443
#define SORTER_MAX_MERGE_COUNT 16
7639177444
7639277445
static int vdbeIncrSwap(IncrMerger*);
@@ -76781,20 +77834,18 @@
7678177834
SortSubtask *pTask = &pSorter->aTask[i];
7678277835
pTask->pSorter = pSorter;
7678377836
}
7678477837
7678577838
if( !sqlite3TempInMemory(db) ){
76786
- pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
77839
+ pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
7678777840
mxCache = db->aDb[0].pSchema->cache_size;
76788
- if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
76789
- pSorter->mxPmaSize = mxCache * pgsz;
76790
-
76791
- /* If the application has not configure scratch memory using
76792
- ** SQLITE_CONFIG_SCRATCH then we assume it is OK to do large memory
76793
- ** allocations. If scratch memory has been configured, then assume
76794
- ** large memory allocations should be avoided to prevent heap
76795
- ** fragmentation.
77841
+ if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842
+ pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77843
+
77844
+ /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77845
+ ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77846
+ ** large heap allocations.
7679677847
*/
7679777848
if( sqlite3GlobalConfig.pScratch==0 ){
7679877849
assert( pSorter->iMemory==0 );
7679977850
pSorter->nMemory = pgsz;
7680077851
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79162,19 +80213,19 @@
7916280213
**
7916380214
** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
7916480215
** is a helper function - a callback for the tree walker.
7916580216
*/
7916680217
static int incrAggDepth(Walker *pWalker, Expr *pExpr){
79167
- if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
80218
+ if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
7916880219
return WRC_Continue;
7916980220
}
7917080221
static void incrAggFunctionDepth(Expr *pExpr, int N){
7917180222
if( N>0 ){
7917280223
Walker w;
7917380224
memset(&w, 0, sizeof(w));
7917480225
w.xExprCallback = incrAggDepth;
79175
- w.u.i = N;
80226
+ w.u.n = N;
7917680227
sqlite3WalkExpr(&w, pExpr);
7917780228
}
7917880229
}
7917980230
7918080231
/*
@@ -79454,10 +80505,14 @@
7945480505
}
7945580506
}
7945680507
if( pMatch ){
7945780508
pExpr->iTable = pMatch->iCursor;
7945880509
pExpr->pTab = pMatch->pTab;
80510
+ assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */
80511
+ if( (pMatch->jointype & JT_LEFT)!=0 ){
80512
+ ExprSetProperty(pExpr, EP_CanBeNull);
80513
+ }
7945980514
pSchema = pExpr->pTab->pSchema;
7946080515
}
7946180516
} /* if( pSrcList ) */
7946280517
7946380518
#ifndef SQLITE_OMIT_TRIGGER
@@ -79718,11 +80773,11 @@
7971880773
double r = -1.0;
7971980774
if( p->op!=TK_FLOAT ) return -1;
7972080775
sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
7972180776
assert( r>=0.0 );
7972280777
if( r>1.0 ) return -1;
79723
- return (int)(r*1000.0);
80778
+ return (int)(r*134217728.0);
7972480779
}
7972580780
7972680781
/*
7972780782
** This routine is callback for sqlite3WalkExpr().
7972880783
**
@@ -79850,11 +80905,11 @@
7985080905
** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
7985180906
** likelihood(X,0.9375).
7985280907
** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
7985380908
** likelihood(X,0.9375). */
7985480909
/* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
79855
- pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
80910
+ pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
7985680911
}
7985780912
}
7985880913
#ifndef SQLITE_OMIT_AUTHORIZATION
7985980914
auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
7986080915
if( auth!=SQLITE_OK ){
@@ -81807,69 +82862,79 @@
8180782862
sqlite3DbFree(db, pList->a);
8180882863
sqlite3DbFree(db, pList);
8180982864
}
8181082865
8181182866
/*
81812
-** These routines are Walker callbacks. Walker.u.pi is a pointer
81813
-** to an integer. These routines are checking an expression to see
81814
-** if it is a constant. Set *Walker.u.i to 0 if the expression is
81815
-** not constant.
82867
+** These routines are Walker callbacks used to check expressions to
82868
+** see if they are "constant" for some definition of constant. The
82869
+** Walker.eCode value determines the type of "constant" we are looking
82870
+** for.
8181682871
**
8181782872
** These callback routines are used to implement the following:
8181882873
**
81819
-** sqlite3ExprIsConstant() pWalker->u.i==1
81820
-** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81821
-** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
82874
+** sqlite3ExprIsConstant() pWalker->eCode==1
82875
+** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
82876
+** sqlite3ExprRefOneTableOnly() pWalker->eCode==3
82877
+** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
82878
+**
82879
+** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
82880
+** is found to not be a constant.
8182282881
**
8182382882
** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
81824
-** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81825
-** an existing schema and 3 when processing a new statement. A bound
82883
+** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
82884
+** an existing schema and 4 when processing a new statement. A bound
8182682885
** parameter raises an error for new statements, but is silently converted
8182782886
** to NULL for existing schemas. This allows sqlite_master tables that
8182882887
** contain a bound parameter because they were generated by older versions
8182982888
** of SQLite to be parsed by newer versions of SQLite without raising a
8183082889
** malformed schema error.
8183182890
*/
8183282891
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
8183382892
81834
- /* If pWalker->u.i is 2 then any term of the expression that comes from
81835
- ** the ON or USING clauses of a join disqualifies the expression
82893
+ /* If pWalker->eCode is 2 then any term of the expression that comes from
82894
+ ** the ON or USING clauses of a left join disqualifies the expression
8183682895
** from being considered constant. */
81837
- if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
81838
- pWalker->u.i = 0;
82896
+ if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
82897
+ pWalker->eCode = 0;
8183982898
return WRC_Abort;
8184082899
}
8184182900
8184282901
switch( pExpr->op ){
8184382902
/* Consider functions to be constant if all their arguments are constant
81844
- ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
81845
- ** flag. */
82903
+ ** and either pWalker->eCode==4 or 5 or the function has the
82904
+ ** SQLITE_FUNC_CONST flag. */
8184682905
case TK_FUNCTION:
81847
- if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
82906
+ if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
8184882907
return WRC_Continue;
82908
+ }else{
82909
+ pWalker->eCode = 0;
82910
+ return WRC_Abort;
8184982911
}
81850
- /* Fall through */
8185182912
case TK_ID:
8185282913
case TK_COLUMN:
8185382914
case TK_AGG_FUNCTION:
8185482915
case TK_AGG_COLUMN:
8185582916
testcase( pExpr->op==TK_ID );
8185682917
testcase( pExpr->op==TK_COLUMN );
8185782918
testcase( pExpr->op==TK_AGG_FUNCTION );
8185882919
testcase( pExpr->op==TK_AGG_COLUMN );
81859
- pWalker->u.i = 0;
81860
- return WRC_Abort;
82920
+ if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
82921
+ return WRC_Continue;
82922
+ }else{
82923
+ pWalker->eCode = 0;
82924
+ return WRC_Abort;
82925
+ }
8186182926
case TK_VARIABLE:
81862
- if( pWalker->u.i==4 ){
82927
+ if( pWalker->eCode==5 ){
8186382928
/* Silently convert bound parameters that appear inside of CREATE
8186482929
** statements into a NULL when parsing the CREATE statement text out
8186582930
** of the sqlite_master table */
8186682931
pExpr->op = TK_NULL;
81867
- }else if( pWalker->u.i==3 ){
82932
+ }else if( pWalker->eCode==4 ){
8186882933
/* A bound parameter in a CREATE statement that originates from
8186982934
** sqlite3_prepare() causes an error */
81870
- pWalker->u.i = 0;
82935
+ pWalker->eCode = 0;
8187182936
return WRC_Abort;
8187282937
}
8187382938
/* Fall through */
8187482939
default:
8187582940
testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -81877,57 +82942,68 @@
8187782942
return WRC_Continue;
8187882943
}
8187982944
}
8188082945
static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
8188182946
UNUSED_PARAMETER(NotUsed);
81882
- pWalker->u.i = 0;
82947
+ pWalker->eCode = 0;
8188382948
return WRC_Abort;
8188482949
}
81885
-static int exprIsConst(Expr *p, int initFlag){
82950
+static int exprIsConst(Expr *p, int initFlag, int iCur){
8188682951
Walker w;
8188782952
memset(&w, 0, sizeof(w));
81888
- w.u.i = initFlag;
82953
+ w.eCode = initFlag;
8188982954
w.xExprCallback = exprNodeIsConstant;
8189082955
w.xSelectCallback = selectNodeIsConstant;
82956
+ w.u.iCur = iCur;
8189182957
sqlite3WalkExpr(&w, p);
81892
- return w.u.i;
82958
+ return w.eCode;
8189382959
}
8189482960
8189582961
/*
81896
-** Walk an expression tree. Return 1 if the expression is constant
82962
+** Walk an expression tree. Return non-zero if the expression is constant
8189782963
** and 0 if it involves variables or function calls.
8189882964
**
8189982965
** For the purposes of this function, a double-quoted string (ex: "abc")
8190082966
** is considered a variable but a single-quoted string (ex: 'abc') is
8190182967
** a constant.
8190282968
*/
8190382969
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
81904
- return exprIsConst(p, 1);
82970
+ return exprIsConst(p, 1, 0);
8190582971
}
8190682972
8190782973
/*
81908
-** Walk an expression tree. Return 1 if the expression is constant
82974
+** Walk an expression tree. Return non-zero if the expression is constant
8190982975
** that does no originate from the ON or USING clauses of a join.
8191082976
** Return 0 if it involves variables or function calls or terms from
8191182977
** an ON or USING clause.
8191282978
*/
8191382979
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81914
- return exprIsConst(p, 2);
82980
+ return exprIsConst(p, 2, 0);
8191582981
}
8191682982
8191782983
/*
81918
-** Walk an expression tree. Return 1 if the expression is constant
82984
+** Walk an expression tree. Return non-zero if the expression constant
82985
+** for any single row of the table with cursor iCur. In other words, the
82986
+** expression must not refer to any non-deterministic function nor any
82987
+** table other than iCur.
82988
+*/
82989
+SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
82990
+ return exprIsConst(p, 3, iCur);
82991
+}
82992
+
82993
+/*
82994
+** Walk an expression tree. Return non-zero if the expression is constant
8191982995
** or a function call with constant arguments. Return and 0 if there
8192082996
** are any variables.
8192182997
**
8192282998
** For the purposes of this function, a double-quoted string (ex: "abc")
8192382999
** is considered a variable but a single-quoted string (ex: 'abc') is
8192483000
** a constant.
8192583001
*/
8192683002
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
8192783003
assert( isInit==0 || isInit==1 );
81928
- return exprIsConst(p, 3+isInit);
83004
+ return exprIsConst(p, 4+isInit, 0);
8192983005
}
8193083006
8193183007
/*
8193283008
** If the expression p codes a constant integer that is small enough
8193383009
** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -81990,11 +83066,12 @@
8199083066
case TK_FLOAT:
8199183067
case TK_BLOB:
8199283068
return 0;
8199383069
case TK_COLUMN:
8199483070
assert( p->pTab!=0 );
81995
- return p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0;
83071
+ return ExprHasProperty(p, EP_CanBeNull) ||
83072
+ (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
8199683073
default:
8199783074
return 1;
8199883075
}
8199983076
}
8200083077
@@ -82433,11 +83510,10 @@
8243383510
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
8243483511
dest.affSdst = (u8)affinity;
8243583512
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
8243683513
pSelect->iLimit = 0;
8243783514
testcase( pSelect->selFlags & SF_Distinct );
82438
- pSelect->selFlags &= ~SF_Distinct;
8243983515
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
8244083516
if( sqlite3Select(pParse, pSelect, &dest) ){
8244183517
sqlite3KeyInfoUnref(pKeyInfo);
8244283518
return 0;
8244383519
}
@@ -83580,11 +84656,14 @@
8358084656
target
8358184657
));
8358284658
8358384659
#ifndef SQLITE_OMIT_FLOATING_POINT
8358484660
/* If the column has REAL affinity, it may currently be stored as an
83585
- ** integer. Use OP_RealAffinity to make sure it is really real. */
84661
+ ** integer. Use OP_RealAffinity to make sure it is really real.
84662
+ **
84663
+ ** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
84664
+ ** floating point when extracting it from the record. */
8358684665
if( pExpr->iColumn>=0
8358784666
&& pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
8358884667
){
8358984668
sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
8359084669
}
@@ -87232,27 +88311,32 @@
8723288311
aLog[i] = sqlite3LogEst(v);
8723388312
#endif
8723488313
if( *z==' ' ) z++;
8723588314
}
8723688315
#ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87237
- assert( pIndex!=0 );
88316
+ assert( pIndex!=0 ); {
8723888317
#else
87239
- if( pIndex )
88318
+ if( pIndex ){
8724088319
#endif
87241
- while( z[0] ){
87242
- if( sqlite3_strglob("unordered*", z)==0 ){
87243
- pIndex->bUnordered = 1;
87244
- }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
87245
- pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
87246
- }
88320
+ pIndex->bUnordered = 0;
88321
+ pIndex->noSkipScan = 0;
88322
+ while( z[0] ){
88323
+ if( sqlite3_strglob("unordered*", z)==0 ){
88324
+ pIndex->bUnordered = 1;
88325
+ }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
88326
+ pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
88327
+ }else if( sqlite3_strglob("noskipscan*", z)==0 ){
88328
+ pIndex->noSkipScan = 1;
88329
+ }
8724788330
#ifdef SQLITE_ENABLE_COSTMULT
87248
- else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
87249
- pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
88331
+ else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
88332
+ pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
88333
+ }
88334
+#endif
88335
+ while( z[0]!=0 && z[0]!=' ' ) z++;
88336
+ while( z[0]==' ' ) z++;
8725088337
}
87251
-#endif
87252
- while( z[0]!=0 && z[0]!=' ' ) z++;
87253
- while( z[0]==' ' ) z++;
8725488338
}
8725588339
}
8725688340
8725788341
/*
8725888342
** This callback is invoked once for each index when reading the
@@ -87366,18 +88450,19 @@
8736688450
tRowcnt avgEq = 0;
8736788451
tRowcnt nRow; /* Number of rows in index */
8736888452
i64 nSum100 = 0; /* Number of terms contributing to sumEq */
8736988453
i64 nDist100; /* Number of distinct values in index */
8737088454
87371
- if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
88455
+ if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
8737288456
nRow = pFinal->anLt[iCol];
8737388457
nDist100 = (i64)100 * pFinal->anDLt[iCol];
8737488458
nSample--;
8737588459
}else{
8737688460
nRow = pIdx->aiRowEst[0];
8737788461
nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
8737888462
}
88463
+ pIdx->nRowEst0 = nRow;
8737988464
8738088465
/* Set nSum to the number of distinct (iCol+1) field prefixes that
8738188466
** occur in the stat4 table for this index. Set sumEq to the sum of
8738288467
** the nEq values for column iCol for the same set (adding the value
8738388468
** only once where there exist duplicate prefixes). */
@@ -87635,11 +88720,11 @@
8763588720
}
8763688721
8763788722
8763888723
/* Load the statistics from the sqlite_stat4 table. */
8763988724
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87640
- if( rc==SQLITE_OK ){
88725
+ if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
8764188726
int lookasideEnabled = db->lookaside.bEnabled;
8764288727
db->lookaside.bEnabled = 0;
8764388728
rc = loadStat4(db, sInfo.zDatabase);
8764488729
db->lookaside.bEnabled = lookasideEnabled;
8764588730
}
@@ -88317,10 +89402,13 @@
8831789402
SQLITE_API int sqlite3_set_authorizer(
8831889403
sqlite3 *db,
8831989404
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
8832089405
void *pArg
8832189406
){
89407
+#ifdef SQLITE_ENABLE_API_ARMOR
89408
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
89409
+#endif
8832289410
sqlite3_mutex_enter(db->mutex);
8832389411
db->xAuth = (sqlite3_xauth)xAuth;
8832489412
db->pAuthArg = pArg;
8832589413
sqlite3ExpirePreparedStatements(db);
8832689414
sqlite3_mutex_leave(db->mutex);
@@ -88811,11 +89899,15 @@
8881189899
** See also sqlite3LocateTable().
8881289900
*/
8881389901
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
8881489902
Table *p = 0;
8881589903
int i;
88816
- assert( zName!=0 );
89904
+
89905
+#ifdef SQLITE_ENABLE_API_ARMOR
89906
+ if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
89907
+#endif
89908
+
8881789909
/* All mutexes are required for schema access. Make sure we hold them. */
8881889910
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
8881989911
#if SQLITE_USER_AUTHENTICATION
8882089912
/* Only the admin user is allowed to know that the sqlite_user table
8882189913
** exists */
@@ -94275,12 +95367,12 @@
9427595367
break;
9427695368
}
9427795369
default: {
9427895370
/* Because sqlite3_value_double() returns 0.0 if the argument is not
9427995371
** something that can be converted into a number, we have:
94280
- ** IMP: R-57326-31541 Abs(X) return 0.0 if X is a string or blob that
94281
- ** cannot be converted to a numeric value.
95372
+ ** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
95373
+ ** that cannot be converted to a numeric value.
9428295374
*/
9428395375
double rVal = sqlite3_value_double(argv[0]);
9428495376
if( rVal<0 ) rVal = -rVal;
9428595377
sqlite3_result_double(context, rVal);
9428695378
break;
@@ -99994,11 +101086,10 @@
99994101086
# define sqlite3_column_database_name16 0
99995101087
# define sqlite3_column_table_name 0
99996101088
# define sqlite3_column_table_name16 0
99997101089
# define sqlite3_column_origin_name 0
99998101090
# define sqlite3_column_origin_name16 0
99999
-# define sqlite3_table_column_metadata 0
100000101091
#endif
100001101092
100002101093
#ifdef SQLITE_OMIT_AUTHORIZATION
100003101094
# define sqlite3_set_authorizer 0
100004101095
#endif
@@ -102928,11 +104019,11 @@
102928104019
break;
102929104020
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
102930104021
102931104022
#ifndef SQLITE_OMIT_WAL
102932104023
/*
102933
- ** PRAGMA [database.]wal_checkpoint = passive|full|restart
104024
+ ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
102934104025
**
102935104026
** Checkpoint the database.
102936104027
*/
102937104028
case PragTyp_WAL_CHECKPOINT: {
102938104029
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
@@ -102940,10 +104031,12 @@
102940104031
if( zRight ){
102941104032
if( sqlite3StrICmp(zRight, "full")==0 ){
102942104033
eMode = SQLITE_CHECKPOINT_FULL;
102943104034
}else if( sqlite3StrICmp(zRight, "restart")==0 ){
102944104035
eMode = SQLITE_CHECKPOINT_RESTART;
104036
+ }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
104037
+ eMode = SQLITE_CHECKPOINT_TRUNCATE;
102945104038
}
102946104039
}
102947104040
sqlite3VdbeSetNumCols(v, 3);
102948104041
pParse->nMem = 3;
102949104042
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
@@ -103834,13 +104927,16 @@
103834104927
Vdbe *pOld, /* VM being reprepared */
103835104928
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
103836104929
const char **pzTail /* OUT: End of parsed string */
103837104930
){
103838104931
int rc;
103839
- assert( ppStmt!=0 );
104932
+
104933
+#ifdef SQLITE_ENABLE_API_ARMOR
104934
+ if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104935
+#endif
103840104936
*ppStmt = 0;
103841
- if( !sqlite3SafetyCheckOk(db) ){
104937
+ if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
103842104938
return SQLITE_MISUSE_BKPT;
103843104939
}
103844104940
sqlite3_mutex_enter(db->mutex);
103845104941
sqlite3BtreeEnterAll(db);
103846104942
rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -103943,13 +105039,15 @@
103943105039
*/
103944105040
char *zSql8;
103945105041
const char *zTail8 = 0;
103946105042
int rc = SQLITE_OK;
103947105043
103948
- assert( ppStmt );
105044
+#ifdef SQLITE_ENABLE_API_ARMOR
105045
+ if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
105046
+#endif
103949105047
*ppStmt = 0;
103950
- if( !sqlite3SafetyCheckOk(db) ){
105048
+ if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
103951105049
return SQLITE_MISUSE_BKPT;
103952105050
}
103953105051
if( nBytes>=0 ){
103954105052
int sz;
103955105053
const char *z = (const char*)zSql;
@@ -108842,11 +109940,11 @@
108842109940
**
108843109941
** SELECT DISTINCT xyz FROM ... ORDER BY xyz
108844109942
**
108845109943
** is transformed to:
108846109944
**
108847
- ** SELECT xyz FROM ... GROUP BY xyz
109945
+ ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
108848109946
**
108849109947
** The second form is preferred as a single index (or temp-table) may be
108850109948
** used for both the ORDER BY and DISTINCT processing. As originally
108851109949
** written the query must use a temp-table for at least one of the ORDER
108852109950
** BY and DISTINCT, and an index or separate temp-table for the other.
@@ -108855,11 +109953,10 @@
108855109953
&& sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0
108856109954
){
108857109955
p->selFlags &= ~SF_Distinct;
108858109956
p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
108859109957
pGroupBy = p->pGroupBy;
108860
- sSort.pOrderBy = 0;
108861109958
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
108862109959
** the sDistinct.isTnct is still set. Hence, isTnct represents the
108863109960
** original setting of the SF_Distinct flag, not the current setting */
108864109961
assert( sDistinct.isTnct );
108865109962
}
@@ -109658,10 +110755,13 @@
109658110755
char **pzErrMsg /* Write error messages here */
109659110756
){
109660110757
int rc;
109661110758
TabResult res;
109662110759
110760
+#ifdef SQLITE_ENABLE_API_ARMOR
110761
+ if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762
+#endif
109663110763
*pazResult = 0;
109664110764
if( pnColumn ) *pnColumn = 0;
109665110765
if( pnRow ) *pnRow = 0;
109666110766
if( pzErrMsg ) *pzErrMsg = 0;
109667110767
res.zErrMsg = 0;
@@ -111721,11 +112821,11 @@
111721112821
** Two writes per page are required in step (3) because the original
111722112822
** database content must be written into the rollback journal prior to
111723112823
** overwriting the database with the vacuumed content.
111724112824
**
111725112825
** Only 1x temporary space and only 1x writes would be required if
111726
-** the copy of step (3) were replace by deleting the original database
112826
+** the copy of step (3) were replaced by deleting the original database
111727112827
** and renaming the transient database as the original. But that will
111728112828
** not work if other processes are attached to the original database.
111729112829
** And a power loss in between deleting the original and renaming the
111730112830
** transient would cause the database file to appear to be deleted
111731112831
** following reboot.
@@ -112079,10 +113179,13 @@
112079113179
sqlite3 *db, /* Database in which module is registered */
112080113180
const char *zName, /* Name assigned to this module */
112081113181
const sqlite3_module *pModule, /* The definition of the module */
112082113182
void *pAux /* Context pointer for xCreate/xConnect */
112083113183
){
113184
+#ifdef SQLITE_ENABLE_API_ARMOR
113185
+ if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
113186
+#endif
112084113187
return createModule(db, zName, pModule, pAux, 0);
112085113188
}
112086113189
112087113190
/*
112088113191
** External API function used to create a new virtual-table module.
@@ -112092,10 +113195,13 @@
112092113195
const char *zName, /* Name assigned to this module */
112093113196
const sqlite3_module *pModule, /* The definition of the module */
112094113197
void *pAux, /* Context pointer for xCreate/xConnect */
112095113198
void (*xDestroy)(void *) /* Module destructor function */
112096113199
){
113200
+#ifdef SQLITE_ENABLE_API_ARMOR
113201
+ if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
113202
+#endif
112097113203
return createModule(db, zName, pModule, pAux, xDestroy);
112098113204
}
112099113205
112100113206
/*
112101113207
** Lock the virtual table so that it cannot be disconnected.
@@ -112324,11 +113430,16 @@
112324113430
pTable->tabFlags |= TF_Virtual;
112325113431
pTable->nModuleArg = 0;
112326113432
addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
112327113433
addModuleArgument(db, pTable, 0);
112328113434
addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
112329
- pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z);
113435
+ assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
113436
+ || (pParse->sNameToken.z==pName1->z && pName2->z==0)
113437
+ );
113438
+ pParse->sNameToken.n = (int)(
113439
+ &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
113440
+ );
112330113441
112331113442
#ifndef SQLITE_OMIT_AUTHORIZATION
112332113443
/* Creating a virtual table invokes the authorization callback twice.
112333113444
** The first invocation, to obtain permission to INSERT a row into the
112334113445
** sqlite_master table, has already been made by sqlite3StartTable().
@@ -112696,10 +113807,13 @@
112696113807
112697113808
int rc = SQLITE_OK;
112698113809
Table *pTab;
112699113810
char *zErr = 0;
112700113811
113812
+#ifdef SQLITE_ENABLE_API_ARMOR
113813
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113814
+#endif
112701113815
sqlite3_mutex_enter(db->mutex);
112702113816
if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
112703113817
sqlite3Error(db, SQLITE_MISUSE);
112704113818
sqlite3_mutex_leave(db->mutex);
112705113819
return SQLITE_MISUSE_BKPT;
@@ -113052,10 +114166,13 @@
113052114166
*/
113053114167
SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
113054114168
static const unsigned char aMap[] = {
113055114169
SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
113056114170
};
114171
+#ifdef SQLITE_ENABLE_API_ARMOR
114172
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
114173
+#endif
113057114174
assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
113058114175
assert( OE_Ignore==4 && OE_Replace==5 );
113059114176
assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
113060114177
return (int)aMap[db->vtabOnConflict-1];
113061114178
}
@@ -113067,12 +114184,14 @@
113067114184
*/
113068114185
SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
113069114186
va_list ap;
113070114187
int rc = SQLITE_OK;
113071114188
114189
+#ifdef SQLITE_ENABLE_API_ARMOR
114190
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
114191
+#endif
113072114192
sqlite3_mutex_enter(db->mutex);
113073
-
113074114193
va_start(ap, op);
113075114194
switch( op ){
113076114195
case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
113077114196
VtabCtx *p = db->pVtabCtx;
113078114197
if( !p ){
@@ -113203,10 +114322,13 @@
113203114322
} in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
113204114323
Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
113205114324
} u;
113206114325
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
113207114326
Bitmask notReady; /* FROM entries not usable at this level */
114327
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
114328
+ int addrVisit; /* Address at which row is visited */
114329
+#endif
113208114330
};
113209114331
113210114332
/*
113211114333
** Each instance of this object represents an algorithm for evaluating one
113212114334
** term of a join. Every term of the FROM clause will have at least
@@ -113233,11 +114355,10 @@
113233114355
LogEst rRun; /* Cost of running each loop */
113234114356
LogEst nOut; /* Estimated number of output rows */
113235114357
union {
113236114358
struct { /* Information for internal btree tables */
113237114359
u16 nEq; /* Number of equality constraints */
113238
- u16 nSkip; /* Number of initial index columns to skip */
113239114360
Index *pIndex; /* Index used, or NULL */
113240114361
} btree;
113241114362
struct { /* Information for virtual tables */
113242114363
int idxNum; /* Index number */
113243114364
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -113246,16 +114367,17 @@
113246114367
char *idxStr; /* Index identifier string */
113247114368
} vtab;
113248114369
} u;
113249114370
u32 wsFlags; /* WHERE_* flags describing the plan */
113250114371
u16 nLTerm; /* Number of entries in aLTerm[] */
114372
+ u16 nSkip; /* Number of NULL aLTerm[] entries */
113251114373
/**** whereLoopXfer() copies fields above ***********************/
113252114374
# define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
113253114375
u16 nLSlot; /* Number of slots allocated for aLTerm[] */
113254114376
WhereTerm **aLTerm; /* WhereTerms used */
113255114377
WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
113256
- WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
114378
+ WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
113257114379
};
113258114380
113259114381
/* This object holds the prerequisites and the cost of running a
113260114382
** subquery on one operand of an OR operator in the WHERE clause.
113261114383
** See WhereOrSet for additional information
@@ -113577,10 +114699,11 @@
113577114699
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
113578114700
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
113579114701
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
113580114702
#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
113581114703
#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
114704
+#define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
113582114705
113583114706
/************** End of whereInt.h ********************************************/
113584114707
/************** Continuing where we left off in where.c **********************/
113585114708
113586114709
/*
@@ -113784,14 +114907,15 @@
113784114907
memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
113785114908
if( pOld!=pWC->aStatic ){
113786114909
sqlite3DbFree(db, pOld);
113787114910
}
113788114911
pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
114912
+ memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm));
113789114913
}
113790114914
pTerm = &pWC->a[idx = pWC->nTerm++];
113791114915
if( p && ExprHasProperty(p, EP_Unlikely) ){
113792
- pTerm->truthProb = sqlite3LogEst(p->iTable) - 99;
114916
+ pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
113793114917
}else{
113794114918
pTerm->truthProb = 1;
113795114919
}
113796114920
pTerm->pExpr = sqlite3ExprSkipCollate(p);
113797114921
pTerm->wtFlags = wtFlags;
@@ -114317,10 +115441,19 @@
114317115441
if( pDerived ){
114318115442
pDerived->flags |= pBase->flags & EP_FromJoin;
114319115443
pDerived->iRightJoinTable = pBase->iRightJoinTable;
114320115444
}
114321115445
}
115446
+
115447
+/*
115448
+** Mark term iChild as being a child of term iParent
115449
+*/
115450
+static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115451
+ pWC->a[iChild].iParent = iParent;
115452
+ pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115453
+ pWC->a[iParent].nChild++;
115454
+}
114322115455
114323115456
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114324115457
/*
114325115458
** Analyze a term that consists of two or more OR-connected
114326115459
** subterms. So in:
@@ -114615,12 +115748,11 @@
114615115748
pNew->x.pList = pList;
114616115749
idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
114617115750
testcase( idxNew==0 );
114618115751
exprAnalyze(pSrc, pWC, idxNew);
114619115752
pTerm = &pWC->a[idxTerm];
114620
- pWC->a[idxNew].iParent = idxTerm;
114621
- pTerm->nChild = 1;
115753
+ markTermAsChild(pWC, idxNew, idxTerm);
114622115754
}else{
114623115755
sqlite3ExprListDelete(db, pList);
114624115756
}
114625115757
pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
114626115758
}
@@ -114718,13 +115850,12 @@
114718115850
return;
114719115851
}
114720115852
idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
114721115853
if( idxNew==0 ) return;
114722115854
pNew = &pWC->a[idxNew];
114723
- pNew->iParent = idxTerm;
115855
+ markTermAsChild(pWC, idxNew, idxTerm);
114724115856
pTerm = &pWC->a[idxTerm];
114725
- pTerm->nChild = 1;
114726115857
pTerm->wtFlags |= TERM_COPIED;
114727115858
if( pExpr->op==TK_EQ
114728115859
&& !ExprHasProperty(pExpr, EP_FromJoin)
114729115860
&& OptimizationEnabled(db, SQLITE_Transitive)
114730115861
){
@@ -114777,13 +115908,12 @@
114777115908
transferJoinMarkings(pNewExpr, pExpr);
114778115909
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
114779115910
testcase( idxNew==0 );
114780115911
exprAnalyze(pSrc, pWC, idxNew);
114781115912
pTerm = &pWC->a[idxTerm];
114782
- pWC->a[idxNew].iParent = idxTerm;
115913
+ markTermAsChild(pWC, idxNew, idxTerm);
114783115914
}
114784
- pTerm->nChild = 2;
114785115915
}
114786115916
#endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
114787115917
114788115918
#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114789115919
/* Analyze a term that is composed of two or more subterms connected by
@@ -114854,13 +115984,12 @@
114854115984
idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
114855115985
testcase( idxNew2==0 );
114856115986
exprAnalyze(pSrc, pWC, idxNew2);
114857115987
pTerm = &pWC->a[idxTerm];
114858115988
if( isComplete ){
114859
- pWC->a[idxNew1].iParent = idxTerm;
114860
- pWC->a[idxNew2].iParent = idxTerm;
114861
- pTerm->nChild = 2;
115989
+ markTermAsChild(pWC, idxNew1, idxTerm);
115990
+ markTermAsChild(pWC, idxNew2, idxTerm);
114862115991
}
114863115992
}
114864115993
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
114865115994
114866115995
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -114889,13 +116018,12 @@
114889116018
pNewTerm = &pWC->a[idxNew];
114890116019
pNewTerm->prereqRight = prereqExpr;
114891116020
pNewTerm->leftCursor = pLeft->iTable;
114892116021
pNewTerm->u.leftColumn = pLeft->iColumn;
114893116022
pNewTerm->eOperator = WO_MATCH;
114894
- pNewTerm->iParent = idxTerm;
116023
+ markTermAsChild(pWC, idxNew, idxTerm);
114895116024
pTerm = &pWC->a[idxTerm];
114896
- pTerm->nChild = 1;
114897116025
pTerm->wtFlags |= TERM_COPIED;
114898116026
pNewTerm->prereqAll = pTerm->prereqAll;
114899116027
}
114900116028
}
114901116029
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -114912,11 +116040,11 @@
114912116040
** the start of the loop will prevent any results from being returned.
114913116041
*/
114914116042
if( pExpr->op==TK_NOTNULL
114915116043
&& pExpr->pLeft->op==TK_COLUMN
114916116044
&& pExpr->pLeft->iColumn>=0
114917
- && OptimizationEnabled(db, SQLITE_Stat3)
116045
+ && OptimizationEnabled(db, SQLITE_Stat34)
114918116046
){
114919116047
Expr *pNewExpr;
114920116048
Expr *pLeft = pExpr->pLeft;
114921116049
int idxNew;
114922116050
WhereTerm *pNewTerm;
@@ -114931,13 +116059,12 @@
114931116059
pNewTerm = &pWC->a[idxNew];
114932116060
pNewTerm->prereqRight = 0;
114933116061
pNewTerm->leftCursor = pLeft->iTable;
114934116062
pNewTerm->u.leftColumn = pLeft->iColumn;
114935116063
pNewTerm->eOperator = WO_GT;
114936
- pNewTerm->iParent = idxTerm;
116064
+ markTermAsChild(pWC, idxNew, idxTerm);
114937116065
pTerm = &pWC->a[idxTerm];
114938
- pTerm->nChild = 1;
114939116066
pTerm->wtFlags |= TERM_COPIED;
114940116067
pNewTerm->prereqAll = pTerm->prereqAll;
114941116068
}
114942116069
}
114943116070
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115153,10 +116280,12 @@
115153116280
WhereLoop *pLoop; /* The Loop object */
115154116281
char *zNotUsed; /* Extra space on the end of pIdx */
115155116282
Bitmask idxCols; /* Bitmap of columns used for indexing */
115156116283
Bitmask extraCols; /* Bitmap of additional columns */
115157116284
u8 sentWarning = 0; /* True if a warnning has been issued */
116285
+ Expr *pPartial = 0; /* Partial Index Expression */
116286
+ int iContinue = 0; /* Jump here to skip excluded rows */
115158116287
115159116288
/* Generate code to skip over the creation and initialization of the
115160116289
** transient index on 2nd and subsequent iterations of the loop. */
115161116290
v = pParse->pVdbe;
115162116291
assert( v!=0 );
@@ -115168,10 +116297,16 @@
115168116297
pTable = pSrc->pTab;
115169116298
pWCEnd = &pWC->a[pWC->nTerm];
115170116299
pLoop = pLevel->pWLoop;
115171116300
idxCols = 0;
115172116301
for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
116302
+ if( pLoop->prereq==0
116303
+ && (pTerm->wtFlags & TERM_VIRTUAL)==0
116304
+ && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
116305
+ pPartial = sqlite3ExprAnd(pParse->db, pPartial,
116306
+ sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
116307
+ }
115173116308
if( termCanDriveIndex(pTerm, pSrc, notReady) ){
115174116309
int iCol = pTerm->u.leftColumn;
115175116310
Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
115176116311
testcase( iCol==BMS );
115177116312
testcase( iCol==BMS-1 );
@@ -115180,11 +116315,13 @@
115180116315
"automatic index on %s(%s)", pTable->zName,
115181116316
pTable->aCol[iCol].zName);
115182116317
sentWarning = 1;
115183116318
}
115184116319
if( (idxCols & cMask)==0 ){
115185
- if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
116320
+ if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
116321
+ goto end_auto_index_create;
116322
+ }
115186116323
pLoop->aLTerm[nKeyCol++] = pTerm;
115187116324
idxCols |= cMask;
115188116325
}
115189116326
}
115190116327
}
@@ -115200,24 +116337,23 @@
115200116337
** be a covering index because the index will not be updated if the
115201116338
** original table changes and the index and table cannot both be used
115202116339
** if they go out of sync.
115203116340
*/
115204116341
extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
115205
- mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
116342
+ mxBitCol = MIN(BMS-1,pTable->nCol);
115206116343
testcase( pTable->nCol==BMS-1 );
115207116344
testcase( pTable->nCol==BMS-2 );
115208116345
for(i=0; i<mxBitCol; i++){
115209116346
if( extraCols & MASKBIT(i) ) nKeyCol++;
115210116347
}
115211116348
if( pSrc->colUsed & MASKBIT(BMS-1) ){
115212116349
nKeyCol += pTable->nCol - BMS + 1;
115213116350
}
115214
- pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
115215116351
115216116352
/* Construct the Index object to describe this index */
115217116353
pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
115218
- if( pIdx==0 ) return;
116354
+ if( pIdx==0 ) goto end_auto_index_create;
115219116355
pLoop->u.btree.pIndex = pIdx;
115220116356
pIdx->zName = "auto-index";
115221116357
pIdx->pTable = pTable;
115222116358
n = 0;
115223116359
idxCols = 0;
@@ -115265,22 +116401,33 @@
115265116401
sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
115266116402
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
115267116403
VdbeComment((v, "for %s", pTable->zName));
115268116404
115269116405
/* Fill the automatic index with content */
116406
+ sqlite3ExprCachePush(pParse);
115270116407
addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
116408
+ if( pPartial ){
116409
+ iContinue = sqlite3VdbeMakeLabel(v);
116410
+ sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
116411
+ pLoop->wsFlags |= WHERE_PARTIALIDX;
116412
+ }
115271116413
regRecord = sqlite3GetTempReg(pParse);
115272116414
sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
115273116415
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
115274116416
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116417
+ if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
115275116418
sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
115276116419
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
115277116420
sqlite3VdbeJumpHere(v, addrTop);
115278116421
sqlite3ReleaseTempReg(pParse, regRecord);
116422
+ sqlite3ExprCachePop(pParse);
115279116423
115280116424
/* Jump here when skipping the initialization */
115281116425
sqlite3VdbeJumpHere(v, addrInit);
116426
+
116427
+end_auto_index_create:
116428
+ sqlite3ExprDelete(pParse->db, pPartial);
115282116429
}
115283116430
#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
115284116431
115285116432
#ifndef SQLITE_OMIT_VIRTUALTABLE
115286116433
/*
@@ -115436,22 +116583,22 @@
115436116583
115437116584
return pParse->nErr;
115438116585
}
115439116586
#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
115440116587
115441
-
115442116588
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115443116589
/*
115444116590
** Estimate the location of a particular key among all keys in an
115445116591
** index. Store the results in aStat as follows:
115446116592
**
115447116593
** aStat[0] Est. number of rows less than pVal
115448116594
** aStat[1] Est. number of rows equal to pVal
115449116595
**
115450
-** Return SQLITE_OK on success.
116596
+** Return the index of the sample that is the smallest sample that
116597
+** is greater than or equal to pRec.
115451116598
*/
115452
-static void whereKeyStats(
116599
+static int whereKeyStats(
115453116600
Parse *pParse, /* Database connection */
115454116601
Index *pIdx, /* Index to consider domain of */
115455116602
UnpackedRecord *pRec, /* Vector of values to consider */
115456116603
int roundUp, /* Round up if true. Round down if false */
115457116604
tRowcnt *aStat /* OUT: stats written here */
@@ -115529,10 +116676,11 @@
115529116676
}else{
115530116677
iGap = iGap/3;
115531116678
}
115532116679
aStat[0] = iLower + iGap;
115533116680
}
116681
+ return i;
115534116682
}
115535116683
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
115536116684
115537116685
/*
115538116686
** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -115679,11 +116827,11 @@
115679116827
** pLower pUpper
115680116828
**
115681116829
** If either of the upper or lower bound is not present, then NULL is passed in
115682116830
** place of the corresponding WhereTerm.
115683116831
**
115684
-** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
116832
+** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
115685116833
** column subject to the range constraint. Or, equivalently, the number of
115686116834
** equality constraints optimized by the proposed index scan. For example,
115687116835
** assuming index p is on t1(a, b), and the SQL query is:
115688116836
**
115689116837
** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -115695,11 +116843,11 @@
115695116843
**
115696116844
** then nEq is set to 0.
115697116845
**
115698116846
** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115699116847
** number of rows that the index scan is expected to visit without
115700
-** considering the range constraints. If nEq is 0, this is the number of
116848
+** considering the range constraints. If nEq is 0, then *pnOut is the number of
115701116849
** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115702116850
** to account for the range constraints pLower and pUpper.
115703116851
**
115704116852
** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115705116853
** used, a single range inequality reduces the search space by a factor of 4.
@@ -115719,14 +116867,11 @@
115719116867
115720116868
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115721116869
Index *p = pLoop->u.btree.pIndex;
115722116870
int nEq = pLoop->u.btree.nEq;
115723116871
115724
- if( p->nSample>0
115725
- && nEq<p->nSampleCol
115726
- && OptimizationEnabled(pParse->db, SQLITE_Stat3)
115727
- ){
116872
+ if( p->nSample>0 && nEq<p->nSampleCol ){
115728116873
if( nEq==pBuilder->nRecValid ){
115729116874
UnpackedRecord *pRec = pBuilder->pRec;
115730116875
tRowcnt a[2];
115731116876
u8 aff;
115732116877
@@ -115738,19 +116883,23 @@
115738116883
**
115739116884
** Or, if pLower is NULL or $L cannot be extracted from it (because it
115740116885
** is not a simple variable or literal value), the lower bound of the
115741116886
** range is $P. Due to a quirk in the way whereKeyStats() works, even
115742116887
** if $L is available, whereKeyStats() is called for both ($P) and
115743
- ** ($P:$L) and the larger of the two returned values used.
116888
+ ** ($P:$L) and the larger of the two returned values is used.
115744116889
**
115745116890
** Similarly, iUpper is to be set to the estimate of the number of rows
115746116891
** less than the upper bound of the range query. Where the upper bound
115747116892
** is either ($P) or ($P:$U). Again, even if $U is available, both values
115748116893
** of iUpper are requested of whereKeyStats() and the smaller used.
116894
+ **
116895
+ ** The number of rows between the two bounds is then just iUpper-iLower.
115749116896
*/
115750
- tRowcnt iLower;
115751
- tRowcnt iUpper;
116897
+ tRowcnt iLower; /* Rows less than the lower bound */
116898
+ tRowcnt iUpper; /* Rows less than the upper bound */
116899
+ int iLwrIdx = -2; /* aSample[] for the lower bound */
116900
+ int iUprIdx = -1; /* aSample[] for the upper bound */
115752116901
115753116902
if( pRec ){
115754116903
testcase( pRec->nField!=pBuilder->nRecValid );
115755116904
pRec->nField = pBuilder->nRecValid;
115756116905
}
@@ -115760,11 +116909,11 @@
115760116909
aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
115761116910
}
115762116911
/* Determine iLower and iUpper using ($P) only. */
115763116912
if( nEq==0 ){
115764116913
iLower = 0;
115765
- iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]);
116914
+ iUpper = p->nRowEst0;
115766116915
}else{
115767116916
/* Note: this call could be optimized away - since the same values must
115768116917
** have been requested when testing key $P in whereEqualScanEst(). */
115769116918
whereKeyStats(pParse, p, pRec, 0, a);
115770116919
iLower = a[0];
@@ -115784,11 +116933,11 @@
115784116933
int bOk; /* True if value is extracted from pExpr */
115785116934
Expr *pExpr = pLower->pExpr->pRight;
115786116935
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115787116936
if( rc==SQLITE_OK && bOk ){
115788116937
tRowcnt iNew;
115789
- whereKeyStats(pParse, p, pRec, 0, a);
116938
+ iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
115790116939
iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115791116940
if( iNew>iLower ) iLower = iNew;
115792116941
nOut--;
115793116942
pLower = 0;
115794116943
}
@@ -115799,11 +116948,11 @@
115799116948
int bOk; /* True if value is extracted from pExpr */
115800116949
Expr *pExpr = pUpper->pExpr->pRight;
115801116950
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115802116951
if( rc==SQLITE_OK && bOk ){
115803116952
tRowcnt iNew;
115804
- whereKeyStats(pParse, p, pRec, 1, a);
116953
+ iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);
115805116954
iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115806116955
if( iNew<iUpper ) iUpper = iNew;
115807116956
nOut--;
115808116957
pUpper = 0;
115809116958
}
@@ -115811,10 +116960,15 @@
115811116960
115812116961
pBuilder->pRec = pRec;
115813116962
if( rc==SQLITE_OK ){
115814116963
if( iUpper>iLower ){
115815116964
nNew = sqlite3LogEst(iUpper - iLower);
116965
+ /* TUNING: If both iUpper and iLower are derived from the same
116966
+ ** sample, then assume they are 4x more selective. This brings
116967
+ ** the estimated selectivity more in line with what it would be
116968
+ ** if estimated without the use of STAT3/4 tables. */
116969
+ if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );
115816116970
}else{
115817116971
nNew = 10; assert( 10==sqlite3LogEst(2) );
115818116972
}
115819116973
if( nNew<nOut ){
115820116974
nOut = nNew;
@@ -115835,16 +116989,19 @@
115835116989
#endif
115836116990
assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
115837116991
nNew = whereRangeAdjust(pLower, nOut);
115838116992
nNew = whereRangeAdjust(pUpper, nNew);
115839116993
115840
- /* TUNING: If there is both an upper and lower limit, assume the range is
116994
+ /* TUNING: If there is both an upper and lower limit and neither limit
116995
+ ** has an application-defined likelihood(), assume the range is
115841116996
** reduced by an additional 75%. This means that, by default, an open-ended
115842116997
** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
115843116998
** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
115844116999
** match 1/64 of the index. */
115845
- if( pLower && pUpper ) nNew -= 20;
117000
+ if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
117001
+ nNew -= 20;
117002
+ }
115846117003
115847117004
nOut -= (pLower!=0) + (pUpper!=0);
115848117005
if( nNew<10 ) nNew = 10;
115849117006
if( nNew<nOut ) nOut = nNew;
115850117007
#if defined(WHERETRACE_ENABLED)
@@ -116200,11 +117357,11 @@
116200117357
116201117358
/* This module is only called on query plans that use an index. */
116202117359
pLoop = pLevel->pWLoop;
116203117360
assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
116204117361
nEq = pLoop->u.btree.nEq;
116205
- nSkip = pLoop->u.btree.nSkip;
117362
+ nSkip = pLoop->nSkip;
116206117363
pIdx = pLoop->u.btree.pIndex;
116207117364
assert( pIdx!=0 );
116208117365
116209117366
/* Figure out how many memory cells we will need then allocate them.
116210117367
*/
@@ -116314,11 +117471,11 @@
116314117471
** "a=? AND b>?"
116315117472
*/
116316117473
static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116317117474
Index *pIndex = pLoop->u.btree.pIndex;
116318117475
u16 nEq = pLoop->u.btree.nEq;
116319
- u16 nSkip = pLoop->u.btree.nSkip;
117476
+ u16 nSkip = pLoop->nSkip;
116320117477
int i, j;
116321117478
Column *aCol = pTab->aCol;
116322117479
i16 *aiColumn = pIndex->aiColumn;
116323117480
116324117481
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -116345,23 +117502,27 @@
116345117502
sqlite3StrAccumAppend(pStr, ")", 1);
116346117503
}
116347117504
116348117505
/*
116349117506
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116350
-** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
116351
-** record is added to the output to describe the table scan strategy in
116352
-** pLevel.
117507
+** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
117508
+** defined at compile-time. If it is not a no-op, a single OP_Explain opcode
117509
+** is added to the output to describe the table scan strategy in pLevel.
117510
+**
117511
+** If an OP_Explain opcode is added to the VM, its address is returned.
117512
+** Otherwise, if no OP_Explain is coded, zero is returned.
116353117513
*/
116354
-static void explainOneScan(
117514
+static int explainOneScan(
116355117515
Parse *pParse, /* Parse context */
116356117516
SrcList *pTabList, /* Table list this loop refers to */
116357117517
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
116358117518
int iLevel, /* Value for "level" column of output */
116359117519
int iFrom, /* Value for "from" column of output */
116360117520
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
116361117521
){
116362
-#ifndef SQLITE_DEBUG
117522
+ int ret = 0;
117523
+#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
116363117524
if( pParse->explain==2 )
116364117525
#endif
116365117526
{
116366117527
struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116367117528
Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -116374,11 +117535,11 @@
116374117535
StrAccum str; /* EQP output string */
116375117536
char zBuf[100]; /* Initial space for EQP output string */
116376117537
116377117538
pLoop = pLevel->pWLoop;
116378117539
flags = pLoop->wsFlags;
116379
- if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
117540
+ if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0;
116380117541
116381117542
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116382117543
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116383117544
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116384117545
@@ -116403,10 +117564,12 @@
116403117564
assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116404117565
if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116405117566
if( isSearch ){
116406117567
zFmt = "PRIMARY KEY";
116407117568
}
117569
+ }else if( flags & WHERE_PARTIALIDX ){
117570
+ zFmt = "AUTOMATIC PARTIAL COVERING INDEX";
116408117571
}else if( flags & WHERE_AUTO_INDEX ){
116409117572
zFmt = "AUTOMATIC COVERING INDEX";
116410117573
}else if( flags & WHERE_IDX_ONLY ){
116411117574
zFmt = "COVERING INDEX %s";
116412117575
}else{
@@ -116444,16 +117607,49 @@
116444117607
}else{
116445117608
sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116446117609
}
116447117610
#endif
116448117611
zMsg = sqlite3StrAccumFinish(&str);
116449
- sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
117612
+ ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC);
116450117613
}
117614
+ return ret;
116451117615
}
116452117616
#else
116453
-# define explainOneScan(u,v,w,x,y,z)
117617
+# define explainOneScan(u,v,w,x,y,z) 0
116454117618
#endif /* SQLITE_OMIT_EXPLAIN */
117619
+
117620
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
117621
+/*
117622
+** Configure the VM passed as the first argument with an
117623
+** sqlite3_stmt_scanstatus() entry corresponding to the scan used to
117624
+** implement level pLvl. Argument pSrclist is a pointer to the FROM
117625
+** clause that the scan reads data from.
117626
+**
117627
+** If argument addrExplain is not 0, it must be the address of an
117628
+** OP_Explain instruction that describes the same loop.
117629
+*/
117630
+static void addScanStatus(
117631
+ Vdbe *v, /* Vdbe to add scanstatus entry to */
117632
+ SrcList *pSrclist, /* FROM clause pLvl reads data from */
117633
+ WhereLevel *pLvl, /* Level to add scanstatus() entry for */
117634
+ int addrExplain /* Address of OP_Explain (or 0) */
117635
+){
117636
+ const char *zObj = 0;
117637
+ WhereLoop *pLoop = pLvl->pWLoop;
117638
+ if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
117639
+ zObj = pLoop->u.btree.pIndex->zName;
117640
+ }else{
117641
+ zObj = pSrclist->a[pLvl->iFrom].zName;
117642
+ }
117643
+ sqlite3VdbeScanStatus(
117644
+ v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
117645
+ );
117646
+}
117647
+#else
117648
+# define addScanStatus(a, b, c, d) ((void)d)
117649
+#endif
117650
+
116455117651
116456117652
116457117653
/*
116458117654
** Generate code for the start of the iLevel-th loop in the WHERE clause
116459117655
** implementation described by pWInfo.
@@ -116751,11 +117947,11 @@
116751117947
u8 bSeekPastNull = 0; /* True to seek past initial nulls */
116752117948
u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
116753117949
116754117950
pIdx = pLoop->u.btree.pIndex;
116755117951
iIdxCur = pLevel->iIdxCur;
116756
- assert( nEq>=pLoop->u.btree.nSkip );
117952
+ assert( nEq>=pLoop->nSkip );
116757117953
116758117954
/* If this loop satisfies a sort order (pOrderBy) request that
116759117955
** was passed to this function to implement a "SELECT min(x) ..."
116760117956
** query, then the caller will only allow the loop to run for
116761117957
** a single iteration. This means that the first row returned
@@ -116768,11 +117964,11 @@
116768117964
|| (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
116769117965
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
116770117966
&& pWInfo->nOBSat>0
116771117967
&& (pIdx->nKeyCol>nEq)
116772117968
){
116773
- assert( pLoop->u.btree.nSkip==0 );
117969
+ assert( pLoop->nSkip==0 );
116774117970
bSeekPastNull = 1;
116775117971
nExtraReg = 1;
116776117972
}
116777117973
116778117974
/* Find any inequality constraint terms for the start and end
@@ -117081,14 +118277,13 @@
117081118277
int iTerm;
117082118278
for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
117083118279
Expr *pExpr = pWC->a[iTerm].pExpr;
117084118280
if( &pWC->a[iTerm] == pTerm ) continue;
117085118281
if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
117086
- testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
117087
- testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
117088
- if( pWC->a[iTerm].wtFlags & (TERM_ORINFO|TERM_VIRTUAL) ) continue;
118282
+ if( (pWC->a[iTerm].wtFlags & TERM_VIRTUAL)!=0 ) continue;
117089118283
if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
118284
+ testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
117090118285
pExpr = sqlite3ExprDup(db, pExpr, 0);
117091118286
pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
117092118287
}
117093118288
if( pAndExpr ){
117094118289
pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
@@ -117117,13 +118312,15 @@
117117118312
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117118118313
wctrlFlags, iCovCur);
117119118314
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
117120118315
if( pSubWInfo ){
117121118316
WhereLoop *pSubLoop;
117122
- explainOneScan(
118317
+ int addrExplain = explainOneScan(
117123118318
pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
117124118319
);
118320
+ addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
118321
+
117125118322
/* This is the sub-WHERE clause body. First skip over
117126118323
** duplicate rows from prior sub-WHERE clauses, and record the
117127118324
** rowid (or PRIMARY KEY) for the current row so that the same
117128118325
** row will be skipped in subsequent sub-WHERE clauses.
117129118326
*/
@@ -117249,10 +118446,14 @@
117249118446
VdbeCoverageIf(v, bRev==0);
117250118447
VdbeCoverageIf(v, bRev!=0);
117251118448
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
117252118449
}
117253118450
}
118451
+
118452
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
118453
+ pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
118454
+#endif
117254118455
117255118456
/* Insert code to test every subexpression that can be completely
117256118457
** computed using the current set of tables.
117257118458
*/
117258118459
for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
@@ -117389,11 +118590,11 @@
117389118590
}
117390118591
sqlite3DebugPrintf(" %-19s", z);
117391118592
sqlite3_free(z);
117392118593
}
117393118594
if( p->wsFlags & WHERE_SKIPSCAN ){
117394
- sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
118595
+ sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
117395118596
}else{
117396118597
sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117397118598
}
117398118599
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117399118600
if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -117500,34 +118701,41 @@
117500118701
sqlite3DbFree(db, pWInfo);
117501118702
}
117502118703
}
117503118704
117504118705
/*
117505
-** Return TRUE if both of the following are true:
118706
+** Return TRUE if all of the following are true:
117506118707
**
117507118708
** (1) X has the same or lower cost that Y
117508118709
** (2) X is a proper subset of Y
118710
+** (3) X skips at least as many columns as Y
117509118711
**
117510118712
** By "proper subset" we mean that X uses fewer WHERE clause terms
117511118713
** than Y and that every WHERE clause term used by X is also used
117512118714
** by Y.
117513118715
**
117514118716
** If X is a proper subset of Y then Y is a better choice and ought
117515118717
** to have a lower cost. This routine returns TRUE when that cost
117516
-** relationship is inverted and needs to be adjusted.
118718
+** relationship is inverted and needs to be adjusted. The third rule
118719
+** was added because if X uses skip-scan less than Y it still might
118720
+** deserve a lower cost even if it is a proper subset of Y.
117517118721
*/
117518118722
static int whereLoopCheaperProperSubset(
117519118723
const WhereLoop *pX, /* First WhereLoop to compare */
117520118724
const WhereLoop *pY /* Compare against this WhereLoop */
117521118725
){
117522118726
int i, j;
117523
- if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */
118727
+ if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
118728
+ return 0; /* X is not a subset of Y */
118729
+ }
118730
+ if( pY->nSkip > pX->nSkip ) return 0;
117524118731
if( pX->rRun >= pY->rRun ){
117525118732
if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
117526118733
if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
117527118734
}
117528118735
for(i=pX->nLTerm-1; i>=0; i--){
118736
+ if( pX->aLTerm[i]==0 ) continue;
117529118737
for(j=pY->nLTerm-1; j>=0; j--){
117530118738
if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
117531118739
}
117532118740
if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
117533118741
}
@@ -117545,37 +118753,28 @@
117545118753
** is a proper subset.
117546118754
**
117547118755
** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
117548118756
** WHERE clause terms than Y and that every WHERE clause term used by X is
117549118757
** also used by Y.
117550
-**
117551
-** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
117552
-** WhereLoop.nLTerm field is not an accurate measure of the number of WHERE
117553
-** clause terms covered, since some of the first nLTerm entries in aLTerm[]
117554
-** will be NULL (because they are skipped). That makes it more difficult
117555
-** to compare the loops. We could add extra code to do the comparison, and
117556
-** perhaps we will someday. But SKIPSCAN is sufficiently uncommon, and this
117557
-** adjustment is sufficient minor, that it is very difficult to construct
117558
-** a test case where the extra code would improve the query plan. Better
117559
-** to avoid the added complexity and just omit cost adjustments to SKIPSCAN
117560
-** loops.
117561118758
*/
117562118759
static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
117563118760
if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
117564
- if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return;
117565118761
for(; p; p=p->pNextLoop){
117566118762
if( p->iTab!=pTemplate->iTab ) continue;
117567118763
if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
117568
- if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue;
117569118764
if( whereLoopCheaperProperSubset(p, pTemplate) ){
117570118765
/* Adjust pTemplate cost downward so that it is cheaper than its
117571
- ** subset p */
118766
+ ** subset p. */
118767
+ WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118768
+ pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
117572118769
pTemplate->rRun = p->rRun;
117573118770
pTemplate->nOut = p->nOut - 1;
117574118771
}else if( whereLoopCheaperProperSubset(pTemplate, p) ){
117575118772
/* Adjust pTemplate cost upward so that it is costlier than p since
117576118773
** pTemplate is a proper subset of p */
118774
+ WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118775
+ pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1));
117577118776
pTemplate->rRun = p->rRun;
117578118777
pTemplate->nOut = p->nOut + 1;
117579118778
}
117580118779
}
117581118780
}
@@ -117616,12 +118815,13 @@
117616118815
** rSetup. Call this SETUP-INVARIANT */
117617118816
assert( p->rSetup>=pTemplate->rSetup );
117618118817
117619118818
/* Any loop using an appliation-defined index (or PRIMARY KEY or
117620118819
** UNIQUE constraint) with one or more == constraints is better
117621
- ** than an automatic index. */
118820
+ ** than an automatic index. Unless it is a skip-scan. */
117622118821
if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
118822
+ && (pTemplate->nSkip)==0
117623118823
&& (pTemplate->wsFlags & WHERE_INDEXED)!=0
117624118824
&& (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
117625118825
&& (p->prereq & pTemplate->prereq)==pTemplate->prereq
117626118826
){
117627118827
break;
@@ -117776,25 +118976,46 @@
117776118976
117777118977
/*
117778118978
** Adjust the WhereLoop.nOut value downward to account for terms of the
117779118979
** WHERE clause that reference the loop but which are not used by an
117780118980
** index.
118981
+*
118982
+** For every WHERE clause term that is not used by the index
118983
+** and which has a truth probability assigned by one of the likelihood(),
118984
+** likely(), or unlikely() SQL functions, reduce the estimated number
118985
+** of output rows by the probability specified.
117781118986
**
117782
-** In the current implementation, the first extra WHERE clause term reduces
117783
-** the number of output rows by a factor of 10 and each additional term
117784
-** reduces the number of output rows by sqrt(2).
118987
+** TUNING: For every WHERE clause term that is not used by the index
118988
+** and which does not have an assigned truth probability, heuristics
118989
+** described below are used to try to estimate the truth probability.
118990
+** TODO --> Perhaps this is something that could be improved by better
118991
+** table statistics.
118992
+**
118993
+** Heuristic 1: Estimate the truth probability as 93.75%. The 93.75%
118994
+** value corresponds to -1 in LogEst notation, so this means decrement
118995
+** the WhereLoop.nOut field for every such WHERE clause term.
118996
+**
118997
+** Heuristic 2: If there exists one or more WHERE clause terms of the
118998
+** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
118999
+** final output row estimate is no greater than 1/4 of the total number
119000
+** of rows in the table. In other words, assume that x==EXPR will filter
119001
+** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
119002
+** "x" column is boolean or else -1 or 0 or 1 is a common default value
119003
+** on the "x" column and so in that case only cap the output row estimate
119004
+** at 1/2 instead of 1/4.
117785119005
*/
117786119006
static void whereLoopOutputAdjust(
117787119007
WhereClause *pWC, /* The WHERE clause */
117788119008
WhereLoop *pLoop, /* The loop to adjust downward */
117789119009
LogEst nRow /* Number of rows in the entire table */
117790119010
){
117791119011
WhereTerm *pTerm, *pX;
117792119012
Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
117793
- int i, j;
117794
- int nEq = 0; /* Number of = constraints not within likely()/unlikely() */
119013
+ int i, j, k;
119014
+ LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
117795119015
119016
+ assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
117796119017
for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
117797119018
if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
117798119019
if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
117799119020
if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
117800119021
for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117803,24 +119024,30 @@
117803119024
if( pX==pTerm ) break;
117804119025
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
117805119026
}
117806119027
if( j<0 ){
117807119028
if( pTerm->truthProb<=0 ){
119029
+ /* If a truth probability is specified using the likelihood() hints,
119030
+ ** then use the probability provided by the application. */
117808119031
pLoop->nOut += pTerm->truthProb;
117809119032
}else{
119033
+ /* In the absence of explicit truth probabilities, use heuristics to
119034
+ ** guess a reasonable truth probability. */
117810119035
pLoop->nOut--;
117811
- if( pTerm->eOperator&WO_EQ ) nEq++;
119036
+ if( pTerm->eOperator&WO_EQ ){
119037
+ Expr *pRight = pTerm->pExpr->pRight;
119038
+ if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){
119039
+ k = 10;
119040
+ }else{
119041
+ k = 20;
119042
+ }
119043
+ if( iReduce<k ) iReduce = k;
119044
+ }
117812119045
}
117813119046
}
117814119047
}
117815
- /* TUNING: If there is at least one equality constraint in the WHERE
117816
- ** clause that does not have a likelihood() explicitly assigned to it
117817
- ** then do not let the estimated number of output rows exceed half
117818
- ** the number of rows in the table. */
117819
- if( nEq && pLoop->nOut>nRow-10 ){
117820
- pLoop->nOut = nRow - 10;
117821
- }
119048
+ if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce;
117822119049
}
117823119050
117824119051
/*
117825119052
** Adjust the cost C by the costMult facter T. This only occurs if
117826119053
** compiled with -DSQLITE_ENABLE_COSTMULT
@@ -117857,11 +119084,11 @@
117857119084
int opMask; /* Valid operators for constraints */
117858119085
WhereScan scan; /* Iterator for WHERE terms */
117859119086
Bitmask saved_prereq; /* Original value of pNew->prereq */
117860119087
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
117861119088
u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
117862
- u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
119089
+ u16 saved_nSkip; /* Original value of pNew->nSkip */
117863119090
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117864119091
LogEst saved_nOut; /* Original value of pNew->nOut */
117865119092
int iCol; /* Index of the column in the table */
117866119093
int rc = SQLITE_OK; /* Return code */
117867119094
LogEst rSize; /* Number of rows in the table */
@@ -117886,56 +119113,18 @@
117886119113
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
117887119114
117888119115
pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
117889119116
opMask, pProbe);
117890119117
saved_nEq = pNew->u.btree.nEq;
117891
- saved_nSkip = pNew->u.btree.nSkip;
119118
+ saved_nSkip = pNew->nSkip;
117892119119
saved_nLTerm = pNew->nLTerm;
117893119120
saved_wsFlags = pNew->wsFlags;
117894119121
saved_prereq = pNew->prereq;
117895119122
saved_nOut = pNew->nOut;
117896119123
pNew->rSetup = 0;
117897119124
rSize = pProbe->aiRowLogEst[0];
117898119125
rLogSize = estLog(rSize);
117899
-
117900
- /* Consider using a skip-scan if there are no WHERE clause constraints
117901
- ** available for the left-most terms of the index, and if the average
117902
- ** number of repeats in the left-most terms is at least 18.
117903
- **
117904
- ** The magic number 18 is selected on the basis that scanning 17 rows
117905
- ** is almost always quicker than an index seek (even though if the index
117906
- ** contains fewer than 2^17 rows we assume otherwise in other parts of
117907
- ** the code). And, even if it is not, it should not be too much slower.
117908
- ** On the other hand, the extra seeks could end up being significantly
117909
- ** more expensive. */
117910
- assert( 42==sqlite3LogEst(18) );
117911
- if( saved_nEq==saved_nSkip
117912
- && saved_nEq+1<pProbe->nKeyCol
117913
- && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
117914
- && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
117915
- ){
117916
- LogEst nIter;
117917
- pNew->u.btree.nEq++;
117918
- pNew->u.btree.nSkip++;
117919
- pNew->aLTerm[pNew->nLTerm++] = 0;
117920
- pNew->wsFlags |= WHERE_SKIPSCAN;
117921
- nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117922
- if( pTerm ){
117923
- /* TUNING: When estimating skip-scan for a term that is also indexable,
117924
- ** multiply the cost of the skip-scan by 2.0, to make it a little less
117925
- ** desirable than the regular index lookup. */
117926
- nIter += 10; assert( 10==sqlite3LogEst(2) );
117927
- }
117928
- pNew->nOut -= nIter;
117929
- /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117930
- ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117931
- nIter += 5;
117932
- whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117933
- pNew->nOut = saved_nOut;
117934
- pNew->u.btree.nEq = saved_nEq;
117935
- pNew->u.btree.nSkip = saved_nSkip;
117936
- }
117937119126
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
117938119127
u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
117939119128
LogEst rCostIdx;
117940119129
LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
117941119130
int nIn = 0;
@@ -118026,11 +119215,10 @@
118026119215
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
118027119216
tRowcnt nOut = 0;
118028119217
if( nInMul==0
118029119218
&& pProbe->nSample
118030119219
&& pNew->u.btree.nEq<=pProbe->nSampleCol
118031
- && OptimizationEnabled(db, SQLITE_Stat3)
118032119220
&& ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
118033119221
){
118034119222
Expr *pExpr = pTerm->pExpr;
118035119223
if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
118036119224
testcase( eOp & WO_EQ );
@@ -118094,14 +119282,49 @@
118094119282
pBuilder->nRecValid = nRecValid;
118095119283
#endif
118096119284
}
118097119285
pNew->prereq = saved_prereq;
118098119286
pNew->u.btree.nEq = saved_nEq;
118099
- pNew->u.btree.nSkip = saved_nSkip;
119287
+ pNew->nSkip = saved_nSkip;
118100119288
pNew->wsFlags = saved_wsFlags;
118101119289
pNew->nOut = saved_nOut;
118102119290
pNew->nLTerm = saved_nLTerm;
119291
+
119292
+ /* Consider using a skip-scan if there are no WHERE clause constraints
119293
+ ** available for the left-most terms of the index, and if the average
119294
+ ** number of repeats in the left-most terms is at least 18.
119295
+ **
119296
+ ** The magic number 18 is selected on the basis that scanning 17 rows
119297
+ ** is almost always quicker than an index seek (even though if the index
119298
+ ** contains fewer than 2^17 rows we assume otherwise in other parts of
119299
+ ** the code). And, even if it is not, it should not be too much slower.
119300
+ ** On the other hand, the extra seeks could end up being significantly
119301
+ ** more expensive. */
119302
+ assert( 42==sqlite3LogEst(18) );
119303
+ if( saved_nEq==saved_nSkip
119304
+ && saved_nEq+1<pProbe->nKeyCol
119305
+ && pProbe->noSkipScan==0
119306
+ && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
119307
+ && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
119308
+ ){
119309
+ LogEst nIter;
119310
+ pNew->u.btree.nEq++;
119311
+ pNew->nSkip++;
119312
+ pNew->aLTerm[pNew->nLTerm++] = 0;
119313
+ pNew->wsFlags |= WHERE_SKIPSCAN;
119314
+ nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
119315
+ pNew->nOut -= nIter;
119316
+ /* TUNING: Because uncertainties in the estimates for skip-scan queries,
119317
+ ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
119318
+ nIter += 5;
119319
+ whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
119320
+ pNew->nOut = saved_nOut;
119321
+ pNew->u.btree.nEq = saved_nEq;
119322
+ pNew->nSkip = saved_nSkip;
119323
+ pNew->wsFlags = saved_wsFlags;
119324
+ }
119325
+
118103119326
return rc;
118104119327
}
118105119328
118106119329
/*
118107119330
** Return True if it is possible that pIndex might be useful in
@@ -118276,11 +119499,11 @@
118276119499
WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
118277119500
for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
118278119501
if( pTerm->prereqRight & pNew->maskSelf ) continue;
118279119502
if( termCanDriveIndex(pTerm, pSrc, 0) ){
118280119503
pNew->u.btree.nEq = 1;
118281
- pNew->u.btree.nSkip = 0;
119504
+ pNew->nSkip = 0;
118282119505
pNew->u.btree.pIndex = 0;
118283119506
pNew->nLTerm = 1;
118284119507
pNew->aLTerm[0] = pTerm;
118285119508
/* TUNING: One-time cost for computing the automatic index is
118286119509
** estimated to be X*N*log2(N) where N is the number of rows in
@@ -118317,11 +119540,11 @@
118317119540
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
118318119541
continue; /* Partial index inappropriate for this query */
118319119542
}
118320119543
rSize = pProbe->aiRowLogEst[0];
118321119544
pNew->u.btree.nEq = 0;
118322
- pNew->u.btree.nSkip = 0;
119545
+ pNew->nSkip = 0;
118323119546
pNew->nLTerm = 0;
118324119547
pNew->iSortIdx = 0;
118325119548
pNew->rSetup = 0;
118326119549
pNew->prereq = mExtra;
118327119550
pNew->nOut = rSize;
@@ -118867,11 +120090,11 @@
118867120090
for(j=0; j<nColumn; j++){
118868120091
u8 bOnce; /* True to run the ORDER BY search loop */
118869120092
118870120093
/* Skip over == and IS NULL terms */
118871120094
if( j<pLoop->u.btree.nEq
118872
- && pLoop->u.btree.nSkip==0
120095
+ && pLoop->nSkip==0
118873120096
&& ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
118874120097
){
118875120098
if( i & WO_ISNULL ){
118876120099
testcase( isOrderDistinct );
118877120100
isOrderDistinct = 0;
@@ -119321,11 +120544,11 @@
119321120544
}
119322120545
}
119323120546
}
119324120547
119325120548
#ifdef WHERETRACE_ENABLED /* >=2 */
119326
- if( sqlite3WhereTrace>=2 ){
120549
+ if( sqlite3WhereTrace & 0x02 ){
119327120550
sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
119328120551
for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
119329120552
sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
119330120553
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
119331120554
pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -119440,11 +120663,11 @@
119440120663
if( pItem->zIndex ) return 0;
119441120664
iCur = pItem->iCursor;
119442120665
pWC = &pWInfo->sWC;
119443120666
pLoop = pBuilder->pNew;
119444120667
pLoop->wsFlags = 0;
119445
- pLoop->u.btree.nSkip = 0;
120668
+ pLoop->nSkip = 0;
119446120669
pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
119447120670
if( pTerm ){
119448120671
pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
119449120672
pLoop->aLTerm[0] = pTerm;
119450120673
pLoop->nLTerm = 1;
@@ -119452,11 +120675,10 @@
119452120675
/* TUNING: Cost of a rowid lookup is 10 */
119453120676
pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
119454120677
}else{
119455120678
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
119456120679
assert( pLoop->aLTermSpace==pLoop->aLTerm );
119457
- assert( ArraySize(pLoop->aLTermSpace)==4 );
119458120680
if( !IsUniqueIndex(pIdx)
119459120681
|| pIdx->pPartIdxWhere!=0
119460120682
|| pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
119461120683
) continue;
119462120684
for(j=0; j<pIdx->nKeyCol; j++){
@@ -119961,22 +121183,30 @@
119961121183
** loop below generates code for a single nested loop of the VM
119962121184
** program.
119963121185
*/
119964121186
notReady = ~(Bitmask)0;
119965121187
for(ii=0; ii<nTabList; ii++){
121188
+ int addrExplain;
121189
+ int wsFlags;
119966121190
pLevel = &pWInfo->a[ii];
121191
+ wsFlags = pLevel->pWLoop->wsFlags;
119967121192
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
119968121193
if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
119969121194
constructAutomaticIndex(pParse, &pWInfo->sWC,
119970121195
&pTabList->a[pLevel->iFrom], notReady, pLevel);
119971121196
if( db->mallocFailed ) goto whereBeginError;
119972121197
}
119973121198
#endif
119974
- explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
121199
+ addrExplain = explainOneScan(
121200
+ pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
121201
+ );
119975121202
pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
119976121203
notReady = codeOneLoopStart(pWInfo, ii, notReady);
119977121204
pWInfo->iContinue = pLevel->addrCont;
121205
+ if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){
121206
+ addScanStatus(v, pTabList, pLevel, addrExplain);
121207
+ }
119978121208
}
119979121209
119980121210
/* Done. */
119981121211
VdbeModuleComment((v, "Begin WHERE-core"));
119982121212
return pWInfo;
@@ -124640,10 +125870,17 @@
124640125870
** is look for a semicolon that is not part of an string or comment.
124641125871
*/
124642125872
SQLITE_API int sqlite3_complete(const char *zSql){
124643125873
u8 state = 0; /* Current state, using numbers defined in header comment */
124644125874
u8 token; /* Value of the next token */
125875
+
125876
+#ifdef SQLITE_ENABLE_API_ARMOR
125877
+ if( zSql==0 ){
125878
+ (void)SQLITE_MISUSE_BKPT;
125879
+ return 0;
125880
+ }
125881
+#endif
124645125882
124646125883
#ifndef SQLITE_OMIT_TRIGGER
124647125884
/* A complex statement machine used to detect the end of a CREATE TRIGGER
124648125885
** statement. This is the normal case.
124649125886
*/
@@ -125238,74 +126475,106 @@
125238126475
125239126476
va_start(ap, op);
125240126477
switch( op ){
125241126478
125242126479
/* Mutex configuration options are only available in a threadsafe
125243
- ** compile.
126480
+ ** compile.
125244126481
*/
125245
-#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0
126482
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
125246126483
case SQLITE_CONFIG_SINGLETHREAD: {
125247126484
/* Disable all mutexing */
125248126485
sqlite3GlobalConfig.bCoreMutex = 0;
125249126486
sqlite3GlobalConfig.bFullMutex = 0;
125250126487
break;
125251126488
}
126489
+#endif
126490
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
125252126491
case SQLITE_CONFIG_MULTITHREAD: {
125253126492
/* Disable mutexing of database connections */
125254126493
/* Enable mutexing of core data structures */
125255126494
sqlite3GlobalConfig.bCoreMutex = 1;
125256126495
sqlite3GlobalConfig.bFullMutex = 0;
125257126496
break;
125258126497
}
126498
+#endif
126499
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
125259126500
case SQLITE_CONFIG_SERIALIZED: {
125260126501
/* Enable all mutexing */
125261126502
sqlite3GlobalConfig.bCoreMutex = 1;
125262126503
sqlite3GlobalConfig.bFullMutex = 1;
125263126504
break;
125264126505
}
126506
+#endif
126507
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
125265126508
case SQLITE_CONFIG_MUTEX: {
125266126509
/* Specify an alternative mutex implementation */
125267126510
sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
125268126511
break;
125269126512
}
126513
+#endif
126514
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
125270126515
case SQLITE_CONFIG_GETMUTEX: {
125271126516
/* Retrieve the current mutex implementation */
125272126517
*va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
125273126518
break;
125274126519
}
125275126520
#endif
125276126521
125277
-
125278126522
case SQLITE_CONFIG_MALLOC: {
125279
- /* Specify an alternative malloc implementation */
126523
+ /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
126524
+ ** single argument which is a pointer to an instance of the
126525
+ ** sqlite3_mem_methods structure. The argument specifies alternative
126526
+ ** low-level memory allocation routines to be used in place of the memory
126527
+ ** allocation routines built into SQLite. */
125280126528
sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
125281126529
break;
125282126530
}
125283126531
case SQLITE_CONFIG_GETMALLOC: {
125284
- /* Retrieve the current malloc() implementation */
126532
+ /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
126533
+ ** single argument which is a pointer to an instance of the
126534
+ ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
126535
+ ** filled with the currently defined memory allocation routines. */
125285126536
if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
125286126537
*va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
125287126538
break;
125288126539
}
125289126540
case SQLITE_CONFIG_MEMSTATUS: {
125290
- /* Enable or disable the malloc status collection */
126541
+ /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
126542
+ ** single argument of type int, interpreted as a boolean, which enables
126543
+ ** or disables the collection of memory allocation statistics. */
125291126544
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
125292126545
break;
125293126546
}
125294126547
case SQLITE_CONFIG_SCRATCH: {
125295
- /* Designate a buffer for scratch memory space */
126548
+ /* EVIDENCE-OF: R-08404-60887 There are three arguments to
126549
+ ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
126550
+ ** which the scratch allocations will be drawn, the size of each scratch
126551
+ ** allocation (sz), and the maximum number of scratch allocations (N). */
125296126552
sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
125297126553
sqlite3GlobalConfig.szScratch = va_arg(ap, int);
125298126554
sqlite3GlobalConfig.nScratch = va_arg(ap, int);
125299126555
break;
125300126556
}
125301126557
case SQLITE_CONFIG_PAGECACHE: {
125302
- /* Designate a buffer for page cache memory space */
126558
+ /* EVIDENCE-OF: R-31408-40510 There are three arguments to
126559
+ ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size
126560
+ ** of each page buffer (sz), and the number of pages (N). */
125303126561
sqlite3GlobalConfig.pPage = va_arg(ap, void*);
125304126562
sqlite3GlobalConfig.szPage = va_arg(ap, int);
125305126563
sqlite3GlobalConfig.nPage = va_arg(ap, int);
125306126564
break;
126565
+ }
126566
+ case SQLITE_CONFIG_PCACHE_HDRSZ: {
126567
+ /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
126568
+ ** a single parameter which is a pointer to an integer and writes into
126569
+ ** that integer the number of extra bytes per page required for each page
126570
+ ** in SQLITE_CONFIG_PAGECACHE. */
126571
+ *va_arg(ap, int*) =
126572
+ sqlite3HeaderSizeBtree() +
126573
+ sqlite3HeaderSizePcache() +
126574
+ sqlite3HeaderSizePcache1();
126575
+ break;
125307126576
}
125308126577
125309126578
case SQLITE_CONFIG_PCACHE: {
125310126579
/* no-op */
125311126580
break;
@@ -125315,25 +126584,37 @@
125315126584
rc = SQLITE_ERROR;
125316126585
break;
125317126586
}
125318126587
125319126588
case SQLITE_CONFIG_PCACHE2: {
125320
- /* Specify an alternative page cache implementation */
126589
+ /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
126590
+ ** single argument which is a pointer to an sqlite3_pcache_methods2
126591
+ ** object. This object specifies the interface to a custom page cache
126592
+ ** implementation. */
125321126593
sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
125322126594
break;
125323126595
}
125324126596
case SQLITE_CONFIG_GETPCACHE2: {
126597
+ /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
126598
+ ** single argument which is a pointer to an sqlite3_pcache_methods2
126599
+ ** object. SQLite copies of the current page cache implementation into
126600
+ ** that object. */
125325126601
if( sqlite3GlobalConfig.pcache2.xInit==0 ){
125326126602
sqlite3PCacheSetDefault();
125327126603
}
125328126604
*va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
125329126605
break;
125330126606
}
125331126607
126608
+/* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
126609
+** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
126610
+** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
125332126611
#if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
125333126612
case SQLITE_CONFIG_HEAP: {
125334
- /* Designate a buffer for heap memory space */
126613
+ /* EVIDENCE-OF: R-19854-42126 There are three arguments to
126614
+ ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
126615
+ ** number of bytes in the memory buffer, and the minimum allocation size. */
125335126616
sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
125336126617
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125337126618
sqlite3GlobalConfig.mnReq = va_arg(ap, int);
125338126619
125339126620
if( sqlite3GlobalConfig.mnReq<1 ){
@@ -125342,21 +126623,23 @@
125342126623
/* cap min request size at 2^12 */
125343126624
sqlite3GlobalConfig.mnReq = (1<<12);
125344126625
}
125345126626
125346126627
if( sqlite3GlobalConfig.pHeap==0 ){
125347
- /* If the heap pointer is NULL, then restore the malloc implementation
125348
- ** back to NULL pointers too. This will cause the malloc to go
125349
- ** back to its default implementation when sqlite3_initialize() is
125350
- ** run.
126628
+ /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
126629
+ ** is NULL, then SQLite reverts to using its default memory allocator
126630
+ ** (the system malloc() implementation), undoing any prior invocation of
126631
+ ** SQLITE_CONFIG_MALLOC.
126632
+ **
126633
+ ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
126634
+ ** revert to its default implementation when sqlite3_initialize() is run
125351126635
*/
125352126636
memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
125353126637
}else{
125354
- /* The heap pointer is not NULL, then install one of the
125355
- ** mem5.c/mem3.c methods. The enclosing #if guarantees at
125356
- ** least one of these methods is currently enabled.
125357
- */
126638
+ /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
126639
+ ** alternative memory allocator is engaged to handle all of SQLites
126640
+ ** memory allocation needs. */
125358126641
#ifdef SQLITE_ENABLE_MEMSYS3
125359126642
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
125360126643
#endif
125361126644
#ifdef SQLITE_ENABLE_MEMSYS5
125362126645
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -125391,15 +126674,23 @@
125391126674
** can be changed at start-time using the
125392126675
** sqlite3_config(SQLITE_CONFIG_URI,1) or
125393126676
** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
125394126677
*/
125395126678
case SQLITE_CONFIG_URI: {
126679
+ /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
126680
+ ** argument of type int. If non-zero, then URI handling is globally
126681
+ ** enabled. If the parameter is zero, then URI handling is globally
126682
+ ** disabled. */
125396126683
sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125397126684
break;
125398126685
}
125399126686
125400126687
case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
126688
+ /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
126689
+ ** option takes a single integer argument which is interpreted as a
126690
+ ** boolean in order to enable or disable the use of covering indices for
126691
+ ** full table scans in the query optimizer. */
125401126692
sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
125402126693
break;
125403126694
}
125404126695
125405126696
#ifdef SQLITE_ENABLE_SQLLOG
@@ -125410,24 +126701,37 @@
125410126701
break;
125411126702
}
125412126703
#endif
125413126704
125414126705
case SQLITE_CONFIG_MMAP_SIZE: {
126706
+ /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
126707
+ ** integer (sqlite3_int64) values that are the default mmap size limit
126708
+ ** (the default setting for PRAGMA mmap_size) and the maximum allowed
126709
+ ** mmap size limit. */
125415126710
sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
125416126711
sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
125417
- if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
125418
- mxMmap = SQLITE_MAX_MMAP_SIZE;
125419
- }
125420
- sqlite3GlobalConfig.mxMmap = mxMmap;
126712
+ /* EVIDENCE-OF: R-53367-43190 If either argument to this option is
126713
+ ** negative, then that argument is changed to its compile-time default.
126714
+ **
126715
+ ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
126716
+ ** silently truncated if necessary so that it does not exceed the
126717
+ ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
126718
+ ** compile-time option.
126719
+ */
126720
+ if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
125421126721
if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
125422126722
if( szMmap>mxMmap) szMmap = mxMmap;
126723
+ sqlite3GlobalConfig.mxMmap = mxMmap;
125423126724
sqlite3GlobalConfig.szMmap = szMmap;
125424126725
break;
125425126726
}
125426126727
125427
-#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
126728
+#if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
125428126729
case SQLITE_CONFIG_WIN32_HEAPSIZE: {
126730
+ /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
126731
+ ** unsigned integer value that specifies the maximum size of the created
126732
+ ** heap. */
125429126733
sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125430126734
break;
125431126735
}
125432126736
#endif
125433126737
@@ -125507,19 +126811,29 @@
125507126811
125508126812
/*
125509126813
** Return the mutex associated with a database connection.
125510126814
*/
125511126815
SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
126816
+#ifdef SQLITE_ENABLE_API_ARMOR
126817
+ if( !sqlite3SafetyCheckOk(db) ){
126818
+ (void)SQLITE_MISUSE_BKPT;
126819
+ return 0;
126820
+ }
126821
+#endif
125512126822
return db->mutex;
125513126823
}
125514126824
125515126825
/*
125516126826
** Free up as much memory as we can from the given database
125517126827
** connection.
125518126828
*/
125519126829
SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
125520126830
int i;
126831
+
126832
+#ifdef SQLITE_ENABLE_API_ARMOR
126833
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
126834
+#endif
125521126835
sqlite3_mutex_enter(db->mutex);
125522126836
sqlite3BtreeEnterAll(db);
125523126837
for(i=0; i<db->nDb; i++){
125524126838
Btree *pBt = db->aDb[i].pBt;
125525126839
if( pBt ){
@@ -125605,17 +126919,24 @@
125605126919
int nKey1, const void *pKey1,
125606126920
int nKey2, const void *pKey2
125607126921
){
125608126922
int rc, n;
125609126923
n = nKey1<nKey2 ? nKey1 : nKey2;
126924
+ /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
126925
+ ** strings byte by byte using the memcmp() function from the standard C
126926
+ ** library. */
125610126927
rc = memcmp(pKey1, pKey2, n);
125611126928
if( rc==0 ){
125612126929
if( padFlag
125613126930
&& allSpaces(((char*)pKey1)+n, nKey1-n)
125614126931
&& allSpaces(((char*)pKey2)+n, nKey2-n)
125615126932
){
125616
- /* Leave rc unchanged at 0 */
126933
+ /* EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra
126934
+ ** spaces at the end of either string do not change the result. In other
126935
+ ** words, strings will compare equal to one another as long as they
126936
+ ** differ only in the number of spaces at the end.
126937
+ */
125617126938
}else{
125618126939
rc = nKey1 - nKey2;
125619126940
}
125620126941
}
125621126942
return rc;
@@ -125646,24 +126967,42 @@
125646126967
125647126968
/*
125648126969
** Return the ROWID of the most recent insert
125649126970
*/
125650126971
SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
126972
+#ifdef SQLITE_ENABLE_API_ARMOR
126973
+ if( !sqlite3SafetyCheckOk(db) ){
126974
+ (void)SQLITE_MISUSE_BKPT;
126975
+ return 0;
126976
+ }
126977
+#endif
125651126978
return db->lastRowid;
125652126979
}
125653126980
125654126981
/*
125655126982
** Return the number of changes in the most recent call to sqlite3_exec().
125656126983
*/
125657126984
SQLITE_API int sqlite3_changes(sqlite3 *db){
126985
+#ifdef SQLITE_ENABLE_API_ARMOR
126986
+ if( !sqlite3SafetyCheckOk(db) ){
126987
+ (void)SQLITE_MISUSE_BKPT;
126988
+ return 0;
126989
+ }
126990
+#endif
125658126991
return db->nChange;
125659126992
}
125660126993
125661126994
/*
125662126995
** Return the number of changes since the database handle was opened.
125663126996
*/
125664126997
SQLITE_API int sqlite3_total_changes(sqlite3 *db){
126998
+#ifdef SQLITE_ENABLE_API_ARMOR
126999
+ if( !sqlite3SafetyCheckOk(db) ){
127000
+ (void)SQLITE_MISUSE_BKPT;
127001
+ return 0;
127002
+ }
127003
+#endif
125665127004
return db->nTotalChange;
125666127005
}
125667127006
125668127007
/*
125669127008
** Close all open savepoints. This function only manipulates fields of the
@@ -125839,10 +127178,20 @@
125839127178
125840127179
/* Close all database connections */
125841127180
for(j=0; j<db->nDb; j++){
125842127181
struct Db *pDb = &db->aDb[j];
125843127182
if( pDb->pBt ){
127183
+ if( pDb->pSchema ){
127184
+ /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185
+ sqlite3BtreeEnter(pDb->pBt);
127186
+ for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187
+ Index *pIdx = sqliteHashData(i);
127188
+ sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189
+ pIdx->pKeyInfo = 0;
127190
+ }
127191
+ sqlite3BtreeLeave(pDb->pBt);
127192
+ }
125844127193
sqlite3BtreeClose(pDb->pBt);
125845127194
pDb->pBt = 0;
125846127195
if( j!=1 ){
125847127196
pDb->pSchema = 0;
125848127197
}
@@ -125925,17 +127274,19 @@
125925127274
sqlite3_free(db);
125926127275
}
125927127276
125928127277
/*
125929127278
** Rollback all database files. If tripCode is not SQLITE_OK, then
125930
-** any open cursors are invalidated ("tripped" - as in "tripping a circuit
127279
+** any write cursors are invalidated ("tripped" - as in "tripping a circuit
125931127280
** breaker") and made to return tripCode if there are any further
125932
-** attempts to use that cursor.
127281
+** attempts to use that cursor. Read cursors remain open and valid
127282
+** but are "saved" in case the table pages are moved around.
125933127283
*/
125934127284
SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
125935127285
int i;
125936127286
int inTrans = 0;
127287
+ int schemaChange;
125937127288
assert( sqlite3_mutex_held(db->mutex) );
125938127289
sqlite3BeginBenignMalloc();
125939127290
125940127291
/* Obtain all b-tree mutexes before making any calls to BtreeRollback().
125941127292
** This is important in case the transaction being rolled back has
@@ -125942,18 +127293,19 @@
125942127293
** modified the database schema. If the b-tree mutexes are not taken
125943127294
** here, then another shared-cache connection might sneak in between
125944127295
** the database rollback and schema reset, which can cause false
125945127296
** corruption reports in some cases. */
125946127297
sqlite3BtreeEnterAll(db);
127298
+ schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
125947127299
125948127300
for(i=0; i<db->nDb; i++){
125949127301
Btree *p = db->aDb[i].pBt;
125950127302
if( p ){
125951127303
if( sqlite3BtreeIsInTrans(p) ){
125952127304
inTrans = 1;
125953127305
}
125954
- sqlite3BtreeRollback(p, tripCode);
127306
+ sqlite3BtreeRollback(p, tripCode, !schemaChange);
125955127307
}
125956127308
}
125957127309
sqlite3VtabRollback(db);
125958127310
sqlite3EndBenignMalloc();
125959127311
@@ -126205,10 +127557,13 @@
126205127557
SQLITE_API int sqlite3_busy_handler(
126206127558
sqlite3 *db,
126207127559
int (*xBusy)(void*,int),
126208127560
void *pArg
126209127561
){
127562
+#ifdef SQLITE_ENABLE_API_ARMOR
127563
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
127564
+#endif
126210127565
sqlite3_mutex_enter(db->mutex);
126211127566
db->busyHandler.xFunc = xBusy;
126212127567
db->busyHandler.pArg = pArg;
126213127568
db->busyHandler.nBusy = 0;
126214127569
db->busyTimeout = 0;
@@ -126226,10 +127581,16 @@
126226127581
sqlite3 *db,
126227127582
int nOps,
126228127583
int (*xProgress)(void*),
126229127584
void *pArg
126230127585
){
127586
+#ifdef SQLITE_ENABLE_API_ARMOR
127587
+ if( !sqlite3SafetyCheckOk(db) ){
127588
+ (void)SQLITE_MISUSE_BKPT;
127589
+ return;
127590
+ }
127591
+#endif
126231127592
sqlite3_mutex_enter(db->mutex);
126232127593
if( nOps>0 ){
126233127594
db->xProgress = xProgress;
126234127595
db->nProgressOps = (unsigned)nOps;
126235127596
db->pProgressArg = pArg;
@@ -126246,10 +127607,13 @@
126246127607
/*
126247127608
** This routine installs a default busy handler that waits for the
126248127609
** specified number of milliseconds before returning 0.
126249127610
*/
126250127611
SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
127612
+#ifdef SQLITE_ENABLE_API_ARMOR
127613
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127614
+#endif
126251127615
if( ms>0 ){
126252127616
sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
126253127617
db->busyTimeout = ms;
126254127618
}else{
126255127619
sqlite3_busy_handler(db, 0, 0);
@@ -126259,10 +127623,16 @@
126259127623
126260127624
/*
126261127625
** Cause any pending operation to stop at its earliest opportunity.
126262127626
*/
126263127627
SQLITE_API void sqlite3_interrupt(sqlite3 *db){
127628
+#ifdef SQLITE_ENABLE_API_ARMOR
127629
+ if( !sqlite3SafetyCheckOk(db) ){
127630
+ (void)SQLITE_MISUSE_BKPT;
127631
+ return;
127632
+ }
127633
+#endif
126264127634
db->u1.isInterrupted = 1;
126265127635
}
126266127636
126267127637
126268127638
/*
@@ -126396,10 +127766,16 @@
126396127766
void (*xFinal)(sqlite3_context*),
126397127767
void (*xDestroy)(void *)
126398127768
){
126399127769
int rc = SQLITE_ERROR;
126400127770
FuncDestructor *pArg = 0;
127771
+
127772
+#ifdef SQLITE_ENABLE_API_ARMOR
127773
+ if( !sqlite3SafetyCheckOk(db) ){
127774
+ return SQLITE_MISUSE_BKPT;
127775
+ }
127776
+#endif
126401127777
sqlite3_mutex_enter(db->mutex);
126402127778
if( xDestroy ){
126403127779
pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
126404127780
if( !pArg ){
126405127781
xDestroy(p);
@@ -126432,10 +127808,14 @@
126432127808
void (*xStep)(sqlite3_context*,int,sqlite3_value**),
126433127809
void (*xFinal)(sqlite3_context*)
126434127810
){
126435127811
int rc;
126436127812
char *zFunc8;
127813
+
127814
+#ifdef SQLITE_ENABLE_API_ARMOR
127815
+ if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
127816
+#endif
126437127817
sqlite3_mutex_enter(db->mutex);
126438127818
assert( !db->mallocFailed );
126439127819
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
126440127820
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
126441127821
sqlite3DbFree(db, zFunc8);
@@ -126463,10 +127843,16 @@
126463127843
const char *zName,
126464127844
int nArg
126465127845
){
126466127846
int nName = sqlite3Strlen30(zName);
126467127847
int rc = SQLITE_OK;
127848
+
127849
+#ifdef SQLITE_ENABLE_API_ARMOR
127850
+ if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
127851
+ return SQLITE_MISUSE_BKPT;
127852
+ }
127853
+#endif
126468127854
sqlite3_mutex_enter(db->mutex);
126469127855
if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
126470127856
rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
126471127857
0, sqlite3InvalidFunction, 0, 0, 0);
126472127858
}
@@ -126484,10 +127870,17 @@
126484127870
** trace is a pointer to a function that is invoked at the start of each
126485127871
** SQL statement.
126486127872
*/
126487127873
SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
126488127874
void *pOld;
127875
+
127876
+#ifdef SQLITE_ENABLE_API_ARMOR
127877
+ if( !sqlite3SafetyCheckOk(db) ){
127878
+ (void)SQLITE_MISUSE_BKPT;
127879
+ return 0;
127880
+ }
127881
+#endif
126489127882
sqlite3_mutex_enter(db->mutex);
126490127883
pOld = db->pTraceArg;
126491127884
db->xTrace = xTrace;
126492127885
db->pTraceArg = pArg;
126493127886
sqlite3_mutex_leave(db->mutex);
@@ -126505,10 +127898,17 @@
126505127898
sqlite3 *db,
126506127899
void (*xProfile)(void*,const char*,sqlite_uint64),
126507127900
void *pArg
126508127901
){
126509127902
void *pOld;
127903
+
127904
+#ifdef SQLITE_ENABLE_API_ARMOR
127905
+ if( !sqlite3SafetyCheckOk(db) ){
127906
+ (void)SQLITE_MISUSE_BKPT;
127907
+ return 0;
127908
+ }
127909
+#endif
126510127910
sqlite3_mutex_enter(db->mutex);
126511127911
pOld = db->pProfileArg;
126512127912
db->xProfile = xProfile;
126513127913
db->pProfileArg = pArg;
126514127914
sqlite3_mutex_leave(db->mutex);
@@ -126525,10 +127925,17 @@
126525127925
sqlite3 *db, /* Attach the hook to this database */
126526127926
int (*xCallback)(void*), /* Function to invoke on each commit */
126527127927
void *pArg /* Argument to the function */
126528127928
){
126529127929
void *pOld;
127930
+
127931
+#ifdef SQLITE_ENABLE_API_ARMOR
127932
+ if( !sqlite3SafetyCheckOk(db) ){
127933
+ (void)SQLITE_MISUSE_BKPT;
127934
+ return 0;
127935
+ }
127936
+#endif
126530127937
sqlite3_mutex_enter(db->mutex);
126531127938
pOld = db->pCommitArg;
126532127939
db->xCommitCallback = xCallback;
126533127940
db->pCommitArg = pArg;
126534127941
sqlite3_mutex_leave(db->mutex);
@@ -126543,10 +127950,17 @@
126543127950
sqlite3 *db, /* Attach the hook to this database */
126544127951
void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
126545127952
void *pArg /* Argument to the function */
126546127953
){
126547127954
void *pRet;
127955
+
127956
+#ifdef SQLITE_ENABLE_API_ARMOR
127957
+ if( !sqlite3SafetyCheckOk(db) ){
127958
+ (void)SQLITE_MISUSE_BKPT;
127959
+ return 0;
127960
+ }
127961
+#endif
126548127962
sqlite3_mutex_enter(db->mutex);
126549127963
pRet = db->pUpdateArg;
126550127964
db->xUpdateCallback = xCallback;
126551127965
db->pUpdateArg = pArg;
126552127966
sqlite3_mutex_leave(db->mutex);
@@ -126561,10 +127975,17 @@
126561127975
sqlite3 *db, /* Attach the hook to this database */
126562127976
void (*xCallback)(void*), /* Callback function */
126563127977
void *pArg /* Argument to the function */
126564127978
){
126565127979
void *pRet;
127980
+
127981
+#ifdef SQLITE_ENABLE_API_ARMOR
127982
+ if( !sqlite3SafetyCheckOk(db) ){
127983
+ (void)SQLITE_MISUSE_BKPT;
127984
+ return 0;
127985
+ }
127986
+#endif
126566127987
sqlite3_mutex_enter(db->mutex);
126567127988
pRet = db->pRollbackArg;
126568127989
db->xRollbackCallback = xCallback;
126569127990
db->pRollbackArg = pArg;
126570127991
sqlite3_mutex_leave(db->mutex);
@@ -126607,10 +128028,13 @@
126607128028
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
126608128029
#ifdef SQLITE_OMIT_WAL
126609128030
UNUSED_PARAMETER(db);
126610128031
UNUSED_PARAMETER(nFrame);
126611128032
#else
128033
+#ifdef SQLITE_ENABLE_API_ARMOR
128034
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128035
+#endif
126612128036
if( nFrame>0 ){
126613128037
sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
126614128038
}else{
126615128039
sqlite3_wal_hook(db, 0, 0);
126616128040
}
@@ -126627,10 +128051,16 @@
126627128051
int(*xCallback)(void *, sqlite3*, const char*, int),
126628128052
void *pArg /* First argument passed to xCallback() */
126629128053
){
126630128054
#ifndef SQLITE_OMIT_WAL
126631128055
void *pRet;
128056
+#ifdef SQLITE_ENABLE_API_ARMOR
128057
+ if( !sqlite3SafetyCheckOk(db) ){
128058
+ (void)SQLITE_MISUSE_BKPT;
128059
+ return 0;
128060
+ }
128061
+#endif
126632128062
sqlite3_mutex_enter(db->mutex);
126633128063
pRet = db->pWalArg;
126634128064
db->xWalCallback = xCallback;
126635128065
db->pWalArg = pArg;
126636128066
sqlite3_mutex_leave(db->mutex);
@@ -126653,19 +128083,26 @@
126653128083
#ifdef SQLITE_OMIT_WAL
126654128084
return SQLITE_OK;
126655128085
#else
126656128086
int rc; /* Return code */
126657128087
int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
128088
+
128089
+#ifdef SQLITE_ENABLE_API_ARMOR
128090
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128091
+#endif
126658128092
126659128093
/* Initialize the output variables to -1 in case an error occurs. */
126660128094
if( pnLog ) *pnLog = -1;
126661128095
if( pnCkpt ) *pnCkpt = -1;
126662128096
126663
- assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE );
126664
- assert( SQLITE_CHECKPOINT_FULL<SQLITE_CHECKPOINT_RESTART );
126665
- assert( SQLITE_CHECKPOINT_PASSIVE+2==SQLITE_CHECKPOINT_RESTART );
126666
- if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_RESTART ){
128097
+ assert( SQLITE_CHECKPOINT_PASSIVE==0 );
128098
+ assert( SQLITE_CHECKPOINT_FULL==1 );
128099
+ assert( SQLITE_CHECKPOINT_RESTART==2 );
128100
+ assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
128101
+ if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){
128102
+ /* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
128103
+ ** mode: */
126667128104
return SQLITE_MISUSE;
126668128105
}
126669128106
126670128107
sqlite3_mutex_enter(db->mutex);
126671128108
if( zDb && zDb[0] ){
@@ -126689,11 +128126,13 @@
126689128126
** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
126690128127
** to contains a zero-length string, all attached databases are
126691128128
** checkpointed.
126692128129
*/
126693128130
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
126694
- return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0);
128131
+ /* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
128132
+ ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
128133
+ return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
126695128134
}
126696128135
126697128136
#ifndef SQLITE_OMIT_WAL
126698128137
/*
126699128138
** Run a checkpoint on database iDb. This is a no-op if database iDb is
@@ -127050,10 +128489,16 @@
127050128489
** from forming.
127051128490
*/
127052128491
SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
127053128492
int oldLimit;
127054128493
128494
+#ifdef SQLITE_ENABLE_API_ARMOR
128495
+ if( !sqlite3SafetyCheckOk(db) ){
128496
+ (void)SQLITE_MISUSE_BKPT;
128497
+ return -1;
128498
+ }
128499
+#endif
127055128500
127056128501
/* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
127057128502
** there is a hard upper bound set at compile-time by a C preprocessor
127058128503
** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
127059128504
** "_MAX_".)
@@ -127126,11 +128571,12 @@
127126128571
char c;
127127128572
int nUri = sqlite3Strlen30(zUri);
127128128573
127129128574
assert( *pzErrMsg==0 );
127130128575
127131
- if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
128576
+ if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
128577
+ || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
127132128578
&& nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
127133128579
){
127134128580
char *zOpt;
127135128581
int eState; /* Parser state when parsing URI */
127136128582
int iIn; /* Input character index */
@@ -127335,10 +128781,13 @@
127335128781
int rc; /* Return code */
127336128782
int isThreadsafe; /* True for threadsafe connections */
127337128783
char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
127338128784
char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
127339128785
128786
+#ifdef SQLITE_ENABLE_API_ARMOR
128787
+ if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128788
+#endif
127340128789
*ppDb = 0;
127341128790
#ifndef SQLITE_OMIT_AUTOINIT
127342128791
rc = sqlite3_initialize();
127343128792
if( rc ) return rc;
127344128793
#endif
@@ -127440,33 +128889,40 @@
127440128889
| SQLITE_RecTriggers
127441128890
#endif
127442128891
#if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
127443128892
| SQLITE_ForeignKeys
127444128893
#endif
128894
+#if defined(SQLITE_REVERSE_UNORDERED_SELECTS)
128895
+ | SQLITE_ReverseOrder
128896
+#endif
127445128897
;
127446128898
sqlite3HashInit(&db->aCollSeq);
127447128899
#ifndef SQLITE_OMIT_VIRTUALTABLE
127448128900
sqlite3HashInit(&db->aModule);
127449128901
#endif
127450128902
127451128903
/* Add the default collation sequence BINARY. BINARY works for both UTF-8
127452128904
** and UTF-16, so add a version for each to avoid any unnecessary
127453128905
** conversions. The only error that can occur here is a malloc() failure.
128906
+ **
128907
+ ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
128908
+ ** functions:
127454128909
*/
127455128910
createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
127456128911
createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
127457128912
createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
128913
+ createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
127458128914
createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
127459128915
if( db->mallocFailed ){
127460128916
goto opendb_out;
127461128917
}
128918
+ /* EVIDENCE-OF: R-08308-17224 The default collating function for all
128919
+ ** strings is BINARY.
128920
+ */
127462128921
db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
127463128922
assert( db->pDfltColl!=0 );
127464128923
127465
- /* Also add a UTF-8 case-insensitive collation sequence. */
127466
- createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
127467
-
127468128924
/* Parse the filename/URI argument. */
127469128925
db->openFlags = flags;
127470128926
rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
127471128927
if( rc!=SQLITE_OK ){
127472128928
if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -127483,11 +128939,13 @@
127483128939
rc = SQLITE_NOMEM;
127484128940
}
127485128941
sqlite3Error(db, rc);
127486128942
goto opendb_out;
127487128943
}
128944
+ sqlite3BtreeEnter(db->aDb[0].pBt);
127488128945
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
128946
+ sqlite3BtreeLeave(db->aDb[0].pBt);
127489128947
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
127490128948
127491128949
/* The default safety_level for the main database is 'full'; for the temp
127492128950
** database it is 'NONE'. This matches the pager layer defaults.
127493128951
*/
@@ -127624,17 +129082,19 @@
127624129082
){
127625129083
char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
127626129084
sqlite3_value *pVal;
127627129085
int rc;
127628129086
127629
- assert( zFilename );
127630
- assert( ppDb );
129087
+#ifdef SQLITE_ENABLE_API_ARMOR
129088
+ if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
129089
+#endif
127631129090
*ppDb = 0;
127632129091
#ifndef SQLITE_OMIT_AUTOINIT
127633129092
rc = sqlite3_initialize();
127634129093
if( rc ) return rc;
127635129094
#endif
129095
+ if( zFilename==0 ) zFilename = "\000\000";
127636129096
pVal = sqlite3ValueNew(0);
127637129097
sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
127638129098
zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
127639129099
if( zFilename8 ){
127640129100
rc = openDatabase(zFilename8, ppDb,
@@ -127660,17 +129120,11 @@
127660129120
const char *zName,
127661129121
int enc,
127662129122
void* pCtx,
127663129123
int(*xCompare)(void*,int,const void*,int,const void*)
127664129124
){
127665
- int rc;
127666
- sqlite3_mutex_enter(db->mutex);
127667
- assert( !db->mallocFailed );
127668
- rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
127669
- rc = sqlite3ApiExit(db, rc);
127670
- sqlite3_mutex_leave(db->mutex);
127671
- return rc;
129125
+ return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
127672129126
}
127673129127
127674129128
/*
127675129129
** Register a new collation sequence with the database handle db.
127676129130
*/
@@ -127681,10 +129135,14 @@
127681129135
void* pCtx,
127682129136
int(*xCompare)(void*,int,const void*,int,const void*),
127683129137
void(*xDel)(void*)
127684129138
){
127685129139
int rc;
129140
+
129141
+#ifdef SQLITE_ENABLE_API_ARMOR
129142
+ if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
129143
+#endif
127686129144
sqlite3_mutex_enter(db->mutex);
127687129145
assert( !db->mallocFailed );
127688129146
rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
127689129147
rc = sqlite3ApiExit(db, rc);
127690129148
sqlite3_mutex_leave(db->mutex);
@@ -127702,10 +129160,14 @@
127702129160
void* pCtx,
127703129161
int(*xCompare)(void*,int,const void*,int,const void*)
127704129162
){
127705129163
int rc = SQLITE_OK;
127706129164
char *zName8;
129165
+
129166
+#ifdef SQLITE_ENABLE_API_ARMOR
129167
+ if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
129168
+#endif
127707129169
sqlite3_mutex_enter(db->mutex);
127708129170
assert( !db->mallocFailed );
127709129171
zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
127710129172
if( zName8 ){
127711129173
rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -127724,10 +129186,13 @@
127724129186
SQLITE_API int sqlite3_collation_needed(
127725129187
sqlite3 *db,
127726129188
void *pCollNeededArg,
127727129189
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
127728129190
){
129191
+#ifdef SQLITE_ENABLE_API_ARMOR
129192
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129193
+#endif
127729129194
sqlite3_mutex_enter(db->mutex);
127730129195
db->xCollNeeded = xCollNeeded;
127731129196
db->xCollNeeded16 = 0;
127732129197
db->pCollNeededArg = pCollNeededArg;
127733129198
sqlite3_mutex_leave(db->mutex);
@@ -127742,10 +129207,13 @@
127742129207
SQLITE_API int sqlite3_collation_needed16(
127743129208
sqlite3 *db,
127744129209
void *pCollNeededArg,
127745129210
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
127746129211
){
129212
+#ifdef SQLITE_ENABLE_API_ARMOR
129213
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129214
+#endif
127747129215
sqlite3_mutex_enter(db->mutex);
127748129216
db->xCollNeeded = 0;
127749129217
db->xCollNeeded16 = xCollNeeded16;
127750129218
db->pCollNeededArg = pCollNeededArg;
127751129219
sqlite3_mutex_leave(db->mutex);
@@ -127768,10 +129236,16 @@
127768129236
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
127769129237
** by default. Autocommit is disabled by a BEGIN statement and reenabled
127770129238
** by the next COMMIT or ROLLBACK.
127771129239
*/
127772129240
SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
129241
+#ifdef SQLITE_ENABLE_API_ARMOR
129242
+ if( !sqlite3SafetyCheckOk(db) ){
129243
+ (void)SQLITE_MISUSE_BKPT;
129244
+ return 0;
129245
+ }
129246
+#endif
127773129247
return db->autoCommit;
127774129248
}
127775129249
127776129250
/*
127777129251
** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -127821,11 +129295,10 @@
127821129295
127822129296
/*
127823129297
** Return meta information about a specific column of a database table.
127824129298
** See comment in sqlite3.h (sqlite.h.in) for details.
127825129299
*/
127826
-#ifdef SQLITE_ENABLE_COLUMN_METADATA
127827129300
SQLITE_API int sqlite3_table_column_metadata(
127828129301
sqlite3 *db, /* Connection handle */
127829129302
const char *zDbName, /* Database name or NULL */
127830129303
const char *zTableName, /* Table name */
127831129304
const char *zColumnName, /* Column name */
@@ -127861,25 +129334,27 @@
127861129334
pTab = 0;
127862129335
goto error_out;
127863129336
}
127864129337
127865129338
/* Find the column for which info is requested */
127866
- if( sqlite3IsRowid(zColumnName) ){
127867
- iCol = pTab->iPKey;
127868
- if( iCol>=0 ){
127869
- pCol = &pTab->aCol[iCol];
127870
- }
129339
+ if( zColumnName==0 ){
129340
+ /* Query for existance of table only */
127871129341
}else{
127872129342
for(iCol=0; iCol<pTab->nCol; iCol++){
127873129343
pCol = &pTab->aCol[iCol];
127874129344
if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
127875129345
break;
127876129346
}
127877129347
}
127878129348
if( iCol==pTab->nCol ){
127879
- pTab = 0;
127880
- goto error_out;
129349
+ if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
129350
+ iCol = pTab->iPKey;
129351
+ pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
129352
+ }else{
129353
+ pTab = 0;
129354
+ goto error_out;
129355
+ }
127881129356
}
127882129357
}
127883129358
127884129359
/* The following block stores the meta information that will be returned
127885129360
** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
@@ -127928,11 +129403,10 @@
127928129403
sqlite3DbFree(db, zErrMsg);
127929129404
rc = sqlite3ApiExit(db, rc);
127930129405
sqlite3_mutex_leave(db->mutex);
127931129406
return rc;
127932129407
}
127933
-#endif
127934129408
127935129409
/*
127936129410
** Sleep for a little while. Return the amount of time slept.
127937129411
*/
127938129412
SQLITE_API int sqlite3_sleep(int ms){
@@ -127950,10 +129424,13 @@
127950129424
127951129425
/*
127952129426
** Enable or disable the extended result codes.
127953129427
*/
127954129428
SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
129429
+#ifdef SQLITE_ENABLE_API_ARMOR
129430
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129431
+#endif
127955129432
sqlite3_mutex_enter(db->mutex);
127956129433
db->errMask = onoff ? 0xffffffff : 0xff;
127957129434
sqlite3_mutex_leave(db->mutex);
127958129435
return SQLITE_OK;
127959129436
}
@@ -127963,10 +129440,13 @@
127963129440
*/
127964129441
SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
127965129442
int rc = SQLITE_ERROR;
127966129443
Btree *pBtree;
127967129444
129445
+#ifdef SQLITE_ENABLE_API_ARMOR
129446
+ if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129447
+#endif
127968129448
sqlite3_mutex_enter(db->mutex);
127969129449
pBtree = sqlite3DbNameToBtree(db, zDbName);
127970129450
if( pBtree ){
127971129451
Pager *pPager;
127972129452
sqlite3_file *fd;
@@ -128305,11 +129785,11 @@
128305129785
** query parameter we seek. This routine returns the value of the zParam
128306129786
** parameter if it exists. If the parameter does not exist, this routine
128307129787
** returns a NULL pointer.
128308129788
*/
128309129789
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
128310
- if( zFilename==0 ) return 0;
129790
+ if( zFilename==0 || zParam==0 ) return 0;
128311129791
zFilename += sqlite3Strlen30(zFilename) + 1;
128312129792
while( zFilename[0] ){
128313129793
int x = strcmp(zFilename, zParam);
128314129794
zFilename += sqlite3Strlen30(zFilename) + 1;
128315129795
if( x==0 ) return zFilename;
@@ -128361,19 +129841,31 @@
128361129841
/*
128362129842
** Return the filename of the database associated with a database
128363129843
** connection.
128364129844
*/
128365129845
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129846
+#ifdef SQLITE_ENABLE_API_ARMOR
129847
+ if( !sqlite3SafetyCheckOk(db) ){
129848
+ (void)SQLITE_MISUSE_BKPT;
129849
+ return 0;
129850
+ }
129851
+#endif
128366129852
Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128367129853
return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
128368129854
}
128369129855
128370129856
/*
128371129857
** Return 1 if database is read-only or 0 if read/write. Return -1 if
128372129858
** no such database exists.
128373129859
*/
128374129860
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129861
+#ifdef SQLITE_ENABLE_API_ARMOR
129862
+ if( !sqlite3SafetyCheckOk(db) ){
129863
+ (void)SQLITE_MISUSE_BKPT;
129864
+ return -1;
129865
+ }
129866
+#endif
128375129867
Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128376129868
return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
128377129869
}
128378129870
128379129871
/************** End of main.c ************************************************/
@@ -137791,11 +139283,11 @@
137791139283
** Return true if the m-value for z is 1 or more. In other words,
137792139284
** return true if z contains at least one vowel that is followed
137793139285
** by a consonant.
137794139286
**
137795139287
** In this routine z[] is in reverse order. So we are really looking
137796
-** for an instance of of a consonant followed by a vowel.
139288
+** for an instance of a consonant followed by a vowel.
137797139289
*/
137798139290
static int m_gt_0(const char *z){
137799139291
while( isVowel(z) ){ z++; }
137800139292
if( *z==0 ) return 0;
137801139293
while( isConsonant(z) ){ z++; }
137802139294
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.7.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -179,11 +179,11 @@
179
180
181 /*
182 ** These no-op macros are used in front of interfaces to mark those
183 ** interfaces as either deprecated or experimental. New applications
184 ** should not use deprecated interfaces - they are support for backwards
185 ** compatibility only. Application writers should be aware that
186 ** experimental interfaces are subject to change in point releases.
187 **
188 ** These macros used to resolve to various kinds of compiler magic that
189 ** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229 **
230 ** See also: [sqlite3_libversion()],
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.7.1"
235 #define SQLITE_VERSION_NUMBER 3008007
236 #define SQLITE_SOURCE_ID "2014-10-29 01:27:43 83afe23e553e802c0947c80d0ffdd120423e7c52"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -1343,11 +1343,11 @@
1343 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1344 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1345 ** </ul>
1346 **
1347 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1348 ** was given no the corresponding lock.
1349 **
1350 ** The xShmLock method can transition between unlocked and SHARED or
1351 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1352 ** and EXCLUSIVE.
1353 */
@@ -1626,30 +1626,32 @@
1626 ** it is not possible to set the Serialized [threading mode] and
1627 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1628 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1629 **
1630 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631 ** <dd> ^(This option takes a single argument which is a pointer to an
1632 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
 
1633 ** alternative low-level memory allocation routines to be used in place of
1634 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1635 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1636 ** before the [sqlite3_config()] call returns.</dd>
1637 **
1638 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1639 ** <dd> ^(This option takes a single argument which is a pointer to an
1640 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
 
1641 ** structure is filled with the currently defined memory allocation routines.)^
1642 ** This option can be used to overload the default memory allocation
1643 ** routines with a wrapper that simulations memory allocation failure or
1644 ** tracks memory usage, for example. </dd>
1645 **
1646 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1647 ** <dd> ^This option takes single argument of type int, interpreted as a
1648 ** boolean, which enables or disables the collection of memory allocation
1649 ** statistics. ^(When memory allocation statistics are disabled, the
1650 ** following SQLite interfaces become non-operational:
1651 ** <ul>
1652 ** <li> [sqlite3_memory_used()]
1653 ** <li> [sqlite3_memory_highwater()]
1654 ** <li> [sqlite3_soft_heap_limit64()]
1655 ** <li> [sqlite3_status()]
@@ -1658,78 +1660,92 @@
1658 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1659 ** allocation statistics are disabled by default.
1660 ** </dd>
1661 **
1662 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1663 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1664 ** scratch memory. There are three arguments: A pointer an 8-byte
 
1665 ** aligned memory buffer from which the scratch allocations will be
1666 ** drawn, the size of each scratch allocation (sz),
1667 ** and the maximum number of scratch allocations (N). The sz
1668 ** argument must be a multiple of 16.
1669 ** The first argument must be a pointer to an 8-byte aligned buffer
1670 ** of at least sz*N bytes of memory.
1671 ** ^SQLite will use no more than two scratch buffers per thread. So
1672 ** N should be set to twice the expected maximum number of threads.
1673 ** ^SQLite will never require a scratch buffer that is more than 6
1674 ** times the database page size. ^If SQLite needs needs additional
1675 ** scratch memory beyond what is provided by this configuration option, then
1676 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
 
 
 
 
 
 
1677 **
1678 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1679 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1680 ** the database page cache with the default page cache implementation.
 
1681 ** This configuration should not be used if an application-define page
1682 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1683 ** There are three arguments to this option: A pointer to 8-byte aligned
 
 
1684 ** memory, the size of each page buffer (sz), and the number of pages (N).
1685 ** The sz argument should be the size of the largest database page
1686 ** (a power of two between 512 and 32768) plus a little extra for each
1687 ** page header. ^The page header size is 20 to 40 bytes depending on
1688 ** the host architecture. ^It is harmless, apart from the wasted memory,
1689 ** to make sz a little too large. The first
1690 ** argument should point to an allocation of at least sz*N bytes of memory.
 
 
 
 
1691 ** ^SQLite will use the memory provided by the first argument to satisfy its
1692 ** memory needs for the first N pages that it adds to cache. ^If additional
1693 ** page cache memory is needed beyond what is provided by this option, then
1694 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1695 ** The pointer in the first argument must
1696 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1697 ** will be undefined.</dd>
1698 **
1699 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1700 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1701 ** for all of its dynamic memory allocation needs beyond those provided
1702 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1703 ** There are three arguments: An 8-byte aligned pointer to the memory,
 
 
 
 
 
1704 ** the number of bytes in the memory buffer, and the minimum allocation size.
1705 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1706 ** to using its default memory allocator (the system malloc() implementation),
1707 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1708 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1709 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1710 ** allocator is engaged to handle all of SQLites memory allocation needs.
1711 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1712 ** boundary or subsequent behavior of SQLite will be undefined.
1713 ** The minimum allocation size is capped at 2**12. Reasonable values
1714 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1715 **
1716 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1717 ** <dd> ^(This option takes a single argument which is a pointer to an
1718 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1719 ** alternative low-level mutex routines to be used in place
1720 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1721 ** content of the [sqlite3_mutex_methods] structure before the call to
1722 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1723 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1724 ** the entire mutexing subsystem is omitted from the build and hence calls to
1725 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1726 ** return [SQLITE_ERROR].</dd>
1727 **
1728 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1729 ** <dd> ^(This option takes a single argument which is a pointer to an
1730 ** instance of the [sqlite3_mutex_methods] structure. The
1731 ** [sqlite3_mutex_methods]
1732 ** structure is filled with the currently defined mutex routines.)^
1733 ** This option can be used to overload the default mutex allocation
1734 ** routines with a wrapper used to track mutex usage for performance
1735 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1737,29 +1753,29 @@
1737 ** the entire mutexing subsystem is omitted from the build and hence calls to
1738 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1739 ** return [SQLITE_ERROR].</dd>
1740 **
1741 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1742 ** <dd> ^(This option takes two arguments that determine the default
1743 ** memory allocation for the lookaside memory allocator on each
1744 ** [database connection]. The first argument is the
1745 ** size of each lookaside buffer slot and the second is the number of
1746 ** slots allocated to each database connection.)^ ^(This option sets the
1747 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1748 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1749 ** configuration on individual connections.)^ </dd>
1750 **
1751 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1752 ** <dd> ^(This option takes a single argument which is a pointer to
1753 ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1754 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1755 ** object and uses it for page cache memory allocations.</dd>
1756 **
1757 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1758 ** <dd> ^(This option takes a single argument which is a pointer to an
1759 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1760 ** page cache implementation into that object.)^ </dd>
1761 **
1762 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1763 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1764 ** global [error log].
1765 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1778,26 +1794,28 @@
1778 ** supplied by the application must not invoke any SQLite interface.
1779 ** In a multi-threaded application, the application-defined logger
1780 ** function must be threadsafe. </dd>
1781 **
1782 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1783 ** <dd>^(This option takes a single argument of type int. If non-zero, then
1784 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1785 ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1786 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
 
1787 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1788 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1789 ** connection is opened. ^If it is globally disabled, filenames are
1790 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1791 ** database connection is opened. ^(By default, URI handling is globally
1792 ** disabled. The default value may be changed by compiling with the
1793 ** [SQLITE_USE_URI] symbol defined.)^
1794 **
1795 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1796 ** <dd>^This option takes a single integer argument which is interpreted as
1797 ** a boolean in order to enable or disable the use of covering indices for
1798 ** full table scans in the query optimizer. ^The default setting is determined
 
1799 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1800 ** if that compile-time option is omitted.
1801 ** The ability to disable the use of covering indices for full table scans
1802 ** is because some incorrectly coded legacy applications might malfunction
1803 ** when the optimization is enabled. Providing the ability to
@@ -1833,23 +1851,32 @@
1833 ** that are the default mmap size limit (the default setting for
1834 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1835 ** ^The default setting can be overridden by each database connection using
1836 ** either the [PRAGMA mmap_size] command, or by using the
1837 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1838 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1839 ** exceed the compile-time maximum mmap size set by the
1840 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1841 ** ^If either argument to this option is negative, then that argument is
1842 ** changed to its compile-time default.
1843 **
1844 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1845 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1846 ** <dd>^This option is only available if SQLite is compiled for Windows
1847 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1848 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1849 ** that specifies the maximum size of the created heap.
1850 ** </dl>
 
 
 
 
 
 
 
 
 
1851 */
1852 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1853 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1854 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1855 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1870,10 +1897,11 @@
1870 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1871 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1872 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1873 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1874 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
 
1875
1876 /*
1877 ** CAPI3REF: Database Connection Configuration Options
1878 **
1879 ** These constants are the available integer configuration options that
@@ -1997,51 +2025,49 @@
1997 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1998
1999 /*
2000 ** CAPI3REF: Count The Number Of Rows Modified
2001 **
2002 ** ^This function returns the number of database rows that were changed
2003 ** or inserted or deleted by the most recently completed SQL statement
2004 ** on the [database connection] specified by the first parameter.
2005 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
2006 ** or [DELETE] statement are counted. Auxiliary changes caused by
2007 ** triggers or [foreign key actions] are not counted.)^ Use the
2008 ** [sqlite3_total_changes()] function to find the total number of changes
2009 ** including changes caused by triggers and foreign key actions.
2010 **
2011 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
2012 ** are not counted. Only real table changes are counted.
2013 **
2014 ** ^(A "row change" is a change to a single row of a single table
2015 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
2016 ** are changed as side effects of [REPLACE] constraint resolution,
2017 ** rollback, ABORT processing, [DROP TABLE], or by any other
2018 ** mechanisms do not count as direct row changes.)^
2019 **
2020 ** A "trigger context" is a scope of execution that begins and
2021 ** ends with the script of a [CREATE TRIGGER | trigger].
2022 ** Most SQL statements are
2023 ** evaluated outside of any trigger. This is the "top level"
2024 ** trigger context. If a trigger fires from the top level, a
2025 ** new trigger context is entered for the duration of that one
2026 ** trigger. Subtriggers create subcontexts for their duration.
2027 **
2028 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
2029 ** not create a new trigger context.
2030 **
2031 ** ^This function returns the number of direct row changes in the
2032 ** most recent INSERT, UPDATE, or DELETE statement within the same
2033 ** trigger context.
2034 **
2035 ** ^Thus, when called from the top level, this function returns the
2036 ** number of changes in the most recent INSERT, UPDATE, or DELETE
2037 ** that also occurred at the top level. ^(Within the body of a trigger,
2038 ** the sqlite3_changes() interface can be called to find the number of
2039 ** changes in the most recently completed INSERT, UPDATE, or DELETE
2040 ** statement within the body of the same trigger.
2041 ** However, the number returned does not include changes
2042 ** caused by subtriggers since those have their own context.)^
2043 **
2044 ** See also the [sqlite3_total_changes()] interface, the
2045 ** [count_changes pragma], and the [changes() SQL function].
2046 **
2047 ** If a separate thread makes changes on the same database connection
@@ -2051,24 +2077,21 @@
2051 SQLITE_API int sqlite3_changes(sqlite3*);
2052
2053 /*
2054 ** CAPI3REF: Total Number Of Rows Modified
2055 **
2056 ** ^This function returns the number of row changes caused by [INSERT],
2057 ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
2058 ** ^(The count returned by sqlite3_total_changes() includes all changes
2059 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
2060 ** [foreign key actions]. However,
2061 ** the count does not include changes used to implement [REPLACE] constraints,
2062 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
2063 ** count does not include rows of views that fire an [INSTEAD OF trigger],
2064 ** though if the INSTEAD OF trigger makes changes of its own, those changes
2065 ** are counted.)^
2066 ** ^The sqlite3_total_changes() function counts the changes as soon as
2067 ** the statement that makes them is completed (when the statement handle
2068 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
2069 **
2070 ** See also the [sqlite3_changes()] interface, the
2071 ** [count_changes pragma], and the [total_changes() SQL function].
2072 **
2073 ** If a separate thread makes changes on the same database connection
2074 ** while [sqlite3_total_changes()] is running then the value
@@ -2151,10 +2174,11 @@
2151 SQLITE_API int sqlite3_complete(const char *sql);
2152 SQLITE_API int sqlite3_complete16(const void *sql);
2153
2154 /*
2155 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
 
2156 **
2157 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2158 ** that might be invoked with argument P whenever
2159 ** an attempt is made to access a database table associated with
2160 ** [database connection] D when another thread
@@ -2167,11 +2191,11 @@
2167 ** is not NULL, then the callback might be invoked with two arguments.
2168 **
2169 ** ^The first argument to the busy handler is a copy of the void* pointer which
2170 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2171 ** the busy handler callback is the number of times that the busy handler has
2172 ** been invoked for the same locking event. ^If the
2173 ** busy callback returns 0, then no additional attempts are made to
2174 ** access the database and [SQLITE_BUSY] is returned
2175 ** to the application.
2176 ** ^If the callback returns non-zero, then another attempt
2177 ** is made to access the database and the cycle repeats.
@@ -2542,17 +2566,18 @@
2542 ** already uses the largest possible [ROWID]. The PRNG is also used for
2543 ** the build-in random() and randomblob() SQL functions. This interface allows
2544 ** applications to access the same PRNG for other purposes.
2545 **
2546 ** ^A call to this routine stores N bytes of randomness into buffer P.
2547 ** ^If N is less than one, then P can be a NULL pointer.
2548 **
2549 ** ^If this routine has not been previously called or if the previous
2550 ** call had N less than one, then the PRNG is seeded using randomness
2551 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2552 ** ^If the previous call to this routine had an N of 1 or more then
2553 ** the pseudo-randomness is generated
 
2554 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2555 ** method.
2556 */
2557 SQLITE_API void sqlite3_randomness(int N, void *P);
2558
@@ -4270,13 +4295,13 @@
4270 ** CAPI3REF: Text Encodings
4271 **
4272 ** These constant define integer codes that represent the various
4273 ** text encodings supported by SQLite.
4274 */
4275 #define SQLITE_UTF8 1
4276 #define SQLITE_UTF16LE 2
4277 #define SQLITE_UTF16BE 3
4278 #define SQLITE_UTF16 4 /* Use native byte order */
4279 #define SQLITE_ANY 5 /* Deprecated */
4280 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4281
4282 /*
@@ -4621,11 +4646,12 @@
4621 ** If these routines are called from within the different thread
4622 ** than the one containing the application-defined function that received
4623 ** the [sqlite3_context] pointer, the results are undefined.
4624 */
4625 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4626 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
 
4627 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4628 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4629 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4630 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4631 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5253,24 +5279,31 @@
5253
5254
5255 /*
5256 ** CAPI3REF: Extract Metadata About A Column Of A Table
5257 **
5258 ** ^This routine returns metadata about a specific column of a specific
5259 ** database table accessible using the [database connection] handle
5260 ** passed as the first function argument.
 
 
 
 
 
 
 
 
5261 **
5262 ** ^The column is identified by the second, third and fourth parameters to
5263 ** this function. ^The second parameter is either the name of the database
5264 ** (i.e. "main", "temp", or an attached database) containing the specified
5265 ** table or NULL. ^If it is NULL, then all attached databases are searched
5266 ** for the table using the same algorithm used by the database engine to
5267 ** resolve unqualified table references.
5268 **
5269 ** ^The third and fourth parameters to this function are the table and column
5270 ** name of the desired column, respectively. Neither of these parameters
5271 ** may be NULL.
5272 **
5273 ** ^Metadata is returned by writing to the memory locations passed as the 5th
5274 ** and subsequent parameters to this function. ^Any of these arguments may be
5275 ** NULL, in which case the corresponding element of metadata is omitted.
5276 **
@@ -5285,36 +5318,33 @@
5285 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5286 ** </table>
5287 ** </blockquote>)^
5288 **
5289 ** ^The memory pointed to by the character pointers returned for the
5290 ** declaration type and collation sequence is valid only until the next
5291 ** call to any SQLite API function.
5292 **
5293 ** ^If the specified table is actually a view, an [error code] is returned.
5294 **
5295 ** ^If the specified column is "rowid", "oid" or "_rowid_" and an
 
5296 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5297 ** parameters are set for the explicitly declared column. ^(If there is no
5298 ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
5299 ** parameters are set as follows:
5300 **
5301 ** <pre>
5302 ** data type: "INTEGER"
5303 ** collation sequence: "BINARY"
5304 ** not null: 0
5305 ** primary key: 1
5306 ** auto increment: 0
5307 ** </pre>)^
5308 **
5309 ** ^(This function may load one or more schemas from database files. If an
5310 ** error occurs during this process, or if the requested table or column
5311 ** cannot be found, an [error code] is returned and an error message left
5312 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
5313 **
5314 ** ^This API is only available if the library was compiled with the
5315 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
5316 */
5317 SQLITE_API int sqlite3_table_column_metadata(
5318 sqlite3 *db, /* Connection handle */
5319 const char *zDbName, /* Database name or NULL */
5320 const char *zTableName, /* Table name */
@@ -5762,31 +5792,47 @@
5762 ** in other words, the same BLOB that would be selected by:
5763 **
5764 ** <pre>
5765 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5766 ** </pre>)^
 
 
 
 
 
 
5767 **
5768 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5769 ** and write access. ^If it is zero, the BLOB is opened for read access.
5770 ** ^It is not possible to open a column that is part of an index or primary
5771 ** key for writing. ^If [foreign key constraints] are enabled, it is
5772 ** not possible to open a column that is part of a [child key] for writing.
5773 **
5774 ** ^Note that the database name is not the filename that contains
5775 ** the database but rather the symbolic name of the database that
5776 ** appears after the AS keyword when the database is connected using [ATTACH].
5777 ** ^For the main database file, the database name is "main".
5778 ** ^For TEMP tables, the database name is "temp".
5779 **
5780 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5781 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5782 ** to be a null pointer.)^
5783 ** ^This function sets the [database connection] error code and message
5784 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5785 ** functions. ^Note that the *ppBlob variable is always initialized in a
5786 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5787 ** regardless of the success or failure of this routine.
 
 
 
 
 
 
 
 
 
 
5788 **
5789 ** ^(If the row that a BLOB handle points to is modified by an
5790 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5791 ** then the BLOB handle is marked as "expired".
5792 ** This is true if any column of the row is changed, even a column
@@ -5800,17 +5846,13 @@
5800 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5801 ** the opened blob. ^The size of a blob may not be changed by this
5802 ** interface. Use the [UPDATE] SQL command to change the size of a
5803 ** blob.
5804 **
5805 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5806 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5807 **
5808 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5809 ** and the built-in [zeroblob] SQL function can be used, if desired,
5810 ** to create an empty, zero-filled blob in which to read or write using
5811 ** this interface.
5812 **
5813 ** To avoid a resource leak, every open [BLOB handle] should eventually
5814 ** be released by a call to [sqlite3_blob_close()].
5815 */
5816 SQLITE_API int sqlite3_blob_open(
@@ -5848,28 +5890,26 @@
5848 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5849
5850 /*
5851 ** CAPI3REF: Close A BLOB Handle
5852 **
5853 ** ^Closes an open [BLOB handle].
5854 **
5855 ** ^Closing a BLOB shall cause the current transaction to commit
5856 ** if there are no other BLOBs, no pending prepared statements, and the
5857 ** database connection is in [autocommit mode].
5858 ** ^If any writes were made to the BLOB, they might be held in cache
5859 ** until the close operation if they will fit.
5860 **
5861 ** ^(Closing the BLOB often forces the changes
5862 ** out to disk and so if any I/O errors occur, they will likely occur
5863 ** at the time when the BLOB is closed. Any errors that occur during
5864 ** closing are reported as a non-zero return value.)^
5865 **
5866 ** ^(The BLOB is closed unconditionally. Even if this routine returns
5867 ** an error code, the BLOB is still closed.)^
5868 **
5869 ** ^Calling this routine with a null pointer (such as would be returned
5870 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5871 */
5872 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5873
5874 /*
5875 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5915,36 +5955,39 @@
5915 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5916
5917 /*
5918 ** CAPI3REF: Write Data Into A BLOB Incrementally
5919 **
5920 ** ^This function is used to write data into an open [BLOB handle] from a
5921 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5922 ** into the open BLOB, starting at offset iOffset.
 
 
 
 
 
 
5923 **
5924 ** ^If the [BLOB handle] passed as the first argument was not opened for
5925 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5926 ** this function returns [SQLITE_READONLY].
5927 **
5928 ** ^This function may only modify the contents of the BLOB; it is
5929 ** not possible to increase the size of a BLOB using this API.
5930 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5931 ** [SQLITE_ERROR] is returned and no data is written. ^If N is
5932 ** less than zero [SQLITE_ERROR] is returned and no data is written.
5933 ** The size of the BLOB (and hence the maximum value of N+iOffset)
5934 ** can be determined using the [sqlite3_blob_bytes()] interface.
5935 **
5936 ** ^An attempt to write to an expired [BLOB handle] fails with an
5937 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5938 ** before the [BLOB handle] expired are not rolled back by the
5939 ** expiration of the handle, though of course those changes might
5940 ** have been overwritten by the statement that expired the BLOB handle
5941 ** or by other independent statements.
5942 **
5943 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5944 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5945 **
5946 ** This routine only works on a [BLOB handle] which has been created
5947 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5948 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5949 ** to this routine results in undefined and probably undesirable behavior.
5950 **
@@ -5993,38 +6036,38 @@
5993 ** use by SQLite, code that links against SQLite is
5994 ** permitted to use any of these routines.
5995 **
5996 ** The SQLite source code contains multiple implementations
5997 ** of these mutex routines. An appropriate implementation
5998 ** is selected automatically at compile-time. ^(The following
5999 ** implementations are available in the SQLite core:
6000 **
6001 ** <ul>
6002 ** <li> SQLITE_MUTEX_PTHREADS
6003 ** <li> SQLITE_MUTEX_W32
6004 ** <li> SQLITE_MUTEX_NOOP
6005 ** </ul>)^
6006 **
6007 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
6008 ** that does no real locking and is appropriate for use in
6009 ** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
6010 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
6011 ** and Windows.
6012 **
6013 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
6014 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
6015 ** implementation is included with the library. In this case the
6016 ** application must supply a custom mutex implementation using the
6017 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
6018 ** before calling sqlite3_initialize() or any other public sqlite3_
6019 ** function that calls sqlite3_initialize().)^
6020 **
6021 ** ^The sqlite3_mutex_alloc() routine allocates a new
6022 ** mutex and returns a pointer to it. ^If it returns NULL
6023 ** that means that a mutex could not be allocated. ^SQLite
6024 ** will unwind its stack and return an error. ^(The argument
6025 ** to sqlite3_mutex_alloc() is one of these integer constants:
6026 **
6027 ** <ul>
6028 ** <li> SQLITE_MUTEX_FAST
6029 ** <li> SQLITE_MUTEX_RECURSIVE
6030 ** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -6033,68 +6076,64 @@
6033 ** <li> SQLITE_MUTEX_STATIC_PRNG
6034 ** <li> SQLITE_MUTEX_STATIC_LRU
6035 ** <li> SQLITE_MUTEX_STATIC_PMEM
6036 ** <li> SQLITE_MUTEX_STATIC_APP1
6037 ** <li> SQLITE_MUTEX_STATIC_APP2
6038 ** </ul>)^
 
6039 **
6040 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
6041 ** cause sqlite3_mutex_alloc() to create
6042 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
6043 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
6044 ** The mutex implementation does not need to make a distinction
6045 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
6046 ** not want to. ^SQLite will only request a recursive mutex in
6047 ** cases where it really needs one. ^If a faster non-recursive mutex
6048 ** implementation is available on the host platform, the mutex subsystem
6049 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
6050 **
6051 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
6052 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
6053 ** a pointer to a static preexisting mutex. ^Six static mutexes are
6054 ** used by the current version of SQLite. Future versions of SQLite
6055 ** may add additional static mutexes. Static mutexes are for internal
6056 ** use by SQLite only. Applications that use SQLite mutexes should
6057 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
6058 ** SQLITE_MUTEX_RECURSIVE.
6059 **
6060 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
6061 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
6062 ** returns a different mutex on every call. ^But for the static
6063 ** mutex types, the same mutex is returned on every call that has
6064 ** the same type number.
6065 **
6066 ** ^The sqlite3_mutex_free() routine deallocates a previously
6067 ** allocated dynamic mutex. ^SQLite is careful to deallocate every
6068 ** dynamic mutex that it allocates. The dynamic mutexes must not be in
6069 ** use when they are deallocated. Attempting to deallocate a static
6070 ** mutex results in undefined behavior. ^SQLite never deallocates
6071 ** a static mutex.
6072 **
6073 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
6074 ** to enter a mutex. ^If another thread is already within the mutex,
6075 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
6076 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
6077 ** upon successful entry. ^(Mutexes created using
6078 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
6079 ** In such cases the,
6080 ** mutex must be exited an equal number of times before another thread
6081 ** can enter.)^ ^(If the same thread tries to enter any other
6082 ** kind of mutex more than once, the behavior is undefined.
6083 ** SQLite will never exhibit
6084 ** such behavior in its own use of mutexes.)^
6085 **
6086 ** ^(Some systems (for example, Windows 95) do not support the operation
6087 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
6088 ** will always return SQLITE_BUSY. The SQLite core only ever uses
6089 ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
 
6090 **
6091 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
6092 ** previously entered by the same thread. ^(The behavior
6093 ** is undefined if the mutex is not currently entered by the
6094 ** calling thread or is not currently allocated. SQLite will
6095 ** never do either.)^
6096 **
6097 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
6098 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
6099 ** behave as no-ops.
6100 **
@@ -6111,13 +6150,13 @@
6111 **
6112 ** An instance of this structure defines the low-level routines
6113 ** used to allocate and use mutexes.
6114 **
6115 ** Usually, the default mutex implementations provided by SQLite are
6116 ** sufficient, however the user has the option of substituting a custom
6117 ** implementation for specialized deployments or systems for which SQLite
6118 ** does not provide a suitable implementation. In this case, the user
6119 ** creates and populates an instance of this structure to pass
6120 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
6121 ** Additionally, an instance of this structure can be used as an
6122 ** output variable when querying the system for the current mutex
6123 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6154,17 +6193,17 @@
6154 ** by this structure are not required to handle this case, the results
6155 ** of passing a NULL pointer instead of a valid mutex handle are undefined
6156 ** (i.e. it is acceptable to provide an implementation that segfaults if
6157 ** it is passed a NULL pointer).
6158 **
6159 ** The xMutexInit() method must be threadsafe. ^It must be harmless to
6160 ** invoke xMutexInit() multiple times within the same process and without
6161 ** intervening calls to xMutexEnd(). Second and subsequent calls to
6162 ** xMutexInit() must be no-ops.
6163 **
6164 ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6165 ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
6166 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
6167 ** memory allocation for a fast or recursive mutex.
6168 **
6169 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
6170 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6186,33 +6225,33 @@
6186
6187 /*
6188 ** CAPI3REF: Mutex Verification Routines
6189 **
6190 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6191 ** are intended for use inside assert() statements. ^The SQLite core
6192 ** never uses these routines except inside an assert() and applications
6193 ** are advised to follow the lead of the core. ^The SQLite core only
6194 ** provides implementations for these routines when it is compiled
6195 ** with the SQLITE_DEBUG flag. ^External mutex implementations
6196 ** are only required to provide these routines if SQLITE_DEBUG is
6197 ** defined and if NDEBUG is not defined.
6198 **
6199 ** ^These routines should return true if the mutex in their argument
6200 ** is held or not held, respectively, by the calling thread.
6201 **
6202 ** ^The implementation is not required to provide versions of these
6203 ** routines that actually work. If the implementation does not provide working
6204 ** versions of these routines, it should at least provide stubs that always
6205 ** return true so that one does not get spurious assertion failures.
6206 **
6207 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
6208 ** the routine should return 1. This seems counter-intuitive since
6209 ** clearly the mutex cannot be held if it does not exist. But
6210 ** the reason the mutex does not exist is because the build is not
6211 ** using mutexes. And we do not want the assert() containing the
6212 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
6213 ** the appropriate thing to do. ^The sqlite3_mutex_notheld()
6214 ** interface should also return 1 when given a NULL pointer.
6215 */
6216 #ifndef NDEBUG
6217 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
6218 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6940,10 +6979,14 @@
6940 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6941 ** and database name of the source database, respectively.
6942 ** ^The source and destination [database connections] (parameters S and D)
6943 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6944 ** an error.
 
 
 
 
6945 **
6946 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6947 ** returned and an error code and error message are stored in the
6948 ** destination [database connection] D.
6949 ** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7334,101 +7377,118 @@
7334 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7335
7336 /*
7337 ** CAPI3REF: Checkpoint a database
7338 **
7339 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7340 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7341 ** empty string, then a checkpoint is run on all databases of
7342 ** connection D. ^If the database connection D is not in
7343 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7344 ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7345 ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7346 ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7347 ** or RESET checkpoint.
7348 **
7349 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7350 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7351 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7352 ** run whenever the WAL reaches a certain size threshold.
7353 **
7354 ** See also: [sqlite3_wal_checkpoint_v2()]
7355 */
7356 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7357
7358 /*
7359 ** CAPI3REF: Checkpoint a database
7360 **
7361 ** Run a checkpoint operation on WAL database zDb attached to database
7362 ** handle db. The specific operation is determined by the value of the
7363 ** eMode parameter:
 
7364 **
7365 ** <dl>
7366 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7367 ** Checkpoint as many frames as possible without waiting for any database
7368 ** readers or writers to finish. Sync the db file if all frames in the log
7369 ** are checkpointed. This mode is the same as calling
7370 ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7371 ** is never invoked.
 
7372 **
7373 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7374 ** This mode blocks (it invokes the
7375 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7376 ** database writer and all readers are reading from the most recent database
7377 ** snapshot. It then checkpoints all frames in the log file and syncs the
7378 ** database file. This call blocks database writers while it is running,
7379 ** but not database readers.
7380 **
7381 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7382 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7383 ** checkpointing the log file it blocks (calls the
7384 ** [sqlite3_busy_handler|busy-handler callback])
7385 ** until all readers are reading from the database file only. This ensures
7386 ** that the next client to write to the database file restarts the log file
7387 ** from the beginning. This call blocks database writers while it is running,
7388 ** but not database readers.
 
 
 
 
 
7389 ** </dl>
7390 **
7391 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7392 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7393 ** the total number of checkpointed frames (including any that were already
7394 ** checkpointed when this function is called). *pnLog and *pnCkpt may be
7395 ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
7396 ** If no values are available because of an error, they are both set to -1
7397 ** before returning to communicate this to the caller.
 
 
7398 **
7399 ** All calls obtain an exclusive "checkpoint" lock on the database file. If
7400 ** any other process is running a checkpoint operation at the same time, the
7401 ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
7402 ** busy-handler configured, it will not be invoked in this case.
7403 **
7404 ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
7405 ** "writer" lock on the database file. If the writer lock cannot be obtained
7406 ** immediately, and a busy-handler is configured, it is invoked and the writer
7407 ** lock retried until either the busy-handler returns 0 or the lock is
7408 ** successfully obtained. The busy-handler is also invoked while waiting for
7409 ** database readers as described above. If the busy-handler returns 0 before
7410 ** the writer lock is obtained or while waiting for database readers, the
7411 ** checkpoint operation proceeds from that point in the same way as
7412 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7413 ** without blocking any further. SQLITE_BUSY is returned in this case.
7414 **
7415 ** If parameter zDb is NULL or points to a zero length string, then the
7416 ** specified operation is attempted on all WAL databases. In this case the
7417 ** values written to output parameters *pnLog and *pnCkpt are undefined. If
 
7418 ** an SQLITE_BUSY error is encountered when processing one or more of the
7419 ** attached WAL databases, the operation is still attempted on any remaining
7420 ** attached databases and SQLITE_BUSY is returned to the caller. If any other
7421 ** error occurs while processing an attached database, processing is abandoned
7422 ** and the error code returned to the caller immediately. If no error
7423 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
7424 ** databases, SQLITE_OK is returned.
7425 **
7426 ** If database zDb is the name of an attached database that is not in WAL
7427 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
7428 ** zDb is not NULL (or a zero length string) and is not the name of any
7429 ** attached database, SQLITE_ERROR is returned to the caller.
 
 
 
 
 
 
 
 
7430 */
7431 SQLITE_API int sqlite3_wal_checkpoint_v2(
7432 sqlite3 *db, /* Database handle */
7433 const char *zDb, /* Name of attached database (or NULL) */
7434 int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7435,20 +7495,22 @@
7435 int *pnLog, /* OUT: Size of WAL log in frames */
7436 int *pnCkpt /* OUT: Total number of frames checkpointed */
7437 );
7438
7439 /*
7440 ** CAPI3REF: Checkpoint operation parameters
 
7441 **
7442 ** These constants can be used as the 3rd parameter to
7443 ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
7444 ** documentation for additional information about the meaning and use of
7445 ** each of these values.
7446 */
7447 #define SQLITE_CHECKPOINT_PASSIVE 0
7448 #define SQLITE_CHECKPOINT_FULL 1
7449 #define SQLITE_CHECKPOINT_RESTART 2
 
7450
7451 /*
7452 ** CAPI3REF: Virtual Table Interface Configuration
7453 **
7454 ** This function may be called by either the [xConnect] or [xCreate] method
@@ -7533,10 +7595,102 @@
7533 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7534 #define SQLITE_FAIL 3
7535 /* #define SQLITE_ABORT 4 // Also an error code */
7536 #define SQLITE_REPLACE 5
7537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7538
7539
7540 /*
7541 ** Undo the hack that converts floating point types to integer for
7542 ** builds on processors without floating point support.
@@ -7978,14 +8132,13 @@
7978 #ifndef SQLITE_POWERSAFE_OVERWRITE
7979 # define SQLITE_POWERSAFE_OVERWRITE 1
7980 #endif
7981
7982 /*
7983 ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
7984 ** It determines whether or not the features related to
7985 ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
7986 ** be overridden at runtime using the sqlite3_config() API.
7987 */
7988 #if !defined(SQLITE_DEFAULT_MEMSTATUS)
7989 # define SQLITE_DEFAULT_MEMSTATUS 1
7990 #endif
7991
@@ -8611,11 +8764,11 @@
8611 ** Estimated quantities used for query planning are stored as 16-bit
8612 ** logarithms. For quantity X, the value stored is 10*log2(X). This
8613 ** gives a possible range of values of approximately 1.0e986 to 1e-986.
8614 ** But the allowed values are "grainy". Not every value is representable.
8615 ** For example, quantities 16 and 17 are both represented by a LogEst
8616 ** of 40. However, since LogEst quantaties are suppose to be estimates,
8617 ** not exact values, this imprecision is not a problem.
8618 **
8619 ** "LogEst" is short for "Logarithmic Estimate".
8620 **
8621 ** Examples:
@@ -9011,11 +9164,11 @@
9011 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
9012 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
9013 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
9014 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
9015 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
9016 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int);
9017 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
9018 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
9019 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
9020 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
9021 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
@@ -9044,11 +9197,11 @@
9044 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
9045
9046 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
9047 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
9048 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9049 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree*, int);
9050
9051 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
9052 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
9053
9054 SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9124,10 +9277,11 @@
9124 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9125 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9126 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9127 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9128 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
 
9129
9130 #ifndef NDEBUG
9131 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
9132 #endif
9133
@@ -9666,10 +9820,16 @@
9666 # define VdbeCoverageAlwaysTaken(v)
9667 # define VdbeCoverageNeverTaken(v)
9668 # define VDBE_OFFSET_LINENO(x) 0
9669 #endif
9670
 
 
 
 
 
 
9671 #endif
9672
9673 /************** End of vdbe.h ************************************************/
9674 /************** Continuing where we left off in sqliteInt.h ******************/
9675 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9862,10 +10022,12 @@
9862 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
9863
9864 /* Functions used to truncate the database file. */
9865 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
9866
 
 
9867 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
9868 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
9869 #endif
9870
9871 /* Functions to support testing and debugging. */
@@ -10049,10 +10211,14 @@
10049 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
10050 #endif
10051
10052 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
10053
 
 
 
 
10054 #endif /* _PCACHE_H_ */
10055
10056 /************** End of pcache.h **********************************************/
10057 /************** Continuing where we left off in sqliteInt.h ******************/
10058
@@ -10735,11 +10901,11 @@
10735 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10736 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10737 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10738 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10739 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10740 #define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
10741 #define SQLITE_AllOpts 0xffff /* All optimizations */
10742
10743 /*
10744 ** Macros for testing whether or not optimizations are enabled or disabled.
10745 */
@@ -11317,16 +11483,18 @@
11317 unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
11318 unsigned bUnordered:1; /* Use this index for == or IN queries only */
11319 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
11320 unsigned isResized:1; /* True if resizeIndexObject() has been called */
11321 unsigned isCovering:1; /* True if this is a covering index */
 
11322 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11323 int nSample; /* Number of elements in aSample[] */
11324 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11325 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11326 IndexSample *aSample; /* Samples of the left-most key */
11327 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this table */
 
11328 #endif
11329 };
11330
11331 /*
11332 ** Allowed values for Index.idxType
@@ -11520,11 +11688,11 @@
11520 int nHeight; /* Height of the tree headed by this node */
11521 #endif
11522 int iTable; /* TK_COLUMN: cursor number of table holding column
11523 ** TK_REGISTER: register number
11524 ** TK_TRIGGER: 1 -> new, 0 -> old
11525 ** EP_Unlikely: 1000 times likelihood */
11526 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
11527 ** TK_VARIABLE: variable number (always >= 1). */
11528 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
11529 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11530 u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -11535,11 +11703,11 @@
11535 };
11536
11537 /*
11538 ** The following are the meanings of bits in the Expr.flags field.
11539 */
11540 #define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
11541 #define EP_Agg 0x000002 /* Contains one or more aggregate functions */
11542 #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
11543 #define EP_Error 0x000008 /* Expression contains one or more errors */
11544 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11545 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
@@ -11555,10 +11723,11 @@
11555 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11556 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11557 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11558 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11559 #define EP_Constant 0x080000 /* Node is a constant */
 
11560
11561 /*
11562 ** These macros can be used to test, set, or clear bits in the
11563 ** Expr.flags field.
11564 */
@@ -12412,13 +12581,15 @@
12412 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
12413 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
12414 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
12415 Parse *pParse; /* Parser context. */
12416 int walkerDepth; /* Number of subqueries */
 
12417 union { /* Extra data for callback */
12418 NameContext *pNC; /* Naming context */
12419 int i; /* Integer value */
 
12420 SrcList *pSrcList; /* FROM clause */
12421 struct SrcCount *pSrcCount; /* Counting column references */
12422 } u;
12423 };
12424
@@ -12815,10 +12986,11 @@
12815 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12816 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12817 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12818 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12819 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
 
12820 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12821 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12822 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12823 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12824 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13060,11 +13232,11 @@
13060 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13061
13062 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13063 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13064 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13065 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int);
13066 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13067 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
13068 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
13069 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
13070
@@ -13472,15 +13644,23 @@
13472 ** compatibility for legacy applications, the URI filename capability is
13473 ** disabled by default.
13474 **
13475 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13476 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
 
 
 
 
13477 */
13478 #ifndef SQLITE_USE_URI
13479 # define SQLITE_USE_URI 0
13480 #endif
13481
 
 
 
 
13482 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13483 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13484 #endif
13485
13486 /*
@@ -13566,12 +13746,12 @@
13566 ** than 1 GiB. The sqlite3_test_control() interface can be used to
13567 ** move the pending byte.
13568 **
13569 ** IMPORTANT: Changing the pending byte to any value other than
13570 ** 0x40000000 results in an incompatible database file format!
13571 ** Changing the pending byte during operating results in undefined
13572 ** and dileterious behavior.
13573 */
13574 #ifndef SQLITE_OMIT_WSD
13575 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
13576 #endif
13577
@@ -13646,10 +13826,13 @@
13646 #ifdef SQLITE_DISABLE_DIRSYNC
13647 "DISABLE_DIRSYNC",
13648 #endif
13649 #ifdef SQLITE_DISABLE_LFS
13650 "DISABLE_LFS",
 
 
 
13651 #endif
13652 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13653 "ENABLE_ATOMIC_WRITE",
13654 #endif
13655 #ifdef SQLITE_ENABLE_CEROD
@@ -13972,10 +14155,17 @@
13972 ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
13973 ** is not required for a match.
13974 */
13975 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
13976 int i, n;
 
 
 
 
 
 
 
13977 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
13978 n = sqlite3Strlen30(zOptName);
13979
13980 /* Since ArraySize(azCompileOpt) is normally in single digits, a
13981 ** linear search is adequate. No need for a binary search. */
@@ -14153,10 +14343,11 @@
14153 typedef struct VdbeFrame VdbeFrame;
14154 struct VdbeFrame {
14155 Vdbe *v; /* VM this frame belongs to */
14156 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
14157 Op *aOp; /* Program instructions for parent frame */
 
14158 Mem *aMem; /* Array of memory cells for parent frame */
14159 u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
14160 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
14161 void *token; /* Copy of SubProgram.token */
14162 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14165,11 +14356,12 @@
14165 int nOp; /* Size of aOp array */
14166 int nMem; /* Number of entries in aMem */
14167 int nOnceFlag; /* Number of entries in aOnceFlag */
14168 int nChildMem; /* Number of memory cells for child frame */
14169 int nChildCsr; /* Number of cursors for child frame */
14170 int nChange; /* Statement changes (Vdbe.nChanges) */
 
14171 };
14172
14173 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
14174
14175 /*
@@ -14316,10 +14508,20 @@
14316 /* A bitfield type for use inside of structures. Always follow with :N where
14317 ** N is the number of bits.
14318 */
14319 typedef unsigned bft; /* Bit Field Type */
14320
 
 
 
 
 
 
 
 
 
 
14321 /*
14322 ** An instance of the virtual machine. This structure contains the complete
14323 ** state of the virtual machine.
14324 **
14325 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14388,10 +14590,15 @@
14388 u32 expmask; /* Binding to these vars invalidates VM */
14389 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
14390 int nOnceFlag; /* Size of array aOnceFlag[] */
14391 u8 *aOnceFlag; /* Flags for OP_Once */
14392 AuxData *pAuxData; /* Linked list of auxdata allocations */
 
 
 
 
 
14393 };
14394
14395 /*
14396 ** The following are allowed values for Vdbe.magic
14397 */
@@ -14577,10 +14784,13 @@
14577 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
14578 wsdStatInit;
14579 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
14580 return SQLITE_MISUSE_BKPT;
14581 }
 
 
 
14582 *pCurrent = wsdStat.nowValue[op];
14583 *pHighwater = wsdStat.mxValue[op];
14584 if( resetFlag ){
14585 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14586 }
@@ -14596,10 +14806,15 @@
14596 int *pCurrent, /* Write current value here */
14597 int *pHighwater, /* Write high-water mark here */
14598 int resetFlag /* Reset high-water mark if true */
14599 ){
14600 int rc = SQLITE_OK; /* Return code */
 
 
 
 
 
14601 sqlite3_mutex_enter(db->mutex);
14602 switch( op ){
14603 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
14604 *pCurrent = db->lookaside.nOut;
14605 *pHighwater = db->lookaside.mxOut;
@@ -14774,11 +14989,11 @@
14774 **
14775 ** There is only one exported symbol in this file - the function
14776 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
14777 ** All other code has file scope.
14778 **
14779 ** SQLite processes all times and dates as Julian Day numbers. The
14780 ** dates and times are stored as the number of days since noon
14781 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
14782 ** calendar system.
14783 **
14784 ** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14789,11 +15004,11 @@
14789 ** be represented, even though julian day numbers allow a much wider
14790 ** range of dates.
14791 **
14792 ** The Gregorian calendar system is used for all dates and times,
14793 ** even those that predate the Gregorian calendar. Historians usually
14794 ** use the Julian calendar for dates prior to 1582-10-15 and for some
14795 ** dates afterwards, depending on locale. Beware of this difference.
14796 **
14797 ** The conversion algorithms are implemented based on descriptions
14798 ** in the following text:
14799 **
@@ -15061,11 +15276,11 @@
15061 return 1;
15062 }
15063 }
15064
15065 /*
15066 ** Attempt to parse the given string into a Julian Day Number. Return
15067 ** the number of errors.
15068 **
15069 ** The following are acceptable forms for the input string:
15070 **
15071 ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15632,11 +15847,11 @@
15632 **
15633 ** %d day of month
15634 ** %f ** fractional seconds SS.SSS
15635 ** %H hour 00-24
15636 ** %j day of year 000-366
15637 ** %J ** Julian day number
15638 ** %m month 01-12
15639 ** %M minute 00-59
15640 ** %s seconds since 1970-01-01
15641 ** %S seconds 00-59
15642 ** %w day of week 0-6 sunday==0
@@ -16257,10 +16472,14 @@
16257 MUTEX_LOGIC(sqlite3_mutex *mutex;)
16258 #ifndef SQLITE_OMIT_AUTOINIT
16259 int rc = sqlite3_initialize();
16260 if( rc ) return rc;
16261 #endif
 
 
 
 
16262 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
16263 sqlite3_mutex_enter(mutex);
16264 vfsUnlink(pVfs);
16265 if( makeDflt || vfsList==0 ){
16266 pVfs->pNext = vfsList;
@@ -18614,10 +18833,11 @@
18614 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18615 */
18616 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18617 #ifndef SQLITE_OMIT_AUTOINIT
18618 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
 
18619 #endif
18620 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18621 }
18622
18623 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19070,12 +19290,16 @@
19070 pthread_mutex_init(&p->mutex, 0);
19071 }
19072 break;
19073 }
19074 default: {
19075 assert( iType-2 >= 0 );
19076 assert( iType-2 < ArraySize(staticMutexes) );
 
 
 
 
19077 p = &staticMutexes[iType-2];
19078 #if SQLITE_MUTEX_NREF
19079 p->id = iType;
19080 #endif
19081 break;
@@ -20293,15 +20517,16 @@
20293 }
20294 assert( sqlite3_mutex_notheld(mem0.mutex) );
20295
20296
20297 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20298 /* Verify that no more than two scratch allocations per thread
20299 ** are outstanding at one time. (This is only checked in the
20300 ** single-threaded case since checking in the multi-threaded case
20301 ** would be much more complicated.) */
20302 assert( scratchAllocOut<=1 );
 
20303 if( p ) scratchAllocOut++;
20304 #endif
20305
20306 return p;
20307 }
@@ -20945,11 +21170,11 @@
20945 sqlite_uint64 longvalue; /* Value for integer types */
20946 LONGDOUBLE_TYPE realvalue; /* Value for real types */
20947 const et_info *infop; /* Pointer to the appropriate info structure */
20948 char *zOut; /* Rendering buffer */
20949 int nOut; /* Size of the rendering buffer */
20950 char *zExtra; /* Malloced memory used by some conversion */
20951 #ifndef SQLITE_OMIT_FLOATING_POINT
20952 int exp, e2; /* exponent of real numbers */
20953 int nsd; /* Number of significant digits returned */
20954 double rounder; /* Used for rounding floating point values */
20955 etByte flag_dp; /* True if decimal point should be shown */
@@ -20956,10 +21181,17 @@
20956 etByte flag_rtz; /* True if trailing zeros should be removed */
20957 #endif
20958 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
20959 char buf[etBUFSIZE]; /* Conversion buffer */
20960
 
 
 
 
 
 
 
20961 bufpt = 0;
20962 if( bFlags ){
20963 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20964 pArgList = va_arg(ap, PrintfArguments*);
20965 }
@@ -21062,11 +21294,10 @@
21062 return;
21063 }
21064 break;
21065 }
21066 }
21067 zExtra = 0;
21068
21069 /*
21070 ** At this point, variables are initialized as follows:
21071 **
21072 ** flag_alternateform TRUE if a '#' is present.
@@ -21353,17 +21584,20 @@
21353 bufpt = getTextArg(pArgList);
21354 c = bufpt ? bufpt[0] : 0;
21355 }else{
21356 c = va_arg(ap,int);
21357 }
21358 buf[0] = (char)c;
21359 if( precision>=0 ){
21360 for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
21361 length = precision;
21362 }else{
21363 length =1;
 
21364 }
 
 
21365 bufpt = buf;
21366 break;
21367 case etSTRING:
21368 case etDYNSTRING:
21369 if( bArgList ){
@@ -21460,15 +21694,18 @@
21460 ** The text of the conversion is pointed to by "bufpt" and is
21461 ** "length" characters long. The field width is "width". Do
21462 ** the output.
21463 */
21464 width -= length;
21465 if( width>0 && !flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
21466 sqlite3StrAccumAppend(pAccum, bufpt, length);
21467 if( width>0 && flag_leftjustify ) sqlite3AppendSpace(pAccum, width);
21468
21469 if( zExtra ) sqlite3_free(zExtra);
 
 
 
21470 }/* End for loop over the format string */
21471 } /* End of function */
21472
21473 /*
21474 ** Enlarge the memory allocation on a StrAccum object so that it is
@@ -21491,10 +21728,15 @@
21491 return N;
21492 }else{
21493 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
21494 i64 szNew = p->nChar;
21495 szNew += N + 1;
 
 
 
 
 
21496 if( szNew > p->mxAlloc ){
21497 sqlite3StrAccumReset(p);
21498 setStrAccumError(p, STRACCUM_TOOBIG);
21499 return 0;
21500 }else{
@@ -21507,10 +21749,11 @@
21507 }
21508 if( zNew ){
21509 assert( p->zText!=0 || p->nChar==0 );
21510 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
21511 p->zText = zNew;
 
21512 }else{
21513 sqlite3StrAccumReset(p);
21514 setStrAccumError(p, STRACCUM_NOMEM);
21515 return 0;
21516 }
@@ -21517,15 +21760,15 @@
21517 }
21518 return N;
21519 }
21520
21521 /*
21522 ** Append N space characters to the given string buffer.
21523 */
21524 SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum *p, int N){
21525 if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return;
21526 while( (N--)>0 ) p->zText[p->nChar++] = ' ';
21527 }
21528
21529 /*
21530 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
21531 ** So enlarge if first, then do the append.
@@ -21676,10 +21919,17 @@
21676 */
21677 SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
21678 char *z;
21679 char zBase[SQLITE_PRINT_BUF_SIZE];
21680 StrAccum acc;
 
 
 
 
 
 
 
21681 #ifndef SQLITE_OMIT_AUTOINIT
21682 if( sqlite3_initialize() ) return 0;
21683 #endif
21684 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
21685 acc.useMalloc = 2;
@@ -21718,10 +21968,17 @@
21718 ** sqlite3_vsnprintf() is the varargs version.
21719 */
21720 SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
21721 StrAccum acc;
21722 if( n<=0 ) return zBuf;
 
 
 
 
 
 
 
21723 sqlite3StrAccumInit(&acc, zBuf, n, 0);
21724 acc.useMalloc = 0;
21725 sqlite3VXPrintf(&acc, 0, zFormat, ap);
21726 return sqlite3StrAccumFinish(&acc);
21727 }
@@ -21909,15 +22166,23 @@
21909 #else
21910 # define wsdPrng sqlite3Prng
21911 #endif
21912
21913 #if SQLITE_THREADSAFE
21914 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
 
 
 
 
 
 
 
 
 
 
21915 sqlite3_mutex_enter(mutex);
21916 #endif
21917
21918 if( N<=0 ){
21919 wsdPrng.isInit = 0;
21920 sqlite3_mutex_leave(mutex);
21921 return;
21922 }
21923
@@ -23035,17 +23300,27 @@
23035 ** case-independent fashion, using the same definition of "case
23036 ** independence" that SQLite uses internally when comparing identifiers.
23037 */
23038 SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
23039 register unsigned char *a, *b;
 
 
 
 
 
23040 a = (unsigned char *)zLeft;
23041 b = (unsigned char *)zRight;
23042 while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23043 return UpperToLower[*a] - UpperToLower[*b];
23044 }
23045 SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
23046 register unsigned char *a, *b;
 
 
 
 
 
23047 a = (unsigned char *)zLeft;
23048 b = (unsigned char *)zRight;
23049 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23050 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
23051 }
@@ -32574,10 +32849,15 @@
32574 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
32575 # error "WAL mode requires support from the Windows NT kernel, compile\
32576 with SQLITE_OMIT_WAL."
32577 #endif
32578
 
 
 
 
 
32579 /*
32580 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
32581 ** based on the sub-platform)?
32582 */
32583 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32703,14 +32983,15 @@
32703 # define winGetDirSep() '\\'
32704 #endif
32705
32706 /*
32707 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
32708 ** mode (e.g. these APIs are available in the Windows CE SDK; however, they
32709 ** are not present in the header file)?
32710 */
32711 #if SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL)
 
32712 /*
32713 ** Two of the file mapping APIs are different under WinRT. Figure out which
32714 ** set we need.
32715 */
32716 #if SQLITE_OS_WINRT
@@ -32734,11 +33015,11 @@
32734
32735 /*
32736 ** This file mapping API is common to both Win32 and WinRT.
32737 */
32738 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
32739 #endif /* SQLITE_WIN32_FILEMAPPING_API && !defined(SQLITE_OMIT_WAL) */
32740
32741 /*
32742 ** Some Microsoft compilers lack this definition.
32743 */
32744 #ifndef INVALID_FILE_ATTRIBUTES
@@ -33027,21 +33308,21 @@
33027
33028 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
33029 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
33030
33031 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33032 !defined(SQLITE_OMIT_WAL))
33033 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
33034 #else
33035 { "CreateFileMappingA", (SYSCALL)0, 0 },
33036 #endif
33037
33038 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
33039 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
33040
33041 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33042 !defined(SQLITE_OMIT_WAL))
33043 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
33044 #else
33045 { "CreateFileMappingW", (SYSCALL)0, 0 },
33046 #endif
33047
@@ -33377,11 +33658,12 @@
33377 #ifndef osLockFileEx
33378 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
33379 LPOVERLAPPED))aSyscall[48].pCurrent)
33380 #endif
33381
33382 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
 
33383 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
33384 #else
33385 { "MapViewOfFile", (SYSCALL)0, 0 },
33386 #endif
33387
@@ -33447,11 +33729,11 @@
33447 #endif
33448
33449 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
33450 LPOVERLAPPED))aSyscall[58].pCurrent)
33451
33452 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
33453 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
33454 #else
33455 { "UnmapViewOfFile", (SYSCALL)0, 0 },
33456 #endif
33457
@@ -33510,11 +33792,11 @@
33510 #endif
33511
33512 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
33513 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
33514
33515 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33516 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
33517 #else
33518 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
33519 #endif
33520
@@ -33574,11 +33856,11 @@
33574
33575 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
33576
33577 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
33578
33579 #if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
33580 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
33581 #else
33582 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
33583 #endif
33584
@@ -39150,10 +39432,17 @@
39150 */
39151 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
39152 assert( pCache->pCache!=0 );
39153 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
39154 }
 
 
 
 
 
 
 
39155
39156 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39157 /*
39158 ** For all dirty pages currently in the cache, invoke the specified
39159 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40149,10 +40438,15 @@
40149 pcache1Shrink /* xShrink */
40150 };
40151 sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
40152 }
40153
 
 
 
 
 
40154 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40155 /*
40156 ** This function is called to free superfluous dynamically allocated memory
40157 ** held by the pager system. Memory in use by any SQLite pager allocated
40158 ** by the current thread may be sqlite3_free()ed.
@@ -43758,11 +44052,11 @@
43758 ** should be page numbers which are never 0xffffffff. So filling
43759 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
43760 **
43761 ** For an encrypted database, the situation is more complex: bytes
43762 ** 24..39 of the database are white noise. But the probability of
43763 ** white noising equaling 16 bytes of 0xff is vanishingly small so
43764 ** we should still be ok.
43765 */
43766 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
43767 }else{
43768 u8 *dbFileVers = &((u8*)pPg->pData)[24];
@@ -47705,10 +47999,22 @@
47705 }
47706
47707 return SQLITE_OK;
47708 }
47709 #endif
 
 
 
 
 
 
 
 
 
 
 
 
47710
47711 /*
47712 ** Return a pointer to the data for the specified page.
47713 */
47714 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
@@ -47922,11 +48228,12 @@
47922 */
47923 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){
47924 int rc = SQLITE_OK;
47925 if( pPager->pWal ){
47926 rc = sqlite3WalCheckpoint(pPager->pWal, eMode,
47927 pPager->xBusyHandler, pPager->pBusyHandlerArg,
 
47928 pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
47929 pnLog, pnCkpt
47930 );
47931 }
47932 return rc;
@@ -48103,10 +48410,11 @@
48103 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
48104 assert( pPager->eState>=PAGER_READER );
48105 return sqlite3WalFramesize(pPager->pWal);
48106 }
48107 #endif
 
48108
48109 #endif /* SQLITE_OMIT_DISKIO */
48110
48111 /************** End of pager.c ***********************************************/
48112 /************** Begin file wal.c *********************************************/
@@ -49613,11 +49921,11 @@
49613
49614 /*
49615 ** Free an iterator allocated by walIteratorInit().
49616 */
49617 static void walIteratorFree(WalIterator *p){
49618 sqlite3ScratchFree(p);
49619 }
49620
49621 /*
49622 ** Construct a WalInterator object that can be used to loop over all
49623 ** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49648,21 +49956,21 @@
49648 /* Allocate space for the WalIterator object. */
49649 nSegment = walFramePage(iLast) + 1;
49650 nByte = sizeof(WalIterator)
49651 + (nSegment-1)*sizeof(struct WalSegment)
49652 + iLast*sizeof(ht_slot);
49653 p = (WalIterator *)sqlite3ScratchMalloc(nByte);
49654 if( !p ){
49655 return SQLITE_NOMEM;
49656 }
49657 memset(p, 0, nByte);
49658 p->nSegment = nSegment;
49659
49660 /* Allocate temporary space used by the merge-sort routine. This block
49661 ** of memory will be freed before this function returns.
49662 */
49663 aTmp = (ht_slot *)sqlite3ScratchMalloc(
49664 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
49665 );
49666 if( !aTmp ){
49667 rc = SQLITE_NOMEM;
49668 }
@@ -49695,11 +50003,11 @@
49695 p->aSegment[i].nEntry = nEntry;
49696 p->aSegment[i].aIndex = aIndex;
49697 p->aSegment[i].aPgno = (u32 *)aPgno;
49698 }
49699 }
49700 sqlite3ScratchFree(aTmp);
49701
49702 if( rc!=SQLITE_OK ){
49703 walIteratorFree(p);
49704 }
49705 *pp = p;
@@ -49731,10 +50039,42 @@
49731 ** Return the page-size in bytes used by the database.
49732 */
49733 static int walPagesize(Wal *pWal){
49734 return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
49735 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49736
49737 /*
49738 ** Copy as much content as we can from the WAL back into the database file
49739 ** in response to an sqlite3_wal_checkpoint() request or the equivalent.
49740 **
@@ -49766,11 +50106,11 @@
49766 ** time.
49767 */
49768 static int walCheckpoint(
49769 Wal *pWal, /* Wal connection */
49770 int eMode, /* One of PASSIVE, FULL or RESTART */
49771 int (*xBusyCall)(void*), /* Function to call when busy */
49772 void *pBusyArg, /* Context argument for xBusyHandler */
49773 int sync_flags, /* Flags for OsSync() (or 0) */
49774 u8 *zBuf /* Temporary buffer to use */
49775 ){
49776 int rc; /* Return code */
@@ -49780,11 +50120,10 @@
49780 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
49781 u32 mxSafeFrame; /* Max frame that can be backfilled */
49782 u32 mxPage; /* Max database page to write */
49783 int i; /* Loop counter */
49784 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
49785 int (*xBusy)(void*) = 0; /* Function to call when waiting for locks */
49786
49787 szPage = walPagesize(pWal);
49788 testcase( szPage<=32768 );
49789 testcase( szPage>=65536 );
49790 pInfo = walCkptInfo(pWal);
@@ -49795,11 +50134,13 @@
49795 if( rc!=SQLITE_OK ){
49796 return rc;
49797 }
49798 assert( pIter );
49799
49800 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ) xBusy = xBusyCall;
 
 
49801
49802 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
49803 ** safe to write into the database. Frames beyond mxSafeFrame might
49804 ** overwrite database pages that are in use by active readers and thus
49805 ** cannot be backfilled from the WAL.
@@ -49884,23 +50225,42 @@
49884 /* Reset the return code so as not to report a checkpoint failure
49885 ** just because there are active readers. */
49886 rc = SQLITE_OK;
49887 }
49888
49889 /* If this is an SQLITE_CHECKPOINT_RESTART operation, and the entire wal
49890 ** file has been copied into the database file, then block until all
49891 ** readers have finished using the wal file. This ensures that the next
49892 ** process to write to the database restarts the wal file.
49893 */
49894 if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){
49895 assert( pWal->writeLock );
49896 if( pInfo->nBackfill<pWal->hdr.mxFrame ){
49897 rc = SQLITE_BUSY;
49898 }else if( eMode==SQLITE_CHECKPOINT_RESTART ){
 
 
49899 assert( mxSafeFrame==pWal->hdr.mxFrame );
49900 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
49901 if( rc==SQLITE_OK ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49902 walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
49903 }
49904 }
49905 }
49906
@@ -50634,11 +50994,10 @@
50634 assert( walFramePgno(pWal, iFrame)!=1 );
50635 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
50636 }
50637 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
50638 }
50639 assert( rc==SQLITE_OK );
50640 return rc;
50641 }
50642
50643 /*
50644 ** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
@@ -50683,11 +51042,10 @@
50683 }
50684
50685 return rc;
50686 }
50687
50688
50689 /*
50690 ** This function is called just before writing a set of frames to the log
50691 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
50692 ** to the current log file, it is possible to overwrite the start of the
50693 ** existing log file with the new frames (i.e. "reset" the log). If so,
@@ -50716,24 +51074,12 @@
50716 ** wal-index header to reflect this.
50717 **
50718 ** In theory it would be Ok to update the cache of the header only
50719 ** at this point. But updating the actual wal-index header is also
50720 ** safe and means there is no special case for sqlite3WalUndo()
50721 ** to handle if this transaction is rolled back.
50722 */
50723 int i; /* Loop counter */
50724 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
50725
50726 pWal->nCkpt++;
50727 pWal->hdr.mxFrame = 0;
50728 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
50729 aSalt[1] = salt1;
50730 walIndexWriteHdr(pWal);
50731 pInfo->nBackfill = 0;
50732 pInfo->aReadMark[1] = 0;
50733 for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
50734 assert( pInfo->aReadMark[0]==0 );
50735 walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
50736 }else if( rc!=SQLITE_BUSY ){
50737 return rc;
50738 }
50739 }
@@ -51017,11 +51363,11 @@
51017 ** If parameter xBusy is not NULL, it is a pointer to a busy-handler
51018 ** callback. In this case this function runs a blocking checkpoint.
51019 */
51020 SQLITE_PRIVATE int sqlite3WalCheckpoint(
51021 Wal *pWal, /* Wal connection */
51022 int eMode, /* PASSIVE, FULL or RESTART */
51023 int (*xBusy)(void*), /* Function to call when busy */
51024 void *pBusyArg, /* Context argument for xBusyHandler */
51025 int sync_flags, /* Flags to sync db file with (or 0) */
51026 int nBuf, /* Size of temporary buffer */
51027 u8 *zBuf, /* Temporary buffer to use */
@@ -51029,40 +51375,54 @@
51029 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
51030 ){
51031 int rc; /* Return code */
51032 int isChanged = 0; /* True if a new wal-index header is loaded */
51033 int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
 
51034
51035 assert( pWal->ckptLock==0 );
51036 assert( pWal->writeLock==0 );
51037
 
 
 
 
51038 if( pWal->readOnly ) return SQLITE_READONLY;
51039 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
 
 
 
51040 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
51041 if( rc ){
51042 /* Usually this is SQLITE_BUSY meaning that another thread or process
51043 ** is already running a checkpoint, or maybe a recovery. But it might
51044 ** also be SQLITE_IOERR. */
 
 
 
 
 
51045 return rc;
51046 }
51047 pWal->ckptLock = 1;
51048
51049 /* If this is a blocking-checkpoint, then obtain the write-lock as well
51050 ** to prevent any writers from running while the checkpoint is underway.
51051 ** This has to be done before the call to walIndexReadHdr() below.
51052 **
51053 ** If the writer lock cannot be obtained, then a passive checkpoint is
51054 ** run instead. Since the checkpointer is not holding the writer lock,
51055 ** there is no point in blocking waiting for any readers. Assuming no
51056 ** other error occurs, this function will return SQLITE_BUSY to the caller.
51057 */
51058 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
51059 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1);
51060 if( rc==SQLITE_OK ){
51061 pWal->writeLock = 1;
51062 }else if( rc==SQLITE_BUSY ){
51063 eMode2 = SQLITE_CHECKPOINT_PASSIVE;
 
51064 rc = SQLITE_OK;
51065 }
51066 }
51067
51068 /* Read the wal-index header. */
@@ -51076,11 +51436,11 @@
51076 /* Copy data from the log to the database file. */
51077 if( rc==SQLITE_OK ){
51078 if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
51079 rc = SQLITE_CORRUPT_BKPT;
51080 }else{
51081 rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf);
51082 }
51083
51084 /* If no error occurred, set the output variables. */
51085 if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
51086 if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
@@ -51713,10 +52073,15 @@
51713 ** but cursors cannot be shared. Each cursor is associated with a
51714 ** particular database connection identified BtCursor.pBtree.db.
51715 **
51716 ** Fields in this structure are accessed under the BtShared.mutex
51717 ** found at self->pBt->mutex.
 
 
 
 
 
51718 */
51719 struct BtCursor {
51720 Btree *pBtree; /* The Btree to which this cursor belongs */
51721 BtShared *pBt; /* The BtShared this cursor points to */
51722 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -51725,11 +52090,12 @@
51725 CellInfo info; /* A parse of the cell we are pointing at */
51726 i64 nKey; /* Size of pKey, or last integer key */
51727 void *pKey; /* Saved key that was cursor last known position */
51728 Pgno pgnoRoot; /* The root page of this tree */
51729 int nOvflAlloc; /* Allocated size of aOverflow[] array */
51730 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
 
51731 u8 curFlags; /* zero or more BTCF_* flags defined below */
51732 u8 eState; /* One of the CURSOR_XXX constants (see below) */
51733 u8 hints; /* As configured by CursorSetHints() */
51734 i16 iPage; /* Index of current page in apPage */
51735 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -51771,11 +52137,11 @@
51771 ** CURSOR_FAULT:
51772 ** An unrecoverable error (an I/O error or a malloc failure) has occurred
51773 ** on a different connection that shares the BtShared cache with this
51774 ** cursor. The error has left the cache in an inconsistent state.
51775 ** Do nothing else with this cursor. Any attempt to use the cursor
51776 ** should return the error code stored in BtCursor.skip
51777 */
51778 #define CURSOR_INVALID 0
51779 #define CURSOR_VALID 1
51780 #define CURSOR_SKIPNEXT 2
51781 #define CURSOR_REQUIRESEEK 3
@@ -53321,10 +53687,15 @@
53321 /*
53322 ** Defragment the page given. All Cells are moved to the
53323 ** end of the page and all free space is collected into one
53324 ** big FreeBlk that occurs in between the header and cell
53325 ** pointer array and the cell content area.
 
 
 
 
 
53326 */
53327 static int defragmentPage(MemPage *pPage){
53328 int i; /* Loop counter */
53329 int pc; /* Address of the i-th cell */
53330 int hdr; /* Offset to the page header */
@@ -53333,28 +53704,27 @@
53333 int cellOffset; /* Offset to the cell pointer array */
53334 int cbrk; /* Offset to the cell content area */
53335 int nCell; /* Number of cells on the page */
53336 unsigned char *data; /* The page data */
53337 unsigned char *temp; /* Temp area for cell content */
 
53338 int iCellFirst; /* First allowable cell index */
53339 int iCellLast; /* Last possible cell index */
53340
53341
53342 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53343 assert( pPage->pBt!=0 );
53344 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
53345 assert( pPage->nOverflow==0 );
53346 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53347 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53348 data = pPage->aData;
53349 hdr = pPage->hdrOffset;
53350 cellOffset = pPage->cellOffset;
53351 nCell = pPage->nCell;
53352 assert( nCell==get2byte(&data[hdr+3]) );
53353 usableSize = pPage->pBt->usableSize;
53354 cbrk = get2byte(&data[hdr+5]);
53355 memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
53356 cbrk = usableSize;
53357 iCellFirst = cellOffset + 2*nCell;
53358 iCellLast = usableSize - 4;
53359 for(i=0; i<nCell; i++){
53360 u8 *pAddr; /* The i-th cell pointer */
@@ -53369,11 +53739,11 @@
53369 if( pc<iCellFirst || pc>iCellLast ){
53370 return SQLITE_CORRUPT_BKPT;
53371 }
53372 #endif
53373 assert( pc>=iCellFirst && pc<=iCellLast );
53374 size = cellSizePtr(pPage, &temp[pc]);
53375 cbrk -= size;
53376 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
53377 if( cbrk<iCellFirst ){
53378 return SQLITE_CORRUPT_BKPT;
53379 }
@@ -53383,12 +53753,20 @@
53383 }
53384 #endif
53385 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
53386 testcase( cbrk+size==usableSize );
53387 testcase( pc+size==usableSize );
53388 memcpy(&data[cbrk], &temp[pc], size);
53389 put2byte(pAddr, cbrk);
 
 
 
 
 
 
 
 
 
53390 }
53391 assert( cbrk>=iCellFirst );
53392 put2byte(&data[hdr+5], cbrk);
53393 data[hdr+1] = 0;
53394 data[hdr+2] = 0;
@@ -53398,10 +53776,73 @@
53398 if( cbrk-iCellFirst!=pPage->nFree ){
53399 return SQLITE_CORRUPT_BKPT;
53400 }
53401 return SQLITE_OK;
53402 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53403
53404 /*
53405 ** Allocate nByte bytes of space from within the B-Tree page passed
53406 ** as the first argument. Write into *pIdx the index into pPage->aData[]
53407 ** of the first byte of allocated space. Return either SQLITE_OK or
@@ -53416,80 +53857,58 @@
53416 */
53417 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
53418 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
53419 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
53420 int top; /* First byte of cell content area */
 
53421 int gap; /* First byte of gap between cell pointers and cell content */
53422 int rc; /* Integer return code */
53423 int usableSize; /* Usable size of the page */
53424
53425 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53426 assert( pPage->pBt );
53427 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53428 assert( nByte>=0 ); /* Minimum cell size is 4 */
53429 assert( pPage->nFree>=nByte );
53430 assert( pPage->nOverflow==0 );
53431 usableSize = pPage->pBt->usableSize;
53432 assert( nByte < usableSize-8 );
53433
53434 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
53435 gap = pPage->cellOffset + 2*pPage->nCell;
53436 assert( gap<=65536 );
53437 top = get2byte(&data[hdr+5]);
53438 if( gap>top ){
53439 if( top==0 ){
53440 top = 65536;
53441 }else{
53442 return SQLITE_CORRUPT_BKPT;
53443 }
53444 }
53445
53446 /* If there is enough space between gap and top for one more cell pointer
53447 ** array entry offset, and if the freelist is not empty, then search the
53448 ** freelist looking for a free slot big enough to satisfy the request.
53449 */
53450 testcase( gap+2==top );
53451 testcase( gap+1==top );
53452 testcase( gap==top );
53453 if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53454 int pc, addr;
53455 for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){
53456 int size; /* Size of the free slot */
53457 if( pc>usableSize-4 || pc<addr+4 ){
53458 return SQLITE_CORRUPT_BKPT;
53459 }
53460 size = get2byte(&data[pc+2]);
53461 if( size>=nByte ){
53462 int x = size - nByte;
53463 testcase( x==4 );
53464 testcase( x==3 );
53465 if( x<4 ){
53466 if( data[hdr+7]>=60 ) goto defragment_page;
53467 /* Remove the slot from the free-list. Update the number of
53468 ** fragmented bytes within the page. */
53469 memcpy(&data[addr], &data[pc], 2);
53470 data[hdr+7] += (u8)x;
53471 }else if( size+pc > usableSize ){
53472 return SQLITE_CORRUPT_BKPT;
53473 }else{
53474 /* The slot remains on the free-list. Reduce its size to account
53475 ** for the portion used by the new allocation. */
53476 put2byte(&data[pc+2], x);
53477 }
53478 *pIdx = pc + x;
53479 return SQLITE_OK;
53480 }
53481 }
53482 }
53483
53484 /* The request could not be fulfilled using a freelist slot. Check
53485 ** to see if defragmentation is necessary.
53486 */
53487 testcase( gap+2+nByte==top );
53488 if( gap+2+nByte>top ){
53489 defragment_page:
53490 testcase( pPage->nCell==0 );
53491 rc = defragmentPage(pPage);
53492 if( rc ) return rc;
53493 top = get2byteNotZero(&data[hdr+5]);
53494 assert( gap+nByte<=top );
53495 }
@@ -53532,11 +53951,11 @@
53532 unsigned char *data = pPage->aData; /* Page content */
53533
53534 assert( pPage->pBt!=0 );
53535 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53536 assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53537 assert( iEnd <= pPage->pBt->usableSize );
53538 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53539 assert( iSize>=4 ); /* Minimum cell size is 4 */
53540 assert( iStart<=iLast );
53541
53542 /* Overwrite deleted information with zeros when the secure_delete
@@ -53627,22 +54046,36 @@
53627 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
53628 flagByte &= ~PTF_LEAF;
53629 pPage->childPtrSize = 4-4*pPage->leaf;
53630 pBt = pPage->pBt;
53631 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
 
 
 
 
 
 
53632 pPage->intKey = 1;
53633 pPage->intKeyLeaf = pPage->leaf;
53634 pPage->noPayload = !pPage->leaf;
53635 pPage->maxLocal = pBt->maxLeaf;
53636 pPage->minLocal = pBt->minLeaf;
53637 }else if( flagByte==PTF_ZERODATA ){
 
 
 
 
 
 
53638 pPage->intKey = 0;
53639 pPage->intKeyLeaf = 0;
53640 pPage->noPayload = 0;
53641 pPage->maxLocal = pBt->maxLocal;
53642 pPage->minLocal = pBt->minLocal;
53643 }else{
 
 
53644 return SQLITE_CORRUPT_BKPT;
53645 }
53646 pPage->max1bytePayload = pBt->max1bytePayload;
53647 return SQLITE_OK;
53648 }
@@ -53678,25 +54111,37 @@
53678
53679 pBt = pPage->pBt;
53680
53681 hdr = pPage->hdrOffset;
53682 data = pPage->aData;
 
 
53683 if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
53684 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
53685 pPage->maskPage = (u16)(pBt->pageSize - 1);
53686 pPage->nOverflow = 0;
53687 usableSize = pBt->usableSize;
53688 pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf;
53689 pPage->aDataEnd = &data[usableSize];
53690 pPage->aCellIdx = &data[cellOffset];
 
 
 
53691 top = get2byteNotZero(&data[hdr+5]);
 
 
53692 pPage->nCell = get2byte(&data[hdr+3]);
53693 if( pPage->nCell>MX_CELL(pBt) ){
53694 /* To many cells for a single page. The page must be corrupt */
53695 return SQLITE_CORRUPT_BKPT;
53696 }
53697 testcase( pPage->nCell==MX_CELL(pBt) );
 
 
 
 
 
53698
53699 /* A malformed database page might cause us to read past the end
53700 ** of page when parsing a cell.
53701 **
53702 ** The following block of code checks early to see if a cell extends
@@ -53726,17 +54171,24 @@
53726 }
53727 if( !pPage->leaf ) iCellLast++;
53728 }
53729 #endif
53730
53731 /* Compute the total free space on the page */
 
 
 
53732 pc = get2byte(&data[hdr+1]);
53733 nFree = data[hdr+7] + top;
53734 while( pc>0 ){
53735 u16 next, size;
53736 if( pc<iCellFirst || pc>iCellLast ){
53737 /* Start of free block is off the page */
 
 
 
 
53738 return SQLITE_CORRUPT_BKPT;
53739 }
53740 next = get2byte(&data[pc]);
53741 size = get2byte(&data[pc+2]);
53742 if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
@@ -54138,10 +54590,13 @@
54138 pBt->pPage1 = 0;
54139 if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
54140 #ifdef SQLITE_SECURE_DELETE
54141 pBt->btsFlags |= BTS_SECURE_DELETE;
54142 #endif
 
 
 
54143 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
54144 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
54145 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
54146 pBt->pageSize = 0;
54147 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -54156,10 +54611,13 @@
54156 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
54157 }
54158 #endif
54159 nReserve = 0;
54160 }else{
 
 
 
54161 nReserve = zDbHeader[20];
54162 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
54163 #ifndef SQLITE_OMIT_AUTOVACUUM
54164 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
54165 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
@@ -54353,11 +54811,11 @@
54353
54354 /* Rollback any active transaction and free the handle structure.
54355 ** The call to sqlite3BtreeRollback() drops any table-locks held by
54356 ** this handle.
54357 */
54358 sqlite3BtreeRollback(p, SQLITE_OK);
54359 sqlite3BtreeLeave(p);
54360
54361 /* If there are still other outstanding references to the shared-btree
54362 ** structure, return now. The remainder of this procedure cleans
54363 ** up the shared-btree.
@@ -54665,10 +55123,13 @@
54665 if( nPage>0 ){
54666 u32 pageSize;
54667 u32 usableSize;
54668 u8 *page1 = pPage1->aData;
54669 rc = SQLITE_NOTADB;
 
 
 
54670 if( memcmp(page1, zMagicHeader, 16)!=0 ){
54671 goto page1_init_failed;
54672 }
54673
54674 #ifdef SQLITE_OMIT_WAL
@@ -54705,26 +55166,39 @@
54705 }
54706 rc = SQLITE_NOTADB;
54707 }
54708 #endif
54709
54710 /* The maximum embedded fraction must be exactly 25%. And the minimum
54711 ** embedded fraction must be 12.5% for both leaf-data and non-leaf-data.
 
54712 ** The original design allowed these amounts to vary, but as of
54713 ** version 3.6.0, we require them to be fixed.
54714 */
54715 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
54716 goto page1_init_failed;
54717 }
 
 
 
54718 pageSize = (page1[16]<<8) | (page1[17]<<16);
 
 
54719 if( ((pageSize-1)&pageSize)!=0
54720 || pageSize>SQLITE_MAX_PAGE_SIZE
54721 || pageSize<=256
54722 ){
54723 goto page1_init_failed;
54724 }
54725 assert( (pageSize & 7)==0 );
 
 
 
 
 
 
 
54726 usableSize = pageSize - page1[20];
54727 if( (u32)pageSize!=pBt->pageSize ){
54728 /* After reading the first page of the database assuming a page size
54729 ** of BtShared.pageSize, we have discovered that the page-size is
54730 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
@@ -54741,10 +55215,13 @@
54741 }
54742 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
54743 rc = SQLITE_CORRUPT_BKPT;
54744 goto page1_init_failed;
54745 }
 
 
 
54746 if( usableSize<480 ){
54747 goto page1_init_failed;
54748 }
54749 pBt->pageSize = pageSize;
54750 pBt->usableSize = usableSize;
@@ -55646,64 +56123,95 @@
55646 return rc;
55647 }
55648
55649 /*
55650 ** This routine sets the state to CURSOR_FAULT and the error
55651 ** code to errCode for every cursor on BtShared that pBtree
55652 ** references.
55653 **
55654 ** Every cursor is tripped, including cursors that belong
55655 ** to other database connections that happen to be sharing
55656 ** the cache with pBtree.
55657 **
55658 ** This routine gets called when a rollback occurs.
55659 ** All cursors using the same cache must be tripped
55660 ** to prevent them from trying to use the btree after
55661 ** the rollback. The rollback may have deleted tables
55662 ** or moved root pages, so it is not sufficient to
55663 ** save the state of the cursor. The cursor must be
55664 ** invalidated.
55665 */
55666 SQLITE_PRIVATE void sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode){
 
 
 
 
 
 
 
 
 
55667 BtCursor *p;
55668 if( pBtree==0 ) return;
55669 sqlite3BtreeEnter(pBtree);
55670 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
55671 int i;
55672 sqlite3BtreeClearCursor(p);
55673 p->eState = CURSOR_FAULT;
55674 p->skipNext = errCode;
55675 for(i=0; i<=p->iPage; i++){
55676 releasePage(p->apPage[i]);
55677 p->apPage[i] = 0;
55678 }
55679 }
55680 sqlite3BtreeLeave(pBtree);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55681 }
55682
55683 /*
55684 ** Rollback the transaction in progress. All cursors will be
55685 ** invalided by this operation. Any attempt to use a cursor
55686 ** that was open at the beginning of this operation will result
55687 ** in an error.
 
 
55688 **
55689 ** This will release the write lock on the database file. If there
55690 ** are no active cursors, it also releases the read lock.
55691 */
55692 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode){
55693 int rc;
55694 BtShared *pBt = p->pBt;
55695 MemPage *pPage1;
55696
 
 
55697 sqlite3BtreeEnter(p);
55698 if( tripCode==SQLITE_OK ){
55699 rc = tripCode = saveAllCursors(pBt, 0, 0);
 
55700 }else{
55701 rc = SQLITE_OK;
55702 }
55703 if( tripCode ){
55704 sqlite3BtreeTripAllCursors(p, tripCode);
 
 
55705 }
55706 btreeIntegrity(p);
55707
55708 if( p->inTrans==TRANS_WRITE ){
55709 int rc2;
@@ -56034,17 +56542,13 @@
56034 **
56035 ** This routine cannot fail. It always returns SQLITE_OK.
56036 */
56037 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
56038 assert( cursorHoldsMutex(pCur) );
56039 assert( pCur->eState==CURSOR_INVALID || pCur->eState==CURSOR_VALID );
56040 if( pCur->eState!=CURSOR_VALID ){
56041 *pSize = 0;
56042 }else{
56043 getCellInfo(pCur);
56044 *pSize = pCur->info.nKey;
56045 }
56046 return SQLITE_OK;
56047 }
56048
56049 /*
56050 ** Set *pSize to the number of bytes of data in the entry the
@@ -57291,10 +57795,12 @@
57291
57292 assert( sqlite3_mutex_held(pBt->mutex) );
57293 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
57294 pPage1 = pBt->pPage1;
57295 mxPage = btreePagecount(pBt);
 
 
57296 n = get4byte(&pPage1->aData[36]);
57297 testcase( n==mxPage-1 );
57298 if( n>=mxPage ){
57299 return SQLITE_CORRUPT_BKPT;
57300 }
@@ -57337,12 +57843,18 @@
57337 ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
57338 */
57339 do {
57340 pPrevTrunk = pTrunk;
57341 if( pPrevTrunk ){
 
 
 
57342 iTrunk = get4byte(&pPrevTrunk->aData[0]);
57343 }else{
 
 
 
57344 iTrunk = get4byte(&pPage1->aData[32]);
57345 }
57346 testcase( iTrunk==mxPage );
57347 if( iTrunk>mxPage ){
57348 rc = SQLITE_CORRUPT_BKPT;
@@ -57353,12 +57865,13 @@
57353 pTrunk = 0;
57354 goto end_allocate_page;
57355 }
57356 assert( pTrunk!=0 );
57357 assert( pTrunk->aData!=0 );
57358
57359 k = get4byte(&pTrunk->aData[4]); /* # of leaves on this trunk page */
 
57360 if( k==0 && !searchList ){
57361 /* The trunk has no leaves and the list is not being searched.
57362 ** So extract the trunk page itself and use it as the newly
57363 ** allocated page */
57364 assert( pPrevTrunk==0 );
@@ -57672,10 +58185,15 @@
57672 ** to maintain backwards compatibility with older versions of SQLite,
57673 ** we will continue to restrict the number of entries to usableSize/4 - 8
57674 ** for now. At some point in the future (once everyone has upgraded
57675 ** to 3.6.0 or later) we should consider fixing the conditional above
57676 ** to read "usableSize/4-2" instead of "usableSize/4-8".
 
 
 
 
 
57677 */
57678 rc = sqlite3PagerWrite(pTrunk->pDbPage);
57679 if( rc==SQLITE_OK ){
57680 put4byte(&pTrunk->aData[4], nLeaf+1);
57681 put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
@@ -58023,13 +58541,21 @@
58023 if( rc ){
58024 *pRC = rc;
58025 return;
58026 }
58027 pPage->nCell--;
58028 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
58029 put2byte(&data[hdr+3], pPage->nCell);
58030 pPage->nFree += 2;
 
 
 
 
 
 
 
 
58031 }
58032
58033 /*
58034 ** Insert a new cell on pPage at cell index "i". pCell points to the
58035 ** content of the cell.
@@ -58120,49 +58646,275 @@
58120 #endif
58121 }
58122 }
58123
58124 /*
58125 ** Add a list of cells to a page. The page should be initially empty.
58126 ** The cells are guaranteed to fit on the page.
58127 */
58128 static void assemblePage(
58129 MemPage *pPage, /* The page to be assembled */
58130 int nCell, /* The number of cells to add to this page */
58131 u8 **apCell, /* Pointers to cell bodies */
58132 u16 *aSize /* Sizes of the cells */
58133 ){
58134 int i; /* Loop counter */
58135 u8 *pCellptr; /* Address of next cell pointer */
58136 int cellbody; /* Address of next cell body */
58137 u8 * const data = pPage->aData; /* Pointer to data for pPage */
58138 const int hdr = pPage->hdrOffset; /* Offset of header on pPage */
58139 const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
58140
58141 assert( pPage->nOverflow==0 );
58142 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58143 assert( nCell>=0 && nCell<=(int)MX_CELL(pPage->pBt)
58144 && (int)MX_CELL(pPage->pBt)<=10921);
58145 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
58146
58147 /* Check that the page has just been zeroed by zeroPage() */
58148 assert( pPage->nCell==0 );
58149 assert( get2byteNotZero(&data[hdr+5])==nUsable );
58150
58151 pCellptr = &pPage->aCellIdx[nCell*2];
58152 cellbody = nUsable;
58153 for(i=nCell-1; i>=0; i--){
58154 u16 sz = aSize[i];
58155 pCellptr -= 2;
58156 cellbody -= sz;
58157 put2byte(pCellptr, cellbody);
58158 memcpy(&data[cellbody], apCell[i], sz);
58159 }
58160 put2byte(&data[hdr+3], nCell);
58161 put2byte(&data[hdr+5], cellbody);
58162 pPage->nFree -= (nCell*2 + nUsable - cellbody);
58163 pPage->nCell = (u16)nCell;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58164 }
58165
58166 /*
58167 ** The following parameters determine how many adjacent pages get involved
58168 ** in a balancing operation. NN is the number of neighbors on either side
@@ -58212,11 +58964,11 @@
58212 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58213 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58214 assert( pPage->nOverflow==1 );
58215
58216 /* This error condition is now caught prior to reaching this function */
58217 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT;
58218
58219 /* Allocate a new page. This page will become the right-sibling of
58220 ** pPage. Make the parent page writable, so that the new divider cell
58221 ** may be inserted. If both these operations are successful, proceed.
58222 */
@@ -58230,11 +58982,12 @@
58230 u8 *pStop;
58231
58232 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
58233 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
58234 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58235 assemblePage(pNew, 1, &pCell, &szCell);
 
58236
58237 /* If this is an auto-vacuum database, update the pointer map
58238 ** with entries for the new page, and any pointer from the
58239 ** cell on the page to an overflow page. If either of these
58240 ** operations fails, the return code is set, but the contents
@@ -58449,21 +59202,26 @@
58449 int subtotal; /* Subtotal of bytes in cells on one page */
58450 int iSpace1 = 0; /* First unused byte of aSpace1[] */
58451 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
58452 int szScratch; /* Size of scratch memory requested */
58453 MemPage *apOld[NB]; /* pPage and up to two siblings */
58454 MemPage *apCopy[NB]; /* Private copies of apOld[] pages */
58455 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
58456 u8 *pRight; /* Location in parent of right-sibling pointer */
58457 u8 *apDiv[NB-1]; /* Divider cells in pParent */
58458 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
58459 int szNew[NB+2]; /* Combined size of cells place on i-th page */
 
58460 u8 **apCell = 0; /* All cells begin balanced */
58461 u16 *szCell; /* Local size of all cells in apCell[] */
58462 u8 *aSpace1; /* Space for copies of dividers cells */
58463 Pgno pgno; /* Temp var to store a page number in */
 
 
 
 
58464
 
58465 pBt = pParent->pBt;
58466 assert( sqlite3_mutex_held(pBt->mutex) );
58467 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58468
58469 #if 0
@@ -58568,16 +59326,18 @@
58568 nMaxCells = (nMaxCells + 3)&~3;
58569
58570 /*
58571 ** Allocate space for memory structures
58572 */
58573 k = pBt->pageSize + ROUND8(sizeof(MemPage));
58574 szScratch =
58575 nMaxCells*sizeof(u8*) /* apCell */
58576 + nMaxCells*sizeof(u16) /* szCell */
58577 + pBt->pageSize /* aSpace1 */
58578 + k*nOld; /* Page copies (apCopy) */
 
 
 
58579 apCell = sqlite3ScratchMalloc( szScratch );
58580 if( apCell==0 ){
58581 rc = SQLITE_NOMEM;
58582 goto balance_cleanup;
58583 }
@@ -58586,12 +59346,12 @@
58586 assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
58587
58588 /*
58589 ** Load pointers to all cells on sibling pages and the divider cells
58590 ** into the local apCell[] array. Make copies of the divider cells
58591 ** into space obtained from aSpace1[] and remove the divider cells
58592 ** from pParent.
58593 **
58594 ** If the siblings are on leaf pages, then the child pointers of the
58595 ** divider cells are stripped from the cells before they are copied
58596 ** into aSpace1[]. In this way, all cells in apCell[] are without
58597 ** child pointers. If siblings are not leaves, then all cell in
@@ -58603,19 +59363,11 @@
58603 */
58604 leafCorrection = apOld[0]->leaf*4;
58605 leafData = apOld[0]->intKeyLeaf;
58606 for(i=0; i<nOld; i++){
58607 int limit;
58608
58609 /* Before doing anything else, take a copy of the i'th original sibling
58610 ** The rest of this function will use data from the copies rather
58611 ** that the original pages since the original pages will be in the
58612 ** process of being overwritten. */
58613 MemPage *pOld = apCopy[i] = (MemPage*)&aSpace1[pBt->pageSize + k*i];
58614 memcpy(pOld, apOld[i], sizeof(MemPage));
58615 pOld->aData = (void*)&pOld[1];
58616 memcpy(pOld->aData, apOld[i]->aData, pBt->pageSize);
58617
58618 limit = pOld->nCell+pOld->nOverflow;
58619 if( pOld->nOverflow>0 ){
58620 for(j=0; j<limit; j++){
58621 assert( nCell<nMaxCells );
@@ -58632,10 +59384,11 @@
58632 apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
58633 szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
58634 nCell++;
58635 }
58636 }
 
58637 if( i<nOld-1 && !leafData){
58638 u16 sz = (u16)szNew[i];
58639 u8 *pTemp;
58640 assert( nCell<nMaxCells );
58641 szCell[nCell] = sz;
@@ -58654,11 +59407,15 @@
58654 ** pointer of the divider cell */
58655 memcpy(apCell[nCell], &pOld->aData[8], 4);
58656 }else{
58657 assert( leafCorrection==4 );
58658 if( szCell[nCell]<4 ){
58659 /* Do not allow any cells smaller than 4 bytes. */
 
 
 
 
58660 szCell[nCell] = 4;
58661 }
58662 }
58663 nCell++;
58664 }
@@ -58683,11 +59440,11 @@
58683 usableSpace = pBt->usableSize - 12 + leafCorrection;
58684 for(subtotal=k=i=0; i<nCell; i++){
58685 assert( i<nMaxCells );
58686 subtotal += szCell[i] + 2;
58687 if( subtotal > usableSpace ){
58688 szNew[k] = subtotal - szCell[i];
58689 cntNew[k] = i;
58690 if( leafData ){ i--; }
58691 subtotal = 0;
58692 k++;
58693 if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -58697,13 +59454,14 @@
58697 cntNew[k] = nCell;
58698 k++;
58699
58700 /*
58701 ** The packing computed by the previous block is biased toward the siblings
58702 ** on the left side. The left siblings are always nearly full, while the
58703 ** right-most sibling might be nearly empty. This block of code attempts
58704 ** to adjust the packing of siblings to get a better balance.
 
58705 **
58706 ** This adjustment is more than an optimization. The packing above might
58707 ** be so out of balance as to be illegal. For example, the right-most
58708 ** sibling might be completely empty. This adjustment is not optional.
58709 */
@@ -58728,26 +59486,22 @@
58728 }
58729 szNew[i] = szRight;
58730 szNew[i-1] = szLeft;
58731 }
58732
58733 /* Either we found one or more cells (cntnew[0])>0) or pPage is
58734 ** a virtual root page. A virtual root page is when the real root
58735 ** page is page 1 and we are the only child of that page.
58736 **
58737 ** UPDATE: The assert() below is not necessarily true if the database
58738 ** file is corrupt. The corruption will be detected and reported later
58739 ** in this procedure so there is no need to act upon it now.
58740 */
58741 #if 0
58742 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) );
58743 #endif
58744
58745 TRACE(("BALANCE: old: %d %d %d ",
58746 apOld[0]->pgno,
58747 nOld>=2 ? apOld[1]->pgno : 0,
58748 nOld>=3 ? apOld[2]->pgno : 0
58749 ));
58750
58751 /*
58752 ** Allocate k new pages. Reuse old pages where possible.
58753 */
@@ -58766,12 +59520,14 @@
58766 if( rc ) goto balance_cleanup;
58767 }else{
58768 assert( i>0 );
58769 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
58770 if( rc ) goto balance_cleanup;
 
58771 apNew[i] = pNew;
58772 nNew++;
 
58773
58774 /* Set the pointer-map entry for the new sibling page. */
58775 if( ISAUTOVACUUM ){
58776 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
58777 if( rc!=SQLITE_OK ){
@@ -58779,139 +59535,251 @@
58779 }
58780 }
58781 }
58782 }
58783
58784 /* Free any old pages that were not reused as new pages.
58785 */
58786 while( i<nOld ){
58787 freePage(apOld[i], &rc);
58788 if( rc ) goto balance_cleanup;
58789 releasePage(apOld[i]);
58790 apOld[i] = 0;
58791 i++;
58792 }
58793
58794 /*
58795 ** Put the new pages in ascending order. This helps to
58796 ** keep entries in the disk file in order so that a scan
58797 ** of the table is a linear scan through the file. That
58798 ** in turn helps the operating system to deliver pages
58799 ** from the disk more rapidly.
58800 **
58801 ** An O(n^2) insertion sort algorithm is used, but since
58802 ** n is never more than NB (a small constant), that should
58803 ** not be a problem.
58804 **
58805 ** When NB==3, this one optimization makes the database
58806 ** about 25% faster for large insertions and deletions.
58807 */
58808 for(i=0; i<k-1; i++){
58809 int minV = apNew[i]->pgno;
58810 int minI = i;
58811 for(j=i+1; j<k; j++){
58812 if( apNew[j]->pgno<(unsigned)minV ){
58813 minI = j;
58814 minV = apNew[j]->pgno;
58815 }
58816 }
58817 if( minI>i ){
58818 MemPage *pT;
58819 pT = apNew[i];
58820 apNew[i] = apNew[minI];
58821 apNew[minI] = pT;
58822 }
58823 }
58824 TRACE(("new: %d(%d) %d(%d) %d(%d) %d(%d) %d(%d)\n",
58825 apNew[0]->pgno, szNew[0],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58826 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
 
58827 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
 
58828 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
58829 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0));
 
 
 
58830
58831 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58832 put4byte(pRight, apNew[nNew-1]->pgno);
58833
58834 /*
58835 ** Evenly distribute the data in apCell[] across the new pages.
58836 ** Insert divider cells into pParent as necessary.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58837 */
58838 j = 0;
58839 for(i=0; i<nNew; i++){
58840 /* Assemble the new sibling page. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58841 MemPage *pNew = apNew[i];
58842 assert( j<nMaxCells );
58843 zeroPage(pNew, pageFlags);
58844 assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]);
58845 assert( pNew->nCell>0 || (nNew==1 && cntNew[0]==0) );
58846 assert( pNew->nOverflow==0 );
58847
58848 j = cntNew[i];
58849
58850 /* If the sibling page assembled above was not the right-most sibling,
58851 ** insert a divider cell into the parent page.
58852 */
58853 assert( i<nNew-1 || j==nCell );
58854 if( j<nCell ){
58855 u8 *pCell;
58856 u8 *pTemp;
58857 int sz;
58858
58859 assert( j<nMaxCells );
58860 pCell = apCell[j];
58861 sz = szCell[j] + leafCorrection;
58862 pTemp = &aOvflSpace[iOvflSpace];
58863 if( !pNew->leaf ){
58864 memcpy(&pNew->aData[8], pCell, 4);
58865 }else if( leafData ){
58866 /* If the tree is a leaf-data tree, and the siblings are leaves,
58867 ** then there is no divider cell in apCell[]. Instead, the divider
58868 ** cell consists of the integer key for the right-most cell of
58869 ** the sibling-page assembled above only.
58870 */
58871 CellInfo info;
58872 j--;
58873 btreeParseCellPtr(pNew, apCell[j], &info);
58874 pCell = pTemp;
58875 sz = 4 + putVarint(&pCell[4], info.nKey);
58876 pTemp = 0;
58877 }else{
58878 pCell -= 4;
58879 /* Obscure case for non-leaf-data trees: If the cell at pCell was
58880 ** previously stored on a leaf node, and its reported size was 4
58881 ** bytes, then it may actually be smaller than this
58882 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
58883 ** any cell). But it is important to pass the correct size to
58884 ** insertCell(), so reparse the cell now.
58885 **
58886 ** Note that this can never happen in an SQLite data file, as all
58887 ** cells are at least 4 bytes. It only happens in b-trees used
58888 ** to evaluate "IN (SELECT ...)" and similar clauses.
58889 */
58890 if( szCell[j]==4 ){
58891 assert(leafCorrection==4);
58892 sz = cellSizePtr(pParent, pCell);
58893 }
58894 }
58895 iOvflSpace += sz;
58896 assert( sz<=pBt->maxLocal+23 );
58897 assert( iOvflSpace <= (int)pBt->pageSize );
58898 insertCell(pParent, nxDiv, pCell, sz, pTemp, pNew->pgno, &rc);
58899 if( rc!=SQLITE_OK ) goto balance_cleanup;
58900 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58901
58902 j++;
58903 nxDiv++;
58904 }
58905 }
58906 assert( j==nCell );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58907 assert( nOld>0 );
58908 assert( nNew>0 );
58909 if( (pageFlags & PTF_LEAF)==0 ){
58910 u8 *zChild = &apCopy[nOld-1]->aData[8];
58911 memcpy(&apNew[nNew-1]->aData[8], zChild, 4);
58912 }
58913
58914 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
58915 /* The root page of the b-tree now contains no cells. The only sibling
58916 ** page is the right-child of the parent. Copy the contents of the
58917 ** child page into the parent, decreasing the overall height of the
@@ -58920,130 +59788,54 @@
58920 **
58921 ** If this is an auto-vacuum database, the call to copyNodeContent()
58922 ** sets all pointer-map entries corresponding to database image pages
58923 ** for which the pointer is stored within the content being copied.
58924 **
58925 ** The second assert below verifies that the child page is defragmented
58926 ** (it must be, as it was just reconstructed using assemblePage()). This
58927 ** is important if the parent page happens to be page 1 of the database
58928 ** image. */
 
58929 assert( nNew==1 );
 
 
58930 assert( apNew[0]->nFree ==
58931 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
 
58932 );
58933 copyNodeContent(apNew[0], pParent, &rc);
58934 freePage(apNew[0], &rc);
58935 }else if( ISAUTOVACUUM ){
58936 /* Fix the pointer-map entries for all the cells that were shifted around.
58937 ** There are several different types of pointer-map entries that need to
58938 ** be dealt with by this routine. Some of these have been set already, but
58939 ** many have not. The following is a summary:
58940 **
58941 ** 1) The entries associated with new sibling pages that were not
58942 ** siblings when this function was called. These have already
58943 ** been set. We don't need to worry about old siblings that were
58944 ** moved to the free-list - the freePage() code has taken care
58945 ** of those.
58946 **
58947 ** 2) The pointer-map entries associated with the first overflow
58948 ** page in any overflow chains used by new divider cells. These
58949 ** have also already been taken care of by the insertCell() code.
58950 **
58951 ** 3) If the sibling pages are not leaves, then the child pages of
58952 ** cells stored on the sibling pages may need to be updated.
58953 **
58954 ** 4) If the sibling pages are not internal intkey nodes, then any
58955 ** overflow pages used by these cells may need to be updated
58956 ** (internal intkey nodes never contain pointers to overflow pages).
58957 **
58958 ** 5) If the sibling pages are not leaves, then the pointer-map
58959 ** entries for the right-child pages of each sibling may need
58960 ** to be updated.
58961 **
58962 ** Cases 1 and 2 are dealt with above by other code. The next
58963 ** block deals with cases 3 and 4 and the one after that, case 5. Since
58964 ** setting a pointer map entry is a relatively expensive operation, this
58965 ** code only sets pointer map entries for child or overflow pages that have
58966 ** actually moved between pages. */
58967 MemPage *pNew = apNew[0];
58968 MemPage *pOld = apCopy[0];
58969 int nOverflow = pOld->nOverflow;
58970 int iNextOld = pOld->nCell + nOverflow;
58971 int iOverflow = (nOverflow ? pOld->aiOvfl[0] : -1);
58972 j = 0; /* Current 'old' sibling page */
58973 k = 0; /* Current 'new' sibling page */
58974 for(i=0; i<nCell; i++){
58975 int isDivider = 0;
58976 while( i==iNextOld ){
58977 /* Cell i is the cell immediately following the last cell on old
58978 ** sibling page j. If the siblings are not leaf pages of an
58979 ** intkey b-tree, then cell i was a divider cell. */
58980 assert( j+1 < ArraySize(apCopy) );
58981 assert( j+1 < nOld );
58982 pOld = apCopy[++j];
58983 iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow;
58984 if( pOld->nOverflow ){
58985 nOverflow = pOld->nOverflow;
58986 iOverflow = i + !leafData + pOld->aiOvfl[0];
58987 }
58988 isDivider = !leafData;
58989 }
58990
58991 assert(nOverflow>0 || iOverflow<i );
58992 assert(nOverflow<2 || pOld->aiOvfl[0]==pOld->aiOvfl[1]-1);
58993 assert(nOverflow<3 || pOld->aiOvfl[1]==pOld->aiOvfl[2]-1);
58994 if( i==iOverflow ){
58995 isDivider = 1;
58996 if( (--nOverflow)>0 ){
58997 iOverflow++;
58998 }
58999 }
59000
59001 if( i==cntNew[k] ){
59002 /* Cell i is the cell immediately following the last cell on new
59003 ** sibling page k. If the siblings are not leaf pages of an
59004 ** intkey b-tree, then cell i is a divider cell. */
59005 pNew = apNew[++k];
59006 if( !leafData ) continue;
59007 }
59008 assert( j<nOld );
59009 assert( k<nNew );
59010
59011 /* If the cell was originally divider cell (and is not now) or
59012 ** an overflow cell, or if the cell was located on a different sibling
59013 ** page before the balancing, then the pointer map entries associated
59014 ** with any child or overflow pages need to be updated. */
59015 if( isDivider || pOld->pgno!=pNew->pgno ){
59016 if( !leafCorrection ){
59017 ptrmapPut(pBt, get4byte(apCell[i]), PTRMAP_BTREE, pNew->pgno, &rc);
59018 }
59019 if( szCell[i]>pNew->minLocal ){
59020 ptrmapPutOvflPtr(pNew, apCell[i], &rc);
59021 }
59022 }
59023 }
59024
59025 if( !leafCorrection ){
59026 for(i=0; i<nNew; i++){
59027 u32 key = get4byte(&apNew[i]->aData[8]);
59028 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59029 }
59030 }
59031
59032 #if 0
 
59033 /* The ptrmapCheckPages() contains assert() statements that verify that
59034 ** all pointer map pages are set correctly. This is helpful while
59035 ** debugging. This is usually disabled because a corrupt database may
59036 ** cause an assert() statement to fail. */
59037 ptrmapCheckPages(apNew, nNew);
59038 ptrmapCheckPages(&pParent, 1);
 
59039 #endif
59040 }
59041
59042 assert( pParent->isInit );
59043 TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59044 nOld, nNew, nCell));
59045
59046 /*
59047 ** Cleanup before returning.
59048 */
59049 balance_cleanup:
@@ -60424,12 +61216,18 @@
60424 }else{
60425 int contentOffset = get2byteNotZero(&data[hdr+5]);
60426 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
60427 memset(hit+contentOffset, 0, usableSize-contentOffset);
60428 memset(hit, 1, contentOffset);
 
 
60429 nCell = get2byte(&data[hdr+3]);
 
 
60430 cellStart = hdr + 12 - 4*pPage->leaf;
 
 
60431 for(i=0; i<nCell; i++){
60432 int pc = get2byte(&data[cellStart+i*2]);
60433 u32 size = 65536;
60434 int j;
60435 if( pc<=usableSize-4 ){
@@ -60441,18 +61239,27 @@
60441 "Corruption detected in cell %d on page %d",i,iPage);
60442 }else{
60443 for(j=pc+size-1; j>=pc; j--) hit[j]++;
60444 }
60445 }
 
 
 
60446 i = get2byte(&data[hdr+1]);
60447 while( i>0 ){
60448 int size, j;
60449 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
60450 size = get2byte(&data[i+2]);
60451 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
60452 for(j=i+size-1; j>=i; j--) hit[j]++;
 
 
 
 
60453 j = get2byte(&data[i]);
 
 
60454 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
60455 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
60456 i = j;
60457 }
60458 for(i=cnt=0; i<usableSize; i++){
@@ -60462,10 +61269,15 @@
60462 checkAppendMsg(pCheck,
60463 "Multiple uses for byte %d of page %d", i, iPage);
60464 break;
60465 }
60466 }
 
 
 
 
 
60467 if( cnt!=data[hdr+7] ){
60468 checkAppendMsg(pCheck,
60469 "Fragmentation of %d bytes reported as %d on page %d",
60470 cnt, data[hdr+7], iPage);
60471 }
@@ -60865,10 +61677,15 @@
60865 */
60866 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
60867 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
60868 }
60869
 
 
 
 
 
60870 /************** End of btree.c ***********************************************/
60871 /************** Begin file backup.c ******************************************/
60872 /*
60873 ** 2009 January 28
60874 **
@@ -60988,10 +61805,24 @@
60988 static int setDestPgsz(sqlite3_backup *p){
60989 int rc;
60990 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
60991 return rc;
60992 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60993
60994 /*
60995 ** Create an sqlite3_backup process to copy the contents of zSrcDb from
60996 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
60997 ** a pointer to the new sqlite3_backup object.
@@ -61004,10 +61835,17 @@
61004 const char *zDestDb, /* Name of database within pDestDb */
61005 sqlite3* pSrcDb, /* Database connection to read from */
61006 const char *zSrcDb /* Name of database within pSrcDb */
61007 ){
61008 sqlite3_backup *p; /* Value to return */
 
 
 
 
 
 
 
61009
61010 /* Lock the source database handle. The destination database
61011 ** handle is not locked in this routine, but it is locked in
61012 ** sqlite3_backup_step(). The user is required to ensure that no
61013 ** other thread accesses the destination handle for the duration
@@ -61041,16 +61879,19 @@
61041 p->pDestDb = pDestDb;
61042 p->pSrcDb = pSrcDb;
61043 p->iNext = 1;
61044 p->isAttached = 0;
61045
61046 if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){
 
 
 
61047 /* One (or both) of the named databases did not exist or an OOM
61048 ** error was hit. The error has already been written into the
61049 ** pDestDb handle. All that is left to do here is free the
61050 ** sqlite3_backup structure.
61051 */
61052 sqlite3_free(p);
61053 p = 0;
61054 }
61055 }
61056 if( p ){
@@ -61201,10 +62042,13 @@
61201 int rc;
61202 int destMode; /* Destination journal mode */
61203 int pgszSrc = 0; /* Source page size */
61204 int pgszDest = 0; /* Destination page size */
61205
 
 
 
61206 sqlite3_mutex_enter(p->pSrcDb->mutex);
61207 sqlite3BtreeEnter(p->pSrc);
61208 if( p->pDestDb ){
61209 sqlite3_mutex_enter(p->pDestDb->mutex);
61210 }
@@ -61464,11 +62308,11 @@
61464 }
61465 *pp = p->pNext;
61466 }
61467
61468 /* If a transaction is still open on the Btree, roll it back. */
61469 sqlite3BtreeRollback(p->pDest, SQLITE_OK);
61470
61471 /* Set the error code of the destination database handle. */
61472 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
61473 if( p->pDestDb ){
61474 sqlite3Error(p->pDestDb, rc);
@@ -61490,18 +62334,30 @@
61490 /*
61491 ** Return the number of pages still to be backed up as of the most recent
61492 ** call to sqlite3_backup_step().
61493 */
61494 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
 
 
 
 
 
 
61495 return p->nRemaining;
61496 }
61497
61498 /*
61499 ** Return the total number of pages in the source database as of the most
61500 ** recent call to sqlite3_backup_step().
61501 */
61502 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
 
 
 
 
 
 
61503 return p->nPagecount;
61504 }
61505
61506 /*
61507 ** This function is called after the contents of page iPage of the
@@ -63788,10 +64644,38 @@
63788 }
63789 p->nOp += nOp;
63790 }
63791 return addr;
63792 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63793
63794 /*
63795 ** Change the value of the P1 operand for a specific instruction.
63796 ** This routine is useful when a large program is loaded from a
63797 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -64887,10 +65771,13 @@
64887 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
64888 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
64889 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
64890 &zCsr, zEnd, &nByte);
64891 p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
 
 
 
64892 if( nByte ){
64893 p->pFree = sqlite3DbMallocZero(db, nByte);
64894 }
64895 zCsr = p->pFree;
64896 zEnd = &zCsr[nByte];
@@ -64903,11 +65790,11 @@
64903 for(n=0; n<nVar; n++){
64904 p->aVar[n].flags = MEM_Null;
64905 p->aVar[n].db = db;
64906 }
64907 }
64908 if( p->azVar ){
64909 p->nzVar = pParse->nzVar;
64910 memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
64911 memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
64912 }
64913 if( p->aMem ){
@@ -64954,10 +65841,13 @@
64954 ** is used, for example, when a trigger sub-program is halted to restore
64955 ** control to the main program.
64956 */
64957 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
64958 Vdbe *v = pFrame->v;
 
 
 
64959 v->aOnceFlag = pFrame->aOnceFlag;
64960 v->nOnceFlag = pFrame->nOnceFlag;
64961 v->aOp = pFrame->aOp;
64962 v->nOp = pFrame->nOp;
64963 v->aMem = pFrame->aMem;
@@ -64964,10 +65854,11 @@
64964 v->nMem = pFrame->nMem;
64965 v->apCsr = pFrame->apCsr;
64966 v->nCursor = pFrame->nCursor;
64967 v->db->lastRowid = pFrame->lastRowid;
64968 v->nChange = pFrame->nChange;
 
64969 return pFrame->pc;
64970 }
64971
64972 /*
64973 ** Close all cursors.
@@ -65531,10 +66422,11 @@
65531 ** so, abort any other statements this handle currently has active.
65532 */
65533 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65534 sqlite3CloseSavepoints(db);
65535 db->autoCommit = 1;
 
65536 }
65537 }
65538 }
65539
65540 /* Check for immediate foreign key violations. */
@@ -65571,18 +66463,20 @@
65571 sqlite3VdbeLeave(p);
65572 return SQLITE_BUSY;
65573 }else if( rc!=SQLITE_OK ){
65574 p->rc = rc;
65575 sqlite3RollbackAll(db, SQLITE_OK);
 
65576 }else{
65577 db->nDeferredCons = 0;
65578 db->nDeferredImmCons = 0;
65579 db->flags &= ~SQLITE_DeferFKs;
65580 sqlite3CommitInternalChanges(db);
65581 }
65582 }else{
65583 sqlite3RollbackAll(db, SQLITE_OK);
 
65584 }
65585 db->nStatement = 0;
65586 }else if( eStatementOp==0 ){
65587 if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
65588 eStatementOp = SAVEPOINT_RELEASE;
@@ -65590,10 +66484,11 @@
65590 eStatementOp = SAVEPOINT_ROLLBACK;
65591 }else{
65592 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65593 sqlite3CloseSavepoints(db);
65594 db->autoCommit = 1;
 
65595 }
65596 }
65597
65598 /* If eStatementOp is non-zero, then a statement transaction needs to
65599 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -65610,10 +66505,11 @@
65610 p->zErrMsg = 0;
65611 }
65612 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
65613 sqlite3CloseSavepoints(db);
65614 db->autoCommit = 1;
 
65615 }
65616 }
65617
65618 /* If this was an INSERT, UPDATE or DELETE and no statement transaction
65619 ** has been rolled back, update the database connection change-counter.
@@ -65871,10 +66767,16 @@
65871 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
65872 vdbeFreeOpArray(db, p->aOp, p->nOp);
65873 sqlite3DbFree(db, p->aColName);
65874 sqlite3DbFree(db, p->zSql);
65875 sqlite3DbFree(db, p->pFree);
 
 
 
 
 
 
65876 }
65877
65878 /*
65879 ** Delete an entire VDBE.
65880 */
@@ -66029,13 +66931,11 @@
66029 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
66030 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
66031 i64 i = pMem->u.i;
66032 u64 u;
66033 if( i<0 ){
66034 if( i<(-MAX_6BYTE) ) return 6;
66035 /* Previous test prevents: u = -(-9223372036854775808) */
66036 u = -i;
66037 }else{
66038 u = i;
66039 }
66040 if( u<=127 ){
66041 return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
@@ -66197,14 +67097,18 @@
66197 ){
66198 u64 x = FOUR_BYTE_UINT(buf);
66199 u32 y = FOUR_BYTE_UINT(buf+4);
66200 x = (x<<32) + y;
66201 if( serial_type==6 ){
 
 
66202 pMem->u.i = *(i64*)&x;
66203 pMem->flags = MEM_Int;
66204 testcase( pMem->u.i<0 );
66205 }else{
 
 
66206 #if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
66207 /* Verify that integers and floating point values use the same
66208 ** byte order. Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
66209 ** defined that 64-bit floating point values really are mixed
66210 ** endian.
@@ -66228,39 +67132,50 @@
66228 Mem *pMem /* Memory cell to write value into */
66229 ){
66230 switch( serial_type ){
66231 case 10: /* Reserved for future use */
66232 case 11: /* Reserved for future use */
66233 case 0: { /* NULL */
 
66234 pMem->flags = MEM_Null;
66235 break;
66236 }
66237 case 1: { /* 1-byte signed integer */
 
 
66238 pMem->u.i = ONE_BYTE_INT(buf);
66239 pMem->flags = MEM_Int;
66240 testcase( pMem->u.i<0 );
66241 return 1;
66242 }
66243 case 2: { /* 2-byte signed integer */
 
 
66244 pMem->u.i = TWO_BYTE_INT(buf);
66245 pMem->flags = MEM_Int;
66246 testcase( pMem->u.i<0 );
66247 return 2;
66248 }
66249 case 3: { /* 3-byte signed integer */
 
 
66250 pMem->u.i = THREE_BYTE_INT(buf);
66251 pMem->flags = MEM_Int;
66252 testcase( pMem->u.i<0 );
66253 return 3;
66254 }
66255 case 4: { /* 4-byte signed integer */
 
 
66256 pMem->u.i = FOUR_BYTE_INT(buf);
66257 pMem->flags = MEM_Int;
66258 testcase( pMem->u.i<0 );
66259 return 4;
66260 }
66261 case 5: { /* 6-byte signed integer */
 
 
66262 pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
66263 pMem->flags = MEM_Int;
66264 testcase( pMem->u.i<0 );
66265 return 6;
66266 }
@@ -66270,15 +67185,21 @@
66270 ** to avoid having to move the frame pointer in the common case */
66271 return serialGet(buf,serial_type,pMem);
66272 }
66273 case 8: /* Integer 0 */
66274 case 9: { /* Integer 1 */
 
 
66275 pMem->u.i = serial_type-8;
66276 pMem->flags = MEM_Int;
66277 return 0;
66278 }
66279 default: {
 
 
 
 
66280 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
66281 pMem->z = (char *)buf;
66282 pMem->n = (serial_type-12)/2;
66283 pMem->flags = aFlag[serial_type&1];
66284 return pMem->n;
@@ -68238,15 +69159,23 @@
68238 sqlite3_stmt *pStmt,
68239 int N,
68240 const void *(*xFunc)(Mem*),
68241 int useType
68242 ){
68243 const void *ret = 0;
68244 Vdbe *p = (Vdbe *)pStmt;
68245 int n;
68246 sqlite3 *db = p->db;
68247
 
 
 
 
 
 
 
 
68248 assert( db!=0 );
68249 n = sqlite3_column_count(pStmt);
68250 if( N<n && N>=0 ){
68251 N += useType*n;
68252 sqlite3_mutex_enter(db->mutex);
@@ -68707,10 +69636,16 @@
68707 ** prepared statement for the database connection. Return NULL if there
68708 ** are no more.
68709 */
68710 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
68711 sqlite3_stmt *pNext;
 
 
 
 
 
 
68712 sqlite3_mutex_enter(pDb->mutex);
68713 if( pStmt==0 ){
68714 pNext = (sqlite3_stmt*)pDb->pVdbe;
68715 }else{
68716 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -68722,15 +69657,91 @@
68722 /*
68723 ** Return the value of a status counter for a prepared statement
68724 */
68725 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
68726 Vdbe *pVdbe = (Vdbe*)pStmt;
68727 u32 v = pVdbe->aCounter[op];
 
 
 
 
 
 
 
68728 if( resetFlag ) pVdbe->aCounter[op] = 0;
68729 return (int)v;
68730 }
68731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68732 /************** End of vdbeapi.c *********************************************/
68733 /************** Begin file vdbetrace.c ***************************************/
68734 /*
68735 ** 2009 November 25
68736 **
@@ -69612,10 +70623,13 @@
69612 #ifdef VDBE_PROFILE
69613 start = sqlite3Hwtime();
69614 #endif
69615 nVmStep++;
69616 pOp = &aOp[pc];
 
 
 
69617
69618 /* Only allow tracing if SQLITE_DEBUG is defined.
69619 */
69620 #ifdef SQLITE_DEBUG
69621 if( db->flags & SQLITE_VdbeTrace ){
@@ -71302,11 +72316,11 @@
71302 assert( pReg->flags & MEM_Blob );
71303 assert( memIsValid(pReg) );
71304 pC->payloadSize = pC->szRow = avail = pReg->n;
71305 pC->aRow = (u8*)pReg->z;
71306 }else{
71307 MemSetTypeFlag(pDest, MEM_Null);
71308 goto op_column_out;
71309 }
71310 }else{
71311 assert( pCrsr );
71312 if( pC->isTable==0 ){
@@ -71637,11 +72651,14 @@
71637 testcase( serial_type==127 );
71638 testcase( serial_type==128 );
71639 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
71640 }while( (--pRec)>=pData0 );
71641
71642 /* Add the initial header varint and total the size */
 
 
 
71643 testcase( nHdr==126 );
71644 testcase( nHdr==127 );
71645 if( nHdr<=126 ){
71646 /* The common case */
71647 nHdr += 1;
@@ -71671,11 +72688,15 @@
71671 j = nHdr;
71672 assert( pData0<=pLast );
71673 pRec = pData0;
71674 do{
71675 serial_type = pRec->uTemp;
 
 
71676 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
 
 
71677 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
71678 }while( (++pRec)<=pLast );
71679 assert( i==nHdr );
71680 assert( j==nByte );
71681
@@ -71826,23 +72847,30 @@
71826 goto vdbe_return;
71827 }
71828 db->isTransactionSavepoint = 0;
71829 rc = p->rc;
71830 }else{
 
71831 iSavepoint = db->nSavepoint - iSavepoint - 1;
71832 if( p1==SAVEPOINT_ROLLBACK ){
 
71833 for(ii=0; ii<db->nDb; ii++){
71834 sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT);
 
 
 
71835 }
 
 
71836 }
71837 for(ii=0; ii<db->nDb; ii++){
71838 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
71839 if( rc!=SQLITE_OK ){
71840 goto abort_due_to_error;
71841 }
71842 }
71843 if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
71844 sqlite3ExpirePreparedStatements(db);
71845 sqlite3ResetAllSchemasOfConnection(db);
71846 db->flags = (db->flags | SQLITE_InternChanges);
71847 }
71848 }
@@ -72235,11 +73263,11 @@
72235 assert( p->bIsReader );
72236 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
72237 || p->readOnly==0 );
72238
72239 if( p->expired ){
72240 rc = SQLITE_ABORT;
72241 break;
72242 }
72243
72244 nField = 0;
72245 pKeyInfo = 0;
@@ -72799,14 +73827,14 @@
72799 }
72800 pIdxKey = &r;
72801 }else{
72802 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
72803 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
72804 );
72805 if( pIdxKey==0 ) goto no_mem;
72806 assert( pIn3->flags & MEM_Blob );
72807 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */
72808 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
72809 }
72810 pIdxKey->default_rc = 0;
72811 if( pOp->opcode==OP_NoConflict ){
72812 /* For the OP_NoConflict opcode, take the jump if any of the
@@ -73402,10 +74430,14 @@
73402 #endif /* SQLITE_OMIT_VIRTUALTABLE */
73403 }else{
73404 assert( pC->pCursor!=0 );
73405 rc = sqlite3VdbeCursorRestore(pC);
73406 if( rc ) goto abort_due_to_error;
 
 
 
 
73407 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
73408 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
73409 }
73410 pOut->u.i = v;
73411 break;
@@ -73492,13 +74524,13 @@
73492 }
73493 /* Opcode: Rewind P1 P2 * * *
73494 **
73495 ** The next use of the Rowid or Column or Next instruction for P1
73496 ** will refer to the first entry in the database table or index.
73497 ** If the table or index is empty and P2>0, then jump immediately to P2.
73498 ** If P2 is 0 or if the table or index is not empty, fall through
73499 ** to the following instruction.
73500 **
73501 ** This opcode leaves the cursor configured to move in forward order,
73502 ** from the beginning toward the end. In other words, the cursor is
73503 ** configured to use Next, not Prev.
73504 */
@@ -74410,10 +75442,13 @@
74410 pFrame->aOp = p->aOp;
74411 pFrame->nOp = p->nOp;
74412 pFrame->token = pProgram->token;
74413 pFrame->aOnceFlag = p->aOnceFlag;
74414 pFrame->nOnceFlag = p->nOnceFlag;
 
 
 
74415
74416 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
74417 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
74418 pMem->flags = MEM_Undefined;
74419 pMem->db = db;
@@ -74427,10 +75462,11 @@
74427
74428 p->nFrame++;
74429 pFrame->pParent = p->pFrame;
74430 pFrame->lastRowid = lastRowid;
74431 pFrame->nChange = p->nChange;
 
74432 p->nChange = 0;
74433 p->pFrame = pFrame;
74434 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
74435 p->nMem = pFrame->nChildMem;
74436 p->nCursor = (u16)pFrame->nChildCsr;
@@ -74437,10 +75473,13 @@
74437 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
74438 p->aOp = aOp = pProgram->aOp;
74439 p->nOp = pProgram->nOp;
74440 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
74441 p->nOnceFlag = pProgram->nOnce;
 
 
 
74442 pc = -1;
74443 memset(p->aOnceFlag, 0, p->nOnceFlag);
74444
74445 break;
74446 }
@@ -74681,12 +75720,12 @@
74681
74682 #ifndef SQLITE_OMIT_WAL
74683 /* Opcode: Checkpoint P1 P2 P3 * *
74684 **
74685 ** Checkpoint database P1. This is a no-op if P1 is not currently in
74686 ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL
74687 ** or RESTART. Write 1 or 0 into mem[P3] if the checkpoint returns
74688 ** SQLITE_BUSY or not, respectively. Write the number of pages in the
74689 ** WAL after the checkpoint into mem[P3+1] and the number of pages
74690 ** in the WAL that have been checkpointed after the checkpoint
74691 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
74692 ** mem[P3+2] are initialized to -1.
@@ -74700,10 +75739,11 @@
74700 aRes[0] = 0;
74701 aRes[1] = aRes[2] = -1;
74702 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
74703 || pOp->p2==SQLITE_CHECKPOINT_FULL
74704 || pOp->p2==SQLITE_CHECKPOINT_RESTART
 
74705 );
74706 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
74707 if( rc==SQLITE_BUSY ){
74708 rc = SQLITE_OK;
74709 aRes[0] = 1;
@@ -75625,10 +76665,15 @@
75625 char *zErr = 0;
75626 Table *pTab;
75627 Parse *pParse = 0;
75628 Incrblob *pBlob = 0;
75629
 
 
 
 
 
75630 flags = !!flags; /* flags = (flags ? 1 : 0); */
75631 *ppBlob = 0;
75632
75633 sqlite3_mutex_enter(db->mutex);
75634
@@ -75843,11 +76888,10 @@
75843 v = (Vdbe*)p->pStmt;
75844
75845 if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
75846 /* Request is out of range. Return a transient error. */
75847 rc = SQLITE_ERROR;
75848 sqlite3Error(db, SQLITE_ERROR);
75849 }else if( v==0 ){
75850 /* If there is no statement handle, then the blob-handle has
75851 ** already been invalidated. Return SQLITE_ABORT in this case.
75852 */
75853 rc = SQLITE_ABORT;
@@ -75861,14 +76905,14 @@
75861 sqlite3BtreeLeaveCursor(p->pCsr);
75862 if( rc==SQLITE_ABORT ){
75863 sqlite3VdbeFinalize(v);
75864 p->pStmt = 0;
75865 }else{
75866 db->errCode = rc;
75867 v->rc = rc;
75868 }
75869 }
 
75870 rc = sqlite3ApiExit(db, rc);
75871 sqlite3_mutex_leave(db->mutex);
75872 return rc;
75873 }
75874
@@ -76041,11 +77085,11 @@
76041 ** itself.
76042 **
76043 ** The sorter is running in multi-threaded mode if (a) the library was built
76044 ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
76045 ** than zero, and (b) worker threads have been enabled at runtime by calling
76046 ** sqlite3_config(SQLITE_CONFIG_WORKER_THREADS, ...).
76047 **
76048 ** When Rewind() is called, any data remaining in memory is flushed to a
76049 ** final PMA. So at this point the data is stored in some number of sorted
76050 ** PMAs within temporary files on disk.
76051 **
@@ -76086,10 +77130,17 @@
76086 */
76087 #if 0
76088 # define SQLITE_DEBUG_SORTER_THREADS 1
76089 #endif
76090
 
 
 
 
 
 
 
76091 /*
76092 ** Private objects used by the sorter
76093 */
76094 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
76095 typedef struct PmaReader PmaReader; /* Incrementally read one PMA */
@@ -76382,11 +77433,13 @@
76382 */
76383 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
76384
76385 /* The minimum PMA size is set to this value multiplied by the database
76386 ** page size in bytes. */
76387 #define SORTER_MIN_WORKING 10
 
 
76388
76389 /* Maximum number of PMAs that a single MergeEngine can merge */
76390 #define SORTER_MAX_MERGE_COUNT 16
76391
76392 static int vdbeIncrSwap(IncrMerger*);
@@ -76781,20 +77834,18 @@
76781 SortSubtask *pTask = &pSorter->aTask[i];
76782 pTask->pSorter = pSorter;
76783 }
76784
76785 if( !sqlite3TempInMemory(db) ){
76786 pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
76787 mxCache = db->aDb[0].pSchema->cache_size;
76788 if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
76789 pSorter->mxPmaSize = mxCache * pgsz;
76790
76791 /* If the application has not configure scratch memory using
76792 ** SQLITE_CONFIG_SCRATCH then we assume it is OK to do large memory
76793 ** allocations. If scratch memory has been configured, then assume
76794 ** large memory allocations should be avoided to prevent heap
76795 ** fragmentation.
76796 */
76797 if( sqlite3GlobalConfig.pScratch==0 ){
76798 assert( pSorter->iMemory==0 );
76799 pSorter->nMemory = pgsz;
76800 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79162,19 +80213,19 @@
79162 **
79163 ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
79164 ** is a helper function - a callback for the tree walker.
79165 */
79166 static int incrAggDepth(Walker *pWalker, Expr *pExpr){
79167 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i;
79168 return WRC_Continue;
79169 }
79170 static void incrAggFunctionDepth(Expr *pExpr, int N){
79171 if( N>0 ){
79172 Walker w;
79173 memset(&w, 0, sizeof(w));
79174 w.xExprCallback = incrAggDepth;
79175 w.u.i = N;
79176 sqlite3WalkExpr(&w, pExpr);
79177 }
79178 }
79179
79180 /*
@@ -79454,10 +80505,14 @@
79454 }
79455 }
79456 if( pMatch ){
79457 pExpr->iTable = pMatch->iCursor;
79458 pExpr->pTab = pMatch->pTab;
 
 
 
 
79459 pSchema = pExpr->pTab->pSchema;
79460 }
79461 } /* if( pSrcList ) */
79462
79463 #ifndef SQLITE_OMIT_TRIGGER
@@ -79718,11 +80773,11 @@
79718 double r = -1.0;
79719 if( p->op!=TK_FLOAT ) return -1;
79720 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
79721 assert( r>=0.0 );
79722 if( r>1.0 ) return -1;
79723 return (int)(r*1000.0);
79724 }
79725
79726 /*
79727 ** This routine is callback for sqlite3WalkExpr().
79728 **
@@ -79850,11 +80905,11 @@
79850 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
79851 ** likelihood(X,0.9375).
79852 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
79853 ** likelihood(X,0.9375). */
79854 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
79855 pExpr->iTable = pDef->zName[0]=='u' ? 62 : 938;
79856 }
79857 }
79858 #ifndef SQLITE_OMIT_AUTHORIZATION
79859 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
79860 if( auth!=SQLITE_OK ){
@@ -81807,69 +82862,79 @@
81807 sqlite3DbFree(db, pList->a);
81808 sqlite3DbFree(db, pList);
81809 }
81810
81811 /*
81812 ** These routines are Walker callbacks. Walker.u.pi is a pointer
81813 ** to an integer. These routines are checking an expression to see
81814 ** if it is a constant. Set *Walker.u.i to 0 if the expression is
81815 ** not constant.
81816 **
81817 ** These callback routines are used to implement the following:
81818 **
81819 ** sqlite3ExprIsConstant() pWalker->u.i==1
81820 ** sqlite3ExprIsConstantNotJoin() pWalker->u.i==2
81821 ** sqlite3ExprIsConstantOrFunction() pWalker->u.i==3 or 4
 
 
 
 
81822 **
81823 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
81824 ** in a CREATE TABLE statement. The Walker.u.i value is 4 when parsing
81825 ** an existing schema and 3 when processing a new statement. A bound
81826 ** parameter raises an error for new statements, but is silently converted
81827 ** to NULL for existing schemas. This allows sqlite_master tables that
81828 ** contain a bound parameter because they were generated by older versions
81829 ** of SQLite to be parsed by newer versions of SQLite without raising a
81830 ** malformed schema error.
81831 */
81832 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
81833
81834 /* If pWalker->u.i is 2 then any term of the expression that comes from
81835 ** the ON or USING clauses of a join disqualifies the expression
81836 ** from being considered constant. */
81837 if( pWalker->u.i==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
81838 pWalker->u.i = 0;
81839 return WRC_Abort;
81840 }
81841
81842 switch( pExpr->op ){
81843 /* Consider functions to be constant if all their arguments are constant
81844 ** and either pWalker->u.i==3 or 4 or the function as the SQLITE_FUNC_CONST
81845 ** flag. */
81846 case TK_FUNCTION:
81847 if( pWalker->u.i>=3 || ExprHasProperty(pExpr,EP_Constant) ){
81848 return WRC_Continue;
 
 
 
81849 }
81850 /* Fall through */
81851 case TK_ID:
81852 case TK_COLUMN:
81853 case TK_AGG_FUNCTION:
81854 case TK_AGG_COLUMN:
81855 testcase( pExpr->op==TK_ID );
81856 testcase( pExpr->op==TK_COLUMN );
81857 testcase( pExpr->op==TK_AGG_FUNCTION );
81858 testcase( pExpr->op==TK_AGG_COLUMN );
81859 pWalker->u.i = 0;
81860 return WRC_Abort;
 
 
 
 
81861 case TK_VARIABLE:
81862 if( pWalker->u.i==4 ){
81863 /* Silently convert bound parameters that appear inside of CREATE
81864 ** statements into a NULL when parsing the CREATE statement text out
81865 ** of the sqlite_master table */
81866 pExpr->op = TK_NULL;
81867 }else if( pWalker->u.i==3 ){
81868 /* A bound parameter in a CREATE statement that originates from
81869 ** sqlite3_prepare() causes an error */
81870 pWalker->u.i = 0;
81871 return WRC_Abort;
81872 }
81873 /* Fall through */
81874 default:
81875 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -81877,57 +82942,68 @@
81877 return WRC_Continue;
81878 }
81879 }
81880 static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
81881 UNUSED_PARAMETER(NotUsed);
81882 pWalker->u.i = 0;
81883 return WRC_Abort;
81884 }
81885 static int exprIsConst(Expr *p, int initFlag){
81886 Walker w;
81887 memset(&w, 0, sizeof(w));
81888 w.u.i = initFlag;
81889 w.xExprCallback = exprNodeIsConstant;
81890 w.xSelectCallback = selectNodeIsConstant;
 
81891 sqlite3WalkExpr(&w, p);
81892 return w.u.i;
81893 }
81894
81895 /*
81896 ** Walk an expression tree. Return 1 if the expression is constant
81897 ** and 0 if it involves variables or function calls.
81898 **
81899 ** For the purposes of this function, a double-quoted string (ex: "abc")
81900 ** is considered a variable but a single-quoted string (ex: 'abc') is
81901 ** a constant.
81902 */
81903 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
81904 return exprIsConst(p, 1);
81905 }
81906
81907 /*
81908 ** Walk an expression tree. Return 1 if the expression is constant
81909 ** that does no originate from the ON or USING clauses of a join.
81910 ** Return 0 if it involves variables or function calls or terms from
81911 ** an ON or USING clause.
81912 */
81913 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
81914 return exprIsConst(p, 2);
81915 }
81916
81917 /*
81918 ** Walk an expression tree. Return 1 if the expression is constant
 
 
 
 
 
 
 
 
 
 
81919 ** or a function call with constant arguments. Return and 0 if there
81920 ** are any variables.
81921 **
81922 ** For the purposes of this function, a double-quoted string (ex: "abc")
81923 ** is considered a variable but a single-quoted string (ex: 'abc') is
81924 ** a constant.
81925 */
81926 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
81927 assert( isInit==0 || isInit==1 );
81928 return exprIsConst(p, 3+isInit);
81929 }
81930
81931 /*
81932 ** If the expression p codes a constant integer that is small enough
81933 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -81990,11 +83066,12 @@
81990 case TK_FLOAT:
81991 case TK_BLOB:
81992 return 0;
81993 case TK_COLUMN:
81994 assert( p->pTab!=0 );
81995 return p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0;
 
81996 default:
81997 return 1;
81998 }
81999 }
82000
@@ -82433,11 +83510,10 @@
82433 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
82434 dest.affSdst = (u8)affinity;
82435 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
82436 pSelect->iLimit = 0;
82437 testcase( pSelect->selFlags & SF_Distinct );
82438 pSelect->selFlags &= ~SF_Distinct;
82439 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
82440 if( sqlite3Select(pParse, pSelect, &dest) ){
82441 sqlite3KeyInfoUnref(pKeyInfo);
82442 return 0;
82443 }
@@ -83580,11 +84656,14 @@
83580 target
83581 ));
83582
83583 #ifndef SQLITE_OMIT_FLOATING_POINT
83584 /* If the column has REAL affinity, it may currently be stored as an
83585 ** integer. Use OP_RealAffinity to make sure it is really real. */
 
 
 
83586 if( pExpr->iColumn>=0
83587 && pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
83588 ){
83589 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
83590 }
@@ -87232,27 +88311,32 @@
87232 aLog[i] = sqlite3LogEst(v);
87233 #endif
87234 if( *z==' ' ) z++;
87235 }
87236 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
87237 assert( pIndex!=0 );
87238 #else
87239 if( pIndex )
87240 #endif
87241 while( z[0] ){
87242 if( sqlite3_strglob("unordered*", z)==0 ){
87243 pIndex->bUnordered = 1;
87244 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
87245 pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
87246 }
 
 
 
 
87247 #ifdef SQLITE_ENABLE_COSTMULT
87248 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
87249 pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
 
 
 
 
87250 }
87251 #endif
87252 while( z[0]!=0 && z[0]!=' ' ) z++;
87253 while( z[0]==' ' ) z++;
87254 }
87255 }
87256
87257 /*
87258 ** This callback is invoked once for each index when reading the
@@ -87366,18 +88450,19 @@
87366 tRowcnt avgEq = 0;
87367 tRowcnt nRow; /* Number of rows in index */
87368 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
87369 i64 nDist100; /* Number of distinct values in index */
87370
87371 if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
87372 nRow = pFinal->anLt[iCol];
87373 nDist100 = (i64)100 * pFinal->anDLt[iCol];
87374 nSample--;
87375 }else{
87376 nRow = pIdx->aiRowEst[0];
87377 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
87378 }
 
87379
87380 /* Set nSum to the number of distinct (iCol+1) field prefixes that
87381 ** occur in the stat4 table for this index. Set sumEq to the sum of
87382 ** the nEq values for column iCol for the same set (adding the value
87383 ** only once where there exist duplicate prefixes). */
@@ -87635,11 +88720,11 @@
87635 }
87636
87637
87638 /* Load the statistics from the sqlite_stat4 table. */
87639 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
87640 if( rc==SQLITE_OK ){
87641 int lookasideEnabled = db->lookaside.bEnabled;
87642 db->lookaside.bEnabled = 0;
87643 rc = loadStat4(db, sInfo.zDatabase);
87644 db->lookaside.bEnabled = lookasideEnabled;
87645 }
@@ -88317,10 +89402,13 @@
88317 SQLITE_API int sqlite3_set_authorizer(
88318 sqlite3 *db,
88319 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
88320 void *pArg
88321 ){
 
 
 
88322 sqlite3_mutex_enter(db->mutex);
88323 db->xAuth = (sqlite3_xauth)xAuth;
88324 db->pAuthArg = pArg;
88325 sqlite3ExpirePreparedStatements(db);
88326 sqlite3_mutex_leave(db->mutex);
@@ -88811,11 +89899,15 @@
88811 ** See also sqlite3LocateTable().
88812 */
88813 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
88814 Table *p = 0;
88815 int i;
88816 assert( zName!=0 );
 
 
 
 
88817 /* All mutexes are required for schema access. Make sure we hold them. */
88818 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
88819 #if SQLITE_USER_AUTHENTICATION
88820 /* Only the admin user is allowed to know that the sqlite_user table
88821 ** exists */
@@ -94275,12 +95367,12 @@
94275 break;
94276 }
94277 default: {
94278 /* Because sqlite3_value_double() returns 0.0 if the argument is not
94279 ** something that can be converted into a number, we have:
94280 ** IMP: R-57326-31541 Abs(X) return 0.0 if X is a string or blob that
94281 ** cannot be converted to a numeric value.
94282 */
94283 double rVal = sqlite3_value_double(argv[0]);
94284 if( rVal<0 ) rVal = -rVal;
94285 sqlite3_result_double(context, rVal);
94286 break;
@@ -99994,11 +101086,10 @@
99994 # define sqlite3_column_database_name16 0
99995 # define sqlite3_column_table_name 0
99996 # define sqlite3_column_table_name16 0
99997 # define sqlite3_column_origin_name 0
99998 # define sqlite3_column_origin_name16 0
99999 # define sqlite3_table_column_metadata 0
100000 #endif
100001
100002 #ifdef SQLITE_OMIT_AUTHORIZATION
100003 # define sqlite3_set_authorizer 0
100004 #endif
@@ -102928,11 +104019,11 @@
102928 break;
102929 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
102930
102931 #ifndef SQLITE_OMIT_WAL
102932 /*
102933 ** PRAGMA [database.]wal_checkpoint = passive|full|restart
102934 **
102935 ** Checkpoint the database.
102936 */
102937 case PragTyp_WAL_CHECKPOINT: {
102938 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
@@ -102940,10 +104031,12 @@
102940 if( zRight ){
102941 if( sqlite3StrICmp(zRight, "full")==0 ){
102942 eMode = SQLITE_CHECKPOINT_FULL;
102943 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
102944 eMode = SQLITE_CHECKPOINT_RESTART;
 
 
102945 }
102946 }
102947 sqlite3VdbeSetNumCols(v, 3);
102948 pParse->nMem = 3;
102949 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
@@ -103834,13 +104927,16 @@
103834 Vdbe *pOld, /* VM being reprepared */
103835 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
103836 const char **pzTail /* OUT: End of parsed string */
103837 ){
103838 int rc;
103839 assert( ppStmt!=0 );
 
 
 
103840 *ppStmt = 0;
103841 if( !sqlite3SafetyCheckOk(db) ){
103842 return SQLITE_MISUSE_BKPT;
103843 }
103844 sqlite3_mutex_enter(db->mutex);
103845 sqlite3BtreeEnterAll(db);
103846 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -103943,13 +105039,15 @@
103943 */
103944 char *zSql8;
103945 const char *zTail8 = 0;
103946 int rc = SQLITE_OK;
103947
103948 assert( ppStmt );
 
 
103949 *ppStmt = 0;
103950 if( !sqlite3SafetyCheckOk(db) ){
103951 return SQLITE_MISUSE_BKPT;
103952 }
103953 if( nBytes>=0 ){
103954 int sz;
103955 const char *z = (const char*)zSql;
@@ -108842,11 +109940,11 @@
108842 **
108843 ** SELECT DISTINCT xyz FROM ... ORDER BY xyz
108844 **
108845 ** is transformed to:
108846 **
108847 ** SELECT xyz FROM ... GROUP BY xyz
108848 **
108849 ** The second form is preferred as a single index (or temp-table) may be
108850 ** used for both the ORDER BY and DISTINCT processing. As originally
108851 ** written the query must use a temp-table for at least one of the ORDER
108852 ** BY and DISTINCT, and an index or separate temp-table for the other.
@@ -108855,11 +109953,10 @@
108855 && sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0
108856 ){
108857 p->selFlags &= ~SF_Distinct;
108858 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
108859 pGroupBy = p->pGroupBy;
108860 sSort.pOrderBy = 0;
108861 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
108862 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
108863 ** original setting of the SF_Distinct flag, not the current setting */
108864 assert( sDistinct.isTnct );
108865 }
@@ -109658,10 +110755,13 @@
109658 char **pzErrMsg /* Write error messages here */
109659 ){
109660 int rc;
109661 TabResult res;
109662
 
 
 
109663 *pazResult = 0;
109664 if( pnColumn ) *pnColumn = 0;
109665 if( pnRow ) *pnRow = 0;
109666 if( pzErrMsg ) *pzErrMsg = 0;
109667 res.zErrMsg = 0;
@@ -111721,11 +112821,11 @@
111721 ** Two writes per page are required in step (3) because the original
111722 ** database content must be written into the rollback journal prior to
111723 ** overwriting the database with the vacuumed content.
111724 **
111725 ** Only 1x temporary space and only 1x writes would be required if
111726 ** the copy of step (3) were replace by deleting the original database
111727 ** and renaming the transient database as the original. But that will
111728 ** not work if other processes are attached to the original database.
111729 ** And a power loss in between deleting the original and renaming the
111730 ** transient would cause the database file to appear to be deleted
111731 ** following reboot.
@@ -112079,10 +113179,13 @@
112079 sqlite3 *db, /* Database in which module is registered */
112080 const char *zName, /* Name assigned to this module */
112081 const sqlite3_module *pModule, /* The definition of the module */
112082 void *pAux /* Context pointer for xCreate/xConnect */
112083 ){
 
 
 
112084 return createModule(db, zName, pModule, pAux, 0);
112085 }
112086
112087 /*
112088 ** External API function used to create a new virtual-table module.
@@ -112092,10 +113195,13 @@
112092 const char *zName, /* Name assigned to this module */
112093 const sqlite3_module *pModule, /* The definition of the module */
112094 void *pAux, /* Context pointer for xCreate/xConnect */
112095 void (*xDestroy)(void *) /* Module destructor function */
112096 ){
 
 
 
112097 return createModule(db, zName, pModule, pAux, xDestroy);
112098 }
112099
112100 /*
112101 ** Lock the virtual table so that it cannot be disconnected.
@@ -112324,11 +113430,16 @@
112324 pTable->tabFlags |= TF_Virtual;
112325 pTable->nModuleArg = 0;
112326 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
112327 addModuleArgument(db, pTable, 0);
112328 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
112329 pParse->sNameToken.n = (int)(&pModuleName->z[pModuleName->n] - pName1->z);
 
 
 
 
 
112330
112331 #ifndef SQLITE_OMIT_AUTHORIZATION
112332 /* Creating a virtual table invokes the authorization callback twice.
112333 ** The first invocation, to obtain permission to INSERT a row into the
112334 ** sqlite_master table, has already been made by sqlite3StartTable().
@@ -112696,10 +113807,13 @@
112696
112697 int rc = SQLITE_OK;
112698 Table *pTab;
112699 char *zErr = 0;
112700
 
 
 
112701 sqlite3_mutex_enter(db->mutex);
112702 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
112703 sqlite3Error(db, SQLITE_MISUSE);
112704 sqlite3_mutex_leave(db->mutex);
112705 return SQLITE_MISUSE_BKPT;
@@ -113052,10 +114166,13 @@
113052 */
113053 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
113054 static const unsigned char aMap[] = {
113055 SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
113056 };
 
 
 
113057 assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
113058 assert( OE_Ignore==4 && OE_Replace==5 );
113059 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
113060 return (int)aMap[db->vtabOnConflict-1];
113061 }
@@ -113067,12 +114184,14 @@
113067 */
113068 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
113069 va_list ap;
113070 int rc = SQLITE_OK;
113071
 
 
 
113072 sqlite3_mutex_enter(db->mutex);
113073
113074 va_start(ap, op);
113075 switch( op ){
113076 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
113077 VtabCtx *p = db->pVtabCtx;
113078 if( !p ){
@@ -113203,10 +114322,13 @@
113203 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
113204 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
113205 } u;
113206 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
113207 Bitmask notReady; /* FROM entries not usable at this level */
 
 
 
113208 };
113209
113210 /*
113211 ** Each instance of this object represents an algorithm for evaluating one
113212 ** term of a join. Every term of the FROM clause will have at least
@@ -113233,11 +114355,10 @@
113233 LogEst rRun; /* Cost of running each loop */
113234 LogEst nOut; /* Estimated number of output rows */
113235 union {
113236 struct { /* Information for internal btree tables */
113237 u16 nEq; /* Number of equality constraints */
113238 u16 nSkip; /* Number of initial index columns to skip */
113239 Index *pIndex; /* Index used, or NULL */
113240 } btree;
113241 struct { /* Information for virtual tables */
113242 int idxNum; /* Index number */
113243 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -113246,16 +114367,17 @@
113246 char *idxStr; /* Index identifier string */
113247 } vtab;
113248 } u;
113249 u32 wsFlags; /* WHERE_* flags describing the plan */
113250 u16 nLTerm; /* Number of entries in aLTerm[] */
 
113251 /**** whereLoopXfer() copies fields above ***********************/
113252 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
113253 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
113254 WhereTerm **aLTerm; /* WhereTerms used */
113255 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
113256 WhereTerm *aLTermSpace[4]; /* Initial aLTerm[] space */
113257 };
113258
113259 /* This object holds the prerequisites and the cost of running a
113260 ** subquery on one operand of an OR operator in the WHERE clause.
113261 ** See WhereOrSet for additional information
@@ -113577,10 +114699,11 @@
113577 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
113578 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
113579 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
113580 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
113581 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
 
113582
113583 /************** End of whereInt.h ********************************************/
113584 /************** Continuing where we left off in where.c **********************/
113585
113586 /*
@@ -113784,14 +114907,15 @@
113784 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
113785 if( pOld!=pWC->aStatic ){
113786 sqlite3DbFree(db, pOld);
113787 }
113788 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
 
113789 }
113790 pTerm = &pWC->a[idx = pWC->nTerm++];
113791 if( p && ExprHasProperty(p, EP_Unlikely) ){
113792 pTerm->truthProb = sqlite3LogEst(p->iTable) - 99;
113793 }else{
113794 pTerm->truthProb = 1;
113795 }
113796 pTerm->pExpr = sqlite3ExprSkipCollate(p);
113797 pTerm->wtFlags = wtFlags;
@@ -114317,10 +115441,19 @@
114317 if( pDerived ){
114318 pDerived->flags |= pBase->flags & EP_FromJoin;
114319 pDerived->iRightJoinTable = pBase->iRightJoinTable;
114320 }
114321 }
 
 
 
 
 
 
 
 
 
114322
114323 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114324 /*
114325 ** Analyze a term that consists of two or more OR-connected
114326 ** subterms. So in:
@@ -114615,12 +115748,11 @@
114615 pNew->x.pList = pList;
114616 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
114617 testcase( idxNew==0 );
114618 exprAnalyze(pSrc, pWC, idxNew);
114619 pTerm = &pWC->a[idxTerm];
114620 pWC->a[idxNew].iParent = idxTerm;
114621 pTerm->nChild = 1;
114622 }else{
114623 sqlite3ExprListDelete(db, pList);
114624 }
114625 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
114626 }
@@ -114718,13 +115850,12 @@
114718 return;
114719 }
114720 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
114721 if( idxNew==0 ) return;
114722 pNew = &pWC->a[idxNew];
114723 pNew->iParent = idxTerm;
114724 pTerm = &pWC->a[idxTerm];
114725 pTerm->nChild = 1;
114726 pTerm->wtFlags |= TERM_COPIED;
114727 if( pExpr->op==TK_EQ
114728 && !ExprHasProperty(pExpr, EP_FromJoin)
114729 && OptimizationEnabled(db, SQLITE_Transitive)
114730 ){
@@ -114777,13 +115908,12 @@
114777 transferJoinMarkings(pNewExpr, pExpr);
114778 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
114779 testcase( idxNew==0 );
114780 exprAnalyze(pSrc, pWC, idxNew);
114781 pTerm = &pWC->a[idxTerm];
114782 pWC->a[idxNew].iParent = idxTerm;
114783 }
114784 pTerm->nChild = 2;
114785 }
114786 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
114787
114788 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
114789 /* Analyze a term that is composed of two or more subterms connected by
@@ -114854,13 +115984,12 @@
114854 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
114855 testcase( idxNew2==0 );
114856 exprAnalyze(pSrc, pWC, idxNew2);
114857 pTerm = &pWC->a[idxTerm];
114858 if( isComplete ){
114859 pWC->a[idxNew1].iParent = idxTerm;
114860 pWC->a[idxNew2].iParent = idxTerm;
114861 pTerm->nChild = 2;
114862 }
114863 }
114864 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
114865
114866 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -114889,13 +116018,12 @@
114889 pNewTerm = &pWC->a[idxNew];
114890 pNewTerm->prereqRight = prereqExpr;
114891 pNewTerm->leftCursor = pLeft->iTable;
114892 pNewTerm->u.leftColumn = pLeft->iColumn;
114893 pNewTerm->eOperator = WO_MATCH;
114894 pNewTerm->iParent = idxTerm;
114895 pTerm = &pWC->a[idxTerm];
114896 pTerm->nChild = 1;
114897 pTerm->wtFlags |= TERM_COPIED;
114898 pNewTerm->prereqAll = pTerm->prereqAll;
114899 }
114900 }
114901 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -114912,11 +116040,11 @@
114912 ** the start of the loop will prevent any results from being returned.
114913 */
114914 if( pExpr->op==TK_NOTNULL
114915 && pExpr->pLeft->op==TK_COLUMN
114916 && pExpr->pLeft->iColumn>=0
114917 && OptimizationEnabled(db, SQLITE_Stat3)
114918 ){
114919 Expr *pNewExpr;
114920 Expr *pLeft = pExpr->pLeft;
114921 int idxNew;
114922 WhereTerm *pNewTerm;
@@ -114931,13 +116059,12 @@
114931 pNewTerm = &pWC->a[idxNew];
114932 pNewTerm->prereqRight = 0;
114933 pNewTerm->leftCursor = pLeft->iTable;
114934 pNewTerm->u.leftColumn = pLeft->iColumn;
114935 pNewTerm->eOperator = WO_GT;
114936 pNewTerm->iParent = idxTerm;
114937 pTerm = &pWC->a[idxTerm];
114938 pTerm->nChild = 1;
114939 pTerm->wtFlags |= TERM_COPIED;
114940 pNewTerm->prereqAll = pTerm->prereqAll;
114941 }
114942 }
114943 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115153,10 +116280,12 @@
115153 WhereLoop *pLoop; /* The Loop object */
115154 char *zNotUsed; /* Extra space on the end of pIdx */
115155 Bitmask idxCols; /* Bitmap of columns used for indexing */
115156 Bitmask extraCols; /* Bitmap of additional columns */
115157 u8 sentWarning = 0; /* True if a warnning has been issued */
 
 
115158
115159 /* Generate code to skip over the creation and initialization of the
115160 ** transient index on 2nd and subsequent iterations of the loop. */
115161 v = pParse->pVdbe;
115162 assert( v!=0 );
@@ -115168,10 +116297,16 @@
115168 pTable = pSrc->pTab;
115169 pWCEnd = &pWC->a[pWC->nTerm];
115170 pLoop = pLevel->pWLoop;
115171 idxCols = 0;
115172 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
 
 
 
 
 
 
115173 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
115174 int iCol = pTerm->u.leftColumn;
115175 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
115176 testcase( iCol==BMS );
115177 testcase( iCol==BMS-1 );
@@ -115180,11 +116315,13 @@
115180 "automatic index on %s(%s)", pTable->zName,
115181 pTable->aCol[iCol].zName);
115182 sentWarning = 1;
115183 }
115184 if( (idxCols & cMask)==0 ){
115185 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ) return;
 
 
115186 pLoop->aLTerm[nKeyCol++] = pTerm;
115187 idxCols |= cMask;
115188 }
115189 }
115190 }
@@ -115200,24 +116337,23 @@
115200 ** be a covering index because the index will not be updated if the
115201 ** original table changes and the index and table cannot both be used
115202 ** if they go out of sync.
115203 */
115204 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
115205 mxBitCol = (pTable->nCol >= BMS-1) ? BMS-1 : pTable->nCol;
115206 testcase( pTable->nCol==BMS-1 );
115207 testcase( pTable->nCol==BMS-2 );
115208 for(i=0; i<mxBitCol; i++){
115209 if( extraCols & MASKBIT(i) ) nKeyCol++;
115210 }
115211 if( pSrc->colUsed & MASKBIT(BMS-1) ){
115212 nKeyCol += pTable->nCol - BMS + 1;
115213 }
115214 pLoop->wsFlags |= WHERE_COLUMN_EQ | WHERE_IDX_ONLY;
115215
115216 /* Construct the Index object to describe this index */
115217 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
115218 if( pIdx==0 ) return;
115219 pLoop->u.btree.pIndex = pIdx;
115220 pIdx->zName = "auto-index";
115221 pIdx->pTable = pTable;
115222 n = 0;
115223 idxCols = 0;
@@ -115265,22 +116401,33 @@
115265 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
115266 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
115267 VdbeComment((v, "for %s", pTable->zName));
115268
115269 /* Fill the automatic index with content */
 
115270 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
 
 
 
 
 
115271 regRecord = sqlite3GetTempReg(pParse);
115272 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
115273 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
115274 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
 
115275 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
115276 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
115277 sqlite3VdbeJumpHere(v, addrTop);
115278 sqlite3ReleaseTempReg(pParse, regRecord);
 
115279
115280 /* Jump here when skipping the initialization */
115281 sqlite3VdbeJumpHere(v, addrInit);
 
 
 
115282 }
115283 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
115284
115285 #ifndef SQLITE_OMIT_VIRTUALTABLE
115286 /*
@@ -115436,22 +116583,22 @@
115436
115437 return pParse->nErr;
115438 }
115439 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
115440
115441
115442 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115443 /*
115444 ** Estimate the location of a particular key among all keys in an
115445 ** index. Store the results in aStat as follows:
115446 **
115447 ** aStat[0] Est. number of rows less than pVal
115448 ** aStat[1] Est. number of rows equal to pVal
115449 **
115450 ** Return SQLITE_OK on success.
 
115451 */
115452 static void whereKeyStats(
115453 Parse *pParse, /* Database connection */
115454 Index *pIdx, /* Index to consider domain of */
115455 UnpackedRecord *pRec, /* Vector of values to consider */
115456 int roundUp, /* Round up if true. Round down if false */
115457 tRowcnt *aStat /* OUT: stats written here */
@@ -115529,10 +116676,11 @@
115529 }else{
115530 iGap = iGap/3;
115531 }
115532 aStat[0] = iLower + iGap;
115533 }
 
115534 }
115535 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
115536
115537 /*
115538 ** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -115679,11 +116827,11 @@
115679 ** pLower pUpper
115680 **
115681 ** If either of the upper or lower bound is not present, then NULL is passed in
115682 ** place of the corresponding WhereTerm.
115683 **
115684 ** The value in (pBuilder->pNew->u.btree.nEq) is the index of the index
115685 ** column subject to the range constraint. Or, equivalently, the number of
115686 ** equality constraints optimized by the proposed index scan. For example,
115687 ** assuming index p is on t1(a, b), and the SQL query is:
115688 **
115689 ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -115695,11 +116843,11 @@
115695 **
115696 ** then nEq is set to 0.
115697 **
115698 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
115699 ** number of rows that the index scan is expected to visit without
115700 ** considering the range constraints. If nEq is 0, this is the number of
115701 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
115702 ** to account for the range constraints pLower and pUpper.
115703 **
115704 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
115705 ** used, a single range inequality reduces the search space by a factor of 4.
@@ -115719,14 +116867,11 @@
115719
115720 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
115721 Index *p = pLoop->u.btree.pIndex;
115722 int nEq = pLoop->u.btree.nEq;
115723
115724 if( p->nSample>0
115725 && nEq<p->nSampleCol
115726 && OptimizationEnabled(pParse->db, SQLITE_Stat3)
115727 ){
115728 if( nEq==pBuilder->nRecValid ){
115729 UnpackedRecord *pRec = pBuilder->pRec;
115730 tRowcnt a[2];
115731 u8 aff;
115732
@@ -115738,19 +116883,23 @@
115738 **
115739 ** Or, if pLower is NULL or $L cannot be extracted from it (because it
115740 ** is not a simple variable or literal value), the lower bound of the
115741 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
115742 ** if $L is available, whereKeyStats() is called for both ($P) and
115743 ** ($P:$L) and the larger of the two returned values used.
115744 **
115745 ** Similarly, iUpper is to be set to the estimate of the number of rows
115746 ** less than the upper bound of the range query. Where the upper bound
115747 ** is either ($P) or ($P:$U). Again, even if $U is available, both values
115748 ** of iUpper are requested of whereKeyStats() and the smaller used.
 
 
115749 */
115750 tRowcnt iLower;
115751 tRowcnt iUpper;
 
 
115752
115753 if( pRec ){
115754 testcase( pRec->nField!=pBuilder->nRecValid );
115755 pRec->nField = pBuilder->nRecValid;
115756 }
@@ -115760,11 +116909,11 @@
115760 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
115761 }
115762 /* Determine iLower and iUpper using ($P) only. */
115763 if( nEq==0 ){
115764 iLower = 0;
115765 iUpper = sqlite3LogEstToInt(p->aiRowLogEst[0]);
115766 }else{
115767 /* Note: this call could be optimized away - since the same values must
115768 ** have been requested when testing key $P in whereEqualScanEst(). */
115769 whereKeyStats(pParse, p, pRec, 0, a);
115770 iLower = a[0];
@@ -115784,11 +116933,11 @@
115784 int bOk; /* True if value is extracted from pExpr */
115785 Expr *pExpr = pLower->pExpr->pRight;
115786 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115787 if( rc==SQLITE_OK && bOk ){
115788 tRowcnt iNew;
115789 whereKeyStats(pParse, p, pRec, 0, a);
115790 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115791 if( iNew>iLower ) iLower = iNew;
115792 nOut--;
115793 pLower = 0;
115794 }
@@ -115799,11 +116948,11 @@
115799 int bOk; /* True if value is extracted from pExpr */
115800 Expr *pExpr = pUpper->pExpr->pRight;
115801 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
115802 if( rc==SQLITE_OK && bOk ){
115803 tRowcnt iNew;
115804 whereKeyStats(pParse, p, pRec, 1, a);
115805 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
115806 if( iNew<iUpper ) iUpper = iNew;
115807 nOut--;
115808 pUpper = 0;
115809 }
@@ -115811,10 +116960,15 @@
115811
115812 pBuilder->pRec = pRec;
115813 if( rc==SQLITE_OK ){
115814 if( iUpper>iLower ){
115815 nNew = sqlite3LogEst(iUpper - iLower);
 
 
 
 
 
115816 }else{
115817 nNew = 10; assert( 10==sqlite3LogEst(2) );
115818 }
115819 if( nNew<nOut ){
115820 nOut = nNew;
@@ -115835,16 +116989,19 @@
115835 #endif
115836 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
115837 nNew = whereRangeAdjust(pLower, nOut);
115838 nNew = whereRangeAdjust(pUpper, nNew);
115839
115840 /* TUNING: If there is both an upper and lower limit, assume the range is
 
115841 ** reduced by an additional 75%. This means that, by default, an open-ended
115842 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
115843 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
115844 ** match 1/64 of the index. */
115845 if( pLower && pUpper ) nNew -= 20;
 
 
115846
115847 nOut -= (pLower!=0) + (pUpper!=0);
115848 if( nNew<10 ) nNew = 10;
115849 if( nNew<nOut ) nOut = nNew;
115850 #if defined(WHERETRACE_ENABLED)
@@ -116200,11 +117357,11 @@
116200
116201 /* This module is only called on query plans that use an index. */
116202 pLoop = pLevel->pWLoop;
116203 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
116204 nEq = pLoop->u.btree.nEq;
116205 nSkip = pLoop->u.btree.nSkip;
116206 pIdx = pLoop->u.btree.pIndex;
116207 assert( pIdx!=0 );
116208
116209 /* Figure out how many memory cells we will need then allocate them.
116210 */
@@ -116314,11 +117471,11 @@
116314 ** "a=? AND b>?"
116315 */
116316 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
116317 Index *pIndex = pLoop->u.btree.pIndex;
116318 u16 nEq = pLoop->u.btree.nEq;
116319 u16 nSkip = pLoop->u.btree.nSkip;
116320 int i, j;
116321 Column *aCol = pTab->aCol;
116322 i16 *aiColumn = pIndex->aiColumn;
116323
116324 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -116345,23 +117502,27 @@
116345 sqlite3StrAccumAppend(pStr, ")", 1);
116346 }
116347
116348 /*
116349 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
116350 ** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
116351 ** record is added to the output to describe the table scan strategy in
116352 ** pLevel.
 
 
 
116353 */
116354 static void explainOneScan(
116355 Parse *pParse, /* Parse context */
116356 SrcList *pTabList, /* Table list this loop refers to */
116357 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
116358 int iLevel, /* Value for "level" column of output */
116359 int iFrom, /* Value for "from" column of output */
116360 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
116361 ){
116362 #ifndef SQLITE_DEBUG
 
116363 if( pParse->explain==2 )
116364 #endif
116365 {
116366 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
116367 Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -116374,11 +117535,11 @@
116374 StrAccum str; /* EQP output string */
116375 char zBuf[100]; /* Initial space for EQP output string */
116376
116377 pLoop = pLevel->pWLoop;
116378 flags = pLoop->wsFlags;
116379 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return;
116380
116381 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
116382 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
116383 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
116384
@@ -116403,10 +117564,12 @@
116403 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
116404 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
116405 if( isSearch ){
116406 zFmt = "PRIMARY KEY";
116407 }
 
 
116408 }else if( flags & WHERE_AUTO_INDEX ){
116409 zFmt = "AUTOMATIC COVERING INDEX";
116410 }else if( flags & WHERE_IDX_ONLY ){
116411 zFmt = "COVERING INDEX %s";
116412 }else{
@@ -116444,16 +117607,49 @@
116444 }else{
116445 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
116446 }
116447 #endif
116448 zMsg = sqlite3StrAccumFinish(&str);
116449 sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg, P4_DYNAMIC);
116450 }
 
116451 }
116452 #else
116453 # define explainOneScan(u,v,w,x,y,z)
116454 #endif /* SQLITE_OMIT_EXPLAIN */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116455
116456
116457 /*
116458 ** Generate code for the start of the iLevel-th loop in the WHERE clause
116459 ** implementation described by pWInfo.
@@ -116751,11 +117947,11 @@
116751 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
116752 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
116753
116754 pIdx = pLoop->u.btree.pIndex;
116755 iIdxCur = pLevel->iIdxCur;
116756 assert( nEq>=pLoop->u.btree.nSkip );
116757
116758 /* If this loop satisfies a sort order (pOrderBy) request that
116759 ** was passed to this function to implement a "SELECT min(x) ..."
116760 ** query, then the caller will only allow the loop to run for
116761 ** a single iteration. This means that the first row returned
@@ -116768,11 +117964,11 @@
116768 || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
116769 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
116770 && pWInfo->nOBSat>0
116771 && (pIdx->nKeyCol>nEq)
116772 ){
116773 assert( pLoop->u.btree.nSkip==0 );
116774 bSeekPastNull = 1;
116775 nExtraReg = 1;
116776 }
116777
116778 /* Find any inequality constraint terms for the start and end
@@ -117081,14 +118277,13 @@
117081 int iTerm;
117082 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
117083 Expr *pExpr = pWC->a[iTerm].pExpr;
117084 if( &pWC->a[iTerm] == pTerm ) continue;
117085 if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
117086 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
117087 testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL );
117088 if( pWC->a[iTerm].wtFlags & (TERM_ORINFO|TERM_VIRTUAL) ) continue;
117089 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
 
117090 pExpr = sqlite3ExprDup(db, pExpr, 0);
117091 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
117092 }
117093 if( pAndExpr ){
117094 pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
@@ -117117,13 +118312,15 @@
117117 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
117118 wctrlFlags, iCovCur);
117119 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
117120 if( pSubWInfo ){
117121 WhereLoop *pSubLoop;
117122 explainOneScan(
117123 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
117124 );
 
 
117125 /* This is the sub-WHERE clause body. First skip over
117126 ** duplicate rows from prior sub-WHERE clauses, and record the
117127 ** rowid (or PRIMARY KEY) for the current row so that the same
117128 ** row will be skipped in subsequent sub-WHERE clauses.
117129 */
@@ -117249,10 +118446,14 @@
117249 VdbeCoverageIf(v, bRev==0);
117250 VdbeCoverageIf(v, bRev!=0);
117251 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
117252 }
117253 }
 
 
 
 
117254
117255 /* Insert code to test every subexpression that can be completely
117256 ** computed using the current set of tables.
117257 */
117258 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
@@ -117389,11 +118590,11 @@
117389 }
117390 sqlite3DebugPrintf(" %-19s", z);
117391 sqlite3_free(z);
117392 }
117393 if( p->wsFlags & WHERE_SKIPSCAN ){
117394 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->u.btree.nSkip);
117395 }else{
117396 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
117397 }
117398 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
117399 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -117500,34 +118701,41 @@
117500 sqlite3DbFree(db, pWInfo);
117501 }
117502 }
117503
117504 /*
117505 ** Return TRUE if both of the following are true:
117506 **
117507 ** (1) X has the same or lower cost that Y
117508 ** (2) X is a proper subset of Y
 
117509 **
117510 ** By "proper subset" we mean that X uses fewer WHERE clause terms
117511 ** than Y and that every WHERE clause term used by X is also used
117512 ** by Y.
117513 **
117514 ** If X is a proper subset of Y then Y is a better choice and ought
117515 ** to have a lower cost. This routine returns TRUE when that cost
117516 ** relationship is inverted and needs to be adjusted.
 
 
117517 */
117518 static int whereLoopCheaperProperSubset(
117519 const WhereLoop *pX, /* First WhereLoop to compare */
117520 const WhereLoop *pY /* Compare against this WhereLoop */
117521 ){
117522 int i, j;
117523 if( pX->nLTerm >= pY->nLTerm ) return 0; /* X is not a subset of Y */
 
 
 
117524 if( pX->rRun >= pY->rRun ){
117525 if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
117526 if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
117527 }
117528 for(i=pX->nLTerm-1; i>=0; i--){
 
117529 for(j=pY->nLTerm-1; j>=0; j--){
117530 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
117531 }
117532 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
117533 }
@@ -117545,37 +118753,28 @@
117545 ** is a proper subset.
117546 **
117547 ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
117548 ** WHERE clause terms than Y and that every WHERE clause term used by X is
117549 ** also used by Y.
117550 **
117551 ** This adjustment is omitted for SKIPSCAN loops. In a SKIPSCAN loop, the
117552 ** WhereLoop.nLTerm field is not an accurate measure of the number of WHERE
117553 ** clause terms covered, since some of the first nLTerm entries in aLTerm[]
117554 ** will be NULL (because they are skipped). That makes it more difficult
117555 ** to compare the loops. We could add extra code to do the comparison, and
117556 ** perhaps we will someday. But SKIPSCAN is sufficiently uncommon, and this
117557 ** adjustment is sufficient minor, that it is very difficult to construct
117558 ** a test case where the extra code would improve the query plan. Better
117559 ** to avoid the added complexity and just omit cost adjustments to SKIPSCAN
117560 ** loops.
117561 */
117562 static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
117563 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
117564 if( (pTemplate->wsFlags & WHERE_SKIPSCAN)!=0 ) return;
117565 for(; p; p=p->pNextLoop){
117566 if( p->iTab!=pTemplate->iTab ) continue;
117567 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
117568 if( (p->wsFlags & WHERE_SKIPSCAN)!=0 ) continue;
117569 if( whereLoopCheaperProperSubset(p, pTemplate) ){
117570 /* Adjust pTemplate cost downward so that it is cheaper than its
117571 ** subset p */
 
 
117572 pTemplate->rRun = p->rRun;
117573 pTemplate->nOut = p->nOut - 1;
117574 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
117575 /* Adjust pTemplate cost upward so that it is costlier than p since
117576 ** pTemplate is a proper subset of p */
 
 
117577 pTemplate->rRun = p->rRun;
117578 pTemplate->nOut = p->nOut + 1;
117579 }
117580 }
117581 }
@@ -117616,12 +118815,13 @@
117616 ** rSetup. Call this SETUP-INVARIANT */
117617 assert( p->rSetup>=pTemplate->rSetup );
117618
117619 /* Any loop using an appliation-defined index (or PRIMARY KEY or
117620 ** UNIQUE constraint) with one or more == constraints is better
117621 ** than an automatic index. */
117622 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
 
117623 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
117624 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
117625 && (p->prereq & pTemplate->prereq)==pTemplate->prereq
117626 ){
117627 break;
@@ -117776,25 +118976,46 @@
117776
117777 /*
117778 ** Adjust the WhereLoop.nOut value downward to account for terms of the
117779 ** WHERE clause that reference the loop but which are not used by an
117780 ** index.
 
 
 
 
 
117781 **
117782 ** In the current implementation, the first extra WHERE clause term reduces
117783 ** the number of output rows by a factor of 10 and each additional term
117784 ** reduces the number of output rows by sqrt(2).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117785 */
117786 static void whereLoopOutputAdjust(
117787 WhereClause *pWC, /* The WHERE clause */
117788 WhereLoop *pLoop, /* The loop to adjust downward */
117789 LogEst nRow /* Number of rows in the entire table */
117790 ){
117791 WhereTerm *pTerm, *pX;
117792 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
117793 int i, j;
117794 int nEq = 0; /* Number of = constraints not within likely()/unlikely() */
117795
 
117796 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
117797 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
117798 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
117799 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
117800 for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117803,24 +119024,30 @@
117803 if( pX==pTerm ) break;
117804 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
117805 }
117806 if( j<0 ){
117807 if( pTerm->truthProb<=0 ){
 
 
117808 pLoop->nOut += pTerm->truthProb;
117809 }else{
 
 
117810 pLoop->nOut--;
117811 if( pTerm->eOperator&WO_EQ ) nEq++;
 
 
 
 
 
 
 
 
117812 }
117813 }
117814 }
117815 /* TUNING: If there is at least one equality constraint in the WHERE
117816 ** clause that does not have a likelihood() explicitly assigned to it
117817 ** then do not let the estimated number of output rows exceed half
117818 ** the number of rows in the table. */
117819 if( nEq && pLoop->nOut>nRow-10 ){
117820 pLoop->nOut = nRow - 10;
117821 }
117822 }
117823
117824 /*
117825 ** Adjust the cost C by the costMult facter T. This only occurs if
117826 ** compiled with -DSQLITE_ENABLE_COSTMULT
@@ -117857,11 +119084,11 @@
117857 int opMask; /* Valid operators for constraints */
117858 WhereScan scan; /* Iterator for WHERE terms */
117859 Bitmask saved_prereq; /* Original value of pNew->prereq */
117860 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
117861 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
117862 u16 saved_nSkip; /* Original value of pNew->u.btree.nSkip */
117863 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
117864 LogEst saved_nOut; /* Original value of pNew->nOut */
117865 int iCol; /* Index of the column in the table */
117866 int rc = SQLITE_OK; /* Return code */
117867 LogEst rSize; /* Number of rows in the table */
@@ -117886,56 +119113,18 @@
117886 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
117887
117888 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
117889 opMask, pProbe);
117890 saved_nEq = pNew->u.btree.nEq;
117891 saved_nSkip = pNew->u.btree.nSkip;
117892 saved_nLTerm = pNew->nLTerm;
117893 saved_wsFlags = pNew->wsFlags;
117894 saved_prereq = pNew->prereq;
117895 saved_nOut = pNew->nOut;
117896 pNew->rSetup = 0;
117897 rSize = pProbe->aiRowLogEst[0];
117898 rLogSize = estLog(rSize);
117899
117900 /* Consider using a skip-scan if there are no WHERE clause constraints
117901 ** available for the left-most terms of the index, and if the average
117902 ** number of repeats in the left-most terms is at least 18.
117903 **
117904 ** The magic number 18 is selected on the basis that scanning 17 rows
117905 ** is almost always quicker than an index seek (even though if the index
117906 ** contains fewer than 2^17 rows we assume otherwise in other parts of
117907 ** the code). And, even if it is not, it should not be too much slower.
117908 ** On the other hand, the extra seeks could end up being significantly
117909 ** more expensive. */
117910 assert( 42==sqlite3LogEst(18) );
117911 if( saved_nEq==saved_nSkip
117912 && saved_nEq+1<pProbe->nKeyCol
117913 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
117914 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
117915 ){
117916 LogEst nIter;
117917 pNew->u.btree.nEq++;
117918 pNew->u.btree.nSkip++;
117919 pNew->aLTerm[pNew->nLTerm++] = 0;
117920 pNew->wsFlags |= WHERE_SKIPSCAN;
117921 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
117922 if( pTerm ){
117923 /* TUNING: When estimating skip-scan for a term that is also indexable,
117924 ** multiply the cost of the skip-scan by 2.0, to make it a little less
117925 ** desirable than the regular index lookup. */
117926 nIter += 10; assert( 10==sqlite3LogEst(2) );
117927 }
117928 pNew->nOut -= nIter;
117929 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
117930 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
117931 nIter += 5;
117932 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
117933 pNew->nOut = saved_nOut;
117934 pNew->u.btree.nEq = saved_nEq;
117935 pNew->u.btree.nSkip = saved_nSkip;
117936 }
117937 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
117938 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
117939 LogEst rCostIdx;
117940 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
117941 int nIn = 0;
@@ -118026,11 +119215,10 @@
118026 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
118027 tRowcnt nOut = 0;
118028 if( nInMul==0
118029 && pProbe->nSample
118030 && pNew->u.btree.nEq<=pProbe->nSampleCol
118031 && OptimizationEnabled(db, SQLITE_Stat3)
118032 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
118033 ){
118034 Expr *pExpr = pTerm->pExpr;
118035 if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
118036 testcase( eOp & WO_EQ );
@@ -118094,14 +119282,49 @@
118094 pBuilder->nRecValid = nRecValid;
118095 #endif
118096 }
118097 pNew->prereq = saved_prereq;
118098 pNew->u.btree.nEq = saved_nEq;
118099 pNew->u.btree.nSkip = saved_nSkip;
118100 pNew->wsFlags = saved_wsFlags;
118101 pNew->nOut = saved_nOut;
118102 pNew->nLTerm = saved_nLTerm;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118103 return rc;
118104 }
118105
118106 /*
118107 ** Return True if it is possible that pIndex might be useful in
@@ -118276,11 +119499,11 @@
118276 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
118277 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
118278 if( pTerm->prereqRight & pNew->maskSelf ) continue;
118279 if( termCanDriveIndex(pTerm, pSrc, 0) ){
118280 pNew->u.btree.nEq = 1;
118281 pNew->u.btree.nSkip = 0;
118282 pNew->u.btree.pIndex = 0;
118283 pNew->nLTerm = 1;
118284 pNew->aLTerm[0] = pTerm;
118285 /* TUNING: One-time cost for computing the automatic index is
118286 ** estimated to be X*N*log2(N) where N is the number of rows in
@@ -118317,11 +119540,11 @@
118317 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
118318 continue; /* Partial index inappropriate for this query */
118319 }
118320 rSize = pProbe->aiRowLogEst[0];
118321 pNew->u.btree.nEq = 0;
118322 pNew->u.btree.nSkip = 0;
118323 pNew->nLTerm = 0;
118324 pNew->iSortIdx = 0;
118325 pNew->rSetup = 0;
118326 pNew->prereq = mExtra;
118327 pNew->nOut = rSize;
@@ -118867,11 +120090,11 @@
118867 for(j=0; j<nColumn; j++){
118868 u8 bOnce; /* True to run the ORDER BY search loop */
118869
118870 /* Skip over == and IS NULL terms */
118871 if( j<pLoop->u.btree.nEq
118872 && pLoop->u.btree.nSkip==0
118873 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
118874 ){
118875 if( i & WO_ISNULL ){
118876 testcase( isOrderDistinct );
118877 isOrderDistinct = 0;
@@ -119321,11 +120544,11 @@
119321 }
119322 }
119323 }
119324
119325 #ifdef WHERETRACE_ENABLED /* >=2 */
119326 if( sqlite3WhereTrace>=2 ){
119327 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
119328 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
119329 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
119330 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
119331 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -119440,11 +120663,11 @@
119440 if( pItem->zIndex ) return 0;
119441 iCur = pItem->iCursor;
119442 pWC = &pWInfo->sWC;
119443 pLoop = pBuilder->pNew;
119444 pLoop->wsFlags = 0;
119445 pLoop->u.btree.nSkip = 0;
119446 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
119447 if( pTerm ){
119448 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
119449 pLoop->aLTerm[0] = pTerm;
119450 pLoop->nLTerm = 1;
@@ -119452,11 +120675,10 @@
119452 /* TUNING: Cost of a rowid lookup is 10 */
119453 pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
119454 }else{
119455 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
119456 assert( pLoop->aLTermSpace==pLoop->aLTerm );
119457 assert( ArraySize(pLoop->aLTermSpace)==4 );
119458 if( !IsUniqueIndex(pIdx)
119459 || pIdx->pPartIdxWhere!=0
119460 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
119461 ) continue;
119462 for(j=0; j<pIdx->nKeyCol; j++){
@@ -119961,22 +121183,30 @@
119961 ** loop below generates code for a single nested loop of the VM
119962 ** program.
119963 */
119964 notReady = ~(Bitmask)0;
119965 for(ii=0; ii<nTabList; ii++){
 
 
119966 pLevel = &pWInfo->a[ii];
 
119967 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
119968 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
119969 constructAutomaticIndex(pParse, &pWInfo->sWC,
119970 &pTabList->a[pLevel->iFrom], notReady, pLevel);
119971 if( db->mallocFailed ) goto whereBeginError;
119972 }
119973 #endif
119974 explainOneScan(pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags);
 
 
119975 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
119976 notReady = codeOneLoopStart(pWInfo, ii, notReady);
119977 pWInfo->iContinue = pLevel->addrCont;
 
 
 
119978 }
119979
119980 /* Done. */
119981 VdbeModuleComment((v, "Begin WHERE-core"));
119982 return pWInfo;
@@ -124640,10 +125870,17 @@
124640 ** is look for a semicolon that is not part of an string or comment.
124641 */
124642 SQLITE_API int sqlite3_complete(const char *zSql){
124643 u8 state = 0; /* Current state, using numbers defined in header comment */
124644 u8 token; /* Value of the next token */
 
 
 
 
 
 
 
124645
124646 #ifndef SQLITE_OMIT_TRIGGER
124647 /* A complex statement machine used to detect the end of a CREATE TRIGGER
124648 ** statement. This is the normal case.
124649 */
@@ -125238,74 +126475,106 @@
125238
125239 va_start(ap, op);
125240 switch( op ){
125241
125242 /* Mutex configuration options are only available in a threadsafe
125243 ** compile.
125244 */
125245 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0
125246 case SQLITE_CONFIG_SINGLETHREAD: {
125247 /* Disable all mutexing */
125248 sqlite3GlobalConfig.bCoreMutex = 0;
125249 sqlite3GlobalConfig.bFullMutex = 0;
125250 break;
125251 }
 
 
125252 case SQLITE_CONFIG_MULTITHREAD: {
125253 /* Disable mutexing of database connections */
125254 /* Enable mutexing of core data structures */
125255 sqlite3GlobalConfig.bCoreMutex = 1;
125256 sqlite3GlobalConfig.bFullMutex = 0;
125257 break;
125258 }
 
 
125259 case SQLITE_CONFIG_SERIALIZED: {
125260 /* Enable all mutexing */
125261 sqlite3GlobalConfig.bCoreMutex = 1;
125262 sqlite3GlobalConfig.bFullMutex = 1;
125263 break;
125264 }
 
 
125265 case SQLITE_CONFIG_MUTEX: {
125266 /* Specify an alternative mutex implementation */
125267 sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
125268 break;
125269 }
 
 
125270 case SQLITE_CONFIG_GETMUTEX: {
125271 /* Retrieve the current mutex implementation */
125272 *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
125273 break;
125274 }
125275 #endif
125276
125277
125278 case SQLITE_CONFIG_MALLOC: {
125279 /* Specify an alternative malloc implementation */
 
 
 
 
125280 sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
125281 break;
125282 }
125283 case SQLITE_CONFIG_GETMALLOC: {
125284 /* Retrieve the current malloc() implementation */
 
 
 
125285 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
125286 *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
125287 break;
125288 }
125289 case SQLITE_CONFIG_MEMSTATUS: {
125290 /* Enable or disable the malloc status collection */
 
 
125291 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
125292 break;
125293 }
125294 case SQLITE_CONFIG_SCRATCH: {
125295 /* Designate a buffer for scratch memory space */
 
 
 
125296 sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
125297 sqlite3GlobalConfig.szScratch = va_arg(ap, int);
125298 sqlite3GlobalConfig.nScratch = va_arg(ap, int);
125299 break;
125300 }
125301 case SQLITE_CONFIG_PAGECACHE: {
125302 /* Designate a buffer for page cache memory space */
 
 
125303 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
125304 sqlite3GlobalConfig.szPage = va_arg(ap, int);
125305 sqlite3GlobalConfig.nPage = va_arg(ap, int);
125306 break;
 
 
 
 
 
 
 
 
 
 
 
125307 }
125308
125309 case SQLITE_CONFIG_PCACHE: {
125310 /* no-op */
125311 break;
@@ -125315,25 +126584,37 @@
125315 rc = SQLITE_ERROR;
125316 break;
125317 }
125318
125319 case SQLITE_CONFIG_PCACHE2: {
125320 /* Specify an alternative page cache implementation */
 
 
 
125321 sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
125322 break;
125323 }
125324 case SQLITE_CONFIG_GETPCACHE2: {
 
 
 
 
125325 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
125326 sqlite3PCacheSetDefault();
125327 }
125328 *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
125329 break;
125330 }
125331
 
 
 
125332 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
125333 case SQLITE_CONFIG_HEAP: {
125334 /* Designate a buffer for heap memory space */
 
 
125335 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
125336 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125337 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
125338
125339 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -125342,21 +126623,23 @@
125342 /* cap min request size at 2^12 */
125343 sqlite3GlobalConfig.mnReq = (1<<12);
125344 }
125345
125346 if( sqlite3GlobalConfig.pHeap==0 ){
125347 /* If the heap pointer is NULL, then restore the malloc implementation
125348 ** back to NULL pointers too. This will cause the malloc to go
125349 ** back to its default implementation when sqlite3_initialize() is
125350 ** run.
 
 
 
125351 */
125352 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
125353 }else{
125354 /* The heap pointer is not NULL, then install one of the
125355 ** mem5.c/mem3.c methods. The enclosing #if guarantees at
125356 ** least one of these methods is currently enabled.
125357 */
125358 #ifdef SQLITE_ENABLE_MEMSYS3
125359 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
125360 #endif
125361 #ifdef SQLITE_ENABLE_MEMSYS5
125362 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -125391,15 +126674,23 @@
125391 ** can be changed at start-time using the
125392 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
125393 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
125394 */
125395 case SQLITE_CONFIG_URI: {
 
 
 
 
125396 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
125397 break;
125398 }
125399
125400 case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
 
 
 
 
125401 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
125402 break;
125403 }
125404
125405 #ifdef SQLITE_ENABLE_SQLLOG
@@ -125410,24 +126701,37 @@
125410 break;
125411 }
125412 #endif
125413
125414 case SQLITE_CONFIG_MMAP_SIZE: {
 
 
 
 
125415 sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
125416 sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
125417 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ){
125418 mxMmap = SQLITE_MAX_MMAP_SIZE;
125419 }
125420 sqlite3GlobalConfig.mxMmap = mxMmap;
 
 
 
 
 
125421 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
125422 if( szMmap>mxMmap) szMmap = mxMmap;
 
125423 sqlite3GlobalConfig.szMmap = szMmap;
125424 break;
125425 }
125426
125427 #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC)
125428 case SQLITE_CONFIG_WIN32_HEAPSIZE: {
 
 
 
125429 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
125430 break;
125431 }
125432 #endif
125433
@@ -125507,19 +126811,29 @@
125507
125508 /*
125509 ** Return the mutex associated with a database connection.
125510 */
125511 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
 
 
 
 
 
 
125512 return db->mutex;
125513 }
125514
125515 /*
125516 ** Free up as much memory as we can from the given database
125517 ** connection.
125518 */
125519 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
125520 int i;
 
 
 
 
125521 sqlite3_mutex_enter(db->mutex);
125522 sqlite3BtreeEnterAll(db);
125523 for(i=0; i<db->nDb; i++){
125524 Btree *pBt = db->aDb[i].pBt;
125525 if( pBt ){
@@ -125605,17 +126919,24 @@
125605 int nKey1, const void *pKey1,
125606 int nKey2, const void *pKey2
125607 ){
125608 int rc, n;
125609 n = nKey1<nKey2 ? nKey1 : nKey2;
 
 
 
125610 rc = memcmp(pKey1, pKey2, n);
125611 if( rc==0 ){
125612 if( padFlag
125613 && allSpaces(((char*)pKey1)+n, nKey1-n)
125614 && allSpaces(((char*)pKey2)+n, nKey2-n)
125615 ){
125616 /* Leave rc unchanged at 0 */
 
 
 
 
125617 }else{
125618 rc = nKey1 - nKey2;
125619 }
125620 }
125621 return rc;
@@ -125646,24 +126967,42 @@
125646
125647 /*
125648 ** Return the ROWID of the most recent insert
125649 */
125650 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
 
 
 
 
 
 
125651 return db->lastRowid;
125652 }
125653
125654 /*
125655 ** Return the number of changes in the most recent call to sqlite3_exec().
125656 */
125657 SQLITE_API int sqlite3_changes(sqlite3 *db){
 
 
 
 
 
 
125658 return db->nChange;
125659 }
125660
125661 /*
125662 ** Return the number of changes since the database handle was opened.
125663 */
125664 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
 
 
 
 
 
 
125665 return db->nTotalChange;
125666 }
125667
125668 /*
125669 ** Close all open savepoints. This function only manipulates fields of the
@@ -125839,10 +127178,20 @@
125839
125840 /* Close all database connections */
125841 for(j=0; j<db->nDb; j++){
125842 struct Db *pDb = &db->aDb[j];
125843 if( pDb->pBt ){
 
 
 
 
 
 
 
 
 
 
125844 sqlite3BtreeClose(pDb->pBt);
125845 pDb->pBt = 0;
125846 if( j!=1 ){
125847 pDb->pSchema = 0;
125848 }
@@ -125925,17 +127274,19 @@
125925 sqlite3_free(db);
125926 }
125927
125928 /*
125929 ** Rollback all database files. If tripCode is not SQLITE_OK, then
125930 ** any open cursors are invalidated ("tripped" - as in "tripping a circuit
125931 ** breaker") and made to return tripCode if there are any further
125932 ** attempts to use that cursor.
 
125933 */
125934 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
125935 int i;
125936 int inTrans = 0;
 
125937 assert( sqlite3_mutex_held(db->mutex) );
125938 sqlite3BeginBenignMalloc();
125939
125940 /* Obtain all b-tree mutexes before making any calls to BtreeRollback().
125941 ** This is important in case the transaction being rolled back has
@@ -125942,18 +127293,19 @@
125942 ** modified the database schema. If the b-tree mutexes are not taken
125943 ** here, then another shared-cache connection might sneak in between
125944 ** the database rollback and schema reset, which can cause false
125945 ** corruption reports in some cases. */
125946 sqlite3BtreeEnterAll(db);
 
125947
125948 for(i=0; i<db->nDb; i++){
125949 Btree *p = db->aDb[i].pBt;
125950 if( p ){
125951 if( sqlite3BtreeIsInTrans(p) ){
125952 inTrans = 1;
125953 }
125954 sqlite3BtreeRollback(p, tripCode);
125955 }
125956 }
125957 sqlite3VtabRollback(db);
125958 sqlite3EndBenignMalloc();
125959
@@ -126205,10 +127557,13 @@
126205 SQLITE_API int sqlite3_busy_handler(
126206 sqlite3 *db,
126207 int (*xBusy)(void*,int),
126208 void *pArg
126209 ){
 
 
 
126210 sqlite3_mutex_enter(db->mutex);
126211 db->busyHandler.xFunc = xBusy;
126212 db->busyHandler.pArg = pArg;
126213 db->busyHandler.nBusy = 0;
126214 db->busyTimeout = 0;
@@ -126226,10 +127581,16 @@
126226 sqlite3 *db,
126227 int nOps,
126228 int (*xProgress)(void*),
126229 void *pArg
126230 ){
 
 
 
 
 
 
126231 sqlite3_mutex_enter(db->mutex);
126232 if( nOps>0 ){
126233 db->xProgress = xProgress;
126234 db->nProgressOps = (unsigned)nOps;
126235 db->pProgressArg = pArg;
@@ -126246,10 +127607,13 @@
126246 /*
126247 ** This routine installs a default busy handler that waits for the
126248 ** specified number of milliseconds before returning 0.
126249 */
126250 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
 
 
 
126251 if( ms>0 ){
126252 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
126253 db->busyTimeout = ms;
126254 }else{
126255 sqlite3_busy_handler(db, 0, 0);
@@ -126259,10 +127623,16 @@
126259
126260 /*
126261 ** Cause any pending operation to stop at its earliest opportunity.
126262 */
126263 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
 
 
 
 
 
 
126264 db->u1.isInterrupted = 1;
126265 }
126266
126267
126268 /*
@@ -126396,10 +127766,16 @@
126396 void (*xFinal)(sqlite3_context*),
126397 void (*xDestroy)(void *)
126398 ){
126399 int rc = SQLITE_ERROR;
126400 FuncDestructor *pArg = 0;
 
 
 
 
 
 
126401 sqlite3_mutex_enter(db->mutex);
126402 if( xDestroy ){
126403 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
126404 if( !pArg ){
126405 xDestroy(p);
@@ -126432,10 +127808,14 @@
126432 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
126433 void (*xFinal)(sqlite3_context*)
126434 ){
126435 int rc;
126436 char *zFunc8;
 
 
 
 
126437 sqlite3_mutex_enter(db->mutex);
126438 assert( !db->mallocFailed );
126439 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
126440 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
126441 sqlite3DbFree(db, zFunc8);
@@ -126463,10 +127843,16 @@
126463 const char *zName,
126464 int nArg
126465 ){
126466 int nName = sqlite3Strlen30(zName);
126467 int rc = SQLITE_OK;
 
 
 
 
 
 
126468 sqlite3_mutex_enter(db->mutex);
126469 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
126470 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
126471 0, sqlite3InvalidFunction, 0, 0, 0);
126472 }
@@ -126484,10 +127870,17 @@
126484 ** trace is a pointer to a function that is invoked at the start of each
126485 ** SQL statement.
126486 */
126487 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
126488 void *pOld;
 
 
 
 
 
 
 
126489 sqlite3_mutex_enter(db->mutex);
126490 pOld = db->pTraceArg;
126491 db->xTrace = xTrace;
126492 db->pTraceArg = pArg;
126493 sqlite3_mutex_leave(db->mutex);
@@ -126505,10 +127898,17 @@
126505 sqlite3 *db,
126506 void (*xProfile)(void*,const char*,sqlite_uint64),
126507 void *pArg
126508 ){
126509 void *pOld;
 
 
 
 
 
 
 
126510 sqlite3_mutex_enter(db->mutex);
126511 pOld = db->pProfileArg;
126512 db->xProfile = xProfile;
126513 db->pProfileArg = pArg;
126514 sqlite3_mutex_leave(db->mutex);
@@ -126525,10 +127925,17 @@
126525 sqlite3 *db, /* Attach the hook to this database */
126526 int (*xCallback)(void*), /* Function to invoke on each commit */
126527 void *pArg /* Argument to the function */
126528 ){
126529 void *pOld;
 
 
 
 
 
 
 
126530 sqlite3_mutex_enter(db->mutex);
126531 pOld = db->pCommitArg;
126532 db->xCommitCallback = xCallback;
126533 db->pCommitArg = pArg;
126534 sqlite3_mutex_leave(db->mutex);
@@ -126543,10 +127950,17 @@
126543 sqlite3 *db, /* Attach the hook to this database */
126544 void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
126545 void *pArg /* Argument to the function */
126546 ){
126547 void *pRet;
 
 
 
 
 
 
 
126548 sqlite3_mutex_enter(db->mutex);
126549 pRet = db->pUpdateArg;
126550 db->xUpdateCallback = xCallback;
126551 db->pUpdateArg = pArg;
126552 sqlite3_mutex_leave(db->mutex);
@@ -126561,10 +127975,17 @@
126561 sqlite3 *db, /* Attach the hook to this database */
126562 void (*xCallback)(void*), /* Callback function */
126563 void *pArg /* Argument to the function */
126564 ){
126565 void *pRet;
 
 
 
 
 
 
 
126566 sqlite3_mutex_enter(db->mutex);
126567 pRet = db->pRollbackArg;
126568 db->xRollbackCallback = xCallback;
126569 db->pRollbackArg = pArg;
126570 sqlite3_mutex_leave(db->mutex);
@@ -126607,10 +128028,13 @@
126607 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
126608 #ifdef SQLITE_OMIT_WAL
126609 UNUSED_PARAMETER(db);
126610 UNUSED_PARAMETER(nFrame);
126611 #else
 
 
 
126612 if( nFrame>0 ){
126613 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
126614 }else{
126615 sqlite3_wal_hook(db, 0, 0);
126616 }
@@ -126627,10 +128051,16 @@
126627 int(*xCallback)(void *, sqlite3*, const char*, int),
126628 void *pArg /* First argument passed to xCallback() */
126629 ){
126630 #ifndef SQLITE_OMIT_WAL
126631 void *pRet;
 
 
 
 
 
 
126632 sqlite3_mutex_enter(db->mutex);
126633 pRet = db->pWalArg;
126634 db->xWalCallback = xCallback;
126635 db->pWalArg = pArg;
126636 sqlite3_mutex_leave(db->mutex);
@@ -126653,19 +128083,26 @@
126653 #ifdef SQLITE_OMIT_WAL
126654 return SQLITE_OK;
126655 #else
126656 int rc; /* Return code */
126657 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
 
 
 
 
126658
126659 /* Initialize the output variables to -1 in case an error occurs. */
126660 if( pnLog ) *pnLog = -1;
126661 if( pnCkpt ) *pnCkpt = -1;
126662
126663 assert( SQLITE_CHECKPOINT_FULL>SQLITE_CHECKPOINT_PASSIVE );
126664 assert( SQLITE_CHECKPOINT_FULL<SQLITE_CHECKPOINT_RESTART );
126665 assert( SQLITE_CHECKPOINT_PASSIVE+2==SQLITE_CHECKPOINT_RESTART );
126666 if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_RESTART ){
 
 
 
126667 return SQLITE_MISUSE;
126668 }
126669
126670 sqlite3_mutex_enter(db->mutex);
126671 if( zDb && zDb[0] ){
@@ -126689,11 +128126,13 @@
126689 ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
126690 ** to contains a zero-length string, all attached databases are
126691 ** checkpointed.
126692 */
126693 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
126694 return sqlite3_wal_checkpoint_v2(db, zDb, SQLITE_CHECKPOINT_PASSIVE, 0, 0);
 
 
126695 }
126696
126697 #ifndef SQLITE_OMIT_WAL
126698 /*
126699 ** Run a checkpoint on database iDb. This is a no-op if database iDb is
@@ -127050,10 +128489,16 @@
127050 ** from forming.
127051 */
127052 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
127053 int oldLimit;
127054
 
 
 
 
 
 
127055
127056 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
127057 ** there is a hard upper bound set at compile-time by a C preprocessor
127058 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
127059 ** "_MAX_".)
@@ -127126,11 +128571,12 @@
127126 char c;
127127 int nUri = sqlite3Strlen30(zUri);
127128
127129 assert( *pzErrMsg==0 );
127130
127131 if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri)
 
127132 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
127133 ){
127134 char *zOpt;
127135 int eState; /* Parser state when parsing URI */
127136 int iIn; /* Input character index */
@@ -127335,10 +128781,13 @@
127335 int rc; /* Return code */
127336 int isThreadsafe; /* True for threadsafe connections */
127337 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
127338 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
127339
 
 
 
127340 *ppDb = 0;
127341 #ifndef SQLITE_OMIT_AUTOINIT
127342 rc = sqlite3_initialize();
127343 if( rc ) return rc;
127344 #endif
@@ -127440,33 +128889,40 @@
127440 | SQLITE_RecTriggers
127441 #endif
127442 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
127443 | SQLITE_ForeignKeys
127444 #endif
 
 
 
127445 ;
127446 sqlite3HashInit(&db->aCollSeq);
127447 #ifndef SQLITE_OMIT_VIRTUALTABLE
127448 sqlite3HashInit(&db->aModule);
127449 #endif
127450
127451 /* Add the default collation sequence BINARY. BINARY works for both UTF-8
127452 ** and UTF-16, so add a version for each to avoid any unnecessary
127453 ** conversions. The only error that can occur here is a malloc() failure.
 
 
 
127454 */
127455 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
127456 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
127457 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
 
127458 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
127459 if( db->mallocFailed ){
127460 goto opendb_out;
127461 }
 
 
 
127462 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
127463 assert( db->pDfltColl!=0 );
127464
127465 /* Also add a UTF-8 case-insensitive collation sequence. */
127466 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
127467
127468 /* Parse the filename/URI argument. */
127469 db->openFlags = flags;
127470 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
127471 if( rc!=SQLITE_OK ){
127472 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -127483,11 +128939,13 @@
127483 rc = SQLITE_NOMEM;
127484 }
127485 sqlite3Error(db, rc);
127486 goto opendb_out;
127487 }
 
127488 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
 
127489 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
127490
127491 /* The default safety_level for the main database is 'full'; for the temp
127492 ** database it is 'NONE'. This matches the pager layer defaults.
127493 */
@@ -127624,17 +129082,19 @@
127624 ){
127625 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
127626 sqlite3_value *pVal;
127627 int rc;
127628
127629 assert( zFilename );
127630 assert( ppDb );
 
127631 *ppDb = 0;
127632 #ifndef SQLITE_OMIT_AUTOINIT
127633 rc = sqlite3_initialize();
127634 if( rc ) return rc;
127635 #endif
 
127636 pVal = sqlite3ValueNew(0);
127637 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
127638 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
127639 if( zFilename8 ){
127640 rc = openDatabase(zFilename8, ppDb,
@@ -127660,17 +129120,11 @@
127660 const char *zName,
127661 int enc,
127662 void* pCtx,
127663 int(*xCompare)(void*,int,const void*,int,const void*)
127664 ){
127665 int rc;
127666 sqlite3_mutex_enter(db->mutex);
127667 assert( !db->mallocFailed );
127668 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
127669 rc = sqlite3ApiExit(db, rc);
127670 sqlite3_mutex_leave(db->mutex);
127671 return rc;
127672 }
127673
127674 /*
127675 ** Register a new collation sequence with the database handle db.
127676 */
@@ -127681,10 +129135,14 @@
127681 void* pCtx,
127682 int(*xCompare)(void*,int,const void*,int,const void*),
127683 void(*xDel)(void*)
127684 ){
127685 int rc;
 
 
 
 
127686 sqlite3_mutex_enter(db->mutex);
127687 assert( !db->mallocFailed );
127688 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
127689 rc = sqlite3ApiExit(db, rc);
127690 sqlite3_mutex_leave(db->mutex);
@@ -127702,10 +129160,14 @@
127702 void* pCtx,
127703 int(*xCompare)(void*,int,const void*,int,const void*)
127704 ){
127705 int rc = SQLITE_OK;
127706 char *zName8;
 
 
 
 
127707 sqlite3_mutex_enter(db->mutex);
127708 assert( !db->mallocFailed );
127709 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
127710 if( zName8 ){
127711 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -127724,10 +129186,13 @@
127724 SQLITE_API int sqlite3_collation_needed(
127725 sqlite3 *db,
127726 void *pCollNeededArg,
127727 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
127728 ){
 
 
 
127729 sqlite3_mutex_enter(db->mutex);
127730 db->xCollNeeded = xCollNeeded;
127731 db->xCollNeeded16 = 0;
127732 db->pCollNeededArg = pCollNeededArg;
127733 sqlite3_mutex_leave(db->mutex);
@@ -127742,10 +129207,13 @@
127742 SQLITE_API int sqlite3_collation_needed16(
127743 sqlite3 *db,
127744 void *pCollNeededArg,
127745 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
127746 ){
 
 
 
127747 sqlite3_mutex_enter(db->mutex);
127748 db->xCollNeeded = 0;
127749 db->xCollNeeded16 = xCollNeeded16;
127750 db->pCollNeededArg = pCollNeededArg;
127751 sqlite3_mutex_leave(db->mutex);
@@ -127768,10 +129236,16 @@
127768 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
127769 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
127770 ** by the next COMMIT or ROLLBACK.
127771 */
127772 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
 
 
 
 
 
 
127773 return db->autoCommit;
127774 }
127775
127776 /*
127777 ** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -127821,11 +129295,10 @@
127821
127822 /*
127823 ** Return meta information about a specific column of a database table.
127824 ** See comment in sqlite3.h (sqlite.h.in) for details.
127825 */
127826 #ifdef SQLITE_ENABLE_COLUMN_METADATA
127827 SQLITE_API int sqlite3_table_column_metadata(
127828 sqlite3 *db, /* Connection handle */
127829 const char *zDbName, /* Database name or NULL */
127830 const char *zTableName, /* Table name */
127831 const char *zColumnName, /* Column name */
@@ -127861,25 +129334,27 @@
127861 pTab = 0;
127862 goto error_out;
127863 }
127864
127865 /* Find the column for which info is requested */
127866 if( sqlite3IsRowid(zColumnName) ){
127867 iCol = pTab->iPKey;
127868 if( iCol>=0 ){
127869 pCol = &pTab->aCol[iCol];
127870 }
127871 }else{
127872 for(iCol=0; iCol<pTab->nCol; iCol++){
127873 pCol = &pTab->aCol[iCol];
127874 if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
127875 break;
127876 }
127877 }
127878 if( iCol==pTab->nCol ){
127879 pTab = 0;
127880 goto error_out;
 
 
 
 
 
127881 }
127882 }
127883
127884 /* The following block stores the meta information that will be returned
127885 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
@@ -127928,11 +129403,10 @@
127928 sqlite3DbFree(db, zErrMsg);
127929 rc = sqlite3ApiExit(db, rc);
127930 sqlite3_mutex_leave(db->mutex);
127931 return rc;
127932 }
127933 #endif
127934
127935 /*
127936 ** Sleep for a little while. Return the amount of time slept.
127937 */
127938 SQLITE_API int sqlite3_sleep(int ms){
@@ -127950,10 +129424,13 @@
127950
127951 /*
127952 ** Enable or disable the extended result codes.
127953 */
127954 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
 
 
 
127955 sqlite3_mutex_enter(db->mutex);
127956 db->errMask = onoff ? 0xffffffff : 0xff;
127957 sqlite3_mutex_leave(db->mutex);
127958 return SQLITE_OK;
127959 }
@@ -127963,10 +129440,13 @@
127963 */
127964 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
127965 int rc = SQLITE_ERROR;
127966 Btree *pBtree;
127967
 
 
 
127968 sqlite3_mutex_enter(db->mutex);
127969 pBtree = sqlite3DbNameToBtree(db, zDbName);
127970 if( pBtree ){
127971 Pager *pPager;
127972 sqlite3_file *fd;
@@ -128305,11 +129785,11 @@
128305 ** query parameter we seek. This routine returns the value of the zParam
128306 ** parameter if it exists. If the parameter does not exist, this routine
128307 ** returns a NULL pointer.
128308 */
128309 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
128310 if( zFilename==0 ) return 0;
128311 zFilename += sqlite3Strlen30(zFilename) + 1;
128312 while( zFilename[0] ){
128313 int x = strcmp(zFilename, zParam);
128314 zFilename += sqlite3Strlen30(zFilename) + 1;
128315 if( x==0 ) return zFilename;
@@ -128361,19 +129841,31 @@
128361 /*
128362 ** Return the filename of the database associated with a database
128363 ** connection.
128364 */
128365 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
 
 
 
 
 
 
128366 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128367 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
128368 }
128369
128370 /*
128371 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
128372 ** no such database exists.
128373 */
128374 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
 
 
 
 
 
 
128375 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
128376 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
128377 }
128378
128379 /************** End of main.c ************************************************/
@@ -137791,11 +139283,11 @@
137791 ** Return true if the m-value for z is 1 or more. In other words,
137792 ** return true if z contains at least one vowel that is followed
137793 ** by a consonant.
137794 **
137795 ** In this routine z[] is in reverse order. So we are really looking
137796 ** for an instance of of a consonant followed by a vowel.
137797 */
137798 static int m_gt_0(const char *z){
137799 while( isVowel(z) ){ z++; }
137800 if( *z==0 ) return 0;
137801 while( isConsonant(z) ){ z++; }
137802
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.8. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -179,11 +179,11 @@
179
180
181 /*
182 ** These no-op macros are used in front of interfaces to mark those
183 ** interfaces as either deprecated or experimental. New applications
184 ** should not use deprecated interfaces - they are supported for backwards
185 ** compatibility only. Application writers should be aware that
186 ** experimental interfaces are subject to change in point releases.
187 **
188 ** These macros used to resolve to various kinds of compiler magic that
189 ** would generate warning messages when they were used. But that
@@ -229,13 +229,13 @@
229 **
230 ** See also: [sqlite3_libversion()],
231 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
232 ** [sqlite_version()] and [sqlite_source_id()].
233 */
234 #define SQLITE_VERSION "3.8.8"
235 #define SQLITE_VERSION_NUMBER 3008008
236 #define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
237
238 /*
239 ** CAPI3REF: Run-Time Library Version Numbers
240 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
241 **
@@ -1343,11 +1343,11 @@
1343 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1344 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1345 ** </ul>
1346 **
1347 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1348 ** was given on the corresponding lock.
1349 **
1350 ** The xShmLock method can transition between unlocked and SHARED or
1351 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1352 ** and EXCLUSIVE.
1353 */
@@ -1626,30 +1626,32 @@
1626 ** it is not possible to set the Serialized [threading mode] and
1627 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1628 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1629 **
1630 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1631 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1632 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1633 ** The argument specifies
1634 ** alternative low-level memory allocation routines to be used in place of
1635 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1636 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1637 ** before the [sqlite3_config()] call returns.</dd>
1638 **
1639 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1640 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1641 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1642 ** The [sqlite3_mem_methods]
1643 ** structure is filled with the currently defined memory allocation routines.)^
1644 ** This option can be used to overload the default memory allocation
1645 ** routines with a wrapper that simulations memory allocation failure or
1646 ** tracks memory usage, for example. </dd>
1647 **
1648 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1649 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1650 ** interpreted as a boolean, which enables or disables the collection of
1651 ** memory allocation statistics. ^(When memory allocation statistics are
1652 ** disabled, the following SQLite interfaces become non-operational:
1653 ** <ul>
1654 ** <li> [sqlite3_memory_used()]
1655 ** <li> [sqlite3_memory_highwater()]
1656 ** <li> [sqlite3_soft_heap_limit64()]
1657 ** <li> [sqlite3_status()]
@@ -1658,78 +1660,92 @@
1660 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1661 ** allocation statistics are disabled by default.
1662 ** </dd>
1663 **
1664 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1665 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1666 ** that SQLite can use for scratch memory. ^(There are three arguments
1667 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1668 ** aligned memory buffer from which the scratch allocations will be
1669 ** drawn, the size of each scratch allocation (sz),
1670 ** and the maximum number of scratch allocations (N).)^
 
1671 ** The first argument must be a pointer to an 8-byte aligned buffer
1672 ** of at least sz*N bytes of memory.
1673 ** ^SQLite will not use more than one scratch buffers per thread.
1674 ** ^SQLite will never request a scratch buffer that is more than 6
1675 ** times the database page size.
1676 ** ^If SQLite needs needs additional
1677 ** scratch memory beyond what is provided by this configuration option, then
1678 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1679 ** ^When the application provides any amount of scratch memory using
1680 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1681 ** [sqlite3_malloc|heap allocations].
1682 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1683 ** fragmentation in low-memory embedded systems.
1684 ** </dd>
1685 **
1686 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1687 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1688 ** that SQLite can use for the database page cache with the default page
1689 ** cache implementation.
1690 ** This configuration should not be used if an application-define page
1691 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1692 ** configuration option.
1693 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1694 ** 8-byte aligned
1695 ** memory, the size of each page buffer (sz), and the number of pages (N).
1696 ** The sz argument should be the size of the largest database page
1697 ** (a power of two between 512 and 32768) plus some extra bytes for each
1698 ** page header. ^The number of extra bytes needed by the page header
1699 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1700 ** to [sqlite3_config()].
1701 ** ^It is harmless, apart from the wasted memory,
1702 ** for the sz parameter to be larger than necessary. The first
1703 ** argument should pointer to an 8-byte aligned block of memory that
1704 ** is at least sz*N bytes of memory, otherwise subsequent behavior is
1705 ** undefined.
1706 ** ^SQLite will use the memory provided by the first argument to satisfy its
1707 ** memory needs for the first N pages that it adds to cache. ^If additional
1708 ** page cache memory is needed beyond what is provided by this option, then
1709 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
 
 
 
1710 **
1711 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1712 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1713 ** that SQLite will use for all of its dynamic memory allocation needs
1714 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1715 ** [SQLITE_CONFIG_PAGECACHE].
1716 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1717 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1718 ** [SQLITE_ERROR] if invoked otherwise.
1719 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1720 ** An 8-byte aligned pointer to the memory,
1721 ** the number of bytes in the memory buffer, and the minimum allocation size.
1722 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1723 ** to using its default memory allocator (the system malloc() implementation),
1724 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1725 ** memory pointer is not NULL then the alternative memory
 
1726 ** allocator is engaged to handle all of SQLites memory allocation needs.
1727 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1728 ** boundary or subsequent behavior of SQLite will be undefined.
1729 ** The minimum allocation size is capped at 2**12. Reasonable values
1730 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1731 **
1732 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1733 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1734 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1735 ** The argument specifies alternative low-level mutex routines to be used
1736 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1737 ** the content of the [sqlite3_mutex_methods] structure before the call to
1738 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1739 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1740 ** the entire mutexing subsystem is omitted from the build and hence calls to
1741 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1742 ** return [SQLITE_ERROR].</dd>
1743 **
1744 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1745 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1746 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1747 ** [sqlite3_mutex_methods]
1748 ** structure is filled with the currently defined mutex routines.)^
1749 ** This option can be used to overload the default mutex allocation
1750 ** routines with a wrapper used to track mutex usage for performance
1751 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1737,29 +1753,29 @@
1753 ** the entire mutexing subsystem is omitted from the build and hence calls to
1754 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1755 ** return [SQLITE_ERROR].</dd>
1756 **
1757 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1758 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1759 ** the default size of lookaside memory on each [database connection].
1760 ** The first argument is the
1761 ** size of each lookaside buffer slot and the second is the number of
1762 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1763 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1764 ** option to [sqlite3_db_config()] can be used to change the lookaside
1765 ** configuration on individual connections.)^ </dd>
1766 **
1767 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1768 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1769 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1770 ** the interface to a custom page cache implementation.)^
1771 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1772 **
1773 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1774 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1775 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
1776 ** the current page cache implementation into that object.)^ </dd>
1777 **
1778 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1779 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1780 ** global [error log].
1781 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1778,26 +1794,28 @@
1794 ** supplied by the application must not invoke any SQLite interface.
1795 ** In a multi-threaded application, the application-defined logger
1796 ** function must be threadsafe. </dd>
1797 **
1798 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1799 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1800 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1801 ** then URI handling is globally disabled.)^ ^If URI handling is globally
1802 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1803 ** [sqlite3_open16()] or
1804 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1805 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1806 ** connection is opened. ^If it is globally disabled, filenames are
1807 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1808 ** database connection is opened. ^(By default, URI handling is globally
1809 ** disabled. The default value may be changed by compiling with the
1810 ** [SQLITE_USE_URI] symbol defined.)^
1811 **
1812 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1813 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1814 ** argument which is interpreted as a boolean in order to enable or disable
1815 ** the use of covering indices for full table scans in the query optimizer.
1816 ** ^The default setting is determined
1817 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1818 ** if that compile-time option is omitted.
1819 ** The ability to disable the use of covering indices for full table scans
1820 ** is because some incorrectly coded legacy applications might malfunction
1821 ** when the optimization is enabled. Providing the ability to
@@ -1833,23 +1851,32 @@
1851 ** that are the default mmap size limit (the default setting for
1852 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1853 ** ^The default setting can be overridden by each database connection using
1854 ** either the [PRAGMA mmap_size] command, or by using the
1855 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1856 ** will be silently truncated if necessary so that it does not exceed the
1857 ** compile-time maximum mmap size set by the
1858 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1859 ** ^If either argument to this option is negative, then that argument is
1860 ** changed to its compile-time default.
1861 **
1862 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1863 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1864 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1865 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1866 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1867 ** that specifies the maximum size of the created heap.
1868 ** </dl>
1869 **
1870 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1871 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1872 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1873 ** is a pointer to an integer and writes into that integer the number of extra
1874 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1875 ** The amount of extra space required can change depending on the compiler,
1876 ** target platform, and SQLite version.
1877 ** </dl>
1878 */
1879 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1880 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1881 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1882 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1870,10 +1897,11 @@
1897 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1898 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1899 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1900 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1901 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1902 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1903
1904 /*
1905 ** CAPI3REF: Database Connection Configuration Options
1906 **
1907 ** These constants are the available integer configuration options that
@@ -1997,51 +2025,49 @@
2025 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
2026
2027 /*
2028 ** CAPI3REF: Count The Number Of Rows Modified
2029 **
2030 ** ^This function returns the number of rows modified, inserted or
2031 ** deleted by the most recently completed INSERT, UPDATE or DELETE
2032 ** statement on the database connection specified by the only parameter.
2033 ** ^Executing any other type of SQL statement does not modify the value
2034 ** returned by this function.
2035 **
2036 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
2037 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
2038 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
2039 **
2040 ** Changes to a view that are intercepted by
2041 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
2042 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
2043 ** DELETE statement run on a view is always zero. Only changes made to real
2044 ** tables are counted.
2045 **
2046 ** Things are more complicated if the sqlite3_changes() function is
2047 ** executed while a trigger program is running. This may happen if the
2048 ** program uses the [changes() SQL function], or if some other callback
2049 ** function invokes sqlite3_changes() directly. Essentially:
2050 **
2051 ** <ul>
2052 ** <li> ^(Before entering a trigger program the value returned by
2053 ** sqlite3_changes() function is saved. After the trigger program
2054 ** has finished, the original value is restored.)^
2055 **
2056 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
2057 ** statement sets the value returned by sqlite3_changes()
2058 ** upon completion as normal. Of course, this value will not include
2059 ** any changes performed by sub-triggers, as the sqlite3_changes()
2060 ** value will be saved and restored after each sub-trigger has run.)^
2061 ** </ul>
2062 **
2063 ** ^This means that if the changes() SQL function (or similar) is used
2064 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
2065 ** returns the value as set when the calling statement began executing.
2066 ** ^If it is used by the second or subsequent such statement within a trigger
2067 ** program, the value returned reflects the number of rows modified by the
2068 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
 
 
2069 **
2070 ** See also the [sqlite3_total_changes()] interface, the
2071 ** [count_changes pragma], and the [changes() SQL function].
2072 **
2073 ** If a separate thread makes changes on the same database connection
@@ -2051,24 +2077,21 @@
2077 SQLITE_API int sqlite3_changes(sqlite3*);
2078
2079 /*
2080 ** CAPI3REF: Total Number Of Rows Modified
2081 **
2082 ** ^This function returns the total number of rows inserted, modified or
2083 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
2084 ** since the database connection was opened, including those executed as
2085 ** part of trigger programs. ^Executing any other type of SQL statement
2086 ** does not affect the value returned by sqlite3_total_changes().
2087 **
2088 ** ^Changes made as part of [foreign key actions] are included in the
2089 ** count, but those made as part of REPLACE constraint resolution are
2090 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
2091 ** are not counted.
2092 **
 
 
 
2093 ** See also the [sqlite3_changes()] interface, the
2094 ** [count_changes pragma], and the [total_changes() SQL function].
2095 **
2096 ** If a separate thread makes changes on the same database connection
2097 ** while [sqlite3_total_changes()] is running then the value
@@ -2151,10 +2174,11 @@
2174 SQLITE_API int sqlite3_complete(const char *sql);
2175 SQLITE_API int sqlite3_complete16(const void *sql);
2176
2177 /*
2178 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2179 ** KEYWORDS: {busy-handler callback} {busy handler}
2180 **
2181 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2182 ** that might be invoked with argument P whenever
2183 ** an attempt is made to access a database table associated with
2184 ** [database connection] D when another thread
@@ -2167,11 +2191,11 @@
2191 ** is not NULL, then the callback might be invoked with two arguments.
2192 **
2193 ** ^The first argument to the busy handler is a copy of the void* pointer which
2194 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2195 ** the busy handler callback is the number of times that the busy handler has
2196 ** been invoked previously for the same locking event. ^If the
2197 ** busy callback returns 0, then no additional attempts are made to
2198 ** access the database and [SQLITE_BUSY] is returned
2199 ** to the application.
2200 ** ^If the callback returns non-zero, then another attempt
2201 ** is made to access the database and the cycle repeats.
@@ -2542,17 +2566,18 @@
2566 ** already uses the largest possible [ROWID]. The PRNG is also used for
2567 ** the build-in random() and randomblob() SQL functions. This interface allows
2568 ** applications to access the same PRNG for other purposes.
2569 **
2570 ** ^A call to this routine stores N bytes of randomness into buffer P.
2571 ** ^The P parameter can be a NULL pointer.
2572 **
2573 ** ^If this routine has not been previously called or if the previous
2574 ** call had N less than one or a NULL pointer for P, then the PRNG is
2575 ** seeded using randomness obtained from the xRandomness method of
2576 ** the default [sqlite3_vfs] object.
2577 ** ^If the previous call to this routine had an N of 1 or more and a
2578 ** non-NULL P then the pseudo-randomness is generated
2579 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2580 ** method.
2581 */
2582 SQLITE_API void sqlite3_randomness(int N, void *P);
2583
@@ -4270,13 +4295,13 @@
4295 ** CAPI3REF: Text Encodings
4296 **
4297 ** These constant define integer codes that represent the various
4298 ** text encodings supported by SQLite.
4299 */
4300 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
4301 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
4302 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
4303 #define SQLITE_UTF16 4 /* Use native byte order */
4304 #define SQLITE_ANY 5 /* Deprecated */
4305 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4306
4307 /*
@@ -4621,11 +4646,12 @@
4646 ** If these routines are called from within the different thread
4647 ** than the one containing the application-defined function that received
4648 ** the [sqlite3_context] pointer, the results are undefined.
4649 */
4650 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4651 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
4652 sqlite3_uint64,void(*)(void*));
4653 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4654 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4655 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4656 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4657 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5253,24 +5279,31 @@
5279
5280
5281 /*
5282 ** CAPI3REF: Extract Metadata About A Column Of A Table
5283 **
5284 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5285 ** information about column C of table T in database D
5286 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5287 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
5288 ** the final five arguments with appropriate values if the specified
5289 ** column exists. ^The sqlite3_table_column_metadata() interface returns
5290 ** SQLITE_ERROR and if the specified column does not exist.
5291 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
5292 ** NULL pointer, then this routine simply checks for the existance of the
5293 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5294 ** does not.
5295 **
5296 ** ^The column is identified by the second, third and fourth parameters to
5297 ** this function. ^(The second parameter is either the name of the database
5298 ** (i.e. "main", "temp", or an attached database) containing the specified
5299 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
5300 ** for the table using the same algorithm used by the database engine to
5301 ** resolve unqualified table references.
5302 **
5303 ** ^The third and fourth parameters to this function are the table and column
5304 ** name of the desired column, respectively.
 
5305 **
5306 ** ^Metadata is returned by writing to the memory locations passed as the 5th
5307 ** and subsequent parameters to this function. ^Any of these arguments may be
5308 ** NULL, in which case the corresponding element of metadata is omitted.
5309 **
@@ -5285,36 +5318,33 @@
5318 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5319 ** </table>
5320 ** </blockquote>)^
5321 **
5322 ** ^The memory pointed to by the character pointers returned for the
5323 ** declaration type and collation sequence is valid until the next
5324 ** call to any SQLite API function.
5325 **
5326 ** ^If the specified table is actually a view, an [error code] is returned.
5327 **
5328 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5329 ** is not a [WITHOUT ROWID] table and an
5330 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5331 ** parameters are set for the explicitly declared column. ^(If there is no
5332 ** [INTEGER PRIMARY KEY] column, then the outputs
5333 ** for the [rowid] are set as follows:
5334 **
5335 ** <pre>
5336 ** data type: "INTEGER"
5337 ** collation sequence: "BINARY"
5338 ** not null: 0
5339 ** primary key: 1
5340 ** auto increment: 0
5341 ** </pre>)^
5342 **
5343 ** ^This function causes all database schemas to be read from disk and
5344 ** parsed, if that has not already been done, and returns an error if
5345 ** any errors are encountered while loading the schema.
 
 
 
 
5346 */
5347 SQLITE_API int sqlite3_table_column_metadata(
5348 sqlite3 *db, /* Connection handle */
5349 const char *zDbName, /* Database name or NULL */
5350 const char *zTableName, /* Table name */
@@ -5762,31 +5792,47 @@
5792 ** in other words, the same BLOB that would be selected by:
5793 **
5794 ** <pre>
5795 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5796 ** </pre>)^
5797 **
5798 ** ^(Parameter zDb is not the filename that contains the database, but
5799 ** rather the symbolic name of the database. For attached databases, this is
5800 ** the name that appears after the AS keyword in the [ATTACH] statement.
5801 ** For the main database file, the database name is "main". For TEMP
5802 ** tables, the database name is "temp".)^
5803 **
5804 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5805 ** and write access. ^If the flags parameter is zero, the BLOB is opened for
5806 ** read-only access.
5807 **
5808 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5809 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5810 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5811 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5812 ** on *ppBlob after this function it returns.
5813 **
5814 ** This function fails with SQLITE_ERROR if any of the following are true:
5815 ** <ul>
5816 ** <li> ^(Database zDb does not exist)^,
5817 ** <li> ^(Table zTable does not exist within database zDb)^,
5818 ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5819 ** <li> ^(Column zColumn does not exist)^,
5820 ** <li> ^(Row iRow is not present in the table)^,
5821 ** <li> ^(The specified column of row iRow contains a value that is not
5822 ** a TEXT or BLOB value)^,
5823 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5824 ** constraint and the blob is being opened for read/write access)^,
5825 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5826 ** column zColumn is part of a [child key] definition and the blob is
5827 ** being opened for read/write access)^.
5828 ** </ul>
5829 **
5830 ** ^Unless it returns SQLITE_MISUSE, this function sets the
5831 ** [database connection] error code and message accessible via
5832 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5833 **
5834 **
5835 ** ^(If the row that a BLOB handle points to is modified by an
5836 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5837 ** then the BLOB handle is marked as "expired".
5838 ** This is true if any column of the row is changed, even a column
@@ -5800,17 +5846,13 @@
5846 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5847 ** the opened blob. ^The size of a blob may not be changed by this
5848 ** interface. Use the [UPDATE] SQL command to change the size of a
5849 ** blob.
5850 **
 
 
 
5851 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5852 ** and the built-in [zeroblob] SQL function may be used to create a
5853 ** zero-filled blob to read or write using the incremental-blob interface.
 
5854 **
5855 ** To avoid a resource leak, every open [BLOB handle] should eventually
5856 ** be released by a call to [sqlite3_blob_close()].
5857 */
5858 SQLITE_API int sqlite3_blob_open(
@@ -5848,28 +5890,26 @@
5890 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5891
5892 /*
5893 ** CAPI3REF: Close A BLOB Handle
5894 **
5895 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5896 ** unconditionally. Even if this routine returns an error code, the
5897 ** handle is still closed.)^
5898 **
5899 ** ^If the blob handle being closed was opened for read-write access, and if
5900 ** the database is in auto-commit mode and there are no other open read-write
5901 ** blob handles or active write statements, the current transaction is
5902 ** committed. ^If an error occurs while committing the transaction, an error
5903 ** code is returned and the transaction rolled back.
5904 **
5905 ** Calling this function with an argument that is not a NULL pointer or an
5906 ** open blob handle results in undefined behaviour. ^Calling this routine
5907 ** with a null pointer (such as would be returned by a failed call to
5908 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5909 ** is passed a valid open blob handle, the values returned by the
5910 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 
 
5911 */
5912 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5913
5914 /*
5915 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5915,36 +5955,39 @@
5955 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5956
5957 /*
5958 ** CAPI3REF: Write Data Into A BLOB Incrementally
5959 **
5960 ** ^(This function is used to write data into an open [BLOB handle] from a
5961 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5962 ** into the open BLOB, starting at offset iOffset.)^
5963 **
5964 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5965 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5966 ** ^Unless SQLITE_MISUSE is returned, this function sets the
5967 ** [database connection] error code and message accessible via
5968 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5969 **
5970 ** ^If the [BLOB handle] passed as the first argument was not opened for
5971 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5972 ** this function returns [SQLITE_READONLY].
5973 **
5974 ** This function may only modify the contents of the BLOB; it is
5975 ** not possible to increase the size of a BLOB using this API.
5976 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5977 ** [SQLITE_ERROR] is returned and no data is written. The size of the
5978 ** BLOB (and hence the maximum value of N+iOffset) can be determined
5979 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5980 ** than zero [SQLITE_ERROR] is returned and no data is written.
5981 **
5982 ** ^An attempt to write to an expired [BLOB handle] fails with an
5983 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5984 ** before the [BLOB handle] expired are not rolled back by the
5985 ** expiration of the handle, though of course those changes might
5986 ** have been overwritten by the statement that expired the BLOB handle
5987 ** or by other independent statements.
5988 **
 
 
 
5989 ** This routine only works on a [BLOB handle] which has been created
5990 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5991 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5992 ** to this routine results in undefined and probably undesirable behavior.
5993 **
@@ -5993,38 +6036,38 @@
6036 ** use by SQLite, code that links against SQLite is
6037 ** permitted to use any of these routines.
6038 **
6039 ** The SQLite source code contains multiple implementations
6040 ** of these mutex routines. An appropriate implementation
6041 ** is selected automatically at compile-time. The following
6042 ** implementations are available in the SQLite core:
6043 **
6044 ** <ul>
6045 ** <li> SQLITE_MUTEX_PTHREADS
6046 ** <li> SQLITE_MUTEX_W32
6047 ** <li> SQLITE_MUTEX_NOOP
6048 ** </ul>
6049 **
6050 ** The SQLITE_MUTEX_NOOP implementation is a set of routines
6051 ** that does no real locking and is appropriate for use in
6052 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
6053 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
6054 ** and Windows.
6055 **
6056 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
6057 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
6058 ** implementation is included with the library. In this case the
6059 ** application must supply a custom mutex implementation using the
6060 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
6061 ** before calling sqlite3_initialize() or any other public sqlite3_
6062 ** function that calls sqlite3_initialize().
6063 **
6064 ** ^The sqlite3_mutex_alloc() routine allocates a new
6065 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
6066 ** routine returns NULL if it is unable to allocate the requested
6067 ** mutex. The argument to sqlite3_mutex_alloc() must one of these
6068 ** integer constants:
6069 **
6070 ** <ul>
6071 ** <li> SQLITE_MUTEX_FAST
6072 ** <li> SQLITE_MUTEX_RECURSIVE
6073 ** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -6033,68 +6076,64 @@
6076 ** <li> SQLITE_MUTEX_STATIC_PRNG
6077 ** <li> SQLITE_MUTEX_STATIC_LRU
6078 ** <li> SQLITE_MUTEX_STATIC_PMEM
6079 ** <li> SQLITE_MUTEX_STATIC_APP1
6080 ** <li> SQLITE_MUTEX_STATIC_APP2
6081 ** <li> SQLITE_MUTEX_STATIC_APP3
6082 ** </ul>
6083 **
6084 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
6085 ** cause sqlite3_mutex_alloc() to create
6086 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
6087 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
6088 ** The mutex implementation does not need to make a distinction
6089 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
6090 ** not want to. SQLite will only request a recursive mutex in
6091 ** cases where it really needs one. If a faster non-recursive mutex
6092 ** implementation is available on the host platform, the mutex subsystem
6093 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
6094 **
6095 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
6096 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
6097 ** a pointer to a static preexisting mutex. ^Nine static mutexes are
6098 ** used by the current version of SQLite. Future versions of SQLite
6099 ** may add additional static mutexes. Static mutexes are for internal
6100 ** use by SQLite only. Applications that use SQLite mutexes should
6101 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
6102 ** SQLITE_MUTEX_RECURSIVE.
6103 **
6104 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
6105 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
6106 ** returns a different mutex on every call. ^For the static
6107 ** mutex types, the same mutex is returned on every call that has
6108 ** the same type number.
6109 **
6110 ** ^The sqlite3_mutex_free() routine deallocates a previously
6111 ** allocated dynamic mutex. Attempting to deallocate a static
6112 ** mutex results in undefined behavior.
 
 
 
6113 **
6114 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
6115 ** to enter a mutex. ^If another thread is already within the mutex,
6116 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
6117 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
6118 ** upon successful entry. ^(Mutexes created using
6119 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
6120 ** In such cases, the
6121 ** mutex must be exited an equal number of times before another thread
6122 ** can enter.)^ If the same thread tries to enter any mutex other
6123 ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
 
 
6124 **
6125 ** ^(Some systems (for example, Windows 95) do not support the operation
6126 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
6127 ** will always return SQLITE_BUSY. The SQLite core only ever uses
6128 ** sqlite3_mutex_try() as an optimization so this is acceptable
6129 ** behavior.)^
6130 **
6131 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
6132 ** previously entered by the same thread. The behavior
6133 ** is undefined if the mutex is not currently entered by the
6134 ** calling thread or is not currently allocated.
 
6135 **
6136 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
6137 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
6138 ** behave as no-ops.
6139 **
@@ -6111,13 +6150,13 @@
6150 **
6151 ** An instance of this structure defines the low-level routines
6152 ** used to allocate and use mutexes.
6153 **
6154 ** Usually, the default mutex implementations provided by SQLite are
6155 ** sufficient, however the application has the option of substituting a custom
6156 ** implementation for specialized deployments or systems for which SQLite
6157 ** does not provide a suitable implementation. In this case, the application
6158 ** creates and populates an instance of this structure to pass
6159 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
6160 ** Additionally, an instance of this structure can be used as an
6161 ** output variable when querying the system for the current mutex
6162 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6154,17 +6193,17 @@
6193 ** by this structure are not required to handle this case, the results
6194 ** of passing a NULL pointer instead of a valid mutex handle are undefined
6195 ** (i.e. it is acceptable to provide an implementation that segfaults if
6196 ** it is passed a NULL pointer).
6197 **
6198 ** The xMutexInit() method must be threadsafe. It must be harmless to
6199 ** invoke xMutexInit() multiple times within the same process and without
6200 ** intervening calls to xMutexEnd(). Second and subsequent calls to
6201 ** xMutexInit() must be no-ops.
6202 **
6203 ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6204 ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
6205 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
6206 ** memory allocation for a fast or recursive mutex.
6207 **
6208 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
6209 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6186,33 +6225,33 @@
6225
6226 /*
6227 ** CAPI3REF: Mutex Verification Routines
6228 **
6229 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6230 ** are intended for use inside assert() statements. The SQLite core
6231 ** never uses these routines except inside an assert() and applications
6232 ** are advised to follow the lead of the core. The SQLite core only
6233 ** provides implementations for these routines when it is compiled
6234 ** with the SQLITE_DEBUG flag. External mutex implementations
6235 ** are only required to provide these routines if SQLITE_DEBUG is
6236 ** defined and if NDEBUG is not defined.
6237 **
6238 ** These routines should return true if the mutex in their argument
6239 ** is held or not held, respectively, by the calling thread.
6240 **
6241 ** The implementation is not required to provide versions of these
6242 ** routines that actually work. If the implementation does not provide working
6243 ** versions of these routines, it should at least provide stubs that always
6244 ** return true so that one does not get spurious assertion failures.
6245 **
6246 ** If the argument to sqlite3_mutex_held() is a NULL pointer then
6247 ** the routine should return 1. This seems counter-intuitive since
6248 ** clearly the mutex cannot be held if it does not exist. But
6249 ** the reason the mutex does not exist is because the build is not
6250 ** using mutexes. And we do not want the assert() containing the
6251 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
6252 ** the appropriate thing to do. The sqlite3_mutex_notheld()
6253 ** interface should also return 1 when given a NULL pointer.
6254 */
6255 #ifndef NDEBUG
6256 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
6257 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6940,10 +6979,14 @@
6979 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6980 ** and database name of the source database, respectively.
6981 ** ^The source and destination [database connections] (parameters S and D)
6982 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6983 ** an error.
6984 **
6985 ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
6986 ** there is already a read or read-write transaction open on the
6987 ** destination database.
6988 **
6989 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6990 ** returned and an error code and error message are stored in the
6991 ** destination [database connection] D.
6992 ** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7334,101 +7377,118 @@
7377 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7378
7379 /*
7380 ** CAPI3REF: Checkpoint a database
7381 **
7382 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7383 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7384 **
7385 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
7386 ** [write-ahead log] for database X on [database connection] D to be
7387 ** transferred into the database file and for the write-ahead log to
7388 ** be reset. See the [checkpointing] documentation for addition
7389 ** information.
7390 **
7391 ** This interface used to be the only way to cause a checkpoint to
7392 ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
7393 ** interface was added. This interface is retained for backwards
7394 ** compatibility and as a convenience for applications that need to manually
7395 ** start a callback but which do not need the full power (and corresponding
7396 ** complication) of [sqlite3_wal_checkpoint_v2()].
 
7397 */
7398 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7399
7400 /*
7401 ** CAPI3REF: Checkpoint a database
7402 **
7403 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7404 ** operation on database X of [database connection] D in mode M. Status
7405 ** information is written back into integers pointed to by L and C.)^
7406 ** ^(The M parameter must be a valid [checkpoint mode]:)^
7407 **
7408 ** <dl>
7409 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7410 ** ^Checkpoint as many frames as possible without waiting for any database
7411 ** readers or writers to finish, then sync the database file if all frames
7412 ** in the log were checkpointed. ^The [busy-handler callback]
7413 ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
7414 ** ^On the other hand, passive mode might leave the checkpoint unfinished
7415 ** if there are concurrent readers or writers.
7416 **
7417 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7418 ** ^This mode blocks (it invokes the
7419 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7420 ** database writer and all readers are reading from the most recent database
7421 ** snapshot. ^It then checkpoints all frames in the log file and syncs the
7422 ** database file. ^This mode blocks new database writers while it is pending,
7423 ** but new database readers are allowed to continue unimpeded.
7424 **
7425 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7426 ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
7427 ** that after checkpointing the log file it blocks (calls the
7428 ** [busy-handler callback])
7429 ** until all readers are reading from the database file only. ^This ensures
7430 ** that the next writer will restart the log file from the beginning.
7431 ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
7432 ** database writer attempts while it is pending, but does not impede readers.
7433 **
7434 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
7435 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
7436 ** addition that it also truncates the log file to zero bytes just prior
7437 ** to a successful return.
7438 ** </dl>
7439 **
7440 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
7441 ** the log file or to -1 if the checkpoint could not run because
7442 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
7443 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
7444 ** log file (including any that were already checkpointed before the function
7445 ** was called) or to -1 if the checkpoint could not run due to an error or
7446 ** because the database is not in WAL mode. ^Note that upon successful
7447 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
7448 ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
7449 **
7450 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
7451 ** any other process is running a checkpoint operation at the same time, the
7452 ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
7453 ** busy-handler configured, it will not be invoked in this case.
7454 **
7455 ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
7456 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
7457 ** obtained immediately, and a busy-handler is configured, it is invoked and
7458 ** the writer lock retried until either the busy-handler returns 0 or the lock
7459 ** is successfully obtained. ^The busy-handler is also invoked while waiting for
7460 ** database readers as described above. ^If the busy-handler returns 0 before
7461 ** the writer lock is obtained or while waiting for database readers, the
7462 ** checkpoint operation proceeds from that point in the same way as
7463 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7464 ** without blocking any further. ^SQLITE_BUSY is returned in this case.
7465 **
7466 ** ^If parameter zDb is NULL or points to a zero length string, then the
7467 ** specified operation is attempted on all WAL databases [attached] to
7468 ** [database connection] db. In this case the
7469 ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
7470 ** an SQLITE_BUSY error is encountered when processing one or more of the
7471 ** attached WAL databases, the operation is still attempted on any remaining
7472 ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
7473 ** error occurs while processing an attached database, processing is abandoned
7474 ** and the error code is returned to the caller immediately. ^If no error
7475 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
7476 ** databases, SQLITE_OK is returned.
7477 **
7478 ** ^If database zDb is the name of an attached database that is not in WAL
7479 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
7480 ** zDb is not NULL (or a zero length string) and is not the name of any
7481 ** attached database, SQLITE_ERROR is returned to the caller.
7482 **
7483 ** ^Unless it returns SQLITE_MISUSE,
7484 ** the sqlite3_wal_checkpoint_v2() interface
7485 ** sets the error information that is queried by
7486 ** [sqlite3_errcode()] and [sqlite3_errmsg()].
7487 **
7488 ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
7489 ** from SQL.
7490 */
7491 SQLITE_API int sqlite3_wal_checkpoint_v2(
7492 sqlite3 *db, /* Database handle */
7493 const char *zDb, /* Name of attached database (or NULL) */
7494 int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7435,20 +7495,22 @@
7495 int *pnLog, /* OUT: Size of WAL log in frames */
7496 int *pnCkpt /* OUT: Total number of frames checkpointed */
7497 );
7498
7499 /*
7500 ** CAPI3REF: Checkpoint Mode Values
7501 ** KEYWORDS: {checkpoint mode}
7502 **
7503 ** These constants define all valid values for the "checkpoint mode" passed
7504 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
7505 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
7506 ** meaning of each of these checkpoint modes.
7507 */
7508 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
7509 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
7510 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
7511 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
7512
7513 /*
7514 ** CAPI3REF: Virtual Table Interface Configuration
7515 **
7516 ** This function may be called by either the [xConnect] or [xCreate] method
@@ -7533,10 +7595,102 @@
7595 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7596 #define SQLITE_FAIL 3
7597 /* #define SQLITE_ABORT 4 // Also an error code */
7598 #define SQLITE_REPLACE 5
7599
7600 /*
7601 ** CAPI3REF: Prepared Statement Scan Status Opcodes
7602 ** KEYWORDS: {scanstatus options}
7603 **
7604 ** The following constants can be used for the T parameter to the
7605 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7606 ** different metric for sqlite3_stmt_scanstatus() to return.
7607 **
7608 ** <dl>
7609 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7610 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7611 ** set to the total number of times that the X-th loop has run.</dd>
7612 **
7613 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7614 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
7615 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
7616 **
7617 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7618 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
7619 ** query planner's estimate for the average number of rows output from each
7620 ** iteration of the X-th loop. If the query planner's estimates was accurate,
7621 ** then this value will approximate the quotient NVISIT/NLOOP and the
7622 ** product of this value for all prior loops with the same SELECTID will
7623 ** be the NLOOP value for the current loop.
7624 **
7625 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7626 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
7627 ** to a zero-terminated UTF-8 string containing the name of the index or table
7628 ** used for the X-th loop.
7629 **
7630 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7631 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
7632 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
7633 ** description for the X-th loop.
7634 **
7635 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7636 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
7637 ** "select-id" for the X-th loop. The select-id identifies which query or
7638 ** subquery the loop is part of. The main query has a select-id of zero.
7639 ** The select-id is the same value as is output in the first column
7640 ** of an [EXPLAIN QUERY PLAN] query.
7641 ** </dl>
7642 */
7643 #define SQLITE_SCANSTAT_NLOOP 0
7644 #define SQLITE_SCANSTAT_NVISIT 1
7645 #define SQLITE_SCANSTAT_EST 2
7646 #define SQLITE_SCANSTAT_NAME 3
7647 #define SQLITE_SCANSTAT_EXPLAIN 4
7648 #define SQLITE_SCANSTAT_SELECTID 5
7649
7650 /*
7651 ** CAPI3REF: Prepared Statement Scan Status
7652 **
7653 ** Return status data for a single loop within query pStmt.
7654 **
7655 ** The "iScanStatusOp" parameter determines which status information to return.
7656 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7657 ** of this interface is undefined.
7658 ** ^The requested measurement is written into a variable pointed to by
7659 ** the "pOut" parameter.
7660 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
7661 ** Loops are numbered starting from zero. ^If idx is out of range - less than
7662 ** zero or greater than or equal to the total number of loops used to implement
7663 ** the statement - a non-zero value is returned and the variable that pOut
7664 ** points to is unchanged.
7665 **
7666 ** ^Statistics might not be available for all loops in all statements. ^In cases
7667 ** where there exist loops with no available statistics, this function behaves
7668 ** as if the loop did not exist - it returns non-zero and leave the variable
7669 ** that pOut points to unchanged.
7670 **
7671 ** This API is only available if the library is built with pre-processor
7672 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7673 **
7674 ** See also: [sqlite3_stmt_scanstatus_reset()]
7675 */
7676 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7677 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7678 int idx, /* Index of loop to report on */
7679 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7680 void *pOut /* Result written here */
7681 );
7682
7683 /*
7684 ** CAPI3REF: Zero Scan-Status Counters
7685 **
7686 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7687 **
7688 ** This API is only available if the library is built with pre-processor
7689 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7690 */
7691 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
7692
7693
7694 /*
7695 ** Undo the hack that converts floating point types to integer for
7696 ** builds on processors without floating point support.
@@ -7978,14 +8132,13 @@
8132 #ifndef SQLITE_POWERSAFE_OVERWRITE
8133 # define SQLITE_POWERSAFE_OVERWRITE 1
8134 #endif
8135
8136 /*
8137 ** EVIDENCE-OF: R-25715-37072 Memory allocation statistics are enabled by
8138 ** default unless SQLite is compiled with SQLITE_DEFAULT_MEMSTATUS=0 in
8139 ** which case memory allocation statistics are disabled by default.
 
8140 */
8141 #if !defined(SQLITE_DEFAULT_MEMSTATUS)
8142 # define SQLITE_DEFAULT_MEMSTATUS 1
8143 #endif
8144
@@ -8611,11 +8764,11 @@
8764 ** Estimated quantities used for query planning are stored as 16-bit
8765 ** logarithms. For quantity X, the value stored is 10*log2(X). This
8766 ** gives a possible range of values of approximately 1.0e986 to 1e-986.
8767 ** But the allowed values are "grainy". Not every value is representable.
8768 ** For example, quantities 16 and 17 are both represented by a LogEst
8769 ** of 40. However, since LogEst quantities are suppose to be estimates,
8770 ** not exact values, this imprecision is not a problem.
8771 **
8772 ** "LogEst" is short for "Logarithmic Estimate".
8773 **
8774 ** Examples:
@@ -9011,11 +9164,11 @@
9164 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
9165 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int);
9166 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
9167 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
9168 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
9169 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
9170 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
9171 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
9172 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
9173 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
9174 SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
@@ -9044,11 +9197,11 @@
9197 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
9198
9199 SQLITE_PRIVATE int sqlite3BtreeDropTable(Btree*, int, int*);
9200 SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree*, int, int*);
9201 SQLITE_PRIVATE int sqlite3BtreeClearTableOfCursor(BtCursor*);
9202 SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree*, int, int);
9203
9204 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
9205 SQLITE_PRIVATE int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
9206
9207 SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
@@ -9124,10 +9277,11 @@
9277 SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *);
9278 SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *);
9279 SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
9280 SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
9281 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
9282 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
9283
9284 #ifndef NDEBUG
9285 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
9286 #endif
9287
@@ -9666,10 +9820,16 @@
9820 # define VdbeCoverageAlwaysTaken(v)
9821 # define VdbeCoverageNeverTaken(v)
9822 # define VDBE_OFFSET_LINENO(x) 0
9823 #endif
9824
9825 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9826 SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
9827 #else
9828 # define sqlite3VdbeScanStatus(a,b,c,d,e)
9829 #endif
9830
9831 #endif
9832
9833 /************** End of vdbe.h ************************************************/
9834 /************** Continuing where we left off in sqliteInt.h ******************/
9835 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -9862,10 +10022,12 @@
10022 SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *);
10023
10024 /* Functions used to truncate the database file. */
10025 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
10026
10027 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16);
10028
10029 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
10030 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
10031 #endif
10032
10033 /* Functions to support testing and debugging. */
@@ -10049,10 +10211,14 @@
10211 SQLITE_PRIVATE void sqlite3PcacheStats(int*,int*,int*,int*);
10212 #endif
10213
10214 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
10215
10216 /* Return the header size */
10217 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
10218 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
10219
10220 #endif /* _PCACHE_H_ */
10221
10222 /************** End of pcache.h **********************************************/
10223 /************** Continuing where we left off in sqliteInt.h ******************/
10224
@@ -10735,11 +10901,11 @@
10901 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10902 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10903 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10904 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10905 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10906 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
10907 #define SQLITE_AllOpts 0xffff /* All optimizations */
10908
10909 /*
10910 ** Macros for testing whether or not optimizations are enabled or disabled.
10911 */
@@ -11317,16 +11483,18 @@
11483 unsigned idxType:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
11484 unsigned bUnordered:1; /* Use this index for == or IN queries only */
11485 unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
11486 unsigned isResized:1; /* True if resizeIndexObject() has been called */
11487 unsigned isCovering:1; /* True if this is a covering index */
11488 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
11489 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
11490 int nSample; /* Number of elements in aSample[] */
11491 int nSampleCol; /* Size of IndexSample.anEq[] and so on */
11492 tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
11493 IndexSample *aSample; /* Samples of the left-most key */
11494 tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
11495 tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
11496 #endif
11497 };
11498
11499 /*
11500 ** Allowed values for Index.idxType
@@ -11520,11 +11688,11 @@
11688 int nHeight; /* Height of the tree headed by this node */
11689 #endif
11690 int iTable; /* TK_COLUMN: cursor number of table holding column
11691 ** TK_REGISTER: register number
11692 ** TK_TRIGGER: 1 -> new, 0 -> old
11693 ** EP_Unlikely: 134217728 times likelihood */
11694 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
11695 ** TK_VARIABLE: variable number (always >= 1). */
11696 i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
11697 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
11698 u8 op2; /* TK_REGISTER: original value of Expr.op
@@ -11535,11 +11703,11 @@
11703 };
11704
11705 /*
11706 ** The following are the meanings of bits in the Expr.flags field.
11707 */
11708 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
11709 #define EP_Agg 0x000002 /* Contains one or more aggregate functions */
11710 #define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
11711 #define EP_Error 0x000008 /* Expression contains one or more errors */
11712 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
11713 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
@@ -11555,10 +11723,11 @@
11723 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11724 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11725 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11726 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11727 #define EP_Constant 0x080000 /* Node is a constant */
11728 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
11729
11730 /*
11731 ** These macros can be used to test, set, or clear bits in the
11732 ** Expr.flags field.
11733 */
@@ -12412,13 +12581,15 @@
12581 int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */
12582 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
12583 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
12584 Parse *pParse; /* Parser context. */
12585 int walkerDepth; /* Number of subqueries */
12586 u8 eCode; /* A small processing code */
12587 union { /* Extra data for callback */
12588 NameContext *pNC; /* Naming context */
12589 int n; /* A counter */
12590 int iCur; /* A cursor number */
12591 SrcList *pSrcList; /* FROM clause */
12592 struct SrcCount *pSrcCount; /* Counting column references */
12593 } u;
12594 };
12595
@@ -12815,10 +12986,11 @@
12986 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
12987 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
12988 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12989 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12990 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
12991 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
12992 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12993 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12994 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12995 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12996 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
@@ -13060,11 +13232,11 @@
13232 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
13233
13234 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int);
13235 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
13236 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
13237 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
13238 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
13239 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
13240 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
13241 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
13242
@@ -13472,15 +13644,23 @@
13644 ** compatibility for legacy applications, the URI filename capability is
13645 ** disabled by default.
13646 **
13647 ** EVIDENCE-OF: R-38799-08373 URI filenames can be enabled or disabled
13648 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
13649 **
13650 ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
13651 ** disabled. The default value may be changed by compiling with the
13652 ** SQLITE_USE_URI symbol defined.
13653 */
13654 #ifndef SQLITE_USE_URI
13655 # define SQLITE_USE_URI 0
13656 #endif
13657
13658 /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
13659 ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
13660 ** that compile-time option is omitted.
13661 */
13662 #ifndef SQLITE_ALLOW_COVERING_INDEX_SCAN
13663 # define SQLITE_ALLOW_COVERING_INDEX_SCAN 1
13664 #endif
13665
13666 /*
@@ -13566,12 +13746,12 @@
13746 ** than 1 GiB. The sqlite3_test_control() interface can be used to
13747 ** move the pending byte.
13748 **
13749 ** IMPORTANT: Changing the pending byte to any value other than
13750 ** 0x40000000 results in an incompatible database file format!
13751 ** Changing the pending byte during operation will result in undefined
13752 ** and incorrect behavior.
13753 */
13754 #ifndef SQLITE_OMIT_WSD
13755 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
13756 #endif
13757
@@ -13646,10 +13826,13 @@
13826 #ifdef SQLITE_DISABLE_DIRSYNC
13827 "DISABLE_DIRSYNC",
13828 #endif
13829 #ifdef SQLITE_DISABLE_LFS
13830 "DISABLE_LFS",
13831 #endif
13832 #ifdef SQLITE_ENABLE_API_ARMOR
13833 "ENABLE_API_ARMOR",
13834 #endif
13835 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
13836 "ENABLE_ATOMIC_WRITE",
13837 #endif
13838 #ifdef SQLITE_ENABLE_CEROD
@@ -13972,10 +14155,17 @@
14155 ** The name can optionally begin with "SQLITE_" but the "SQLITE_" prefix
14156 ** is not required for a match.
14157 */
14158 SQLITE_API int sqlite3_compileoption_used(const char *zOptName){
14159 int i, n;
14160
14161 #ifdef SQLITE_ENABLE_API_ARMOR
14162 if( zOptName==0 ){
14163 (void)SQLITE_MISUSE_BKPT;
14164 return 0;
14165 }
14166 #endif
14167 if( sqlite3StrNICmp(zOptName, "SQLITE_", 7)==0 ) zOptName += 7;
14168 n = sqlite3Strlen30(zOptName);
14169
14170 /* Since ArraySize(azCompileOpt) is normally in single digits, a
14171 ** linear search is adequate. No need for a binary search. */
@@ -14153,10 +14343,11 @@
14343 typedef struct VdbeFrame VdbeFrame;
14344 struct VdbeFrame {
14345 Vdbe *v; /* VM this frame belongs to */
14346 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
14347 Op *aOp; /* Program instructions for parent frame */
14348 i64 *anExec; /* Event counters from parent frame */
14349 Mem *aMem; /* Array of memory cells for parent frame */
14350 u8 *aOnceFlag; /* Array of OP_Once flags for parent frame */
14351 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
14352 void *token; /* Copy of SubProgram.token */
14353 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -14165,11 +14356,12 @@
14356 int nOp; /* Size of aOp array */
14357 int nMem; /* Number of entries in aMem */
14358 int nOnceFlag; /* Number of entries in aOnceFlag */
14359 int nChildMem; /* Number of memory cells for child frame */
14360 int nChildCsr; /* Number of cursors for child frame */
14361 int nChange; /* Statement changes (Vdbe.nChange) */
14362 int nDbChange; /* Value of db->nChange */
14363 };
14364
14365 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
14366
14367 /*
@@ -14316,10 +14508,20 @@
14508 /* A bitfield type for use inside of structures. Always follow with :N where
14509 ** N is the number of bits.
14510 */
14511 typedef unsigned bft; /* Bit Field Type */
14512
14513 typedef struct ScanStatus ScanStatus;
14514 struct ScanStatus {
14515 int addrExplain; /* OP_Explain for loop */
14516 int addrLoop; /* Address of "loops" counter */
14517 int addrVisit; /* Address of "rows visited" counter */
14518 int iSelectID; /* The "Select-ID" for this loop */
14519 LogEst nEst; /* Estimated output rows per loop */
14520 char *zName; /* Name of table or index */
14521 };
14522
14523 /*
14524 ** An instance of the virtual machine. This structure contains the complete
14525 ** state of the virtual machine.
14526 **
14527 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
@@ -14388,10 +14590,15 @@
14590 u32 expmask; /* Binding to these vars invalidates VM */
14591 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
14592 int nOnceFlag; /* Size of array aOnceFlag[] */
14593 u8 *aOnceFlag; /* Flags for OP_Once */
14594 AuxData *pAuxData; /* Linked list of auxdata allocations */
14595 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
14596 i64 *anExec; /* Number of times each op has been executed */
14597 int nScan; /* Entries in aScan[] */
14598 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
14599 #endif
14600 };
14601
14602 /*
14603 ** The following are allowed values for Vdbe.magic
14604 */
@@ -14577,10 +14784,13 @@
14784 SQLITE_API int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag){
14785 wsdStatInit;
14786 if( op<0 || op>=ArraySize(wsdStat.nowValue) ){
14787 return SQLITE_MISUSE_BKPT;
14788 }
14789 #ifdef SQLITE_ENABLE_API_ARMOR
14790 if( pCurrent==0 || pHighwater==0 ) return SQLITE_MISUSE_BKPT;
14791 #endif
14792 *pCurrent = wsdStat.nowValue[op];
14793 *pHighwater = wsdStat.mxValue[op];
14794 if( resetFlag ){
14795 wsdStat.mxValue[op] = wsdStat.nowValue[op];
14796 }
@@ -14596,10 +14806,15 @@
14806 int *pCurrent, /* Write current value here */
14807 int *pHighwater, /* Write high-water mark here */
14808 int resetFlag /* Reset high-water mark if true */
14809 ){
14810 int rc = SQLITE_OK; /* Return code */
14811 #ifdef SQLITE_ENABLE_API_ARMOR
14812 if( !sqlite3SafetyCheckOk(db) || pCurrent==0|| pHighwater==0 ){
14813 return SQLITE_MISUSE_BKPT;
14814 }
14815 #endif
14816 sqlite3_mutex_enter(db->mutex);
14817 switch( op ){
14818 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
14819 *pCurrent = db->lookaside.nOut;
14820 *pHighwater = db->lookaside.mxOut;
@@ -14774,11 +14989,11 @@
14989 **
14990 ** There is only one exported symbol in this file - the function
14991 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
14992 ** All other code has file scope.
14993 **
14994 ** SQLite processes all times and dates as julian day numbers. The
14995 ** dates and times are stored as the number of days since noon
14996 ** in Greenwich on November 24, 4714 B.C. according to the Gregorian
14997 ** calendar system.
14998 **
14999 ** 1970-01-01 00:00:00 is JD 2440587.5
@@ -14789,11 +15004,11 @@
15004 ** be represented, even though julian day numbers allow a much wider
15005 ** range of dates.
15006 **
15007 ** The Gregorian calendar system is used for all dates and times,
15008 ** even those that predate the Gregorian calendar. Historians usually
15009 ** use the julian calendar for dates prior to 1582-10-15 and for some
15010 ** dates afterwards, depending on locale. Beware of this difference.
15011 **
15012 ** The conversion algorithms are implemented based on descriptions
15013 ** in the following text:
15014 **
@@ -15061,11 +15276,11 @@
15276 return 1;
15277 }
15278 }
15279
15280 /*
15281 ** Attempt to parse the given string into a julian day number. Return
15282 ** the number of errors.
15283 **
15284 ** The following are acceptable forms for the input string:
15285 **
15286 ** YYYY-MM-DD HH:MM:SS.FFF +/-HH:MM
@@ -15632,11 +15847,11 @@
15847 **
15848 ** %d day of month
15849 ** %f ** fractional seconds SS.SSS
15850 ** %H hour 00-24
15851 ** %j day of year 000-366
15852 ** %J ** julian day number
15853 ** %m month 01-12
15854 ** %M minute 00-59
15855 ** %s seconds since 1970-01-01
15856 ** %S seconds 00-59
15857 ** %w day of week 0-6 sunday==0
@@ -16257,10 +16472,14 @@
16472 MUTEX_LOGIC(sqlite3_mutex *mutex;)
16473 #ifndef SQLITE_OMIT_AUTOINIT
16474 int rc = sqlite3_initialize();
16475 if( rc ) return rc;
16476 #endif
16477 #ifdef SQLITE_ENABLE_API_ARMOR
16478 if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
16479 #endif
16480
16481 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
16482 sqlite3_mutex_enter(mutex);
16483 vfsUnlink(pVfs);
16484 if( makeDflt || vfsList==0 ){
16485 pVfs->pNext = vfsList;
@@ -18614,10 +18833,11 @@
18833 ** Retrieve a pointer to a static mutex or allocate a new dynamic one.
18834 */
18835 SQLITE_API sqlite3_mutex *sqlite3_mutex_alloc(int id){
18836 #ifndef SQLITE_OMIT_AUTOINIT
18837 if( id<=SQLITE_MUTEX_RECURSIVE && sqlite3_initialize() ) return 0;
18838 if( id>SQLITE_MUTEX_RECURSIVE && sqlite3MutexInit() ) return 0;
18839 #endif
18840 return sqlite3GlobalConfig.mutex.xMutexAlloc(id);
18841 }
18842
18843 SQLITE_PRIVATE sqlite3_mutex *sqlite3MutexAlloc(int id){
@@ -19070,12 +19290,16 @@
19290 pthread_mutex_init(&p->mutex, 0);
19291 }
19292 break;
19293 }
19294 default: {
19295 #ifdef SQLITE_ENABLE_API_ARMOR
19296 if( iType-2<0 || iType-2>=ArraySize(staticMutexes) ){
19297 (void)SQLITE_MISUSE_BKPT;
19298 return 0;
19299 }
19300 #endif
19301 p = &staticMutexes[iType-2];
19302 #if SQLITE_MUTEX_NREF
19303 p->id = iType;
19304 #endif
19305 break;
@@ -20293,15 +20517,16 @@
20517 }
20518 assert( sqlite3_mutex_notheld(mem0.mutex) );
20519
20520
20521 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
20522 /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
20523 ** buffers per thread.
20524 **
20525 ** This can only be checked in single-threaded mode.
20526 */
20527 assert( scratchAllocOut==0 );
20528 if( p ) scratchAllocOut++;
20529 #endif
20530
20531 return p;
20532 }
@@ -20945,11 +21170,11 @@
21170 sqlite_uint64 longvalue; /* Value for integer types */
21171 LONGDOUBLE_TYPE realvalue; /* Value for real types */
21172 const et_info *infop; /* Pointer to the appropriate info structure */
21173 char *zOut; /* Rendering buffer */
21174 int nOut; /* Size of the rendering buffer */
21175 char *zExtra = 0; /* Malloced memory used by some conversion */
21176 #ifndef SQLITE_OMIT_FLOATING_POINT
21177 int exp, e2; /* exponent of real numbers */
21178 int nsd; /* Number of significant digits returned */
21179 double rounder; /* Used for rounding floating point values */
21180 etByte flag_dp; /* True if decimal point should be shown */
@@ -20956,10 +21181,17 @@
21181 etByte flag_rtz; /* True if trailing zeros should be removed */
21182 #endif
21183 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
21184 char buf[etBUFSIZE]; /* Conversion buffer */
21185
21186 #ifdef SQLITE_ENABLE_API_ARMOR
21187 if( ap==0 ){
21188 (void)SQLITE_MISUSE_BKPT;
21189 sqlite3StrAccumReset(pAccum);
21190 return;
21191 }
21192 #endif
21193 bufpt = 0;
21194 if( bFlags ){
21195 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
21196 pArgList = va_arg(ap, PrintfArguments*);
21197 }
@@ -21062,11 +21294,10 @@
21294 return;
21295 }
21296 break;
21297 }
21298 }
 
21299
21300 /*
21301 ** At this point, variables are initialized as follows:
21302 **
21303 ** flag_alternateform TRUE if a '#' is present.
@@ -21353,17 +21584,20 @@
21584 bufpt = getTextArg(pArgList);
21585 c = bufpt ? bufpt[0] : 0;
21586 }else{
21587 c = va_arg(ap,int);
21588 }
21589 if( precision>1 ){
21590 width -= precision-1;
21591 if( width>1 && !flag_leftjustify ){
21592 sqlite3AppendChar(pAccum, width-1, ' ');
21593 width = 0;
21594 }
21595 sqlite3AppendChar(pAccum, precision-1, c);
21596 }
21597 length = 1;
21598 buf[0] = c;
21599 bufpt = buf;
21600 break;
21601 case etSTRING:
21602 case etDYNSTRING:
21603 if( bArgList ){
@@ -21460,15 +21694,18 @@
21694 ** The text of the conversion is pointed to by "bufpt" and is
21695 ** "length" characters long. The field width is "width". Do
21696 ** the output.
21697 */
21698 width -= length;
21699 if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
21700 sqlite3StrAccumAppend(pAccum, bufpt, length);
21701 if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
21702
21703 if( zExtra ){
21704 sqlite3_free(zExtra);
21705 zExtra = 0;
21706 }
21707 }/* End for loop over the format string */
21708 } /* End of function */
21709
21710 /*
21711 ** Enlarge the memory allocation on a StrAccum object so that it is
@@ -21491,10 +21728,15 @@
21728 return N;
21729 }else{
21730 char *zOld = (p->zText==p->zBase ? 0 : p->zText);
21731 i64 szNew = p->nChar;
21732 szNew += N + 1;
21733 if( szNew+p->nChar<=p->mxAlloc ){
21734 /* Force exponential buffer size growth as long as it does not overflow,
21735 ** to avoid having to call this routine too often */
21736 szNew += p->nChar;
21737 }
21738 if( szNew > p->mxAlloc ){
21739 sqlite3StrAccumReset(p);
21740 setStrAccumError(p, STRACCUM_TOOBIG);
21741 return 0;
21742 }else{
@@ -21507,10 +21749,11 @@
21749 }
21750 if( zNew ){
21751 assert( p->zText!=0 || p->nChar==0 );
21752 if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
21753 p->zText = zNew;
21754 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
21755 }else{
21756 sqlite3StrAccumReset(p);
21757 setStrAccumError(p, STRACCUM_NOMEM);
21758 return 0;
21759 }
@@ -21517,15 +21760,15 @@
21760 }
21761 return N;
21762 }
21763
21764 /*
21765 ** Append N copies of character c to the given string buffer.
21766 */
21767 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
21768 if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ) return;
21769 while( (N--)>0 ) p->zText[p->nChar++] = c;
21770 }
21771
21772 /*
21773 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
21774 ** So enlarge if first, then do the append.
@@ -21676,10 +21919,17 @@
21919 */
21920 SQLITE_API char *sqlite3_vmprintf(const char *zFormat, va_list ap){
21921 char *z;
21922 char zBase[SQLITE_PRINT_BUF_SIZE];
21923 StrAccum acc;
21924
21925 #ifdef SQLITE_ENABLE_API_ARMOR
21926 if( zFormat==0 ){
21927 (void)SQLITE_MISUSE_BKPT;
21928 return 0;
21929 }
21930 #endif
21931 #ifndef SQLITE_OMIT_AUTOINIT
21932 if( sqlite3_initialize() ) return 0;
21933 #endif
21934 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
21935 acc.useMalloc = 2;
@@ -21718,10 +21968,17 @@
21968 ** sqlite3_vsnprintf() is the varargs version.
21969 */
21970 SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
21971 StrAccum acc;
21972 if( n<=0 ) return zBuf;
21973 #ifdef SQLITE_ENABLE_API_ARMOR
21974 if( zBuf==0 || zFormat==0 ) {
21975 (void)SQLITE_MISUSE_BKPT;
21976 if( zBuf && n>0 ) zBuf[0] = 0;
21977 return zBuf;
21978 }
21979 #endif
21980 sqlite3StrAccumInit(&acc, zBuf, n, 0);
21981 acc.useMalloc = 0;
21982 sqlite3VXPrintf(&acc, 0, zFormat, ap);
21983 return sqlite3StrAccumFinish(&acc);
21984 }
@@ -21909,15 +22166,23 @@
22166 #else
22167 # define wsdPrng sqlite3Prng
22168 #endif
22169
22170 #if SQLITE_THREADSAFE
22171 sqlite3_mutex *mutex;
22172 #endif
22173
22174 #ifndef SQLITE_OMIT_AUTOINIT
22175 if( sqlite3_initialize() ) return;
22176 #endif
22177
22178 #if SQLITE_THREADSAFE
22179 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
22180 #endif
22181
22182 sqlite3_mutex_enter(mutex);
22183 if( N<=0 || pBuf==0 ){
 
 
22184 wsdPrng.isInit = 0;
22185 sqlite3_mutex_leave(mutex);
22186 return;
22187 }
22188
@@ -23035,17 +23300,27 @@
23300 ** case-independent fashion, using the same definition of "case
23301 ** independence" that SQLite uses internally when comparing identifiers.
23302 */
23303 SQLITE_API int sqlite3_stricmp(const char *zLeft, const char *zRight){
23304 register unsigned char *a, *b;
23305 if( zLeft==0 ){
23306 return zRight ? -1 : 0;
23307 }else if( zRight==0 ){
23308 return 1;
23309 }
23310 a = (unsigned char *)zLeft;
23311 b = (unsigned char *)zRight;
23312 while( *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23313 return UpperToLower[*a] - UpperToLower[*b];
23314 }
23315 SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
23316 register unsigned char *a, *b;
23317 if( zLeft==0 ){
23318 return zRight ? -1 : 0;
23319 }else if( zRight==0 ){
23320 return 1;
23321 }
23322 a = (unsigned char *)zLeft;
23323 b = (unsigned char *)zRight;
23324 while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
23325 return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
23326 }
@@ -32574,10 +32849,15 @@
32849 #if !SQLITE_OS_WINNT && !defined(SQLITE_OMIT_WAL)
32850 # error "WAL mode requires support from the Windows NT kernel, compile\
32851 with SQLITE_OMIT_WAL."
32852 #endif
32853
32854 #if !SQLITE_OS_WINNT && SQLITE_MAX_MMAP_SIZE>0
32855 # error "Memory mapped files require support from the Windows NT kernel,\
32856 compile with SQLITE_MAX_MMAP_SIZE=0."
32857 #endif
32858
32859 /*
32860 ** Are most of the Win32 ANSI APIs available (i.e. with certain exceptions
32861 ** based on the sub-platform)?
32862 */
32863 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(SQLITE_WIN32_NO_ANSI)
@@ -32703,14 +32983,15 @@
32983 # define winGetDirSep() '\\'
32984 #endif
32985
32986 /*
32987 ** Do we need to manually define the Win32 file mapping APIs for use with WAL
32988 ** mode or memory mapped files (e.g. these APIs are available in the Windows
32989 ** CE SDK; however, they are not present in the header file)?
32990 */
32991 #if SQLITE_WIN32_FILEMAPPING_API && \
32992 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
32993 /*
32994 ** Two of the file mapping APIs are different under WinRT. Figure out which
32995 ** set we need.
32996 */
32997 #if SQLITE_OS_WINRT
@@ -32734,11 +33015,11 @@
33015
33016 /*
33017 ** This file mapping API is common to both Win32 and WinRT.
33018 */
33019 WINBASEAPI BOOL WINAPI UnmapViewOfFile(LPCVOID);
33020 #endif /* SQLITE_WIN32_FILEMAPPING_API */
33021
33022 /*
33023 ** Some Microsoft compilers lack this definition.
33024 */
33025 #ifndef INVALID_FILE_ATTRIBUTES
@@ -33027,21 +33308,21 @@
33308
33309 #define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
33310 LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
33311
33312 #if (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_ANSI) && \
33313 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33314 { "CreateFileMappingA", (SYSCALL)CreateFileMappingA, 0 },
33315 #else
33316 { "CreateFileMappingA", (SYSCALL)0, 0 },
33317 #endif
33318
33319 #define osCreateFileMappingA ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
33320 DWORD,DWORD,DWORD,LPCSTR))aSyscall[6].pCurrent)
33321
33322 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
33323 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33324 { "CreateFileMappingW", (SYSCALL)CreateFileMappingW, 0 },
33325 #else
33326 { "CreateFileMappingW", (SYSCALL)0, 0 },
33327 #endif
33328
@@ -33377,11 +33658,12 @@
33658 #ifndef osLockFileEx
33659 #define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
33660 LPOVERLAPPED))aSyscall[48].pCurrent)
33661 #endif
33662
33663 #if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && \
33664 (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0))
33665 { "MapViewOfFile", (SYSCALL)MapViewOfFile, 0 },
33666 #else
33667 { "MapViewOfFile", (SYSCALL)0, 0 },
33668 #endif
33669
@@ -33447,11 +33729,11 @@
33729 #endif
33730
33731 #define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
33732 LPOVERLAPPED))aSyscall[58].pCurrent)
33733
33734 #if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
33735 { "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
33736 #else
33737 { "UnmapViewOfFile", (SYSCALL)0, 0 },
33738 #endif
33739
@@ -33510,11 +33792,11 @@
33792 #endif
33793
33794 #define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
33795 FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[66].pCurrent)
33796
33797 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33798 { "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
33799 #else
33800 { "MapViewOfFileFromApp", (SYSCALL)0, 0 },
33801 #endif
33802
@@ -33574,11 +33856,11 @@
33856
33857 { "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
33858
33859 #define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[74].pCurrent)
33860
33861 #if SQLITE_OS_WINRT && (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0)
33862 { "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
33863 #else
33864 { "CreateFileMappingFromApp", (SYSCALL)0, 0 },
33865 #endif
33866
@@ -39150,10 +39432,17 @@
39432 */
39433 SQLITE_PRIVATE void sqlite3PcacheShrink(PCache *pCache){
39434 assert( pCache->pCache!=0 );
39435 sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
39436 }
39437
39438 /*
39439 ** Return the size of the header added by this middleware layer
39440 ** in the page-cache hierarchy.
39441 */
39442 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return sizeof(PgHdr); }
39443
39444
39445 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
39446 /*
39447 ** For all dirty pages currently in the cache, invoke the specified
39448 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -40149,10 +40438,15 @@
40438 pcache1Shrink /* xShrink */
40439 };
40440 sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
40441 }
40442
40443 /*
40444 ** Return the size of the header on each page of this PCACHE implementation.
40445 */
40446 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void){ return sizeof(PgHdr1); }
40447
40448 #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
40449 /*
40450 ** This function is called to free superfluous dynamically allocated memory
40451 ** held by the pager system. Memory in use by any SQLite pager allocated
40452 ** by the current thread may be sqlite3_free()ed.
@@ -43758,11 +44052,11 @@
44052 ** should be page numbers which are never 0xffffffff. So filling
44053 ** pPager->dbFileVers[] with all 0xff bytes should suffice.
44054 **
44055 ** For an encrypted database, the situation is more complex: bytes
44056 ** 24..39 of the database are white noise. But the probability of
44057 ** white noise equaling 16 bytes of 0xff is vanishingly small so
44058 ** we should still be ok.
44059 */
44060 memset(pPager->dbFileVers, 0xff, sizeof(pPager->dbFileVers));
44061 }else{
44062 u8 *dbFileVers = &((u8*)pPg->pData)[24];
@@ -47705,10 +47999,22 @@
47999 }
48000
48001 return SQLITE_OK;
48002 }
48003 #endif
48004
48005 /*
48006 ** The page handle passed as the first argument refers to a dirty page
48007 ** with a page number other than iNew. This function changes the page's
48008 ** page number to iNew and sets the value of the PgHdr.flags field to
48009 ** the value passed as the third parameter.
48010 */
48011 SQLITE_PRIVATE void sqlite3PagerRekey(DbPage *pPg, Pgno iNew, u16 flags){
48012 assert( pPg->pgno!=iNew );
48013 pPg->flags = flags;
48014 sqlite3PcacheMove(pPg, iNew);
48015 }
48016
48017 /*
48018 ** Return a pointer to the data for the specified page.
48019 */
48020 SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *pPg){
@@ -47922,11 +48228,12 @@
48228 */
48229 SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){
48230 int rc = SQLITE_OK;
48231 if( pPager->pWal ){
48232 rc = sqlite3WalCheckpoint(pPager->pWal, eMode,
48233 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
48234 pPager->pBusyHandlerArg,
48235 pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
48236 pnLog, pnCkpt
48237 );
48238 }
48239 return rc;
@@ -48103,10 +48410,11 @@
48410 SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager){
48411 assert( pPager->eState>=PAGER_READER );
48412 return sqlite3WalFramesize(pPager->pWal);
48413 }
48414 #endif
48415
48416
48417 #endif /* SQLITE_OMIT_DISKIO */
48418
48419 /************** End of pager.c ***********************************************/
48420 /************** Begin file wal.c *********************************************/
@@ -49613,11 +49921,11 @@
49921
49922 /*
49923 ** Free an iterator allocated by walIteratorInit().
49924 */
49925 static void walIteratorFree(WalIterator *p){
49926 sqlite3_free(p);
49927 }
49928
49929 /*
49930 ** Construct a WalInterator object that can be used to loop over all
49931 ** pages in the WAL in ascending order. The caller must hold the checkpoint
@@ -49648,21 +49956,21 @@
49956 /* Allocate space for the WalIterator object. */
49957 nSegment = walFramePage(iLast) + 1;
49958 nByte = sizeof(WalIterator)
49959 + (nSegment-1)*sizeof(struct WalSegment)
49960 + iLast*sizeof(ht_slot);
49961 p = (WalIterator *)sqlite3_malloc(nByte);
49962 if( !p ){
49963 return SQLITE_NOMEM;
49964 }
49965 memset(p, 0, nByte);
49966 p->nSegment = nSegment;
49967
49968 /* Allocate temporary space used by the merge-sort routine. This block
49969 ** of memory will be freed before this function returns.
49970 */
49971 aTmp = (ht_slot *)sqlite3_malloc(
49972 sizeof(ht_slot) * (iLast>HASHTABLE_NPAGE?HASHTABLE_NPAGE:iLast)
49973 );
49974 if( !aTmp ){
49975 rc = SQLITE_NOMEM;
49976 }
@@ -49695,11 +50003,11 @@
50003 p->aSegment[i].nEntry = nEntry;
50004 p->aSegment[i].aIndex = aIndex;
50005 p->aSegment[i].aPgno = (u32 *)aPgno;
50006 }
50007 }
50008 sqlite3_free(aTmp);
50009
50010 if( rc!=SQLITE_OK ){
50011 walIteratorFree(p);
50012 }
50013 *pp = p;
@@ -49731,10 +50039,42 @@
50039 ** Return the page-size in bytes used by the database.
50040 */
50041 static int walPagesize(Wal *pWal){
50042 return (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
50043 }
50044
50045 /*
50046 ** The following is guaranteed when this function is called:
50047 **
50048 ** a) the WRITER lock is held,
50049 ** b) the entire log file has been checkpointed, and
50050 ** c) any existing readers are reading exclusively from the database
50051 ** file - there are no readers that may attempt to read a frame from
50052 ** the log file.
50053 **
50054 ** This function updates the shared-memory structures so that the next
50055 ** client to write to the database (which may be this one) does so by
50056 ** writing frames into the start of the log file.
50057 **
50058 ** The value of parameter salt1 is used as the aSalt[1] value in the
50059 ** new wal-index header. It should be passed a pseudo-random value (i.e.
50060 ** one obtained from sqlite3_randomness()).
50061 */
50062 static void walRestartHdr(Wal *pWal, u32 salt1){
50063 volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
50064 int i; /* Loop counter */
50065 u32 *aSalt = pWal->hdr.aSalt; /* Big-endian salt values */
50066 pWal->nCkpt++;
50067 pWal->hdr.mxFrame = 0;
50068 sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
50069 memcpy(&pWal->hdr.aSalt[1], &salt1, 4);
50070 walIndexWriteHdr(pWal);
50071 pInfo->nBackfill = 0;
50072 pInfo->aReadMark[1] = 0;
50073 for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
50074 assert( pInfo->aReadMark[0]==0 );
50075 }
50076
50077 /*
50078 ** Copy as much content as we can from the WAL back into the database file
50079 ** in response to an sqlite3_wal_checkpoint() request or the equivalent.
50080 **
@@ -49766,11 +50106,11 @@
50106 ** time.
50107 */
50108 static int walCheckpoint(
50109 Wal *pWal, /* Wal connection */
50110 int eMode, /* One of PASSIVE, FULL or RESTART */
50111 int (*xBusy)(void*), /* Function to call when busy */
50112 void *pBusyArg, /* Context argument for xBusyHandler */
50113 int sync_flags, /* Flags for OsSync() (or 0) */
50114 u8 *zBuf /* Temporary buffer to use */
50115 ){
50116 int rc; /* Return code */
@@ -49780,11 +50120,10 @@
50120 u32 iFrame = 0; /* Wal frame containing data for iDbpage */
50121 u32 mxSafeFrame; /* Max frame that can be backfilled */
50122 u32 mxPage; /* Max database page to write */
50123 int i; /* Loop counter */
50124 volatile WalCkptInfo *pInfo; /* The checkpoint status information */
 
50125
50126 szPage = walPagesize(pWal);
50127 testcase( szPage<=32768 );
50128 testcase( szPage>=65536 );
50129 pInfo = walCkptInfo(pWal);
@@ -49795,11 +50134,13 @@
50134 if( rc!=SQLITE_OK ){
50135 return rc;
50136 }
50137 assert( pIter );
50138
50139 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
50140 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
50141 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
50142
50143 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
50144 ** safe to write into the database. Frames beyond mxSafeFrame might
50145 ** overwrite database pages that are in use by active readers and thus
50146 ** cannot be backfilled from the WAL.
@@ -49884,23 +50225,42 @@
50225 /* Reset the return code so as not to report a checkpoint failure
50226 ** just because there are active readers. */
50227 rc = SQLITE_OK;
50228 }
50229
50230 /* If this is an SQLITE_CHECKPOINT_RESTART or TRUNCATE operation, and the
50231 ** entire wal file has been copied into the database file, then block
50232 ** until all readers have finished using the wal file. This ensures that
50233 ** the next process to write to the database restarts the wal file.
50234 */
50235 if( rc==SQLITE_OK && eMode!=SQLITE_CHECKPOINT_PASSIVE ){
50236 assert( pWal->writeLock );
50237 if( pInfo->nBackfill<pWal->hdr.mxFrame ){
50238 rc = SQLITE_BUSY;
50239 }else if( eMode>=SQLITE_CHECKPOINT_RESTART ){
50240 u32 salt1;
50241 sqlite3_randomness(4, &salt1);
50242 assert( mxSafeFrame==pWal->hdr.mxFrame );
50243 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_READ_LOCK(1), WAL_NREADER-1);
50244 if( rc==SQLITE_OK ){
50245 if( eMode==SQLITE_CHECKPOINT_TRUNCATE ){
50246 /* IMPLEMENTATION-OF: R-44699-57140 This mode works the same way as
50247 ** SQLITE_CHECKPOINT_RESTART with the addition that it also
50248 ** truncates the log file to zero bytes just prior to a
50249 ** successful return.
50250 **
50251 ** In theory, it might be safe to do this without updating the
50252 ** wal-index header in shared memory, as all subsequent reader or
50253 ** writer clients should see that the entire log file has been
50254 ** checkpointed and behave accordingly. This seems unsafe though,
50255 ** as it would leave the system in a state where the contents of
50256 ** the wal-index header do not match the contents of the
50257 ** file-system. To avoid this, update the wal-index header to
50258 ** indicate that the log file contains zero valid frames. */
50259 walRestartHdr(pWal, salt1);
50260 rc = sqlite3OsTruncate(pWal->pWalFd, 0);
50261 }
50262 walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
50263 }
50264 }
50265 }
50266
@@ -50634,11 +50994,10 @@
50994 assert( walFramePgno(pWal, iFrame)!=1 );
50995 rc = xUndo(pUndoCtx, walFramePgno(pWal, iFrame));
50996 }
50997 if( iMax!=pWal->hdr.mxFrame ) walCleanupHash(pWal);
50998 }
 
50999 return rc;
51000 }
51001
51002 /*
51003 ** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
@@ -50683,11 +51042,10 @@
51042 }
51043
51044 return rc;
51045 }
51046
 
51047 /*
51048 ** This function is called just before writing a set of frames to the log
51049 ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
51050 ** to the current log file, it is possible to overwrite the start of the
51051 ** existing log file with the new frames (i.e. "reset" the log). If so,
@@ -50716,24 +51074,12 @@
51074 ** wal-index header to reflect this.
51075 **
51076 ** In theory it would be Ok to update the cache of the header only
51077 ** at this point. But updating the actual wal-index header is also
51078 ** safe and means there is no special case for sqlite3WalUndo()
51079 ** to handle if this transaction is rolled back. */
51080 walRestartHdr(pWal, salt1);
 
 
 
 
 
 
 
 
 
 
 
 
51081 walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
51082 }else if( rc!=SQLITE_BUSY ){
51083 return rc;
51084 }
51085 }
@@ -51017,11 +51363,11 @@
51363 ** If parameter xBusy is not NULL, it is a pointer to a busy-handler
51364 ** callback. In this case this function runs a blocking checkpoint.
51365 */
51366 SQLITE_PRIVATE int sqlite3WalCheckpoint(
51367 Wal *pWal, /* Wal connection */
51368 int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */
51369 int (*xBusy)(void*), /* Function to call when busy */
51370 void *pBusyArg, /* Context argument for xBusyHandler */
51371 int sync_flags, /* Flags to sync db file with (or 0) */
51372 int nBuf, /* Size of temporary buffer */
51373 u8 *zBuf, /* Temporary buffer to use */
@@ -51029,40 +51375,54 @@
51375 int *pnCkpt /* OUT: Number of backfilled frames in WAL */
51376 ){
51377 int rc; /* Return code */
51378 int isChanged = 0; /* True if a new wal-index header is loaded */
51379 int eMode2 = eMode; /* Mode to pass to walCheckpoint() */
51380 int (*xBusy2)(void*) = xBusy; /* Busy handler for eMode2 */
51381
51382 assert( pWal->ckptLock==0 );
51383 assert( pWal->writeLock==0 );
51384
51385 /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
51386 ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
51387 assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );
51388
51389 if( pWal->readOnly ) return SQLITE_READONLY;
51390 WALTRACE(("WAL%p: checkpoint begins\n", pWal));
51391
51392 /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive
51393 ** "checkpoint" lock on the database file. */
51394 rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
51395 if( rc ){
51396 /* EVIDENCE-OF: R-10421-19736 If any other process is running a
51397 ** checkpoint operation at the same time, the lock cannot be obtained and
51398 ** SQLITE_BUSY is returned.
51399 ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
51400 ** it will not be invoked in this case.
51401 */
51402 testcase( rc==SQLITE_BUSY );
51403 testcase( xBusy!=0 );
51404 return rc;
51405 }
51406 pWal->ckptLock = 1;
51407
51408 /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
51409 ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
51410 ** file.
51411 **
51412 ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
51413 ** immediately, and a busy-handler is configured, it is invoked and the
51414 ** writer lock retried until either the busy-handler returns 0 or the
51415 ** lock is successfully obtained.
51416 */
51417 if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
51418 rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1);
51419 if( rc==SQLITE_OK ){
51420 pWal->writeLock = 1;
51421 }else if( rc==SQLITE_BUSY ){
51422 eMode2 = SQLITE_CHECKPOINT_PASSIVE;
51423 xBusy2 = 0;
51424 rc = SQLITE_OK;
51425 }
51426 }
51427
51428 /* Read the wal-index header. */
@@ -51076,11 +51436,11 @@
51436 /* Copy data from the log to the database file. */
51437 if( rc==SQLITE_OK ){
51438 if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
51439 rc = SQLITE_CORRUPT_BKPT;
51440 }else{
51441 rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf);
51442 }
51443
51444 /* If no error occurred, set the output variables. */
51445 if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
51446 if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
@@ -51713,10 +52073,15 @@
52073 ** but cursors cannot be shared. Each cursor is associated with a
52074 ** particular database connection identified BtCursor.pBtree.db.
52075 **
52076 ** Fields in this structure are accessed under the BtShared.mutex
52077 ** found at self->pBt->mutex.
52078 **
52079 ** skipNext meaning:
52080 ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
52081 ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
52082 ** eState==FAULT: Cursor fault with skipNext as error code.
52083 */
52084 struct BtCursor {
52085 Btree *pBtree; /* The Btree to which this cursor belongs */
52086 BtShared *pBt; /* The BtShared this cursor points to */
52087 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
@@ -51725,11 +52090,12 @@
52090 CellInfo info; /* A parse of the cell we are pointing at */
52091 i64 nKey; /* Size of pKey, or last integer key */
52092 void *pKey; /* Saved key that was cursor last known position */
52093 Pgno pgnoRoot; /* The root page of this tree */
52094 int nOvflAlloc; /* Allocated size of aOverflow[] array */
52095 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
52096 ** Error code if eState==CURSOR_FAULT */
52097 u8 curFlags; /* zero or more BTCF_* flags defined below */
52098 u8 eState; /* One of the CURSOR_XXX constants (see below) */
52099 u8 hints; /* As configured by CursorSetHints() */
52100 i16 iPage; /* Index of current page in apPage */
52101 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
@@ -51771,11 +52137,11 @@
52137 ** CURSOR_FAULT:
52138 ** An unrecoverable error (an I/O error or a malloc failure) has occurred
52139 ** on a different connection that shares the BtShared cache with this
52140 ** cursor. The error has left the cache in an inconsistent state.
52141 ** Do nothing else with this cursor. Any attempt to use the cursor
52142 ** should return the error code stored in BtCursor.skipNext
52143 */
52144 #define CURSOR_INVALID 0
52145 #define CURSOR_VALID 1
52146 #define CURSOR_SKIPNEXT 2
52147 #define CURSOR_REQUIRESEEK 3
@@ -53321,10 +53687,15 @@
53687 /*
53688 ** Defragment the page given. All Cells are moved to the
53689 ** end of the page and all free space is collected into one
53690 ** big FreeBlk that occurs in between the header and cell
53691 ** pointer array and the cell content area.
53692 **
53693 ** EVIDENCE-OF: R-44582-60138 SQLite may from time to time reorganize a
53694 ** b-tree page so that there are no freeblocks or fragment bytes, all
53695 ** unused bytes are contained in the unallocated space region, and all
53696 ** cells are packed tightly at the end of the page.
53697 */
53698 static int defragmentPage(MemPage *pPage){
53699 int i; /* Loop counter */
53700 int pc; /* Address of the i-th cell */
53701 int hdr; /* Offset to the page header */
@@ -53333,28 +53704,27 @@
53704 int cellOffset; /* Offset to the cell pointer array */
53705 int cbrk; /* Offset to the cell content area */
53706 int nCell; /* Number of cells on the page */
53707 unsigned char *data; /* The page data */
53708 unsigned char *temp; /* Temp area for cell content */
53709 unsigned char *src; /* Source of content */
53710 int iCellFirst; /* First allowable cell index */
53711 int iCellLast; /* Last possible cell index */
53712
53713
53714 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53715 assert( pPage->pBt!=0 );
53716 assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
53717 assert( pPage->nOverflow==0 );
53718 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53719 temp = 0;
53720 src = data = pPage->aData;
53721 hdr = pPage->hdrOffset;
53722 cellOffset = pPage->cellOffset;
53723 nCell = pPage->nCell;
53724 assert( nCell==get2byte(&data[hdr+3]) );
53725 usableSize = pPage->pBt->usableSize;
 
 
53726 cbrk = usableSize;
53727 iCellFirst = cellOffset + 2*nCell;
53728 iCellLast = usableSize - 4;
53729 for(i=0; i<nCell; i++){
53730 u8 *pAddr; /* The i-th cell pointer */
@@ -53369,11 +53739,11 @@
53739 if( pc<iCellFirst || pc>iCellLast ){
53740 return SQLITE_CORRUPT_BKPT;
53741 }
53742 #endif
53743 assert( pc>=iCellFirst && pc<=iCellLast );
53744 size = cellSizePtr(pPage, &src[pc]);
53745 cbrk -= size;
53746 #if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
53747 if( cbrk<iCellFirst ){
53748 return SQLITE_CORRUPT_BKPT;
53749 }
@@ -53383,12 +53753,20 @@
53753 }
53754 #endif
53755 assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
53756 testcase( cbrk+size==usableSize );
53757 testcase( pc+size==usableSize );
 
53758 put2byte(pAddr, cbrk);
53759 if( temp==0 ){
53760 int x;
53761 if( cbrk==pc ) continue;
53762 temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
53763 x = get2byte(&data[hdr+5]);
53764 memcpy(&temp[x], &data[x], (cbrk+size) - x);
53765 src = temp;
53766 }
53767 memcpy(&data[cbrk], &src[pc], size);
53768 }
53769 assert( cbrk>=iCellFirst );
53770 put2byte(&data[hdr+5], cbrk);
53771 data[hdr+1] = 0;
53772 data[hdr+2] = 0;
@@ -53398,10 +53776,73 @@
53776 if( cbrk-iCellFirst!=pPage->nFree ){
53777 return SQLITE_CORRUPT_BKPT;
53778 }
53779 return SQLITE_OK;
53780 }
53781
53782 /*
53783 ** Search the free-list on page pPg for space to store a cell nByte bytes in
53784 ** size. If one can be found, return a pointer to the space and remove it
53785 ** from the free-list.
53786 **
53787 ** If no suitable space can be found on the free-list, return NULL.
53788 **
53789 ** This function may detect corruption within pPg. If corruption is
53790 ** detected then *pRc is set to SQLITE_CORRUPT and NULL is returned.
53791 **
53792 ** If a slot of at least nByte bytes is found but cannot be used because
53793 ** there are already at least 60 fragmented bytes on the page, return NULL.
53794 ** In this case, if pbDefrag parameter is not NULL, set *pbDefrag to true.
53795 */
53796 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc, int *pbDefrag){
53797 const int hdr = pPg->hdrOffset;
53798 u8 * const aData = pPg->aData;
53799 int iAddr;
53800 int pc;
53801 int usableSize = pPg->pBt->usableSize;
53802
53803 for(iAddr=hdr+1; (pc = get2byte(&aData[iAddr]))>0; iAddr=pc){
53804 int size; /* Size of the free slot */
53805 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
53806 ** increasing offset. */
53807 if( pc>usableSize-4 || pc<iAddr+4 ){
53808 *pRc = SQLITE_CORRUPT_BKPT;
53809 return 0;
53810 }
53811 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
53812 ** freeblock form a big-endian integer which is the size of the freeblock
53813 ** in bytes, including the 4-byte header. */
53814 size = get2byte(&aData[pc+2]);
53815 if( size>=nByte ){
53816 int x = size - nByte;
53817 testcase( x==4 );
53818 testcase( x==3 );
53819 if( x<4 ){
53820 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
53821 ** number of bytes in fragments may not exceed 60. */
53822 if( aData[hdr+7]>=60 ){
53823 if( pbDefrag ) *pbDefrag = 1;
53824 return 0;
53825 }
53826 /* Remove the slot from the free-list. Update the number of
53827 ** fragmented bytes within the page. */
53828 memcpy(&aData[iAddr], &aData[pc], 2);
53829 aData[hdr+7] += (u8)x;
53830 }else if( size+pc > usableSize ){
53831 *pRc = SQLITE_CORRUPT_BKPT;
53832 return 0;
53833 }else{
53834 /* The slot remains on the free-list. Reduce its size to account
53835 ** for the portion used by the new allocation. */
53836 put2byte(&aData[pc+2], x);
53837 }
53838 return &aData[pc + x];
53839 }
53840 }
53841
53842 return 0;
53843 }
53844
53845 /*
53846 ** Allocate nByte bytes of space from within the B-Tree page passed
53847 ** as the first argument. Write into *pIdx the index into pPage->aData[]
53848 ** of the first byte of allocated space. Return either SQLITE_OK or
@@ -53416,80 +53857,58 @@
53857 */
53858 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
53859 const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */
53860 u8 * const data = pPage->aData; /* Local cache of pPage->aData */
53861 int top; /* First byte of cell content area */
53862 int rc = SQLITE_OK; /* Integer return code */
53863 int gap; /* First byte of gap between cell pointers and cell content */
 
 
53864
53865 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53866 assert( pPage->pBt );
53867 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53868 assert( nByte>=0 ); /* Minimum cell size is 4 */
53869 assert( pPage->nFree>=nByte );
53870 assert( pPage->nOverflow==0 );
53871 assert( nByte < (int)(pPage->pBt->usableSize-8) );
 
53872
53873 assert( pPage->cellOffset == hdr + 12 - 4*pPage->leaf );
53874 gap = pPage->cellOffset + 2*pPage->nCell;
53875 assert( gap<=65536 );
53876 /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size
53877 ** and the reserved space is zero (the usual value for reserved space)
53878 ** then the cell content offset of an empty page wants to be 65536.
53879 ** However, that integer is too large to be stored in a 2-byte unsigned
53880 ** integer, so a value of 0 is used in its place. */
53881 top = get2byteNotZero(&data[hdr+5]);
53882 if( gap>top ) return SQLITE_CORRUPT_BKPT;
 
53883
53884 /* If there is enough space between gap and top for one more cell pointer
53885 ** array entry offset, and if the freelist is not empty, then search the
53886 ** freelist looking for a free slot big enough to satisfy the request.
53887 */
53888 testcase( gap+2==top );
53889 testcase( gap+1==top );
53890 testcase( gap==top );
53891 if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
53892 int bDefrag = 0;
53893 u8 *pSpace = pageFindSlot(pPage, nByte, &rc, &bDefrag);
53894 if( rc ) return rc;
53895 if( bDefrag ) goto defragment_page;
53896 if( pSpace ){
53897 assert( pSpace>=data && (pSpace - data)<65536 );
53898 *pIdx = (int)(pSpace - data);
53899 return SQLITE_OK;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53900 }
53901 }
53902
53903 /* The request could not be fulfilled using a freelist slot. Check
53904 ** to see if defragmentation is necessary.
53905 */
53906 testcase( gap+2+nByte==top );
53907 if( gap+2+nByte>top ){
53908 defragment_page:
53909 assert( pPage->nCell>0 || CORRUPT_DB );
53910 rc = defragmentPage(pPage);
53911 if( rc ) return rc;
53912 top = get2byteNotZero(&data[hdr+5]);
53913 assert( gap+nByte<=top );
53914 }
@@ -53532,11 +53951,11 @@
53951 unsigned char *data = pPage->aData; /* Page content */
53952
53953 assert( pPage->pBt!=0 );
53954 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
53955 assert( iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
53956 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
53957 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
53958 assert( iSize>=4 ); /* Minimum cell size is 4 */
53959 assert( iStart<=iLast );
53960
53961 /* Overwrite deleted information with zeros when the secure_delete
@@ -53627,22 +54046,36 @@
54046 pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
54047 flagByte &= ~PTF_LEAF;
54048 pPage->childPtrSize = 4-4*pPage->leaf;
54049 pBt = pPage->pBt;
54050 if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
54051 /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior
54052 ** table b-tree page. */
54053 assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
54054 /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf
54055 ** table b-tree page. */
54056 assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
54057 pPage->intKey = 1;
54058 pPage->intKeyLeaf = pPage->leaf;
54059 pPage->noPayload = !pPage->leaf;
54060 pPage->maxLocal = pBt->maxLeaf;
54061 pPage->minLocal = pBt->minLeaf;
54062 }else if( flagByte==PTF_ZERODATA ){
54063 /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior
54064 ** index b-tree page. */
54065 assert( (PTF_ZERODATA)==2 );
54066 /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf
54067 ** index b-tree page. */
54068 assert( (PTF_ZERODATA|PTF_LEAF)==10 );
54069 pPage->intKey = 0;
54070 pPage->intKeyLeaf = 0;
54071 pPage->noPayload = 0;
54072 pPage->maxLocal = pBt->maxLocal;
54073 pPage->minLocal = pBt->minLocal;
54074 }else{
54075 /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
54076 ** an error. */
54077 return SQLITE_CORRUPT_BKPT;
54078 }
54079 pPage->max1bytePayload = pBt->max1bytePayload;
54080 return SQLITE_OK;
54081 }
@@ -53678,25 +54111,37 @@
54111
54112 pBt = pPage->pBt;
54113
54114 hdr = pPage->hdrOffset;
54115 data = pPage->aData;
54116 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
54117 ** the b-tree page type. */
54118 if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
54119 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
54120 pPage->maskPage = (u16)(pBt->pageSize - 1);
54121 pPage->nOverflow = 0;
54122 usableSize = pBt->usableSize;
54123 pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
54124 pPage->aDataEnd = &data[usableSize];
54125 pPage->aCellIdx = &data[cellOffset];
54126 /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
54127 ** the start of the cell content area. A zero value for this integer is
54128 ** interpreted as 65536. */
54129 top = get2byteNotZero(&data[hdr+5]);
54130 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
54131 ** number of cells on the page. */
54132 pPage->nCell = get2byte(&data[hdr+3]);
54133 if( pPage->nCell>MX_CELL(pBt) ){
54134 /* To many cells for a single page. The page must be corrupt */
54135 return SQLITE_CORRUPT_BKPT;
54136 }
54137 testcase( pPage->nCell==MX_CELL(pBt) );
54138 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
54139 ** possible for a root page of a table that contains no rows) then the
54140 ** offset to the cell content area will equal the page size minus the
54141 ** bytes of reserved space. */
54142 assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
54143
54144 /* A malformed database page might cause us to read past the end
54145 ** of page when parsing a cell.
54146 **
54147 ** The following block of code checks early to see if a cell extends
@@ -53726,17 +54171,24 @@
54171 }
54172 if( !pPage->leaf ) iCellLast++;
54173 }
54174 #endif
54175
54176 /* Compute the total free space on the page
54177 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
54178 ** start of the first freeblock on the page, or is zero if there are no
54179 ** freeblocks. */
54180 pc = get2byte(&data[hdr+1]);
54181 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
54182 while( pc>0 ){
54183 u16 next, size;
54184 if( pc<iCellFirst || pc>iCellLast ){
54185 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
54186 ** always be at least one cell before the first freeblock.
54187 **
54188 ** Or, the freeblock is off the end of the page
54189 */
54190 return SQLITE_CORRUPT_BKPT;
54191 }
54192 next = get2byte(&data[pc]);
54193 size = get2byte(&data[pc+2]);
54194 if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
@@ -54138,10 +54590,13 @@
54590 pBt->pPage1 = 0;
54591 if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
54592 #ifdef SQLITE_SECURE_DELETE
54593 pBt->btsFlags |= BTS_SECURE_DELETE;
54594 #endif
54595 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
54596 ** determined by the 2-byte integer located at an offset of 16 bytes from
54597 ** the beginning of the database file. */
54598 pBt->pageSize = (zDbHeader[16]<<8) | (zDbHeader[17]<<16);
54599 if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
54600 || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
54601 pBt->pageSize = 0;
54602 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -54156,10 +54611,13 @@
54611 pBt->incrVacuum = (SQLITE_DEFAULT_AUTOVACUUM==2 ? 1 : 0);
54612 }
54613 #endif
54614 nReserve = 0;
54615 }else{
54616 /* EVIDENCE-OF: R-37497-42412 The size of the reserved region is
54617 ** determined by the one-byte unsigned integer found at an offset of 20
54618 ** into the database file header. */
54619 nReserve = zDbHeader[20];
54620 pBt->btsFlags |= BTS_PAGESIZE_FIXED;
54621 #ifndef SQLITE_OMIT_AUTOVACUUM
54622 pBt->autoVacuum = (get4byte(&zDbHeader[36 + 4*4])?1:0);
54623 pBt->incrVacuum = (get4byte(&zDbHeader[36 + 7*4])?1:0);
@@ -54353,11 +54811,11 @@
54811
54812 /* Rollback any active transaction and free the handle structure.
54813 ** The call to sqlite3BtreeRollback() drops any table-locks held by
54814 ** this handle.
54815 */
54816 sqlite3BtreeRollback(p, SQLITE_OK, 0);
54817 sqlite3BtreeLeave(p);
54818
54819 /* If there are still other outstanding references to the shared-btree
54820 ** structure, return now. The remainder of this procedure cleans
54821 ** up the shared-btree.
@@ -54665,10 +55123,13 @@
55123 if( nPage>0 ){
55124 u32 pageSize;
55125 u32 usableSize;
55126 u8 *page1 = pPage1->aData;
55127 rc = SQLITE_NOTADB;
55128 /* EVIDENCE-OF: R-43737-39999 Every valid SQLite database file begins
55129 ** with the following 16 bytes (in hex): 53 51 4c 69 74 65 20 66 6f 72 6d
55130 ** 61 74 20 33 00. */
55131 if( memcmp(page1, zMagicHeader, 16)!=0 ){
55132 goto page1_init_failed;
55133 }
55134
55135 #ifdef SQLITE_OMIT_WAL
@@ -54705,26 +55166,39 @@
55166 }
55167 rc = SQLITE_NOTADB;
55168 }
55169 #endif
55170
55171 /* EVIDENCE-OF: R-15465-20813 The maximum and minimum embedded payload
55172 ** fractions and the leaf payload fraction values must be 64, 32, and 32.
55173 **
55174 ** The original design allowed these amounts to vary, but as of
55175 ** version 3.6.0, we require them to be fixed.
55176 */
55177 if( memcmp(&page1[21], "\100\040\040",3)!=0 ){
55178 goto page1_init_failed;
55179 }
55180 /* EVIDENCE-OF: R-51873-39618 The page size for a database file is
55181 ** determined by the 2-byte integer located at an offset of 16 bytes from
55182 ** the beginning of the database file. */
55183 pageSize = (page1[16]<<8) | (page1[17]<<16);
55184 /* EVIDENCE-OF: R-25008-21688 The size of a page is a power of two
55185 ** between 512 and 65536 inclusive. */
55186 if( ((pageSize-1)&pageSize)!=0
55187 || pageSize>SQLITE_MAX_PAGE_SIZE
55188 || pageSize<=256
55189 ){
55190 goto page1_init_failed;
55191 }
55192 assert( (pageSize & 7)==0 );
55193 /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte
55194 ** integer at offset 20 is the number of bytes of space at the end of
55195 ** each page to reserve for extensions.
55196 **
55197 ** EVIDENCE-OF: R-37497-42412 The size of the reserved region is
55198 ** determined by the one-byte unsigned integer found at an offset of 20
55199 ** into the database file header. */
55200 usableSize = pageSize - page1[20];
55201 if( (u32)pageSize!=pBt->pageSize ){
55202 /* After reading the first page of the database assuming a page size
55203 ** of BtShared.pageSize, we have discovered that the page-size is
55204 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
@@ -54741,10 +55215,13 @@
55215 }
55216 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPage>nPageFile ){
55217 rc = SQLITE_CORRUPT_BKPT;
55218 goto page1_init_failed;
55219 }
55220 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
55221 ** be less than 480. In other words, if the page size is 512, then the
55222 ** reserved space size cannot exceed 32. */
55223 if( usableSize<480 ){
55224 goto page1_init_failed;
55225 }
55226 pBt->pageSize = pageSize;
55227 pBt->usableSize = usableSize;
@@ -55646,64 +56123,95 @@
56123 return rc;
56124 }
56125
56126 /*
56127 ** This routine sets the state to CURSOR_FAULT and the error
56128 ** code to errCode for every cursor on any BtShared that pBtree
56129 ** references. Or if the writeOnly flag is set to 1, then only
56130 ** trip write cursors and leave read cursors unchanged.
56131 **
56132 ** Every cursor is a candidate to be tripped, including cursors
56133 ** that belong to other database connections that happen to be
56134 ** sharing the cache with pBtree.
56135 **
56136 ** This routine gets called when a rollback occurs. If the writeOnly
56137 ** flag is true, then only write-cursors need be tripped - read-only
56138 ** cursors save their current positions so that they may continue
56139 ** following the rollback. Or, if writeOnly is false, all cursors are
56140 ** tripped. In general, writeOnly is false if the transaction being
56141 ** rolled back modified the database schema. In this case b-tree root
56142 ** pages may be moved or deleted from the database altogether, making
56143 ** it unsafe for read cursors to continue.
56144 **
56145 ** If the writeOnly flag is true and an error is encountered while
56146 ** saving the current position of a read-only cursor, all cursors,
56147 ** including all read-cursors are tripped.
56148 **
56149 ** SQLITE_OK is returned if successful, or if an error occurs while
56150 ** saving a cursor position, an SQLite error code.
56151 */
56152 SQLITE_PRIVATE int sqlite3BtreeTripAllCursors(Btree *pBtree, int errCode, int writeOnly){
56153 BtCursor *p;
56154 int rc = SQLITE_OK;
56155
56156 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
56157 if( pBtree ){
56158 sqlite3BtreeEnter(pBtree);
56159 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
56160 int i;
56161 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
56162 if( p->eState==CURSOR_VALID ){
56163 rc = saveCursorPosition(p);
56164 if( rc!=SQLITE_OK ){
56165 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
56166 break;
56167 }
56168 }
56169 }else{
56170 sqlite3BtreeClearCursor(p);
56171 p->eState = CURSOR_FAULT;
56172 p->skipNext = errCode;
56173 }
56174 for(i=0; i<=p->iPage; i++){
56175 releasePage(p->apPage[i]);
56176 p->apPage[i] = 0;
56177 }
56178 }
56179 sqlite3BtreeLeave(pBtree);
56180 }
56181 return rc;
56182 }
56183
56184 /*
56185 ** Rollback the transaction in progress.
56186 **
56187 ** If tripCode is not SQLITE_OK then cursors will be invalidated (tripped).
56188 ** Only write cursors are tripped if writeOnly is true but all cursors are
56189 ** tripped if writeOnly is false. Any attempt to use
56190 ** a tripped cursor will result in an error.
56191 **
56192 ** This will release the write lock on the database file. If there
56193 ** are no active cursors, it also releases the read lock.
56194 */
56195 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p, int tripCode, int writeOnly){
56196 int rc;
56197 BtShared *pBt = p->pBt;
56198 MemPage *pPage1;
56199
56200 assert( writeOnly==1 || writeOnly==0 );
56201 assert( tripCode==SQLITE_ABORT_ROLLBACK || tripCode==SQLITE_OK );
56202 sqlite3BtreeEnter(p);
56203 if( tripCode==SQLITE_OK ){
56204 rc = tripCode = saveAllCursors(pBt, 0, 0);
56205 if( rc ) writeOnly = 0;
56206 }else{
56207 rc = SQLITE_OK;
56208 }
56209 if( tripCode ){
56210 int rc2 = sqlite3BtreeTripAllCursors(p, tripCode, writeOnly);
56211 assert( rc==SQLITE_OK || (writeOnly==0 && rc2==SQLITE_OK) );
56212 if( rc2!=SQLITE_OK ) rc = rc2;
56213 }
56214 btreeIntegrity(p);
56215
56216 if( p->inTrans==TRANS_WRITE ){
56217 int rc2;
@@ -56034,17 +56542,13 @@
56542 **
56543 ** This routine cannot fail. It always returns SQLITE_OK.
56544 */
56545 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){
56546 assert( cursorHoldsMutex(pCur) );
56547 assert( pCur->eState==CURSOR_VALID );
56548 getCellInfo(pCur);
56549 *pSize = pCur->info.nKey;
 
 
 
 
56550 return SQLITE_OK;
56551 }
56552
56553 /*
56554 ** Set *pSize to the number of bytes of data in the entry the
@@ -57291,10 +57795,12 @@
57795
57796 assert( sqlite3_mutex_held(pBt->mutex) );
57797 assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) );
57798 pPage1 = pBt->pPage1;
57799 mxPage = btreePagecount(pBt);
57800 /* EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36
57801 ** stores stores the total number of pages on the freelist. */
57802 n = get4byte(&pPage1->aData[36]);
57803 testcase( n==mxPage-1 );
57804 if( n>=mxPage ){
57805 return SQLITE_CORRUPT_BKPT;
57806 }
@@ -57337,12 +57843,18 @@
57843 ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT)
57844 */
57845 do {
57846 pPrevTrunk = pTrunk;
57847 if( pPrevTrunk ){
57848 /* EVIDENCE-OF: R-01506-11053 The first integer on a freelist trunk page
57849 ** is the page number of the next freelist trunk page in the list or
57850 ** zero if this is the last freelist trunk page. */
57851 iTrunk = get4byte(&pPrevTrunk->aData[0]);
57852 }else{
57853 /* EVIDENCE-OF: R-59841-13798 The 4-byte big-endian integer at offset 32
57854 ** stores the page number of the first page of the freelist, or zero if
57855 ** the freelist is empty. */
57856 iTrunk = get4byte(&pPage1->aData[32]);
57857 }
57858 testcase( iTrunk==mxPage );
57859 if( iTrunk>mxPage ){
57860 rc = SQLITE_CORRUPT_BKPT;
@@ -57353,12 +57865,13 @@
57865 pTrunk = 0;
57866 goto end_allocate_page;
57867 }
57868 assert( pTrunk!=0 );
57869 assert( pTrunk->aData!=0 );
57870 /* EVIDENCE-OF: R-13523-04394 The second integer on a freelist trunk page
57871 ** is the number of leaf page pointers to follow. */
57872 k = get4byte(&pTrunk->aData[4]);
57873 if( k==0 && !searchList ){
57874 /* The trunk has no leaves and the list is not being searched.
57875 ** So extract the trunk page itself and use it as the newly
57876 ** allocated page */
57877 assert( pPrevTrunk==0 );
@@ -57672,10 +58185,15 @@
58185 ** to maintain backwards compatibility with older versions of SQLite,
58186 ** we will continue to restrict the number of entries to usableSize/4 - 8
58187 ** for now. At some point in the future (once everyone has upgraded
58188 ** to 3.6.0 or later) we should consider fixing the conditional above
58189 ** to read "usableSize/4-2" instead of "usableSize/4-8".
58190 **
58191 ** EVIDENCE-OF: R-19920-11576 However, newer versions of SQLite still
58192 ** avoid using the last six entries in the freelist trunk page array in
58193 ** order that database files created by newer versions of SQLite can be
58194 ** read by older versions of SQLite.
58195 */
58196 rc = sqlite3PagerWrite(pTrunk->pDbPage);
58197 if( rc==SQLITE_OK ){
58198 put4byte(&pTrunk->aData[4], nLeaf+1);
58199 put4byte(&pTrunk->aData[8+nLeaf*4], iPage);
@@ -58023,13 +58541,21 @@
58541 if( rc ){
58542 *pRC = rc;
58543 return;
58544 }
58545 pPage->nCell--;
58546 if( pPage->nCell==0 ){
58547 memset(&data[hdr+1], 0, 4);
58548 data[hdr+7] = 0;
58549 put2byte(&data[hdr+5], pPage->pBt->usableSize);
58550 pPage->nFree = pPage->pBt->usableSize - pPage->hdrOffset
58551 - pPage->childPtrSize - 8;
58552 }else{
58553 memmove(ptr, ptr+2, 2*(pPage->nCell - idx));
58554 put2byte(&data[hdr+3], pPage->nCell);
58555 pPage->nFree += 2;
58556 }
58557 }
58558
58559 /*
58560 ** Insert a new cell on pPage at cell index "i". pCell points to the
58561 ** content of the cell.
@@ -58120,49 +58646,275 @@
58646 #endif
58647 }
58648 }
58649
58650 /*
58651 ** Array apCell[] contains pointers to nCell b-tree page cells. The
58652 ** szCell[] array contains the size in bytes of each cell. This function
58653 ** replaces the current contents of page pPg with the contents of the cell
58654 ** array.
58655 **
58656 ** Some of the cells in apCell[] may currently be stored in pPg. This
58657 ** function works around problems caused by this by making a copy of any
58658 ** such cells before overwriting the page data.
58659 **
58660 ** The MemPage.nFree field is invalidated by this function. It is the
58661 ** responsibility of the caller to set it correctly.
58662 */
58663 static void rebuildPage(
58664 MemPage *pPg, /* Edit this page */
58665 int nCell, /* Final number of cells on page */
58666 u8 **apCell, /* Array of cells */
58667 u16 *szCell /* Array of cell sizes */
58668 ){
58669 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
58670 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
58671 const int usableSize = pPg->pBt->usableSize;
58672 u8 * const pEnd = &aData[usableSize];
58673 int i;
58674 u8 *pCellptr = pPg->aCellIdx;
58675 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58676 u8 *pData;
58677
58678 i = get2byte(&aData[hdr+5]);
58679 memcpy(&pTmp[i], &aData[i], usableSize - i);
58680
58681 pData = pEnd;
58682 for(i=0; i<nCell; i++){
58683 u8 *pCell = apCell[i];
58684 if( pCell>aData && pCell<pEnd ){
58685 pCell = &pTmp[pCell - aData];
58686 }
58687 pData -= szCell[i];
58688 memcpy(pData, pCell, szCell[i]);
58689 put2byte(pCellptr, (pData - aData));
58690 pCellptr += 2;
58691 assert( szCell[i]==cellSizePtr(pPg, pCell) );
58692 }
58693
58694 /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
58695 pPg->nCell = nCell;
58696 pPg->nOverflow = 0;
58697
58698 put2byte(&aData[hdr+1], 0);
58699 put2byte(&aData[hdr+3], pPg->nCell);
58700 put2byte(&aData[hdr+5], pData - aData);
58701 aData[hdr+7] = 0x00;
58702 }
58703
58704 /*
58705 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58706 ** contains the size in bytes of each such cell. This function attempts to
58707 ** add the cells stored in the array to page pPg. If it cannot (because
58708 ** the page needs to be defragmented before the cells will fit), non-zero
58709 ** is returned. Otherwise, if the cells are added successfully, zero is
58710 ** returned.
58711 **
58712 ** Argument pCellptr points to the first entry in the cell-pointer array
58713 ** (part of page pPg) to populate. After cell apCell[0] is written to the
58714 ** page body, a 16-bit offset is written to pCellptr. And so on, for each
58715 ** cell in the array. It is the responsibility of the caller to ensure
58716 ** that it is safe to overwrite this part of the cell-pointer array.
58717 **
58718 ** When this function is called, *ppData points to the start of the
58719 ** content area on page pPg. If the size of the content area is extended,
58720 ** *ppData is updated to point to the new start of the content area
58721 ** before returning.
58722 **
58723 ** Finally, argument pBegin points to the byte immediately following the
58724 ** end of the space required by this page for the cell-pointer area (for
58725 ** all cells - not just those inserted by the current call). If the content
58726 ** area must be extended to before this point in order to accomodate all
58727 ** cells in apCell[], then the cells do not fit and non-zero is returned.
58728 */
58729 static int pageInsertArray(
58730 MemPage *pPg, /* Page to add cells to */
58731 u8 *pBegin, /* End of cell-pointer array */
58732 u8 **ppData, /* IN/OUT: Page content -area pointer */
58733 u8 *pCellptr, /* Pointer to cell-pointer area */
58734 int nCell, /* Number of cells to add to pPg */
58735 u8 **apCell, /* Array of cells */
58736 u16 *szCell /* Array of cell sizes */
58737 ){
58738 int i;
58739 u8 *aData = pPg->aData;
58740 u8 *pData = *ppData;
58741 const int bFreelist = aData[1] || aData[2];
58742 assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
58743 for(i=0; i<nCell; i++){
58744 int sz = szCell[i];
58745 int rc;
58746 u8 *pSlot;
58747 if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
58748 pData -= sz;
58749 if( pData<pBegin ) return 1;
58750 pSlot = pData;
58751 }
58752 memcpy(pSlot, apCell[i], sz);
58753 put2byte(pCellptr, (pSlot - aData));
58754 pCellptr += 2;
58755 }
58756 *ppData = pData;
58757 return 0;
58758 }
58759
58760 /*
58761 ** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
58762 ** contains the size in bytes of each such cell. This function adds the
58763 ** space associated with each cell in the array that is currently stored
58764 ** within the body of pPg to the pPg free-list. The cell-pointers and other
58765 ** fields of the page are not updated.
58766 **
58767 ** This function returns the total number of cells added to the free-list.
58768 */
58769 static int pageFreeArray(
58770 MemPage *pPg, /* Page to edit */
58771 int nCell, /* Cells to delete */
58772 u8 **apCell, /* Array of cells */
58773 u16 *szCell /* Array of cell sizes */
58774 ){
58775 u8 * const aData = pPg->aData;
58776 u8 * const pEnd = &aData[pPg->pBt->usableSize];
58777 u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
58778 int nRet = 0;
58779 int i;
58780 u8 *pFree = 0;
58781 int szFree = 0;
58782
58783 for(i=0; i<nCell; i++){
58784 u8 *pCell = apCell[i];
58785 if( pCell>=pStart && pCell<pEnd ){
58786 int sz = szCell[i];
58787 if( pFree!=(pCell + sz) ){
58788 if( pFree ){
58789 assert( pFree>aData && (pFree - aData)<65536 );
58790 freeSpace(pPg, (u16)(pFree - aData), szFree);
58791 }
58792 pFree = pCell;
58793 szFree = sz;
58794 if( pFree+sz>pEnd ) return 0;
58795 }else{
58796 pFree = pCell;
58797 szFree += sz;
58798 }
58799 nRet++;
58800 }
58801 }
58802 if( pFree ){
58803 assert( pFree>aData && (pFree - aData)<65536 );
58804 freeSpace(pPg, (u16)(pFree - aData), szFree);
58805 }
58806 return nRet;
58807 }
58808
58809 /*
58810 ** apCell[] and szCell[] contains pointers to and sizes of all cells in the
58811 ** pages being balanced. The current page, pPg, has pPg->nCell cells starting
58812 ** with apCell[iOld]. After balancing, this page should hold nNew cells
58813 ** starting at apCell[iNew].
58814 **
58815 ** This routine makes the necessary adjustments to pPg so that it contains
58816 ** the correct cells after being balanced.
58817 **
58818 ** The pPg->nFree field is invalid when this function returns. It is the
58819 ** responsibility of the caller to set it correctly.
58820 */
58821 static void editPage(
58822 MemPage *pPg, /* Edit this page */
58823 int iOld, /* Index of first cell currently on page */
58824 int iNew, /* Index of new first cell on page */
58825 int nNew, /* Final number of cells on page */
58826 u8 **apCell, /* Array of cells */
58827 u16 *szCell /* Array of cell sizes */
58828 ){
58829 u8 * const aData = pPg->aData;
58830 const int hdr = pPg->hdrOffset;
58831 u8 *pBegin = &pPg->aCellIdx[nNew * 2];
58832 int nCell = pPg->nCell; /* Cells stored on pPg */
58833 u8 *pData;
58834 u8 *pCellptr;
58835 int i;
58836 int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
58837 int iNewEnd = iNew + nNew;
58838
58839 #ifdef SQLITE_DEBUG
58840 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
58841 memcpy(pTmp, aData, pPg->pBt->usableSize);
58842 #endif
58843
58844 /* Remove cells from the start and end of the page */
58845 if( iOld<iNew ){
58846 int nShift = pageFreeArray(
58847 pPg, iNew-iOld, &apCell[iOld], &szCell[iOld]
58848 );
58849 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
58850 nCell -= nShift;
58851 }
58852 if( iNewEnd < iOldEnd ){
58853 nCell -= pageFreeArray(
58854 pPg, iOldEnd-iNewEnd, &apCell[iNewEnd], &szCell[iNewEnd]
58855 );
58856 }
58857
58858 pData = &aData[get2byteNotZero(&aData[hdr+5])];
58859 if( pData<pBegin ) goto editpage_fail;
58860
58861 /* Add cells to the start of the page */
58862 if( iNew<iOld ){
58863 int nAdd = MIN(nNew,iOld-iNew);
58864 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
58865 pCellptr = pPg->aCellIdx;
58866 memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
58867 if( pageInsertArray(
58868 pPg, pBegin, &pData, pCellptr,
58869 nAdd, &apCell[iNew], &szCell[iNew]
58870 ) ) goto editpage_fail;
58871 nCell += nAdd;
58872 }
58873
58874 /* Add any overflow cells */
58875 for(i=0; i<pPg->nOverflow; i++){
58876 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
58877 if( iCell>=0 && iCell<nNew ){
58878 pCellptr = &pPg->aCellIdx[iCell * 2];
58879 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
58880 nCell++;
58881 if( pageInsertArray(
58882 pPg, pBegin, &pData, pCellptr,
58883 1, &apCell[iCell + iNew], &szCell[iCell + iNew]
58884 ) ) goto editpage_fail;
58885 }
58886 }
58887
58888 /* Append cells to the end of the page */
58889 pCellptr = &pPg->aCellIdx[nCell*2];
58890 if( pageInsertArray(
58891 pPg, pBegin, &pData, pCellptr,
58892 nNew-nCell, &apCell[iNew+nCell], &szCell[iNew+nCell]
58893 ) ) goto editpage_fail;
58894
58895 pPg->nCell = nNew;
58896 pPg->nOverflow = 0;
58897
58898 put2byte(&aData[hdr+3], pPg->nCell);
58899 put2byte(&aData[hdr+5], pData - aData);
58900
58901 #ifdef SQLITE_DEBUG
58902 for(i=0; i<nNew && !CORRUPT_DB; i++){
58903 u8 *pCell = apCell[i+iNew];
58904 int iOff = get2byte(&pPg->aCellIdx[i*2]);
58905 if( pCell>=aData && pCell<&aData[pPg->pBt->usableSize] ){
58906 pCell = &pTmp[pCell - aData];
58907 }
58908 assert( 0==memcmp(pCell, &aData[iOff], szCell[i+iNew]) );
58909 }
58910 #endif
58911
58912 return;
58913 editpage_fail:
58914 /* Unable to edit this page. Rebuild it from scratch instead. */
58915 rebuildPage(pPg, nNew, &apCell[iNew], &szCell[iNew]);
58916 }
58917
58918 /*
58919 ** The following parameters determine how many adjacent pages get involved
58920 ** in a balancing operation. NN is the number of neighbors on either side
@@ -58212,11 +58964,11 @@
58964 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
58965 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
58966 assert( pPage->nOverflow==1 );
58967
58968 /* This error condition is now caught prior to reaching this function */
58969 if( NEVER(pPage->nCell==0) ) return SQLITE_CORRUPT_BKPT;
58970
58971 /* Allocate a new page. This page will become the right-sibling of
58972 ** pPage. Make the parent page writable, so that the new divider cell
58973 ** may be inserted. If both these operations are successful, proceed.
58974 */
@@ -58230,11 +58982,12 @@
58982 u8 *pStop;
58983
58984 assert( sqlite3PagerIswriteable(pNew->pDbPage) );
58985 assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
58986 zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
58987 rebuildPage(pNew, 1, &pCell, &szCell);
58988 pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
58989
58990 /* If this is an auto-vacuum database, update the pointer map
58991 ** with entries for the new page, and any pointer from the
58992 ** cell on the page to an overflow page. If either of these
58993 ** operations fails, the return code is set, but the contents
@@ -58449,21 +59202,26 @@
59202 int subtotal; /* Subtotal of bytes in cells on one page */
59203 int iSpace1 = 0; /* First unused byte of aSpace1[] */
59204 int iOvflSpace = 0; /* First unused byte of aOvflSpace[] */
59205 int szScratch; /* Size of scratch memory requested */
59206 MemPage *apOld[NB]; /* pPage and up to two siblings */
 
59207 MemPage *apNew[NB+2]; /* pPage and up to NB siblings after balancing */
59208 u8 *pRight; /* Location in parent of right-sibling pointer */
59209 u8 *apDiv[NB-1]; /* Divider cells in pParent */
59210 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
59211 int cntOld[NB+2]; /* Old index in aCell[] after i-th page */
59212 int szNew[NB+2]; /* Combined size of cells placed on i-th page */
59213 u8 **apCell = 0; /* All cells begin balanced */
59214 u16 *szCell; /* Local size of all cells in apCell[] */
59215 u8 *aSpace1; /* Space for copies of dividers cells */
59216 Pgno pgno; /* Temp var to store a page number in */
59217 u8 abDone[NB+2]; /* True after i'th new page is populated */
59218 Pgno aPgno[NB+2]; /* Page numbers of new pages before shuffling */
59219 Pgno aPgOrder[NB+2]; /* Copy of aPgno[] used for sorting pages */
59220 u16 aPgFlags[NB+2]; /* flags field of new pages before shuffling */
59221
59222 memset(abDone, 0, sizeof(abDone));
59223 pBt = pParent->pBt;
59224 assert( sqlite3_mutex_held(pBt->mutex) );
59225 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59226
59227 #if 0
@@ -58568,16 +59326,18 @@
59326 nMaxCells = (nMaxCells + 3)&~3;
59327
59328 /*
59329 ** Allocate space for memory structures
59330 */
 
59331 szScratch =
59332 nMaxCells*sizeof(u8*) /* apCell */
59333 + nMaxCells*sizeof(u16) /* szCell */
59334 + pBt->pageSize; /* aSpace1 */
59335
59336 /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
59337 ** that is more than 6 times the database page size. */
59338 assert( szScratch<=6*(int)pBt->pageSize );
59339 apCell = sqlite3ScratchMalloc( szScratch );
59340 if( apCell==0 ){
59341 rc = SQLITE_NOMEM;
59342 goto balance_cleanup;
59343 }
@@ -58586,12 +59346,12 @@
59346 assert( EIGHT_BYTE_ALIGNMENT(aSpace1) );
59347
59348 /*
59349 ** Load pointers to all cells on sibling pages and the divider cells
59350 ** into the local apCell[] array. Make copies of the divider cells
59351 ** into space obtained from aSpace1[]. The divider cells have already
59352 ** been removed from pParent.
59353 **
59354 ** If the siblings are on leaf pages, then the child pointers of the
59355 ** divider cells are stripped from the cells before they are copied
59356 ** into aSpace1[]. In this way, all cells in apCell[] are without
59357 ** child pointers. If siblings are not leaves, then all cell in
@@ -58603,19 +59363,11 @@
59363 */
59364 leafCorrection = apOld[0]->leaf*4;
59365 leafData = apOld[0]->intKeyLeaf;
59366 for(i=0; i<nOld; i++){
59367 int limit;
59368 MemPage *pOld = apOld[i];
 
 
 
 
 
 
 
 
59369
59370 limit = pOld->nCell+pOld->nOverflow;
59371 if( pOld->nOverflow>0 ){
59372 for(j=0; j<limit; j++){
59373 assert( nCell<nMaxCells );
@@ -58632,10 +59384,11 @@
59384 apCell[nCell] = findCellv2(aData, maskPage, cellOffset, j);
59385 szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
59386 nCell++;
59387 }
59388 }
59389 cntOld[i] = nCell;
59390 if( i<nOld-1 && !leafData){
59391 u16 sz = (u16)szNew[i];
59392 u8 *pTemp;
59393 assert( nCell<nMaxCells );
59394 szCell[nCell] = sz;
@@ -58654,11 +59407,15 @@
59407 ** pointer of the divider cell */
59408 memcpy(apCell[nCell], &pOld->aData[8], 4);
59409 }else{
59410 assert( leafCorrection==4 );
59411 if( szCell[nCell]<4 ){
59412 /* Do not allow any cells smaller than 4 bytes. If a smaller cell
59413 ** does exist, pad it with 0x00 bytes. */
59414 assert( szCell[nCell]==3 );
59415 assert( apCell[nCell]==&pTemp[iSpace1-3] );
59416 pTemp[iSpace1++] = 0x00;
59417 szCell[nCell] = 4;
59418 }
59419 }
59420 nCell++;
59421 }
@@ -58683,11 +59440,11 @@
59440 usableSpace = pBt->usableSize - 12 + leafCorrection;
59441 for(subtotal=k=i=0; i<nCell; i++){
59442 assert( i<nMaxCells );
59443 subtotal += szCell[i] + 2;
59444 if( subtotal > usableSpace ){
59445 szNew[k] = subtotal - szCell[i] - 2;
59446 cntNew[k] = i;
59447 if( leafData ){ i--; }
59448 subtotal = 0;
59449 k++;
59450 if( k>NB+1 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; }
@@ -58697,13 +59454,14 @@
59454 cntNew[k] = nCell;
59455 k++;
59456
59457 /*
59458 ** The packing computed by the previous block is biased toward the siblings
59459 ** on the left side (siblings with smaller keys). The left siblings are
59460 ** always nearly full, while the right-most sibling might be nearly empty.
59461 ** The next block of code attempts to adjust the packing of siblings to
59462 ** get a better balance.
59463 **
59464 ** This adjustment is more than an optimization. The packing above might
59465 ** be so out of balance as to be illegal. For example, the right-most
59466 ** sibling might be completely empty. This adjustment is not optional.
59467 */
@@ -58728,26 +59486,22 @@
59486 }
59487 szNew[i] = szRight;
59488 szNew[i-1] = szLeft;
59489 }
59490
59491 /* Sanity check: For a non-corrupt database file one of the follwing
59492 ** must be true:
59493 ** (1) We found one or more cells (cntNew[0])>0), or
59494 ** (2) pPage is a virtual root page. A virtual root page is when
59495 ** the real root page is page 1 and we are the only child of
59496 ** that page.
 
59497 */
59498 assert( cntNew[0]>0 || (pParent->pgno==1 && pParent->nCell==0) || CORRUPT_DB);
59499 TRACE(("BALANCE: old: %d(nc=%d) %d(nc=%d) %d(nc=%d)\n",
59500 apOld[0]->pgno, apOld[0]->nCell,
59501 nOld>=2 ? apOld[1]->pgno : 0, nOld>=2 ? apOld[1]->nCell : 0,
59502 nOld>=3 ? apOld[2]->pgno : 0, nOld>=3 ? apOld[2]->nCell : 0
 
 
 
59503 ));
59504
59505 /*
59506 ** Allocate k new pages. Reuse old pages where possible.
59507 */
@@ -58766,12 +59520,14 @@
59520 if( rc ) goto balance_cleanup;
59521 }else{
59522 assert( i>0 );
59523 rc = allocateBtreePage(pBt, &pNew, &pgno, (bBulk ? 1 : pgno), 0);
59524 if( rc ) goto balance_cleanup;
59525 zeroPage(pNew, pageFlags);
59526 apNew[i] = pNew;
59527 nNew++;
59528 cntOld[i] = nCell;
59529
59530 /* Set the pointer-map entry for the new sibling page. */
59531 if( ISAUTOVACUUM ){
59532 ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
59533 if( rc!=SQLITE_OK ){
@@ -58779,139 +59535,251 @@
59535 }
59536 }
59537 }
59538 }
59539
 
 
 
 
 
 
 
 
 
 
59540 /*
59541 ** Reassign page numbers so that the new pages are in ascending order.
59542 ** This helps to keep entries in the disk file in order so that a scan
59543 ** of the table is closer to a linear scan through the file. That in turn
59544 ** helps the operating system to deliver pages from the disk more rapidly.
59545 **
59546 ** An O(n^2) insertion sort algorithm is used, but since n is never more
59547 ** than (NB+2) (a small constant), that should not be a problem.
59548 **
59549 ** When NB==3, this one optimization makes the database about 25% faster
59550 ** for large insertions and deletions.
59551 */
59552 for(i=0; i<nNew; i++){
59553 aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
59554 aPgFlags[i] = apNew[i]->pDbPage->flags;
59555 for(j=0; j<i; j++){
59556 if( aPgno[j]==aPgno[i] ){
59557 /* This branch is taken if the set of sibling pages somehow contains
59558 ** duplicate entries. This can happen if the database is corrupt.
59559 ** It would be simpler to detect this as part of the loop below, but
59560 ** we do the detection here in order to avoid populating the pager
59561 ** cache with two separate objects associated with the same
59562 ** page number. */
59563 assert( CORRUPT_DB );
59564 rc = SQLITE_CORRUPT_BKPT;
59565 goto balance_cleanup;
59566 }
59567 }
59568 }
59569 for(i=0; i<nNew; i++){
59570 int iBest = 0; /* aPgno[] index of page number to use */
59571 for(j=1; j<nNew; j++){
59572 if( aPgOrder[j]<aPgOrder[iBest] ) iBest = j;
59573 }
59574 pgno = aPgOrder[iBest];
59575 aPgOrder[iBest] = 0xffffffff;
59576 if( iBest!=i ){
59577 if( iBest>i ){
59578 sqlite3PagerRekey(apNew[iBest]->pDbPage, pBt->nPage+iBest+1, 0);
59579 }
59580 sqlite3PagerRekey(apNew[i]->pDbPage, pgno, aPgFlags[iBest]);
59581 apNew[i]->pgno = pgno;
59582 }
59583 }
59584
59585 TRACE(("BALANCE: new: %d(%d nc=%d) %d(%d nc=%d) %d(%d nc=%d) "
59586 "%d(%d nc=%d) %d(%d nc=%d)\n",
59587 apNew[0]->pgno, szNew[0], cntNew[0],
59588 nNew>=2 ? apNew[1]->pgno : 0, nNew>=2 ? szNew[1] : 0,
59589 nNew>=2 ? cntNew[1] - cntNew[0] - !leafData : 0,
59590 nNew>=3 ? apNew[2]->pgno : 0, nNew>=3 ? szNew[2] : 0,
59591 nNew>=3 ? cntNew[2] - cntNew[1] - !leafData : 0,
59592 nNew>=4 ? apNew[3]->pgno : 0, nNew>=4 ? szNew[3] : 0,
59593 nNew>=4 ? cntNew[3] - cntNew[2] - !leafData : 0,
59594 nNew>=5 ? apNew[4]->pgno : 0, nNew>=5 ? szNew[4] : 0,
59595 nNew>=5 ? cntNew[4] - cntNew[3] - !leafData : 0
59596 ));
59597
59598 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59599 put4byte(pRight, apNew[nNew-1]->pgno);
59600
59601 /* If the sibling pages are not leaves, ensure that the right-child pointer
59602 ** of the right-most new sibling page is set to the value that was
59603 ** originally in the same field of the right-most old sibling page. */
59604 if( (pageFlags & PTF_LEAF)==0 && nOld!=nNew ){
59605 MemPage *pOld = (nNew>nOld ? apNew : apOld)[nOld-1];
59606 memcpy(&apNew[nNew-1]->aData[8], &pOld->aData[8], 4);
59607 }
59608
59609 /* Make any required updates to pointer map entries associated with
59610 ** cells stored on sibling pages following the balance operation. Pointer
59611 ** map entries associated with divider cells are set by the insertCell()
59612 ** routine. The associated pointer map entries are:
59613 **
59614 ** a) if the cell contains a reference to an overflow chain, the
59615 ** entry associated with the first page in the overflow chain, and
59616 **
59617 ** b) if the sibling pages are not leaves, the child page associated
59618 ** with the cell.
59619 **
59620 ** If the sibling pages are not leaves, then the pointer map entry
59621 ** associated with the right-child of each sibling may also need to be
59622 ** updated. This happens below, after the sibling pages have been
59623 ** populated, not here.
59624 */
59625 if( ISAUTOVACUUM ){
59626 MemPage *pNew = apNew[0];
59627 u8 *aOld = pNew->aData;
59628 int cntOldNext = pNew->nCell + pNew->nOverflow;
59629 int usableSize = pBt->usableSize;
59630 int iNew = 0;
59631 int iOld = 0;
59632
59633 for(i=0; i<nCell; i++){
59634 u8 *pCell = apCell[i];
59635 if( i==cntOldNext ){
59636 MemPage *pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
59637 cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
59638 aOld = pOld->aData;
59639 }
59640 if( i==cntNew[iNew] ){
59641 pNew = apNew[++iNew];
59642 if( !leafData ) continue;
59643 }
59644
59645 /* Cell pCell is destined for new sibling page pNew. Originally, it
59646 ** was either part of sibling page iOld (possibly an overflow cell),
59647 ** or else the divider cell to the left of sibling page iOld. So,
59648 ** if sibling page iOld had the same page number as pNew, and if
59649 ** pCell really was a part of sibling page iOld (not a divider or
59650 ** overflow cell), we can skip updating the pointer map entries. */
59651 if( iOld>=nNew
59652 || pNew->pgno!=aPgno[iOld]
59653 || pCell<aOld
59654 || pCell>=&aOld[usableSize]
59655 ){
59656 if( !leafCorrection ){
59657 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
59658 }
59659 if( szCell[i]>pNew->minLocal ){
59660 ptrmapPutOvflPtr(pNew, pCell, &rc);
59661 }
59662 }
59663 }
59664 }
59665
59666 /* Insert new divider cells into pParent. */
59667 for(i=0; i<nNew-1; i++){
59668 u8 *pCell;
59669 u8 *pTemp;
59670 int sz;
59671 MemPage *pNew = apNew[i];
 
 
 
 
 
 
59672 j = cntNew[i];
59673
59674 assert( j<nMaxCells );
59675 pCell = apCell[j];
59676 sz = szCell[j] + leafCorrection;
59677 pTemp = &aOvflSpace[iOvflSpace];
59678 if( !pNew->leaf ){
59679 memcpy(&pNew->aData[8], pCell, 4);
59680 }else if( leafData ){
59681 /* If the tree is a leaf-data tree, and the siblings are leaves,
59682 ** then there is no divider cell in apCell[]. Instead, the divider
59683 ** cell consists of the integer key for the right-most cell of
59684 ** the sibling-page assembled above only.
59685 */
59686 CellInfo info;
59687 j--;
59688 btreeParseCellPtr(pNew, apCell[j], &info);
59689 pCell = pTemp;
59690 sz = 4 + putVarint(&pCell[4], info.nKey);
59691 pTemp = 0;
59692 }else{
59693 pCell -= 4;
59694 /* Obscure case for non-leaf-data trees: If the cell at pCell was
59695 ** previously stored on a leaf node, and its reported size was 4
59696 ** bytes, then it may actually be smaller than this
59697 ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
59698 ** any cell). But it is important to pass the correct size to
59699 ** insertCell(), so reparse the cell now.
59700 **
59701 ** Note that this can never happen in an SQLite data file, as all
59702 ** cells are at least 4 bytes. It only happens in b-trees used
59703 ** to evaluate "IN (SELECT ...)" and similar clauses.
59704 */
59705 if( szCell[j]==4 ){
59706 assert(leafCorrection==4);
59707 sz = cellSizePtr(pParent, pCell);
59708 }
59709 }
59710 iOvflSpace += sz;
59711 assert( sz<=pBt->maxLocal+23 );
59712 assert( iOvflSpace <= (int)pBt->pageSize );
59713 insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
59714 if( rc!=SQLITE_OK ) goto balance_cleanup;
59715 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
59716 }
59717
59718 /* Now update the actual sibling pages. The order in which they are updated
59719 ** is important, as this code needs to avoid disrupting any page from which
59720 ** cells may still to be read. In practice, this means:
59721 **
59722 ** (1) If cells are moving left (from apNew[iPg] to apNew[iPg-1])
59723 ** then it is not safe to update page apNew[iPg] until after
59724 ** the left-hand sibling apNew[iPg-1] has been updated.
59725 **
59726 ** (2) If cells are moving right (from apNew[iPg] to apNew[iPg+1])
59727 ** then it is not safe to update page apNew[iPg] until after
59728 ** the right-hand sibling apNew[iPg+1] has been updated.
59729 **
59730 ** If neither of the above apply, the page is safe to update.
59731 **
59732 ** The iPg value in the following loop starts at nNew-1 goes down
59733 ** to 0, then back up to nNew-1 again, thus making two passes over
59734 ** the pages. On the initial downward pass, only condition (1) above
59735 ** needs to be tested because (2) will always be true from the previous
59736 ** step. On the upward pass, both conditions are always true, so the
59737 ** upwards pass simply processes pages that were missed on the downward
59738 ** pass.
59739 */
59740 for(i=1-nNew; i<nNew; i++){
59741 int iPg = i<0 ? -i : i;
59742 assert( iPg>=0 && iPg<nNew );
59743 if( abDone[iPg] ) continue; /* Skip pages already processed */
59744 if( i>=0 /* On the upwards pass, or... */
59745 || cntOld[iPg-1]>=cntNew[iPg-1] /* Condition (1) is true */
59746 ){
59747 int iNew;
59748 int iOld;
59749 int nNewCell;
59750
59751 /* Verify condition (1): If cells are moving left, update iPg
59752 ** only after iPg-1 has already been updated. */
59753 assert( iPg==0 || cntOld[iPg-1]>=cntNew[iPg-1] || abDone[iPg-1] );
59754
59755 /* Verify condition (2): If cells are moving right, update iPg
59756 ** only after iPg+1 has already been updated. */
59757 assert( cntNew[iPg]>=cntOld[iPg] || abDone[iPg+1] );
59758
59759 if( iPg==0 ){
59760 iNew = iOld = 0;
59761 nNewCell = cntNew[0];
59762 }else{
59763 iOld = iPg<nOld ? (cntOld[iPg-1] + !leafData) : nCell;
59764 iNew = cntNew[iPg-1] + !leafData;
59765 nNewCell = cntNew[iPg] - iNew;
59766 }
59767
59768 editPage(apNew[iPg], iOld, iNew, nNewCell, apCell, szCell);
59769 abDone[iPg]++;
59770 apNew[iPg]->nFree = usableSpace-szNew[iPg];
59771 assert( apNew[iPg]->nOverflow==0 );
59772 assert( apNew[iPg]->nCell==nNewCell );
59773 }
59774 }
59775
59776 /* All pages have been processed exactly once */
59777 assert( memcmp(abDone, "\01\01\01\01\01", nNew)==0 );
59778
59779 assert( nOld>0 );
59780 assert( nNew>0 );
 
 
 
 
59781
59782 if( isRoot && pParent->nCell==0 && pParent->hdrOffset<=apNew[0]->nFree ){
59783 /* The root page of the b-tree now contains no cells. The only sibling
59784 ** page is the right-child of the parent. Copy the contents of the
59785 ** child page into the parent, decreasing the overall height of the
@@ -58920,130 +59788,54 @@
59788 **
59789 ** If this is an auto-vacuum database, the call to copyNodeContent()
59790 ** sets all pointer-map entries corresponding to database image pages
59791 ** for which the pointer is stored within the content being copied.
59792 **
59793 ** It is critical that the child page be defragmented before being
59794 ** copied into the parent, because if the parent is page 1 then it will
59795 ** by smaller than the child due to the database header, and so all the
59796 ** free space needs to be up front.
59797 */
59798 assert( nNew==1 );
59799 rc = defragmentPage(apNew[0]);
59800 testcase( rc!=SQLITE_OK );
59801 assert( apNew[0]->nFree ==
59802 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
59803 || rc!=SQLITE_OK
59804 );
59805 copyNodeContent(apNew[0], pParent, &rc);
59806 freePage(apNew[0], &rc);
59807 }else if( ISAUTOVACUUM && !leafCorrection ){
59808 /* Fix the pointer map entries associated with the right-child of each
59809 ** sibling page. All other pointer map entries have already been taken
59810 ** care of. */
59811 for(i=0; i<nNew; i++){
59812 u32 key = get4byte(&apNew[i]->aData[8]);
59813 ptrmapPut(pBt, key, PTRMAP_BTREE, apNew[i]->pgno, &rc);
59814 }
59815 }
59816
59817 assert( pParent->isInit );
59818 TRACE(("BALANCE: finished: old=%d new=%d cells=%d\n",
59819 nOld, nNew, nCell));
59820
59821 /* Free any old pages that were not reused as new pages.
59822 */
59823 for(i=nNew; i<nOld; i++){
59824 freePage(apOld[i], &rc);
59825 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59826
59827 #if 0
59828 if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
59829 /* The ptrmapCheckPages() contains assert() statements that verify that
59830 ** all pointer map pages are set correctly. This is helpful while
59831 ** debugging. This is usually disabled because a corrupt database may
59832 ** cause an assert() statement to fail. */
59833 ptrmapCheckPages(apNew, nNew);
59834 ptrmapCheckPages(&pParent, 1);
59835 }
59836 #endif
 
 
 
 
 
59837
59838 /*
59839 ** Cleanup before returning.
59840 */
59841 balance_cleanup:
@@ -60424,12 +61216,18 @@
61216 }else{
61217 int contentOffset = get2byteNotZero(&data[hdr+5]);
61218 assert( contentOffset<=usableSize ); /* Enforced by btreeInitPage() */
61219 memset(hit+contentOffset, 0, usableSize-contentOffset);
61220 memset(hit, 1, contentOffset);
61221 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
61222 ** number of cells on the page. */
61223 nCell = get2byte(&data[hdr+3]);
61224 /* EVIDENCE-OF: R-23882-45353 The cell pointer array of a b-tree page
61225 ** immediately follows the b-tree page header. */
61226 cellStart = hdr + 12 - 4*pPage->leaf;
61227 /* EVIDENCE-OF: R-02776-14802 The cell pointer array consists of K 2-byte
61228 ** integer offsets to the cell contents. */
61229 for(i=0; i<nCell; i++){
61230 int pc = get2byte(&data[cellStart+i*2]);
61231 u32 size = 65536;
61232 int j;
61233 if( pc<=usableSize-4 ){
@@ -60441,18 +61239,27 @@
61239 "Corruption detected in cell %d on page %d",i,iPage);
61240 }else{
61241 for(j=pc+size-1; j>=pc; j--) hit[j]++;
61242 }
61243 }
61244 /* EVIDENCE-OF: R-20690-50594 The second field of the b-tree page header
61245 ** is the offset of the first freeblock, or zero if there are no
61246 ** freeblocks on the page. */
61247 i = get2byte(&data[hdr+1]);
61248 while( i>0 ){
61249 int size, j;
61250 assert( i<=usableSize-4 ); /* Enforced by btreeInitPage() */
61251 size = get2byte(&data[i+2]);
61252 assert( i+size<=usableSize ); /* Enforced by btreeInitPage() */
61253 for(j=i+size-1; j>=i; j--) hit[j]++;
61254 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
61255 ** big-endian integer which is the offset in the b-tree page of the next
61256 ** freeblock in the chain, or zero if the freeblock is the last on the
61257 ** chain. */
61258 j = get2byte(&data[i]);
61259 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
61260 ** increasing offset. */
61261 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
61262 assert( j<=usableSize-4 ); /* Enforced by btreeInitPage() */
61263 i = j;
61264 }
61265 for(i=cnt=0; i<usableSize; i++){
@@ -60462,10 +61269,15 @@
61269 checkAppendMsg(pCheck,
61270 "Multiple uses for byte %d of page %d", i, iPage);
61271 break;
61272 }
61273 }
61274 /* EVIDENCE-OF: R-43263-13491 The total number of bytes in all fragments
61275 ** is stored in the fifth field of the b-tree page header.
61276 ** EVIDENCE-OF: R-07161-27322 The one-byte integer at offset 7 gives the
61277 ** number of fragmented free bytes within the cell content area.
61278 */
61279 if( cnt!=data[hdr+7] ){
61280 checkAppendMsg(pCheck,
61281 "Fragmentation of %d bytes reported as %d on page %d",
61282 cnt, data[hdr+7], iPage);
61283 }
@@ -60865,10 +61677,15 @@
61677 */
61678 SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *p){
61679 return (p->pBt->btsFlags & BTS_READ_ONLY)!=0;
61680 }
61681
61682 /*
61683 ** Return the size of the header added to each page by this module.
61684 */
61685 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void){ return sizeof(MemPage); }
61686
61687 /************** End of btree.c ***********************************************/
61688 /************** Begin file backup.c ******************************************/
61689 /*
61690 ** 2009 January 28
61691 **
@@ -60988,10 +61805,24 @@
61805 static int setDestPgsz(sqlite3_backup *p){
61806 int rc;
61807 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
61808 return rc;
61809 }
61810
61811 /*
61812 ** Check that there is no open read-transaction on the b-tree passed as the
61813 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
61814 ** is an open read-transaction, return SQLITE_ERROR and leave an error
61815 ** message in database handle db.
61816 */
61817 static int checkReadTransaction(sqlite3 *db, Btree *p){
61818 if( sqlite3BtreeIsInReadTrans(p) ){
61819 sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
61820 return SQLITE_ERROR;
61821 }
61822 return SQLITE_OK;
61823 }
61824
61825 /*
61826 ** Create an sqlite3_backup process to copy the contents of zSrcDb from
61827 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
61828 ** a pointer to the new sqlite3_backup object.
@@ -61004,10 +61835,17 @@
61835 const char *zDestDb, /* Name of database within pDestDb */
61836 sqlite3* pSrcDb, /* Database connection to read from */
61837 const char *zSrcDb /* Name of database within pSrcDb */
61838 ){
61839 sqlite3_backup *p; /* Value to return */
61840
61841 #ifdef SQLITE_ENABLE_API_ARMOR
61842 if( !sqlite3SafetyCheckOk(pSrcDb)||!sqlite3SafetyCheckOk(pDestDb) ){
61843 (void)SQLITE_MISUSE_BKPT;
61844 return 0;
61845 }
61846 #endif
61847
61848 /* Lock the source database handle. The destination database
61849 ** handle is not locked in this routine, but it is locked in
61850 ** sqlite3_backup_step(). The user is required to ensure that no
61851 ** other thread accesses the destination handle for the duration
@@ -61041,16 +61879,19 @@
61879 p->pDestDb = pDestDb;
61880 p->pSrcDb = pSrcDb;
61881 p->iNext = 1;
61882 p->isAttached = 0;
61883
61884 if( 0==p->pSrc || 0==p->pDest
61885 || setDestPgsz(p)==SQLITE_NOMEM
61886 || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK
61887 ){
61888 /* One (or both) of the named databases did not exist or an OOM
61889 ** error was hit. Or there is a transaction open on the destination
61890 ** database. The error has already been written into the pDestDb
61891 ** handle. All that is left to do here is free the sqlite3_backup
61892 ** structure. */
61893 sqlite3_free(p);
61894 p = 0;
61895 }
61896 }
61897 if( p ){
@@ -61201,10 +62042,13 @@
62042 int rc;
62043 int destMode; /* Destination journal mode */
62044 int pgszSrc = 0; /* Source page size */
62045 int pgszDest = 0; /* Destination page size */
62046
62047 #ifdef SQLITE_ENABLE_API_ARMOR
62048 if( p==0 ) return SQLITE_MISUSE_BKPT;
62049 #endif
62050 sqlite3_mutex_enter(p->pSrcDb->mutex);
62051 sqlite3BtreeEnter(p->pSrc);
62052 if( p->pDestDb ){
62053 sqlite3_mutex_enter(p->pDestDb->mutex);
62054 }
@@ -61464,11 +62308,11 @@
62308 }
62309 *pp = p->pNext;
62310 }
62311
62312 /* If a transaction is still open on the Btree, roll it back. */
62313 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
62314
62315 /* Set the error code of the destination database handle. */
62316 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
62317 if( p->pDestDb ){
62318 sqlite3Error(p->pDestDb, rc);
@@ -61490,18 +62334,30 @@
62334 /*
62335 ** Return the number of pages still to be backed up as of the most recent
62336 ** call to sqlite3_backup_step().
62337 */
62338 SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
62339 #ifdef SQLITE_ENABLE_API_ARMOR
62340 if( p==0 ){
62341 (void)SQLITE_MISUSE_BKPT;
62342 return 0;
62343 }
62344 #endif
62345 return p->nRemaining;
62346 }
62347
62348 /*
62349 ** Return the total number of pages in the source database as of the most
62350 ** recent call to sqlite3_backup_step().
62351 */
62352 SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
62353 #ifdef SQLITE_ENABLE_API_ARMOR
62354 if( p==0 ){
62355 (void)SQLITE_MISUSE_BKPT;
62356 return 0;
62357 }
62358 #endif
62359 return p->nPagecount;
62360 }
62361
62362 /*
62363 ** This function is called after the contents of page iPage of the
@@ -63788,10 +64644,38 @@
64644 }
64645 p->nOp += nOp;
64646 }
64647 return addr;
64648 }
64649
64650 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS)
64651 /*
64652 ** Add an entry to the array of counters managed by sqlite3_stmt_scanstatus().
64653 */
64654 SQLITE_PRIVATE void sqlite3VdbeScanStatus(
64655 Vdbe *p, /* VM to add scanstatus() to */
64656 int addrExplain, /* Address of OP_Explain (or 0) */
64657 int addrLoop, /* Address of loop counter */
64658 int addrVisit, /* Address of rows visited counter */
64659 LogEst nEst, /* Estimated number of output rows */
64660 const char *zName /* Name of table or index being scanned */
64661 ){
64662 int nByte = (p->nScan+1) * sizeof(ScanStatus);
64663 ScanStatus *aNew;
64664 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
64665 if( aNew ){
64666 ScanStatus *pNew = &aNew[p->nScan++];
64667 pNew->addrExplain = addrExplain;
64668 pNew->addrLoop = addrLoop;
64669 pNew->addrVisit = addrVisit;
64670 pNew->nEst = nEst;
64671 pNew->zName = sqlite3DbStrDup(p->db, zName);
64672 p->aScan = aNew;
64673 }
64674 }
64675 #endif
64676
64677
64678 /*
64679 ** Change the value of the P1 operand for a specific instruction.
64680 ** This routine is useful when a large program is loaded from a
64681 ** static array using sqlite3VdbeAddOpList but we want to make a
@@ -64887,10 +65771,13 @@
65771 p->apArg = allocSpace(p->apArg, nArg*sizeof(Mem*), &zCsr, zEnd, &nByte);
65772 p->azVar = allocSpace(p->azVar, nVar*sizeof(char*), &zCsr, zEnd, &nByte);
65773 p->apCsr = allocSpace(p->apCsr, nCursor*sizeof(VdbeCursor*),
65774 &zCsr, zEnd, &nByte);
65775 p->aOnceFlag = allocSpace(p->aOnceFlag, nOnce, &zCsr, zEnd, &nByte);
65776 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65777 p->anExec = allocSpace(p->anExec, p->nOp*sizeof(i64), &zCsr, zEnd, &nByte);
65778 #endif
65779 if( nByte ){
65780 p->pFree = sqlite3DbMallocZero(db, nByte);
65781 }
65782 zCsr = p->pFree;
65783 zEnd = &zCsr[nByte];
@@ -64903,11 +65790,11 @@
65790 for(n=0; n<nVar; n++){
65791 p->aVar[n].flags = MEM_Null;
65792 p->aVar[n].db = db;
65793 }
65794 }
65795 if( p->azVar && pParse->nzVar>0 ){
65796 p->nzVar = pParse->nzVar;
65797 memcpy(p->azVar, pParse->azVar, p->nzVar*sizeof(p->azVar[0]));
65798 memset(pParse->azVar, 0, pParse->nzVar*sizeof(pParse->azVar[0]));
65799 }
65800 if( p->aMem ){
@@ -64954,10 +65841,13 @@
65841 ** is used, for example, when a trigger sub-program is halted to restore
65842 ** control to the main program.
65843 */
65844 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
65845 Vdbe *v = pFrame->v;
65846 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
65847 v->anExec = pFrame->anExec;
65848 #endif
65849 v->aOnceFlag = pFrame->aOnceFlag;
65850 v->nOnceFlag = pFrame->nOnceFlag;
65851 v->aOp = pFrame->aOp;
65852 v->nOp = pFrame->nOp;
65853 v->aMem = pFrame->aMem;
@@ -64964,10 +65854,11 @@
65854 v->nMem = pFrame->nMem;
65855 v->apCsr = pFrame->apCsr;
65856 v->nCursor = pFrame->nCursor;
65857 v->db->lastRowid = pFrame->lastRowid;
65858 v->nChange = pFrame->nChange;
65859 v->db->nChange = pFrame->nDbChange;
65860 return pFrame->pc;
65861 }
65862
65863 /*
65864 ** Close all cursors.
@@ -65531,10 +66422,11 @@
66422 ** so, abort any other statements this handle currently has active.
66423 */
66424 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66425 sqlite3CloseSavepoints(db);
66426 db->autoCommit = 1;
66427 p->nChange = 0;
66428 }
66429 }
66430 }
66431
66432 /* Check for immediate foreign key violations. */
@@ -65571,18 +66463,20 @@
66463 sqlite3VdbeLeave(p);
66464 return SQLITE_BUSY;
66465 }else if( rc!=SQLITE_OK ){
66466 p->rc = rc;
66467 sqlite3RollbackAll(db, SQLITE_OK);
66468 p->nChange = 0;
66469 }else{
66470 db->nDeferredCons = 0;
66471 db->nDeferredImmCons = 0;
66472 db->flags &= ~SQLITE_DeferFKs;
66473 sqlite3CommitInternalChanges(db);
66474 }
66475 }else{
66476 sqlite3RollbackAll(db, SQLITE_OK);
66477 p->nChange = 0;
66478 }
66479 db->nStatement = 0;
66480 }else if( eStatementOp==0 ){
66481 if( p->rc==SQLITE_OK || p->errorAction==OE_Fail ){
66482 eStatementOp = SAVEPOINT_RELEASE;
@@ -65590,10 +66484,11 @@
66484 eStatementOp = SAVEPOINT_ROLLBACK;
66485 }else{
66486 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66487 sqlite3CloseSavepoints(db);
66488 db->autoCommit = 1;
66489 p->nChange = 0;
66490 }
66491 }
66492
66493 /* If eStatementOp is non-zero, then a statement transaction needs to
66494 ** be committed or rolled back. Call sqlite3VdbeCloseStatement() to
@@ -65610,10 +66505,11 @@
66505 p->zErrMsg = 0;
66506 }
66507 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK);
66508 sqlite3CloseSavepoints(db);
66509 db->autoCommit = 1;
66510 p->nChange = 0;
66511 }
66512 }
66513
66514 /* If this was an INSERT, UPDATE or DELETE and no statement transaction
66515 ** has been rolled back, update the database connection change-counter.
@@ -65871,10 +66767,16 @@
66767 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
66768 vdbeFreeOpArray(db, p->aOp, p->nOp);
66769 sqlite3DbFree(db, p->aColName);
66770 sqlite3DbFree(db, p->zSql);
66771 sqlite3DbFree(db, p->pFree);
66772 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
66773 for(i=0; i<p->nScan; i++){
66774 sqlite3DbFree(db, p->aScan[i].zName);
66775 }
66776 sqlite3DbFree(db, p->aScan);
66777 #endif
66778 }
66779
66780 /*
66781 ** Delete an entire VDBE.
66782 */
@@ -66029,13 +66931,11 @@
66931 /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
66932 # define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
66933 i64 i = pMem->u.i;
66934 u64 u;
66935 if( i<0 ){
66936 u = ~i;
 
 
66937 }else{
66938 u = i;
66939 }
66940 if( u<=127 ){
66941 return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
@@ -66197,14 +67097,18 @@
67097 ){
67098 u64 x = FOUR_BYTE_UINT(buf);
67099 u32 y = FOUR_BYTE_UINT(buf+4);
67100 x = (x<<32) + y;
67101 if( serial_type==6 ){
67102 /* EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit
67103 ** twos-complement integer. */
67104 pMem->u.i = *(i64*)&x;
67105 pMem->flags = MEM_Int;
67106 testcase( pMem->u.i<0 );
67107 }else{
67108 /* EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit
67109 ** floating point number. */
67110 #if !defined(NDEBUG) && !defined(SQLITE_OMIT_FLOATING_POINT)
67111 /* Verify that integers and floating point values use the same
67112 ** byte order. Or, that if SQLITE_MIXED_ENDIAN_64BIT_FLOAT is
67113 ** defined that 64-bit floating point values really are mixed
67114 ** endian.
@@ -66228,39 +67132,50 @@
67132 Mem *pMem /* Memory cell to write value into */
67133 ){
67134 switch( serial_type ){
67135 case 10: /* Reserved for future use */
67136 case 11: /* Reserved for future use */
67137 case 0: { /* Null */
67138 /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */
67139 pMem->flags = MEM_Null;
67140 break;
67141 }
67142 case 1: {
67143 /* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement
67144 ** integer. */
67145 pMem->u.i = ONE_BYTE_INT(buf);
67146 pMem->flags = MEM_Int;
67147 testcase( pMem->u.i<0 );
67148 return 1;
67149 }
67150 case 2: { /* 2-byte signed integer */
67151 /* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit
67152 ** twos-complement integer. */
67153 pMem->u.i = TWO_BYTE_INT(buf);
67154 pMem->flags = MEM_Int;
67155 testcase( pMem->u.i<0 );
67156 return 2;
67157 }
67158 case 3: { /* 3-byte signed integer */
67159 /* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit
67160 ** twos-complement integer. */
67161 pMem->u.i = THREE_BYTE_INT(buf);
67162 pMem->flags = MEM_Int;
67163 testcase( pMem->u.i<0 );
67164 return 3;
67165 }
67166 case 4: { /* 4-byte signed integer */
67167 /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit
67168 ** twos-complement integer. */
67169 pMem->u.i = FOUR_BYTE_INT(buf);
67170 pMem->flags = MEM_Int;
67171 testcase( pMem->u.i<0 );
67172 return 4;
67173 }
67174 case 5: { /* 6-byte signed integer */
67175 /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit
67176 ** twos-complement integer. */
67177 pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
67178 pMem->flags = MEM_Int;
67179 testcase( pMem->u.i<0 );
67180 return 6;
67181 }
@@ -66270,15 +67185,21 @@
67185 ** to avoid having to move the frame pointer in the common case */
67186 return serialGet(buf,serial_type,pMem);
67187 }
67188 case 8: /* Integer 0 */
67189 case 9: { /* Integer 1 */
67190 /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */
67191 /* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */
67192 pMem->u.i = serial_type-8;
67193 pMem->flags = MEM_Int;
67194 return 0;
67195 }
67196 default: {
67197 /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in
67198 ** length.
67199 ** EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and
67200 ** (N-13)/2 bytes in length. */
67201 static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
67202 pMem->z = (char *)buf;
67203 pMem->n = (serial_type-12)/2;
67204 pMem->flags = aFlag[serial_type&1];
67205 return pMem->n;
@@ -68238,15 +69159,23 @@
69159 sqlite3_stmt *pStmt,
69160 int N,
69161 const void *(*xFunc)(Mem*),
69162 int useType
69163 ){
69164 const void *ret;
69165 Vdbe *p;
69166 int n;
69167 sqlite3 *db;
69168 #ifdef SQLITE_ENABLE_API_ARMOR
69169 if( pStmt==0 ){
69170 (void)SQLITE_MISUSE_BKPT;
69171 return 0;
69172 }
69173 #endif
69174 ret = 0;
69175 p = (Vdbe *)pStmt;
69176 db = p->db;
69177 assert( db!=0 );
69178 n = sqlite3_column_count(pStmt);
69179 if( N<n && N>=0 ){
69180 N += useType*n;
69181 sqlite3_mutex_enter(db->mutex);
@@ -68707,10 +69636,16 @@
69636 ** prepared statement for the database connection. Return NULL if there
69637 ** are no more.
69638 */
69639 SQLITE_API sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt){
69640 sqlite3_stmt *pNext;
69641 #ifdef SQLITE_ENABLE_API_ARMOR
69642 if( !sqlite3SafetyCheckOk(pDb) ){
69643 (void)SQLITE_MISUSE_BKPT;
69644 return 0;
69645 }
69646 #endif
69647 sqlite3_mutex_enter(pDb->mutex);
69648 if( pStmt==0 ){
69649 pNext = (sqlite3_stmt*)pDb->pVdbe;
69650 }else{
69651 pNext = (sqlite3_stmt*)((Vdbe*)pStmt)->pNext;
@@ -68722,15 +69657,91 @@
69657 /*
69658 ** Return the value of a status counter for a prepared statement
69659 */
69660 SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
69661 Vdbe *pVdbe = (Vdbe*)pStmt;
69662 u32 v;
69663 #ifdef SQLITE_ENABLE_API_ARMOR
69664 if( !pStmt ){
69665 (void)SQLITE_MISUSE_BKPT;
69666 return 0;
69667 }
69668 #endif
69669 v = pVdbe->aCounter[op];
69670 if( resetFlag ) pVdbe->aCounter[op] = 0;
69671 return (int)v;
69672 }
69673
69674 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
69675 /*
69676 ** Return status data for a single loop within query pStmt.
69677 */
69678 SQLITE_API int sqlite3_stmt_scanstatus(
69679 sqlite3_stmt *pStmt, /* Prepared statement being queried */
69680 int idx, /* Index of loop to report on */
69681 int iScanStatusOp, /* Which metric to return */
69682 void *pOut /* OUT: Write the answer here */
69683 ){
69684 Vdbe *p = (Vdbe*)pStmt;
69685 ScanStatus *pScan;
69686 if( idx<0 || idx>=p->nScan ) return 1;
69687 pScan = &p->aScan[idx];
69688 switch( iScanStatusOp ){
69689 case SQLITE_SCANSTAT_NLOOP: {
69690 *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
69691 break;
69692 }
69693 case SQLITE_SCANSTAT_NVISIT: {
69694 *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
69695 break;
69696 }
69697 case SQLITE_SCANSTAT_EST: {
69698 double r = 1.0;
69699 LogEst x = pScan->nEst;
69700 while( x<100 ){
69701 x += 10;
69702 r *= 0.5;
69703 }
69704 *(double*)pOut = r*sqlite3LogEstToInt(x);
69705 break;
69706 }
69707 case SQLITE_SCANSTAT_NAME: {
69708 *(const char**)pOut = pScan->zName;
69709 break;
69710 }
69711 case SQLITE_SCANSTAT_EXPLAIN: {
69712 if( pScan->addrExplain ){
69713 *(const char**)pOut = p->aOp[ pScan->addrExplain ].p4.z;
69714 }else{
69715 *(const char**)pOut = 0;
69716 }
69717 break;
69718 }
69719 case SQLITE_SCANSTAT_SELECTID: {
69720 if( pScan->addrExplain ){
69721 *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
69722 }else{
69723 *(int*)pOut = -1;
69724 }
69725 break;
69726 }
69727 default: {
69728 return 1;
69729 }
69730 }
69731 return 0;
69732 }
69733
69734 /*
69735 ** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
69736 */
69737 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
69738 Vdbe *p = (Vdbe*)pStmt;
69739 memset(p->anExec, 0, p->nOp * sizeof(i64));
69740 }
69741 #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
69742
69743 /************** End of vdbeapi.c *********************************************/
69744 /************** Begin file vdbetrace.c ***************************************/
69745 /*
69746 ** 2009 November 25
69747 **
@@ -69612,10 +70623,13 @@
70623 #ifdef VDBE_PROFILE
70624 start = sqlite3Hwtime();
70625 #endif
70626 nVmStep++;
70627 pOp = &aOp[pc];
70628 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
70629 if( p->anExec ) p->anExec[pc]++;
70630 #endif
70631
70632 /* Only allow tracing if SQLITE_DEBUG is defined.
70633 */
70634 #ifdef SQLITE_DEBUG
70635 if( db->flags & SQLITE_VdbeTrace ){
@@ -71302,11 +72316,11 @@
72316 assert( pReg->flags & MEM_Blob );
72317 assert( memIsValid(pReg) );
72318 pC->payloadSize = pC->szRow = avail = pReg->n;
72319 pC->aRow = (u8*)pReg->z;
72320 }else{
72321 sqlite3VdbeMemSetNull(pDest);
72322 goto op_column_out;
72323 }
72324 }else{
72325 assert( pCrsr );
72326 if( pC->isTable==0 ){
@@ -71637,11 +72651,14 @@
72651 testcase( serial_type==127 );
72652 testcase( serial_type==128 );
72653 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type);
72654 }while( (--pRec)>=pData0 );
72655
72656 /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint
72657 ** which determines the total number of bytes in the header. The varint
72658 ** value is the size of the header in bytes including the size varint
72659 ** itself. */
72660 testcase( nHdr==126 );
72661 testcase( nHdr==127 );
72662 if( nHdr<=126 ){
72663 /* The common case */
72664 nHdr += 1;
@@ -71671,11 +72688,15 @@
72688 j = nHdr;
72689 assert( pData0<=pLast );
72690 pRec = pData0;
72691 do{
72692 serial_type = pRec->uTemp;
72693 /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more
72694 ** additional varints, one per column. */
72695 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */
72696 /* EVIDENCE-OF: R-64536-51728 The values for each column in the record
72697 ** immediately follow the header. */
72698 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */
72699 }while( (++pRec)<=pLast );
72700 assert( i==nHdr );
72701 assert( j==nByte );
72702
@@ -71826,23 +72847,30 @@
72847 goto vdbe_return;
72848 }
72849 db->isTransactionSavepoint = 0;
72850 rc = p->rc;
72851 }else{
72852 int isSchemaChange;
72853 iSavepoint = db->nSavepoint - iSavepoint - 1;
72854 if( p1==SAVEPOINT_ROLLBACK ){
72855 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
72856 for(ii=0; ii<db->nDb; ii++){
72857 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
72858 SQLITE_ABORT_ROLLBACK,
72859 isSchemaChange==0);
72860 if( rc!=SQLITE_OK ) goto abort_due_to_error;
72861 }
72862 }else{
72863 isSchemaChange = 0;
72864 }
72865 for(ii=0; ii<db->nDb; ii++){
72866 rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint);
72867 if( rc!=SQLITE_OK ){
72868 goto abort_due_to_error;
72869 }
72870 }
72871 if( isSchemaChange ){
72872 sqlite3ExpirePreparedStatements(db);
72873 sqlite3ResetAllSchemasOfConnection(db);
72874 db->flags = (db->flags | SQLITE_InternChanges);
72875 }
72876 }
@@ -72235,11 +73263,11 @@
73263 assert( p->bIsReader );
73264 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
73265 || p->readOnly==0 );
73266
73267 if( p->expired ){
73268 rc = SQLITE_ABORT_ROLLBACK;
73269 break;
73270 }
73271
73272 nField = 0;
73273 pKeyInfo = 0;
@@ -72799,14 +73827,14 @@
73827 }
73828 pIdxKey = &r;
73829 }else{
73830 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
73831 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
73832 );
73833 if( pIdxKey==0 ) goto no_mem;
73834 assert( pIn3->flags & MEM_Blob );
73835 ExpandBlob(pIn3);
73836 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
73837 }
73838 pIdxKey->default_rc = 0;
73839 if( pOp->opcode==OP_NoConflict ){
73840 /* For the OP_NoConflict opcode, take the jump if any of the
@@ -73402,10 +74430,14 @@
74430 #endif /* SQLITE_OMIT_VIRTUALTABLE */
74431 }else{
74432 assert( pC->pCursor!=0 );
74433 rc = sqlite3VdbeCursorRestore(pC);
74434 if( rc ) goto abort_due_to_error;
74435 if( pC->nullRow ){
74436 pOut->flags = MEM_Null;
74437 break;
74438 }
74439 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
74440 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */
74441 }
74442 pOut->u.i = v;
74443 break;
@@ -73492,13 +74524,13 @@
74524 }
74525 /* Opcode: Rewind P1 P2 * * *
74526 **
74527 ** The next use of the Rowid or Column or Next instruction for P1
74528 ** will refer to the first entry in the database table or index.
74529 ** If the table or index is empty, jump immediately to P2.
74530 ** If the table or index is not empty, fall through to the following
74531 ** instruction.
74532 **
74533 ** This opcode leaves the cursor configured to move in forward order,
74534 ** from the beginning toward the end. In other words, the cursor is
74535 ** configured to use Next, not Prev.
74536 */
@@ -74410,10 +75442,13 @@
75442 pFrame->aOp = p->aOp;
75443 pFrame->nOp = p->nOp;
75444 pFrame->token = pProgram->token;
75445 pFrame->aOnceFlag = p->aOnceFlag;
75446 pFrame->nOnceFlag = p->nOnceFlag;
75447 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75448 pFrame->anExec = p->anExec;
75449 #endif
75450
75451 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
75452 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
75453 pMem->flags = MEM_Undefined;
75454 pMem->db = db;
@@ -74427,10 +75462,11 @@
75462
75463 p->nFrame++;
75464 pFrame->pParent = p->pFrame;
75465 pFrame->lastRowid = lastRowid;
75466 pFrame->nChange = p->nChange;
75467 pFrame->nDbChange = p->db->nChange;
75468 p->nChange = 0;
75469 p->pFrame = pFrame;
75470 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1];
75471 p->nMem = pFrame->nChildMem;
75472 p->nCursor = (u16)pFrame->nChildCsr;
@@ -74437,10 +75473,13 @@
75473 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1];
75474 p->aOp = aOp = pProgram->aOp;
75475 p->nOp = pProgram->nOp;
75476 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor];
75477 p->nOnceFlag = pProgram->nOnce;
75478 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
75479 p->anExec = 0;
75480 #endif
75481 pc = -1;
75482 memset(p->aOnceFlag, 0, p->nOnceFlag);
75483
75484 break;
75485 }
@@ -74681,12 +75720,12 @@
75720
75721 #ifndef SQLITE_OMIT_WAL
75722 /* Opcode: Checkpoint P1 P2 P3 * *
75723 **
75724 ** Checkpoint database P1. This is a no-op if P1 is not currently in
75725 ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
75726 ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns
75727 ** SQLITE_BUSY or not, respectively. Write the number of pages in the
75728 ** WAL after the checkpoint into mem[P3+1] and the number of pages
75729 ** in the WAL that have been checkpointed after the checkpoint
75730 ** completes into mem[P3+2]. However on an error, mem[P3+1] and
75731 ** mem[P3+2] are initialized to -1.
@@ -74700,10 +75739,11 @@
75739 aRes[0] = 0;
75740 aRes[1] = aRes[2] = -1;
75741 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE
75742 || pOp->p2==SQLITE_CHECKPOINT_FULL
75743 || pOp->p2==SQLITE_CHECKPOINT_RESTART
75744 || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE
75745 );
75746 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]);
75747 if( rc==SQLITE_BUSY ){
75748 rc = SQLITE_OK;
75749 aRes[0] = 1;
@@ -75625,10 +76665,15 @@
76665 char *zErr = 0;
76666 Table *pTab;
76667 Parse *pParse = 0;
76668 Incrblob *pBlob = 0;
76669
76670 #ifdef SQLITE_ENABLE_API_ARMOR
76671 if( !sqlite3SafetyCheckOk(db) || ppBlob==0 || zTable==0 ){
76672 return SQLITE_MISUSE_BKPT;
76673 }
76674 #endif
76675 flags = !!flags; /* flags = (flags ? 1 : 0); */
76676 *ppBlob = 0;
76677
76678 sqlite3_mutex_enter(db->mutex);
76679
@@ -75843,11 +76888,10 @@
76888 v = (Vdbe*)p->pStmt;
76889
76890 if( n<0 || iOffset<0 || (iOffset+n)>p->nByte ){
76891 /* Request is out of range. Return a transient error. */
76892 rc = SQLITE_ERROR;
 
76893 }else if( v==0 ){
76894 /* If there is no statement handle, then the blob-handle has
76895 ** already been invalidated. Return SQLITE_ABORT in this case.
76896 */
76897 rc = SQLITE_ABORT;
@@ -75861,14 +76905,14 @@
76905 sqlite3BtreeLeaveCursor(p->pCsr);
76906 if( rc==SQLITE_ABORT ){
76907 sqlite3VdbeFinalize(v);
76908 p->pStmt = 0;
76909 }else{
 
76910 v->rc = rc;
76911 }
76912 }
76913 sqlite3Error(db, rc);
76914 rc = sqlite3ApiExit(db, rc);
76915 sqlite3_mutex_leave(db->mutex);
76916 return rc;
76917 }
76918
@@ -76041,11 +77085,11 @@
77085 ** itself.
77086 **
77087 ** The sorter is running in multi-threaded mode if (a) the library was built
77088 ** with pre-processor symbol SQLITE_MAX_WORKER_THREADS set to a value greater
77089 ** than zero, and (b) worker threads have been enabled at runtime by calling
77090 ** "PRAGMA threads=N" with some value of N greater than 0.
77091 **
77092 ** When Rewind() is called, any data remaining in memory is flushed to a
77093 ** final PMA. So at this point the data is stored in some number of sorted
77094 ** PMAs within temporary files on disk.
77095 **
@@ -76086,10 +77130,17 @@
77130 */
77131 #if 0
77132 # define SQLITE_DEBUG_SORTER_THREADS 1
77133 #endif
77134
77135 /*
77136 ** Hard-coded maximum amount of data to accumulate in memory before flushing
77137 ** to a level 0 PMA. The purpose of this limit is to prevent various integer
77138 ** overflows. 512MiB.
77139 */
77140 #define SQLITE_MAX_MXPMASIZE (1<<29)
77141
77142 /*
77143 ** Private objects used by the sorter
77144 */
77145 typedef struct MergeEngine MergeEngine; /* Merge PMAs together */
77146 typedef struct PmaReader PmaReader; /* Incrementally read one PMA */
@@ -76382,11 +77433,13 @@
77433 */
77434 #define SRVAL(p) ((void*)((SorterRecord*)(p) + 1))
77435
77436 /* The minimum PMA size is set to this value multiplied by the database
77437 ** page size in bytes. */
77438 #ifndef SQLITE_SORTER_PMASZ
77439 # define SQLITE_SORTER_PMASZ 10
77440 #endif
77441
77442 /* Maximum number of PMAs that a single MergeEngine can merge */
77443 #define SORTER_MAX_MERGE_COUNT 16
77444
77445 static int vdbeIncrSwap(IncrMerger*);
@@ -76781,20 +77834,18 @@
77834 SortSubtask *pTask = &pSorter->aTask[i];
77835 pTask->pSorter = pSorter;
77836 }
77837
77838 if( !sqlite3TempInMemory(db) ){
77839 pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
77840 mxCache = db->aDb[0].pSchema->cache_size;
77841 if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
77842 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
77843
77844 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
77845 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
77846 ** large heap allocations.
 
 
77847 */
77848 if( sqlite3GlobalConfig.pScratch==0 ){
77849 assert( pSorter->iMemory==0 );
77850 pSorter->nMemory = pgsz;
77851 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
@@ -79162,19 +80213,19 @@
80213 **
80214 ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
80215 ** is a helper function - a callback for the tree walker.
80216 */
80217 static int incrAggDepth(Walker *pWalker, Expr *pExpr){
80218 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
80219 return WRC_Continue;
80220 }
80221 static void incrAggFunctionDepth(Expr *pExpr, int N){
80222 if( N>0 ){
80223 Walker w;
80224 memset(&w, 0, sizeof(w));
80225 w.xExprCallback = incrAggDepth;
80226 w.u.n = N;
80227 sqlite3WalkExpr(&w, pExpr);
80228 }
80229 }
80230
80231 /*
@@ -79454,10 +80505,14 @@
80505 }
80506 }
80507 if( pMatch ){
80508 pExpr->iTable = pMatch->iCursor;
80509 pExpr->pTab = pMatch->pTab;
80510 assert( (pMatch->jointype & JT_RIGHT)==0 ); /* RIGHT JOIN not (yet) supported */
80511 if( (pMatch->jointype & JT_LEFT)!=0 ){
80512 ExprSetProperty(pExpr, EP_CanBeNull);
80513 }
80514 pSchema = pExpr->pTab->pSchema;
80515 }
80516 } /* if( pSrcList ) */
80517
80518 #ifndef SQLITE_OMIT_TRIGGER
@@ -79718,11 +80773,11 @@
80773 double r = -1.0;
80774 if( p->op!=TK_FLOAT ) return -1;
80775 sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
80776 assert( r>=0.0 );
80777 if( r>1.0 ) return -1;
80778 return (int)(r*134217728.0);
80779 }
80780
80781 /*
80782 ** This routine is callback for sqlite3WalkExpr().
80783 **
@@ -79850,11 +80905,11 @@
80905 ** EVIDENCE-OF: R-36850-34127 The likely(X) function is short-hand for
80906 ** likelihood(X,0.9375).
80907 ** EVIDENCE-OF: R-53436-40973 The likely(X) function is equivalent to
80908 ** likelihood(X,0.9375). */
80909 /* TUNING: unlikely() probability is 0.0625. likely() is 0.9375 */
80910 pExpr->iTable = pDef->zName[0]=='u' ? 8388608 : 125829120;
80911 }
80912 }
80913 #ifndef SQLITE_OMIT_AUTHORIZATION
80914 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
80915 if( auth!=SQLITE_OK ){
@@ -81807,69 +82862,79 @@
82862 sqlite3DbFree(db, pList->a);
82863 sqlite3DbFree(db, pList);
82864 }
82865
82866 /*
82867 ** These routines are Walker callbacks used to check expressions to
82868 ** see if they are "constant" for some definition of constant. The
82869 ** Walker.eCode value determines the type of "constant" we are looking
82870 ** for.
82871 **
82872 ** These callback routines are used to implement the following:
82873 **
82874 ** sqlite3ExprIsConstant() pWalker->eCode==1
82875 ** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
82876 ** sqlite3ExprRefOneTableOnly() pWalker->eCode==3
82877 ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
82878 **
82879 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
82880 ** is found to not be a constant.
82881 **
82882 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions
82883 ** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing
82884 ** an existing schema and 4 when processing a new statement. A bound
82885 ** parameter raises an error for new statements, but is silently converted
82886 ** to NULL for existing schemas. This allows sqlite_master tables that
82887 ** contain a bound parameter because they were generated by older versions
82888 ** of SQLite to be parsed by newer versions of SQLite without raising a
82889 ** malformed schema error.
82890 */
82891 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
82892
82893 /* If pWalker->eCode is 2 then any term of the expression that comes from
82894 ** the ON or USING clauses of a left join disqualifies the expression
82895 ** from being considered constant. */
82896 if( pWalker->eCode==2 && ExprHasProperty(pExpr, EP_FromJoin) ){
82897 pWalker->eCode = 0;
82898 return WRC_Abort;
82899 }
82900
82901 switch( pExpr->op ){
82902 /* Consider functions to be constant if all their arguments are constant
82903 ** and either pWalker->eCode==4 or 5 or the function has the
82904 ** SQLITE_FUNC_CONST flag. */
82905 case TK_FUNCTION:
82906 if( pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_Constant) ){
82907 return WRC_Continue;
82908 }else{
82909 pWalker->eCode = 0;
82910 return WRC_Abort;
82911 }
 
82912 case TK_ID:
82913 case TK_COLUMN:
82914 case TK_AGG_FUNCTION:
82915 case TK_AGG_COLUMN:
82916 testcase( pExpr->op==TK_ID );
82917 testcase( pExpr->op==TK_COLUMN );
82918 testcase( pExpr->op==TK_AGG_FUNCTION );
82919 testcase( pExpr->op==TK_AGG_COLUMN );
82920 if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
82921 return WRC_Continue;
82922 }else{
82923 pWalker->eCode = 0;
82924 return WRC_Abort;
82925 }
82926 case TK_VARIABLE:
82927 if( pWalker->eCode==5 ){
82928 /* Silently convert bound parameters that appear inside of CREATE
82929 ** statements into a NULL when parsing the CREATE statement text out
82930 ** of the sqlite_master table */
82931 pExpr->op = TK_NULL;
82932 }else if( pWalker->eCode==4 ){
82933 /* A bound parameter in a CREATE statement that originates from
82934 ** sqlite3_prepare() causes an error */
82935 pWalker->eCode = 0;
82936 return WRC_Abort;
82937 }
82938 /* Fall through */
82939 default:
82940 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
@@ -81877,57 +82942,68 @@
82942 return WRC_Continue;
82943 }
82944 }
82945 static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
82946 UNUSED_PARAMETER(NotUsed);
82947 pWalker->eCode = 0;
82948 return WRC_Abort;
82949 }
82950 static int exprIsConst(Expr *p, int initFlag, int iCur){
82951 Walker w;
82952 memset(&w, 0, sizeof(w));
82953 w.eCode = initFlag;
82954 w.xExprCallback = exprNodeIsConstant;
82955 w.xSelectCallback = selectNodeIsConstant;
82956 w.u.iCur = iCur;
82957 sqlite3WalkExpr(&w, p);
82958 return w.eCode;
82959 }
82960
82961 /*
82962 ** Walk an expression tree. Return non-zero if the expression is constant
82963 ** and 0 if it involves variables or function calls.
82964 **
82965 ** For the purposes of this function, a double-quoted string (ex: "abc")
82966 ** is considered a variable but a single-quoted string (ex: 'abc') is
82967 ** a constant.
82968 */
82969 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr *p){
82970 return exprIsConst(p, 1, 0);
82971 }
82972
82973 /*
82974 ** Walk an expression tree. Return non-zero if the expression is constant
82975 ** that does no originate from the ON or USING clauses of a join.
82976 ** Return 0 if it involves variables or function calls or terms from
82977 ** an ON or USING clause.
82978 */
82979 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr *p){
82980 return exprIsConst(p, 2, 0);
82981 }
82982
82983 /*
82984 ** Walk an expression tree. Return non-zero if the expression constant
82985 ** for any single row of the table with cursor iCur. In other words, the
82986 ** expression must not refer to any non-deterministic function nor any
82987 ** table other than iCur.
82988 */
82989 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
82990 return exprIsConst(p, 3, iCur);
82991 }
82992
82993 /*
82994 ** Walk an expression tree. Return non-zero if the expression is constant
82995 ** or a function call with constant arguments. Return and 0 if there
82996 ** are any variables.
82997 **
82998 ** For the purposes of this function, a double-quoted string (ex: "abc")
82999 ** is considered a variable but a single-quoted string (ex: 'abc') is
83000 ** a constant.
83001 */
83002 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr *p, u8 isInit){
83003 assert( isInit==0 || isInit==1 );
83004 return exprIsConst(p, 4+isInit, 0);
83005 }
83006
83007 /*
83008 ** If the expression p codes a constant integer that is small enough
83009 ** to fit in a 32-bit integer, return 1 and put the value of the integer
@@ -81990,11 +83066,12 @@
83066 case TK_FLOAT:
83067 case TK_BLOB:
83068 return 0;
83069 case TK_COLUMN:
83070 assert( p->pTab!=0 );
83071 return ExprHasProperty(p, EP_CanBeNull) ||
83072 (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
83073 default:
83074 return 1;
83075 }
83076 }
83077
@@ -82433,11 +83510,10 @@
83510 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
83511 dest.affSdst = (u8)affinity;
83512 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
83513 pSelect->iLimit = 0;
83514 testcase( pSelect->selFlags & SF_Distinct );
 
83515 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
83516 if( sqlite3Select(pParse, pSelect, &dest) ){
83517 sqlite3KeyInfoUnref(pKeyInfo);
83518 return 0;
83519 }
@@ -83580,11 +84656,14 @@
84656 target
84657 ));
84658
84659 #ifndef SQLITE_OMIT_FLOATING_POINT
84660 /* If the column has REAL affinity, it may currently be stored as an
84661 ** integer. Use OP_RealAffinity to make sure it is really real.
84662 **
84663 ** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
84664 ** floating point when extracting it from the record. */
84665 if( pExpr->iColumn>=0
84666 && pTab->aCol[pExpr->iColumn].affinity==SQLITE_AFF_REAL
84667 ){
84668 sqlite3VdbeAddOp1(v, OP_RealAffinity, target);
84669 }
@@ -87232,27 +88311,32 @@
88311 aLog[i] = sqlite3LogEst(v);
88312 #endif
88313 if( *z==' ' ) z++;
88314 }
88315 #ifndef SQLITE_ENABLE_STAT3_OR_STAT4
88316 assert( pIndex!=0 ); {
88317 #else
88318 if( pIndex ){
88319 #endif
88320 pIndex->bUnordered = 0;
88321 pIndex->noSkipScan = 0;
88322 while( z[0] ){
88323 if( sqlite3_strglob("unordered*", z)==0 ){
88324 pIndex->bUnordered = 1;
88325 }else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
88326 pIndex->szIdxRow = sqlite3LogEst(sqlite3Atoi(z+3));
88327 }else if( sqlite3_strglob("noskipscan*", z)==0 ){
88328 pIndex->noSkipScan = 1;
88329 }
88330 #ifdef SQLITE_ENABLE_COSTMULT
88331 else if( sqlite3_strglob("costmult=[0-9]*",z)==0 ){
88332 pIndex->pTable->costMult = sqlite3LogEst(sqlite3Atoi(z+9));
88333 }
88334 #endif
88335 while( z[0]!=0 && z[0]!=' ' ) z++;
88336 while( z[0]==' ' ) z++;
88337 }
 
 
 
88338 }
88339 }
88340
88341 /*
88342 ** This callback is invoked once for each index when reading the
@@ -87366,18 +88450,19 @@
88450 tRowcnt avgEq = 0;
88451 tRowcnt nRow; /* Number of rows in index */
88452 i64 nSum100 = 0; /* Number of terms contributing to sumEq */
88453 i64 nDist100; /* Number of distinct values in index */
88454
88455 if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
88456 nRow = pFinal->anLt[iCol];
88457 nDist100 = (i64)100 * pFinal->anDLt[iCol];
88458 nSample--;
88459 }else{
88460 nRow = pIdx->aiRowEst[0];
88461 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
88462 }
88463 pIdx->nRowEst0 = nRow;
88464
88465 /* Set nSum to the number of distinct (iCol+1) field prefixes that
88466 ** occur in the stat4 table for this index. Set sumEq to the sum of
88467 ** the nEq values for column iCol for the same set (adding the value
88468 ** only once where there exist duplicate prefixes). */
@@ -87635,11 +88720,11 @@
88720 }
88721
88722
88723 /* Load the statistics from the sqlite_stat4 table. */
88724 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
88725 if( rc==SQLITE_OK && OptimizationEnabled(db, SQLITE_Stat34) ){
88726 int lookasideEnabled = db->lookaside.bEnabled;
88727 db->lookaside.bEnabled = 0;
88728 rc = loadStat4(db, sInfo.zDatabase);
88729 db->lookaside.bEnabled = lookasideEnabled;
88730 }
@@ -88317,10 +89402,13 @@
89402 SQLITE_API int sqlite3_set_authorizer(
89403 sqlite3 *db,
89404 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
89405 void *pArg
89406 ){
89407 #ifdef SQLITE_ENABLE_API_ARMOR
89408 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
89409 #endif
89410 sqlite3_mutex_enter(db->mutex);
89411 db->xAuth = (sqlite3_xauth)xAuth;
89412 db->pAuthArg = pArg;
89413 sqlite3ExpirePreparedStatements(db);
89414 sqlite3_mutex_leave(db->mutex);
@@ -88811,11 +89899,15 @@
89899 ** See also sqlite3LocateTable().
89900 */
89901 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
89902 Table *p = 0;
89903 int i;
89904
89905 #ifdef SQLITE_ENABLE_API_ARMOR
89906 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return 0;
89907 #endif
89908
89909 /* All mutexes are required for schema access. Make sure we hold them. */
89910 assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
89911 #if SQLITE_USER_AUTHENTICATION
89912 /* Only the admin user is allowed to know that the sqlite_user table
89913 ** exists */
@@ -94275,12 +95367,12 @@
95367 break;
95368 }
95369 default: {
95370 /* Because sqlite3_value_double() returns 0.0 if the argument is not
95371 ** something that can be converted into a number, we have:
95372 ** IMP: R-01992-00519 Abs(X) returns 0.0 if X is a string or blob
95373 ** that cannot be converted to a numeric value.
95374 */
95375 double rVal = sqlite3_value_double(argv[0]);
95376 if( rVal<0 ) rVal = -rVal;
95377 sqlite3_result_double(context, rVal);
95378 break;
@@ -99994,11 +101086,10 @@
101086 # define sqlite3_column_database_name16 0
101087 # define sqlite3_column_table_name 0
101088 # define sqlite3_column_table_name16 0
101089 # define sqlite3_column_origin_name 0
101090 # define sqlite3_column_origin_name16 0
 
101091 #endif
101092
101093 #ifdef SQLITE_OMIT_AUTHORIZATION
101094 # define sqlite3_set_authorizer 0
101095 #endif
@@ -102928,11 +104019,11 @@
104019 break;
104020 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
104021
104022 #ifndef SQLITE_OMIT_WAL
104023 /*
104024 ** PRAGMA [database.]wal_checkpoint = passive|full|restart|truncate
104025 **
104026 ** Checkpoint the database.
104027 */
104028 case PragTyp_WAL_CHECKPOINT: {
104029 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
@@ -102940,10 +104031,12 @@
104031 if( zRight ){
104032 if( sqlite3StrICmp(zRight, "full")==0 ){
104033 eMode = SQLITE_CHECKPOINT_FULL;
104034 }else if( sqlite3StrICmp(zRight, "restart")==0 ){
104035 eMode = SQLITE_CHECKPOINT_RESTART;
104036 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
104037 eMode = SQLITE_CHECKPOINT_TRUNCATE;
104038 }
104039 }
104040 sqlite3VdbeSetNumCols(v, 3);
104041 pParse->nMem = 3;
104042 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "busy", SQLITE_STATIC);
@@ -103834,13 +104927,16 @@
104927 Vdbe *pOld, /* VM being reprepared */
104928 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
104929 const char **pzTail /* OUT: End of parsed string */
104930 ){
104931 int rc;
104932
104933 #ifdef SQLITE_ENABLE_API_ARMOR
104934 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
104935 #endif
104936 *ppStmt = 0;
104937 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
104938 return SQLITE_MISUSE_BKPT;
104939 }
104940 sqlite3_mutex_enter(db->mutex);
104941 sqlite3BtreeEnterAll(db);
104942 rc = sqlite3Prepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
@@ -103943,13 +105039,15 @@
105039 */
105040 char *zSql8;
105041 const char *zTail8 = 0;
105042 int rc = SQLITE_OK;
105043
105044 #ifdef SQLITE_ENABLE_API_ARMOR
105045 if( ppStmt==0 ) return SQLITE_MISUSE_BKPT;
105046 #endif
105047 *ppStmt = 0;
105048 if( !sqlite3SafetyCheckOk(db)||zSql==0 ){
105049 return SQLITE_MISUSE_BKPT;
105050 }
105051 if( nBytes>=0 ){
105052 int sz;
105053 const char *z = (const char*)zSql;
@@ -108842,11 +109940,11 @@
109940 **
109941 ** SELECT DISTINCT xyz FROM ... ORDER BY xyz
109942 **
109943 ** is transformed to:
109944 **
109945 ** SELECT xyz FROM ... GROUP BY xyz ORDER BY xyz
109946 **
109947 ** The second form is preferred as a single index (or temp-table) may be
109948 ** used for both the ORDER BY and DISTINCT processing. As originally
109949 ** written the query must use a temp-table for at least one of the ORDER
109950 ** BY and DISTINCT, and an index or separate temp-table for the other.
@@ -108855,11 +109953,10 @@
109953 && sqlite3ExprListCompare(sSort.pOrderBy, p->pEList, -1)==0
109954 ){
109955 p->selFlags &= ~SF_Distinct;
109956 p->pGroupBy = sqlite3ExprListDup(db, p->pEList, 0);
109957 pGroupBy = p->pGroupBy;
 
109958 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
109959 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
109960 ** original setting of the SF_Distinct flag, not the current setting */
109961 assert( sDistinct.isTnct );
109962 }
@@ -109658,10 +110755,13 @@
110755 char **pzErrMsg /* Write error messages here */
110756 ){
110757 int rc;
110758 TabResult res;
110759
110760 #ifdef SQLITE_ENABLE_API_ARMOR
110761 if( pazResult==0 ) return SQLITE_MISUSE_BKPT;
110762 #endif
110763 *pazResult = 0;
110764 if( pnColumn ) *pnColumn = 0;
110765 if( pnRow ) *pnRow = 0;
110766 if( pzErrMsg ) *pzErrMsg = 0;
110767 res.zErrMsg = 0;
@@ -111721,11 +112821,11 @@
112821 ** Two writes per page are required in step (3) because the original
112822 ** database content must be written into the rollback journal prior to
112823 ** overwriting the database with the vacuumed content.
112824 **
112825 ** Only 1x temporary space and only 1x writes would be required if
112826 ** the copy of step (3) were replaced by deleting the original database
112827 ** and renaming the transient database as the original. But that will
112828 ** not work if other processes are attached to the original database.
112829 ** And a power loss in between deleting the original and renaming the
112830 ** transient would cause the database file to appear to be deleted
112831 ** following reboot.
@@ -112079,10 +113179,13 @@
113179 sqlite3 *db, /* Database in which module is registered */
113180 const char *zName, /* Name assigned to this module */
113181 const sqlite3_module *pModule, /* The definition of the module */
113182 void *pAux /* Context pointer for xCreate/xConnect */
113183 ){
113184 #ifdef SQLITE_ENABLE_API_ARMOR
113185 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
113186 #endif
113187 return createModule(db, zName, pModule, pAux, 0);
113188 }
113189
113190 /*
113191 ** External API function used to create a new virtual-table module.
@@ -112092,10 +113195,13 @@
113195 const char *zName, /* Name assigned to this module */
113196 const sqlite3_module *pModule, /* The definition of the module */
113197 void *pAux, /* Context pointer for xCreate/xConnect */
113198 void (*xDestroy)(void *) /* Module destructor function */
113199 ){
113200 #ifdef SQLITE_ENABLE_API_ARMOR
113201 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
113202 #endif
113203 return createModule(db, zName, pModule, pAux, xDestroy);
113204 }
113205
113206 /*
113207 ** Lock the virtual table so that it cannot be disconnected.
@@ -112324,11 +113430,16 @@
113430 pTable->tabFlags |= TF_Virtual;
113431 pTable->nModuleArg = 0;
113432 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
113433 addModuleArgument(db, pTable, 0);
113434 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
113435 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
113436 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
113437 );
113438 pParse->sNameToken.n = (int)(
113439 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
113440 );
113441
113442 #ifndef SQLITE_OMIT_AUTHORIZATION
113443 /* Creating a virtual table invokes the authorization callback twice.
113444 ** The first invocation, to obtain permission to INSERT a row into the
113445 ** sqlite_master table, has already been made by sqlite3StartTable().
@@ -112696,10 +113807,13 @@
113807
113808 int rc = SQLITE_OK;
113809 Table *pTab;
113810 char *zErr = 0;
113811
113812 #ifdef SQLITE_ENABLE_API_ARMOR
113813 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
113814 #endif
113815 sqlite3_mutex_enter(db->mutex);
113816 if( !db->pVtabCtx || !(pTab = db->pVtabCtx->pTab) ){
113817 sqlite3Error(db, SQLITE_MISUSE);
113818 sqlite3_mutex_leave(db->mutex);
113819 return SQLITE_MISUSE_BKPT;
@@ -113052,10 +114166,13 @@
114166 */
114167 SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *db){
114168 static const unsigned char aMap[] = {
114169 SQLITE_ROLLBACK, SQLITE_ABORT, SQLITE_FAIL, SQLITE_IGNORE, SQLITE_REPLACE
114170 };
114171 #ifdef SQLITE_ENABLE_API_ARMOR
114172 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
114173 #endif
114174 assert( OE_Rollback==1 && OE_Abort==2 && OE_Fail==3 );
114175 assert( OE_Ignore==4 && OE_Replace==5 );
114176 assert( db->vtabOnConflict>=1 && db->vtabOnConflict<=5 );
114177 return (int)aMap[db->vtabOnConflict-1];
114178 }
@@ -113067,12 +114184,14 @@
114184 */
114185 SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){
114186 va_list ap;
114187 int rc = SQLITE_OK;
114188
114189 #ifdef SQLITE_ENABLE_API_ARMOR
114190 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
114191 #endif
114192 sqlite3_mutex_enter(db->mutex);
 
114193 va_start(ap, op);
114194 switch( op ){
114195 case SQLITE_VTAB_CONSTRAINT_SUPPORT: {
114196 VtabCtx *p = db->pVtabCtx;
114197 if( !p ){
@@ -113203,10 +114322,13 @@
114322 } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */
114323 Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
114324 } u;
114325 struct WhereLoop *pWLoop; /* The selected WhereLoop object */
114326 Bitmask notReady; /* FROM entries not usable at this level */
114327 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
114328 int addrVisit; /* Address at which row is visited */
114329 #endif
114330 };
114331
114332 /*
114333 ** Each instance of this object represents an algorithm for evaluating one
114334 ** term of a join. Every term of the FROM clause will have at least
@@ -113233,11 +114355,10 @@
114355 LogEst rRun; /* Cost of running each loop */
114356 LogEst nOut; /* Estimated number of output rows */
114357 union {
114358 struct { /* Information for internal btree tables */
114359 u16 nEq; /* Number of equality constraints */
 
114360 Index *pIndex; /* Index used, or NULL */
114361 } btree;
114362 struct { /* Information for virtual tables */
114363 int idxNum; /* Index number */
114364 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -113246,16 +114367,17 @@
114367 char *idxStr; /* Index identifier string */
114368 } vtab;
114369 } u;
114370 u32 wsFlags; /* WHERE_* flags describing the plan */
114371 u16 nLTerm; /* Number of entries in aLTerm[] */
114372 u16 nSkip; /* Number of NULL aLTerm[] entries */
114373 /**** whereLoopXfer() copies fields above ***********************/
114374 # define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
114375 u16 nLSlot; /* Number of slots allocated for aLTerm[] */
114376 WhereTerm **aLTerm; /* WhereTerms used */
114377 WhereLoop *pNextLoop; /* Next WhereLoop object in the WhereClause */
114378 WhereTerm *aLTermSpace[3]; /* Initial aLTerm[] space */
114379 };
114380
114381 /* This object holds the prerequisites and the cost of running a
114382 ** subquery on one operand of an OR operator in the WHERE clause.
114383 ** See WhereOrSet for additional information
@@ -113577,10 +114699,11 @@
114699 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
114700 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
114701 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
114702 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
114703 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
114704 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
114705
114706 /************** End of whereInt.h ********************************************/
114707 /************** Continuing where we left off in where.c **********************/
114708
114709 /*
@@ -113784,14 +114907,15 @@
114907 memcpy(pWC->a, pOld, sizeof(pWC->a[0])*pWC->nTerm);
114908 if( pOld!=pWC->aStatic ){
114909 sqlite3DbFree(db, pOld);
114910 }
114911 pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
114912 memset(&pWC->a[pWC->nTerm], 0, sizeof(pWC->a[0])*(pWC->nSlot-pWC->nTerm));
114913 }
114914 pTerm = &pWC->a[idx = pWC->nTerm++];
114915 if( p && ExprHasProperty(p, EP_Unlikely) ){
114916 pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
114917 }else{
114918 pTerm->truthProb = 1;
114919 }
114920 pTerm->pExpr = sqlite3ExprSkipCollate(p);
114921 pTerm->wtFlags = wtFlags;
@@ -114317,10 +115441,19 @@
115441 if( pDerived ){
115442 pDerived->flags |= pBase->flags & EP_FromJoin;
115443 pDerived->iRightJoinTable = pBase->iRightJoinTable;
115444 }
115445 }
115446
115447 /*
115448 ** Mark term iChild as being a child of term iParent
115449 */
115450 static void markTermAsChild(WhereClause *pWC, int iChild, int iParent){
115451 pWC->a[iChild].iParent = iParent;
115452 pWC->a[iChild].truthProb = pWC->a[iParent].truthProb;
115453 pWC->a[iParent].nChild++;
115454 }
115455
115456 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115457 /*
115458 ** Analyze a term that consists of two or more OR-connected
115459 ** subterms. So in:
@@ -114615,12 +115748,11 @@
115748 pNew->x.pList = pList;
115749 idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
115750 testcase( idxNew==0 );
115751 exprAnalyze(pSrc, pWC, idxNew);
115752 pTerm = &pWC->a[idxTerm];
115753 markTermAsChild(pWC, idxNew, idxTerm);
 
115754 }else{
115755 sqlite3ExprListDelete(db, pList);
115756 }
115757 pTerm->eOperator = WO_NOOP; /* case 1 trumps case 2 */
115758 }
@@ -114718,13 +115850,12 @@
115850 return;
115851 }
115852 idxNew = whereClauseInsert(pWC, pDup, TERM_VIRTUAL|TERM_DYNAMIC);
115853 if( idxNew==0 ) return;
115854 pNew = &pWC->a[idxNew];
115855 markTermAsChild(pWC, idxNew, idxTerm);
115856 pTerm = &pWC->a[idxTerm];
 
115857 pTerm->wtFlags |= TERM_COPIED;
115858 if( pExpr->op==TK_EQ
115859 && !ExprHasProperty(pExpr, EP_FromJoin)
115860 && OptimizationEnabled(db, SQLITE_Transitive)
115861 ){
@@ -114777,13 +115908,12 @@
115908 transferJoinMarkings(pNewExpr, pExpr);
115909 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
115910 testcase( idxNew==0 );
115911 exprAnalyze(pSrc, pWC, idxNew);
115912 pTerm = &pWC->a[idxTerm];
115913 markTermAsChild(pWC, idxNew, idxTerm);
115914 }
 
115915 }
115916 #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */
115917
115918 #if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY)
115919 /* Analyze a term that is composed of two or more subterms connected by
@@ -114854,13 +115984,12 @@
115984 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC);
115985 testcase( idxNew2==0 );
115986 exprAnalyze(pSrc, pWC, idxNew2);
115987 pTerm = &pWC->a[idxTerm];
115988 if( isComplete ){
115989 markTermAsChild(pWC, idxNew1, idxTerm);
115990 markTermAsChild(pWC, idxNew2, idxTerm);
 
115991 }
115992 }
115993 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
115994
115995 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -114889,13 +116018,12 @@
116018 pNewTerm = &pWC->a[idxNew];
116019 pNewTerm->prereqRight = prereqExpr;
116020 pNewTerm->leftCursor = pLeft->iTable;
116021 pNewTerm->u.leftColumn = pLeft->iColumn;
116022 pNewTerm->eOperator = WO_MATCH;
116023 markTermAsChild(pWC, idxNew, idxTerm);
116024 pTerm = &pWC->a[idxTerm];
 
116025 pTerm->wtFlags |= TERM_COPIED;
116026 pNewTerm->prereqAll = pTerm->prereqAll;
116027 }
116028 }
116029 #endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -114912,11 +116040,11 @@
116040 ** the start of the loop will prevent any results from being returned.
116041 */
116042 if( pExpr->op==TK_NOTNULL
116043 && pExpr->pLeft->op==TK_COLUMN
116044 && pExpr->pLeft->iColumn>=0
116045 && OptimizationEnabled(db, SQLITE_Stat34)
116046 ){
116047 Expr *pNewExpr;
116048 Expr *pLeft = pExpr->pLeft;
116049 int idxNew;
116050 WhereTerm *pNewTerm;
@@ -114931,13 +116059,12 @@
116059 pNewTerm = &pWC->a[idxNew];
116060 pNewTerm->prereqRight = 0;
116061 pNewTerm->leftCursor = pLeft->iTable;
116062 pNewTerm->u.leftColumn = pLeft->iColumn;
116063 pNewTerm->eOperator = WO_GT;
116064 markTermAsChild(pWC, idxNew, idxTerm);
116065 pTerm = &pWC->a[idxTerm];
 
116066 pTerm->wtFlags |= TERM_COPIED;
116067 pNewTerm->prereqAll = pTerm->prereqAll;
116068 }
116069 }
116070 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
@@ -115153,10 +116280,12 @@
116280 WhereLoop *pLoop; /* The Loop object */
116281 char *zNotUsed; /* Extra space on the end of pIdx */
116282 Bitmask idxCols; /* Bitmap of columns used for indexing */
116283 Bitmask extraCols; /* Bitmap of additional columns */
116284 u8 sentWarning = 0; /* True if a warnning has been issued */
116285 Expr *pPartial = 0; /* Partial Index Expression */
116286 int iContinue = 0; /* Jump here to skip excluded rows */
116287
116288 /* Generate code to skip over the creation and initialization of the
116289 ** transient index on 2nd and subsequent iterations of the loop. */
116290 v = pParse->pVdbe;
116291 assert( v!=0 );
@@ -115168,10 +116297,16 @@
116297 pTable = pSrc->pTab;
116298 pWCEnd = &pWC->a[pWC->nTerm];
116299 pLoop = pLevel->pWLoop;
116300 idxCols = 0;
116301 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
116302 if( pLoop->prereq==0
116303 && (pTerm->wtFlags & TERM_VIRTUAL)==0
116304 && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){
116305 pPartial = sqlite3ExprAnd(pParse->db, pPartial,
116306 sqlite3ExprDup(pParse->db, pTerm->pExpr, 0));
116307 }
116308 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
116309 int iCol = pTerm->u.leftColumn;
116310 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
116311 testcase( iCol==BMS );
116312 testcase( iCol==BMS-1 );
@@ -115180,11 +116315,13 @@
116315 "automatic index on %s(%s)", pTable->zName,
116316 pTable->aCol[iCol].zName);
116317 sentWarning = 1;
116318 }
116319 if( (idxCols & cMask)==0 ){
116320 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
116321 goto end_auto_index_create;
116322 }
116323 pLoop->aLTerm[nKeyCol++] = pTerm;
116324 idxCols |= cMask;
116325 }
116326 }
116327 }
@@ -115200,24 +116337,23 @@
116337 ** be a covering index because the index will not be updated if the
116338 ** original table changes and the index and table cannot both be used
116339 ** if they go out of sync.
116340 */
116341 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));
116342 mxBitCol = MIN(BMS-1,pTable->nCol);
116343 testcase( pTable->nCol==BMS-1 );
116344 testcase( pTable->nCol==BMS-2 );
116345 for(i=0; i<mxBitCol; i++){
116346 if( extraCols & MASKBIT(i) ) nKeyCol++;
116347 }
116348 if( pSrc->colUsed & MASKBIT(BMS-1) ){
116349 nKeyCol += pTable->nCol - BMS + 1;
116350 }
 
116351
116352 /* Construct the Index object to describe this index */
116353 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
116354 if( pIdx==0 ) goto end_auto_index_create;
116355 pLoop->u.btree.pIndex = pIdx;
116356 pIdx->zName = "auto-index";
116357 pIdx->pTable = pTable;
116358 n = 0;
116359 idxCols = 0;
@@ -115265,22 +116401,33 @@
116401 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
116402 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
116403 VdbeComment((v, "for %s", pTable->zName));
116404
116405 /* Fill the automatic index with content */
116406 sqlite3ExprCachePush(pParse);
116407 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
116408 if( pPartial ){
116409 iContinue = sqlite3VdbeMakeLabel(v);
116410 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);
116411 pLoop->wsFlags |= WHERE_PARTIALIDX;
116412 }
116413 regRecord = sqlite3GetTempReg(pParse);
116414 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
116415 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
116416 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
116417 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
116418 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
116419 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
116420 sqlite3VdbeJumpHere(v, addrTop);
116421 sqlite3ReleaseTempReg(pParse, regRecord);
116422 sqlite3ExprCachePop(pParse);
116423
116424 /* Jump here when skipping the initialization */
116425 sqlite3VdbeJumpHere(v, addrInit);
116426
116427 end_auto_index_create:
116428 sqlite3ExprDelete(pParse->db, pPartial);
116429 }
116430 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
116431
116432 #ifndef SQLITE_OMIT_VIRTUALTABLE
116433 /*
@@ -115436,22 +116583,22 @@
116583
116584 return pParse->nErr;
116585 }
116586 #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
116587
 
116588 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116589 /*
116590 ** Estimate the location of a particular key among all keys in an
116591 ** index. Store the results in aStat as follows:
116592 **
116593 ** aStat[0] Est. number of rows less than pVal
116594 ** aStat[1] Est. number of rows equal to pVal
116595 **
116596 ** Return the index of the sample that is the smallest sample that
116597 ** is greater than or equal to pRec.
116598 */
116599 static int whereKeyStats(
116600 Parse *pParse, /* Database connection */
116601 Index *pIdx, /* Index to consider domain of */
116602 UnpackedRecord *pRec, /* Vector of values to consider */
116603 int roundUp, /* Round up if true. Round down if false */
116604 tRowcnt *aStat /* OUT: stats written here */
@@ -115529,10 +116676,11 @@
116676 }else{
116677 iGap = iGap/3;
116678 }
116679 aStat[0] = iLower + iGap;
116680 }
116681 return i;
116682 }
116683 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
116684
116685 /*
116686 ** If it is not NULL, pTerm is a term that provides an upper or lower
@@ -115679,11 +116827,11 @@
116827 ** pLower pUpper
116828 **
116829 ** If either of the upper or lower bound is not present, then NULL is passed in
116830 ** place of the corresponding WhereTerm.
116831 **
116832 ** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index
116833 ** column subject to the range constraint. Or, equivalently, the number of
116834 ** equality constraints optimized by the proposed index scan. For example,
116835 ** assuming index p is on t1(a, b), and the SQL query is:
116836 **
116837 ** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...
@@ -115695,11 +116843,11 @@
116843 **
116844 ** then nEq is set to 0.
116845 **
116846 ** When this function is called, *pnOut is set to the sqlite3LogEst() of the
116847 ** number of rows that the index scan is expected to visit without
116848 ** considering the range constraints. If nEq is 0, then *pnOut is the number of
116849 ** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
116850 ** to account for the range constraints pLower and pUpper.
116851 **
116852 ** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be
116853 ** used, a single range inequality reduces the search space by a factor of 4.
@@ -115719,14 +116867,11 @@
116867
116868 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
116869 Index *p = pLoop->u.btree.pIndex;
116870 int nEq = pLoop->u.btree.nEq;
116871
116872 if( p->nSample>0 && nEq<p->nSampleCol ){
 
 
 
116873 if( nEq==pBuilder->nRecValid ){
116874 UnpackedRecord *pRec = pBuilder->pRec;
116875 tRowcnt a[2];
116876 u8 aff;
116877
@@ -115738,19 +116883,23 @@
116883 **
116884 ** Or, if pLower is NULL or $L cannot be extracted from it (because it
116885 ** is not a simple variable or literal value), the lower bound of the
116886 ** range is $P. Due to a quirk in the way whereKeyStats() works, even
116887 ** if $L is available, whereKeyStats() is called for both ($P) and
116888 ** ($P:$L) and the larger of the two returned values is used.
116889 **
116890 ** Similarly, iUpper is to be set to the estimate of the number of rows
116891 ** less than the upper bound of the range query. Where the upper bound
116892 ** is either ($P) or ($P:$U). Again, even if $U is available, both values
116893 ** of iUpper are requested of whereKeyStats() and the smaller used.
116894 **
116895 ** The number of rows between the two bounds is then just iUpper-iLower.
116896 */
116897 tRowcnt iLower; /* Rows less than the lower bound */
116898 tRowcnt iUpper; /* Rows less than the upper bound */
116899 int iLwrIdx = -2; /* aSample[] for the lower bound */
116900 int iUprIdx = -1; /* aSample[] for the upper bound */
116901
116902 if( pRec ){
116903 testcase( pRec->nField!=pBuilder->nRecValid );
116904 pRec->nField = pBuilder->nRecValid;
116905 }
@@ -115760,11 +116909,11 @@
116909 aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
116910 }
116911 /* Determine iLower and iUpper using ($P) only. */
116912 if( nEq==0 ){
116913 iLower = 0;
116914 iUpper = p->nRowEst0;
116915 }else{
116916 /* Note: this call could be optimized away - since the same values must
116917 ** have been requested when testing key $P in whereEqualScanEst(). */
116918 whereKeyStats(pParse, p, pRec, 0, a);
116919 iLower = a[0];
@@ -115784,11 +116933,11 @@
116933 int bOk; /* True if value is extracted from pExpr */
116934 Expr *pExpr = pLower->pExpr->pRight;
116935 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116936 if( rc==SQLITE_OK && bOk ){
116937 tRowcnt iNew;
116938 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);
116939 iNew = a[0] + ((pLower->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116940 if( iNew>iLower ) iLower = iNew;
116941 nOut--;
116942 pLower = 0;
116943 }
@@ -115799,11 +116948,11 @@
116948 int bOk; /* True if value is extracted from pExpr */
116949 Expr *pExpr = pUpper->pExpr->pRight;
116950 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
116951 if( rc==SQLITE_OK && bOk ){
116952 tRowcnt iNew;
116953 iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);
116954 iNew = a[0] + ((pUpper->eOperator & (WO_GT|WO_LE)) ? a[1] : 0);
116955 if( iNew<iUpper ) iUpper = iNew;
116956 nOut--;
116957 pUpper = 0;
116958 }
@@ -115811,10 +116960,15 @@
116960
116961 pBuilder->pRec = pRec;
116962 if( rc==SQLITE_OK ){
116963 if( iUpper>iLower ){
116964 nNew = sqlite3LogEst(iUpper - iLower);
116965 /* TUNING: If both iUpper and iLower are derived from the same
116966 ** sample, then assume they are 4x more selective. This brings
116967 ** the estimated selectivity more in line with what it would be
116968 ** if estimated without the use of STAT3/4 tables. */
116969 if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );
116970 }else{
116971 nNew = 10; assert( 10==sqlite3LogEst(2) );
116972 }
116973 if( nNew<nOut ){
116974 nOut = nNew;
@@ -115835,16 +116989,19 @@
116989 #endif
116990 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
116991 nNew = whereRangeAdjust(pLower, nOut);
116992 nNew = whereRangeAdjust(pUpper, nNew);
116993
116994 /* TUNING: If there is both an upper and lower limit and neither limit
116995 ** has an application-defined likelihood(), assume the range is
116996 ** reduced by an additional 75%. This means that, by default, an open-ended
116997 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the
116998 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to
116999 ** match 1/64 of the index. */
117000 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
117001 nNew -= 20;
117002 }
117003
117004 nOut -= (pLower!=0) + (pUpper!=0);
117005 if( nNew<10 ) nNew = 10;
117006 if( nNew<nOut ) nOut = nNew;
117007 #if defined(WHERETRACE_ENABLED)
@@ -116200,11 +117357,11 @@
117357
117358 /* This module is only called on query plans that use an index. */
117359 pLoop = pLevel->pWLoop;
117360 assert( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 );
117361 nEq = pLoop->u.btree.nEq;
117362 nSkip = pLoop->nSkip;
117363 pIdx = pLoop->u.btree.pIndex;
117364 assert( pIdx!=0 );
117365
117366 /* Figure out how many memory cells we will need then allocate them.
117367 */
@@ -116314,11 +117471,11 @@
117471 ** "a=? AND b>?"
117472 */
117473 static void explainIndexRange(StrAccum *pStr, WhereLoop *pLoop, Table *pTab){
117474 Index *pIndex = pLoop->u.btree.pIndex;
117475 u16 nEq = pLoop->u.btree.nEq;
117476 u16 nSkip = pLoop->nSkip;
117477 int i, j;
117478 Column *aCol = pTab->aCol;
117479 i16 *aiColumn = pIndex->aiColumn;
117480
117481 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
@@ -116345,23 +117502,27 @@
117502 sqlite3StrAccumAppend(pStr, ")", 1);
117503 }
117504
117505 /*
117506 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
117507 ** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
117508 ** defined at compile-time. If it is not a no-op, a single OP_Explain opcode
117509 ** is added to the output to describe the table scan strategy in pLevel.
117510 **
117511 ** If an OP_Explain opcode is added to the VM, its address is returned.
117512 ** Otherwise, if no OP_Explain is coded, zero is returned.
117513 */
117514 static int explainOneScan(
117515 Parse *pParse, /* Parse context */
117516 SrcList *pTabList, /* Table list this loop refers to */
117517 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
117518 int iLevel, /* Value for "level" column of output */
117519 int iFrom, /* Value for "from" column of output */
117520 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
117521 ){
117522 int ret = 0;
117523 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
117524 if( pParse->explain==2 )
117525 #endif
117526 {
117527 struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
117528 Vdbe *v = pParse->pVdbe; /* VM being constructed */
@@ -116374,11 +117535,11 @@
117535 StrAccum str; /* EQP output string */
117536 char zBuf[100]; /* Initial space for EQP output string */
117537
117538 pLoop = pLevel->pWLoop;
117539 flags = pLoop->wsFlags;
117540 if( (flags&WHERE_MULTI_OR) || (wctrlFlags&WHERE_ONETABLE_ONLY) ) return 0;
117541
117542 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
117543 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
117544 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
117545
@@ -116403,10 +117564,12 @@
117564 assert( !(flags&WHERE_AUTO_INDEX) || (flags&WHERE_IDX_ONLY) );
117565 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
117566 if( isSearch ){
117567 zFmt = "PRIMARY KEY";
117568 }
117569 }else if( flags & WHERE_PARTIALIDX ){
117570 zFmt = "AUTOMATIC PARTIAL COVERING INDEX";
117571 }else if( flags & WHERE_AUTO_INDEX ){
117572 zFmt = "AUTOMATIC COVERING INDEX";
117573 }else if( flags & WHERE_IDX_ONLY ){
117574 zFmt = "COVERING INDEX %s";
117575 }else{
@@ -116444,16 +117607,49 @@
117607 }else{
117608 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
117609 }
117610 #endif
117611 zMsg = sqlite3StrAccumFinish(&str);
117612 ret = sqlite3VdbeAddOp4(v, OP_Explain, iId, iLevel, iFrom, zMsg,P4_DYNAMIC);
117613 }
117614 return ret;
117615 }
117616 #else
117617 # define explainOneScan(u,v,w,x,y,z) 0
117618 #endif /* SQLITE_OMIT_EXPLAIN */
117619
117620 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
117621 /*
117622 ** Configure the VM passed as the first argument with an
117623 ** sqlite3_stmt_scanstatus() entry corresponding to the scan used to
117624 ** implement level pLvl. Argument pSrclist is a pointer to the FROM
117625 ** clause that the scan reads data from.
117626 **
117627 ** If argument addrExplain is not 0, it must be the address of an
117628 ** OP_Explain instruction that describes the same loop.
117629 */
117630 static void addScanStatus(
117631 Vdbe *v, /* Vdbe to add scanstatus entry to */
117632 SrcList *pSrclist, /* FROM clause pLvl reads data from */
117633 WhereLevel *pLvl, /* Level to add scanstatus() entry for */
117634 int addrExplain /* Address of OP_Explain (or 0) */
117635 ){
117636 const char *zObj = 0;
117637 WhereLoop *pLoop = pLvl->pWLoop;
117638 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
117639 zObj = pLoop->u.btree.pIndex->zName;
117640 }else{
117641 zObj = pSrclist->a[pLvl->iFrom].zName;
117642 }
117643 sqlite3VdbeScanStatus(
117644 v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
117645 );
117646 }
117647 #else
117648 # define addScanStatus(a, b, c, d) ((void)d)
117649 #endif
117650
117651
117652
117653 /*
117654 ** Generate code for the start of the iLevel-th loop in the WHERE clause
117655 ** implementation described by pWInfo.
@@ -116751,11 +117947,11 @@
117947 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
117948 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
117949
117950 pIdx = pLoop->u.btree.pIndex;
117951 iIdxCur = pLevel->iIdxCur;
117952 assert( nEq>=pLoop->nSkip );
117953
117954 /* If this loop satisfies a sort order (pOrderBy) request that
117955 ** was passed to this function to implement a "SELECT min(x) ..."
117956 ** query, then the caller will only allow the loop to run for
117957 ** a single iteration. This means that the first row returned
@@ -116768,11 +117964,11 @@
117964 || (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0 );
117965 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
117966 && pWInfo->nOBSat>0
117967 && (pIdx->nKeyCol>nEq)
117968 ){
117969 assert( pLoop->nSkip==0 );
117970 bSeekPastNull = 1;
117971 nExtraReg = 1;
117972 }
117973
117974 /* Find any inequality constraint terms for the start and end
@@ -117081,14 +118277,13 @@
118277 int iTerm;
118278 for(iTerm=0; iTerm<pWC->nTerm; iTerm++){
118279 Expr *pExpr = pWC->a[iTerm].pExpr;
118280 if( &pWC->a[iTerm] == pTerm ) continue;
118281 if( ExprHasProperty(pExpr, EP_FromJoin) ) continue;
118282 if( (pWC->a[iTerm].wtFlags & TERM_VIRTUAL)!=0 ) continue;
 
 
118283 if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
118284 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
118285 pExpr = sqlite3ExprDup(db, pExpr, 0);
118286 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
118287 }
118288 if( pAndExpr ){
118289 pAndExpr = sqlite3PExpr(pParse, TK_AND, 0, pAndExpr, 0);
@@ -117117,13 +118312,15 @@
118312 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
118313 wctrlFlags, iCovCur);
118314 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
118315 if( pSubWInfo ){
118316 WhereLoop *pSubLoop;
118317 int addrExplain = explainOneScan(
118318 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
118319 );
118320 addScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
118321
118322 /* This is the sub-WHERE clause body. First skip over
118323 ** duplicate rows from prior sub-WHERE clauses, and record the
118324 ** rowid (or PRIMARY KEY) for the current row so that the same
118325 ** row will be skipped in subsequent sub-WHERE clauses.
118326 */
@@ -117249,10 +118446,14 @@
118446 VdbeCoverageIf(v, bRev==0);
118447 VdbeCoverageIf(v, bRev!=0);
118448 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
118449 }
118450 }
118451
118452 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
118453 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
118454 #endif
118455
118456 /* Insert code to test every subexpression that can be completely
118457 ** computed using the current set of tables.
118458 */
118459 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
@@ -117389,11 +118590,11 @@
118590 }
118591 sqlite3DebugPrintf(" %-19s", z);
118592 sqlite3_free(z);
118593 }
118594 if( p->wsFlags & WHERE_SKIPSCAN ){
118595 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);
118596 }else{
118597 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);
118598 }
118599 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
118600 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){
@@ -117500,34 +118701,41 @@
118701 sqlite3DbFree(db, pWInfo);
118702 }
118703 }
118704
118705 /*
118706 ** Return TRUE if all of the following are true:
118707 **
118708 ** (1) X has the same or lower cost that Y
118709 ** (2) X is a proper subset of Y
118710 ** (3) X skips at least as many columns as Y
118711 **
118712 ** By "proper subset" we mean that X uses fewer WHERE clause terms
118713 ** than Y and that every WHERE clause term used by X is also used
118714 ** by Y.
118715 **
118716 ** If X is a proper subset of Y then Y is a better choice and ought
118717 ** to have a lower cost. This routine returns TRUE when that cost
118718 ** relationship is inverted and needs to be adjusted. The third rule
118719 ** was added because if X uses skip-scan less than Y it still might
118720 ** deserve a lower cost even if it is a proper subset of Y.
118721 */
118722 static int whereLoopCheaperProperSubset(
118723 const WhereLoop *pX, /* First WhereLoop to compare */
118724 const WhereLoop *pY /* Compare against this WhereLoop */
118725 ){
118726 int i, j;
118727 if( pX->nLTerm-pX->nSkip >= pY->nLTerm-pY->nSkip ){
118728 return 0; /* X is not a subset of Y */
118729 }
118730 if( pY->nSkip > pX->nSkip ) return 0;
118731 if( pX->rRun >= pY->rRun ){
118732 if( pX->rRun > pY->rRun ) return 0; /* X costs more than Y */
118733 if( pX->nOut > pY->nOut ) return 0; /* X costs more than Y */
118734 }
118735 for(i=pX->nLTerm-1; i>=0; i--){
118736 if( pX->aLTerm[i]==0 ) continue;
118737 for(j=pY->nLTerm-1; j>=0; j--){
118738 if( pY->aLTerm[j]==pX->aLTerm[i] ) break;
118739 }
118740 if( j<0 ) return 0; /* X not a subset of Y since term X[i] not used by Y */
118741 }
@@ -117545,37 +118753,28 @@
118753 ** is a proper subset.
118754 **
118755 ** To say "WhereLoop X is a proper subset of Y" means that X uses fewer
118756 ** WHERE clause terms than Y and that every WHERE clause term used by X is
118757 ** also used by Y.
 
 
 
 
 
 
 
 
 
 
 
118758 */
118759 static void whereLoopAdjustCost(const WhereLoop *p, WhereLoop *pTemplate){
118760 if( (pTemplate->wsFlags & WHERE_INDEXED)==0 ) return;
 
118761 for(; p; p=p->pNextLoop){
118762 if( p->iTab!=pTemplate->iTab ) continue;
118763 if( (p->wsFlags & WHERE_INDEXED)==0 ) continue;
 
118764 if( whereLoopCheaperProperSubset(p, pTemplate) ){
118765 /* Adjust pTemplate cost downward so that it is cheaper than its
118766 ** subset p. */
118767 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118768 pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut-1));
118769 pTemplate->rRun = p->rRun;
118770 pTemplate->nOut = p->nOut - 1;
118771 }else if( whereLoopCheaperProperSubset(pTemplate, p) ){
118772 /* Adjust pTemplate cost upward so that it is costlier than p since
118773 ** pTemplate is a proper subset of p */
118774 WHERETRACE(0x80,("subset cost adjustment %d,%d to %d,%d\n",
118775 pTemplate->rRun, pTemplate->nOut, p->rRun, p->nOut+1));
118776 pTemplate->rRun = p->rRun;
118777 pTemplate->nOut = p->nOut + 1;
118778 }
118779 }
118780 }
@@ -117616,12 +118815,13 @@
118815 ** rSetup. Call this SETUP-INVARIANT */
118816 assert( p->rSetup>=pTemplate->rSetup );
118817
118818 /* Any loop using an appliation-defined index (or PRIMARY KEY or
118819 ** UNIQUE constraint) with one or more == constraints is better
118820 ** than an automatic index. Unless it is a skip-scan. */
118821 if( (p->wsFlags & WHERE_AUTO_INDEX)!=0
118822 && (pTemplate->nSkip)==0
118823 && (pTemplate->wsFlags & WHERE_INDEXED)!=0
118824 && (pTemplate->wsFlags & WHERE_COLUMN_EQ)!=0
118825 && (p->prereq & pTemplate->prereq)==pTemplate->prereq
118826 ){
118827 break;
@@ -117776,25 +118976,46 @@
118976
118977 /*
118978 ** Adjust the WhereLoop.nOut value downward to account for terms of the
118979 ** WHERE clause that reference the loop but which are not used by an
118980 ** index.
118981 *
118982 ** For every WHERE clause term that is not used by the index
118983 ** and which has a truth probability assigned by one of the likelihood(),
118984 ** likely(), or unlikely() SQL functions, reduce the estimated number
118985 ** of output rows by the probability specified.
118986 **
118987 ** TUNING: For every WHERE clause term that is not used by the index
118988 ** and which does not have an assigned truth probability, heuristics
118989 ** described below are used to try to estimate the truth probability.
118990 ** TODO --> Perhaps this is something that could be improved by better
118991 ** table statistics.
118992 **
118993 ** Heuristic 1: Estimate the truth probability as 93.75%. The 93.75%
118994 ** value corresponds to -1 in LogEst notation, so this means decrement
118995 ** the WhereLoop.nOut field for every such WHERE clause term.
118996 **
118997 ** Heuristic 2: If there exists one or more WHERE clause terms of the
118998 ** form "x==EXPR" and EXPR is not a constant 0 or 1, then make sure the
118999 ** final output row estimate is no greater than 1/4 of the total number
119000 ** of rows in the table. In other words, assume that x==EXPR will filter
119001 ** out at least 3 out of 4 rows. If EXPR is -1 or 0 or 1, then maybe the
119002 ** "x" column is boolean or else -1 or 0 or 1 is a common default value
119003 ** on the "x" column and so in that case only cap the output row estimate
119004 ** at 1/2 instead of 1/4.
119005 */
119006 static void whereLoopOutputAdjust(
119007 WhereClause *pWC, /* The WHERE clause */
119008 WhereLoop *pLoop, /* The loop to adjust downward */
119009 LogEst nRow /* Number of rows in the entire table */
119010 ){
119011 WhereTerm *pTerm, *pX;
119012 Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
119013 int i, j, k;
119014 LogEst iReduce = 0; /* pLoop->nOut should not exceed nRow-iReduce */
119015
119016 assert( (pLoop->wsFlags & WHERE_AUTO_INDEX)==0 );
119017 for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
119018 if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
119019 if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
119020 if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
119021 for(j=pLoop->nLTerm-1; j>=0; j--){
@@ -117803,24 +119024,30 @@
119024 if( pX==pTerm ) break;
119025 if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
119026 }
119027 if( j<0 ){
119028 if( pTerm->truthProb<=0 ){
119029 /* If a truth probability is specified using the likelihood() hints,
119030 ** then use the probability provided by the application. */
119031 pLoop->nOut += pTerm->truthProb;
119032 }else{
119033 /* In the absence of explicit truth probabilities, use heuristics to
119034 ** guess a reasonable truth probability. */
119035 pLoop->nOut--;
119036 if( pTerm->eOperator&WO_EQ ){
119037 Expr *pRight = pTerm->pExpr->pRight;
119038 if( sqlite3ExprIsInteger(pRight, &k) && k>=(-1) && k<=1 ){
119039 k = 10;
119040 }else{
119041 k = 20;
119042 }
119043 if( iReduce<k ) iReduce = k;
119044 }
119045 }
119046 }
119047 }
119048 if( pLoop->nOut > nRow-iReduce ) pLoop->nOut = nRow - iReduce;
 
 
 
 
 
 
119049 }
119050
119051 /*
119052 ** Adjust the cost C by the costMult facter T. This only occurs if
119053 ** compiled with -DSQLITE_ENABLE_COSTMULT
@@ -117857,11 +119084,11 @@
119084 int opMask; /* Valid operators for constraints */
119085 WhereScan scan; /* Iterator for WHERE terms */
119086 Bitmask saved_prereq; /* Original value of pNew->prereq */
119087 u16 saved_nLTerm; /* Original value of pNew->nLTerm */
119088 u16 saved_nEq; /* Original value of pNew->u.btree.nEq */
119089 u16 saved_nSkip; /* Original value of pNew->nSkip */
119090 u32 saved_wsFlags; /* Original value of pNew->wsFlags */
119091 LogEst saved_nOut; /* Original value of pNew->nOut */
119092 int iCol; /* Index of the column in the table */
119093 int rc = SQLITE_OK; /* Return code */
119094 LogEst rSize; /* Number of rows in the table */
@@ -117886,56 +119113,18 @@
119113 iCol = pProbe->aiColumn[pNew->u.btree.nEq];
119114
119115 pTerm = whereScanInit(&scan, pBuilder->pWC, pSrc->iCursor, iCol,
119116 opMask, pProbe);
119117 saved_nEq = pNew->u.btree.nEq;
119118 saved_nSkip = pNew->nSkip;
119119 saved_nLTerm = pNew->nLTerm;
119120 saved_wsFlags = pNew->wsFlags;
119121 saved_prereq = pNew->prereq;
119122 saved_nOut = pNew->nOut;
119123 pNew->rSetup = 0;
119124 rSize = pProbe->aiRowLogEst[0];
119125 rLogSize = estLog(rSize);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119126 for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
119127 u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */
119128 LogEst rCostIdx;
119129 LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */
119130 int nIn = 0;
@@ -118026,11 +119215,10 @@
119215 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
119216 tRowcnt nOut = 0;
119217 if( nInMul==0
119218 && pProbe->nSample
119219 && pNew->u.btree.nEq<=pProbe->nSampleCol
 
119220 && ((eOp & WO_IN)==0 || !ExprHasProperty(pTerm->pExpr, EP_xIsSelect))
119221 ){
119222 Expr *pExpr = pTerm->pExpr;
119223 if( (eOp & (WO_EQ|WO_ISNULL))!=0 ){
119224 testcase( eOp & WO_EQ );
@@ -118094,14 +119282,49 @@
119282 pBuilder->nRecValid = nRecValid;
119283 #endif
119284 }
119285 pNew->prereq = saved_prereq;
119286 pNew->u.btree.nEq = saved_nEq;
119287 pNew->nSkip = saved_nSkip;
119288 pNew->wsFlags = saved_wsFlags;
119289 pNew->nOut = saved_nOut;
119290 pNew->nLTerm = saved_nLTerm;
119291
119292 /* Consider using a skip-scan if there are no WHERE clause constraints
119293 ** available for the left-most terms of the index, and if the average
119294 ** number of repeats in the left-most terms is at least 18.
119295 **
119296 ** The magic number 18 is selected on the basis that scanning 17 rows
119297 ** is almost always quicker than an index seek (even though if the index
119298 ** contains fewer than 2^17 rows we assume otherwise in other parts of
119299 ** the code). And, even if it is not, it should not be too much slower.
119300 ** On the other hand, the extra seeks could end up being significantly
119301 ** more expensive. */
119302 assert( 42==sqlite3LogEst(18) );
119303 if( saved_nEq==saved_nSkip
119304 && saved_nEq+1<pProbe->nKeyCol
119305 && pProbe->noSkipScan==0
119306 && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
119307 && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
119308 ){
119309 LogEst nIter;
119310 pNew->u.btree.nEq++;
119311 pNew->nSkip++;
119312 pNew->aLTerm[pNew->nLTerm++] = 0;
119313 pNew->wsFlags |= WHERE_SKIPSCAN;
119314 nIter = pProbe->aiRowLogEst[saved_nEq] - pProbe->aiRowLogEst[saved_nEq+1];
119315 pNew->nOut -= nIter;
119316 /* TUNING: Because uncertainties in the estimates for skip-scan queries,
119317 ** add a 1.375 fudge factor to make skip-scan slightly less likely. */
119318 nIter += 5;
119319 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nIter + nInMul);
119320 pNew->nOut = saved_nOut;
119321 pNew->u.btree.nEq = saved_nEq;
119322 pNew->nSkip = saved_nSkip;
119323 pNew->wsFlags = saved_wsFlags;
119324 }
119325
119326 return rc;
119327 }
119328
119329 /*
119330 ** Return True if it is possible that pIndex might be useful in
@@ -118276,11 +119499,11 @@
119499 WhereTerm *pWCEnd = pWC->a + pWC->nTerm;
119500 for(pTerm=pWC->a; rc==SQLITE_OK && pTerm<pWCEnd; pTerm++){
119501 if( pTerm->prereqRight & pNew->maskSelf ) continue;
119502 if( termCanDriveIndex(pTerm, pSrc, 0) ){
119503 pNew->u.btree.nEq = 1;
119504 pNew->nSkip = 0;
119505 pNew->u.btree.pIndex = 0;
119506 pNew->nLTerm = 1;
119507 pNew->aLTerm[0] = pTerm;
119508 /* TUNING: One-time cost for computing the automatic index is
119509 ** estimated to be X*N*log2(N) where N is the number of rows in
@@ -118317,11 +119540,11 @@
119540 testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
119541 continue; /* Partial index inappropriate for this query */
119542 }
119543 rSize = pProbe->aiRowLogEst[0];
119544 pNew->u.btree.nEq = 0;
119545 pNew->nSkip = 0;
119546 pNew->nLTerm = 0;
119547 pNew->iSortIdx = 0;
119548 pNew->rSetup = 0;
119549 pNew->prereq = mExtra;
119550 pNew->nOut = rSize;
@@ -118867,11 +120090,11 @@
120090 for(j=0; j<nColumn; j++){
120091 u8 bOnce; /* True to run the ORDER BY search loop */
120092
120093 /* Skip over == and IS NULL terms */
120094 if( j<pLoop->u.btree.nEq
120095 && pLoop->nSkip==0
120096 && ((i = pLoop->aLTerm[j]->eOperator) & (WO_EQ|WO_ISNULL))!=0
120097 ){
120098 if( i & WO_ISNULL ){
120099 testcase( isOrderDistinct );
120100 isOrderDistinct = 0;
@@ -119321,11 +120544,11 @@
120544 }
120545 }
120546 }
120547
120548 #ifdef WHERETRACE_ENABLED /* >=2 */
120549 if( sqlite3WhereTrace & 0x02 ){
120550 sqlite3DebugPrintf("---- after round %d ----\n", iLoop);
120551 for(ii=0, pTo=aTo; ii<nTo; ii++, pTo++){
120552 sqlite3DebugPrintf(" %s cost=%-3d nrow=%-3d order=%c",
120553 wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
120554 pTo->isOrdered>=0 ? (pTo->isOrdered+'0') : '?');
@@ -119440,11 +120663,11 @@
120663 if( pItem->zIndex ) return 0;
120664 iCur = pItem->iCursor;
120665 pWC = &pWInfo->sWC;
120666 pLoop = pBuilder->pNew;
120667 pLoop->wsFlags = 0;
120668 pLoop->nSkip = 0;
120669 pTerm = findTerm(pWC, iCur, -1, 0, WO_EQ, 0);
120670 if( pTerm ){
120671 pLoop->wsFlags = WHERE_COLUMN_EQ|WHERE_IPK|WHERE_ONEROW;
120672 pLoop->aLTerm[0] = pTerm;
120673 pLoop->nLTerm = 1;
@@ -119452,11 +120675,10 @@
120675 /* TUNING: Cost of a rowid lookup is 10 */
120676 pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
120677 }else{
120678 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
120679 assert( pLoop->aLTermSpace==pLoop->aLTerm );
 
120680 if( !IsUniqueIndex(pIdx)
120681 || pIdx->pPartIdxWhere!=0
120682 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
120683 ) continue;
120684 for(j=0; j<pIdx->nKeyCol; j++){
@@ -119961,22 +121183,30 @@
121183 ** loop below generates code for a single nested loop of the VM
121184 ** program.
121185 */
121186 notReady = ~(Bitmask)0;
121187 for(ii=0; ii<nTabList; ii++){
121188 int addrExplain;
121189 int wsFlags;
121190 pLevel = &pWInfo->a[ii];
121191 wsFlags = pLevel->pWLoop->wsFlags;
121192 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
121193 if( (pLevel->pWLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){
121194 constructAutomaticIndex(pParse, &pWInfo->sWC,
121195 &pTabList->a[pLevel->iFrom], notReady, pLevel);
121196 if( db->mallocFailed ) goto whereBeginError;
121197 }
121198 #endif
121199 addrExplain = explainOneScan(
121200 pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
121201 );
121202 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
121203 notReady = codeOneLoopStart(pWInfo, ii, notReady);
121204 pWInfo->iContinue = pLevel->addrCont;
121205 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_ONETABLE_ONLY)==0 ){
121206 addScanStatus(v, pTabList, pLevel, addrExplain);
121207 }
121208 }
121209
121210 /* Done. */
121211 VdbeModuleComment((v, "Begin WHERE-core"));
121212 return pWInfo;
@@ -124640,10 +125870,17 @@
125870 ** is look for a semicolon that is not part of an string or comment.
125871 */
125872 SQLITE_API int sqlite3_complete(const char *zSql){
125873 u8 state = 0; /* Current state, using numbers defined in header comment */
125874 u8 token; /* Value of the next token */
125875
125876 #ifdef SQLITE_ENABLE_API_ARMOR
125877 if( zSql==0 ){
125878 (void)SQLITE_MISUSE_BKPT;
125879 return 0;
125880 }
125881 #endif
125882
125883 #ifndef SQLITE_OMIT_TRIGGER
125884 /* A complex statement machine used to detect the end of a CREATE TRIGGER
125885 ** statement. This is the normal case.
125886 */
@@ -125238,74 +126475,106 @@
126475
126476 va_start(ap, op);
126477 switch( op ){
126478
126479 /* Mutex configuration options are only available in a threadsafe
126480 ** compile.
126481 */
126482 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-54466-46756 */
126483 case SQLITE_CONFIG_SINGLETHREAD: {
126484 /* Disable all mutexing */
126485 sqlite3GlobalConfig.bCoreMutex = 0;
126486 sqlite3GlobalConfig.bFullMutex = 0;
126487 break;
126488 }
126489 #endif
126490 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-20520-54086 */
126491 case SQLITE_CONFIG_MULTITHREAD: {
126492 /* Disable mutexing of database connections */
126493 /* Enable mutexing of core data structures */
126494 sqlite3GlobalConfig.bCoreMutex = 1;
126495 sqlite3GlobalConfig.bFullMutex = 0;
126496 break;
126497 }
126498 #endif
126499 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-59593-21810 */
126500 case SQLITE_CONFIG_SERIALIZED: {
126501 /* Enable all mutexing */
126502 sqlite3GlobalConfig.bCoreMutex = 1;
126503 sqlite3GlobalConfig.bFullMutex = 1;
126504 break;
126505 }
126506 #endif
126507 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-63666-48755 */
126508 case SQLITE_CONFIG_MUTEX: {
126509 /* Specify an alternative mutex implementation */
126510 sqlite3GlobalConfig.mutex = *va_arg(ap, sqlite3_mutex_methods*);
126511 break;
126512 }
126513 #endif
126514 #if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE>0 /* IMP: R-14450-37597 */
126515 case SQLITE_CONFIG_GETMUTEX: {
126516 /* Retrieve the current mutex implementation */
126517 *va_arg(ap, sqlite3_mutex_methods*) = sqlite3GlobalConfig.mutex;
126518 break;
126519 }
126520 #endif
126521
 
126522 case SQLITE_CONFIG_MALLOC: {
126523 /* EVIDENCE-OF: R-55594-21030 The SQLITE_CONFIG_MALLOC option takes a
126524 ** single argument which is a pointer to an instance of the
126525 ** sqlite3_mem_methods structure. The argument specifies alternative
126526 ** low-level memory allocation routines to be used in place of the memory
126527 ** allocation routines built into SQLite. */
126528 sqlite3GlobalConfig.m = *va_arg(ap, sqlite3_mem_methods*);
126529 break;
126530 }
126531 case SQLITE_CONFIG_GETMALLOC: {
126532 /* EVIDENCE-OF: R-51213-46414 The SQLITE_CONFIG_GETMALLOC option takes a
126533 ** single argument which is a pointer to an instance of the
126534 ** sqlite3_mem_methods structure. The sqlite3_mem_methods structure is
126535 ** filled with the currently defined memory allocation routines. */
126536 if( sqlite3GlobalConfig.m.xMalloc==0 ) sqlite3MemSetDefault();
126537 *va_arg(ap, sqlite3_mem_methods*) = sqlite3GlobalConfig.m;
126538 break;
126539 }
126540 case SQLITE_CONFIG_MEMSTATUS: {
126541 /* EVIDENCE-OF: R-61275-35157 The SQLITE_CONFIG_MEMSTATUS option takes
126542 ** single argument of type int, interpreted as a boolean, which enables
126543 ** or disables the collection of memory allocation statistics. */
126544 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
126545 break;
126546 }
126547 case SQLITE_CONFIG_SCRATCH: {
126548 /* EVIDENCE-OF: R-08404-60887 There are three arguments to
126549 ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
126550 ** which the scratch allocations will be drawn, the size of each scratch
126551 ** allocation (sz), and the maximum number of scratch allocations (N). */
126552 sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
126553 sqlite3GlobalConfig.szScratch = va_arg(ap, int);
126554 sqlite3GlobalConfig.nScratch = va_arg(ap, int);
126555 break;
126556 }
126557 case SQLITE_CONFIG_PAGECACHE: {
126558 /* EVIDENCE-OF: R-31408-40510 There are three arguments to
126559 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory, the size
126560 ** of each page buffer (sz), and the number of pages (N). */
126561 sqlite3GlobalConfig.pPage = va_arg(ap, void*);
126562 sqlite3GlobalConfig.szPage = va_arg(ap, int);
126563 sqlite3GlobalConfig.nPage = va_arg(ap, int);
126564 break;
126565 }
126566 case SQLITE_CONFIG_PCACHE_HDRSZ: {
126567 /* EVIDENCE-OF: R-39100-27317 The SQLITE_CONFIG_PCACHE_HDRSZ option takes
126568 ** a single parameter which is a pointer to an integer and writes into
126569 ** that integer the number of extra bytes per page required for each page
126570 ** in SQLITE_CONFIG_PAGECACHE. */
126571 *va_arg(ap, int*) =
126572 sqlite3HeaderSizeBtree() +
126573 sqlite3HeaderSizePcache() +
126574 sqlite3HeaderSizePcache1();
126575 break;
126576 }
126577
126578 case SQLITE_CONFIG_PCACHE: {
126579 /* no-op */
126580 break;
@@ -125315,25 +126584,37 @@
126584 rc = SQLITE_ERROR;
126585 break;
126586 }
126587
126588 case SQLITE_CONFIG_PCACHE2: {
126589 /* EVIDENCE-OF: R-63325-48378 The SQLITE_CONFIG_PCACHE2 option takes a
126590 ** single argument which is a pointer to an sqlite3_pcache_methods2
126591 ** object. This object specifies the interface to a custom page cache
126592 ** implementation. */
126593 sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
126594 break;
126595 }
126596 case SQLITE_CONFIG_GETPCACHE2: {
126597 /* EVIDENCE-OF: R-22035-46182 The SQLITE_CONFIG_GETPCACHE2 option takes a
126598 ** single argument which is a pointer to an sqlite3_pcache_methods2
126599 ** object. SQLite copies of the current page cache implementation into
126600 ** that object. */
126601 if( sqlite3GlobalConfig.pcache2.xInit==0 ){
126602 sqlite3PCacheSetDefault();
126603 }
126604 *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
126605 break;
126606 }
126607
126608 /* EVIDENCE-OF: R-06626-12911 The SQLITE_CONFIG_HEAP option is only
126609 ** available if SQLite is compiled with either SQLITE_ENABLE_MEMSYS3 or
126610 ** SQLITE_ENABLE_MEMSYS5 and returns SQLITE_ERROR if invoked otherwise. */
126611 #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
126612 case SQLITE_CONFIG_HEAP: {
126613 /* EVIDENCE-OF: R-19854-42126 There are three arguments to
126614 ** SQLITE_CONFIG_HEAP: An 8-byte aligned pointer to the memory, the
126615 ** number of bytes in the memory buffer, and the minimum allocation size. */
126616 sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
126617 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126618 sqlite3GlobalConfig.mnReq = va_arg(ap, int);
126619
126620 if( sqlite3GlobalConfig.mnReq<1 ){
@@ -125342,21 +126623,23 @@
126623 /* cap min request size at 2^12 */
126624 sqlite3GlobalConfig.mnReq = (1<<12);
126625 }
126626
126627 if( sqlite3GlobalConfig.pHeap==0 ){
126628 /* EVIDENCE-OF: R-49920-60189 If the first pointer (the memory pointer)
126629 ** is NULL, then SQLite reverts to using its default memory allocator
126630 ** (the system malloc() implementation), undoing any prior invocation of
126631 ** SQLITE_CONFIG_MALLOC.
126632 **
126633 ** Setting sqlite3GlobalConfig.m to all zeros will cause malloc to
126634 ** revert to its default implementation when sqlite3_initialize() is run
126635 */
126636 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
126637 }else{
126638 /* EVIDENCE-OF: R-61006-08918 If the memory pointer is not NULL then the
126639 ** alternative memory allocator is engaged to handle all of SQLites
126640 ** memory allocation needs. */
 
126641 #ifdef SQLITE_ENABLE_MEMSYS3
126642 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
126643 #endif
126644 #ifdef SQLITE_ENABLE_MEMSYS5
126645 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys5();
@@ -125391,15 +126674,23 @@
126674 ** can be changed at start-time using the
126675 ** sqlite3_config(SQLITE_CONFIG_URI,1) or
126676 ** sqlite3_config(SQLITE_CONFIG_URI,0) configuration calls.
126677 */
126678 case SQLITE_CONFIG_URI: {
126679 /* EVIDENCE-OF: R-25451-61125 The SQLITE_CONFIG_URI option takes a single
126680 ** argument of type int. If non-zero, then URI handling is globally
126681 ** enabled. If the parameter is zero, then URI handling is globally
126682 ** disabled. */
126683 sqlite3GlobalConfig.bOpenUri = va_arg(ap, int);
126684 break;
126685 }
126686
126687 case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
126688 /* EVIDENCE-OF: R-36592-02772 The SQLITE_CONFIG_COVERING_INDEX_SCAN
126689 ** option takes a single integer argument which is interpreted as a
126690 ** boolean in order to enable or disable the use of covering indices for
126691 ** full table scans in the query optimizer. */
126692 sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
126693 break;
126694 }
126695
126696 #ifdef SQLITE_ENABLE_SQLLOG
@@ -125410,24 +126701,37 @@
126701 break;
126702 }
126703 #endif
126704
126705 case SQLITE_CONFIG_MMAP_SIZE: {
126706 /* EVIDENCE-OF: R-58063-38258 SQLITE_CONFIG_MMAP_SIZE takes two 64-bit
126707 ** integer (sqlite3_int64) values that are the default mmap size limit
126708 ** (the default setting for PRAGMA mmap_size) and the maximum allowed
126709 ** mmap size limit. */
126710 sqlite3_int64 szMmap = va_arg(ap, sqlite3_int64);
126711 sqlite3_int64 mxMmap = va_arg(ap, sqlite3_int64);
126712 /* EVIDENCE-OF: R-53367-43190 If either argument to this option is
126713 ** negative, then that argument is changed to its compile-time default.
126714 **
126715 ** EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
126716 ** silently truncated if necessary so that it does not exceed the
126717 ** compile-time maximum mmap size set by the SQLITE_MAX_MMAP_SIZE
126718 ** compile-time option.
126719 */
126720 if( mxMmap<0 || mxMmap>SQLITE_MAX_MMAP_SIZE ) mxMmap = SQLITE_MAX_MMAP_SIZE;
126721 if( szMmap<0 ) szMmap = SQLITE_DEFAULT_MMAP_SIZE;
126722 if( szMmap>mxMmap) szMmap = mxMmap;
126723 sqlite3GlobalConfig.mxMmap = mxMmap;
126724 sqlite3GlobalConfig.szMmap = szMmap;
126725 break;
126726 }
126727
126728 #if SQLITE_OS_WIN && defined(SQLITE_WIN32_MALLOC) /* IMP: R-04780-55815 */
126729 case SQLITE_CONFIG_WIN32_HEAPSIZE: {
126730 /* EVIDENCE-OF: R-34926-03360 SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit
126731 ** unsigned integer value that specifies the maximum size of the created
126732 ** heap. */
126733 sqlite3GlobalConfig.nHeap = va_arg(ap, int);
126734 break;
126735 }
126736 #endif
126737
@@ -125507,19 +126811,29 @@
126811
126812 /*
126813 ** Return the mutex associated with a database connection.
126814 */
126815 SQLITE_API sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
126816 #ifdef SQLITE_ENABLE_API_ARMOR
126817 if( !sqlite3SafetyCheckOk(db) ){
126818 (void)SQLITE_MISUSE_BKPT;
126819 return 0;
126820 }
126821 #endif
126822 return db->mutex;
126823 }
126824
126825 /*
126826 ** Free up as much memory as we can from the given database
126827 ** connection.
126828 */
126829 SQLITE_API int sqlite3_db_release_memory(sqlite3 *db){
126830 int i;
126831
126832 #ifdef SQLITE_ENABLE_API_ARMOR
126833 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
126834 #endif
126835 sqlite3_mutex_enter(db->mutex);
126836 sqlite3BtreeEnterAll(db);
126837 for(i=0; i<db->nDb; i++){
126838 Btree *pBt = db->aDb[i].pBt;
126839 if( pBt ){
@@ -125605,17 +126919,24 @@
126919 int nKey1, const void *pKey1,
126920 int nKey2, const void *pKey2
126921 ){
126922 int rc, n;
126923 n = nKey1<nKey2 ? nKey1 : nKey2;
126924 /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
126925 ** strings byte by byte using the memcmp() function from the standard C
126926 ** library. */
126927 rc = memcmp(pKey1, pKey2, n);
126928 if( rc==0 ){
126929 if( padFlag
126930 && allSpaces(((char*)pKey1)+n, nKey1-n)
126931 && allSpaces(((char*)pKey2)+n, nKey2-n)
126932 ){
126933 /* EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra
126934 ** spaces at the end of either string do not change the result. In other
126935 ** words, strings will compare equal to one another as long as they
126936 ** differ only in the number of spaces at the end.
126937 */
126938 }else{
126939 rc = nKey1 - nKey2;
126940 }
126941 }
126942 return rc;
@@ -125646,24 +126967,42 @@
126967
126968 /*
126969 ** Return the ROWID of the most recent insert
126970 */
126971 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
126972 #ifdef SQLITE_ENABLE_API_ARMOR
126973 if( !sqlite3SafetyCheckOk(db) ){
126974 (void)SQLITE_MISUSE_BKPT;
126975 return 0;
126976 }
126977 #endif
126978 return db->lastRowid;
126979 }
126980
126981 /*
126982 ** Return the number of changes in the most recent call to sqlite3_exec().
126983 */
126984 SQLITE_API int sqlite3_changes(sqlite3 *db){
126985 #ifdef SQLITE_ENABLE_API_ARMOR
126986 if( !sqlite3SafetyCheckOk(db) ){
126987 (void)SQLITE_MISUSE_BKPT;
126988 return 0;
126989 }
126990 #endif
126991 return db->nChange;
126992 }
126993
126994 /*
126995 ** Return the number of changes since the database handle was opened.
126996 */
126997 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
126998 #ifdef SQLITE_ENABLE_API_ARMOR
126999 if( !sqlite3SafetyCheckOk(db) ){
127000 (void)SQLITE_MISUSE_BKPT;
127001 return 0;
127002 }
127003 #endif
127004 return db->nTotalChange;
127005 }
127006
127007 /*
127008 ** Close all open savepoints. This function only manipulates fields of the
@@ -125839,10 +127178,20 @@
127178
127179 /* Close all database connections */
127180 for(j=0; j<db->nDb; j++){
127181 struct Db *pDb = &db->aDb[j];
127182 if( pDb->pBt ){
127183 if( pDb->pSchema ){
127184 /* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
127185 sqlite3BtreeEnter(pDb->pBt);
127186 for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
127187 Index *pIdx = sqliteHashData(i);
127188 sqlite3KeyInfoUnref(pIdx->pKeyInfo);
127189 pIdx->pKeyInfo = 0;
127190 }
127191 sqlite3BtreeLeave(pDb->pBt);
127192 }
127193 sqlite3BtreeClose(pDb->pBt);
127194 pDb->pBt = 0;
127195 if( j!=1 ){
127196 pDb->pSchema = 0;
127197 }
@@ -125925,17 +127274,19 @@
127274 sqlite3_free(db);
127275 }
127276
127277 /*
127278 ** Rollback all database files. If tripCode is not SQLITE_OK, then
127279 ** any write cursors are invalidated ("tripped" - as in "tripping a circuit
127280 ** breaker") and made to return tripCode if there are any further
127281 ** attempts to use that cursor. Read cursors remain open and valid
127282 ** but are "saved" in case the table pages are moved around.
127283 */
127284 SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
127285 int i;
127286 int inTrans = 0;
127287 int schemaChange;
127288 assert( sqlite3_mutex_held(db->mutex) );
127289 sqlite3BeginBenignMalloc();
127290
127291 /* Obtain all b-tree mutexes before making any calls to BtreeRollback().
127292 ** This is important in case the transaction being rolled back has
@@ -125942,18 +127293,19 @@
127293 ** modified the database schema. If the b-tree mutexes are not taken
127294 ** here, then another shared-cache connection might sneak in between
127295 ** the database rollback and schema reset, which can cause false
127296 ** corruption reports in some cases. */
127297 sqlite3BtreeEnterAll(db);
127298 schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
127299
127300 for(i=0; i<db->nDb; i++){
127301 Btree *p = db->aDb[i].pBt;
127302 if( p ){
127303 if( sqlite3BtreeIsInTrans(p) ){
127304 inTrans = 1;
127305 }
127306 sqlite3BtreeRollback(p, tripCode, !schemaChange);
127307 }
127308 }
127309 sqlite3VtabRollback(db);
127310 sqlite3EndBenignMalloc();
127311
@@ -126205,10 +127557,13 @@
127557 SQLITE_API int sqlite3_busy_handler(
127558 sqlite3 *db,
127559 int (*xBusy)(void*,int),
127560 void *pArg
127561 ){
127562 #ifdef SQLITE_ENABLE_API_ARMOR
127563 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE;
127564 #endif
127565 sqlite3_mutex_enter(db->mutex);
127566 db->busyHandler.xFunc = xBusy;
127567 db->busyHandler.pArg = pArg;
127568 db->busyHandler.nBusy = 0;
127569 db->busyTimeout = 0;
@@ -126226,10 +127581,16 @@
127581 sqlite3 *db,
127582 int nOps,
127583 int (*xProgress)(void*),
127584 void *pArg
127585 ){
127586 #ifdef SQLITE_ENABLE_API_ARMOR
127587 if( !sqlite3SafetyCheckOk(db) ){
127588 (void)SQLITE_MISUSE_BKPT;
127589 return;
127590 }
127591 #endif
127592 sqlite3_mutex_enter(db->mutex);
127593 if( nOps>0 ){
127594 db->xProgress = xProgress;
127595 db->nProgressOps = (unsigned)nOps;
127596 db->pProgressArg = pArg;
@@ -126246,10 +127607,13 @@
127607 /*
127608 ** This routine installs a default busy handler that waits for the
127609 ** specified number of milliseconds before returning 0.
127610 */
127611 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
127612 #ifdef SQLITE_ENABLE_API_ARMOR
127613 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
127614 #endif
127615 if( ms>0 ){
127616 sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
127617 db->busyTimeout = ms;
127618 }else{
127619 sqlite3_busy_handler(db, 0, 0);
@@ -126259,10 +127623,16 @@
127623
127624 /*
127625 ** Cause any pending operation to stop at its earliest opportunity.
127626 */
127627 SQLITE_API void sqlite3_interrupt(sqlite3 *db){
127628 #ifdef SQLITE_ENABLE_API_ARMOR
127629 if( !sqlite3SafetyCheckOk(db) ){
127630 (void)SQLITE_MISUSE_BKPT;
127631 return;
127632 }
127633 #endif
127634 db->u1.isInterrupted = 1;
127635 }
127636
127637
127638 /*
@@ -126396,10 +127766,16 @@
127766 void (*xFinal)(sqlite3_context*),
127767 void (*xDestroy)(void *)
127768 ){
127769 int rc = SQLITE_ERROR;
127770 FuncDestructor *pArg = 0;
127771
127772 #ifdef SQLITE_ENABLE_API_ARMOR
127773 if( !sqlite3SafetyCheckOk(db) ){
127774 return SQLITE_MISUSE_BKPT;
127775 }
127776 #endif
127777 sqlite3_mutex_enter(db->mutex);
127778 if( xDestroy ){
127779 pArg = (FuncDestructor *)sqlite3DbMallocZero(db, sizeof(FuncDestructor));
127780 if( !pArg ){
127781 xDestroy(p);
@@ -126432,10 +127808,14 @@
127808 void (*xStep)(sqlite3_context*,int,sqlite3_value**),
127809 void (*xFinal)(sqlite3_context*)
127810 ){
127811 int rc;
127812 char *zFunc8;
127813
127814 #ifdef SQLITE_ENABLE_API_ARMOR
127815 if( !sqlite3SafetyCheckOk(db) || zFunctionName==0 ) return SQLITE_MISUSE_BKPT;
127816 #endif
127817 sqlite3_mutex_enter(db->mutex);
127818 assert( !db->mallocFailed );
127819 zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
127820 rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal,0);
127821 sqlite3DbFree(db, zFunc8);
@@ -126463,10 +127843,16 @@
127843 const char *zName,
127844 int nArg
127845 ){
127846 int nName = sqlite3Strlen30(zName);
127847 int rc = SQLITE_OK;
127848
127849 #ifdef SQLITE_ENABLE_API_ARMOR
127850 if( !sqlite3SafetyCheckOk(db) || zName==0 || nArg<-2 ){
127851 return SQLITE_MISUSE_BKPT;
127852 }
127853 #endif
127854 sqlite3_mutex_enter(db->mutex);
127855 if( sqlite3FindFunction(db, zName, nName, nArg, SQLITE_UTF8, 0)==0 ){
127856 rc = sqlite3CreateFunc(db, zName, nArg, SQLITE_UTF8,
127857 0, sqlite3InvalidFunction, 0, 0, 0);
127858 }
@@ -126484,10 +127870,17 @@
127870 ** trace is a pointer to a function that is invoked at the start of each
127871 ** SQL statement.
127872 */
127873 SQLITE_API void *sqlite3_trace(sqlite3 *db, void (*xTrace)(void*,const char*), void *pArg){
127874 void *pOld;
127875
127876 #ifdef SQLITE_ENABLE_API_ARMOR
127877 if( !sqlite3SafetyCheckOk(db) ){
127878 (void)SQLITE_MISUSE_BKPT;
127879 return 0;
127880 }
127881 #endif
127882 sqlite3_mutex_enter(db->mutex);
127883 pOld = db->pTraceArg;
127884 db->xTrace = xTrace;
127885 db->pTraceArg = pArg;
127886 sqlite3_mutex_leave(db->mutex);
@@ -126505,10 +127898,17 @@
127898 sqlite3 *db,
127899 void (*xProfile)(void*,const char*,sqlite_uint64),
127900 void *pArg
127901 ){
127902 void *pOld;
127903
127904 #ifdef SQLITE_ENABLE_API_ARMOR
127905 if( !sqlite3SafetyCheckOk(db) ){
127906 (void)SQLITE_MISUSE_BKPT;
127907 return 0;
127908 }
127909 #endif
127910 sqlite3_mutex_enter(db->mutex);
127911 pOld = db->pProfileArg;
127912 db->xProfile = xProfile;
127913 db->pProfileArg = pArg;
127914 sqlite3_mutex_leave(db->mutex);
@@ -126525,10 +127925,17 @@
127925 sqlite3 *db, /* Attach the hook to this database */
127926 int (*xCallback)(void*), /* Function to invoke on each commit */
127927 void *pArg /* Argument to the function */
127928 ){
127929 void *pOld;
127930
127931 #ifdef SQLITE_ENABLE_API_ARMOR
127932 if( !sqlite3SafetyCheckOk(db) ){
127933 (void)SQLITE_MISUSE_BKPT;
127934 return 0;
127935 }
127936 #endif
127937 sqlite3_mutex_enter(db->mutex);
127938 pOld = db->pCommitArg;
127939 db->xCommitCallback = xCallback;
127940 db->pCommitArg = pArg;
127941 sqlite3_mutex_leave(db->mutex);
@@ -126543,10 +127950,17 @@
127950 sqlite3 *db, /* Attach the hook to this database */
127951 void (*xCallback)(void*,int,char const *,char const *,sqlite_int64),
127952 void *pArg /* Argument to the function */
127953 ){
127954 void *pRet;
127955
127956 #ifdef SQLITE_ENABLE_API_ARMOR
127957 if( !sqlite3SafetyCheckOk(db) ){
127958 (void)SQLITE_MISUSE_BKPT;
127959 return 0;
127960 }
127961 #endif
127962 sqlite3_mutex_enter(db->mutex);
127963 pRet = db->pUpdateArg;
127964 db->xUpdateCallback = xCallback;
127965 db->pUpdateArg = pArg;
127966 sqlite3_mutex_leave(db->mutex);
@@ -126561,10 +127975,17 @@
127975 sqlite3 *db, /* Attach the hook to this database */
127976 void (*xCallback)(void*), /* Callback function */
127977 void *pArg /* Argument to the function */
127978 ){
127979 void *pRet;
127980
127981 #ifdef SQLITE_ENABLE_API_ARMOR
127982 if( !sqlite3SafetyCheckOk(db) ){
127983 (void)SQLITE_MISUSE_BKPT;
127984 return 0;
127985 }
127986 #endif
127987 sqlite3_mutex_enter(db->mutex);
127988 pRet = db->pRollbackArg;
127989 db->xRollbackCallback = xCallback;
127990 db->pRollbackArg = pArg;
127991 sqlite3_mutex_leave(db->mutex);
@@ -126607,10 +128028,13 @@
128028 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int nFrame){
128029 #ifdef SQLITE_OMIT_WAL
128030 UNUSED_PARAMETER(db);
128031 UNUSED_PARAMETER(nFrame);
128032 #else
128033 #ifdef SQLITE_ENABLE_API_ARMOR
128034 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128035 #endif
128036 if( nFrame>0 ){
128037 sqlite3_wal_hook(db, sqlite3WalDefaultHook, SQLITE_INT_TO_PTR(nFrame));
128038 }else{
128039 sqlite3_wal_hook(db, 0, 0);
128040 }
@@ -126627,10 +128051,16 @@
128051 int(*xCallback)(void *, sqlite3*, const char*, int),
128052 void *pArg /* First argument passed to xCallback() */
128053 ){
128054 #ifndef SQLITE_OMIT_WAL
128055 void *pRet;
128056 #ifdef SQLITE_ENABLE_API_ARMOR
128057 if( !sqlite3SafetyCheckOk(db) ){
128058 (void)SQLITE_MISUSE_BKPT;
128059 return 0;
128060 }
128061 #endif
128062 sqlite3_mutex_enter(db->mutex);
128063 pRet = db->pWalArg;
128064 db->xWalCallback = xCallback;
128065 db->pWalArg = pArg;
128066 sqlite3_mutex_leave(db->mutex);
@@ -126653,19 +128083,26 @@
128083 #ifdef SQLITE_OMIT_WAL
128084 return SQLITE_OK;
128085 #else
128086 int rc; /* Return code */
128087 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
128088
128089 #ifdef SQLITE_ENABLE_API_ARMOR
128090 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
128091 #endif
128092
128093 /* Initialize the output variables to -1 in case an error occurs. */
128094 if( pnLog ) *pnLog = -1;
128095 if( pnCkpt ) *pnCkpt = -1;
128096
128097 assert( SQLITE_CHECKPOINT_PASSIVE==0 );
128098 assert( SQLITE_CHECKPOINT_FULL==1 );
128099 assert( SQLITE_CHECKPOINT_RESTART==2 );
128100 assert( SQLITE_CHECKPOINT_TRUNCATE==3 );
128101 if( eMode<SQLITE_CHECKPOINT_PASSIVE || eMode>SQLITE_CHECKPOINT_TRUNCATE ){
128102 /* EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint
128103 ** mode: */
128104 return SQLITE_MISUSE;
128105 }
128106
128107 sqlite3_mutex_enter(db->mutex);
128108 if( zDb && zDb[0] ){
@@ -126689,11 +128126,13 @@
128126 ** Checkpoint database zDb. If zDb is NULL, or if the buffer zDb points
128127 ** to contains a zero-length string, all attached databases are
128128 ** checkpointed.
128129 */
128130 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb){
128131 /* EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is equivalent to
128132 ** sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). */
128133 return sqlite3_wal_checkpoint_v2(db,zDb,SQLITE_CHECKPOINT_PASSIVE,0,0);
128134 }
128135
128136 #ifndef SQLITE_OMIT_WAL
128137 /*
128138 ** Run a checkpoint on database iDb. This is a no-op if database iDb is
@@ -127050,10 +128489,16 @@
128489 ** from forming.
128490 */
128491 SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
128492 int oldLimit;
128493
128494 #ifdef SQLITE_ENABLE_API_ARMOR
128495 if( !sqlite3SafetyCheckOk(db) ){
128496 (void)SQLITE_MISUSE_BKPT;
128497 return -1;
128498 }
128499 #endif
128500
128501 /* EVIDENCE-OF: R-30189-54097 For each limit category SQLITE_LIMIT_NAME
128502 ** there is a hard upper bound set at compile-time by a C preprocessor
128503 ** macro called SQLITE_MAX_NAME. (The "_LIMIT_" in the name is changed to
128504 ** "_MAX_".)
@@ -127126,11 +128571,12 @@
128571 char c;
128572 int nUri = sqlite3Strlen30(zUri);
128573
128574 assert( *pzErrMsg==0 );
128575
128576 if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
128577 || sqlite3GlobalConfig.bOpenUri) /* IMP: R-51689-46548 */
128578 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
128579 ){
128580 char *zOpt;
128581 int eState; /* Parser state when parsing URI */
128582 int iIn; /* Input character index */
@@ -127335,10 +128781,13 @@
128781 int rc; /* Return code */
128782 int isThreadsafe; /* True for threadsafe connections */
128783 char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */
128784 char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */
128785
128786 #ifdef SQLITE_ENABLE_API_ARMOR
128787 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
128788 #endif
128789 *ppDb = 0;
128790 #ifndef SQLITE_OMIT_AUTOINIT
128791 rc = sqlite3_initialize();
128792 if( rc ) return rc;
128793 #endif
@@ -127440,33 +128889,40 @@
128889 | SQLITE_RecTriggers
128890 #endif
128891 #if defined(SQLITE_DEFAULT_FOREIGN_KEYS) && SQLITE_DEFAULT_FOREIGN_KEYS
128892 | SQLITE_ForeignKeys
128893 #endif
128894 #if defined(SQLITE_REVERSE_UNORDERED_SELECTS)
128895 | SQLITE_ReverseOrder
128896 #endif
128897 ;
128898 sqlite3HashInit(&db->aCollSeq);
128899 #ifndef SQLITE_OMIT_VIRTUALTABLE
128900 sqlite3HashInit(&db->aModule);
128901 #endif
128902
128903 /* Add the default collation sequence BINARY. BINARY works for both UTF-8
128904 ** and UTF-16, so add a version for each to avoid any unnecessary
128905 ** conversions. The only error that can occur here is a malloc() failure.
128906 **
128907 ** EVIDENCE-OF: R-52786-44878 SQLite defines three built-in collating
128908 ** functions:
128909 */
128910 createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
128911 createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
128912 createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
128913 createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
128914 createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
128915 if( db->mallocFailed ){
128916 goto opendb_out;
128917 }
128918 /* EVIDENCE-OF: R-08308-17224 The default collating function for all
128919 ** strings is BINARY.
128920 */
128921 db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
128922 assert( db->pDfltColl!=0 );
128923
 
 
 
128924 /* Parse the filename/URI argument. */
128925 db->openFlags = flags;
128926 rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
128927 if( rc!=SQLITE_OK ){
128928 if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
@@ -127483,11 +128939,13 @@
128939 rc = SQLITE_NOMEM;
128940 }
128941 sqlite3Error(db, rc);
128942 goto opendb_out;
128943 }
128944 sqlite3BtreeEnter(db->aDb[0].pBt);
128945 db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
128946 sqlite3BtreeLeave(db->aDb[0].pBt);
128947 db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
128948
128949 /* The default safety_level for the main database is 'full'; for the temp
128950 ** database it is 'NONE'. This matches the pager layer defaults.
128951 */
@@ -127624,17 +129082,19 @@
129082 ){
129083 char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */
129084 sqlite3_value *pVal;
129085 int rc;
129086
129087 #ifdef SQLITE_ENABLE_API_ARMOR
129088 if( ppDb==0 ) return SQLITE_MISUSE_BKPT;
129089 #endif
129090 *ppDb = 0;
129091 #ifndef SQLITE_OMIT_AUTOINIT
129092 rc = sqlite3_initialize();
129093 if( rc ) return rc;
129094 #endif
129095 if( zFilename==0 ) zFilename = "\000\000";
129096 pVal = sqlite3ValueNew(0);
129097 sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC);
129098 zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8);
129099 if( zFilename8 ){
129100 rc = openDatabase(zFilename8, ppDb,
@@ -127660,17 +129120,11 @@
129120 const char *zName,
129121 int enc,
129122 void* pCtx,
129123 int(*xCompare)(void*,int,const void*,int,const void*)
129124 ){
129125 return sqlite3_create_collation_v2(db, zName, enc, pCtx, xCompare, 0);
 
 
 
 
 
 
129126 }
129127
129128 /*
129129 ** Register a new collation sequence with the database handle db.
129130 */
@@ -127681,10 +129135,14 @@
129135 void* pCtx,
129136 int(*xCompare)(void*,int,const void*,int,const void*),
129137 void(*xDel)(void*)
129138 ){
129139 int rc;
129140
129141 #ifdef SQLITE_ENABLE_API_ARMOR
129142 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
129143 #endif
129144 sqlite3_mutex_enter(db->mutex);
129145 assert( !db->mallocFailed );
129146 rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
129147 rc = sqlite3ApiExit(db, rc);
129148 sqlite3_mutex_leave(db->mutex);
@@ -127702,10 +129160,14 @@
129160 void* pCtx,
129161 int(*xCompare)(void*,int,const void*,int,const void*)
129162 ){
129163 int rc = SQLITE_OK;
129164 char *zName8;
129165
129166 #ifdef SQLITE_ENABLE_API_ARMOR
129167 if( !sqlite3SafetyCheckOk(db) || zName==0 ) return SQLITE_MISUSE_BKPT;
129168 #endif
129169 sqlite3_mutex_enter(db->mutex);
129170 assert( !db->mallocFailed );
129171 zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
129172 if( zName8 ){
129173 rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
@@ -127724,10 +129186,13 @@
129186 SQLITE_API int sqlite3_collation_needed(
129187 sqlite3 *db,
129188 void *pCollNeededArg,
129189 void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*)
129190 ){
129191 #ifdef SQLITE_ENABLE_API_ARMOR
129192 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129193 #endif
129194 sqlite3_mutex_enter(db->mutex);
129195 db->xCollNeeded = xCollNeeded;
129196 db->xCollNeeded16 = 0;
129197 db->pCollNeededArg = pCollNeededArg;
129198 sqlite3_mutex_leave(db->mutex);
@@ -127742,10 +129207,13 @@
129207 SQLITE_API int sqlite3_collation_needed16(
129208 sqlite3 *db,
129209 void *pCollNeededArg,
129210 void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*)
129211 ){
129212 #ifdef SQLITE_ENABLE_API_ARMOR
129213 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129214 #endif
129215 sqlite3_mutex_enter(db->mutex);
129216 db->xCollNeeded = 0;
129217 db->xCollNeeded16 = xCollNeeded16;
129218 db->pCollNeededArg = pCollNeededArg;
129219 sqlite3_mutex_leave(db->mutex);
@@ -127768,10 +129236,16 @@
129236 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
129237 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
129238 ** by the next COMMIT or ROLLBACK.
129239 */
129240 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
129241 #ifdef SQLITE_ENABLE_API_ARMOR
129242 if( !sqlite3SafetyCheckOk(db) ){
129243 (void)SQLITE_MISUSE_BKPT;
129244 return 0;
129245 }
129246 #endif
129247 return db->autoCommit;
129248 }
129249
129250 /*
129251 ** The following routines are substitutes for constants SQLITE_CORRUPT,
@@ -127821,11 +129295,10 @@
129295
129296 /*
129297 ** Return meta information about a specific column of a database table.
129298 ** See comment in sqlite3.h (sqlite.h.in) for details.
129299 */
 
129300 SQLITE_API int sqlite3_table_column_metadata(
129301 sqlite3 *db, /* Connection handle */
129302 const char *zDbName, /* Database name or NULL */
129303 const char *zTableName, /* Table name */
129304 const char *zColumnName, /* Column name */
@@ -127861,25 +129334,27 @@
129334 pTab = 0;
129335 goto error_out;
129336 }
129337
129338 /* Find the column for which info is requested */
129339 if( zColumnName==0 ){
129340 /* Query for existance of table only */
 
 
 
129341 }else{
129342 for(iCol=0; iCol<pTab->nCol; iCol++){
129343 pCol = &pTab->aCol[iCol];
129344 if( 0==sqlite3StrICmp(pCol->zName, zColumnName) ){
129345 break;
129346 }
129347 }
129348 if( iCol==pTab->nCol ){
129349 if( HasRowid(pTab) && sqlite3IsRowid(zColumnName) ){
129350 iCol = pTab->iPKey;
129351 pCol = iCol>=0 ? &pTab->aCol[iCol] : 0;
129352 }else{
129353 pTab = 0;
129354 goto error_out;
129355 }
129356 }
129357 }
129358
129359 /* The following block stores the meta information that will be returned
129360 ** to the caller in local variables zDataType, zCollSeq, notnull, primarykey
@@ -127928,11 +129403,10 @@
129403 sqlite3DbFree(db, zErrMsg);
129404 rc = sqlite3ApiExit(db, rc);
129405 sqlite3_mutex_leave(db->mutex);
129406 return rc;
129407 }
 
129408
129409 /*
129410 ** Sleep for a little while. Return the amount of time slept.
129411 */
129412 SQLITE_API int sqlite3_sleep(int ms){
@@ -127950,10 +129424,13 @@
129424
129425 /*
129426 ** Enable or disable the extended result codes.
129427 */
129428 SQLITE_API int sqlite3_extended_result_codes(sqlite3 *db, int onoff){
129429 #ifdef SQLITE_ENABLE_API_ARMOR
129430 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129431 #endif
129432 sqlite3_mutex_enter(db->mutex);
129433 db->errMask = onoff ? 0xffffffff : 0xff;
129434 sqlite3_mutex_leave(db->mutex);
129435 return SQLITE_OK;
129436 }
@@ -127963,10 +129440,13 @@
129440 */
129441 SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
129442 int rc = SQLITE_ERROR;
129443 Btree *pBtree;
129444
129445 #ifdef SQLITE_ENABLE_API_ARMOR
129446 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
129447 #endif
129448 sqlite3_mutex_enter(db->mutex);
129449 pBtree = sqlite3DbNameToBtree(db, zDbName);
129450 if( pBtree ){
129451 Pager *pPager;
129452 sqlite3_file *fd;
@@ -128305,11 +129785,11 @@
129785 ** query parameter we seek. This routine returns the value of the zParam
129786 ** parameter if it exists. If the parameter does not exist, this routine
129787 ** returns a NULL pointer.
129788 */
129789 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
129790 if( zFilename==0 || zParam==0 ) return 0;
129791 zFilename += sqlite3Strlen30(zFilename) + 1;
129792 while( zFilename[0] ){
129793 int x = strcmp(zFilename, zParam);
129794 zFilename += sqlite3Strlen30(zFilename) + 1;
129795 if( x==0 ) return zFilename;
@@ -128361,19 +129841,31 @@
129841 /*
129842 ** Return the filename of the database associated with a database
129843 ** connection.
129844 */
129845 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
129846 #ifdef SQLITE_ENABLE_API_ARMOR
129847 if( !sqlite3SafetyCheckOk(db) ){
129848 (void)SQLITE_MISUSE_BKPT;
129849 return 0;
129850 }
129851 #endif
129852 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129853 return pBt ? sqlite3BtreeGetFilename(pBt) : 0;
129854 }
129855
129856 /*
129857 ** Return 1 if database is read-only or 0 if read/write. Return -1 if
129858 ** no such database exists.
129859 */
129860 SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName){
129861 #ifdef SQLITE_ENABLE_API_ARMOR
129862 if( !sqlite3SafetyCheckOk(db) ){
129863 (void)SQLITE_MISUSE_BKPT;
129864 return -1;
129865 }
129866 #endif
129867 Btree *pBt = sqlite3DbNameToBtree(db, zDbName);
129868 return pBt ? sqlite3BtreeIsReadonly(pBt) : -1;
129869 }
129870
129871 /************** End of main.c ************************************************/
@@ -137791,11 +139283,11 @@
139283 ** Return true if the m-value for z is 1 or more. In other words,
139284 ** return true if z contains at least one vowel that is followed
139285 ** by a consonant.
139286 **
139287 ** In this routine z[] is in reverse order. So we are really looking
139288 ** for an instance of a consonant followed by a vowel.
139289 */
139290 static int m_gt_0(const char *z){
139291 while( isVowel(z) ){ z++; }
139292 if( *z==0 ) return 0;
139293 while( isConsonant(z) ){ z++; }
139294
+472 -318
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
5555
5656
5757
/*
5858
** These no-op macros are used in front of interfaces to mark those
5959
** interfaces as either deprecated or experimental. New applications
60
-** should not use deprecated interfaces - they are support for backwards
60
+** should not use deprecated interfaces - they are supported for backwards
6161
** compatibility only. Application writers should be aware that
6262
** experimental interfaces are subject to change in point releases.
6363
**
6464
** These macros used to resolve to various kinds of compiler magic that
6565
** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.7.1"
111
-#define SQLITE_VERSION_NUMBER 3008007
112
-#define SQLITE_SOURCE_ID "2014-10-29 01:27:43 83afe23e553e802c0947c80d0ffdd120423e7c52"
110
+#define SQLITE_VERSION "3.8.8"
111
+#define SQLITE_VERSION_NUMBER 3008008
112
+#define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -1219,11 +1219,11 @@
12191219
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
12201220
** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
12211221
** </ul>
12221222
**
12231223
** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1224
-** was given no the corresponding lock.
1224
+** was given on the corresponding lock.
12251225
**
12261226
** The xShmLock method can transition between unlocked and SHARED or
12271227
** between unlocked and EXCLUSIVE. It cannot transition between SHARED
12281228
** and EXCLUSIVE.
12291229
*/
@@ -1502,30 +1502,32 @@
15021502
** it is not possible to set the Serialized [threading mode] and
15031503
** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
15041504
** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
15051505
**
15061506
** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507
-** <dd> ^(This option takes a single argument which is a pointer to an
1508
-** instance of the [sqlite3_mem_methods] structure. The argument specifies
1507
+** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1508
+** a pointer to an instance of the [sqlite3_mem_methods] structure.
1509
+** The argument specifies
15091510
** alternative low-level memory allocation routines to be used in place of
15101511
** the memory allocation routines built into SQLite.)^ ^SQLite makes
15111512
** its own private copy of the content of the [sqlite3_mem_methods] structure
15121513
** before the [sqlite3_config()] call returns.</dd>
15131514
**
15141515
** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1515
-** <dd> ^(This option takes a single argument which is a pointer to an
1516
-** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
1516
+** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1517
+** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1518
+** The [sqlite3_mem_methods]
15171519
** structure is filled with the currently defined memory allocation routines.)^
15181520
** This option can be used to overload the default memory allocation
15191521
** routines with a wrapper that simulations memory allocation failure or
15201522
** tracks memory usage, for example. </dd>
15211523
**
15221524
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1523
-** <dd> ^This option takes single argument of type int, interpreted as a
1524
-** boolean, which enables or disables the collection of memory allocation
1525
-** statistics. ^(When memory allocation statistics are disabled, the
1526
-** following SQLite interfaces become non-operational:
1525
+** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1526
+** interpreted as a boolean, which enables or disables the collection of
1527
+** memory allocation statistics. ^(When memory allocation statistics are
1528
+** disabled, the following SQLite interfaces become non-operational:
15271529
** <ul>
15281530
** <li> [sqlite3_memory_used()]
15291531
** <li> [sqlite3_memory_highwater()]
15301532
** <li> [sqlite3_soft_heap_limit64()]
15311533
** <li> [sqlite3_status()]
@@ -1534,78 +1536,92 @@
15341536
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
15351537
** allocation statistics are disabled by default.
15361538
** </dd>
15371539
**
15381540
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1539
-** <dd> ^This option specifies a static memory buffer that SQLite can use for
1540
-** scratch memory. There are three arguments: A pointer an 8-byte
1541
+** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1542
+** that SQLite can use for scratch memory. ^(There are three arguments
1543
+** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
15411544
** aligned memory buffer from which the scratch allocations will be
15421545
** drawn, the size of each scratch allocation (sz),
1543
-** and the maximum number of scratch allocations (N). The sz
1544
-** argument must be a multiple of 16.
1546
+** and the maximum number of scratch allocations (N).)^
15451547
** The first argument must be a pointer to an 8-byte aligned buffer
15461548
** of at least sz*N bytes of memory.
1547
-** ^SQLite will use no more than two scratch buffers per thread. So
1548
-** N should be set to twice the expected maximum number of threads.
1549
-** ^SQLite will never require a scratch buffer that is more than 6
1550
-** times the database page size. ^If SQLite needs needs additional
1549
+** ^SQLite will not use more than one scratch buffers per thread.
1550
+** ^SQLite will never request a scratch buffer that is more than 6
1551
+** times the database page size.
1552
+** ^If SQLite needs needs additional
15511553
** scratch memory beyond what is provided by this configuration option, then
1552
-** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
1554
+** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1555
+** ^When the application provides any amount of scratch memory using
1556
+** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1557
+** [sqlite3_malloc|heap allocations].
1558
+** This can help [Robson proof|prevent memory allocation failures] due to heap
1559
+** fragmentation in low-memory embedded systems.
1560
+** </dd>
15531561
**
15541562
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1555
-** <dd> ^This option specifies a static memory buffer that SQLite can use for
1556
-** the database page cache with the default page cache implementation.
1563
+** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1564
+** that SQLite can use for the database page cache with the default page
1565
+** cache implementation.
15571566
** This configuration should not be used if an application-define page
1558
-** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1559
-** There are three arguments to this option: A pointer to 8-byte aligned
1567
+** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1568
+** configuration option.
1569
+** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570
+** 8-byte aligned
15601571
** memory, the size of each page buffer (sz), and the number of pages (N).
15611572
** The sz argument should be the size of the largest database page
1562
-** (a power of two between 512 and 32768) plus a little extra for each
1563
-** page header. ^The page header size is 20 to 40 bytes depending on
1564
-** the host architecture. ^It is harmless, apart from the wasted memory,
1565
-** to make sz a little too large. The first
1566
-** argument should point to an allocation of at least sz*N bytes of memory.
1573
+** (a power of two between 512 and 32768) plus some extra bytes for each
1574
+** page header. ^The number of extra bytes needed by the page header
1575
+** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576
+** to [sqlite3_config()].
1577
+** ^It is harmless, apart from the wasted memory,
1578
+** for the sz parameter to be larger than necessary. The first
1579
+** argument should pointer to an 8-byte aligned block of memory that
1580
+** is at least sz*N bytes of memory, otherwise subsequent behavior is
1581
+** undefined.
15671582
** ^SQLite will use the memory provided by the first argument to satisfy its
15681583
** memory needs for the first N pages that it adds to cache. ^If additional
15691584
** page cache memory is needed beyond what is provided by this option, then
1570
-** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1571
-** The pointer in the first argument must
1572
-** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1573
-** will be undefined.</dd>
1585
+** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
15741586
**
15751587
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1576
-** <dd> ^This option specifies a static memory buffer that SQLite will use
1577
-** for all of its dynamic memory allocation needs beyond those provided
1578
-** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1579
-** There are three arguments: An 8-byte aligned pointer to the memory,
1588
+** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1589
+** that SQLite will use for all of its dynamic memory allocation needs
1590
+** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1591
+** [SQLITE_CONFIG_PAGECACHE].
1592
+** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1593
+** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1594
+** [SQLITE_ERROR] if invoked otherwise.
1595
+** ^There are three arguments to SQLITE_CONFIG_HEAP:
1596
+** An 8-byte aligned pointer to the memory,
15801597
** the number of bytes in the memory buffer, and the minimum allocation size.
15811598
** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
15821599
** to using its default memory allocator (the system malloc() implementation),
15831600
** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1584
-** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1585
-** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1601
+** memory pointer is not NULL then the alternative memory
15861602
** allocator is engaged to handle all of SQLites memory allocation needs.
15871603
** The first pointer (the memory pointer) must be aligned to an 8-byte
15881604
** boundary or subsequent behavior of SQLite will be undefined.
15891605
** The minimum allocation size is capped at 2**12. Reasonable values
15901606
** for the minimum allocation size are 2**5 through 2**8.</dd>
15911607
**
15921608
** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1593
-** <dd> ^(This option takes a single argument which is a pointer to an
1594
-** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1595
-** alternative low-level mutex routines to be used in place
1596
-** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1597
-** content of the [sqlite3_mutex_methods] structure before the call to
1609
+** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1610
+** pointer to an instance of the [sqlite3_mutex_methods] structure.
1611
+** The argument specifies alternative low-level mutex routines to be used
1612
+** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1613
+** the content of the [sqlite3_mutex_methods] structure before the call to
15981614
** [sqlite3_config()] returns. ^If SQLite is compiled with
15991615
** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
16001616
** the entire mutexing subsystem is omitted from the build and hence calls to
16011617
** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
16021618
** return [SQLITE_ERROR].</dd>
16031619
**
16041620
** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1605
-** <dd> ^(This option takes a single argument which is a pointer to an
1606
-** instance of the [sqlite3_mutex_methods] structure. The
1621
+** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1622
+** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
16071623
** [sqlite3_mutex_methods]
16081624
** structure is filled with the currently defined mutex routines.)^
16091625
** This option can be used to overload the default mutex allocation
16101626
** routines with a wrapper used to track mutex usage for performance
16111627
** profiling or testing, for example. ^If SQLite is compiled with
@@ -1613,29 +1629,29 @@
16131629
** the entire mutexing subsystem is omitted from the build and hence calls to
16141630
** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
16151631
** return [SQLITE_ERROR].</dd>
16161632
**
16171633
** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1618
-** <dd> ^(This option takes two arguments that determine the default
1619
-** memory allocation for the lookaside memory allocator on each
1620
-** [database connection]. The first argument is the
1634
+** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1635
+** the default size of lookaside memory on each [database connection].
1636
+** The first argument is the
16211637
** size of each lookaside buffer slot and the second is the number of
1622
-** slots allocated to each database connection.)^ ^(This option sets the
1623
-** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1624
-** verb to [sqlite3_db_config()] can be used to change the lookaside
1638
+** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1639
+** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1640
+** option to [sqlite3_db_config()] can be used to change the lookaside
16251641
** configuration on individual connections.)^ </dd>
16261642
**
16271643
** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1628
-** <dd> ^(This option takes a single argument which is a pointer to
1629
-** an [sqlite3_pcache_methods2] object. This object specifies the interface
1630
-** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1631
-** object and uses it for page cache memory allocations.</dd>
1644
+** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1645
+** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1646
+** the interface to a custom page cache implementation.)^
1647
+** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
16321648
**
16331649
** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1634
-** <dd> ^(This option takes a single argument which is a pointer to an
1635
-** [sqlite3_pcache_methods2] object. SQLite copies of the current
1636
-** page cache implementation into that object.)^ </dd>
1650
+** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1651
+** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
1652
+** the current page cache implementation into that object.)^ </dd>
16371653
**
16381654
** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
16391655
** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
16401656
** global [error log].
16411657
** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1654,26 +1670,28 @@
16541670
** supplied by the application must not invoke any SQLite interface.
16551671
** In a multi-threaded application, the application-defined logger
16561672
** function must be threadsafe. </dd>
16571673
**
16581674
** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1659
-** <dd>^(This option takes a single argument of type int. If non-zero, then
1660
-** URI handling is globally enabled. If the parameter is zero, then URI handling
1661
-** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1662
-** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
1675
+** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1676
+** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1677
+** then URI handling is globally disabled.)^ ^If URI handling is globally
1678
+** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1679
+** [sqlite3_open16()] or
16631680
** specified as part of [ATTACH] commands are interpreted as URIs, regardless
16641681
** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
16651682
** connection is opened. ^If it is globally disabled, filenames are
16661683
** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
16671684
** database connection is opened. ^(By default, URI handling is globally
16681685
** disabled. The default value may be changed by compiling with the
16691686
** [SQLITE_USE_URI] symbol defined.)^
16701687
**
16711688
** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1672
-** <dd>^This option takes a single integer argument which is interpreted as
1673
-** a boolean in order to enable or disable the use of covering indices for
1674
-** full table scans in the query optimizer. ^The default setting is determined
1689
+** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1690
+** argument which is interpreted as a boolean in order to enable or disable
1691
+** the use of covering indices for full table scans in the query optimizer.
1692
+** ^The default setting is determined
16751693
** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
16761694
** if that compile-time option is omitted.
16771695
** The ability to disable the use of covering indices for full table scans
16781696
** is because some incorrectly coded legacy applications might malfunction
16791697
** when the optimization is enabled. Providing the ability to
@@ -1709,23 +1727,32 @@
17091727
** that are the default mmap size limit (the default setting for
17101728
** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
17111729
** ^The default setting can be overridden by each database connection using
17121730
** either the [PRAGMA mmap_size] command, or by using the
17131731
** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1714
-** cannot be changed at run-time. Nor may the maximum allowed mmap size
1715
-** exceed the compile-time maximum mmap size set by the
1732
+** will be silently truncated if necessary so that it does not exceed the
1733
+** compile-time maximum mmap size set by the
17161734
** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
17171735
** ^If either argument to this option is negative, then that argument is
17181736
** changed to its compile-time default.
17191737
**
17201738
** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
17211739
** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1722
-** <dd>^This option is only available if SQLite is compiled for Windows
1723
-** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1724
-** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1740
+** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1741
+** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1742
+** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
17251743
** that specifies the maximum size of the created heap.
17261744
** </dl>
1745
+**
1746
+** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1747
+** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1748
+** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749
+** is a pointer to an integer and writes into that integer the number of extra
1750
+** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751
+** The amount of extra space required can change depending on the compiler,
1752
+** target platform, and SQLite version.
1753
+** </dl>
17271754
*/
17281755
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
17291756
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
17301757
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
17311758
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1746,10 +1773,11 @@
17461773
#define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
17471774
#define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
17481775
#define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
17491776
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
17501777
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1778
+#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
17511779
17521780
/*
17531781
** CAPI3REF: Database Connection Configuration Options
17541782
**
17551783
** These constants are the available integer configuration options that
@@ -1873,51 +1901,49 @@
18731901
SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
18741902
18751903
/*
18761904
** CAPI3REF: Count The Number Of Rows Modified
18771905
**
1878
-** ^This function returns the number of database rows that were changed
1879
-** or inserted or deleted by the most recently completed SQL statement
1880
-** on the [database connection] specified by the first parameter.
1881
-** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
1882
-** or [DELETE] statement are counted. Auxiliary changes caused by
1883
-** triggers or [foreign key actions] are not counted.)^ Use the
1884
-** [sqlite3_total_changes()] function to find the total number of changes
1885
-** including changes caused by triggers and foreign key actions.
1886
-**
1887
-** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1888
-** are not counted. Only real table changes are counted.
1889
-**
1890
-** ^(A "row change" is a change to a single row of a single table
1891
-** caused by an INSERT, DELETE, or UPDATE statement. Rows that
1892
-** are changed as side effects of [REPLACE] constraint resolution,
1893
-** rollback, ABORT processing, [DROP TABLE], or by any other
1894
-** mechanisms do not count as direct row changes.)^
1895
-**
1896
-** A "trigger context" is a scope of execution that begins and
1897
-** ends with the script of a [CREATE TRIGGER | trigger].
1898
-** Most SQL statements are
1899
-** evaluated outside of any trigger. This is the "top level"
1900
-** trigger context. If a trigger fires from the top level, a
1901
-** new trigger context is entered for the duration of that one
1902
-** trigger. Subtriggers create subcontexts for their duration.
1903
-**
1904
-** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1905
-** not create a new trigger context.
1906
-**
1907
-** ^This function returns the number of direct row changes in the
1908
-** most recent INSERT, UPDATE, or DELETE statement within the same
1909
-** trigger context.
1910
-**
1911
-** ^Thus, when called from the top level, this function returns the
1912
-** number of changes in the most recent INSERT, UPDATE, or DELETE
1913
-** that also occurred at the top level. ^(Within the body of a trigger,
1914
-** the sqlite3_changes() interface can be called to find the number of
1915
-** changes in the most recently completed INSERT, UPDATE, or DELETE
1916
-** statement within the body of the same trigger.
1917
-** However, the number returned does not include changes
1918
-** caused by subtriggers since those have their own context.)^
1906
+** ^This function returns the number of rows modified, inserted or
1907
+** deleted by the most recently completed INSERT, UPDATE or DELETE
1908
+** statement on the database connection specified by the only parameter.
1909
+** ^Executing any other type of SQL statement does not modify the value
1910
+** returned by this function.
1911
+**
1912
+** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
1913
+** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
1914
+** [foreign key actions] or [REPLACE] constraint resolution are not counted.
1915
+**
1916
+** Changes to a view that are intercepted by
1917
+** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
1918
+** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
1919
+** DELETE statement run on a view is always zero. Only changes made to real
1920
+** tables are counted.
1921
+**
1922
+** Things are more complicated if the sqlite3_changes() function is
1923
+** executed while a trigger program is running. This may happen if the
1924
+** program uses the [changes() SQL function], or if some other callback
1925
+** function invokes sqlite3_changes() directly. Essentially:
1926
+**
1927
+** <ul>
1928
+** <li> ^(Before entering a trigger program the value returned by
1929
+** sqlite3_changes() function is saved. After the trigger program
1930
+** has finished, the original value is restored.)^
1931
+**
1932
+** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
1933
+** statement sets the value returned by sqlite3_changes()
1934
+** upon completion as normal. Of course, this value will not include
1935
+** any changes performed by sub-triggers, as the sqlite3_changes()
1936
+** value will be saved and restored after each sub-trigger has run.)^
1937
+** </ul>
1938
+**
1939
+** ^This means that if the changes() SQL function (or similar) is used
1940
+** by the first INSERT, UPDATE or DELETE statement within a trigger, it
1941
+** returns the value as set when the calling statement began executing.
1942
+** ^If it is used by the second or subsequent such statement within a trigger
1943
+** program, the value returned reflects the number of rows modified by the
1944
+** previous INSERT, UPDATE or DELETE statement within the same trigger.
19191945
**
19201946
** See also the [sqlite3_total_changes()] interface, the
19211947
** [count_changes pragma], and the [changes() SQL function].
19221948
**
19231949
** If a separate thread makes changes on the same database connection
@@ -1927,24 +1953,21 @@
19271953
SQLITE_API int sqlite3_changes(sqlite3*);
19281954
19291955
/*
19301956
** CAPI3REF: Total Number Of Rows Modified
19311957
**
1932
-** ^This function returns the number of row changes caused by [INSERT],
1933
-** [UPDATE] or [DELETE] statements since the [database connection] was opened.
1934
-** ^(The count returned by sqlite3_total_changes() includes all changes
1935
-** from all [CREATE TRIGGER | trigger] contexts and changes made by
1936
-** [foreign key actions]. However,
1937
-** the count does not include changes used to implement [REPLACE] constraints,
1938
-** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
1939
-** count does not include rows of views that fire an [INSTEAD OF trigger],
1940
-** though if the INSTEAD OF trigger makes changes of its own, those changes
1941
-** are counted.)^
1942
-** ^The sqlite3_total_changes() function counts the changes as soon as
1943
-** the statement that makes them is completed (when the statement handle
1944
-** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
1945
-**
1958
+** ^This function returns the total number of rows inserted, modified or
1959
+** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1960
+** since the database connection was opened, including those executed as
1961
+** part of trigger programs. ^Executing any other type of SQL statement
1962
+** does not affect the value returned by sqlite3_total_changes().
1963
+**
1964
+** ^Changes made as part of [foreign key actions] are included in the
1965
+** count, but those made as part of REPLACE constraint resolution are
1966
+** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
1967
+** are not counted.
1968
+**
19461969
** See also the [sqlite3_changes()] interface, the
19471970
** [count_changes pragma], and the [total_changes() SQL function].
19481971
**
19491972
** If a separate thread makes changes on the same database connection
19501973
** while [sqlite3_total_changes()] is running then the value
@@ -2027,10 +2050,11 @@
20272050
SQLITE_API int sqlite3_complete(const char *sql);
20282051
SQLITE_API int sqlite3_complete16(const void *sql);
20292052
20302053
/*
20312054
** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2055
+** KEYWORDS: {busy-handler callback} {busy handler}
20322056
**
20332057
** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
20342058
** that might be invoked with argument P whenever
20352059
** an attempt is made to access a database table associated with
20362060
** [database connection] D when another thread
@@ -2043,11 +2067,11 @@
20432067
** is not NULL, then the callback might be invoked with two arguments.
20442068
**
20452069
** ^The first argument to the busy handler is a copy of the void* pointer which
20462070
** is the third argument to sqlite3_busy_handler(). ^The second argument to
20472071
** the busy handler callback is the number of times that the busy handler has
2048
-** been invoked for the same locking event. ^If the
2072
+** been invoked previously for the same locking event. ^If the
20492073
** busy callback returns 0, then no additional attempts are made to
20502074
** access the database and [SQLITE_BUSY] is returned
20512075
** to the application.
20522076
** ^If the callback returns non-zero, then another attempt
20532077
** is made to access the database and the cycle repeats.
@@ -2418,17 +2442,18 @@
24182442
** already uses the largest possible [ROWID]. The PRNG is also used for
24192443
** the build-in random() and randomblob() SQL functions. This interface allows
24202444
** applications to access the same PRNG for other purposes.
24212445
**
24222446
** ^A call to this routine stores N bytes of randomness into buffer P.
2423
-** ^If N is less than one, then P can be a NULL pointer.
2447
+** ^The P parameter can be a NULL pointer.
24242448
**
24252449
** ^If this routine has not been previously called or if the previous
2426
-** call had N less than one, then the PRNG is seeded using randomness
2427
-** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2428
-** ^If the previous call to this routine had an N of 1 or more then
2429
-** the pseudo-randomness is generated
2450
+** call had N less than one or a NULL pointer for P, then the PRNG is
2451
+** seeded using randomness obtained from the xRandomness method of
2452
+** the default [sqlite3_vfs] object.
2453
+** ^If the previous call to this routine had an N of 1 or more and a
2454
+** non-NULL P then the pseudo-randomness is generated
24302455
** internally and without recourse to the [sqlite3_vfs] xRandomness
24312456
** method.
24322457
*/
24332458
SQLITE_API void sqlite3_randomness(int N, void *P);
24342459
@@ -4146,13 +4171,13 @@
41464171
** CAPI3REF: Text Encodings
41474172
**
41484173
** These constant define integer codes that represent the various
41494174
** text encodings supported by SQLite.
41504175
*/
4151
-#define SQLITE_UTF8 1
4152
-#define SQLITE_UTF16LE 2
4153
-#define SQLITE_UTF16BE 3
4176
+#define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
4177
+#define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
4178
+#define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
41544179
#define SQLITE_UTF16 4 /* Use native byte order */
41554180
#define SQLITE_ANY 5 /* Deprecated */
41564181
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
41574182
41584183
/*
@@ -4497,11 +4522,12 @@
44974522
** If these routines are called from within the different thread
44984523
** than the one containing the application-defined function that received
44994524
** the [sqlite3_context] pointer, the results are undefined.
45004525
*/
45014526
SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4502
-SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
4527
+SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
4528
+ sqlite3_uint64,void(*)(void*));
45034529
SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
45044530
SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
45054531
SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
45064532
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
45074533
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5129,24 +5155,31 @@
51295155
51305156
51315157
/*
51325158
** CAPI3REF: Extract Metadata About A Column Of A Table
51335159
**
5134
-** ^This routine returns metadata about a specific column of a specific
5135
-** database table accessible using the [database connection] handle
5136
-** passed as the first function argument.
5160
+** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5161
+** information about column C of table T in database D
5162
+** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5163
+** interface returns SQLITE_OK and fills in the non-NULL pointers in
5164
+** the final five arguments with appropriate values if the specified
5165
+** column exists. ^The sqlite3_table_column_metadata() interface returns
5166
+** SQLITE_ERROR and if the specified column does not exist.
5167
+** ^If the column-name parameter to sqlite3_table_column_metadata() is a
5168
+** NULL pointer, then this routine simply checks for the existance of the
5169
+** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5170
+** does not.
51375171
**
51385172
** ^The column is identified by the second, third and fourth parameters to
5139
-** this function. ^The second parameter is either the name of the database
5173
+** this function. ^(The second parameter is either the name of the database
51405174
** (i.e. "main", "temp", or an attached database) containing the specified
5141
-** table or NULL. ^If it is NULL, then all attached databases are searched
5175
+** table or NULL.)^ ^If it is NULL, then all attached databases are searched
51425176
** for the table using the same algorithm used by the database engine to
51435177
** resolve unqualified table references.
51445178
**
51455179
** ^The third and fourth parameters to this function are the table and column
5146
-** name of the desired column, respectively. Neither of these parameters
5147
-** may be NULL.
5180
+** name of the desired column, respectively.
51485181
**
51495182
** ^Metadata is returned by writing to the memory locations passed as the 5th
51505183
** and subsequent parameters to this function. ^Any of these arguments may be
51515184
** NULL, in which case the corresponding element of metadata is omitted.
51525185
**
@@ -5161,36 +5194,33 @@
51615194
** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
51625195
** </table>
51635196
** </blockquote>)^
51645197
**
51655198
** ^The memory pointed to by the character pointers returned for the
5166
-** declaration type and collation sequence is valid only until the next
5199
+** declaration type and collation sequence is valid until the next
51675200
** call to any SQLite API function.
51685201
**
51695202
** ^If the specified table is actually a view, an [error code] is returned.
51705203
**
5171
-** ^If the specified column is "rowid", "oid" or "_rowid_" and an
5204
+** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5205
+** is not a [WITHOUT ROWID] table and an
51725206
** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
51735207
** parameters are set for the explicitly declared column. ^(If there is no
5174
-** explicitly declared [INTEGER PRIMARY KEY] column, then the output
5175
-** parameters are set as follows:
5208
+** [INTEGER PRIMARY KEY] column, then the outputs
5209
+** for the [rowid] are set as follows:
51765210
**
51775211
** <pre>
51785212
** data type: "INTEGER"
51795213
** collation sequence: "BINARY"
51805214
** not null: 0
51815215
** primary key: 1
51825216
** auto increment: 0
51835217
** </pre>)^
51845218
**
5185
-** ^(This function may load one or more schemas from database files. If an
5186
-** error occurs during this process, or if the requested table or column
5187
-** cannot be found, an [error code] is returned and an error message left
5188
-** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
5189
-**
5190
-** ^This API is only available if the library was compiled with the
5191
-** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
5219
+** ^This function causes all database schemas to be read from disk and
5220
+** parsed, if that has not already been done, and returns an error if
5221
+** any errors are encountered while loading the schema.
51925222
*/
51935223
SQLITE_API int sqlite3_table_column_metadata(
51945224
sqlite3 *db, /* Connection handle */
51955225
const char *zDbName, /* Database name or NULL */
51965226
const char *zTableName, /* Table name */
@@ -5638,31 +5668,47 @@
56385668
** in other words, the same BLOB that would be selected by:
56395669
**
56405670
** <pre>
56415671
** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
56425672
** </pre>)^
5673
+**
5674
+** ^(Parameter zDb is not the filename that contains the database, but
5675
+** rather the symbolic name of the database. For attached databases, this is
5676
+** the name that appears after the AS keyword in the [ATTACH] statement.
5677
+** For the main database file, the database name is "main". For TEMP
5678
+** tables, the database name is "temp".)^
56435679
**
56445680
** ^If the flags parameter is non-zero, then the BLOB is opened for read
5645
-** and write access. ^If it is zero, the BLOB is opened for read access.
5646
-** ^It is not possible to open a column that is part of an index or primary
5647
-** key for writing. ^If [foreign key constraints] are enabled, it is
5648
-** not possible to open a column that is part of a [child key] for writing.
5649
-**
5650
-** ^Note that the database name is not the filename that contains
5651
-** the database but rather the symbolic name of the database that
5652
-** appears after the AS keyword when the database is connected using [ATTACH].
5653
-** ^For the main database file, the database name is "main".
5654
-** ^For TEMP tables, the database name is "temp".
5655
-**
5656
-** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5657
-** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5658
-** to be a null pointer.)^
5659
-** ^This function sets the [database connection] error code and message
5660
-** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5661
-** functions. ^Note that the *ppBlob variable is always initialized in a
5662
-** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5663
-** regardless of the success or failure of this routine.
5681
+** and write access. ^If the flags parameter is zero, the BLOB is opened for
5682
+** read-only access.
5683
+**
5684
+** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5685
+** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5686
+** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5687
+** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5688
+** on *ppBlob after this function it returns.
5689
+**
5690
+** This function fails with SQLITE_ERROR if any of the following are true:
5691
+** <ul>
5692
+** <li> ^(Database zDb does not exist)^,
5693
+** <li> ^(Table zTable does not exist within database zDb)^,
5694
+** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5695
+** <li> ^(Column zColumn does not exist)^,
5696
+** <li> ^(Row iRow is not present in the table)^,
5697
+** <li> ^(The specified column of row iRow contains a value that is not
5698
+** a TEXT or BLOB value)^,
5699
+** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5700
+** constraint and the blob is being opened for read/write access)^,
5701
+** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5702
+** column zColumn is part of a [child key] definition and the blob is
5703
+** being opened for read/write access)^.
5704
+** </ul>
5705
+**
5706
+** ^Unless it returns SQLITE_MISUSE, this function sets the
5707
+** [database connection] error code and message accessible via
5708
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5709
+**
56645710
**
56655711
** ^(If the row that a BLOB handle points to is modified by an
56665712
** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
56675713
** then the BLOB handle is marked as "expired".
56685714
** This is true if any column of the row is changed, even a column
@@ -5676,17 +5722,13 @@
56765722
** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
56775723
** the opened blob. ^The size of a blob may not be changed by this
56785724
** interface. Use the [UPDATE] SQL command to change the size of a
56795725
** blob.
56805726
**
5681
-** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5682
-** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5683
-**
56845727
** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5685
-** and the built-in [zeroblob] SQL function can be used, if desired,
5686
-** to create an empty, zero-filled blob in which to read or write using
5687
-** this interface.
5728
+** and the built-in [zeroblob] SQL function may be used to create a
5729
+** zero-filled blob to read or write using the incremental-blob interface.
56885730
**
56895731
** To avoid a resource leak, every open [BLOB handle] should eventually
56905732
** be released by a call to [sqlite3_blob_close()].
56915733
*/
56925734
SQLITE_API int sqlite3_blob_open(
@@ -5724,28 +5766,26 @@
57245766
SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
57255767
57265768
/*
57275769
** CAPI3REF: Close A BLOB Handle
57285770
**
5729
-** ^Closes an open [BLOB handle].
5730
-**
5731
-** ^Closing a BLOB shall cause the current transaction to commit
5732
-** if there are no other BLOBs, no pending prepared statements, and the
5733
-** database connection is in [autocommit mode].
5734
-** ^If any writes were made to the BLOB, they might be held in cache
5735
-** until the close operation if they will fit.
5736
-**
5737
-** ^(Closing the BLOB often forces the changes
5738
-** out to disk and so if any I/O errors occur, they will likely occur
5739
-** at the time when the BLOB is closed. Any errors that occur during
5740
-** closing are reported as a non-zero return value.)^
5741
-**
5742
-** ^(The BLOB is closed unconditionally. Even if this routine returns
5743
-** an error code, the BLOB is still closed.)^
5744
-**
5745
-** ^Calling this routine with a null pointer (such as would be returned
5746
-** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5771
+** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5772
+** unconditionally. Even if this routine returns an error code, the
5773
+** handle is still closed.)^
5774
+**
5775
+** ^If the blob handle being closed was opened for read-write access, and if
5776
+** the database is in auto-commit mode and there are no other open read-write
5777
+** blob handles or active write statements, the current transaction is
5778
+** committed. ^If an error occurs while committing the transaction, an error
5779
+** code is returned and the transaction rolled back.
5780
+**
5781
+** Calling this function with an argument that is not a NULL pointer or an
5782
+** open blob handle results in undefined behaviour. ^Calling this routine
5783
+** with a null pointer (such as would be returned by a failed call to
5784
+** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5785
+** is passed a valid open blob handle, the values returned by the
5786
+** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
57475787
*/
57485788
SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
57495789
57505790
/*
57515791
** CAPI3REF: Return The Size Of An Open BLOB
@@ -5791,36 +5831,39 @@
57915831
SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
57925832
57935833
/*
57945834
** CAPI3REF: Write Data Into A BLOB Incrementally
57955835
**
5796
-** ^This function is used to write data into an open [BLOB handle] from a
5797
-** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5798
-** into the open BLOB, starting at offset iOffset.
5836
+** ^(This function is used to write data into an open [BLOB handle] from a
5837
+** caller-supplied buffer. N bytes of data are copied from the buffer Z
5838
+** into the open BLOB, starting at offset iOffset.)^
5839
+**
5840
+** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5841
+** Otherwise, an [error code] or an [extended error code] is returned.)^
5842
+** ^Unless SQLITE_MISUSE is returned, this function sets the
5843
+** [database connection] error code and message accessible via
5844
+** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
57995845
**
58005846
** ^If the [BLOB handle] passed as the first argument was not opened for
58015847
** writing (the flags parameter to [sqlite3_blob_open()] was zero),
58025848
** this function returns [SQLITE_READONLY].
58035849
**
5804
-** ^This function may only modify the contents of the BLOB; it is
5850
+** This function may only modify the contents of the BLOB; it is
58055851
** not possible to increase the size of a BLOB using this API.
58065852
** ^If offset iOffset is less than N bytes from the end of the BLOB,
5807
-** [SQLITE_ERROR] is returned and no data is written. ^If N is
5808
-** less than zero [SQLITE_ERROR] is returned and no data is written.
5809
-** The size of the BLOB (and hence the maximum value of N+iOffset)
5810
-** can be determined using the [sqlite3_blob_bytes()] interface.
5853
+** [SQLITE_ERROR] is returned and no data is written. The size of the
5854
+** BLOB (and hence the maximum value of N+iOffset) can be determined
5855
+** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5856
+** than zero [SQLITE_ERROR] is returned and no data is written.
58115857
**
58125858
** ^An attempt to write to an expired [BLOB handle] fails with an
58135859
** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
58145860
** before the [BLOB handle] expired are not rolled back by the
58155861
** expiration of the handle, though of course those changes might
58165862
** have been overwritten by the statement that expired the BLOB handle
58175863
** or by other independent statements.
58185864
**
5819
-** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5820
-** Otherwise, an [error code] or an [extended error code] is returned.)^
5821
-**
58225865
** This routine only works on a [BLOB handle] which has been created
58235866
** by a prior successful call to [sqlite3_blob_open()] and which has not
58245867
** been closed by [sqlite3_blob_close()]. Passing any other pointer in
58255868
** to this routine results in undefined and probably undesirable behavior.
58265869
**
@@ -5869,38 +5912,38 @@
58695912
** use by SQLite, code that links against SQLite is
58705913
** permitted to use any of these routines.
58715914
**
58725915
** The SQLite source code contains multiple implementations
58735916
** of these mutex routines. An appropriate implementation
5874
-** is selected automatically at compile-time. ^(The following
5917
+** is selected automatically at compile-time. The following
58755918
** implementations are available in the SQLite core:
58765919
**
58775920
** <ul>
58785921
** <li> SQLITE_MUTEX_PTHREADS
58795922
** <li> SQLITE_MUTEX_W32
58805923
** <li> SQLITE_MUTEX_NOOP
5881
-** </ul>)^
5924
+** </ul>
58825925
**
5883
-** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
5926
+** The SQLITE_MUTEX_NOOP implementation is a set of routines
58845927
** that does no real locking and is appropriate for use in
5885
-** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
5928
+** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
58865929
** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
58875930
** and Windows.
58885931
**
5889
-** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5932
+** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
58905933
** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
58915934
** implementation is included with the library. In this case the
58925935
** application must supply a custom mutex implementation using the
58935936
** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
58945937
** before calling sqlite3_initialize() or any other public sqlite3_
5895
-** function that calls sqlite3_initialize().)^
5938
+** function that calls sqlite3_initialize().
58965939
**
58975940
** ^The sqlite3_mutex_alloc() routine allocates a new
5898
-** mutex and returns a pointer to it. ^If it returns NULL
5899
-** that means that a mutex could not be allocated. ^SQLite
5900
-** will unwind its stack and return an error. ^(The argument
5901
-** to sqlite3_mutex_alloc() is one of these integer constants:
5941
+** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
5942
+** routine returns NULL if it is unable to allocate the requested
5943
+** mutex. The argument to sqlite3_mutex_alloc() must one of these
5944
+** integer constants:
59025945
**
59035946
** <ul>
59045947
** <li> SQLITE_MUTEX_FAST
59055948
** <li> SQLITE_MUTEX_RECURSIVE
59065949
** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -5909,68 +5952,64 @@
59095952
** <li> SQLITE_MUTEX_STATIC_PRNG
59105953
** <li> SQLITE_MUTEX_STATIC_LRU
59115954
** <li> SQLITE_MUTEX_STATIC_PMEM
59125955
** <li> SQLITE_MUTEX_STATIC_APP1
59135956
** <li> SQLITE_MUTEX_STATIC_APP2
5914
-** </ul>)^
5957
+** <li> SQLITE_MUTEX_STATIC_APP3
5958
+** </ul>
59155959
**
59165960
** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
59175961
** cause sqlite3_mutex_alloc() to create
59185962
** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
59195963
** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
59205964
** The mutex implementation does not need to make a distinction
59215965
** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
5922
-** not want to. ^SQLite will only request a recursive mutex in
5923
-** cases where it really needs one. ^If a faster non-recursive mutex
5966
+** not want to. SQLite will only request a recursive mutex in
5967
+** cases where it really needs one. If a faster non-recursive mutex
59245968
** implementation is available on the host platform, the mutex subsystem
59255969
** might return such a mutex in response to SQLITE_MUTEX_FAST.
59265970
**
59275971
** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
59285972
** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
5929
-** a pointer to a static preexisting mutex. ^Six static mutexes are
5973
+** a pointer to a static preexisting mutex. ^Nine static mutexes are
59305974
** used by the current version of SQLite. Future versions of SQLite
59315975
** may add additional static mutexes. Static mutexes are for internal
59325976
** use by SQLite only. Applications that use SQLite mutexes should
59335977
** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
59345978
** SQLITE_MUTEX_RECURSIVE.
59355979
**
59365980
** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
59375981
** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
5938
-** returns a different mutex on every call. ^But for the static
5982
+** returns a different mutex on every call. ^For the static
59395983
** mutex types, the same mutex is returned on every call that has
59405984
** the same type number.
59415985
**
59425986
** ^The sqlite3_mutex_free() routine deallocates a previously
5943
-** allocated dynamic mutex. ^SQLite is careful to deallocate every
5944
-** dynamic mutex that it allocates. The dynamic mutexes must not be in
5945
-** use when they are deallocated. Attempting to deallocate a static
5946
-** mutex results in undefined behavior. ^SQLite never deallocates
5947
-** a static mutex.
5987
+** allocated dynamic mutex. Attempting to deallocate a static
5988
+** mutex results in undefined behavior.
59485989
**
59495990
** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
59505991
** to enter a mutex. ^If another thread is already within the mutex,
59515992
** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
59525993
** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
59535994
** upon successful entry. ^(Mutexes created using
59545995
** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
5955
-** In such cases the,
5996
+** In such cases, the
59565997
** mutex must be exited an equal number of times before another thread
5957
-** can enter.)^ ^(If the same thread tries to enter any other
5958
-** kind of mutex more than once, the behavior is undefined.
5959
-** SQLite will never exhibit
5960
-** such behavior in its own use of mutexes.)^
5998
+** can enter.)^ If the same thread tries to enter any mutex other
5999
+** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
59616000
**
59626001
** ^(Some systems (for example, Windows 95) do not support the operation
59636002
** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
5964
-** will always return SQLITE_BUSY. The SQLite core only ever uses
5965
-** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
6003
+** will always return SQLITE_BUSY. The SQLite core only ever uses
6004
+** sqlite3_mutex_try() as an optimization so this is acceptable
6005
+** behavior.)^
59666006
**
59676007
** ^The sqlite3_mutex_leave() routine exits a mutex that was
5968
-** previously entered by the same thread. ^(The behavior
6008
+** previously entered by the same thread. The behavior
59696009
** is undefined if the mutex is not currently entered by the
5970
-** calling thread or is not currently allocated. SQLite will
5971
-** never do either.)^
6010
+** calling thread or is not currently allocated.
59726011
**
59736012
** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
59746013
** sqlite3_mutex_leave() is a NULL pointer, then all three routines
59756014
** behave as no-ops.
59766015
**
@@ -5987,13 +6026,13 @@
59876026
**
59886027
** An instance of this structure defines the low-level routines
59896028
** used to allocate and use mutexes.
59906029
**
59916030
** Usually, the default mutex implementations provided by SQLite are
5992
-** sufficient, however the user has the option of substituting a custom
6031
+** sufficient, however the application has the option of substituting a custom
59936032
** implementation for specialized deployments or systems for which SQLite
5994
-** does not provide a suitable implementation. In this case, the user
6033
+** does not provide a suitable implementation. In this case, the application
59956034
** creates and populates an instance of this structure to pass
59966035
** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
59976036
** Additionally, an instance of this structure can be used as an
59986037
** output variable when querying the system for the current mutex
59996038
** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6030,17 +6069,17 @@
60306069
** by this structure are not required to handle this case, the results
60316070
** of passing a NULL pointer instead of a valid mutex handle are undefined
60326071
** (i.e. it is acceptable to provide an implementation that segfaults if
60336072
** it is passed a NULL pointer).
60346073
**
6035
-** The xMutexInit() method must be threadsafe. ^It must be harmless to
6074
+** The xMutexInit() method must be threadsafe. It must be harmless to
60366075
** invoke xMutexInit() multiple times within the same process and without
60376076
** intervening calls to xMutexEnd(). Second and subsequent calls to
60386077
** xMutexInit() must be no-ops.
60396078
**
6040
-** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6041
-** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
6079
+** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6080
+** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
60426081
** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
60436082
** memory allocation for a fast or recursive mutex.
60446083
**
60456084
** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
60466085
** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6062,33 +6101,33 @@
60626101
60636102
/*
60646103
** CAPI3REF: Mutex Verification Routines
60656104
**
60666105
** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6067
-** are intended for use inside assert() statements. ^The SQLite core
6106
+** are intended for use inside assert() statements. The SQLite core
60686107
** never uses these routines except inside an assert() and applications
6069
-** are advised to follow the lead of the core. ^The SQLite core only
6108
+** are advised to follow the lead of the core. The SQLite core only
60706109
** provides implementations for these routines when it is compiled
6071
-** with the SQLITE_DEBUG flag. ^External mutex implementations
6110
+** with the SQLITE_DEBUG flag. External mutex implementations
60726111
** are only required to provide these routines if SQLITE_DEBUG is
60736112
** defined and if NDEBUG is not defined.
60746113
**
6075
-** ^These routines should return true if the mutex in their argument
6114
+** These routines should return true if the mutex in their argument
60766115
** is held or not held, respectively, by the calling thread.
60776116
**
6078
-** ^The implementation is not required to provide versions of these
6117
+** The implementation is not required to provide versions of these
60796118
** routines that actually work. If the implementation does not provide working
60806119
** versions of these routines, it should at least provide stubs that always
60816120
** return true so that one does not get spurious assertion failures.
60826121
**
6083
-** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
6122
+** If the argument to sqlite3_mutex_held() is a NULL pointer then
60846123
** the routine should return 1. This seems counter-intuitive since
60856124
** clearly the mutex cannot be held if it does not exist. But
60866125
** the reason the mutex does not exist is because the build is not
60876126
** using mutexes. And we do not want the assert() containing the
60886127
** call to sqlite3_mutex_held() to fail, so a non-zero return is
6089
-** the appropriate thing to do. ^The sqlite3_mutex_notheld()
6128
+** the appropriate thing to do. The sqlite3_mutex_notheld()
60906129
** interface should also return 1 when given a NULL pointer.
60916130
*/
60926131
#ifndef NDEBUG
60936132
SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
60946133
SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6816,10 +6855,14 @@
68166855
** sqlite3_backup_init(D,N,S,M) identify the [database connection]
68176856
** and database name of the source database, respectively.
68186857
** ^The source and destination [database connections] (parameters S and D)
68196858
** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
68206859
** an error.
6860
+**
6861
+** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
6862
+** there is already a read or read-write transaction open on the
6863
+** destination database.
68216864
**
68226865
** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
68236866
** returned and an error code and error message are stored in the
68246867
** destination [database connection] D.
68256868
** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7210,101 +7253,118 @@
72107253
SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
72117254
72127255
/*
72137256
** CAPI3REF: Checkpoint a database
72147257
**
7215
-** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7216
-** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7217
-** empty string, then a checkpoint is run on all databases of
7218
-** connection D. ^If the database connection D is not in
7219
-** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7220
-** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7221
-** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7222
-** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7223
-** or RESET checkpoint.
7224
-**
7225
-** ^The [wal_checkpoint pragma] can be used to invoke this interface
7226
-** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7227
-** [wal_autocheckpoint pragma] can be used to cause this interface to be
7228
-** run whenever the WAL reaches a certain size threshold.
7229
-**
7230
-** See also: [sqlite3_wal_checkpoint_v2()]
7258
+** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7259
+** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7260
+**
7261
+** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
7262
+** [write-ahead log] for database X on [database connection] D to be
7263
+** transferred into the database file and for the write-ahead log to
7264
+** be reset. See the [checkpointing] documentation for addition
7265
+** information.
7266
+**
7267
+** This interface used to be the only way to cause a checkpoint to
7268
+** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
7269
+** interface was added. This interface is retained for backwards
7270
+** compatibility and as a convenience for applications that need to manually
7271
+** start a callback but which do not need the full power (and corresponding
7272
+** complication) of [sqlite3_wal_checkpoint_v2()].
72317273
*/
72327274
SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
72337275
72347276
/*
72357277
** CAPI3REF: Checkpoint a database
72367278
**
7237
-** Run a checkpoint operation on WAL database zDb attached to database
7238
-** handle db. The specific operation is determined by the value of the
7239
-** eMode parameter:
7279
+** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7280
+** operation on database X of [database connection] D in mode M. Status
7281
+** information is written back into integers pointed to by L and C.)^
7282
+** ^(The M parameter must be a valid [checkpoint mode]:)^
72407283
**
72417284
** <dl>
72427285
** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7243
-** Checkpoint as many frames as possible without waiting for any database
7244
-** readers or writers to finish. Sync the db file if all frames in the log
7245
-** are checkpointed. This mode is the same as calling
7246
-** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7247
-** is never invoked.
7286
+** ^Checkpoint as many frames as possible without waiting for any database
7287
+** readers or writers to finish, then sync the database file if all frames
7288
+** in the log were checkpointed. ^The [busy-handler callback]
7289
+** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
7290
+** ^On the other hand, passive mode might leave the checkpoint unfinished
7291
+** if there are concurrent readers or writers.
72487292
**
72497293
** <dt>SQLITE_CHECKPOINT_FULL<dd>
7250
-** This mode blocks (it invokes the
7294
+** ^This mode blocks (it invokes the
72517295
** [sqlite3_busy_handler|busy-handler callback]) until there is no
72527296
** database writer and all readers are reading from the most recent database
7253
-** snapshot. It then checkpoints all frames in the log file and syncs the
7254
-** database file. This call blocks database writers while it is running,
7255
-** but not database readers.
7297
+** snapshot. ^It then checkpoints all frames in the log file and syncs the
7298
+** database file. ^This mode blocks new database writers while it is pending,
7299
+** but new database readers are allowed to continue unimpeded.
72567300
**
72577301
** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7258
-** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7259
-** checkpointing the log file it blocks (calls the
7260
-** [sqlite3_busy_handler|busy-handler callback])
7261
-** until all readers are reading from the database file only. This ensures
7262
-** that the next client to write to the database file restarts the log file
7263
-** from the beginning. This call blocks database writers while it is running,
7264
-** but not database readers.
7302
+** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
7303
+** that after checkpointing the log file it blocks (calls the
7304
+** [busy-handler callback])
7305
+** until all readers are reading from the database file only. ^This ensures
7306
+** that the next writer will restart the log file from the beginning.
7307
+** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
7308
+** database writer attempts while it is pending, but does not impede readers.
7309
+**
7310
+** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
7311
+** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
7312
+** addition that it also truncates the log file to zero bytes just prior
7313
+** to a successful return.
72657314
** </dl>
72667315
**
7267
-** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7268
-** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7269
-** the total number of checkpointed frames (including any that were already
7270
-** checkpointed when this function is called). *pnLog and *pnCkpt may be
7271
-** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
7272
-** If no values are available because of an error, they are both set to -1
7273
-** before returning to communicate this to the caller.
7316
+** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
7317
+** the log file or to -1 if the checkpoint could not run because
7318
+** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
7319
+** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
7320
+** log file (including any that were already checkpointed before the function
7321
+** was called) or to -1 if the checkpoint could not run due to an error or
7322
+** because the database is not in WAL mode. ^Note that upon successful
7323
+** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
7324
+** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
72747325
**
7275
-** All calls obtain an exclusive "checkpoint" lock on the database file. If
7326
+** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
72767327
** any other process is running a checkpoint operation at the same time, the
7277
-** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
7328
+** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
72787329
** busy-handler configured, it will not be invoked in this case.
72797330
**
7280
-** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
7281
-** "writer" lock on the database file. If the writer lock cannot be obtained
7282
-** immediately, and a busy-handler is configured, it is invoked and the writer
7283
-** lock retried until either the busy-handler returns 0 or the lock is
7284
-** successfully obtained. The busy-handler is also invoked while waiting for
7285
-** database readers as described above. If the busy-handler returns 0 before
7331
+** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
7332
+** exclusive "writer" lock on the database file. ^If the writer lock cannot be
7333
+** obtained immediately, and a busy-handler is configured, it is invoked and
7334
+** the writer lock retried until either the busy-handler returns 0 or the lock
7335
+** is successfully obtained. ^The busy-handler is also invoked while waiting for
7336
+** database readers as described above. ^If the busy-handler returns 0 before
72867337
** the writer lock is obtained or while waiting for database readers, the
72877338
** checkpoint operation proceeds from that point in the same way as
72887339
** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7289
-** without blocking any further. SQLITE_BUSY is returned in this case.
7340
+** without blocking any further. ^SQLITE_BUSY is returned in this case.
72907341
**
7291
-** If parameter zDb is NULL or points to a zero length string, then the
7292
-** specified operation is attempted on all WAL databases. In this case the
7293
-** values written to output parameters *pnLog and *pnCkpt are undefined. If
7342
+** ^If parameter zDb is NULL or points to a zero length string, then the
7343
+** specified operation is attempted on all WAL databases [attached] to
7344
+** [database connection] db. In this case the
7345
+** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
72947346
** an SQLITE_BUSY error is encountered when processing one or more of the
72957347
** attached WAL databases, the operation is still attempted on any remaining
7296
-** attached databases and SQLITE_BUSY is returned to the caller. If any other
7348
+** attached databases and SQLITE_BUSY is returned at the end. ^If any other
72977349
** error occurs while processing an attached database, processing is abandoned
7298
-** and the error code returned to the caller immediately. If no error
7350
+** and the error code is returned to the caller immediately. ^If no error
72997351
** (SQLITE_BUSY or otherwise) is encountered while processing the attached
73007352
** databases, SQLITE_OK is returned.
73017353
**
7302
-** If database zDb is the name of an attached database that is not in WAL
7303
-** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
7354
+** ^If database zDb is the name of an attached database that is not in WAL
7355
+** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
73047356
** zDb is not NULL (or a zero length string) and is not the name of any
73057357
** attached database, SQLITE_ERROR is returned to the caller.
7358
+**
7359
+** ^Unless it returns SQLITE_MISUSE,
7360
+** the sqlite3_wal_checkpoint_v2() interface
7361
+** sets the error information that is queried by
7362
+** [sqlite3_errcode()] and [sqlite3_errmsg()].
7363
+**
7364
+** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
7365
+** from SQL.
73067366
*/
73077367
SQLITE_API int sqlite3_wal_checkpoint_v2(
73087368
sqlite3 *db, /* Database handle */
73097369
const char *zDb, /* Name of attached database (or NULL) */
73107370
int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7311,20 +7371,22 @@
73117371
int *pnLog, /* OUT: Size of WAL log in frames */
73127372
int *pnCkpt /* OUT: Total number of frames checkpointed */
73137373
);
73147374
73157375
/*
7316
-** CAPI3REF: Checkpoint operation parameters
7376
+** CAPI3REF: Checkpoint Mode Values
7377
+** KEYWORDS: {checkpoint mode}
73177378
**
7318
-** These constants can be used as the 3rd parameter to
7319
-** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
7320
-** documentation for additional information about the meaning and use of
7321
-** each of these values.
7379
+** These constants define all valid values for the "checkpoint mode" passed
7380
+** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
7381
+** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
7382
+** meaning of each of these checkpoint modes.
73227383
*/
7323
-#define SQLITE_CHECKPOINT_PASSIVE 0
7324
-#define SQLITE_CHECKPOINT_FULL 1
7325
-#define SQLITE_CHECKPOINT_RESTART 2
7384
+#define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
7385
+#define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
7386
+#define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
7387
+#define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
73267388
73277389
/*
73287390
** CAPI3REF: Virtual Table Interface Configuration
73297391
**
73307392
** This function may be called by either the [xConnect] or [xCreate] method
@@ -7409,10 +7471,102 @@
74097471
/* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
74107472
#define SQLITE_FAIL 3
74117473
/* #define SQLITE_ABORT 4 // Also an error code */
74127474
#define SQLITE_REPLACE 5
74137475
7476
+/*
7477
+** CAPI3REF: Prepared Statement Scan Status Opcodes
7478
+** KEYWORDS: {scanstatus options}
7479
+**
7480
+** The following constants can be used for the T parameter to the
7481
+** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7482
+** different metric for sqlite3_stmt_scanstatus() to return.
7483
+**
7484
+** <dl>
7485
+** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7486
+** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7487
+** set to the total number of times that the X-th loop has run.</dd>
7488
+**
7489
+** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7490
+** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
7491
+** to the total number of rows examined by all iterations of the X-th loop.</dd>
7492
+**
7493
+** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7494
+** <dd>^The "double" variable pointed to by the T parameter will be set to the
7495
+** query planner's estimate for the average number of rows output from each
7496
+** iteration of the X-th loop. If the query planner's estimates was accurate,
7497
+** then this value will approximate the quotient NVISIT/NLOOP and the
7498
+** product of this value for all prior loops with the same SELECTID will
7499
+** be the NLOOP value for the current loop.
7500
+**
7501
+** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7502
+** <dd>^The "const char *" variable pointed to by the T parameter will be set
7503
+** to a zero-terminated UTF-8 string containing the name of the index or table
7504
+** used for the X-th loop.
7505
+**
7506
+** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7507
+** <dd>^The "const char *" variable pointed to by the T parameter will be set
7508
+** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
7509
+** description for the X-th loop.
7510
+**
7511
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7512
+** <dd>^The "int" variable pointed to by the T parameter will be set to the
7513
+** "select-id" for the X-th loop. The select-id identifies which query or
7514
+** subquery the loop is part of. The main query has a select-id of zero.
7515
+** The select-id is the same value as is output in the first column
7516
+** of an [EXPLAIN QUERY PLAN] query.
7517
+** </dl>
7518
+*/
7519
+#define SQLITE_SCANSTAT_NLOOP 0
7520
+#define SQLITE_SCANSTAT_NVISIT 1
7521
+#define SQLITE_SCANSTAT_EST 2
7522
+#define SQLITE_SCANSTAT_NAME 3
7523
+#define SQLITE_SCANSTAT_EXPLAIN 4
7524
+#define SQLITE_SCANSTAT_SELECTID 5
7525
+
7526
+/*
7527
+** CAPI3REF: Prepared Statement Scan Status
7528
+**
7529
+** Return status data for a single loop within query pStmt.
7530
+**
7531
+** The "iScanStatusOp" parameter determines which status information to return.
7532
+** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7533
+** of this interface is undefined.
7534
+** ^The requested measurement is written into a variable pointed to by
7535
+** the "pOut" parameter.
7536
+** Parameter "idx" identifies the specific loop to retrieve statistics for.
7537
+** Loops are numbered starting from zero. ^If idx is out of range - less than
7538
+** zero or greater than or equal to the total number of loops used to implement
7539
+** the statement - a non-zero value is returned and the variable that pOut
7540
+** points to is unchanged.
7541
+**
7542
+** ^Statistics might not be available for all loops in all statements. ^In cases
7543
+** where there exist loops with no available statistics, this function behaves
7544
+** as if the loop did not exist - it returns non-zero and leave the variable
7545
+** that pOut points to unchanged.
7546
+**
7547
+** This API is only available if the library is built with pre-processor
7548
+** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7549
+**
7550
+** See also: [sqlite3_stmt_scanstatus_reset()]
7551
+*/
7552
+SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7553
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7554
+ int idx, /* Index of loop to report on */
7555
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7556
+ void *pOut /* Result written here */
7557
+);
7558
+
7559
+/*
7560
+** CAPI3REF: Zero Scan-Status Counters
7561
+**
7562
+** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7563
+**
7564
+** This API is only available if the library is built with pre-processor
7565
+** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7566
+*/
7567
+SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
74147568
74157569
74167570
/*
74177571
** Undo the hack that converts floating point types to integer for
74187572
** builds on processors without floating point support.
74197573
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
55
56
57 /*
58 ** These no-op macros are used in front of interfaces to mark those
59 ** interfaces as either deprecated or experimental. New applications
60 ** should not use deprecated interfaces - they are support for backwards
61 ** compatibility only. Application writers should be aware that
62 ** experimental interfaces are subject to change in point releases.
63 **
64 ** These macros used to resolve to various kinds of compiler magic that
65 ** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.7.1"
111 #define SQLITE_VERSION_NUMBER 3008007
112 #define SQLITE_SOURCE_ID "2014-10-29 01:27:43 83afe23e553e802c0947c80d0ffdd120423e7c52"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1219,11 +1219,11 @@
1219 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1220 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1221 ** </ul>
1222 **
1223 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1224 ** was given no the corresponding lock.
1225 **
1226 ** The xShmLock method can transition between unlocked and SHARED or
1227 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1228 ** and EXCLUSIVE.
1229 */
@@ -1502,30 +1502,32 @@
1502 ** it is not possible to set the Serialized [threading mode] and
1503 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1504 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1505 **
1506 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507 ** <dd> ^(This option takes a single argument which is a pointer to an
1508 ** instance of the [sqlite3_mem_methods] structure. The argument specifies
 
1509 ** alternative low-level memory allocation routines to be used in place of
1510 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1511 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1512 ** before the [sqlite3_config()] call returns.</dd>
1513 **
1514 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1515 ** <dd> ^(This option takes a single argument which is a pointer to an
1516 ** instance of the [sqlite3_mem_methods] structure. The [sqlite3_mem_methods]
 
1517 ** structure is filled with the currently defined memory allocation routines.)^
1518 ** This option can be used to overload the default memory allocation
1519 ** routines with a wrapper that simulations memory allocation failure or
1520 ** tracks memory usage, for example. </dd>
1521 **
1522 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1523 ** <dd> ^This option takes single argument of type int, interpreted as a
1524 ** boolean, which enables or disables the collection of memory allocation
1525 ** statistics. ^(When memory allocation statistics are disabled, the
1526 ** following SQLite interfaces become non-operational:
1527 ** <ul>
1528 ** <li> [sqlite3_memory_used()]
1529 ** <li> [sqlite3_memory_highwater()]
1530 ** <li> [sqlite3_soft_heap_limit64()]
1531 ** <li> [sqlite3_status()]
@@ -1534,78 +1536,92 @@
1534 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1535 ** allocation statistics are disabled by default.
1536 ** </dd>
1537 **
1538 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1539 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1540 ** scratch memory. There are three arguments: A pointer an 8-byte
 
1541 ** aligned memory buffer from which the scratch allocations will be
1542 ** drawn, the size of each scratch allocation (sz),
1543 ** and the maximum number of scratch allocations (N). The sz
1544 ** argument must be a multiple of 16.
1545 ** The first argument must be a pointer to an 8-byte aligned buffer
1546 ** of at least sz*N bytes of memory.
1547 ** ^SQLite will use no more than two scratch buffers per thread. So
1548 ** N should be set to twice the expected maximum number of threads.
1549 ** ^SQLite will never require a scratch buffer that is more than 6
1550 ** times the database page size. ^If SQLite needs needs additional
1551 ** scratch memory beyond what is provided by this configuration option, then
1552 ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
 
 
 
 
 
 
1553 **
1554 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1555 ** <dd> ^This option specifies a static memory buffer that SQLite can use for
1556 ** the database page cache with the default page cache implementation.
 
1557 ** This configuration should not be used if an application-define page
1558 ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
1559 ** There are three arguments to this option: A pointer to 8-byte aligned
 
 
1560 ** memory, the size of each page buffer (sz), and the number of pages (N).
1561 ** The sz argument should be the size of the largest database page
1562 ** (a power of two between 512 and 32768) plus a little extra for each
1563 ** page header. ^The page header size is 20 to 40 bytes depending on
1564 ** the host architecture. ^It is harmless, apart from the wasted memory,
1565 ** to make sz a little too large. The first
1566 ** argument should point to an allocation of at least sz*N bytes of memory.
 
 
 
 
1567 ** ^SQLite will use the memory provided by the first argument to satisfy its
1568 ** memory needs for the first N pages that it adds to cache. ^If additional
1569 ** page cache memory is needed beyond what is provided by this option, then
1570 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.
1571 ** The pointer in the first argument must
1572 ** be aligned to an 8-byte boundary or subsequent behavior of SQLite
1573 ** will be undefined.</dd>
1574 **
1575 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1576 ** <dd> ^This option specifies a static memory buffer that SQLite will use
1577 ** for all of its dynamic memory allocation needs beyond those provided
1578 ** for by [SQLITE_CONFIG_SCRATCH] and [SQLITE_CONFIG_PAGECACHE].
1579 ** There are three arguments: An 8-byte aligned pointer to the memory,
 
 
 
 
 
1580 ** the number of bytes in the memory buffer, and the minimum allocation size.
1581 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1582 ** to using its default memory allocator (the system malloc() implementation),
1583 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1584 ** memory pointer is not NULL and either [SQLITE_ENABLE_MEMSYS3] or
1585 ** [SQLITE_ENABLE_MEMSYS5] are defined, then the alternative memory
1586 ** allocator is engaged to handle all of SQLites memory allocation needs.
1587 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1588 ** boundary or subsequent behavior of SQLite will be undefined.
1589 ** The minimum allocation size is capped at 2**12. Reasonable values
1590 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1591 **
1592 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1593 ** <dd> ^(This option takes a single argument which is a pointer to an
1594 ** instance of the [sqlite3_mutex_methods] structure. The argument specifies
1595 ** alternative low-level mutex routines to be used in place
1596 ** the mutex routines built into SQLite.)^ ^SQLite makes a copy of the
1597 ** content of the [sqlite3_mutex_methods] structure before the call to
1598 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1599 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1600 ** the entire mutexing subsystem is omitted from the build and hence calls to
1601 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1602 ** return [SQLITE_ERROR].</dd>
1603 **
1604 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1605 ** <dd> ^(This option takes a single argument which is a pointer to an
1606 ** instance of the [sqlite3_mutex_methods] structure. The
1607 ** [sqlite3_mutex_methods]
1608 ** structure is filled with the currently defined mutex routines.)^
1609 ** This option can be used to overload the default mutex allocation
1610 ** routines with a wrapper used to track mutex usage for performance
1611 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1613,29 +1629,29 @@
1613 ** the entire mutexing subsystem is omitted from the build and hence calls to
1614 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1615 ** return [SQLITE_ERROR].</dd>
1616 **
1617 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1618 ** <dd> ^(This option takes two arguments that determine the default
1619 ** memory allocation for the lookaside memory allocator on each
1620 ** [database connection]. The first argument is the
1621 ** size of each lookaside buffer slot and the second is the number of
1622 ** slots allocated to each database connection.)^ ^(This option sets the
1623 ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1624 ** verb to [sqlite3_db_config()] can be used to change the lookaside
1625 ** configuration on individual connections.)^ </dd>
1626 **
1627 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1628 ** <dd> ^(This option takes a single argument which is a pointer to
1629 ** an [sqlite3_pcache_methods2] object. This object specifies the interface
1630 ** to a custom page cache implementation.)^ ^SQLite makes a copy of the
1631 ** object and uses it for page cache memory allocations.</dd>
1632 **
1633 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1634 ** <dd> ^(This option takes a single argument which is a pointer to an
1635 ** [sqlite3_pcache_methods2] object. SQLite copies of the current
1636 ** page cache implementation into that object.)^ </dd>
1637 **
1638 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1639 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1640 ** global [error log].
1641 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1654,26 +1670,28 @@
1654 ** supplied by the application must not invoke any SQLite interface.
1655 ** In a multi-threaded application, the application-defined logger
1656 ** function must be threadsafe. </dd>
1657 **
1658 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1659 ** <dd>^(This option takes a single argument of type int. If non-zero, then
1660 ** URI handling is globally enabled. If the parameter is zero, then URI handling
1661 ** is globally disabled.)^ ^If URI handling is globally enabled, all filenames
1662 ** passed to [sqlite3_open()], [sqlite3_open_v2()], [sqlite3_open16()] or
 
1663 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1664 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1665 ** connection is opened. ^If it is globally disabled, filenames are
1666 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1667 ** database connection is opened. ^(By default, URI handling is globally
1668 ** disabled. The default value may be changed by compiling with the
1669 ** [SQLITE_USE_URI] symbol defined.)^
1670 **
1671 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1672 ** <dd>^This option takes a single integer argument which is interpreted as
1673 ** a boolean in order to enable or disable the use of covering indices for
1674 ** full table scans in the query optimizer. ^The default setting is determined
 
1675 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1676 ** if that compile-time option is omitted.
1677 ** The ability to disable the use of covering indices for full table scans
1678 ** is because some incorrectly coded legacy applications might malfunction
1679 ** when the optimization is enabled. Providing the ability to
@@ -1709,23 +1727,32 @@
1709 ** that are the default mmap size limit (the default setting for
1710 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1711 ** ^The default setting can be overridden by each database connection using
1712 ** either the [PRAGMA mmap_size] command, or by using the
1713 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1714 ** cannot be changed at run-time. Nor may the maximum allowed mmap size
1715 ** exceed the compile-time maximum mmap size set by the
1716 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1717 ** ^If either argument to this option is negative, then that argument is
1718 ** changed to its compile-time default.
1719 **
1720 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1721 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1722 ** <dd>^This option is only available if SQLite is compiled for Windows
1723 ** with the [SQLITE_WIN32_MALLOC] pre-processor macro defined.
1724 ** SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1725 ** that specifies the maximum size of the created heap.
1726 ** </dl>
 
 
 
 
 
 
 
 
 
1727 */
1728 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1729 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1730 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1731 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1746,10 +1773,11 @@
1746 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1747 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1748 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1749 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1750 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
 
1751
1752 /*
1753 ** CAPI3REF: Database Connection Configuration Options
1754 **
1755 ** These constants are the available integer configuration options that
@@ -1873,51 +1901,49 @@
1873 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1874
1875 /*
1876 ** CAPI3REF: Count The Number Of Rows Modified
1877 **
1878 ** ^This function returns the number of database rows that were changed
1879 ** or inserted or deleted by the most recently completed SQL statement
1880 ** on the [database connection] specified by the first parameter.
1881 ** ^(Only changes that are directly specified by the [INSERT], [UPDATE],
1882 ** or [DELETE] statement are counted. Auxiliary changes caused by
1883 ** triggers or [foreign key actions] are not counted.)^ Use the
1884 ** [sqlite3_total_changes()] function to find the total number of changes
1885 ** including changes caused by triggers and foreign key actions.
1886 **
1887 ** ^Changes to a view that are simulated by an [INSTEAD OF trigger]
1888 ** are not counted. Only real table changes are counted.
1889 **
1890 ** ^(A "row change" is a change to a single row of a single table
1891 ** caused by an INSERT, DELETE, or UPDATE statement. Rows that
1892 ** are changed as side effects of [REPLACE] constraint resolution,
1893 ** rollback, ABORT processing, [DROP TABLE], or by any other
1894 ** mechanisms do not count as direct row changes.)^
1895 **
1896 ** A "trigger context" is a scope of execution that begins and
1897 ** ends with the script of a [CREATE TRIGGER | trigger].
1898 ** Most SQL statements are
1899 ** evaluated outside of any trigger. This is the "top level"
1900 ** trigger context. If a trigger fires from the top level, a
1901 ** new trigger context is entered for the duration of that one
1902 ** trigger. Subtriggers create subcontexts for their duration.
1903 **
1904 ** ^Calling [sqlite3_exec()] or [sqlite3_step()] recursively does
1905 ** not create a new trigger context.
1906 **
1907 ** ^This function returns the number of direct row changes in the
1908 ** most recent INSERT, UPDATE, or DELETE statement within the same
1909 ** trigger context.
1910 **
1911 ** ^Thus, when called from the top level, this function returns the
1912 ** number of changes in the most recent INSERT, UPDATE, or DELETE
1913 ** that also occurred at the top level. ^(Within the body of a trigger,
1914 ** the sqlite3_changes() interface can be called to find the number of
1915 ** changes in the most recently completed INSERT, UPDATE, or DELETE
1916 ** statement within the body of the same trigger.
1917 ** However, the number returned does not include changes
1918 ** caused by subtriggers since those have their own context.)^
1919 **
1920 ** See also the [sqlite3_total_changes()] interface, the
1921 ** [count_changes pragma], and the [changes() SQL function].
1922 **
1923 ** If a separate thread makes changes on the same database connection
@@ -1927,24 +1953,21 @@
1927 SQLITE_API int sqlite3_changes(sqlite3*);
1928
1929 /*
1930 ** CAPI3REF: Total Number Of Rows Modified
1931 **
1932 ** ^This function returns the number of row changes caused by [INSERT],
1933 ** [UPDATE] or [DELETE] statements since the [database connection] was opened.
1934 ** ^(The count returned by sqlite3_total_changes() includes all changes
1935 ** from all [CREATE TRIGGER | trigger] contexts and changes made by
1936 ** [foreign key actions]. However,
1937 ** the count does not include changes used to implement [REPLACE] constraints,
1938 ** do rollbacks or ABORT processing, or [DROP TABLE] processing. The
1939 ** count does not include rows of views that fire an [INSTEAD OF trigger],
1940 ** though if the INSTEAD OF trigger makes changes of its own, those changes
1941 ** are counted.)^
1942 ** ^The sqlite3_total_changes() function counts the changes as soon as
1943 ** the statement that makes them is completed (when the statement handle
1944 ** is passed to [sqlite3_reset()] or [sqlite3_finalize()]).
1945 **
1946 ** See also the [sqlite3_changes()] interface, the
1947 ** [count_changes pragma], and the [total_changes() SQL function].
1948 **
1949 ** If a separate thread makes changes on the same database connection
1950 ** while [sqlite3_total_changes()] is running then the value
@@ -2027,10 +2050,11 @@
2027 SQLITE_API int sqlite3_complete(const char *sql);
2028 SQLITE_API int sqlite3_complete16(const void *sql);
2029
2030 /*
2031 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
 
2032 **
2033 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2034 ** that might be invoked with argument P whenever
2035 ** an attempt is made to access a database table associated with
2036 ** [database connection] D when another thread
@@ -2043,11 +2067,11 @@
2043 ** is not NULL, then the callback might be invoked with two arguments.
2044 **
2045 ** ^The first argument to the busy handler is a copy of the void* pointer which
2046 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2047 ** the busy handler callback is the number of times that the busy handler has
2048 ** been invoked for the same locking event. ^If the
2049 ** busy callback returns 0, then no additional attempts are made to
2050 ** access the database and [SQLITE_BUSY] is returned
2051 ** to the application.
2052 ** ^If the callback returns non-zero, then another attempt
2053 ** is made to access the database and the cycle repeats.
@@ -2418,17 +2442,18 @@
2418 ** already uses the largest possible [ROWID]. The PRNG is also used for
2419 ** the build-in random() and randomblob() SQL functions. This interface allows
2420 ** applications to access the same PRNG for other purposes.
2421 **
2422 ** ^A call to this routine stores N bytes of randomness into buffer P.
2423 ** ^If N is less than one, then P can be a NULL pointer.
2424 **
2425 ** ^If this routine has not been previously called or if the previous
2426 ** call had N less than one, then the PRNG is seeded using randomness
2427 ** obtained from the xRandomness method of the default [sqlite3_vfs] object.
2428 ** ^If the previous call to this routine had an N of 1 or more then
2429 ** the pseudo-randomness is generated
 
2430 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2431 ** method.
2432 */
2433 SQLITE_API void sqlite3_randomness(int N, void *P);
2434
@@ -4146,13 +4171,13 @@
4146 ** CAPI3REF: Text Encodings
4147 **
4148 ** These constant define integer codes that represent the various
4149 ** text encodings supported by SQLite.
4150 */
4151 #define SQLITE_UTF8 1
4152 #define SQLITE_UTF16LE 2
4153 #define SQLITE_UTF16BE 3
4154 #define SQLITE_UTF16 4 /* Use native byte order */
4155 #define SQLITE_ANY 5 /* Deprecated */
4156 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4157
4158 /*
@@ -4497,11 +4522,12 @@
4497 ** If these routines are called from within the different thread
4498 ** than the one containing the application-defined function that received
4499 ** the [sqlite3_context] pointer, the results are undefined.
4500 */
4501 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4502 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void(*)(void*));
 
4503 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4504 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4505 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4506 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4507 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5129,24 +5155,31 @@
5129
5130
5131 /*
5132 ** CAPI3REF: Extract Metadata About A Column Of A Table
5133 **
5134 ** ^This routine returns metadata about a specific column of a specific
5135 ** database table accessible using the [database connection] handle
5136 ** passed as the first function argument.
 
 
 
 
 
 
 
 
5137 **
5138 ** ^The column is identified by the second, third and fourth parameters to
5139 ** this function. ^The second parameter is either the name of the database
5140 ** (i.e. "main", "temp", or an attached database) containing the specified
5141 ** table or NULL. ^If it is NULL, then all attached databases are searched
5142 ** for the table using the same algorithm used by the database engine to
5143 ** resolve unqualified table references.
5144 **
5145 ** ^The third and fourth parameters to this function are the table and column
5146 ** name of the desired column, respectively. Neither of these parameters
5147 ** may be NULL.
5148 **
5149 ** ^Metadata is returned by writing to the memory locations passed as the 5th
5150 ** and subsequent parameters to this function. ^Any of these arguments may be
5151 ** NULL, in which case the corresponding element of metadata is omitted.
5152 **
@@ -5161,36 +5194,33 @@
5161 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5162 ** </table>
5163 ** </blockquote>)^
5164 **
5165 ** ^The memory pointed to by the character pointers returned for the
5166 ** declaration type and collation sequence is valid only until the next
5167 ** call to any SQLite API function.
5168 **
5169 ** ^If the specified table is actually a view, an [error code] is returned.
5170 **
5171 ** ^If the specified column is "rowid", "oid" or "_rowid_" and an
 
5172 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5173 ** parameters are set for the explicitly declared column. ^(If there is no
5174 ** explicitly declared [INTEGER PRIMARY KEY] column, then the output
5175 ** parameters are set as follows:
5176 **
5177 ** <pre>
5178 ** data type: "INTEGER"
5179 ** collation sequence: "BINARY"
5180 ** not null: 0
5181 ** primary key: 1
5182 ** auto increment: 0
5183 ** </pre>)^
5184 **
5185 ** ^(This function may load one or more schemas from database files. If an
5186 ** error occurs during this process, or if the requested table or column
5187 ** cannot be found, an [error code] is returned and an error message left
5188 ** in the [database connection] (to be retrieved using sqlite3_errmsg()).)^
5189 **
5190 ** ^This API is only available if the library was compiled with the
5191 ** [SQLITE_ENABLE_COLUMN_METADATA] C-preprocessor symbol defined.
5192 */
5193 SQLITE_API int sqlite3_table_column_metadata(
5194 sqlite3 *db, /* Connection handle */
5195 const char *zDbName, /* Database name or NULL */
5196 const char *zTableName, /* Table name */
@@ -5638,31 +5668,47 @@
5638 ** in other words, the same BLOB that would be selected by:
5639 **
5640 ** <pre>
5641 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5642 ** </pre>)^
 
 
 
 
 
 
5643 **
5644 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5645 ** and write access. ^If it is zero, the BLOB is opened for read access.
5646 ** ^It is not possible to open a column that is part of an index or primary
5647 ** key for writing. ^If [foreign key constraints] are enabled, it is
5648 ** not possible to open a column that is part of a [child key] for writing.
5649 **
5650 ** ^Note that the database name is not the filename that contains
5651 ** the database but rather the symbolic name of the database that
5652 ** appears after the AS keyword when the database is connected using [ATTACH].
5653 ** ^For the main database file, the database name is "main".
5654 ** ^For TEMP tables, the database name is "temp".
5655 **
5656 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is written
5657 ** to *ppBlob. Otherwise an [error code] is returned and *ppBlob is set
5658 ** to be a null pointer.)^
5659 ** ^This function sets the [database connection] error code and message
5660 ** accessible via [sqlite3_errcode()] and [sqlite3_errmsg()] and related
5661 ** functions. ^Note that the *ppBlob variable is always initialized in a
5662 ** way that makes it safe to invoke [sqlite3_blob_close()] on *ppBlob
5663 ** regardless of the success or failure of this routine.
 
 
 
 
 
 
 
 
 
 
5664 **
5665 ** ^(If the row that a BLOB handle points to is modified by an
5666 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5667 ** then the BLOB handle is marked as "expired".
5668 ** This is true if any column of the row is changed, even a column
@@ -5676,17 +5722,13 @@
5676 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5677 ** the opened blob. ^The size of a blob may not be changed by this
5678 ** interface. Use the [UPDATE] SQL command to change the size of a
5679 ** blob.
5680 **
5681 ** ^The [sqlite3_blob_open()] interface will fail for a [WITHOUT ROWID]
5682 ** table. Incremental BLOB I/O is not possible on [WITHOUT ROWID] tables.
5683 **
5684 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5685 ** and the built-in [zeroblob] SQL function can be used, if desired,
5686 ** to create an empty, zero-filled blob in which to read or write using
5687 ** this interface.
5688 **
5689 ** To avoid a resource leak, every open [BLOB handle] should eventually
5690 ** be released by a call to [sqlite3_blob_close()].
5691 */
5692 SQLITE_API int sqlite3_blob_open(
@@ -5724,28 +5766,26 @@
5724 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5725
5726 /*
5727 ** CAPI3REF: Close A BLOB Handle
5728 **
5729 ** ^Closes an open [BLOB handle].
5730 **
5731 ** ^Closing a BLOB shall cause the current transaction to commit
5732 ** if there are no other BLOBs, no pending prepared statements, and the
5733 ** database connection is in [autocommit mode].
5734 ** ^If any writes were made to the BLOB, they might be held in cache
5735 ** until the close operation if they will fit.
5736 **
5737 ** ^(Closing the BLOB often forces the changes
5738 ** out to disk and so if any I/O errors occur, they will likely occur
5739 ** at the time when the BLOB is closed. Any errors that occur during
5740 ** closing are reported as a non-zero return value.)^
5741 **
5742 ** ^(The BLOB is closed unconditionally. Even if this routine returns
5743 ** an error code, the BLOB is still closed.)^
5744 **
5745 ** ^Calling this routine with a null pointer (such as would be returned
5746 ** by a failed call to [sqlite3_blob_open()]) is a harmless no-op.
5747 */
5748 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5749
5750 /*
5751 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5791,36 +5831,39 @@
5791 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5792
5793 /*
5794 ** CAPI3REF: Write Data Into A BLOB Incrementally
5795 **
5796 ** ^This function is used to write data into an open [BLOB handle] from a
5797 ** caller-supplied buffer. ^N bytes of data are copied from the buffer Z
5798 ** into the open BLOB, starting at offset iOffset.
 
 
 
 
 
 
5799 **
5800 ** ^If the [BLOB handle] passed as the first argument was not opened for
5801 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5802 ** this function returns [SQLITE_READONLY].
5803 **
5804 ** ^This function may only modify the contents of the BLOB; it is
5805 ** not possible to increase the size of a BLOB using this API.
5806 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5807 ** [SQLITE_ERROR] is returned and no data is written. ^If N is
5808 ** less than zero [SQLITE_ERROR] is returned and no data is written.
5809 ** The size of the BLOB (and hence the maximum value of N+iOffset)
5810 ** can be determined using the [sqlite3_blob_bytes()] interface.
5811 **
5812 ** ^An attempt to write to an expired [BLOB handle] fails with an
5813 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5814 ** before the [BLOB handle] expired are not rolled back by the
5815 ** expiration of the handle, though of course those changes might
5816 ** have been overwritten by the statement that expired the BLOB handle
5817 ** or by other independent statements.
5818 **
5819 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5820 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5821 **
5822 ** This routine only works on a [BLOB handle] which has been created
5823 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5824 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5825 ** to this routine results in undefined and probably undesirable behavior.
5826 **
@@ -5869,38 +5912,38 @@
5869 ** use by SQLite, code that links against SQLite is
5870 ** permitted to use any of these routines.
5871 **
5872 ** The SQLite source code contains multiple implementations
5873 ** of these mutex routines. An appropriate implementation
5874 ** is selected automatically at compile-time. ^(The following
5875 ** implementations are available in the SQLite core:
5876 **
5877 ** <ul>
5878 ** <li> SQLITE_MUTEX_PTHREADS
5879 ** <li> SQLITE_MUTEX_W32
5880 ** <li> SQLITE_MUTEX_NOOP
5881 ** </ul>)^
5882 **
5883 ** ^The SQLITE_MUTEX_NOOP implementation is a set of routines
5884 ** that does no real locking and is appropriate for use in
5885 ** a single-threaded application. ^The SQLITE_MUTEX_PTHREADS and
5886 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
5887 ** and Windows.
5888 **
5889 ** ^(If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5890 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
5891 ** implementation is included with the library. In this case the
5892 ** application must supply a custom mutex implementation using the
5893 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
5894 ** before calling sqlite3_initialize() or any other public sqlite3_
5895 ** function that calls sqlite3_initialize().)^
5896 **
5897 ** ^The sqlite3_mutex_alloc() routine allocates a new
5898 ** mutex and returns a pointer to it. ^If it returns NULL
5899 ** that means that a mutex could not be allocated. ^SQLite
5900 ** will unwind its stack and return an error. ^(The argument
5901 ** to sqlite3_mutex_alloc() is one of these integer constants:
5902 **
5903 ** <ul>
5904 ** <li> SQLITE_MUTEX_FAST
5905 ** <li> SQLITE_MUTEX_RECURSIVE
5906 ** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -5909,68 +5952,64 @@
5909 ** <li> SQLITE_MUTEX_STATIC_PRNG
5910 ** <li> SQLITE_MUTEX_STATIC_LRU
5911 ** <li> SQLITE_MUTEX_STATIC_PMEM
5912 ** <li> SQLITE_MUTEX_STATIC_APP1
5913 ** <li> SQLITE_MUTEX_STATIC_APP2
5914 ** </ul>)^
 
5915 **
5916 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5917 ** cause sqlite3_mutex_alloc() to create
5918 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
5919 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
5920 ** The mutex implementation does not need to make a distinction
5921 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
5922 ** not want to. ^SQLite will only request a recursive mutex in
5923 ** cases where it really needs one. ^If a faster non-recursive mutex
5924 ** implementation is available on the host platform, the mutex subsystem
5925 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
5926 **
5927 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
5928 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
5929 ** a pointer to a static preexisting mutex. ^Six static mutexes are
5930 ** used by the current version of SQLite. Future versions of SQLite
5931 ** may add additional static mutexes. Static mutexes are for internal
5932 ** use by SQLite only. Applications that use SQLite mutexes should
5933 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
5934 ** SQLITE_MUTEX_RECURSIVE.
5935 **
5936 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
5937 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
5938 ** returns a different mutex on every call. ^But for the static
5939 ** mutex types, the same mutex is returned on every call that has
5940 ** the same type number.
5941 **
5942 ** ^The sqlite3_mutex_free() routine deallocates a previously
5943 ** allocated dynamic mutex. ^SQLite is careful to deallocate every
5944 ** dynamic mutex that it allocates. The dynamic mutexes must not be in
5945 ** use when they are deallocated. Attempting to deallocate a static
5946 ** mutex results in undefined behavior. ^SQLite never deallocates
5947 ** a static mutex.
5948 **
5949 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
5950 ** to enter a mutex. ^If another thread is already within the mutex,
5951 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
5952 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
5953 ** upon successful entry. ^(Mutexes created using
5954 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
5955 ** In such cases the,
5956 ** mutex must be exited an equal number of times before another thread
5957 ** can enter.)^ ^(If the same thread tries to enter any other
5958 ** kind of mutex more than once, the behavior is undefined.
5959 ** SQLite will never exhibit
5960 ** such behavior in its own use of mutexes.)^
5961 **
5962 ** ^(Some systems (for example, Windows 95) do not support the operation
5963 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
5964 ** will always return SQLITE_BUSY. The SQLite core only ever uses
5965 ** sqlite3_mutex_try() as an optimization so this is acceptable behavior.)^
 
5966 **
5967 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
5968 ** previously entered by the same thread. ^(The behavior
5969 ** is undefined if the mutex is not currently entered by the
5970 ** calling thread or is not currently allocated. SQLite will
5971 ** never do either.)^
5972 **
5973 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
5974 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
5975 ** behave as no-ops.
5976 **
@@ -5987,13 +6026,13 @@
5987 **
5988 ** An instance of this structure defines the low-level routines
5989 ** used to allocate and use mutexes.
5990 **
5991 ** Usually, the default mutex implementations provided by SQLite are
5992 ** sufficient, however the user has the option of substituting a custom
5993 ** implementation for specialized deployments or systems for which SQLite
5994 ** does not provide a suitable implementation. In this case, the user
5995 ** creates and populates an instance of this structure to pass
5996 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
5997 ** Additionally, an instance of this structure can be used as an
5998 ** output variable when querying the system for the current mutex
5999 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6030,17 +6069,17 @@
6030 ** by this structure are not required to handle this case, the results
6031 ** of passing a NULL pointer instead of a valid mutex handle are undefined
6032 ** (i.e. it is acceptable to provide an implementation that segfaults if
6033 ** it is passed a NULL pointer).
6034 **
6035 ** The xMutexInit() method must be threadsafe. ^It must be harmless to
6036 ** invoke xMutexInit() multiple times within the same process and without
6037 ** intervening calls to xMutexEnd(). Second and subsequent calls to
6038 ** xMutexInit() must be no-ops.
6039 **
6040 ** ^xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6041 ** and its associates). ^Similarly, xMutexAlloc() must not use SQLite memory
6042 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
6043 ** memory allocation for a fast or recursive mutex.
6044 **
6045 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
6046 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6062,33 +6101,33 @@
6062
6063 /*
6064 ** CAPI3REF: Mutex Verification Routines
6065 **
6066 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6067 ** are intended for use inside assert() statements. ^The SQLite core
6068 ** never uses these routines except inside an assert() and applications
6069 ** are advised to follow the lead of the core. ^The SQLite core only
6070 ** provides implementations for these routines when it is compiled
6071 ** with the SQLITE_DEBUG flag. ^External mutex implementations
6072 ** are only required to provide these routines if SQLITE_DEBUG is
6073 ** defined and if NDEBUG is not defined.
6074 **
6075 ** ^These routines should return true if the mutex in their argument
6076 ** is held or not held, respectively, by the calling thread.
6077 **
6078 ** ^The implementation is not required to provide versions of these
6079 ** routines that actually work. If the implementation does not provide working
6080 ** versions of these routines, it should at least provide stubs that always
6081 ** return true so that one does not get spurious assertion failures.
6082 **
6083 ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
6084 ** the routine should return 1. This seems counter-intuitive since
6085 ** clearly the mutex cannot be held if it does not exist. But
6086 ** the reason the mutex does not exist is because the build is not
6087 ** using mutexes. And we do not want the assert() containing the
6088 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
6089 ** the appropriate thing to do. ^The sqlite3_mutex_notheld()
6090 ** interface should also return 1 when given a NULL pointer.
6091 */
6092 #ifndef NDEBUG
6093 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
6094 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6816,10 +6855,14 @@
6816 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6817 ** and database name of the source database, respectively.
6818 ** ^The source and destination [database connections] (parameters S and D)
6819 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6820 ** an error.
 
 
 
 
6821 **
6822 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6823 ** returned and an error code and error message are stored in the
6824 ** destination [database connection] D.
6825 ** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7210,101 +7253,118 @@
7210 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7211
7212 /*
7213 ** CAPI3REF: Checkpoint a database
7214 **
7215 ** ^The [sqlite3_wal_checkpoint(D,X)] interface causes database named X
7216 ** on [database connection] D to be [checkpointed]. ^If X is NULL or an
7217 ** empty string, then a checkpoint is run on all databases of
7218 ** connection D. ^If the database connection D is not in
7219 ** [WAL | write-ahead log mode] then this interface is a harmless no-op.
7220 ** ^The [sqlite3_wal_checkpoint(D,X)] interface initiates a
7221 ** [sqlite3_wal_checkpoint_v2|PASSIVE] checkpoint.
7222 ** Use the [sqlite3_wal_checkpoint_v2()] interface to get a FULL
7223 ** or RESET checkpoint.
7224 **
7225 ** ^The [wal_checkpoint pragma] can be used to invoke this interface
7226 ** from SQL. ^The [sqlite3_wal_autocheckpoint()] interface and the
7227 ** [wal_autocheckpoint pragma] can be used to cause this interface to be
7228 ** run whenever the WAL reaches a certain size threshold.
7229 **
7230 ** See also: [sqlite3_wal_checkpoint_v2()]
7231 */
7232 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7233
7234 /*
7235 ** CAPI3REF: Checkpoint a database
7236 **
7237 ** Run a checkpoint operation on WAL database zDb attached to database
7238 ** handle db. The specific operation is determined by the value of the
7239 ** eMode parameter:
 
7240 **
7241 ** <dl>
7242 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7243 ** Checkpoint as many frames as possible without waiting for any database
7244 ** readers or writers to finish. Sync the db file if all frames in the log
7245 ** are checkpointed. This mode is the same as calling
7246 ** sqlite3_wal_checkpoint(). The [sqlite3_busy_handler|busy-handler callback]
7247 ** is never invoked.
 
7248 **
7249 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7250 ** This mode blocks (it invokes the
7251 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7252 ** database writer and all readers are reading from the most recent database
7253 ** snapshot. It then checkpoints all frames in the log file and syncs the
7254 ** database file. This call blocks database writers while it is running,
7255 ** but not database readers.
7256 **
7257 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7258 ** This mode works the same way as SQLITE_CHECKPOINT_FULL, except after
7259 ** checkpointing the log file it blocks (calls the
7260 ** [sqlite3_busy_handler|busy-handler callback])
7261 ** until all readers are reading from the database file only. This ensures
7262 ** that the next client to write to the database file restarts the log file
7263 ** from the beginning. This call blocks database writers while it is running,
7264 ** but not database readers.
 
 
 
 
 
7265 ** </dl>
7266 **
7267 ** If pnLog is not NULL, then *pnLog is set to the total number of frames in
7268 ** the log file before returning. If pnCkpt is not NULL, then *pnCkpt is set to
7269 ** the total number of checkpointed frames (including any that were already
7270 ** checkpointed when this function is called). *pnLog and *pnCkpt may be
7271 ** populated even if sqlite3_wal_checkpoint_v2() returns other than SQLITE_OK.
7272 ** If no values are available because of an error, they are both set to -1
7273 ** before returning to communicate this to the caller.
 
 
7274 **
7275 ** All calls obtain an exclusive "checkpoint" lock on the database file. If
7276 ** any other process is running a checkpoint operation at the same time, the
7277 ** lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a
7278 ** busy-handler configured, it will not be invoked in this case.
7279 **
7280 ** The SQLITE_CHECKPOINT_FULL and RESTART modes also obtain the exclusive
7281 ** "writer" lock on the database file. If the writer lock cannot be obtained
7282 ** immediately, and a busy-handler is configured, it is invoked and the writer
7283 ** lock retried until either the busy-handler returns 0 or the lock is
7284 ** successfully obtained. The busy-handler is also invoked while waiting for
7285 ** database readers as described above. If the busy-handler returns 0 before
7286 ** the writer lock is obtained or while waiting for database readers, the
7287 ** checkpoint operation proceeds from that point in the same way as
7288 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7289 ** without blocking any further. SQLITE_BUSY is returned in this case.
7290 **
7291 ** If parameter zDb is NULL or points to a zero length string, then the
7292 ** specified operation is attempted on all WAL databases. In this case the
7293 ** values written to output parameters *pnLog and *pnCkpt are undefined. If
 
7294 ** an SQLITE_BUSY error is encountered when processing one or more of the
7295 ** attached WAL databases, the operation is still attempted on any remaining
7296 ** attached databases and SQLITE_BUSY is returned to the caller. If any other
7297 ** error occurs while processing an attached database, processing is abandoned
7298 ** and the error code returned to the caller immediately. If no error
7299 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
7300 ** databases, SQLITE_OK is returned.
7301 **
7302 ** If database zDb is the name of an attached database that is not in WAL
7303 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. If
7304 ** zDb is not NULL (or a zero length string) and is not the name of any
7305 ** attached database, SQLITE_ERROR is returned to the caller.
 
 
 
 
 
 
 
 
7306 */
7307 SQLITE_API int sqlite3_wal_checkpoint_v2(
7308 sqlite3 *db, /* Database handle */
7309 const char *zDb, /* Name of attached database (or NULL) */
7310 int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7311,20 +7371,22 @@
7311 int *pnLog, /* OUT: Size of WAL log in frames */
7312 int *pnCkpt /* OUT: Total number of frames checkpointed */
7313 );
7314
7315 /*
7316 ** CAPI3REF: Checkpoint operation parameters
 
7317 **
7318 ** These constants can be used as the 3rd parameter to
7319 ** [sqlite3_wal_checkpoint_v2()]. See the [sqlite3_wal_checkpoint_v2()]
7320 ** documentation for additional information about the meaning and use of
7321 ** each of these values.
7322 */
7323 #define SQLITE_CHECKPOINT_PASSIVE 0
7324 #define SQLITE_CHECKPOINT_FULL 1
7325 #define SQLITE_CHECKPOINT_RESTART 2
 
7326
7327 /*
7328 ** CAPI3REF: Virtual Table Interface Configuration
7329 **
7330 ** This function may be called by either the [xConnect] or [xCreate] method
@@ -7409,10 +7471,102 @@
7409 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7410 #define SQLITE_FAIL 3
7411 /* #define SQLITE_ABORT 4 // Also an error code */
7412 #define SQLITE_REPLACE 5
7413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7414
7415
7416 /*
7417 ** Undo the hack that converts floating point types to integer for
7418 ** builds on processors without floating point support.
7419
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -55,11 +55,11 @@
55
56
57 /*
58 ** These no-op macros are used in front of interfaces to mark those
59 ** interfaces as either deprecated or experimental. New applications
60 ** should not use deprecated interfaces - they are supported for backwards
61 ** compatibility only. Application writers should be aware that
62 ** experimental interfaces are subject to change in point releases.
63 **
64 ** These macros used to resolve to various kinds of compiler magic that
65 ** would generate warning messages when they were used. But that
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.8"
111 #define SQLITE_VERSION_NUMBER 3008008
112 #define SQLITE_SOURCE_ID "2014-12-10 04:58:43 3528f8dd39acace8eeb7337994c8617313f4b04b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -1219,11 +1219,11 @@
1219 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED
1220 ** <li> SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE
1221 ** </ul>
1222 **
1223 ** When unlocking, the same SHARED or EXCLUSIVE flag must be supplied as
1224 ** was given on the corresponding lock.
1225 **
1226 ** The xShmLock method can transition between unlocked and SHARED or
1227 ** between unlocked and EXCLUSIVE. It cannot transition between SHARED
1228 ** and EXCLUSIVE.
1229 */
@@ -1502,30 +1502,32 @@
1502 ** it is not possible to set the Serialized [threading mode] and
1503 ** [sqlite3_config()] will return [SQLITE_ERROR] if called with the
1504 ** SQLITE_CONFIG_SERIALIZED configuration option.</dd>
1505 **
1506 ** [[SQLITE_CONFIG_MALLOC]] <dt>SQLITE_CONFIG_MALLOC</dt>
1507 ** <dd> ^(The SQLITE_CONFIG_MALLOC option takes a single argument which is
1508 ** a pointer to an instance of the [sqlite3_mem_methods] structure.
1509 ** The argument specifies
1510 ** alternative low-level memory allocation routines to be used in place of
1511 ** the memory allocation routines built into SQLite.)^ ^SQLite makes
1512 ** its own private copy of the content of the [sqlite3_mem_methods] structure
1513 ** before the [sqlite3_config()] call returns.</dd>
1514 **
1515 ** [[SQLITE_CONFIG_GETMALLOC]] <dt>SQLITE_CONFIG_GETMALLOC</dt>
1516 ** <dd> ^(The SQLITE_CONFIG_GETMALLOC option takes a single argument which
1517 ** is a pointer to an instance of the [sqlite3_mem_methods] structure.
1518 ** The [sqlite3_mem_methods]
1519 ** structure is filled with the currently defined memory allocation routines.)^
1520 ** This option can be used to overload the default memory allocation
1521 ** routines with a wrapper that simulations memory allocation failure or
1522 ** tracks memory usage, for example. </dd>
1523 **
1524 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1525 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1526 ** interpreted as a boolean, which enables or disables the collection of
1527 ** memory allocation statistics. ^(When memory allocation statistics are
1528 ** disabled, the following SQLite interfaces become non-operational:
1529 ** <ul>
1530 ** <li> [sqlite3_memory_used()]
1531 ** <li> [sqlite3_memory_highwater()]
1532 ** <li> [sqlite3_soft_heap_limit64()]
1533 ** <li> [sqlite3_status()]
@@ -1534,78 +1536,92 @@
1536 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1537 ** allocation statistics are disabled by default.
1538 ** </dd>
1539 **
1540 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1541 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1542 ** that SQLite can use for scratch memory. ^(There are three arguments
1543 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1544 ** aligned memory buffer from which the scratch allocations will be
1545 ** drawn, the size of each scratch allocation (sz),
1546 ** and the maximum number of scratch allocations (N).)^
 
1547 ** The first argument must be a pointer to an 8-byte aligned buffer
1548 ** of at least sz*N bytes of memory.
1549 ** ^SQLite will not use more than one scratch buffers per thread.
1550 ** ^SQLite will never request a scratch buffer that is more than 6
1551 ** times the database page size.
1552 ** ^If SQLite needs needs additional
1553 ** scratch memory beyond what is provided by this configuration option, then
1554 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1555 ** ^When the application provides any amount of scratch memory using
1556 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1557 ** [sqlite3_malloc|heap allocations].
1558 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1559 ** fragmentation in low-memory embedded systems.
1560 ** </dd>
1561 **
1562 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1563 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a static memory buffer
1564 ** that SQLite can use for the database page cache with the default page
1565 ** cache implementation.
1566 ** This configuration should not be used if an application-define page
1567 ** cache implementation is loaded using the [SQLITE_CONFIG_PCACHE2]
1568 ** configuration option.
1569 ** ^There are three arguments to SQLITE_CONFIG_PAGECACHE: A pointer to
1570 ** 8-byte aligned
1571 ** memory, the size of each page buffer (sz), and the number of pages (N).
1572 ** The sz argument should be the size of the largest database page
1573 ** (a power of two between 512 and 32768) plus some extra bytes for each
1574 ** page header. ^The number of extra bytes needed by the page header
1575 ** can be determined using the [SQLITE_CONFIG_PCACHE_HDRSZ] option
1576 ** to [sqlite3_config()].
1577 ** ^It is harmless, apart from the wasted memory,
1578 ** for the sz parameter to be larger than necessary. The first
1579 ** argument should pointer to an 8-byte aligned block of memory that
1580 ** is at least sz*N bytes of memory, otherwise subsequent behavior is
1581 ** undefined.
1582 ** ^SQLite will use the memory provided by the first argument to satisfy its
1583 ** memory needs for the first N pages that it adds to cache. ^If additional
1584 ** page cache memory is needed beyond what is provided by this option, then
1585 ** SQLite goes to [sqlite3_malloc()] for the additional storage space.</dd>
 
 
 
1586 **
1587 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1588 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1589 ** that SQLite will use for all of its dynamic memory allocation needs
1590 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1591 ** [SQLITE_CONFIG_PAGECACHE].
1592 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1593 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1594 ** [SQLITE_ERROR] if invoked otherwise.
1595 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1596 ** An 8-byte aligned pointer to the memory,
1597 ** the number of bytes in the memory buffer, and the minimum allocation size.
1598 ** ^If the first pointer (the memory pointer) is NULL, then SQLite reverts
1599 ** to using its default memory allocator (the system malloc() implementation),
1600 ** undoing any prior invocation of [SQLITE_CONFIG_MALLOC]. ^If the
1601 ** memory pointer is not NULL then the alternative memory
 
1602 ** allocator is engaged to handle all of SQLites memory allocation needs.
1603 ** The first pointer (the memory pointer) must be aligned to an 8-byte
1604 ** boundary or subsequent behavior of SQLite will be undefined.
1605 ** The minimum allocation size is capped at 2**12. Reasonable values
1606 ** for the minimum allocation size are 2**5 through 2**8.</dd>
1607 **
1608 ** [[SQLITE_CONFIG_MUTEX]] <dt>SQLITE_CONFIG_MUTEX</dt>
1609 ** <dd> ^(The SQLITE_CONFIG_MUTEX option takes a single argument which is a
1610 ** pointer to an instance of the [sqlite3_mutex_methods] structure.
1611 ** The argument specifies alternative low-level mutex routines to be used
1612 ** in place the mutex routines built into SQLite.)^ ^SQLite makes a copy of
1613 ** the content of the [sqlite3_mutex_methods] structure before the call to
1614 ** [sqlite3_config()] returns. ^If SQLite is compiled with
1615 ** the [SQLITE_THREADSAFE | SQLITE_THREADSAFE=0] compile-time option then
1616 ** the entire mutexing subsystem is omitted from the build and hence calls to
1617 ** [sqlite3_config()] with the SQLITE_CONFIG_MUTEX configuration option will
1618 ** return [SQLITE_ERROR].</dd>
1619 **
1620 ** [[SQLITE_CONFIG_GETMUTEX]] <dt>SQLITE_CONFIG_GETMUTEX</dt>
1621 ** <dd> ^(The SQLITE_CONFIG_GETMUTEX option takes a single argument which
1622 ** is a pointer to an instance of the [sqlite3_mutex_methods] structure. The
1623 ** [sqlite3_mutex_methods]
1624 ** structure is filled with the currently defined mutex routines.)^
1625 ** This option can be used to overload the default mutex allocation
1626 ** routines with a wrapper used to track mutex usage for performance
1627 ** profiling or testing, for example. ^If SQLite is compiled with
@@ -1613,29 +1629,29 @@
1629 ** the entire mutexing subsystem is omitted from the build and hence calls to
1630 ** [sqlite3_config()] with the SQLITE_CONFIG_GETMUTEX configuration option will
1631 ** return [SQLITE_ERROR].</dd>
1632 **
1633 ** [[SQLITE_CONFIG_LOOKASIDE]] <dt>SQLITE_CONFIG_LOOKASIDE</dt>
1634 ** <dd> ^(The SQLITE_CONFIG_LOOKASIDE option takes two arguments that determine
1635 ** the default size of lookaside memory on each [database connection].
1636 ** The first argument is the
1637 ** size of each lookaside buffer slot and the second is the number of
1638 ** slots allocated to each database connection.)^ ^(SQLITE_CONFIG_LOOKASIDE
1639 ** sets the <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
1640 ** option to [sqlite3_db_config()] can be used to change the lookaside
1641 ** configuration on individual connections.)^ </dd>
1642 **
1643 ** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
1644 ** <dd> ^(The SQLITE_CONFIG_PCACHE2 option takes a single argument which is
1645 ** a pointer to an [sqlite3_pcache_methods2] object. This object specifies
1646 ** the interface to a custom page cache implementation.)^
1647 ** ^SQLite makes a copy of the [sqlite3_pcache_methods2] object.</dd>
1648 **
1649 ** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
1650 ** <dd> ^(The SQLITE_CONFIG_GETPCACHE2 option takes a single argument which
1651 ** is a pointer to an [sqlite3_pcache_methods2] object. SQLite copies of
1652 ** the current page cache implementation into that object.)^ </dd>
1653 **
1654 ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
1655 ** <dd> The SQLITE_CONFIG_LOG option is used to configure the SQLite
1656 ** global [error log].
1657 ** (^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
@@ -1654,26 +1670,28 @@
1670 ** supplied by the application must not invoke any SQLite interface.
1671 ** In a multi-threaded application, the application-defined logger
1672 ** function must be threadsafe. </dd>
1673 **
1674 ** [[SQLITE_CONFIG_URI]] <dt>SQLITE_CONFIG_URI
1675 ** <dd>^(The SQLITE_CONFIG_URI option takes a single argument of type int.
1676 ** If non-zero, then URI handling is globally enabled. If the parameter is zero,
1677 ** then URI handling is globally disabled.)^ ^If URI handling is globally
1678 ** enabled, all filenames passed to [sqlite3_open()], [sqlite3_open_v2()],
1679 ** [sqlite3_open16()] or
1680 ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
1681 ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
1682 ** connection is opened. ^If it is globally disabled, filenames are
1683 ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
1684 ** database connection is opened. ^(By default, URI handling is globally
1685 ** disabled. The default value may be changed by compiling with the
1686 ** [SQLITE_USE_URI] symbol defined.)^
1687 **
1688 ** [[SQLITE_CONFIG_COVERING_INDEX_SCAN]] <dt>SQLITE_CONFIG_COVERING_INDEX_SCAN
1689 ** <dd>^The SQLITE_CONFIG_COVERING_INDEX_SCAN option takes a single integer
1690 ** argument which is interpreted as a boolean in order to enable or disable
1691 ** the use of covering indices for full table scans in the query optimizer.
1692 ** ^The default setting is determined
1693 ** by the [SQLITE_ALLOW_COVERING_INDEX_SCAN] compile-time option, or is "on"
1694 ** if that compile-time option is omitted.
1695 ** The ability to disable the use of covering indices for full table scans
1696 ** is because some incorrectly coded legacy applications might malfunction
1697 ** when the optimization is enabled. Providing the ability to
@@ -1709,23 +1727,32 @@
1727 ** that are the default mmap size limit (the default setting for
1728 ** [PRAGMA mmap_size]) and the maximum allowed mmap size limit.
1729 ** ^The default setting can be overridden by each database connection using
1730 ** either the [PRAGMA mmap_size] command, or by using the
1731 ** [SQLITE_FCNTL_MMAP_SIZE] file control. ^(The maximum allowed mmap size
1732 ** will be silently truncated if necessary so that it does not exceed the
1733 ** compile-time maximum mmap size set by the
1734 ** [SQLITE_MAX_MMAP_SIZE] compile-time option.)^
1735 ** ^If either argument to this option is negative, then that argument is
1736 ** changed to its compile-time default.
1737 **
1738 ** [[SQLITE_CONFIG_WIN32_HEAPSIZE]]
1739 ** <dt>SQLITE_CONFIG_WIN32_HEAPSIZE
1740 ** <dd>^The SQLITE_CONFIG_WIN32_HEAPSIZE option is only available if SQLite is
1741 ** compiled for Windows with the [SQLITE_WIN32_MALLOC] pre-processor macro
1742 ** defined. ^SQLITE_CONFIG_WIN32_HEAPSIZE takes a 32-bit unsigned integer value
1743 ** that specifies the maximum size of the created heap.
1744 ** </dl>
1745 **
1746 ** [[SQLITE_CONFIG_PCACHE_HDRSZ]]
1747 ** <dt>SQLITE_CONFIG_PCACHE_HDRSZ
1748 ** <dd>^The SQLITE_CONFIG_PCACHE_HDRSZ option takes a single parameter which
1749 ** is a pointer to an integer and writes into that integer the number of extra
1750 ** bytes per page required for each page in [SQLITE_CONFIG_PAGECACHE].
1751 ** The amount of extra space required can change depending on the compiler,
1752 ** target platform, and SQLite version.
1753 ** </dl>
1754 */
1755 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1756 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1757 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1758 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
@@ -1746,10 +1773,11 @@
1773 #define SQLITE_CONFIG_GETPCACHE2 19 /* sqlite3_pcache_methods2* */
1774 #define SQLITE_CONFIG_COVERING_INDEX_SCAN 20 /* int */
1775 #define SQLITE_CONFIG_SQLLOG 21 /* xSqllog, void* */
1776 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1777 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1778 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1779
1780 /*
1781 ** CAPI3REF: Database Connection Configuration Options
1782 **
1783 ** These constants are the available integer configuration options that
@@ -1873,51 +1901,49 @@
1901 SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
1902
1903 /*
1904 ** CAPI3REF: Count The Number Of Rows Modified
1905 **
1906 ** ^This function returns the number of rows modified, inserted or
1907 ** deleted by the most recently completed INSERT, UPDATE or DELETE
1908 ** statement on the database connection specified by the only parameter.
1909 ** ^Executing any other type of SQL statement does not modify the value
1910 ** returned by this function.
1911 **
1912 ** ^Only changes made directly by the INSERT, UPDATE or DELETE statement are
1913 ** considered - auxiliary changes caused by [CREATE TRIGGER | triggers],
1914 ** [foreign key actions] or [REPLACE] constraint resolution are not counted.
1915 **
1916 ** Changes to a view that are intercepted by
1917 ** [INSTEAD OF trigger | INSTEAD OF triggers] are not counted. ^The value
1918 ** returned by sqlite3_changes() immediately after an INSERT, UPDATE or
1919 ** DELETE statement run on a view is always zero. Only changes made to real
1920 ** tables are counted.
1921 **
1922 ** Things are more complicated if the sqlite3_changes() function is
1923 ** executed while a trigger program is running. This may happen if the
1924 ** program uses the [changes() SQL function], or if some other callback
1925 ** function invokes sqlite3_changes() directly. Essentially:
1926 **
1927 ** <ul>
1928 ** <li> ^(Before entering a trigger program the value returned by
1929 ** sqlite3_changes() function is saved. After the trigger program
1930 ** has finished, the original value is restored.)^
1931 **
1932 ** <li> ^(Within a trigger program each INSERT, UPDATE and DELETE
1933 ** statement sets the value returned by sqlite3_changes()
1934 ** upon completion as normal. Of course, this value will not include
1935 ** any changes performed by sub-triggers, as the sqlite3_changes()
1936 ** value will be saved and restored after each sub-trigger has run.)^
1937 ** </ul>
1938 **
1939 ** ^This means that if the changes() SQL function (or similar) is used
1940 ** by the first INSERT, UPDATE or DELETE statement within a trigger, it
1941 ** returns the value as set when the calling statement began executing.
1942 ** ^If it is used by the second or subsequent such statement within a trigger
1943 ** program, the value returned reflects the number of rows modified by the
1944 ** previous INSERT, UPDATE or DELETE statement within the same trigger.
 
 
1945 **
1946 ** See also the [sqlite3_total_changes()] interface, the
1947 ** [count_changes pragma], and the [changes() SQL function].
1948 **
1949 ** If a separate thread makes changes on the same database connection
@@ -1927,24 +1953,21 @@
1953 SQLITE_API int sqlite3_changes(sqlite3*);
1954
1955 /*
1956 ** CAPI3REF: Total Number Of Rows Modified
1957 **
1958 ** ^This function returns the total number of rows inserted, modified or
1959 ** deleted by all [INSERT], [UPDATE] or [DELETE] statements completed
1960 ** since the database connection was opened, including those executed as
1961 ** part of trigger programs. ^Executing any other type of SQL statement
1962 ** does not affect the value returned by sqlite3_total_changes().
1963 **
1964 ** ^Changes made as part of [foreign key actions] are included in the
1965 ** count, but those made as part of REPLACE constraint resolution are
1966 ** not. ^Changes to a view that are intercepted by INSTEAD OF triggers
1967 ** are not counted.
1968 **
 
 
 
1969 ** See also the [sqlite3_changes()] interface, the
1970 ** [count_changes pragma], and the [total_changes() SQL function].
1971 **
1972 ** If a separate thread makes changes on the same database connection
1973 ** while [sqlite3_total_changes()] is running then the value
@@ -2027,10 +2050,11 @@
2050 SQLITE_API int sqlite3_complete(const char *sql);
2051 SQLITE_API int sqlite3_complete16(const void *sql);
2052
2053 /*
2054 ** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors
2055 ** KEYWORDS: {busy-handler callback} {busy handler}
2056 **
2057 ** ^The sqlite3_busy_handler(D,X,P) routine sets a callback function X
2058 ** that might be invoked with argument P whenever
2059 ** an attempt is made to access a database table associated with
2060 ** [database connection] D when another thread
@@ -2043,11 +2067,11 @@
2067 ** is not NULL, then the callback might be invoked with two arguments.
2068 **
2069 ** ^The first argument to the busy handler is a copy of the void* pointer which
2070 ** is the third argument to sqlite3_busy_handler(). ^The second argument to
2071 ** the busy handler callback is the number of times that the busy handler has
2072 ** been invoked previously for the same locking event. ^If the
2073 ** busy callback returns 0, then no additional attempts are made to
2074 ** access the database and [SQLITE_BUSY] is returned
2075 ** to the application.
2076 ** ^If the callback returns non-zero, then another attempt
2077 ** is made to access the database and the cycle repeats.
@@ -2418,17 +2442,18 @@
2442 ** already uses the largest possible [ROWID]. The PRNG is also used for
2443 ** the build-in random() and randomblob() SQL functions. This interface allows
2444 ** applications to access the same PRNG for other purposes.
2445 **
2446 ** ^A call to this routine stores N bytes of randomness into buffer P.
2447 ** ^The P parameter can be a NULL pointer.
2448 **
2449 ** ^If this routine has not been previously called or if the previous
2450 ** call had N less than one or a NULL pointer for P, then the PRNG is
2451 ** seeded using randomness obtained from the xRandomness method of
2452 ** the default [sqlite3_vfs] object.
2453 ** ^If the previous call to this routine had an N of 1 or more and a
2454 ** non-NULL P then the pseudo-randomness is generated
2455 ** internally and without recourse to the [sqlite3_vfs] xRandomness
2456 ** method.
2457 */
2458 SQLITE_API void sqlite3_randomness(int N, void *P);
2459
@@ -4146,13 +4171,13 @@
4171 ** CAPI3REF: Text Encodings
4172 **
4173 ** These constant define integer codes that represent the various
4174 ** text encodings supported by SQLite.
4175 */
4176 #define SQLITE_UTF8 1 /* IMP: R-37514-35566 */
4177 #define SQLITE_UTF16LE 2 /* IMP: R-03371-37637 */
4178 #define SQLITE_UTF16BE 3 /* IMP: R-51971-34154 */
4179 #define SQLITE_UTF16 4 /* Use native byte order */
4180 #define SQLITE_ANY 5 /* Deprecated */
4181 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4182
4183 /*
@@ -4497,11 +4522,12 @@
4522 ** If these routines are called from within the different thread
4523 ** than the one containing the application-defined function that received
4524 ** the [sqlite3_context] pointer, the results are undefined.
4525 */
4526 SQLITE_API void sqlite3_result_blob(sqlite3_context*, const void*, int, void(*)(void*));
4527 SQLITE_API void sqlite3_result_blob64(sqlite3_context*,const void*,
4528 sqlite3_uint64,void(*)(void*));
4529 SQLITE_API void sqlite3_result_double(sqlite3_context*, double);
4530 SQLITE_API void sqlite3_result_error(sqlite3_context*, const char*, int);
4531 SQLITE_API void sqlite3_result_error16(sqlite3_context*, const void*, int);
4532 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context*);
4533 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context*);
@@ -5129,24 +5155,31 @@
5155
5156
5157 /*
5158 ** CAPI3REF: Extract Metadata About A Column Of A Table
5159 **
5160 ** ^(The sqlite3_table_column_metadata(X,D,T,C,....) routine returns
5161 ** information about column C of table T in database D
5162 ** on [database connection] X.)^ ^The sqlite3_table_column_metadata()
5163 ** interface returns SQLITE_OK and fills in the non-NULL pointers in
5164 ** the final five arguments with appropriate values if the specified
5165 ** column exists. ^The sqlite3_table_column_metadata() interface returns
5166 ** SQLITE_ERROR and if the specified column does not exist.
5167 ** ^If the column-name parameter to sqlite3_table_column_metadata() is a
5168 ** NULL pointer, then this routine simply checks for the existance of the
5169 ** table and returns SQLITE_OK if the table exists and SQLITE_ERROR if it
5170 ** does not.
5171 **
5172 ** ^The column is identified by the second, third and fourth parameters to
5173 ** this function. ^(The second parameter is either the name of the database
5174 ** (i.e. "main", "temp", or an attached database) containing the specified
5175 ** table or NULL.)^ ^If it is NULL, then all attached databases are searched
5176 ** for the table using the same algorithm used by the database engine to
5177 ** resolve unqualified table references.
5178 **
5179 ** ^The third and fourth parameters to this function are the table and column
5180 ** name of the desired column, respectively.
 
5181 **
5182 ** ^Metadata is returned by writing to the memory locations passed as the 5th
5183 ** and subsequent parameters to this function. ^Any of these arguments may be
5184 ** NULL, in which case the corresponding element of metadata is omitted.
5185 **
@@ -5161,36 +5194,33 @@
5194 ** <tr><td> 9th <td> int <td> True if column is [AUTOINCREMENT]
5195 ** </table>
5196 ** </blockquote>)^
5197 **
5198 ** ^The memory pointed to by the character pointers returned for the
5199 ** declaration type and collation sequence is valid until the next
5200 ** call to any SQLite API function.
5201 **
5202 ** ^If the specified table is actually a view, an [error code] is returned.
5203 **
5204 ** ^If the specified column is "rowid", "oid" or "_rowid_" and the table
5205 ** is not a [WITHOUT ROWID] table and an
5206 ** [INTEGER PRIMARY KEY] column has been explicitly declared, then the output
5207 ** parameters are set for the explicitly declared column. ^(If there is no
5208 ** [INTEGER PRIMARY KEY] column, then the outputs
5209 ** for the [rowid] are set as follows:
5210 **
5211 ** <pre>
5212 ** data type: "INTEGER"
5213 ** collation sequence: "BINARY"
5214 ** not null: 0
5215 ** primary key: 1
5216 ** auto increment: 0
5217 ** </pre>)^
5218 **
5219 ** ^This function causes all database schemas to be read from disk and
5220 ** parsed, if that has not already been done, and returns an error if
5221 ** any errors are encountered while loading the schema.
 
 
 
 
5222 */
5223 SQLITE_API int sqlite3_table_column_metadata(
5224 sqlite3 *db, /* Connection handle */
5225 const char *zDbName, /* Database name or NULL */
5226 const char *zTableName, /* Table name */
@@ -5638,31 +5668,47 @@
5668 ** in other words, the same BLOB that would be selected by:
5669 **
5670 ** <pre>
5671 ** SELECT zColumn FROM zDb.zTable WHERE [rowid] = iRow;
5672 ** </pre>)^
5673 **
5674 ** ^(Parameter zDb is not the filename that contains the database, but
5675 ** rather the symbolic name of the database. For attached databases, this is
5676 ** the name that appears after the AS keyword in the [ATTACH] statement.
5677 ** For the main database file, the database name is "main". For TEMP
5678 ** tables, the database name is "temp".)^
5679 **
5680 ** ^If the flags parameter is non-zero, then the BLOB is opened for read
5681 ** and write access. ^If the flags parameter is zero, the BLOB is opened for
5682 ** read-only access.
5683 **
5684 ** ^(On success, [SQLITE_OK] is returned and the new [BLOB handle] is stored
5685 ** in *ppBlob. Otherwise an [error code] is returned and, unless the error
5686 ** code is SQLITE_MISUSE, *ppBlob is set to NULL.)^ ^This means that, provided
5687 ** the API is not misused, it is always safe to call [sqlite3_blob_close()]
5688 ** on *ppBlob after this function it returns.
5689 **
5690 ** This function fails with SQLITE_ERROR if any of the following are true:
5691 ** <ul>
5692 ** <li> ^(Database zDb does not exist)^,
5693 ** <li> ^(Table zTable does not exist within database zDb)^,
5694 ** <li> ^(Table zTable is a WITHOUT ROWID table)^,
5695 ** <li> ^(Column zColumn does not exist)^,
5696 ** <li> ^(Row iRow is not present in the table)^,
5697 ** <li> ^(The specified column of row iRow contains a value that is not
5698 ** a TEXT or BLOB value)^,
5699 ** <li> ^(Column zColumn is part of an index, PRIMARY KEY or UNIQUE
5700 ** constraint and the blob is being opened for read/write access)^,
5701 ** <li> ^([foreign key constraints | Foreign key constraints] are enabled,
5702 ** column zColumn is part of a [child key] definition and the blob is
5703 ** being opened for read/write access)^.
5704 ** </ul>
5705 **
5706 ** ^Unless it returns SQLITE_MISUSE, this function sets the
5707 ** [database connection] error code and message accessible via
5708 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5709 **
5710 **
5711 ** ^(If the row that a BLOB handle points to is modified by an
5712 ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects
5713 ** then the BLOB handle is marked as "expired".
5714 ** This is true if any column of the row is changed, even a column
@@ -5676,17 +5722,13 @@
5722 ** ^Use the [sqlite3_blob_bytes()] interface to determine the size of
5723 ** the opened blob. ^The size of a blob may not be changed by this
5724 ** interface. Use the [UPDATE] SQL command to change the size of a
5725 ** blob.
5726 **
 
 
 
5727 ** ^The [sqlite3_bind_zeroblob()] and [sqlite3_result_zeroblob()] interfaces
5728 ** and the built-in [zeroblob] SQL function may be used to create a
5729 ** zero-filled blob to read or write using the incremental-blob interface.
 
5730 **
5731 ** To avoid a resource leak, every open [BLOB handle] should eventually
5732 ** be released by a call to [sqlite3_blob_close()].
5733 */
5734 SQLITE_API int sqlite3_blob_open(
@@ -5724,28 +5766,26 @@
5766 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64);
5767
5768 /*
5769 ** CAPI3REF: Close A BLOB Handle
5770 **
5771 ** ^This function closes an open [BLOB handle]. ^(The BLOB handle is closed
5772 ** unconditionally. Even if this routine returns an error code, the
5773 ** handle is still closed.)^
5774 **
5775 ** ^If the blob handle being closed was opened for read-write access, and if
5776 ** the database is in auto-commit mode and there are no other open read-write
5777 ** blob handles or active write statements, the current transaction is
5778 ** committed. ^If an error occurs while committing the transaction, an error
5779 ** code is returned and the transaction rolled back.
5780 **
5781 ** Calling this function with an argument that is not a NULL pointer or an
5782 ** open blob handle results in undefined behaviour. ^Calling this routine
5783 ** with a null pointer (such as would be returned by a failed call to
5784 ** [sqlite3_blob_open()]) is a harmless no-op. ^Otherwise, if this function
5785 ** is passed a valid open blob handle, the values returned by the
5786 ** sqlite3_errcode() and sqlite3_errmsg() functions are set before returning.
 
 
5787 */
5788 SQLITE_API int sqlite3_blob_close(sqlite3_blob *);
5789
5790 /*
5791 ** CAPI3REF: Return The Size Of An Open BLOB
@@ -5791,36 +5831,39 @@
5831 SQLITE_API int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset);
5832
5833 /*
5834 ** CAPI3REF: Write Data Into A BLOB Incrementally
5835 **
5836 ** ^(This function is used to write data into an open [BLOB handle] from a
5837 ** caller-supplied buffer. N bytes of data are copied from the buffer Z
5838 ** into the open BLOB, starting at offset iOffset.)^
5839 **
5840 ** ^(On success, sqlite3_blob_write() returns SQLITE_OK.
5841 ** Otherwise, an [error code] or an [extended error code] is returned.)^
5842 ** ^Unless SQLITE_MISUSE is returned, this function sets the
5843 ** [database connection] error code and message accessible via
5844 ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions.
5845 **
5846 ** ^If the [BLOB handle] passed as the first argument was not opened for
5847 ** writing (the flags parameter to [sqlite3_blob_open()] was zero),
5848 ** this function returns [SQLITE_READONLY].
5849 **
5850 ** This function may only modify the contents of the BLOB; it is
5851 ** not possible to increase the size of a BLOB using this API.
5852 ** ^If offset iOffset is less than N bytes from the end of the BLOB,
5853 ** [SQLITE_ERROR] is returned and no data is written. The size of the
5854 ** BLOB (and hence the maximum value of N+iOffset) can be determined
5855 ** using the [sqlite3_blob_bytes()] interface. ^If N or iOffset are less
5856 ** than zero [SQLITE_ERROR] is returned and no data is written.
5857 **
5858 ** ^An attempt to write to an expired [BLOB handle] fails with an
5859 ** error code of [SQLITE_ABORT]. ^Writes to the BLOB that occurred
5860 ** before the [BLOB handle] expired are not rolled back by the
5861 ** expiration of the handle, though of course those changes might
5862 ** have been overwritten by the statement that expired the BLOB handle
5863 ** or by other independent statements.
5864 **
 
 
 
5865 ** This routine only works on a [BLOB handle] which has been created
5866 ** by a prior successful call to [sqlite3_blob_open()] and which has not
5867 ** been closed by [sqlite3_blob_close()]. Passing any other pointer in
5868 ** to this routine results in undefined and probably undesirable behavior.
5869 **
@@ -5869,38 +5912,38 @@
5912 ** use by SQLite, code that links against SQLite is
5913 ** permitted to use any of these routines.
5914 **
5915 ** The SQLite source code contains multiple implementations
5916 ** of these mutex routines. An appropriate implementation
5917 ** is selected automatically at compile-time. The following
5918 ** implementations are available in the SQLite core:
5919 **
5920 ** <ul>
5921 ** <li> SQLITE_MUTEX_PTHREADS
5922 ** <li> SQLITE_MUTEX_W32
5923 ** <li> SQLITE_MUTEX_NOOP
5924 ** </ul>
5925 **
5926 ** The SQLITE_MUTEX_NOOP implementation is a set of routines
5927 ** that does no real locking and is appropriate for use in
5928 ** a single-threaded application. The SQLITE_MUTEX_PTHREADS and
5929 ** SQLITE_MUTEX_W32 implementations are appropriate for use on Unix
5930 ** and Windows.
5931 **
5932 ** If SQLite is compiled with the SQLITE_MUTEX_APPDEF preprocessor
5933 ** macro defined (with "-DSQLITE_MUTEX_APPDEF=1"), then no mutex
5934 ** implementation is included with the library. In this case the
5935 ** application must supply a custom mutex implementation using the
5936 ** [SQLITE_CONFIG_MUTEX] option of the sqlite3_config() function
5937 ** before calling sqlite3_initialize() or any other public sqlite3_
5938 ** function that calls sqlite3_initialize().
5939 **
5940 ** ^The sqlite3_mutex_alloc() routine allocates a new
5941 ** mutex and returns a pointer to it. ^The sqlite3_mutex_alloc()
5942 ** routine returns NULL if it is unable to allocate the requested
5943 ** mutex. The argument to sqlite3_mutex_alloc() must one of these
5944 ** integer constants:
5945 **
5946 ** <ul>
5947 ** <li> SQLITE_MUTEX_FAST
5948 ** <li> SQLITE_MUTEX_RECURSIVE
5949 ** <li> SQLITE_MUTEX_STATIC_MASTER
@@ -5909,68 +5952,64 @@
5952 ** <li> SQLITE_MUTEX_STATIC_PRNG
5953 ** <li> SQLITE_MUTEX_STATIC_LRU
5954 ** <li> SQLITE_MUTEX_STATIC_PMEM
5955 ** <li> SQLITE_MUTEX_STATIC_APP1
5956 ** <li> SQLITE_MUTEX_STATIC_APP2
5957 ** <li> SQLITE_MUTEX_STATIC_APP3
5958 ** </ul>
5959 **
5960 ** ^The first two constants (SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE)
5961 ** cause sqlite3_mutex_alloc() to create
5962 ** a new mutex. ^The new mutex is recursive when SQLITE_MUTEX_RECURSIVE
5963 ** is used but not necessarily so when SQLITE_MUTEX_FAST is used.
5964 ** The mutex implementation does not need to make a distinction
5965 ** between SQLITE_MUTEX_RECURSIVE and SQLITE_MUTEX_FAST if it does
5966 ** not want to. SQLite will only request a recursive mutex in
5967 ** cases where it really needs one. If a faster non-recursive mutex
5968 ** implementation is available on the host platform, the mutex subsystem
5969 ** might return such a mutex in response to SQLITE_MUTEX_FAST.
5970 **
5971 ** ^The other allowed parameters to sqlite3_mutex_alloc() (anything other
5972 ** than SQLITE_MUTEX_FAST and SQLITE_MUTEX_RECURSIVE) each return
5973 ** a pointer to a static preexisting mutex. ^Nine static mutexes are
5974 ** used by the current version of SQLite. Future versions of SQLite
5975 ** may add additional static mutexes. Static mutexes are for internal
5976 ** use by SQLite only. Applications that use SQLite mutexes should
5977 ** use only the dynamic mutexes returned by SQLITE_MUTEX_FAST or
5978 ** SQLITE_MUTEX_RECURSIVE.
5979 **
5980 ** ^Note that if one of the dynamic mutex parameters (SQLITE_MUTEX_FAST
5981 ** or SQLITE_MUTEX_RECURSIVE) is used then sqlite3_mutex_alloc()
5982 ** returns a different mutex on every call. ^For the static
5983 ** mutex types, the same mutex is returned on every call that has
5984 ** the same type number.
5985 **
5986 ** ^The sqlite3_mutex_free() routine deallocates a previously
5987 ** allocated dynamic mutex. Attempting to deallocate a static
5988 ** mutex results in undefined behavior.
 
 
 
5989 **
5990 ** ^The sqlite3_mutex_enter() and sqlite3_mutex_try() routines attempt
5991 ** to enter a mutex. ^If another thread is already within the mutex,
5992 ** sqlite3_mutex_enter() will block and sqlite3_mutex_try() will return
5993 ** SQLITE_BUSY. ^The sqlite3_mutex_try() interface returns [SQLITE_OK]
5994 ** upon successful entry. ^(Mutexes created using
5995 ** SQLITE_MUTEX_RECURSIVE can be entered multiple times by the same thread.
5996 ** In such cases, the
5997 ** mutex must be exited an equal number of times before another thread
5998 ** can enter.)^ If the same thread tries to enter any mutex other
5999 ** than an SQLITE_MUTEX_RECURSIVE more than once, the behavior is undefined.
 
 
6000 **
6001 ** ^(Some systems (for example, Windows 95) do not support the operation
6002 ** implemented by sqlite3_mutex_try(). On those systems, sqlite3_mutex_try()
6003 ** will always return SQLITE_BUSY. The SQLite core only ever uses
6004 ** sqlite3_mutex_try() as an optimization so this is acceptable
6005 ** behavior.)^
6006 **
6007 ** ^The sqlite3_mutex_leave() routine exits a mutex that was
6008 ** previously entered by the same thread. The behavior
6009 ** is undefined if the mutex is not currently entered by the
6010 ** calling thread or is not currently allocated.
 
6011 **
6012 ** ^If the argument to sqlite3_mutex_enter(), sqlite3_mutex_try(), or
6013 ** sqlite3_mutex_leave() is a NULL pointer, then all three routines
6014 ** behave as no-ops.
6015 **
@@ -5987,13 +6026,13 @@
6026 **
6027 ** An instance of this structure defines the low-level routines
6028 ** used to allocate and use mutexes.
6029 **
6030 ** Usually, the default mutex implementations provided by SQLite are
6031 ** sufficient, however the application has the option of substituting a custom
6032 ** implementation for specialized deployments or systems for which SQLite
6033 ** does not provide a suitable implementation. In this case, the application
6034 ** creates and populates an instance of this structure to pass
6035 ** to sqlite3_config() along with the [SQLITE_CONFIG_MUTEX] option.
6036 ** Additionally, an instance of this structure can be used as an
6037 ** output variable when querying the system for the current mutex
6038 ** implementation, using the [SQLITE_CONFIG_GETMUTEX] option.
@@ -6030,17 +6069,17 @@
6069 ** by this structure are not required to handle this case, the results
6070 ** of passing a NULL pointer instead of a valid mutex handle are undefined
6071 ** (i.e. it is acceptable to provide an implementation that segfaults if
6072 ** it is passed a NULL pointer).
6073 **
6074 ** The xMutexInit() method must be threadsafe. It must be harmless to
6075 ** invoke xMutexInit() multiple times within the same process and without
6076 ** intervening calls to xMutexEnd(). Second and subsequent calls to
6077 ** xMutexInit() must be no-ops.
6078 **
6079 ** xMutexInit() must not use SQLite memory allocation ([sqlite3_malloc()]
6080 ** and its associates). Similarly, xMutexAlloc() must not use SQLite memory
6081 ** allocation for a static mutex. ^However xMutexAlloc() may use SQLite
6082 ** memory allocation for a fast or recursive mutex.
6083 **
6084 ** ^SQLite will invoke the xMutexEnd() method when [sqlite3_shutdown()] is
6085 ** called, but only if the prior call to xMutexInit returned SQLITE_OK.
@@ -6062,33 +6101,33 @@
6101
6102 /*
6103 ** CAPI3REF: Mutex Verification Routines
6104 **
6105 ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routines
6106 ** are intended for use inside assert() statements. The SQLite core
6107 ** never uses these routines except inside an assert() and applications
6108 ** are advised to follow the lead of the core. The SQLite core only
6109 ** provides implementations for these routines when it is compiled
6110 ** with the SQLITE_DEBUG flag. External mutex implementations
6111 ** are only required to provide these routines if SQLITE_DEBUG is
6112 ** defined and if NDEBUG is not defined.
6113 **
6114 ** These routines should return true if the mutex in their argument
6115 ** is held or not held, respectively, by the calling thread.
6116 **
6117 ** The implementation is not required to provide versions of these
6118 ** routines that actually work. If the implementation does not provide working
6119 ** versions of these routines, it should at least provide stubs that always
6120 ** return true so that one does not get spurious assertion failures.
6121 **
6122 ** If the argument to sqlite3_mutex_held() is a NULL pointer then
6123 ** the routine should return 1. This seems counter-intuitive since
6124 ** clearly the mutex cannot be held if it does not exist. But
6125 ** the reason the mutex does not exist is because the build is not
6126 ** using mutexes. And we do not want the assert() containing the
6127 ** call to sqlite3_mutex_held() to fail, so a non-zero return is
6128 ** the appropriate thing to do. The sqlite3_mutex_notheld()
6129 ** interface should also return 1 when given a NULL pointer.
6130 */
6131 #ifndef NDEBUG
6132 SQLITE_API int sqlite3_mutex_held(sqlite3_mutex*);
6133 SQLITE_API int sqlite3_mutex_notheld(sqlite3_mutex*);
@@ -6816,10 +6855,14 @@
6855 ** sqlite3_backup_init(D,N,S,M) identify the [database connection]
6856 ** and database name of the source database, respectively.
6857 ** ^The source and destination [database connections] (parameters S and D)
6858 ** must be different or else sqlite3_backup_init(D,N,S,M) will fail with
6859 ** an error.
6860 **
6861 ** ^A call to sqlite3_backup_init() will fail, returning SQLITE_ERROR, if
6862 ** there is already a read or read-write transaction open on the
6863 ** destination database.
6864 **
6865 ** ^If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is
6866 ** returned and an error code and error message are stored in the
6867 ** destination [database connection] D.
6868 ** ^The error code and message for the failed call to sqlite3_backup_init()
@@ -7210,101 +7253,118 @@
7253 SQLITE_API int sqlite3_wal_autocheckpoint(sqlite3 *db, int N);
7254
7255 /*
7256 ** CAPI3REF: Checkpoint a database
7257 **
7258 ** ^(The sqlite3_wal_checkpoint(D,X) is equivalent to
7259 ** [sqlite3_wal_checkpoint_v2](D,X,[SQLITE_CHECKPOINT_PASSIVE],0,0).)^
7260 **
7261 ** In brief, sqlite3_wal_checkpoint(D,X) causes the content in the
7262 ** [write-ahead log] for database X on [database connection] D to be
7263 ** transferred into the database file and for the write-ahead log to
7264 ** be reset. See the [checkpointing] documentation for addition
7265 ** information.
7266 **
7267 ** This interface used to be the only way to cause a checkpoint to
7268 ** occur. But then the newer and more powerful [sqlite3_wal_checkpoint_v2()]
7269 ** interface was added. This interface is retained for backwards
7270 ** compatibility and as a convenience for applications that need to manually
7271 ** start a callback but which do not need the full power (and corresponding
7272 ** complication) of [sqlite3_wal_checkpoint_v2()].
 
7273 */
7274 SQLITE_API int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb);
7275
7276 /*
7277 ** CAPI3REF: Checkpoint a database
7278 **
7279 ** ^(The sqlite3_wal_checkpoint_v2(D,X,M,L,C) interface runs a checkpoint
7280 ** operation on database X of [database connection] D in mode M. Status
7281 ** information is written back into integers pointed to by L and C.)^
7282 ** ^(The M parameter must be a valid [checkpoint mode]:)^
7283 **
7284 ** <dl>
7285 ** <dt>SQLITE_CHECKPOINT_PASSIVE<dd>
7286 ** ^Checkpoint as many frames as possible without waiting for any database
7287 ** readers or writers to finish, then sync the database file if all frames
7288 ** in the log were checkpointed. ^The [busy-handler callback]
7289 ** is never invoked in the SQLITE_CHECKPOINT_PASSIVE mode.
7290 ** ^On the other hand, passive mode might leave the checkpoint unfinished
7291 ** if there are concurrent readers or writers.
7292 **
7293 ** <dt>SQLITE_CHECKPOINT_FULL<dd>
7294 ** ^This mode blocks (it invokes the
7295 ** [sqlite3_busy_handler|busy-handler callback]) until there is no
7296 ** database writer and all readers are reading from the most recent database
7297 ** snapshot. ^It then checkpoints all frames in the log file and syncs the
7298 ** database file. ^This mode blocks new database writers while it is pending,
7299 ** but new database readers are allowed to continue unimpeded.
7300 **
7301 ** <dt>SQLITE_CHECKPOINT_RESTART<dd>
7302 ** ^This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition
7303 ** that after checkpointing the log file it blocks (calls the
7304 ** [busy-handler callback])
7305 ** until all readers are reading from the database file only. ^This ensures
7306 ** that the next writer will restart the log file from the beginning.
7307 ** ^Like SQLITE_CHECKPOINT_FULL, this mode blocks new
7308 ** database writer attempts while it is pending, but does not impede readers.
7309 **
7310 ** <dt>SQLITE_CHECKPOINT_TRUNCATE<dd>
7311 ** ^This mode works the same way as SQLITE_CHECKPOINT_RESTART with the
7312 ** addition that it also truncates the log file to zero bytes just prior
7313 ** to a successful return.
7314 ** </dl>
7315 **
7316 ** ^If pnLog is not NULL, then *pnLog is set to the total number of frames in
7317 ** the log file or to -1 if the checkpoint could not run because
7318 ** of an error or because the database is not in [WAL mode]. ^If pnCkpt is not
7319 ** NULL,then *pnCkpt is set to the total number of checkpointed frames in the
7320 ** log file (including any that were already checkpointed before the function
7321 ** was called) or to -1 if the checkpoint could not run due to an error or
7322 ** because the database is not in WAL mode. ^Note that upon successful
7323 ** completion of an SQLITE_CHECKPOINT_TRUNCATE, the log file will have been
7324 ** truncated to zero bytes and so both *pnLog and *pnCkpt will be set to zero.
7325 **
7326 ** ^All calls obtain an exclusive "checkpoint" lock on the database file. ^If
7327 ** any other process is running a checkpoint operation at the same time, the
7328 ** lock cannot be obtained and SQLITE_BUSY is returned. ^Even if there is a
7329 ** busy-handler configured, it will not be invoked in this case.
7330 **
7331 ** ^The SQLITE_CHECKPOINT_FULL, RESTART and TRUNCATE modes also obtain the
7332 ** exclusive "writer" lock on the database file. ^If the writer lock cannot be
7333 ** obtained immediately, and a busy-handler is configured, it is invoked and
7334 ** the writer lock retried until either the busy-handler returns 0 or the lock
7335 ** is successfully obtained. ^The busy-handler is also invoked while waiting for
7336 ** database readers as described above. ^If the busy-handler returns 0 before
7337 ** the writer lock is obtained or while waiting for database readers, the
7338 ** checkpoint operation proceeds from that point in the same way as
7339 ** SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible
7340 ** without blocking any further. ^SQLITE_BUSY is returned in this case.
7341 **
7342 ** ^If parameter zDb is NULL or points to a zero length string, then the
7343 ** specified operation is attempted on all WAL databases [attached] to
7344 ** [database connection] db. In this case the
7345 ** values written to output parameters *pnLog and *pnCkpt are undefined. ^If
7346 ** an SQLITE_BUSY error is encountered when processing one or more of the
7347 ** attached WAL databases, the operation is still attempted on any remaining
7348 ** attached databases and SQLITE_BUSY is returned at the end. ^If any other
7349 ** error occurs while processing an attached database, processing is abandoned
7350 ** and the error code is returned to the caller immediately. ^If no error
7351 ** (SQLITE_BUSY or otherwise) is encountered while processing the attached
7352 ** databases, SQLITE_OK is returned.
7353 **
7354 ** ^If database zDb is the name of an attached database that is not in WAL
7355 ** mode, SQLITE_OK is returned and both *pnLog and *pnCkpt set to -1. ^If
7356 ** zDb is not NULL (or a zero length string) and is not the name of any
7357 ** attached database, SQLITE_ERROR is returned to the caller.
7358 **
7359 ** ^Unless it returns SQLITE_MISUSE,
7360 ** the sqlite3_wal_checkpoint_v2() interface
7361 ** sets the error information that is queried by
7362 ** [sqlite3_errcode()] and [sqlite3_errmsg()].
7363 **
7364 ** ^The [PRAGMA wal_checkpoint] command can be used to invoke this interface
7365 ** from SQL.
7366 */
7367 SQLITE_API int sqlite3_wal_checkpoint_v2(
7368 sqlite3 *db, /* Database handle */
7369 const char *zDb, /* Name of attached database (or NULL) */
7370 int eMode, /* SQLITE_CHECKPOINT_* value */
@@ -7311,20 +7371,22 @@
7371 int *pnLog, /* OUT: Size of WAL log in frames */
7372 int *pnCkpt /* OUT: Total number of frames checkpointed */
7373 );
7374
7375 /*
7376 ** CAPI3REF: Checkpoint Mode Values
7377 ** KEYWORDS: {checkpoint mode}
7378 **
7379 ** These constants define all valid values for the "checkpoint mode" passed
7380 ** as the third parameter to the [sqlite3_wal_checkpoint_v2()] interface.
7381 ** See the [sqlite3_wal_checkpoint_v2()] documentation for details on the
7382 ** meaning of each of these checkpoint modes.
7383 */
7384 #define SQLITE_CHECKPOINT_PASSIVE 0 /* Do as much as possible w/o blocking */
7385 #define SQLITE_CHECKPOINT_FULL 1 /* Wait for writers, then checkpoint */
7386 #define SQLITE_CHECKPOINT_RESTART 2 /* Like FULL but wait for for readers */
7387 #define SQLITE_CHECKPOINT_TRUNCATE 3 /* Like RESTART but also truncate WAL */
7388
7389 /*
7390 ** CAPI3REF: Virtual Table Interface Configuration
7391 **
7392 ** This function may be called by either the [xConnect] or [xCreate] method
@@ -7409,10 +7471,102 @@
7471 /* #define SQLITE_IGNORE 2 // Also used by sqlite3_authorizer() callback */
7472 #define SQLITE_FAIL 3
7473 /* #define SQLITE_ABORT 4 // Also an error code */
7474 #define SQLITE_REPLACE 5
7475
7476 /*
7477 ** CAPI3REF: Prepared Statement Scan Status Opcodes
7478 ** KEYWORDS: {scanstatus options}
7479 **
7480 ** The following constants can be used for the T parameter to the
7481 ** [sqlite3_stmt_scanstatus(S,X,T,V)] interface. Each constant designates a
7482 ** different metric for sqlite3_stmt_scanstatus() to return.
7483 **
7484 ** <dl>
7485 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
7486 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be
7487 ** set to the total number of times that the X-th loop has run.</dd>
7488 **
7489 ** [[SQLITE_SCANSTAT_NVISIT]] <dt>SQLITE_SCANSTAT_NVISIT</dt>
7490 ** <dd>^The [sqlite3_int64] variable pointed to by the T parameter will be set
7491 ** to the total number of rows examined by all iterations of the X-th loop.</dd>
7492 **
7493 ** [[SQLITE_SCANSTAT_EST]] <dt>SQLITE_SCANSTAT_EST</dt>
7494 ** <dd>^The "double" variable pointed to by the T parameter will be set to the
7495 ** query planner's estimate for the average number of rows output from each
7496 ** iteration of the X-th loop. If the query planner's estimates was accurate,
7497 ** then this value will approximate the quotient NVISIT/NLOOP and the
7498 ** product of this value for all prior loops with the same SELECTID will
7499 ** be the NLOOP value for the current loop.
7500 **
7501 ** [[SQLITE_SCANSTAT_NAME]] <dt>SQLITE_SCANSTAT_NAME</dt>
7502 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
7503 ** to a zero-terminated UTF-8 string containing the name of the index or table
7504 ** used for the X-th loop.
7505 **
7506 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
7507 ** <dd>^The "const char *" variable pointed to by the T parameter will be set
7508 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
7509 ** description for the X-th loop.
7510 **
7511 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
7512 ** <dd>^The "int" variable pointed to by the T parameter will be set to the
7513 ** "select-id" for the X-th loop. The select-id identifies which query or
7514 ** subquery the loop is part of. The main query has a select-id of zero.
7515 ** The select-id is the same value as is output in the first column
7516 ** of an [EXPLAIN QUERY PLAN] query.
7517 ** </dl>
7518 */
7519 #define SQLITE_SCANSTAT_NLOOP 0
7520 #define SQLITE_SCANSTAT_NVISIT 1
7521 #define SQLITE_SCANSTAT_EST 2
7522 #define SQLITE_SCANSTAT_NAME 3
7523 #define SQLITE_SCANSTAT_EXPLAIN 4
7524 #define SQLITE_SCANSTAT_SELECTID 5
7525
7526 /*
7527 ** CAPI3REF: Prepared Statement Scan Status
7528 **
7529 ** Return status data for a single loop within query pStmt.
7530 **
7531 ** The "iScanStatusOp" parameter determines which status information to return.
7532 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
7533 ** of this interface is undefined.
7534 ** ^The requested measurement is written into a variable pointed to by
7535 ** the "pOut" parameter.
7536 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
7537 ** Loops are numbered starting from zero. ^If idx is out of range - less than
7538 ** zero or greater than or equal to the total number of loops used to implement
7539 ** the statement - a non-zero value is returned and the variable that pOut
7540 ** points to is unchanged.
7541 **
7542 ** ^Statistics might not be available for all loops in all statements. ^In cases
7543 ** where there exist loops with no available statistics, this function behaves
7544 ** as if the loop did not exist - it returns non-zero and leave the variable
7545 ** that pOut points to unchanged.
7546 **
7547 ** This API is only available if the library is built with pre-processor
7548 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7549 **
7550 ** See also: [sqlite3_stmt_scanstatus_reset()]
7551 */
7552 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus(
7553 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
7554 int idx, /* Index of loop to report on */
7555 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
7556 void *pOut /* Result written here */
7557 );
7558
7559 /*
7560 ** CAPI3REF: Zero Scan-Status Counters
7561 **
7562 ** ^Zero all [sqlite3_stmt_scanstatus()] related event counters.
7563 **
7564 ** This API is only available if the library is built with pre-processor
7565 ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined.
7566 */
7567 SQLITE_API SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
7568
7569
7570 /*
7571 ** Undo the hack that converts floating point types to integer for
7572 ** builds on processors without floating point support.
7573
+3 -3
--- src/stat.c
+++ src/stat.c
@@ -77,11 +77,11 @@
7777
if( n>0 ){
7878
int a, b;
7979
Stmt q;
8080
@ <tr><th>Uncompressed&nbsp;Artifact&nbsp;Size:</th><td>
8181
db_prepare(&q, "SELECT total(size), avg(size), max(size)"
82
- " FROM blob WHERE size>0");
82
+ " FROM blob WHERE size>0 /*scan*/");
8383
db_step(&q);
8484
t = db_column_int64(&q, 0);
8585
szAvg = db_column_int(&q, 1);
8686
szMax = db_column_int(&q, 2);
8787
db_finalize(&q);
@@ -226,19 +226,19 @@
226226
n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
227227
fossil_print("%*s%d across all branches\n", colWidth, "files:", n);
228228
n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
229229
" WHERE tagname GLOB 'wiki-*'");
230230
m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='w'");
231
- fossil_print("%*s%d (%d changes)\n", colWidth, "wikipages:", n, m);
231
+ fossil_print("%*s%d (%d changes)\n", colWidth, "wiki-pages:", n, m);
232232
n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
233233
" WHERE tagname GLOB 'tkt-*'");
234234
m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='t'");
235235
fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
236236
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
237237
fossil_print("%*s%d\n", colWidth, "events:", n);
238238
n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
239
- fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
239
+ fossil_print("%*s%d\n", colWidth, "tag-changes:", n);
240240
z = db_text(0, "SELECT datetime(mtime) || ' - about ' ||"
241241
" CAST(julianday('now') - mtime AS INTEGER)"
242242
" || ' days ago' FROM event "
243243
" ORDER BY mtime DESC LIMIT 1");
244244
fossil_print("%*s%s\n", colWidth, "latest-change:", z);
245245
--- src/stat.c
+++ src/stat.c
@@ -77,11 +77,11 @@
77 if( n>0 ){
78 int a, b;
79 Stmt q;
80 @ <tr><th>Uncompressed&nbsp;Artifact&nbsp;Size:</th><td>
81 db_prepare(&q, "SELECT total(size), avg(size), max(size)"
82 " FROM blob WHERE size>0");
83 db_step(&q);
84 t = db_column_int64(&q, 0);
85 szAvg = db_column_int(&q, 1);
86 szMax = db_column_int(&q, 2);
87 db_finalize(&q);
@@ -226,19 +226,19 @@
226 n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
227 fossil_print("%*s%d across all branches\n", colWidth, "files:", n);
228 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
229 " WHERE tagname GLOB 'wiki-*'");
230 m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='w'");
231 fossil_print("%*s%d (%d changes)\n", colWidth, "wikipages:", n, m);
232 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
233 " WHERE tagname GLOB 'tkt-*'");
234 m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='t'");
235 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
236 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
237 fossil_print("%*s%d\n", colWidth, "events:", n);
238 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
239 fossil_print("%*s%d\n", colWidth, "tagchanges:", n);
240 z = db_text(0, "SELECT datetime(mtime) || ' - about ' ||"
241 " CAST(julianday('now') - mtime AS INTEGER)"
242 " || ' days ago' FROM event "
243 " ORDER BY mtime DESC LIMIT 1");
244 fossil_print("%*s%s\n", colWidth, "latest-change:", z);
245
--- src/stat.c
+++ src/stat.c
@@ -77,11 +77,11 @@
77 if( n>0 ){
78 int a, b;
79 Stmt q;
80 @ <tr><th>Uncompressed&nbsp;Artifact&nbsp;Size:</th><td>
81 db_prepare(&q, "SELECT total(size), avg(size), max(size)"
82 " FROM blob WHERE size>0 /*scan*/");
83 db_step(&q);
84 t = db_column_int64(&q, 0);
85 szAvg = db_column_int(&q, 1);
86 szMax = db_column_int(&q, 2);
87 db_finalize(&q);
@@ -226,19 +226,19 @@
226 n = db_int(0, "SELECT count(*) FROM filename /*scan*/");
227 fossil_print("%*s%d across all branches\n", colWidth, "files:", n);
228 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
229 " WHERE tagname GLOB 'wiki-*'");
230 m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='w'");
231 fossil_print("%*s%d (%d changes)\n", colWidth, "wiki-pages:", n, m);
232 n = db_int(0, "SELECT count(*) FROM tag /*scan*/"
233 " WHERE tagname GLOB 'tkt-*'");
234 m = db_int(0, "SELECT COUNT(*) FROM event WHERE type='t'");
235 fossil_print("%*s%d (%d changes)\n", colWidth, "tickets:", n, m);
236 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='e'");
237 fossil_print("%*s%d\n", colWidth, "events:", n);
238 n = db_int(0, "SELECT COUNT(*) FROM event WHERE type='g'");
239 fossil_print("%*s%d\n", colWidth, "tag-changes:", n);
240 z = db_text(0, "SELECT datetime(mtime) || ' - about ' ||"
241 " CAST(julianday('now') - mtime AS INTEGER)"
242 " || ' days ago' FROM event "
243 " ORDER BY mtime DESC LIMIT 1");
244 fossil_print("%*s%s\n", colWidth, "latest-change:", z);
245
+66 -2
--- src/style.c
+++ src/style.c
@@ -301,10 +301,11 @@
301301
302302
/* Generate the header up through the main menu */
303303
Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
304304
Th_Store("title", zTitle);
305305
Th_Store("baseurl", g.zBaseURL);
306
+ Th_Store("secureurl", login_wants_https_redirect()? g.zHttpsURL: g.zBaseURL);
306307
Th_Store("home", g.zTop);
307308
Th_Store("index_page", db_get("index-page","/home"));
308309
if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
309310
Th_Store("current_page", local_zCurrentPage);
310311
Th_Store("csrf_token", g.zCsrfToken);
@@ -782,10 +783,15 @@
782783
{ ".filetree",
783784
"tree-view file browser",
784785
@ margin: 1em 0;
785786
@ line-height: 1.5;
786787
},
788
+ {
789
+ ".filetree > ul",
790
+ "tree-view top-level list",
791
+ @ display: inline-block;
792
+ },
787793
{ ".filetree ul",
788794
"tree-view lists",
789795
@ margin: 0;
790796
@ padding: 0;
791797
@ list-style: none;
@@ -831,21 +837,37 @@
831837
},
832838
{ ".filetree a",
833839
"tree-view links",
834840
@ position: relative;
835841
@ z-index: 1;
836
- @ display: inline-block;
842
+ @ display: table-cell;
837843
@ min-height: 16px;
838844
@ padding-left: 21px;
839845
@ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP\/\/\/yEhIf\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAIvlIKpxqcfmgOUvoaqDSCxrEEfF14GqFXImJZsu73wepJzVMNxrtNTj3NATMKhpwAAOw==);
840846
@ background-position: center left;
841847
@ background-repeat: no-repeat;
842848
},
843
- { ".filetree .dir > a",
849
+ { "div.filetreeline",
850
+ "line of a file tree",
851
+ @ display: table;
852
+ @ width: 100%;
853
+ @ white-space: nowrap;
854
+ },
855
+ { ".filetree .dir > div.filetreeline > a",
844856
"tree-view directory links",
845857
@ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
846858
},
859
+ { "div.filetreeage",
860
+ "Last change floating display on the right",
861
+ @ display: table-cell;
862
+ @ padding-left: 3em;
863
+ @ text-align: right;
864
+ },
865
+ { "div.filetreeline:hover",
866
+ "Highlight the line of a file tree",
867
+ @ background-color: #eee;
868
+ },
847869
{ "table.login_out",
848870
"table format for login/out label/input table",
849871
@ text-align: left;
850872
@ margin-right: 10px;
851873
@ margin-left: 10px;
@@ -1208,10 +1230,50 @@
12081230
},
12091231
{ "#canvas", "timeline graph node colors",
12101232
@ color: black;
12111233
@ background-color: white;
12121234
},
1235
+ { "table.adminLogTable",
1236
+ "Class for the /admin_log table",
1237
+ @ text-align: left;
1238
+ },
1239
+ { ".adminLogTable .adminTime",
1240
+ "Class for the /admin_log table",
1241
+ @ text-align: left;
1242
+ @ vertical-align: top;
1243
+ @ white-space: nowrap;
1244
+ },
1245
+ { ".fileage table",
1246
+ "The fileage table",
1247
+ @ border-spacing: 0;
1248
+ },
1249
+ { ".fileage tr:hover",
1250
+ "Mouse-over effects for the file-age table",
1251
+ @ background-color: #eee;
1252
+ },
1253
+ { ".fileage td",
1254
+ "fileage table cells",
1255
+ @ vertical-align: top;
1256
+ @ text-align: left;
1257
+ @ border-top: 1px solid #ddd;
1258
+ @ padding-top: 3px;
1259
+ },
1260
+ { ".fileage td:first-child",
1261
+ "fileage first column (the age)",
1262
+ @ white-space: nowrap;
1263
+ },
1264
+ { ".fileage td:nth-child(2)",
1265
+ "fileage second column (the filename)",
1266
+ @ padding-left: 1em;
1267
+ @ padding-right: 1em;
1268
+ },
1269
+ { ".fileage td:nth-child(3)",
1270
+ "fileage third column (the check-in comment)",
1271
+ @ word-break: break-all;
1272
+ @ word-wrap: break-word;
1273
+ @ max-width: 50%;
1274
+ },
12131275
{ 0,
12141276
0,
12151277
0
12161278
}
12171279
};
@@ -1259,10 +1321,11 @@
12591321
12601322
/* Process through TH1 in order to give an opportunity to substitute
12611323
** variables such as $baseurl.
12621324
*/
12631325
Th_Store("baseurl", g.zBaseURL);
1326
+ Th_Store("secureurl", login_wants_https_redirect()? g.zHttpsURL: g.zBaseURL);
12641327
Th_Store("home", g.zTop);
12651328
image_url_var("logo");
12661329
image_url_var("background");
12671330
Th_Render(blob_str(&css));
12681331
@@ -1304,10 +1367,11 @@
13041367
}
13051368
#if !defined(_WIN32)
13061369
@ uid=%d(getuid()), gid=%d(getgid())<br />
13071370
#endif
13081371
@ g.zBaseURL = %h(g.zBaseURL)<br />
1372
+ @ g.zHttpsURL = %h(g.zHttpsURL)<br />
13091373
@ g.zTop = %h(g.zTop)<br />
13101374
for(i=0, c='a'; c<='z'; c++){
13111375
if( login_has_capability(&c, 1) ) zCap[i++] = c;
13121376
}
13131377
zCap[i] = 0;
13141378
--- src/style.c
+++ src/style.c
@@ -301,10 +301,11 @@
301
302 /* Generate the header up through the main menu */
303 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
304 Th_Store("title", zTitle);
305 Th_Store("baseurl", g.zBaseURL);
 
306 Th_Store("home", g.zTop);
307 Th_Store("index_page", db_get("index-page","/home"));
308 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
309 Th_Store("current_page", local_zCurrentPage);
310 Th_Store("csrf_token", g.zCsrfToken);
@@ -782,10 +783,15 @@
782 { ".filetree",
783 "tree-view file browser",
784 @ margin: 1em 0;
785 @ line-height: 1.5;
786 },
 
 
 
 
 
787 { ".filetree ul",
788 "tree-view lists",
789 @ margin: 0;
790 @ padding: 0;
791 @ list-style: none;
@@ -831,21 +837,37 @@
831 },
832 { ".filetree a",
833 "tree-view links",
834 @ position: relative;
835 @ z-index: 1;
836 @ display: inline-block;
837 @ min-height: 16px;
838 @ padding-left: 21px;
839 @ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP\/\/\/yEhIf\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAIvlIKpxqcfmgOUvoaqDSCxrEEfF14GqFXImJZsu73wepJzVMNxrtNTj3NATMKhpwAAOw==);
840 @ background-position: center left;
841 @ background-repeat: no-repeat;
842 },
843 { ".filetree .dir > a",
 
 
 
 
 
 
844 "tree-view directory links",
845 @ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
846 },
 
 
 
 
 
 
 
 
 
 
847 { "table.login_out",
848 "table format for login/out label/input table",
849 @ text-align: left;
850 @ margin-right: 10px;
851 @ margin-left: 10px;
@@ -1208,10 +1230,50 @@
1208 },
1209 { "#canvas", "timeline graph node colors",
1210 @ color: black;
1211 @ background-color: white;
1212 },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1213 { 0,
1214 0,
1215 0
1216 }
1217 };
@@ -1259,10 +1321,11 @@
1259
1260 /* Process through TH1 in order to give an opportunity to substitute
1261 ** variables such as $baseurl.
1262 */
1263 Th_Store("baseurl", g.zBaseURL);
 
1264 Th_Store("home", g.zTop);
1265 image_url_var("logo");
1266 image_url_var("background");
1267 Th_Render(blob_str(&css));
1268
@@ -1304,10 +1367,11 @@
1304 }
1305 #if !defined(_WIN32)
1306 @ uid=%d(getuid()), gid=%d(getgid())<br />
1307 #endif
1308 @ g.zBaseURL = %h(g.zBaseURL)<br />
 
1309 @ g.zTop = %h(g.zTop)<br />
1310 for(i=0, c='a'; c<='z'; c++){
1311 if( login_has_capability(&c, 1) ) zCap[i++] = c;
1312 }
1313 zCap[i] = 0;
1314
--- src/style.c
+++ src/style.c
@@ -301,10 +301,11 @@
301
302 /* Generate the header up through the main menu */
303 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
304 Th_Store("title", zTitle);
305 Th_Store("baseurl", g.zBaseURL);
306 Th_Store("secureurl", login_wants_https_redirect()? g.zHttpsURL: g.zBaseURL);
307 Th_Store("home", g.zTop);
308 Th_Store("index_page", db_get("index-page","/home"));
309 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
310 Th_Store("current_page", local_zCurrentPage);
311 Th_Store("csrf_token", g.zCsrfToken);
@@ -782,10 +783,15 @@
783 { ".filetree",
784 "tree-view file browser",
785 @ margin: 1em 0;
786 @ line-height: 1.5;
787 },
788 {
789 ".filetree > ul",
790 "tree-view top-level list",
791 @ display: inline-block;
792 },
793 { ".filetree ul",
794 "tree-view lists",
795 @ margin: 0;
796 @ padding: 0;
797 @ list-style: none;
@@ -831,21 +837,37 @@
837 },
838 { ".filetree a",
839 "tree-view links",
840 @ position: relative;
841 @ z-index: 1;
842 @ display: table-cell;
843 @ min-height: 16px;
844 @ padding-left: 21px;
845 @ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP\/\/\/yEhIf\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAIvlIKpxqcfmgOUvoaqDSCxrEEfF14GqFXImJZsu73wepJzVMNxrtNTj3NATMKhpwAAOw==);
846 @ background-position: center left;
847 @ background-repeat: no-repeat;
848 },
849 { "div.filetreeline",
850 "line of a file tree",
851 @ display: table;
852 @ width: 100%;
853 @ white-space: nowrap;
854 },
855 { ".filetree .dir > div.filetreeline > a",
856 "tree-view directory links",
857 @ background-image: url(data:image/gif;base64,R0lGODlhEAAQAJEAAP/WVCIiIv\/\/\/wAAACH5BAEHAAIALAAAAAAQABAAAAInlI9pwa3XYniCgQtkrAFfLXkiFo1jaXpo+jUs6b5Z/K4siDu5RPUFADs=);
858 },
859 { "div.filetreeage",
860 "Last change floating display on the right",
861 @ display: table-cell;
862 @ padding-left: 3em;
863 @ text-align: right;
864 },
865 { "div.filetreeline:hover",
866 "Highlight the line of a file tree",
867 @ background-color: #eee;
868 },
869 { "table.login_out",
870 "table format for login/out label/input table",
871 @ text-align: left;
872 @ margin-right: 10px;
873 @ margin-left: 10px;
@@ -1208,10 +1230,50 @@
1230 },
1231 { "#canvas", "timeline graph node colors",
1232 @ color: black;
1233 @ background-color: white;
1234 },
1235 { "table.adminLogTable",
1236 "Class for the /admin_log table",
1237 @ text-align: left;
1238 },
1239 { ".adminLogTable .adminTime",
1240 "Class for the /admin_log table",
1241 @ text-align: left;
1242 @ vertical-align: top;
1243 @ white-space: nowrap;
1244 },
1245 { ".fileage table",
1246 "The fileage table",
1247 @ border-spacing: 0;
1248 },
1249 { ".fileage tr:hover",
1250 "Mouse-over effects for the file-age table",
1251 @ background-color: #eee;
1252 },
1253 { ".fileage td",
1254 "fileage table cells",
1255 @ vertical-align: top;
1256 @ text-align: left;
1257 @ border-top: 1px solid #ddd;
1258 @ padding-top: 3px;
1259 },
1260 { ".fileage td:first-child",
1261 "fileage first column (the age)",
1262 @ white-space: nowrap;
1263 },
1264 { ".fileage td:nth-child(2)",
1265 "fileage second column (the filename)",
1266 @ padding-left: 1em;
1267 @ padding-right: 1em;
1268 },
1269 { ".fileage td:nth-child(3)",
1270 "fileage third column (the check-in comment)",
1271 @ word-break: break-all;
1272 @ word-wrap: break-word;
1273 @ max-width: 50%;
1274 },
1275 { 0,
1276 0,
1277 0
1278 }
1279 };
@@ -1259,10 +1321,11 @@
1321
1322 /* Process through TH1 in order to give an opportunity to substitute
1323 ** variables such as $baseurl.
1324 */
1325 Th_Store("baseurl", g.zBaseURL);
1326 Th_Store("secureurl", login_wants_https_redirect()? g.zHttpsURL: g.zBaseURL);
1327 Th_Store("home", g.zTop);
1328 image_url_var("logo");
1329 image_url_var("background");
1330 Th_Render(blob_str(&css));
1331
@@ -1304,10 +1367,11 @@
1367 }
1368 #if !defined(_WIN32)
1369 @ uid=%d(getuid()), gid=%d(getgid())<br />
1370 #endif
1371 @ g.zBaseURL = %h(g.zBaseURL)<br />
1372 @ g.zHttpsURL = %h(g.zHttpsURL)<br />
1373 @ g.zTop = %h(g.zTop)<br />
1374 for(i=0, c='a'; c<='z'; c++){
1375 if( login_has_capability(&c, 1) ) zCap[i++] = c;
1376 }
1377 zCap[i] = 0;
1378
+1 -1
--- src/tag.c
+++ src/tag.c
@@ -561,11 +561,11 @@
561561
);
562562
@ <ul>
563563
while( db_step(&q)==SQLITE_ROW ){
564564
const char *zName = db_column_text(&q, 0);
565565
if( g.perm.Hyperlink ){
566
- @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T",zName))
566
+ @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T&n=200",zName))
567567
@ %h(zName)</a></li>
568568
}else{
569569
@ <li><span class="tagDsp">%h(zName)</span></li>
570570
}
571571
}
572572
--- src/tag.c
+++ src/tag.c
@@ -561,11 +561,11 @@
561 );
562 @ <ul>
563 while( db_step(&q)==SQLITE_ROW ){
564 const char *zName = db_column_text(&q, 0);
565 if( g.perm.Hyperlink ){
566 @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T",zName))
567 @ %h(zName)</a></li>
568 }else{
569 @ <li><span class="tagDsp">%h(zName)</span></li>
570 }
571 }
572
--- src/tag.c
+++ src/tag.c
@@ -561,11 +561,11 @@
561 );
562 @ <ul>
563 while( db_step(&q)==SQLITE_ROW ){
564 const char *zName = db_column_text(&q, 0);
565 if( g.perm.Hyperlink ){
566 @ <li>%z(xhref("class='taglink'","%R/timeline?t=%T&n=200",zName))
567 @ %h(zName)</a></li>
568 }else{
569 @ <li><span class="tagDsp">%h(zName)</span></li>
570 }
571 }
572
+60 -23
--- src/timeline.c
+++ src/timeline.c
@@ -20,10 +20,20 @@
2020
*/
2121
#include "config.h"
2222
#include <string.h>
2323
#include <time.h>
2424
#include "timeline.h"
25
+
26
+/*
27
+** Add an appropriate tag to the output if "rid" is unpublished (private)
28
+*/
29
+#define UNPUB_TAG "<em>(unpublished)</em>"
30
+void tag_private_status(int rid){
31
+ if( content_is_private(rid) ){
32
+ cgi_printf("%s", UNPUB_TAG);
33
+ }
34
+}
2535
2636
/*
2737
** Generate a hyperlink to a version.
2838
*/
2939
void hyperlink_to_uuid(const char *zUuid){
@@ -77,10 +87,11 @@
7787
#define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
7888
#define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
7989
#define TIMELINE_UCOLOR 0x0080 /* Background color by user */
8090
#define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
8191
#define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
92
+#define TIMELINE_SHOWRID 0x0400 /* Show RID values in addition to UUIDs */
8293
#endif
8394
8495
/*
8596
** Hash a string and use the hash to determine a background color.
8697
*/
@@ -213,11 +224,11 @@
213224
Stmt fchngQuery; /* Query for file changes on check-ins */
214225
static Stmt qbranch;
215226
int pendingEndTr = 0; /* True if a </td></tr> is needed */
216227
int vid = 0; /* Current checkout version */
217228
int dateFormat = 0; /* 0: HH:MM (default) */
218
- char *zDateFmt;
229
+ const char *zDateFmt;
219230
220231
if( fossil_strcmp(g.zIpAddr, "127.0.0.1")==0 && db_open_local(0) ){
221232
vid = db_lget_int("checkout", 0);
222233
}
223234
zPrevDate[0] = 0;
@@ -394,10 +405,13 @@
394405
}
395406
}else if( zType[0]=='e' && tagid ){
396407
hyperlink_to_event_tagid(tagid<0?-tagid:tagid);
397408
}else if( (tmFlags & TIMELINE_ARTID)!=0 ){
398409
hyperlink_to_uuid(zUuid);
410
+ }
411
+ if( tmFlags & TIMELINE_SHOWRID ){
412
+ @ (%d(rid))
399413
}
400414
db_column_blob(pQuery, commentColumn, &comment);
401415
if( zType[0]!='c' ){
402416
/* Comments for anything other than a check-in are generated by
403417
** "fossil rebuild" and expect to be rendered as text/x-fossil-wiki */
@@ -417,11 +431,11 @@
417431
/* Generate the "user: USERNAME" at the end of the comment, together
418432
** with a hyperlink to another timeline for that user.
419433
*/
420434
if( zTagList && zTagList[0]==0 ) zTagList = 0;
421435
if( g.perm.Hyperlink && fossil_strcmp(zDispUser, zThisUser)!=0 ){
422
- char *zLink = mprintf("%R/timeline?u=%h&c=%t&nd", zDispUser, zDate);
436
+ char *zLink = mprintf("%R/timeline?u=%h&c=%t&nd&n=200", zDispUser, zDate);
423437
@ (user: %z(href("%z",zLink))%h(zDispUser)</a>%s(zTagList?",":"\051")
424438
}else{
425439
@ (user: %h(zDispUser)%s(zTagList?",":"\051")
426440
}
427441
@@ -442,11 +456,11 @@
442456
while( z && z[0] ){
443457
for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
444458
if( zThisTag==0 || memcmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
445459
blob_appendf(&links,
446460
"%z%#h</a>%.2s",
447
- href("%R/timeline?r=%#t&nd&c=%t",i,z,zDate), i,z, &z[i]
461
+ href("%R/timeline?r=%#t&nd&c=%t&n=200",i,z,zDate), i,z, &z[i]
448462
);
449463
}else{
450464
blob_appendf(&links, "%#h", i+2, z);
451465
}
452466
if( z[i]==0 ) break;
@@ -456,11 +470,11 @@
456470
blob_reset(&links);
457471
}else{
458472
@ tags: %h(zTagList))
459473
}
460474
}
461
-
475
+ tag_private_status(rid);
462476
463477
/* Generate extra hyperlinks at the end of the comment */
464478
if( xExtra ){
465479
xExtra(rid);
466480
}
@@ -471,11 +485,11 @@
471485
){
472486
int inUl = 0;
473487
if( !fchngQueryInit ){
474488
db_prepare(&fchngQuery,
475489
"SELECT (pid==0) AS isnew,"
476
- " (fid==0) AS isdel,"
490
+ " fid,"
477491
" (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
478492
" (SELECT uuid FROM blob WHERE rid=fid),"
479493
" (SELECT uuid FROM blob WHERE rid=pid),"
480494
" (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
481495
" FROM mlink"
@@ -488,14 +502,16 @@
488502
}
489503
db_bind_int(&fchngQuery, ":mid", rid);
490504
while( db_step(&fchngQuery)==SQLITE_ROW ){
491505
const char *zFilename = db_column_text(&fchngQuery, 2);
492506
int isNew = db_column_int(&fchngQuery, 0);
493
- int isDel = db_column_int(&fchngQuery, 1);
507
+ int fid = db_column_int(&fchngQuery, 1);
508
+ int isDel = fid==0;
494509
const char *zOldName = db_column_text(&fchngQuery, 5);
495510
const char *zOld = db_column_text(&fchngQuery, 4);
496511
const char *zNew = db_column_text(&fchngQuery, 3);
512
+ const char *zUnpubTag = "";
497513
if( !inUl ){
498514
@ <ul class="filelist">
499515
inUl = 1;
500516
}
501517
if( (tmFlags & TIMELINE_FRENAMES)!=0 ){
@@ -502,23 +518,26 @@
502518
if( !isNew && !isDel && zOldName!=0 ){
503519
@ <li> %h(zOldName) &rarr; %h(zFilename)
504520
}
505521
continue;
506522
}
523
+ if( content_is_private(fid) ){
524
+ zUnpubTag = UNPUB_TAG;
525
+ }
507526
if( isNew ){
508
- @ <li> %h(zFilename) (new file) &nbsp;
527
+ @ <li> %h(zFilename) %s(zUnpubTag) (new file) &nbsp;
509528
@ %z(href("%R/artifact/%s",zNew))[view]</a></li>
510529
}else if( isDel ){
511530
@ <li> %h(zFilename) (deleted)</li>
512531
}else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
513
- @ <li> %h(zOldName) &rarr; %h(zFilename)
532
+ @ <li> %h(zOldName) &rarr; %h(zFilename) %s(zUnpubTag)
514533
@ %z(href("%R/artifact/%s",zNew))[view]</a></li>
515534
}else{
516535
if( zOldName!=0 ){
517
- @ <li> %h(zOldName) &rarr; %h(zFilename)
536
+ @ <li> %h(zOldName) &rarr; %h(zFilename) %s(zUnpubTag)
518537
}else{
519
- @ <li> %h(zFilename) &nbsp;
538
+ @ <li> %h(zFilename) &nbsp; %s(zUnpubTag)
520539
}
521540
@ %z(href("%R/fdiff?sbs=1&v1=%s&v2=%s",zOld,zNew))[diff]</a></li>
522541
}
523542
}
524543
db_reset(&fchngQuery);
@@ -589,12 +608,12 @@
589608
** for the upward portion of a merge arrow. The merge arrow goes up
590609
** to the row identified by mu:. If this value is zero then
591610
** node has no merge children and no merge-out line is drawn.
592611
** mu: The id of the row which is the top of the merge-out arrow.
593612
** u: Draw a thick child-line out of the top of this node and up to
594
- ** the node with an id equal to this value. 0 if there is no
595
- ** thick-line riser.
613
+ ** the node with an id equal to this value. 0 if it is straight to
614
+ ** the top of the page, -1 if there is no thick-line riser.
596615
** f: 0x01: a leaf node.
597616
** au: An array of integers that define thick-line risers for branches.
598617
** The integers are in pairs. For each pair, the first integer is
599618
** is the rail on which the riser should run and the second integer
600619
** is the id of the node upto which the riser should run.
@@ -1055,11 +1074,11 @@
10551074
const char *zYearMonth = P("ym"); /* Show checkins for the given YYYY-MM */
10561075
const char *zYearWeek = P("yw"); /* Show checkins for the given YYYY-WW (week-of-year)*/
10571076
int useDividers = P("nd")==0; /* Show dividers if "nd" is missing */
10581077
int renameOnly = P("namechng")!=0; /* Show only checkins that rename files */
10591078
int tagid; /* Tag ID */
1060
- int tmFlags; /* Timeline flags */
1079
+ int tmFlags = 0; /* Timeline flags */
10611080
const char *zThisTag = 0; /* Suppress links to this tag */
10621081
const char *zThisUser = 0; /* Suppress links to this user */
10631082
HQuery url; /* URL for various branch links */
10641083
int from_rid = name_to_typed_rid(P("from"),"ci"); /* from= for paths */
10651084
int to_rid = name_to_typed_rid(P("to"),"ci"); /* to= for path timelines */
@@ -1088,16 +1107,22 @@
10881107
tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
10891108
zThisTag = zBrName;
10901109
}else{
10911110
tagid = 0;
10921111
}
1112
+ if( tagid>0
1113
+ && db_int(0,"SELECT count(*) FROM tagxref WHERE tagid=%d",tagid)<=nEntry
1114
+ ){
1115
+ zCirca = zBefore = zAfter = 0;
1116
+ nEntry = -1;
1117
+ }
10931118
if( zType[0]=='a' ){
1094
- tmFlags = TIMELINE_BRIEF | TIMELINE_GRAPH;
1119
+ tmFlags |= TIMELINE_BRIEF | TIMELINE_GRAPH;
10951120
}else{
1096
- tmFlags = TIMELINE_GRAPH;
1121
+ tmFlags |= TIMELINE_GRAPH;
10971122
}
1098
- url_add_parameter(&url, "n", mprintf("%d", nEntry));
1123
+ if( nEntry>0 ) url_add_parameter(&url, "n", mprintf("%d", nEntry));
10991124
if( P("ng")!=0 || zSearch!=0 ){
11001125
tmFlags &= ~TIMELINE_GRAPH;
11011126
url_add_parameter(&url, "ng", 0);
11021127
}
11031128
if( P("brbg")!=0 ){
@@ -1185,10 +1210,11 @@
11851210
}else if( (p_rid || d_rid) && g.perm.Read ){
11861211
/* If p= or d= is present, ignore all other parameters other than n= */
11871212
char *zUuid;
11881213
int np, nd;
11891214
1215
+ tmFlags |= TIMELINE_DISJOINT;
11901216
if( p_rid && d_rid ){
11911217
if( p_rid!=d_rid ) p_rid = d_rid;
11921218
if( P("n")==0 ) nEntry = 10;
11931219
}
11941220
db_multi_exec(
@@ -1229,11 +1255,11 @@
12291255
url_add_parameter(&url, "d", zUuid);
12301256
}
12311257
if( nEntry>20 ){
12321258
timeline_submenu(&url, "20 Entries", "n", "20", 0);
12331259
}
1234
- if( nEntry<200 ){
1260
+ if( nEntry<200 && nEntry>0 ){
12351261
timeline_submenu(&url, "200 Entries", "n", "200", 0);
12361262
}
12371263
if( tmFlags & TIMELINE_FCHANGES ){
12381264
timeline_submenu(&url, "Hide Files", "v", 0, 0);
12391265
}else{
@@ -1373,10 +1399,16 @@
13731399
}else if( zType[0]=='g' ){
13741400
zEType = "tag";
13751401
}
13761402
}
13771403
if( zUser ){
1404
+ int n = db_int(0,"SELECT count(*) FROM event"
1405
+ " WHERE user=%Q OR euser=%Q", zUser, zUser);
1406
+ if( n<=nEntry ){
1407
+ zCirca = zBefore = zAfter = 0;
1408
+ nEntry = -1;
1409
+ }
13781410
blob_append_sql(&sql, " AND (event.user=%Q OR event.euser=%Q)",
13791411
zUser, zUser);
13801412
url_add_parameter(&url, "u", zUser);
13811413
zThisUser = zUser;
13821414
}
@@ -1394,11 +1426,11 @@
13941426
blob_append_sql(&sql,
13951427
" AND event.mtime>=%.17g AND event.mtime<=%.17g"
13961428
" ORDER BY event.mtime ASC", rAfter-ONE_SECOND, rBefore+ONE_SECOND);
13971429
url_add_parameter(&url, "a", zAfter);
13981430
url_add_parameter(&url, "b", zBefore);
1399
- nEntry = 1000000;
1431
+ nEntry = -1;
14001432
}else{
14011433
blob_append_sql(&sql,
14021434
" AND event.mtime>=%.17g ORDER BY event.mtime ASC",
14031435
rAfter-ONE_SECOND);
14041436
url_add_parameter(&url, "a", zAfter);
@@ -1425,19 +1457,19 @@
14251457
if( useDividers ) timeline_add_dividers(rCirca, 0);
14261458
url_add_parameter(&url, "c", zCirca);
14271459
}else{
14281460
blob_append_sql(&sql, " ORDER BY event.mtime DESC");
14291461
}
1430
- blob_append_sql(&sql, " LIMIT %d", nEntry);
1462
+ if( nEntry>0 ) blob_append_sql(&sql, " LIMIT %d", nEntry);
14311463
db_multi_exec("%s", blob_sql_text(&sql));
14321464
14331465
n = db_int(0, "SELECT count(*) FROM timeline WHERE etype!='div' /*scan*/");
14341466
if( zYearMonth ){
14351467
blob_appendf(&desc, "%s events for %h", zEType, zYearMonth);
14361468
}else if( zYearWeek ){
14371469
blob_appendf(&desc, "%s events for year/week %h", zEType, zYearWeek);
1438
- }else if( zAfter==0 && zBefore==0 && zCirca==0 ){
1470
+ }else if( zAfter==0 && zBefore==0 && zCirca==0 && n>=nEntry && nEntry>0 ){
14391471
blob_appendf(&desc, "%d most recent %ss", n, zEType);
14401472
}else{
14411473
blob_appendf(&desc, "%d %ss", n, zEType);
14421474
}
14431475
if( zUses ){
@@ -1484,11 +1516,11 @@
14841516
}
14851517
if( zBefore || (zAfter && n==nEntry) ){
14861518
zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
14871519
timeline_submenu(&url, "Newer", "a", zDate, "b");
14881520
free(zDate);
1489
- }else if( tagid==0 ){
1521
+ }else if( tagid==0 && zUses==0 ){
14901522
if( zType[0]!='a' ){
14911523
timeline_submenu(&url, "All Types", "y", "all", 0);
14921524
}
14931525
if( zType[0]!='w' && g.perm.RdWiki ){
14941526
timeline_submenu(&url, "Wiki Only", "y", "w", 0);
@@ -1507,11 +1539,11 @@
15071539
}
15081540
}
15091541
if( nEntry>20 ){
15101542
timeline_submenu(&url, "20 Entries", "n", "20", 0);
15111543
}
1512
- if( nEntry<200 ){
1544
+ if( nEntry<200 && nEntry>0 ){
15131545
timeline_submenu(&url, "200 Entries", "n", "200", 0);
15141546
}
15151547
if( zType[0]=='a' || zType[0]=='c' ){
15161548
if( tmFlags & TIMELINE_FCHANGES ){
15171549
timeline_submenu(&url, "Hide Files", "v", 0, 0);
@@ -1525,10 +1557,11 @@
15251557
}
15261558
}
15271559
if( P("showsql") ){
15281560
@ <blockquote>%h(blob_sql_text(&sql))</blockquote>
15291561
}
1562
+ if( P("showrid") ) tmFlags |= TIMELINE_SHOWRID;
15301563
blob_zero(&sql);
15311564
db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
15321565
@ <h2>%b(&desc)</h2>
15331566
blob_reset(&desc);
15341567
www_print_timeline(&q, tmFlags, zThisUser, zThisTag, 0);
@@ -1617,11 +1650,15 @@
16171650
sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], zBrType);
16181651
n = strlen(zPrefix);
16191652
}
16201653
if( fossil_strcmp(zCurrentUuid,zId)==0 ){
16211654
sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1622
- n += strlen(zPrefix);
1655
+ n += strlen(zPrefix+n);
1656
+ }
1657
+ if( content_is_private(rid) ){
1658
+ sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*UNPUBLISHED* ");
1659
+ n += strlen(zPrefix+n);
16231660
}
16241661
zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom);
16251662
/* record another X lines */
16261663
nLine += comment_print(zFree, zCom, 9, width, g.comFmtFlags);
16271664
fossil_free(zFree);
16281665
--- src/timeline.c
+++ src/timeline.c
@@ -20,10 +20,20 @@
20 */
21 #include "config.h"
22 #include <string.h>
23 #include <time.h>
24 #include "timeline.h"
 
 
 
 
 
 
 
 
 
 
25
26 /*
27 ** Generate a hyperlink to a version.
28 */
29 void hyperlink_to_uuid(const char *zUuid){
@@ -77,10 +87,11 @@
77 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
78 #define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
79 #define TIMELINE_UCOLOR 0x0080 /* Background color by user */
80 #define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
81 #define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
 
82 #endif
83
84 /*
85 ** Hash a string and use the hash to determine a background color.
86 */
@@ -213,11 +224,11 @@
213 Stmt fchngQuery; /* Query for file changes on check-ins */
214 static Stmt qbranch;
215 int pendingEndTr = 0; /* True if a </td></tr> is needed */
216 int vid = 0; /* Current checkout version */
217 int dateFormat = 0; /* 0: HH:MM (default) */
218 char *zDateFmt;
219
220 if( fossil_strcmp(g.zIpAddr, "127.0.0.1")==0 && db_open_local(0) ){
221 vid = db_lget_int("checkout", 0);
222 }
223 zPrevDate[0] = 0;
@@ -394,10 +405,13 @@
394 }
395 }else if( zType[0]=='e' && tagid ){
396 hyperlink_to_event_tagid(tagid<0?-tagid:tagid);
397 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
398 hyperlink_to_uuid(zUuid);
 
 
 
399 }
400 db_column_blob(pQuery, commentColumn, &comment);
401 if( zType[0]!='c' ){
402 /* Comments for anything other than a check-in are generated by
403 ** "fossil rebuild" and expect to be rendered as text/x-fossil-wiki */
@@ -417,11 +431,11 @@
417 /* Generate the "user: USERNAME" at the end of the comment, together
418 ** with a hyperlink to another timeline for that user.
419 */
420 if( zTagList && zTagList[0]==0 ) zTagList = 0;
421 if( g.perm.Hyperlink && fossil_strcmp(zDispUser, zThisUser)!=0 ){
422 char *zLink = mprintf("%R/timeline?u=%h&c=%t&nd", zDispUser, zDate);
423 @ (user: %z(href("%z",zLink))%h(zDispUser)</a>%s(zTagList?",":"\051")
424 }else{
425 @ (user: %h(zDispUser)%s(zTagList?",":"\051")
426 }
427
@@ -442,11 +456,11 @@
442 while( z && z[0] ){
443 for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
444 if( zThisTag==0 || memcmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
445 blob_appendf(&links,
446 "%z%#h</a>%.2s",
447 href("%R/timeline?r=%#t&nd&c=%t",i,z,zDate), i,z, &z[i]
448 );
449 }else{
450 blob_appendf(&links, "%#h", i+2, z);
451 }
452 if( z[i]==0 ) break;
@@ -456,11 +470,11 @@
456 blob_reset(&links);
457 }else{
458 @ tags: %h(zTagList))
459 }
460 }
461
462
463 /* Generate extra hyperlinks at the end of the comment */
464 if( xExtra ){
465 xExtra(rid);
466 }
@@ -471,11 +485,11 @@
471 ){
472 int inUl = 0;
473 if( !fchngQueryInit ){
474 db_prepare(&fchngQuery,
475 "SELECT (pid==0) AS isnew,"
476 " (fid==0) AS isdel,"
477 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
478 " (SELECT uuid FROM blob WHERE rid=fid),"
479 " (SELECT uuid FROM blob WHERE rid=pid),"
480 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
481 " FROM mlink"
@@ -488,14 +502,16 @@
488 }
489 db_bind_int(&fchngQuery, ":mid", rid);
490 while( db_step(&fchngQuery)==SQLITE_ROW ){
491 const char *zFilename = db_column_text(&fchngQuery, 2);
492 int isNew = db_column_int(&fchngQuery, 0);
493 int isDel = db_column_int(&fchngQuery, 1);
 
494 const char *zOldName = db_column_text(&fchngQuery, 5);
495 const char *zOld = db_column_text(&fchngQuery, 4);
496 const char *zNew = db_column_text(&fchngQuery, 3);
 
497 if( !inUl ){
498 @ <ul class="filelist">
499 inUl = 1;
500 }
501 if( (tmFlags & TIMELINE_FRENAMES)!=0 ){
@@ -502,23 +518,26 @@
502 if( !isNew && !isDel && zOldName!=0 ){
503 @ <li> %h(zOldName) &rarr; %h(zFilename)
504 }
505 continue;
506 }
 
 
 
507 if( isNew ){
508 @ <li> %h(zFilename) (new file) &nbsp;
509 @ %z(href("%R/artifact/%s",zNew))[view]</a></li>
510 }else if( isDel ){
511 @ <li> %h(zFilename) (deleted)</li>
512 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
513 @ <li> %h(zOldName) &rarr; %h(zFilename)
514 @ %z(href("%R/artifact/%s",zNew))[view]</a></li>
515 }else{
516 if( zOldName!=0 ){
517 @ <li> %h(zOldName) &rarr; %h(zFilename)
518 }else{
519 @ <li> %h(zFilename) &nbsp;
520 }
521 @ %z(href("%R/fdiff?sbs=1&v1=%s&v2=%s",zOld,zNew))[diff]</a></li>
522 }
523 }
524 db_reset(&fchngQuery);
@@ -589,12 +608,12 @@
589 ** for the upward portion of a merge arrow. The merge arrow goes up
590 ** to the row identified by mu:. If this value is zero then
591 ** node has no merge children and no merge-out line is drawn.
592 ** mu: The id of the row which is the top of the merge-out arrow.
593 ** u: Draw a thick child-line out of the top of this node and up to
594 ** the node with an id equal to this value. 0 if there is no
595 ** thick-line riser.
596 ** f: 0x01: a leaf node.
597 ** au: An array of integers that define thick-line risers for branches.
598 ** The integers are in pairs. For each pair, the first integer is
599 ** is the rail on which the riser should run and the second integer
600 ** is the id of the node upto which the riser should run.
@@ -1055,11 +1074,11 @@
1055 const char *zYearMonth = P("ym"); /* Show checkins for the given YYYY-MM */
1056 const char *zYearWeek = P("yw"); /* Show checkins for the given YYYY-WW (week-of-year)*/
1057 int useDividers = P("nd")==0; /* Show dividers if "nd" is missing */
1058 int renameOnly = P("namechng")!=0; /* Show only checkins that rename files */
1059 int tagid; /* Tag ID */
1060 int tmFlags; /* Timeline flags */
1061 const char *zThisTag = 0; /* Suppress links to this tag */
1062 const char *zThisUser = 0; /* Suppress links to this user */
1063 HQuery url; /* URL for various branch links */
1064 int from_rid = name_to_typed_rid(P("from"),"ci"); /* from= for paths */
1065 int to_rid = name_to_typed_rid(P("to"),"ci"); /* to= for path timelines */
@@ -1088,16 +1107,22 @@
1088 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
1089 zThisTag = zBrName;
1090 }else{
1091 tagid = 0;
1092 }
 
 
 
 
 
 
1093 if( zType[0]=='a' ){
1094 tmFlags = TIMELINE_BRIEF | TIMELINE_GRAPH;
1095 }else{
1096 tmFlags = TIMELINE_GRAPH;
1097 }
1098 url_add_parameter(&url, "n", mprintf("%d", nEntry));
1099 if( P("ng")!=0 || zSearch!=0 ){
1100 tmFlags &= ~TIMELINE_GRAPH;
1101 url_add_parameter(&url, "ng", 0);
1102 }
1103 if( P("brbg")!=0 ){
@@ -1185,10 +1210,11 @@
1185 }else if( (p_rid || d_rid) && g.perm.Read ){
1186 /* If p= or d= is present, ignore all other parameters other than n= */
1187 char *zUuid;
1188 int np, nd;
1189
 
1190 if( p_rid && d_rid ){
1191 if( p_rid!=d_rid ) p_rid = d_rid;
1192 if( P("n")==0 ) nEntry = 10;
1193 }
1194 db_multi_exec(
@@ -1229,11 +1255,11 @@
1229 url_add_parameter(&url, "d", zUuid);
1230 }
1231 if( nEntry>20 ){
1232 timeline_submenu(&url, "20 Entries", "n", "20", 0);
1233 }
1234 if( nEntry<200 ){
1235 timeline_submenu(&url, "200 Entries", "n", "200", 0);
1236 }
1237 if( tmFlags & TIMELINE_FCHANGES ){
1238 timeline_submenu(&url, "Hide Files", "v", 0, 0);
1239 }else{
@@ -1373,10 +1399,16 @@
1373 }else if( zType[0]=='g' ){
1374 zEType = "tag";
1375 }
1376 }
1377 if( zUser ){
 
 
 
 
 
 
1378 blob_append_sql(&sql, " AND (event.user=%Q OR event.euser=%Q)",
1379 zUser, zUser);
1380 url_add_parameter(&url, "u", zUser);
1381 zThisUser = zUser;
1382 }
@@ -1394,11 +1426,11 @@
1394 blob_append_sql(&sql,
1395 " AND event.mtime>=%.17g AND event.mtime<=%.17g"
1396 " ORDER BY event.mtime ASC", rAfter-ONE_SECOND, rBefore+ONE_SECOND);
1397 url_add_parameter(&url, "a", zAfter);
1398 url_add_parameter(&url, "b", zBefore);
1399 nEntry = 1000000;
1400 }else{
1401 blob_append_sql(&sql,
1402 " AND event.mtime>=%.17g ORDER BY event.mtime ASC",
1403 rAfter-ONE_SECOND);
1404 url_add_parameter(&url, "a", zAfter);
@@ -1425,19 +1457,19 @@
1425 if( useDividers ) timeline_add_dividers(rCirca, 0);
1426 url_add_parameter(&url, "c", zCirca);
1427 }else{
1428 blob_append_sql(&sql, " ORDER BY event.mtime DESC");
1429 }
1430 blob_append_sql(&sql, " LIMIT %d", nEntry);
1431 db_multi_exec("%s", blob_sql_text(&sql));
1432
1433 n = db_int(0, "SELECT count(*) FROM timeline WHERE etype!='div' /*scan*/");
1434 if( zYearMonth ){
1435 blob_appendf(&desc, "%s events for %h", zEType, zYearMonth);
1436 }else if( zYearWeek ){
1437 blob_appendf(&desc, "%s events for year/week %h", zEType, zYearWeek);
1438 }else if( zAfter==0 && zBefore==0 && zCirca==0 ){
1439 blob_appendf(&desc, "%d most recent %ss", n, zEType);
1440 }else{
1441 blob_appendf(&desc, "%d %ss", n, zEType);
1442 }
1443 if( zUses ){
@@ -1484,11 +1516,11 @@
1484 }
1485 if( zBefore || (zAfter && n==nEntry) ){
1486 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1487 timeline_submenu(&url, "Newer", "a", zDate, "b");
1488 free(zDate);
1489 }else if( tagid==0 ){
1490 if( zType[0]!='a' ){
1491 timeline_submenu(&url, "All Types", "y", "all", 0);
1492 }
1493 if( zType[0]!='w' && g.perm.RdWiki ){
1494 timeline_submenu(&url, "Wiki Only", "y", "w", 0);
@@ -1507,11 +1539,11 @@
1507 }
1508 }
1509 if( nEntry>20 ){
1510 timeline_submenu(&url, "20 Entries", "n", "20", 0);
1511 }
1512 if( nEntry<200 ){
1513 timeline_submenu(&url, "200 Entries", "n", "200", 0);
1514 }
1515 if( zType[0]=='a' || zType[0]=='c' ){
1516 if( tmFlags & TIMELINE_FCHANGES ){
1517 timeline_submenu(&url, "Hide Files", "v", 0, 0);
@@ -1525,10 +1557,11 @@
1525 }
1526 }
1527 if( P("showsql") ){
1528 @ <blockquote>%h(blob_sql_text(&sql))</blockquote>
1529 }
 
1530 blob_zero(&sql);
1531 db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
1532 @ <h2>%b(&desc)</h2>
1533 blob_reset(&desc);
1534 www_print_timeline(&q, tmFlags, zThisUser, zThisTag, 0);
@@ -1617,11 +1650,15 @@
1617 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], zBrType);
1618 n = strlen(zPrefix);
1619 }
1620 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1621 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1622 n += strlen(zPrefix);
 
 
 
 
1623 }
1624 zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom);
1625 /* record another X lines */
1626 nLine += comment_print(zFree, zCom, 9, width, g.comFmtFlags);
1627 fossil_free(zFree);
1628
--- src/timeline.c
+++ src/timeline.c
@@ -20,10 +20,20 @@
20 */
21 #include "config.h"
22 #include <string.h>
23 #include <time.h>
24 #include "timeline.h"
25
26 /*
27 ** Add an appropriate tag to the output if "rid" is unpublished (private)
28 */
29 #define UNPUB_TAG "<em>(unpublished)</em>"
30 void tag_private_status(int rid){
31 if( content_is_private(rid) ){
32 cgi_printf("%s", UNPUB_TAG);
33 }
34 }
35
36 /*
37 ** Generate a hyperlink to a version.
38 */
39 void hyperlink_to_uuid(const char *zUuid){
@@ -77,10 +87,11 @@
87 #define TIMELINE_FCHANGES 0x0020 /* Detail file changes */
88 #define TIMELINE_BRCOLOR 0x0040 /* Background color by branch name */
89 #define TIMELINE_UCOLOR 0x0080 /* Background color by user */
90 #define TIMELINE_FRENAMES 0x0100 /* Detail only file name changes */
91 #define TIMELINE_UNHIDE 0x0200 /* Unhide check-ins with "hidden" tag */
92 #define TIMELINE_SHOWRID 0x0400 /* Show RID values in addition to UUIDs */
93 #endif
94
95 /*
96 ** Hash a string and use the hash to determine a background color.
97 */
@@ -213,11 +224,11 @@
224 Stmt fchngQuery; /* Query for file changes on check-ins */
225 static Stmt qbranch;
226 int pendingEndTr = 0; /* True if a </td></tr> is needed */
227 int vid = 0; /* Current checkout version */
228 int dateFormat = 0; /* 0: HH:MM (default) */
229 const char *zDateFmt;
230
231 if( fossil_strcmp(g.zIpAddr, "127.0.0.1")==0 && db_open_local(0) ){
232 vid = db_lget_int("checkout", 0);
233 }
234 zPrevDate[0] = 0;
@@ -394,10 +405,13 @@
405 }
406 }else if( zType[0]=='e' && tagid ){
407 hyperlink_to_event_tagid(tagid<0?-tagid:tagid);
408 }else if( (tmFlags & TIMELINE_ARTID)!=0 ){
409 hyperlink_to_uuid(zUuid);
410 }
411 if( tmFlags & TIMELINE_SHOWRID ){
412 @ (%d(rid))
413 }
414 db_column_blob(pQuery, commentColumn, &comment);
415 if( zType[0]!='c' ){
416 /* Comments for anything other than a check-in are generated by
417 ** "fossil rebuild" and expect to be rendered as text/x-fossil-wiki */
@@ -417,11 +431,11 @@
431 /* Generate the "user: USERNAME" at the end of the comment, together
432 ** with a hyperlink to another timeline for that user.
433 */
434 if( zTagList && zTagList[0]==0 ) zTagList = 0;
435 if( g.perm.Hyperlink && fossil_strcmp(zDispUser, zThisUser)!=0 ){
436 char *zLink = mprintf("%R/timeline?u=%h&c=%t&nd&n=200", zDispUser, zDate);
437 @ (user: %z(href("%z",zLink))%h(zDispUser)</a>%s(zTagList?",":"\051")
438 }else{
439 @ (user: %h(zDispUser)%s(zTagList?",":"\051")
440 }
441
@@ -442,11 +456,11 @@
456 while( z && z[0] ){
457 for(i=0; z[i] && (z[i]!=',' || z[i+1]!=' '); i++){}
458 if( zThisTag==0 || memcmp(z, zThisTag, i)!=0 || zThisTag[i]!=0 ){
459 blob_appendf(&links,
460 "%z%#h</a>%.2s",
461 href("%R/timeline?r=%#t&nd&c=%t&n=200",i,z,zDate), i,z, &z[i]
462 );
463 }else{
464 blob_appendf(&links, "%#h", i+2, z);
465 }
466 if( z[i]==0 ) break;
@@ -456,11 +470,11 @@
470 blob_reset(&links);
471 }else{
472 @ tags: %h(zTagList))
473 }
474 }
475 tag_private_status(rid);
476
477 /* Generate extra hyperlinks at the end of the comment */
478 if( xExtra ){
479 xExtra(rid);
480 }
@@ -471,11 +485,11 @@
485 ){
486 int inUl = 0;
487 if( !fchngQueryInit ){
488 db_prepare(&fchngQuery,
489 "SELECT (pid==0) AS isnew,"
490 " fid,"
491 " (SELECT name FROM filename WHERE fnid=mlink.fnid) AS name,"
492 " (SELECT uuid FROM blob WHERE rid=fid),"
493 " (SELECT uuid FROM blob WHERE rid=pid),"
494 " (SELECT name FROM filename WHERE fnid=mlink.pfnid) AS oldnm"
495 " FROM mlink"
@@ -488,14 +502,16 @@
502 }
503 db_bind_int(&fchngQuery, ":mid", rid);
504 while( db_step(&fchngQuery)==SQLITE_ROW ){
505 const char *zFilename = db_column_text(&fchngQuery, 2);
506 int isNew = db_column_int(&fchngQuery, 0);
507 int fid = db_column_int(&fchngQuery, 1);
508 int isDel = fid==0;
509 const char *zOldName = db_column_text(&fchngQuery, 5);
510 const char *zOld = db_column_text(&fchngQuery, 4);
511 const char *zNew = db_column_text(&fchngQuery, 3);
512 const char *zUnpubTag = "";
513 if( !inUl ){
514 @ <ul class="filelist">
515 inUl = 1;
516 }
517 if( (tmFlags & TIMELINE_FRENAMES)!=0 ){
@@ -502,23 +518,26 @@
518 if( !isNew && !isDel && zOldName!=0 ){
519 @ <li> %h(zOldName) &rarr; %h(zFilename)
520 }
521 continue;
522 }
523 if( content_is_private(fid) ){
524 zUnpubTag = UNPUB_TAG;
525 }
526 if( isNew ){
527 @ <li> %h(zFilename) %s(zUnpubTag) (new file) &nbsp;
528 @ %z(href("%R/artifact/%s",zNew))[view]</a></li>
529 }else if( isDel ){
530 @ <li> %h(zFilename) (deleted)</li>
531 }else if( fossil_strcmp(zOld,zNew)==0 && zOldName!=0 ){
532 @ <li> %h(zOldName) &rarr; %h(zFilename) %s(zUnpubTag)
533 @ %z(href("%R/artifact/%s",zNew))[view]</a></li>
534 }else{
535 if( zOldName!=0 ){
536 @ <li> %h(zOldName) &rarr; %h(zFilename) %s(zUnpubTag)
537 }else{
538 @ <li> %h(zFilename) &nbsp; %s(zUnpubTag)
539 }
540 @ %z(href("%R/fdiff?sbs=1&v1=%s&v2=%s",zOld,zNew))[diff]</a></li>
541 }
542 }
543 db_reset(&fchngQuery);
@@ -589,12 +608,12 @@
608 ** for the upward portion of a merge arrow. The merge arrow goes up
609 ** to the row identified by mu:. If this value is zero then
610 ** node has no merge children and no merge-out line is drawn.
611 ** mu: The id of the row which is the top of the merge-out arrow.
612 ** u: Draw a thick child-line out of the top of this node and up to
613 ** the node with an id equal to this value. 0 if it is straight to
614 ** the top of the page, -1 if there is no thick-line riser.
615 ** f: 0x01: a leaf node.
616 ** au: An array of integers that define thick-line risers for branches.
617 ** The integers are in pairs. For each pair, the first integer is
618 ** is the rail on which the riser should run and the second integer
619 ** is the id of the node upto which the riser should run.
@@ -1055,11 +1074,11 @@
1074 const char *zYearMonth = P("ym"); /* Show checkins for the given YYYY-MM */
1075 const char *zYearWeek = P("yw"); /* Show checkins for the given YYYY-WW (week-of-year)*/
1076 int useDividers = P("nd")==0; /* Show dividers if "nd" is missing */
1077 int renameOnly = P("namechng")!=0; /* Show only checkins that rename files */
1078 int tagid; /* Tag ID */
1079 int tmFlags = 0; /* Timeline flags */
1080 const char *zThisTag = 0; /* Suppress links to this tag */
1081 const char *zThisUser = 0; /* Suppress links to this user */
1082 HQuery url; /* URL for various branch links */
1083 int from_rid = name_to_typed_rid(P("from"),"ci"); /* from= for paths */
1084 int to_rid = name_to_typed_rid(P("to"),"ci"); /* to= for path timelines */
@@ -1088,16 +1107,22 @@
1107 tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname='sym-%q'",zBrName);
1108 zThisTag = zBrName;
1109 }else{
1110 tagid = 0;
1111 }
1112 if( tagid>0
1113 && db_int(0,"SELECT count(*) FROM tagxref WHERE tagid=%d",tagid)<=nEntry
1114 ){
1115 zCirca = zBefore = zAfter = 0;
1116 nEntry = -1;
1117 }
1118 if( zType[0]=='a' ){
1119 tmFlags |= TIMELINE_BRIEF | TIMELINE_GRAPH;
1120 }else{
1121 tmFlags |= TIMELINE_GRAPH;
1122 }
1123 if( nEntry>0 ) url_add_parameter(&url, "n", mprintf("%d", nEntry));
1124 if( P("ng")!=0 || zSearch!=0 ){
1125 tmFlags &= ~TIMELINE_GRAPH;
1126 url_add_parameter(&url, "ng", 0);
1127 }
1128 if( P("brbg")!=0 ){
@@ -1185,10 +1210,11 @@
1210 }else if( (p_rid || d_rid) && g.perm.Read ){
1211 /* If p= or d= is present, ignore all other parameters other than n= */
1212 char *zUuid;
1213 int np, nd;
1214
1215 tmFlags |= TIMELINE_DISJOINT;
1216 if( p_rid && d_rid ){
1217 if( p_rid!=d_rid ) p_rid = d_rid;
1218 if( P("n")==0 ) nEntry = 10;
1219 }
1220 db_multi_exec(
@@ -1229,11 +1255,11 @@
1255 url_add_parameter(&url, "d", zUuid);
1256 }
1257 if( nEntry>20 ){
1258 timeline_submenu(&url, "20 Entries", "n", "20", 0);
1259 }
1260 if( nEntry<200 && nEntry>0 ){
1261 timeline_submenu(&url, "200 Entries", "n", "200", 0);
1262 }
1263 if( tmFlags & TIMELINE_FCHANGES ){
1264 timeline_submenu(&url, "Hide Files", "v", 0, 0);
1265 }else{
@@ -1373,10 +1399,16 @@
1399 }else if( zType[0]=='g' ){
1400 zEType = "tag";
1401 }
1402 }
1403 if( zUser ){
1404 int n = db_int(0,"SELECT count(*) FROM event"
1405 " WHERE user=%Q OR euser=%Q", zUser, zUser);
1406 if( n<=nEntry ){
1407 zCirca = zBefore = zAfter = 0;
1408 nEntry = -1;
1409 }
1410 blob_append_sql(&sql, " AND (event.user=%Q OR event.euser=%Q)",
1411 zUser, zUser);
1412 url_add_parameter(&url, "u", zUser);
1413 zThisUser = zUser;
1414 }
@@ -1394,11 +1426,11 @@
1426 blob_append_sql(&sql,
1427 " AND event.mtime>=%.17g AND event.mtime<=%.17g"
1428 " ORDER BY event.mtime ASC", rAfter-ONE_SECOND, rBefore+ONE_SECOND);
1429 url_add_parameter(&url, "a", zAfter);
1430 url_add_parameter(&url, "b", zBefore);
1431 nEntry = -1;
1432 }else{
1433 blob_append_sql(&sql,
1434 " AND event.mtime>=%.17g ORDER BY event.mtime ASC",
1435 rAfter-ONE_SECOND);
1436 url_add_parameter(&url, "a", zAfter);
@@ -1425,19 +1457,19 @@
1457 if( useDividers ) timeline_add_dividers(rCirca, 0);
1458 url_add_parameter(&url, "c", zCirca);
1459 }else{
1460 blob_append_sql(&sql, " ORDER BY event.mtime DESC");
1461 }
1462 if( nEntry>0 ) blob_append_sql(&sql, " LIMIT %d", nEntry);
1463 db_multi_exec("%s", blob_sql_text(&sql));
1464
1465 n = db_int(0, "SELECT count(*) FROM timeline WHERE etype!='div' /*scan*/");
1466 if( zYearMonth ){
1467 blob_appendf(&desc, "%s events for %h", zEType, zYearMonth);
1468 }else if( zYearWeek ){
1469 blob_appendf(&desc, "%s events for year/week %h", zEType, zYearWeek);
1470 }else if( zAfter==0 && zBefore==0 && zCirca==0 && n>=nEntry && nEntry>0 ){
1471 blob_appendf(&desc, "%d most recent %ss", n, zEType);
1472 }else{
1473 blob_appendf(&desc, "%d %ss", n, zEType);
1474 }
1475 if( zUses ){
@@ -1484,11 +1516,11 @@
1516 }
1517 if( zBefore || (zAfter && n==nEntry) ){
1518 zDate = db_text(0, "SELECT max(timestamp) FROM timeline /*scan*/");
1519 timeline_submenu(&url, "Newer", "a", zDate, "b");
1520 free(zDate);
1521 }else if( tagid==0 && zUses==0 ){
1522 if( zType[0]!='a' ){
1523 timeline_submenu(&url, "All Types", "y", "all", 0);
1524 }
1525 if( zType[0]!='w' && g.perm.RdWiki ){
1526 timeline_submenu(&url, "Wiki Only", "y", "w", 0);
@@ -1507,11 +1539,11 @@
1539 }
1540 }
1541 if( nEntry>20 ){
1542 timeline_submenu(&url, "20 Entries", "n", "20", 0);
1543 }
1544 if( nEntry<200 && nEntry>0 ){
1545 timeline_submenu(&url, "200 Entries", "n", "200", 0);
1546 }
1547 if( zType[0]=='a' || zType[0]=='c' ){
1548 if( tmFlags & TIMELINE_FCHANGES ){
1549 timeline_submenu(&url, "Hide Files", "v", 0, 0);
@@ -1525,10 +1557,11 @@
1557 }
1558 }
1559 if( P("showsql") ){
1560 @ <blockquote>%h(blob_sql_text(&sql))</blockquote>
1561 }
1562 if( P("showrid") ) tmFlags |= TIMELINE_SHOWRID;
1563 blob_zero(&sql);
1564 db_prepare(&q, "SELECT * FROM timeline ORDER BY sortby DESC /*scan*/");
1565 @ <h2>%b(&desc)</h2>
1566 blob_reset(&desc);
1567 www_print_timeline(&q, tmFlags, zThisUser, zThisTag, 0);
@@ -1617,11 +1650,15 @@
1650 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], zBrType);
1651 n = strlen(zPrefix);
1652 }
1653 if( fossil_strcmp(zCurrentUuid,zId)==0 ){
1654 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*CURRENT* ");
1655 n += strlen(zPrefix+n);
1656 }
1657 if( content_is_private(rid) ){
1658 sqlite3_snprintf(sizeof(zPrefix)-n, &zPrefix[n], "*UNPUBLISHED* ");
1659 n += strlen(zPrefix+n);
1660 }
1661 zFree = mprintf("[%S] %s%s", zId, zPrefix, zCom);
1662 /* record another X lines */
1663 nLine += comment_print(zFree, zCom, 9, width, g.comFmtFlags);
1664 fossil_free(zFree);
1665
+1 -3
--- src/undo.c
+++ src/undo.c
@@ -127,11 +127,10 @@
127127
** Undo or redo all undoable or redoable changes.
128128
*/
129129
static void undo_all(int redoFlag){
130130
int ucid;
131131
int ncid;
132
- const char *zDb = db_name("localdb");
133132
undo_all_filesystem(redoFlag);
134133
db_multi_exec(
135134
"CREATE TEMP TABLE undo_vfile_2 AS SELECT * FROM vfile;"
136135
"DELETE FROM vfile;"
137136
"INSERT INTO vfile SELECT * FROM undo_vfile;"
@@ -143,12 +142,11 @@
143142
"INSERT INTO vmerge SELECT * FROM undo_vmerge;"
144143
"DELETE FROM undo_vmerge;"
145144
"INSERT INTO undo_vmerge SELECT * FROM undo_vmerge_2;"
146145
"DROP TABLE undo_vmerge_2;"
147146
);
148
- if(db_exists("SELECT 1 FROM \"%w\".sqlite_master"
149
- " WHERE name='undo_stash'", zDb) ){
147
+ if( db_table_exists("localdb", "undo_stash") ){
150148
if( redoFlag ){
151149
db_multi_exec(
152150
"DELETE FROM stash WHERE stashid IN (SELECT stashid FROM undo_stash);"
153151
"DELETE FROM stashfile"
154152
" WHERE stashid NOT IN (SELECT stashid FROM stash);"
155153
--- src/undo.c
+++ src/undo.c
@@ -127,11 +127,10 @@
127 ** Undo or redo all undoable or redoable changes.
128 */
129 static void undo_all(int redoFlag){
130 int ucid;
131 int ncid;
132 const char *zDb = db_name("localdb");
133 undo_all_filesystem(redoFlag);
134 db_multi_exec(
135 "CREATE TEMP TABLE undo_vfile_2 AS SELECT * FROM vfile;"
136 "DELETE FROM vfile;"
137 "INSERT INTO vfile SELECT * FROM undo_vfile;"
@@ -143,12 +142,11 @@
143 "INSERT INTO vmerge SELECT * FROM undo_vmerge;"
144 "DELETE FROM undo_vmerge;"
145 "INSERT INTO undo_vmerge SELECT * FROM undo_vmerge_2;"
146 "DROP TABLE undo_vmerge_2;"
147 );
148 if(db_exists("SELECT 1 FROM \"%w\".sqlite_master"
149 " WHERE name='undo_stash'", zDb) ){
150 if( redoFlag ){
151 db_multi_exec(
152 "DELETE FROM stash WHERE stashid IN (SELECT stashid FROM undo_stash);"
153 "DELETE FROM stashfile"
154 " WHERE stashid NOT IN (SELECT stashid FROM stash);"
155
--- src/undo.c
+++ src/undo.c
@@ -127,11 +127,10 @@
127 ** Undo or redo all undoable or redoable changes.
128 */
129 static void undo_all(int redoFlag){
130 int ucid;
131 int ncid;
 
132 undo_all_filesystem(redoFlag);
133 db_multi_exec(
134 "CREATE TEMP TABLE undo_vfile_2 AS SELECT * FROM vfile;"
135 "DELETE FROM vfile;"
136 "INSERT INTO vfile SELECT * FROM undo_vfile;"
@@ -143,12 +142,11 @@
142 "INSERT INTO vmerge SELECT * FROM undo_vmerge;"
143 "DELETE FROM undo_vmerge;"
144 "INSERT INTO undo_vmerge SELECT * FROM undo_vmerge_2;"
145 "DROP TABLE undo_vmerge_2;"
146 );
147 if( db_table_exists("localdb", "undo_stash") ){
 
148 if( redoFlag ){
149 db_multi_exec(
150 "DELETE FROM stash WHERE stashid IN (SELECT stashid FROM undo_stash);"
151 "DELETE FROM stashfile"
152 " WHERE stashid NOT IN (SELECT stashid FROM stash);"
153
+12 -3
--- src/utf8.c
+++ src/utf8.c
@@ -25,11 +25,11 @@
2525
#ifdef _WIN32
2626
# include <windows.h>
2727
#endif
2828
#include "cygsup.h"
2929
30
-#ifdef _WIN32
30
+#if defined(_WIN32) || defined(__CYGWIN__)
3131
/*
3232
** Translate MBCS to UTF-8. Return a pointer to the translated text.
3333
** Call fossil_mbcs_free() to deallocate any memory used to store the
3434
** returned pointer when done.
3535
*/
@@ -309,10 +309,11 @@
309309
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
310310
#ifdef _WIN32
311311
int nChar, written = 0;
312312
wchar_t *zUnicode; /* Unicode version of zUtf8 */
313313
DWORD dummy;
314
+ Blob blob;
314315
315316
static int istty[2] = { -1, -1 };
316317
if( istty[toStdErr] == -1 ){
317318
istty[toStdErr] = _isatty(toStdErr + 1) != 0;
318319
}
@@ -319,16 +320,24 @@
319320
if( !istty[toStdErr] ){
320321
/* stdout/stderr is not a console. */
321322
return -1;
322323
}
323324
324
- nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, NULL, 0);
325
+ /* If blob to be written to the Windows console is not
326
+ * UTF-8, convert it to UTF-8 first.
327
+ */
328
+ blob_init(&blob, zUtf8, nByte);
329
+ blob_to_utf8_no_bom(&blob, 1);
330
+ nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
331
+ blob_size(&blob), NULL, 0);
325332
zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
326333
if( zUnicode==0 ){
327334
return 0;
328335
}
329
- nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
336
+ nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
337
+ blob_size(&blob), zUnicode, nChar);
338
+ blob_reset(&blob);
330339
/* Split WriteConsoleW call into multiple chunks, if necessary. See:
331340
* <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
332341
while( written < nChar ){
333342
int size = nChar-written;
334343
if( size > 26000 ) size = 26000;
335344
--- src/utf8.c
+++ src/utf8.c
@@ -25,11 +25,11 @@
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
28 #include "cygsup.h"
29
30 #ifdef _WIN32
31 /*
32 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
33 ** Call fossil_mbcs_free() to deallocate any memory used to store the
34 ** returned pointer when done.
35 */
@@ -309,10 +309,11 @@
309 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
310 #ifdef _WIN32
311 int nChar, written = 0;
312 wchar_t *zUnicode; /* Unicode version of zUtf8 */
313 DWORD dummy;
 
314
315 static int istty[2] = { -1, -1 };
316 if( istty[toStdErr] == -1 ){
317 istty[toStdErr] = _isatty(toStdErr + 1) != 0;
318 }
@@ -319,16 +320,24 @@
319 if( !istty[toStdErr] ){
320 /* stdout/stderr is not a console. */
321 return -1;
322 }
323
324 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, NULL, 0);
 
 
 
 
 
 
325 zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
326 if( zUnicode==0 ){
327 return 0;
328 }
329 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
 
 
330 /* Split WriteConsoleW call into multiple chunks, if necessary. See:
331 * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
332 while( written < nChar ){
333 int size = nChar-written;
334 if( size > 26000 ) size = 26000;
335
--- src/utf8.c
+++ src/utf8.c
@@ -25,11 +25,11 @@
25 #ifdef _WIN32
26 # include <windows.h>
27 #endif
28 #include "cygsup.h"
29
30 #if defined(_WIN32) || defined(__CYGWIN__)
31 /*
32 ** Translate MBCS to UTF-8. Return a pointer to the translated text.
33 ** Call fossil_mbcs_free() to deallocate any memory used to store the
34 ** returned pointer when done.
35 */
@@ -309,10 +309,11 @@
309 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
310 #ifdef _WIN32
311 int nChar, written = 0;
312 wchar_t *zUnicode; /* Unicode version of zUtf8 */
313 DWORD dummy;
314 Blob blob;
315
316 static int istty[2] = { -1, -1 };
317 if( istty[toStdErr] == -1 ){
318 istty[toStdErr] = _isatty(toStdErr + 1) != 0;
319 }
@@ -319,16 +320,24 @@
320 if( !istty[toStdErr] ){
321 /* stdout/stderr is not a console. */
322 return -1;
323 }
324
325 /* If blob to be written to the Windows console is not
326 * UTF-8, convert it to UTF-8 first.
327 */
328 blob_init(&blob, zUtf8, nByte);
329 blob_to_utf8_no_bom(&blob, 1);
330 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
331 blob_size(&blob), NULL, 0);
332 zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
333 if( zUnicode==0 ){
334 return 0;
335 }
336 nChar = MultiByteToWideChar(CP_UTF8, 0, blob_buffer(&blob),
337 blob_size(&blob), zUnicode, nChar);
338 blob_reset(&blob);
339 /* Split WriteConsoleW call into multiple chunks, if necessary. See:
340 * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
341 while( written < nChar ){
342 int size = nChar-written;
343 if( size > 26000 ) size = 26000;
344
+1 -1
--- src/xfer.c
+++ src/xfer.c
@@ -532,11 +532,11 @@
532532
** private artifacts if we are not doing a private transfer.
533533
*/
534534
static void request_phantoms(Xfer *pXfer, int maxReq){
535535
Stmt q;
536536
db_prepare(&q,
537
- "SELECT uuid FROM phantom JOIN blob USING(rid)"
537
+ "SELECT uuid FROM phantom CROSS JOIN blob USING(rid) /*scan*/"
538538
" WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s",
539539
(pXfer->syncPrivate ? "" :
540540
" AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)")
541541
);
542542
while( db_step(&q)==SQLITE_ROW && maxReq-- > 0 ){
543543
--- src/xfer.c
+++ src/xfer.c
@@ -532,11 +532,11 @@
532 ** private artifacts if we are not doing a private transfer.
533 */
534 static void request_phantoms(Xfer *pXfer, int maxReq){
535 Stmt q;
536 db_prepare(&q,
537 "SELECT uuid FROM phantom JOIN blob USING(rid)"
538 " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s",
539 (pXfer->syncPrivate ? "" :
540 " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)")
541 );
542 while( db_step(&q)==SQLITE_ROW && maxReq-- > 0 ){
543
--- src/xfer.c
+++ src/xfer.c
@@ -532,11 +532,11 @@
532 ** private artifacts if we are not doing a private transfer.
533 */
534 static void request_phantoms(Xfer *pXfer, int maxReq){
535 Stmt q;
536 db_prepare(&q,
537 "SELECT uuid FROM phantom CROSS JOIN blob USING(rid) /*scan*/"
538 " WHERE NOT EXISTS(SELECT 1 FROM shun WHERE uuid=blob.uuid) %s",
539 (pXfer->syncPrivate ? "" :
540 " AND NOT EXISTS(SELECT 1 FROM private WHERE rid=blob.rid)")
541 );
542 while( db_step(&q)==SQLITE_ROW && maxReq-- > 0 ){
543
--- test/valgrind-www.tcl
+++ test/valgrind-www.tcl
@@ -1,10 +1,10 @@
11
#!/usr/bin/tclsh
22
#
3
-# Run this script in an open Fossil checkout at the top-level with a
3
+# Run this script in an open Fossil checkout at the top-level with a
44
# fresh build of Fossil itself. This script will run fossil on hundreds
5
-# of different web-pages looking for memory allocation problems using
5
+# of different web-pages looking for memory allocation problems using
66
# valgrind. Valgrind output appears on stderr. Suggested test scenario:
77
#
88
# make
99
# tclsh valgrind-www.tcl 2>&1 | tee valgrind-out.txt
1010
#
1111
--- test/valgrind-www.tcl
+++ test/valgrind-www.tcl
@@ -1,10 +1,10 @@
1 #!/usr/bin/tclsh
2 #
3 # Run this script in an open Fossil checkout at the top-level with a
4 # fresh build of Fossil itself. This script will run fossil on hundreds
5 # of different web-pages looking for memory allocation problems using
6 # valgrind. Valgrind output appears on stderr. Suggested test scenario:
7 #
8 # make
9 # tclsh valgrind-www.tcl 2>&1 | tee valgrind-out.txt
10 #
11
--- test/valgrind-www.tcl
+++ test/valgrind-www.tcl
@@ -1,10 +1,10 @@
1 #!/usr/bin/tclsh
2 #
3 # Run this script in an open Fossil checkout at the top-level with a
4 # fresh build of Fossil itself. This script will run fossil on hundreds
5 # of different web-pages looking for memory allocation problems using
6 # valgrind. Valgrind output appears on stderr. Suggested test scenario:
7 #
8 # make
9 # tclsh valgrind-www.tcl 2>&1 | tee valgrind-out.txt
10 #
11
--- tools/fossil_chat.tcl
+++ tools/fossil_chat.tcl
@@ -84,11 +84,11 @@
8484
catch {close $SOCKET}
8585
if {[catch {
8686
if {$::PROXYHOST ne {}} {
8787
set SOCKET [socket $::PROXYHOST $::PROXYPORT]
8888
puts $SOCKET "CONNECT $::SERVERHOST:$::SERVERPORT HTTP/1.1"
89
- puts $SOCKET "Host: $::SERVERHOST:$::SERVERPORT"
89
+ puts $SOCKET "Host: $::SERVERHOST:$::SERVERPORT"
9090
puts $SOCKET ""
9191
} else {
9292
set SOCKET [socket $::SERVERHOST $::SERVERPORT]
9393
}
9494
fconfigure $SOCKET -translation binary -blocking 0
@@ -142,11 +142,11 @@
142142
#
143143
proc delete_files {} {
144144
global FILES
145145
.mb.files delete 3 end
146146
array unset FILES
147
- .mb.files entryconfigure 1 -state disabled
147
+ .mb.files entryconfigure 1 -state disabled
148148
}
149149
150150
# Prompt the user to select a file from the disk. Then send that
151151
# file to all chat participants.
152152
#
@@ -188,11 +188,11 @@
188188
if {![info exists prior] || $filename!=$prior} {
189189
.mb.files add command -label "Save \"$filename\"" \
190190
-command [list save_file $filename]
191191
}
192192
set FILES($filename) $data
193
- .mb.files entryconfigure 1 -state active
193
+ .mb.files entryconfigure 1 -state active
194194
set time [clock format [clock seconds] -format {%H:%M} -gmt 1]
195195
.msg.t insert end "\[$time $from\] " meta "File: \"$filename\"\n" norm
196196
.msg.t see end
197197
}
198198
@@ -232,11 +232,11 @@
232232
} elseif {$cmd=="file"} {
233233
if {[info commands handle_file]=="handle_file"} {
234234
handle_file [lindex $line 1] [lindex $line 2] [lindex $line 3]
235235
}
236236
}
237
-}
237
+}
238238
239239
# Handle a broken socket connection
240240
#
241241
proc disconnect {} {
242242
global SOCKET
243243
--- tools/fossil_chat.tcl
+++ tools/fossil_chat.tcl
@@ -84,11 +84,11 @@
84 catch {close $SOCKET}
85 if {[catch {
86 if {$::PROXYHOST ne {}} {
87 set SOCKET [socket $::PROXYHOST $::PROXYPORT]
88 puts $SOCKET "CONNECT $::SERVERHOST:$::SERVERPORT HTTP/1.1"
89 puts $SOCKET "Host: $::SERVERHOST:$::SERVERPORT"
90 puts $SOCKET ""
91 } else {
92 set SOCKET [socket $::SERVERHOST $::SERVERPORT]
93 }
94 fconfigure $SOCKET -translation binary -blocking 0
@@ -142,11 +142,11 @@
142 #
143 proc delete_files {} {
144 global FILES
145 .mb.files delete 3 end
146 array unset FILES
147 .mb.files entryconfigure 1 -state disabled
148 }
149
150 # Prompt the user to select a file from the disk. Then send that
151 # file to all chat participants.
152 #
@@ -188,11 +188,11 @@
188 if {![info exists prior] || $filename!=$prior} {
189 .mb.files add command -label "Save \"$filename\"" \
190 -command [list save_file $filename]
191 }
192 set FILES($filename) $data
193 .mb.files entryconfigure 1 -state active
194 set time [clock format [clock seconds] -format {%H:%M} -gmt 1]
195 .msg.t insert end "\[$time $from\] " meta "File: \"$filename\"\n" norm
196 .msg.t see end
197 }
198
@@ -232,11 +232,11 @@
232 } elseif {$cmd=="file"} {
233 if {[info commands handle_file]=="handle_file"} {
234 handle_file [lindex $line 1] [lindex $line 2] [lindex $line 3]
235 }
236 }
237 }
238
239 # Handle a broken socket connection
240 #
241 proc disconnect {} {
242 global SOCKET
243
--- tools/fossil_chat.tcl
+++ tools/fossil_chat.tcl
@@ -84,11 +84,11 @@
84 catch {close $SOCKET}
85 if {[catch {
86 if {$::PROXYHOST ne {}} {
87 set SOCKET [socket $::PROXYHOST $::PROXYPORT]
88 puts $SOCKET "CONNECT $::SERVERHOST:$::SERVERPORT HTTP/1.1"
89 puts $SOCKET "Host: $::SERVERHOST:$::SERVERPORT"
90 puts $SOCKET ""
91 } else {
92 set SOCKET [socket $::SERVERHOST $::SERVERPORT]
93 }
94 fconfigure $SOCKET -translation binary -blocking 0
@@ -142,11 +142,11 @@
142 #
143 proc delete_files {} {
144 global FILES
145 .mb.files delete 3 end
146 array unset FILES
147 .mb.files entryconfigure 1 -state disabled
148 }
149
150 # Prompt the user to select a file from the disk. Then send that
151 # file to all chat participants.
152 #
@@ -188,11 +188,11 @@
188 if {![info exists prior] || $filename!=$prior} {
189 .mb.files add command -label "Save \"$filename\"" \
190 -command [list save_file $filename]
191 }
192 set FILES($filename) $data
193 .mb.files entryconfigure 1 -state active
194 set time [clock format [clock seconds] -format {%H:%M} -gmt 1]
195 .msg.t insert end "\[$time $from\] " meta "File: \"$filename\"\n" norm
196 .msg.t see end
197 }
198
@@ -232,11 +232,11 @@
232 } elseif {$cmd=="file"} {
233 if {[info commands handle_file]=="handle_file"} {
234 handle_file [lindex $line 1] [lindex $line 2] [lindex $line 3]
235 }
236 }
237 }
238
239 # Handle a broken socket connection
240 #
241 proc disconnect {} {
242 global SOCKET
243
+34 -4
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -28,13 +28,13 @@
2828
2929
SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
3030
3131
SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3232
33
-SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
33
+SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3434
35
-OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
35
+OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3636
3737
3838
RC=$(DMDIR)\bin\rcc
3939
RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
4040
@@ -49,11 +49,11 @@
4949
5050
$(OBJDIR)\fossil.res: $B\win\fossil.rc
5151
$(RC) $(RCFLAGS) -o$@ $**
5252
5353
$(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54
- +echo add allrepo attach bag bisect blob branch browse builtin cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf rebuild regexp report rss schema search setup sha1 shun skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
54
+ +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
5555
+echo fossil >> $@
5656
+echo fossil >> $@
5757
+echo $(LIBS) >> $@
5858
+echo. >> $@
5959
+echo fossil >> $@
@@ -176,10 +176,16 @@
176176
$(OBJDIR)\builtin$O : builtin_.c builtin.h
177177
$(TCC) -o$@ -c builtin_.c
178178
179179
builtin_.c : $(SRCDIR)\builtin.c
180180
+translate$E $** > $@
181
+
182
+$(OBJDIR)\bundle$O : bundle_.c bundle.h
183
+ $(TCC) -o$@ -c bundle_.c
184
+
185
+bundle_.c : $(SRCDIR)\bundle.c
186
+ +translate$E $** > $@
181187
182188
$(OBJDIR)\cache$O : cache_.c cache.h
183189
$(TCC) -o$@ -c cache_.c
184190
185191
cache_.c : $(SRCDIR)\cache.c
@@ -308,10 +314,16 @@
308314
$(OBJDIR)\finfo$O : finfo_.c finfo.h
309315
$(TCC) -o$@ -c finfo_.c
310316
311317
finfo_.c : $(SRCDIR)\finfo.c
312318
+translate$E $** > $@
319
+
320
+$(OBJDIR)\foci$O : foci_.c foci.h
321
+ $(TCC) -o$@ -c foci_.c
322
+
323
+foci_.c : $(SRCDIR)\foci.c
324
+ +translate$E $** > $@
313325
314326
$(OBJDIR)\fusefs$O : fusefs_.c fusefs.h
315327
$(TCC) -o$@ -c fusefs_.c
316328
317329
fusefs_.c : $(SRCDIR)\fusefs.c
@@ -566,10 +578,22 @@
566578
$(OBJDIR)\printf$O : printf_.c printf.h
567579
$(TCC) -o$@ -c printf_.c
568580
569581
printf_.c : $(SRCDIR)\printf.c
570582
+translate$E $** > $@
583
+
584
+$(OBJDIR)\publish$O : publish_.c publish.h
585
+ $(TCC) -o$@ -c publish_.c
586
+
587
+publish_.c : $(SRCDIR)\publish.c
588
+ +translate$E $** > $@
589
+
590
+$(OBJDIR)\purge$O : purge_.c purge.h
591
+ $(TCC) -o$@ -c purge_.c
592
+
593
+purge_.c : $(SRCDIR)\purge.c
594
+ +translate$E $** > $@
571595
572596
$(OBJDIR)\rebuild$O : rebuild_.c rebuild.h
573597
$(TCC) -o$@ -c rebuild_.c
574598
575599
rebuild_.c : $(SRCDIR)\rebuild.c
@@ -620,10 +644,16 @@
620644
$(OBJDIR)\shun$O : shun_.c shun.h
621645
$(TCC) -o$@ -c shun_.c
622646
623647
shun_.c : $(SRCDIR)\shun.c
624648
+translate$E $** > $@
649
+
650
+$(OBJDIR)\sitemap$O : sitemap_.c sitemap.h
651
+ $(TCC) -o$@ -c sitemap_.c
652
+
653
+sitemap_.c : $(SRCDIR)\sitemap.c
654
+ +translate$E $** > $@
625655
626656
$(OBJDIR)\skins$O : skins_.c skins.h
627657
$(TCC) -o$@ -c skins_.c
628658
629659
skins_.c : $(SRCDIR)\skins.c
@@ -796,7 +826,7 @@
796826
797827
zip_.c : $(SRCDIR)\zip.c
798828
+translate$E $** > $@
799829
800830
headers: makeheaders$E page_index.h builtin_data.h VERSION.h
801
- +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h cache_.c:cache.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h regexp_.c:regexp.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
831
+ +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
802832
@copy /Y nul: headers
803833
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -28,13 +28,13 @@
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
38 RC=$(DMDIR)\bin\rcc
39 RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
40
@@ -49,11 +49,11 @@
49
50 $(OBJDIR)\fossil.res: $B\win\fossil.rc
51 $(RC) $(RCFLAGS) -o$@ $**
52
53 $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54 +echo add allrepo attach bag bisect blob branch browse builtin cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf rebuild regexp report rss schema search setup sha1 shun skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
55 +echo fossil >> $@
56 +echo fossil >> $@
57 +echo $(LIBS) >> $@
58 +echo. >> $@
59 +echo fossil >> $@
@@ -176,10 +176,16 @@
176 $(OBJDIR)\builtin$O : builtin_.c builtin.h
177 $(TCC) -o$@ -c builtin_.c
178
179 builtin_.c : $(SRCDIR)\builtin.c
180 +translate$E $** > $@
 
 
 
 
 
 
181
182 $(OBJDIR)\cache$O : cache_.c cache.h
183 $(TCC) -o$@ -c cache_.c
184
185 cache_.c : $(SRCDIR)\cache.c
@@ -308,10 +314,16 @@
308 $(OBJDIR)\finfo$O : finfo_.c finfo.h
309 $(TCC) -o$@ -c finfo_.c
310
311 finfo_.c : $(SRCDIR)\finfo.c
312 +translate$E $** > $@
 
 
 
 
 
 
313
314 $(OBJDIR)\fusefs$O : fusefs_.c fusefs.h
315 $(TCC) -o$@ -c fusefs_.c
316
317 fusefs_.c : $(SRCDIR)\fusefs.c
@@ -566,10 +578,22 @@
566 $(OBJDIR)\printf$O : printf_.c printf.h
567 $(TCC) -o$@ -c printf_.c
568
569 printf_.c : $(SRCDIR)\printf.c
570 +translate$E $** > $@
 
 
 
 
 
 
 
 
 
 
 
 
571
572 $(OBJDIR)\rebuild$O : rebuild_.c rebuild.h
573 $(TCC) -o$@ -c rebuild_.c
574
575 rebuild_.c : $(SRCDIR)\rebuild.c
@@ -620,10 +644,16 @@
620 $(OBJDIR)\shun$O : shun_.c shun.h
621 $(TCC) -o$@ -c shun_.c
622
623 shun_.c : $(SRCDIR)\shun.c
624 +translate$E $** > $@
 
 
 
 
 
 
625
626 $(OBJDIR)\skins$O : skins_.c skins.h
627 $(TCC) -o$@ -c skins_.c
628
629 skins_.c : $(SRCDIR)\skins.c
@@ -796,7 +826,7 @@
796
797 zip_.c : $(SRCDIR)\zip.c
798 +translate$E $** > $@
799
800 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
801 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h cache_.c:cache.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h rebuild_.c:rebuild.h regexp_.c:regexp.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
802 @copy /Y nul: headers
803
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -28,13 +28,13 @@
28
29 SQLITE_OPTIONS = -DNDEBUG=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Daccess=file_access -Dsystem=fossil_system -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c builtin_.c bundle_.c cache_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c foci_.c fusefs_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c loadctrl_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c publish_.c purge_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c sitemap_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\builtin$O $(OBJDIR)\bundle$O $(OBJDIR)\cache$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\foci$O $(OBJDIR)\fusefs$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\loadctrl$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\publish$O $(OBJDIR)\purge$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\sitemap$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
38 RC=$(DMDIR)\bin\rcc
39 RCFLAGS=-32 -w1 -I$(SRCDIR) /D__DMC__
40
@@ -49,11 +49,11 @@
49
50 $(OBJDIR)\fossil.res: $B\win\fossil.rc
51 $(RC) $(RCFLAGS) -o$@ $**
52
53 $(OBJDIR)\link: $B\win\Makefile.dmc $(OBJDIR)\fossil.res
54 +echo add allrepo attach bag bisect blob branch browse builtin bundle cache captcha cgi checkin checkout clearsign clone comformat configure content db delta deltacmd descendants diff diffcmd doc encode event export file finfo foci fusefs glob graph gzip http http_socket http_ssl http_transport import info json json_artifact json_branch json_config json_diff json_dir json_finfo json_login json_query json_report json_status json_tag json_timeline json_user json_wiki leaf loadctrl login lookslike main manifest markdown markdown_html md5 merge merge3 moderate name path pivot popen pqueue printf publish purge rebuild regexp report rss schema search setup sha1 shun sitemap skins sqlcmd stash stat style sync tag tar th_main timeline tkt tktsetup undo unicode update url user utf8 util verify vfile wiki wikiformat winfile winhttp wysiwyg xfer xfersetup zip shell sqlite3 th th_lang > $@
55 +echo fossil >> $@
56 +echo fossil >> $@
57 +echo $(LIBS) >> $@
58 +echo. >> $@
59 +echo fossil >> $@
@@ -176,10 +176,16 @@
176 $(OBJDIR)\builtin$O : builtin_.c builtin.h
177 $(TCC) -o$@ -c builtin_.c
178
179 builtin_.c : $(SRCDIR)\builtin.c
180 +translate$E $** > $@
181
182 $(OBJDIR)\bundle$O : bundle_.c bundle.h
183 $(TCC) -o$@ -c bundle_.c
184
185 bundle_.c : $(SRCDIR)\bundle.c
186 +translate$E $** > $@
187
188 $(OBJDIR)\cache$O : cache_.c cache.h
189 $(TCC) -o$@ -c cache_.c
190
191 cache_.c : $(SRCDIR)\cache.c
@@ -308,10 +314,16 @@
314 $(OBJDIR)\finfo$O : finfo_.c finfo.h
315 $(TCC) -o$@ -c finfo_.c
316
317 finfo_.c : $(SRCDIR)\finfo.c
318 +translate$E $** > $@
319
320 $(OBJDIR)\foci$O : foci_.c foci.h
321 $(TCC) -o$@ -c foci_.c
322
323 foci_.c : $(SRCDIR)\foci.c
324 +translate$E $** > $@
325
326 $(OBJDIR)\fusefs$O : fusefs_.c fusefs.h
327 $(TCC) -o$@ -c fusefs_.c
328
329 fusefs_.c : $(SRCDIR)\fusefs.c
@@ -566,10 +578,22 @@
578 $(OBJDIR)\printf$O : printf_.c printf.h
579 $(TCC) -o$@ -c printf_.c
580
581 printf_.c : $(SRCDIR)\printf.c
582 +translate$E $** > $@
583
584 $(OBJDIR)\publish$O : publish_.c publish.h
585 $(TCC) -o$@ -c publish_.c
586
587 publish_.c : $(SRCDIR)\publish.c
588 +translate$E $** > $@
589
590 $(OBJDIR)\purge$O : purge_.c purge.h
591 $(TCC) -o$@ -c purge_.c
592
593 purge_.c : $(SRCDIR)\purge.c
594 +translate$E $** > $@
595
596 $(OBJDIR)\rebuild$O : rebuild_.c rebuild.h
597 $(TCC) -o$@ -c rebuild_.c
598
599 rebuild_.c : $(SRCDIR)\rebuild.c
@@ -620,10 +644,16 @@
644 $(OBJDIR)\shun$O : shun_.c shun.h
645 $(TCC) -o$@ -c shun_.c
646
647 shun_.c : $(SRCDIR)\shun.c
648 +translate$E $** > $@
649
650 $(OBJDIR)\sitemap$O : sitemap_.c sitemap.h
651 $(TCC) -o$@ -c sitemap_.c
652
653 sitemap_.c : $(SRCDIR)\sitemap.c
654 +translate$E $** > $@
655
656 $(OBJDIR)\skins$O : skins_.c skins.h
657 $(TCC) -o$@ -c skins_.c
658
659 skins_.c : $(SRCDIR)\skins.c
@@ -796,7 +826,7 @@
826
827 zip_.c : $(SRCDIR)\zip.c
828 +translate$E $** > $@
829
830 headers: makeheaders$E page_index.h builtin_data.h VERSION.h
831 +makeheaders$E add_.c:add.h allrepo_.c:allrepo.h attach_.c:attach.h bag_.c:bag.h bisect_.c:bisect.h blob_.c:blob.h branch_.c:branch.h browse_.c:browse.h builtin_.c:builtin.h bundle_.c:bundle.h cache_.c:cache.h captcha_.c:captcha.h cgi_.c:cgi.h checkin_.c:checkin.h checkout_.c:checkout.h clearsign_.c:clearsign.h clone_.c:clone.h comformat_.c:comformat.h configure_.c:configure.h content_.c:content.h db_.c:db.h delta_.c:delta.h deltacmd_.c:deltacmd.h descendants_.c:descendants.h diff_.c:diff.h diffcmd_.c:diffcmd.h doc_.c:doc.h encode_.c:encode.h event_.c:event.h export_.c:export.h file_.c:file.h finfo_.c:finfo.h foci_.c:foci.h fusefs_.c:fusefs.h glob_.c:glob.h graph_.c:graph.h gzip_.c:gzip.h http_.c:http.h http_socket_.c:http_socket.h http_ssl_.c:http_ssl.h http_transport_.c:http_transport.h import_.c:import.h info_.c:info.h json_.c:json.h json_artifact_.c:json_artifact.h json_branch_.c:json_branch.h json_config_.c:json_config.h json_diff_.c:json_diff.h json_dir_.c:json_dir.h json_finfo_.c:json_finfo.h json_login_.c:json_login.h json_query_.c:json_query.h json_report_.c:json_report.h json_status_.c:json_status.h json_tag_.c:json_tag.h json_timeline_.c:json_timeline.h json_user_.c:json_user.h json_wiki_.c:json_wiki.h leaf_.c:leaf.h loadctrl_.c:loadctrl.h login_.c:login.h lookslike_.c:lookslike.h main_.c:main.h manifest_.c:manifest.h markdown_.c:markdown.h markdown_html_.c:markdown_html.h md5_.c:md5.h merge_.c:merge.h merge3_.c:merge3.h moderate_.c:moderate.h name_.c:name.h path_.c:path.h pivot_.c:pivot.h popen_.c:popen.h pqueue_.c:pqueue.h printf_.c:printf.h publish_.c:publish.h purge_.c:purge.h rebuild_.c:rebuild.h regexp_.c:regexp.h report_.c:report.h rss_.c:rss.h schema_.c:schema.h search_.c:search.h setup_.c:setup.h sha1_.c:sha1.h shun_.c:shun.h sitemap_.c:sitemap.h skins_.c:skins.h sqlcmd_.c:sqlcmd.h stash_.c:stash.h stat_.c:stat.h style_.c:style.h sync_.c:sync.h tag_.c:tag.h tar_.c:tar.h th_main_.c:th_main.h timeline_.c:timeline.h tkt_.c:tkt.h tktsetup_.c:tktsetup.h undo_.c:undo.h unicode_.c:unicode.h update_.c:update.h url_.c:url.h user_.c:user.h utf8_.c:utf8.h util_.c:util.h verify_.c:verify.h vfile_.c:vfile.h wiki_.c:wiki.h wikiformat_.c:wikiformat.h winfile_.c:winfile.h winhttp_.c:winhttp.h wysiwyg_.c:wysiwyg.h xfer_.c:xfer.h xfersetup_.c:xfersetup.h zip_.c:zip.h $(SRCDIR)\sqlite3.h $(SRCDIR)\th.h VERSION.h $(SRCDIR)\cson_amalgamation.h
832 @copy /Y nul: headers
833
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
4646
#
4747
# FOSSIL_ENABLE_JSON = 1
4848
4949
#### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
5050
#
51
-# FOSSIL_ENABLE_SSL = 1
51
+FOSSIL_ENABLE_SSL = 1
5252
5353
#### Automatically build OpenSSL when building Fossil (causes rebuild
5454
# issues when building incrementally).
5555
#
5656
# FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
8787
# This is useful when Tcl has been compiled statically with MinGW.
8888
#
8989
FOSSIL_TCL_SOURCE = 1
9090
9191
#### Check if the workaround for the MinGW command line handling needs to
92
-# be enabled by default.
92
+# be enabled by default. This check may be somewhat fragile due to the
93
+# use of "findstring".
9394
#
9495
ifndef MINGW_IS_32BIT_ONLY
9596
ifeq (,$(findstring w64-mingw32,$(PREFIX)))
9697
MINGW_IS_32BIT_ONLY = 1
9798
endif
@@ -100,26 +101,46 @@
100101
#### The directories where the zlib include and library files are located.
101102
#
102103
ZINCDIR = $(SRCDIR)/../compat/zlib
103104
ZLIBDIR = $(SRCDIR)/../compat/zlib
104105
106
+#### Make an attempt to detect if Fossil is being built for the x64 processor
107
+# architecture. This check may be somewhat fragile due to "findstring".
108
+#
105109
ifndef X64
106110
ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107111
X64 = 1
108112
endif
109113
endif
110114
115
+#### Determine if the optimized assembly routines provided with zlib should be
116
+# used, taking into account whether zlib is actually enabled and the target
117
+# processor architecture.
118
+#
111119
ifndef X64
112120
SSLCONFIG = mingw
121
+ifndef FOSSIL_ENABLE_MINIZ
113122
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114123
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124
+else
125
+ZLIBCONFIG =
126
+LIBTARGETS =
127
+endif
115128
else
116129
SSLCONFIG = mingw64
117
-ZLIBCONFIG =
130
+ZLIBCONFIG =
118131
LIBTARGETS =
119132
endif
120133
134
+#### Disable creation of the OpenSSL shared libraries. Also, disable support
135
+# for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136
+#
137
+SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
+
139
+#### When using zlib, make sure that OpenSSL is configured to use the zlib
140
+# that Fossil knows about (i.e. the one within the source tree).
141
+#
121142
ifndef FOSSIL_ENABLE_MINIZ
122143
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123144
endif
124145
125146
#### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352373
$(SRCDIR)/bisect.c \
353374
$(SRCDIR)/blob.c \
354375
$(SRCDIR)/branch.c \
355376
$(SRCDIR)/browse.c \
356377
$(SRCDIR)/builtin.c \
378
+ $(SRCDIR)/bundle.c \
357379
$(SRCDIR)/cache.c \
358380
$(SRCDIR)/captcha.c \
359381
$(SRCDIR)/cgi.c \
360382
$(SRCDIR)/checkin.c \
361383
$(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374396
$(SRCDIR)/encode.c \
375397
$(SRCDIR)/event.c \
376398
$(SRCDIR)/export.c \
377399
$(SRCDIR)/file.c \
378400
$(SRCDIR)/finfo.c \
401
+ $(SRCDIR)/foci.c \
379402
$(SRCDIR)/fusefs.c \
380403
$(SRCDIR)/glob.c \
381404
$(SRCDIR)/graph.c \
382405
$(SRCDIR)/gzip.c \
383406
$(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417440
$(SRCDIR)/path.c \
418441
$(SRCDIR)/pivot.c \
419442
$(SRCDIR)/popen.c \
420443
$(SRCDIR)/pqueue.c \
421444
$(SRCDIR)/printf.c \
445
+ $(SRCDIR)/publish.c \
446
+ $(SRCDIR)/purge.c \
422447
$(SRCDIR)/rebuild.c \
423448
$(SRCDIR)/regexp.c \
424449
$(SRCDIR)/report.c \
425450
$(SRCDIR)/rss.c \
426451
$(SRCDIR)/schema.c \
427452
$(SRCDIR)/search.c \
428453
$(SRCDIR)/setup.c \
429454
$(SRCDIR)/sha1.c \
430455
$(SRCDIR)/shun.c \
456
+ $(SRCDIR)/sitemap.c \
431457
$(SRCDIR)/skins.c \
432458
$(SRCDIR)/sqlcmd.c \
433459
$(SRCDIR)/stash.c \
434460
$(SRCDIR)/stat.c \
435461
$(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469495
$(OBJDIR)/bisect_.c \
470496
$(OBJDIR)/blob_.c \
471497
$(OBJDIR)/branch_.c \
472498
$(OBJDIR)/browse_.c \
473499
$(OBJDIR)/builtin_.c \
500
+ $(OBJDIR)/bundle_.c \
474501
$(OBJDIR)/cache_.c \
475502
$(OBJDIR)/captcha_.c \
476503
$(OBJDIR)/cgi_.c \
477504
$(OBJDIR)/checkin_.c \
478505
$(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491518
$(OBJDIR)/encode_.c \
492519
$(OBJDIR)/event_.c \
493520
$(OBJDIR)/export_.c \
494521
$(OBJDIR)/file_.c \
495522
$(OBJDIR)/finfo_.c \
523
+ $(OBJDIR)/foci_.c \
496524
$(OBJDIR)/fusefs_.c \
497525
$(OBJDIR)/glob_.c \
498526
$(OBJDIR)/graph_.c \
499527
$(OBJDIR)/gzip_.c \
500528
$(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534562
$(OBJDIR)/path_.c \
535563
$(OBJDIR)/pivot_.c \
536564
$(OBJDIR)/popen_.c \
537565
$(OBJDIR)/pqueue_.c \
538566
$(OBJDIR)/printf_.c \
567
+ $(OBJDIR)/publish_.c \
568
+ $(OBJDIR)/purge_.c \
539569
$(OBJDIR)/rebuild_.c \
540570
$(OBJDIR)/regexp_.c \
541571
$(OBJDIR)/report_.c \
542572
$(OBJDIR)/rss_.c \
543573
$(OBJDIR)/schema_.c \
544574
$(OBJDIR)/search_.c \
545575
$(OBJDIR)/setup_.c \
546576
$(OBJDIR)/sha1_.c \
547577
$(OBJDIR)/shun_.c \
578
+ $(OBJDIR)/sitemap_.c \
548579
$(OBJDIR)/skins_.c \
549580
$(OBJDIR)/sqlcmd_.c \
550581
$(OBJDIR)/stash_.c \
551582
$(OBJDIR)/stat_.c \
552583
$(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583614
$(OBJDIR)/bisect.o \
584615
$(OBJDIR)/blob.o \
585616
$(OBJDIR)/branch.o \
586617
$(OBJDIR)/browse.o \
587618
$(OBJDIR)/builtin.o \
619
+ $(OBJDIR)/bundle.o \
588620
$(OBJDIR)/cache.o \
589621
$(OBJDIR)/captcha.o \
590622
$(OBJDIR)/cgi.o \
591623
$(OBJDIR)/checkin.o \
592624
$(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605637
$(OBJDIR)/encode.o \
606638
$(OBJDIR)/event.o \
607639
$(OBJDIR)/export.o \
608640
$(OBJDIR)/file.o \
609641
$(OBJDIR)/finfo.o \
642
+ $(OBJDIR)/foci.o \
610643
$(OBJDIR)/fusefs.o \
611644
$(OBJDIR)/glob.o \
612645
$(OBJDIR)/graph.o \
613646
$(OBJDIR)/gzip.o \
614647
$(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648681
$(OBJDIR)/path.o \
649682
$(OBJDIR)/pivot.o \
650683
$(OBJDIR)/popen.o \
651684
$(OBJDIR)/pqueue.o \
652685
$(OBJDIR)/printf.o \
686
+ $(OBJDIR)/publish.o \
687
+ $(OBJDIR)/purge.o \
653688
$(OBJDIR)/rebuild.o \
654689
$(OBJDIR)/regexp.o \
655690
$(OBJDIR)/report.o \
656691
$(OBJDIR)/rss.o \
657692
$(OBJDIR)/schema.o \
658693
$(OBJDIR)/search.o \
659694
$(OBJDIR)/setup.o \
660695
$(OBJDIR)/sha1.o \
661696
$(OBJDIR)/shun.o \
697
+ $(OBJDIR)/sitemap.o \
662698
$(OBJDIR)/skins.o \
663699
$(OBJDIR)/sqlcmd.o \
664700
$(OBJDIR)/stash.o \
665701
$(OBJDIR)/stat.o \
666702
$(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890926
$(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891927
$(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892928
$(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893929
$(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894930
$(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931
+ $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
895932
$(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896933
$(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897934
$(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898935
$(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899936
$(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912949
$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913950
$(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914951
$(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915952
$(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916953
$(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954
+ $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
917955
$(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918956
$(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919957
$(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920958
$(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921959
$(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955993
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956994
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957995
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958996
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959997
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998
+ $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999
+ $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
9601000
$(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
9611001
$(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
9621002
$(OBJDIR)/report_.c:$(OBJDIR)/report.h \
9631003
$(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
9641004
$(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
9651005
$(OBJDIR)/search_.c:$(OBJDIR)/search.h \
9661006
$(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
9671007
$(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
9681008
$(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009
+ $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
9691010
$(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
9701011
$(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
9711012
$(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
9721013
$(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
9731014
$(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
10731114
10741115
$(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
10751116
$(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
10761117
10771118
$(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
+
1120
+$(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121
+ $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
+
1123
+$(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124
+ $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
+
1126
+$(OBJDIR)/bundle.h: $(OBJDIR)/headers
10781127
10791128
$(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
10801129
$(TRANSLATE) $(SRCDIR)/cache.c >$@
10811130
10821131
$(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
12491298
12501299
$(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
12511300
$(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
12521301
12531302
$(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
+
1304
+$(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305
+ $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
+
1307
+$(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308
+ $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
+
1310
+$(OBJDIR)/foci.h: $(OBJDIR)/headers
12541311
12551312
$(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
12561313
$(TRANSLATE) $(SRCDIR)/fusefs.c >$@
12571314
12581315
$(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
15931650
15941651
$(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
15951652
$(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
15961653
15971654
$(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
+
1656
+$(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657
+ $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
+
1659
+$(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660
+ $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
+
1662
+$(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
+
1664
+$(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665
+ $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
+
1667
+$(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668
+ $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
+
1670
+$(OBJDIR)/purge.h: $(OBJDIR)/headers
15981671
15991672
$(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
16001673
$(TRANSLATE) $(SRCDIR)/rebuild.c >$@
16011674
16021675
$(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
16651738
16661739
$(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
16671740
$(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
16681741
16691742
$(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
+
1744
+$(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745
+ $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
+
1747
+$(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748
+ $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
+
1750
+$(OBJDIR)/sitemap.h: $(OBJDIR)/headers
16701751
16711752
$(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
16721753
$(TRANSLATE) $(SRCDIR)/skins.c >$@
16731754
16741755
$(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
16751756
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
46 #
47 # FOSSIL_ENABLE_JSON = 1
48
49 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
50 #
51 # FOSSIL_ENABLE_SSL = 1
52
53 #### Automatically build OpenSSL when building Fossil (causes rebuild
54 # issues when building incrementally).
55 #
56 # FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default.
 
93 #
94 ifndef MINGW_IS_32BIT_ONLY
95 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
96 MINGW_IS_32BIT_ONLY = 1
97 endif
@@ -100,26 +101,46 @@
100 #### The directories where the zlib include and library files are located.
101 #
102 ZINCDIR = $(SRCDIR)/../compat/zlib
103 ZLIBDIR = $(SRCDIR)/../compat/zlib
104
 
 
 
105 ifndef X64
106 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107 X64 = 1
108 endif
109 endif
110
 
 
 
 
111 ifndef X64
112 SSLCONFIG = mingw
 
113 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
 
 
 
 
115 else
116 SSLCONFIG = mingw64
117 ZLIBCONFIG =
118 LIBTARGETS =
119 endif
120
 
 
 
 
 
 
 
 
121 ifndef FOSSIL_ENABLE_MINIZ
122 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123 endif
124
125 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352 $(SRCDIR)/bisect.c \
353 $(SRCDIR)/blob.c \
354 $(SRCDIR)/branch.c \
355 $(SRCDIR)/browse.c \
356 $(SRCDIR)/builtin.c \
 
357 $(SRCDIR)/cache.c \
358 $(SRCDIR)/captcha.c \
359 $(SRCDIR)/cgi.c \
360 $(SRCDIR)/checkin.c \
361 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374 $(SRCDIR)/encode.c \
375 $(SRCDIR)/event.c \
376 $(SRCDIR)/export.c \
377 $(SRCDIR)/file.c \
378 $(SRCDIR)/finfo.c \
 
379 $(SRCDIR)/fusefs.c \
380 $(SRCDIR)/glob.c \
381 $(SRCDIR)/graph.c \
382 $(SRCDIR)/gzip.c \
383 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417 $(SRCDIR)/path.c \
418 $(SRCDIR)/pivot.c \
419 $(SRCDIR)/popen.c \
420 $(SRCDIR)/pqueue.c \
421 $(SRCDIR)/printf.c \
 
 
422 $(SRCDIR)/rebuild.c \
423 $(SRCDIR)/regexp.c \
424 $(SRCDIR)/report.c \
425 $(SRCDIR)/rss.c \
426 $(SRCDIR)/schema.c \
427 $(SRCDIR)/search.c \
428 $(SRCDIR)/setup.c \
429 $(SRCDIR)/sha1.c \
430 $(SRCDIR)/shun.c \
 
431 $(SRCDIR)/skins.c \
432 $(SRCDIR)/sqlcmd.c \
433 $(SRCDIR)/stash.c \
434 $(SRCDIR)/stat.c \
435 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469 $(OBJDIR)/bisect_.c \
470 $(OBJDIR)/blob_.c \
471 $(OBJDIR)/branch_.c \
472 $(OBJDIR)/browse_.c \
473 $(OBJDIR)/builtin_.c \
 
474 $(OBJDIR)/cache_.c \
475 $(OBJDIR)/captcha_.c \
476 $(OBJDIR)/cgi_.c \
477 $(OBJDIR)/checkin_.c \
478 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491 $(OBJDIR)/encode_.c \
492 $(OBJDIR)/event_.c \
493 $(OBJDIR)/export_.c \
494 $(OBJDIR)/file_.c \
495 $(OBJDIR)/finfo_.c \
 
496 $(OBJDIR)/fusefs_.c \
497 $(OBJDIR)/glob_.c \
498 $(OBJDIR)/graph_.c \
499 $(OBJDIR)/gzip_.c \
500 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534 $(OBJDIR)/path_.c \
535 $(OBJDIR)/pivot_.c \
536 $(OBJDIR)/popen_.c \
537 $(OBJDIR)/pqueue_.c \
538 $(OBJDIR)/printf_.c \
 
 
539 $(OBJDIR)/rebuild_.c \
540 $(OBJDIR)/regexp_.c \
541 $(OBJDIR)/report_.c \
542 $(OBJDIR)/rss_.c \
543 $(OBJDIR)/schema_.c \
544 $(OBJDIR)/search_.c \
545 $(OBJDIR)/setup_.c \
546 $(OBJDIR)/sha1_.c \
547 $(OBJDIR)/shun_.c \
 
548 $(OBJDIR)/skins_.c \
549 $(OBJDIR)/sqlcmd_.c \
550 $(OBJDIR)/stash_.c \
551 $(OBJDIR)/stat_.c \
552 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583 $(OBJDIR)/bisect.o \
584 $(OBJDIR)/blob.o \
585 $(OBJDIR)/branch.o \
586 $(OBJDIR)/browse.o \
587 $(OBJDIR)/builtin.o \
 
588 $(OBJDIR)/cache.o \
589 $(OBJDIR)/captcha.o \
590 $(OBJDIR)/cgi.o \
591 $(OBJDIR)/checkin.o \
592 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605 $(OBJDIR)/encode.o \
606 $(OBJDIR)/event.o \
607 $(OBJDIR)/export.o \
608 $(OBJDIR)/file.o \
609 $(OBJDIR)/finfo.o \
 
610 $(OBJDIR)/fusefs.o \
611 $(OBJDIR)/glob.o \
612 $(OBJDIR)/graph.o \
613 $(OBJDIR)/gzip.o \
614 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648 $(OBJDIR)/path.o \
649 $(OBJDIR)/pivot.o \
650 $(OBJDIR)/popen.o \
651 $(OBJDIR)/pqueue.o \
652 $(OBJDIR)/printf.o \
 
 
653 $(OBJDIR)/rebuild.o \
654 $(OBJDIR)/regexp.o \
655 $(OBJDIR)/report.o \
656 $(OBJDIR)/rss.o \
657 $(OBJDIR)/schema.o \
658 $(OBJDIR)/search.o \
659 $(OBJDIR)/setup.o \
660 $(OBJDIR)/sha1.o \
661 $(OBJDIR)/shun.o \
 
662 $(OBJDIR)/skins.o \
663 $(OBJDIR)/sqlcmd.o \
664 $(OBJDIR)/stash.o \
665 $(OBJDIR)/stat.o \
666 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
 
895 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
 
917 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
 
 
960 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
961 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
962 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
963 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
964 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
965 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
966 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
967 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
968 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
 
969 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
970 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
971 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
972 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
973 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1073
1074 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1075 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1076
1077 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1078
1079 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1080 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1081
1082 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1249
1250 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1251 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1252
1253 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1254
1255 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1256 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1257
1258 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1593
1594 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1595 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1596
1597 $(OBJDIR)/printf.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1598
1599 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1600 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1601
1602 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1665
1666 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1667 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1668
1669 $(OBJDIR)/shun.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1670
1671 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1672 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1673
1674 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1675
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
46 #
47 # FOSSIL_ENABLE_JSON = 1
48
49 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
50 #
51 FOSSIL_ENABLE_SSL = 1
52
53 #### Automatically build OpenSSL when building Fossil (causes rebuild
54 # issues when building incrementally).
55 #
56 # FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default. This check may be somewhat fragile due to the
93 # use of "findstring".
94 #
95 ifndef MINGW_IS_32BIT_ONLY
96 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
97 MINGW_IS_32BIT_ONLY = 1
98 endif
@@ -100,26 +101,46 @@
101 #### The directories where the zlib include and library files are located.
102 #
103 ZINCDIR = $(SRCDIR)/../compat/zlib
104 ZLIBDIR = $(SRCDIR)/../compat/zlib
105
106 #### Make an attempt to detect if Fossil is being built for the x64 processor
107 # architecture. This check may be somewhat fragile due to "findstring".
108 #
109 ifndef X64
110 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
111 X64 = 1
112 endif
113 endif
114
115 #### Determine if the optimized assembly routines provided with zlib should be
116 # used, taking into account whether zlib is actually enabled and the target
117 # processor architecture.
118 #
119 ifndef X64
120 SSLCONFIG = mingw
121 ifndef FOSSIL_ENABLE_MINIZ
122 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
123 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124 else
125 ZLIBCONFIG =
126 LIBTARGETS =
127 endif
128 else
129 SSLCONFIG = mingw64
130 ZLIBCONFIG =
131 LIBTARGETS =
132 endif
133
134 #### Disable creation of the OpenSSL shared libraries. Also, disable support
135 # for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136 #
137 SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
139 #### When using zlib, make sure that OpenSSL is configured to use the zlib
140 # that Fossil knows about (i.e. the one within the source tree).
141 #
142 ifndef FOSSIL_ENABLE_MINIZ
143 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
144 endif
145
146 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
373 $(SRCDIR)/bisect.c \
374 $(SRCDIR)/blob.c \
375 $(SRCDIR)/branch.c \
376 $(SRCDIR)/browse.c \
377 $(SRCDIR)/builtin.c \
378 $(SRCDIR)/bundle.c \
379 $(SRCDIR)/cache.c \
380 $(SRCDIR)/captcha.c \
381 $(SRCDIR)/cgi.c \
382 $(SRCDIR)/checkin.c \
383 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
396 $(SRCDIR)/encode.c \
397 $(SRCDIR)/event.c \
398 $(SRCDIR)/export.c \
399 $(SRCDIR)/file.c \
400 $(SRCDIR)/finfo.c \
401 $(SRCDIR)/foci.c \
402 $(SRCDIR)/fusefs.c \
403 $(SRCDIR)/glob.c \
404 $(SRCDIR)/graph.c \
405 $(SRCDIR)/gzip.c \
406 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
440 $(SRCDIR)/path.c \
441 $(SRCDIR)/pivot.c \
442 $(SRCDIR)/popen.c \
443 $(SRCDIR)/pqueue.c \
444 $(SRCDIR)/printf.c \
445 $(SRCDIR)/publish.c \
446 $(SRCDIR)/purge.c \
447 $(SRCDIR)/rebuild.c \
448 $(SRCDIR)/regexp.c \
449 $(SRCDIR)/report.c \
450 $(SRCDIR)/rss.c \
451 $(SRCDIR)/schema.c \
452 $(SRCDIR)/search.c \
453 $(SRCDIR)/setup.c \
454 $(SRCDIR)/sha1.c \
455 $(SRCDIR)/shun.c \
456 $(SRCDIR)/sitemap.c \
457 $(SRCDIR)/skins.c \
458 $(SRCDIR)/sqlcmd.c \
459 $(SRCDIR)/stash.c \
460 $(SRCDIR)/stat.c \
461 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
495 $(OBJDIR)/bisect_.c \
496 $(OBJDIR)/blob_.c \
497 $(OBJDIR)/branch_.c \
498 $(OBJDIR)/browse_.c \
499 $(OBJDIR)/builtin_.c \
500 $(OBJDIR)/bundle_.c \
501 $(OBJDIR)/cache_.c \
502 $(OBJDIR)/captcha_.c \
503 $(OBJDIR)/cgi_.c \
504 $(OBJDIR)/checkin_.c \
505 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
518 $(OBJDIR)/encode_.c \
519 $(OBJDIR)/event_.c \
520 $(OBJDIR)/export_.c \
521 $(OBJDIR)/file_.c \
522 $(OBJDIR)/finfo_.c \
523 $(OBJDIR)/foci_.c \
524 $(OBJDIR)/fusefs_.c \
525 $(OBJDIR)/glob_.c \
526 $(OBJDIR)/graph_.c \
527 $(OBJDIR)/gzip_.c \
528 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
562 $(OBJDIR)/path_.c \
563 $(OBJDIR)/pivot_.c \
564 $(OBJDIR)/popen_.c \
565 $(OBJDIR)/pqueue_.c \
566 $(OBJDIR)/printf_.c \
567 $(OBJDIR)/publish_.c \
568 $(OBJDIR)/purge_.c \
569 $(OBJDIR)/rebuild_.c \
570 $(OBJDIR)/regexp_.c \
571 $(OBJDIR)/report_.c \
572 $(OBJDIR)/rss_.c \
573 $(OBJDIR)/schema_.c \
574 $(OBJDIR)/search_.c \
575 $(OBJDIR)/setup_.c \
576 $(OBJDIR)/sha1_.c \
577 $(OBJDIR)/shun_.c \
578 $(OBJDIR)/sitemap_.c \
579 $(OBJDIR)/skins_.c \
580 $(OBJDIR)/sqlcmd_.c \
581 $(OBJDIR)/stash_.c \
582 $(OBJDIR)/stat_.c \
583 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
614 $(OBJDIR)/bisect.o \
615 $(OBJDIR)/blob.o \
616 $(OBJDIR)/branch.o \
617 $(OBJDIR)/browse.o \
618 $(OBJDIR)/builtin.o \
619 $(OBJDIR)/bundle.o \
620 $(OBJDIR)/cache.o \
621 $(OBJDIR)/captcha.o \
622 $(OBJDIR)/cgi.o \
623 $(OBJDIR)/checkin.o \
624 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
637 $(OBJDIR)/encode.o \
638 $(OBJDIR)/event.o \
639 $(OBJDIR)/export.o \
640 $(OBJDIR)/file.o \
641 $(OBJDIR)/finfo.o \
642 $(OBJDIR)/foci.o \
643 $(OBJDIR)/fusefs.o \
644 $(OBJDIR)/glob.o \
645 $(OBJDIR)/graph.o \
646 $(OBJDIR)/gzip.o \
647 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
681 $(OBJDIR)/path.o \
682 $(OBJDIR)/pivot.o \
683 $(OBJDIR)/popen.o \
684 $(OBJDIR)/pqueue.o \
685 $(OBJDIR)/printf.o \
686 $(OBJDIR)/publish.o \
687 $(OBJDIR)/purge.o \
688 $(OBJDIR)/rebuild.o \
689 $(OBJDIR)/regexp.o \
690 $(OBJDIR)/report.o \
691 $(OBJDIR)/rss.o \
692 $(OBJDIR)/schema.o \
693 $(OBJDIR)/search.o \
694 $(OBJDIR)/setup.o \
695 $(OBJDIR)/sha1.o \
696 $(OBJDIR)/shun.o \
697 $(OBJDIR)/sitemap.o \
698 $(OBJDIR)/skins.o \
699 $(OBJDIR)/sqlcmd.o \
700 $(OBJDIR)/stash.o \
701 $(OBJDIR)/stat.o \
702 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
926 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
927 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
928 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
929 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
930 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931 $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
932 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
933 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
934 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
935 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
936 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
949 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
950 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
951 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
952 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
953 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954 $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
955 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
956 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
957 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
958 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
959 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
993 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
994 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
995 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
996 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
997 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999 $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
1000 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
1001 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
1002 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
1003 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
1004 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
1005 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
1006 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
1007 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
1008 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009 $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
1010 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
1011 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
1012 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
1013 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
1014 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1114
1115 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1116 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1117
1118 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
1120 $(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121 $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
1123 $(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124 $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
1126 $(OBJDIR)/bundle.h: $(OBJDIR)/headers
1127
1128 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1129 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1130
1131 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1298
1299 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1300 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1301
1302 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
1304 $(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305 $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
1307 $(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308 $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
1310 $(OBJDIR)/foci.h: $(OBJDIR)/headers
1311
1312 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1313 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1314
1315 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1650
1651 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1652 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1653
1654 $(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
1656 $(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657 $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
1659 $(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660 $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
1662 $(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
1664 $(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665 $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
1667 $(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668 $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
1670 $(OBJDIR)/purge.h: $(OBJDIR)/headers
1671
1672 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1673 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1674
1675 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1738
1739 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1740 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1741
1742 $(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
1744 $(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745 $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
1747 $(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748 $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
1750 $(OBJDIR)/sitemap.h: $(OBJDIR)/headers
1751
1752 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1753 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1754
1755 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1756
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
4646
#
4747
# FOSSIL_ENABLE_JSON = 1
4848
4949
#### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
5050
#
51
-# FOSSIL_ENABLE_SSL = 1
51
+FOSSIL_ENABLE_SSL = 1
5252
5353
#### Automatically build OpenSSL when building Fossil (causes rebuild
5454
# issues when building incrementally).
5555
#
5656
# FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
8787
# This is useful when Tcl has been compiled statically with MinGW.
8888
#
8989
FOSSIL_TCL_SOURCE = 1
9090
9191
#### Check if the workaround for the MinGW command line handling needs to
92
-# be enabled by default.
92
+# be enabled by default. This check may be somewhat fragile due to the
93
+# use of "findstring".
9394
#
9495
ifndef MINGW_IS_32BIT_ONLY
9596
ifeq (,$(findstring w64-mingw32,$(PREFIX)))
9697
MINGW_IS_32BIT_ONLY = 1
9798
endif
@@ -100,26 +101,46 @@
100101
#### The directories where the zlib include and library files are located.
101102
#
102103
ZINCDIR = $(SRCDIR)/../compat/zlib
103104
ZLIBDIR = $(SRCDIR)/../compat/zlib
104105
106
+#### Make an attempt to detect if Fossil is being built for the x64 processor
107
+# architecture. This check may be somewhat fragile due to "findstring".
108
+#
105109
ifndef X64
106110
ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107111
X64 = 1
108112
endif
109113
endif
110114
115
+#### Determine if the optimized assembly routines provided with zlib should be
116
+# used, taking into account whether zlib is actually enabled and the target
117
+# processor architecture.
118
+#
111119
ifndef X64
112120
SSLCONFIG = mingw
121
+ifndef FOSSIL_ENABLE_MINIZ
113122
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114123
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124
+else
125
+ZLIBCONFIG =
126
+LIBTARGETS =
127
+endif
115128
else
116129
SSLCONFIG = mingw64
117
-ZLIBCONFIG =
130
+ZLIBCONFIG =
118131
LIBTARGETS =
119132
endif
120133
134
+#### Disable creation of the OpenSSL shared libraries. Also, disable support
135
+# for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136
+#
137
+SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
+
139
+#### When using zlib, make sure that OpenSSL is configured to use the zlib
140
+# that Fossil knows about (i.e. the one within the source tree).
141
+#
121142
ifndef FOSSIL_ENABLE_MINIZ
122143
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123144
endif
124145
125146
#### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352373
$(SRCDIR)/bisect.c \
353374
$(SRCDIR)/blob.c \
354375
$(SRCDIR)/branch.c \
355376
$(SRCDIR)/browse.c \
356377
$(SRCDIR)/builtin.c \
378
+ $(SRCDIR)/bundle.c \
357379
$(SRCDIR)/cache.c \
358380
$(SRCDIR)/captcha.c \
359381
$(SRCDIR)/cgi.c \
360382
$(SRCDIR)/checkin.c \
361383
$(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374396
$(SRCDIR)/encode.c \
375397
$(SRCDIR)/event.c \
376398
$(SRCDIR)/export.c \
377399
$(SRCDIR)/file.c \
378400
$(SRCDIR)/finfo.c \
401
+ $(SRCDIR)/foci.c \
379402
$(SRCDIR)/fusefs.c \
380403
$(SRCDIR)/glob.c \
381404
$(SRCDIR)/graph.c \
382405
$(SRCDIR)/gzip.c \
383406
$(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417440
$(SRCDIR)/path.c \
418441
$(SRCDIR)/pivot.c \
419442
$(SRCDIR)/popen.c \
420443
$(SRCDIR)/pqueue.c \
421444
$(SRCDIR)/printf.c \
445
+ $(SRCDIR)/publish.c \
446
+ $(SRCDIR)/purge.c \
422447
$(SRCDIR)/rebuild.c \
423448
$(SRCDIR)/regexp.c \
424449
$(SRCDIR)/report.c \
425450
$(SRCDIR)/rss.c \
426451
$(SRCDIR)/schema.c \
427452
$(SRCDIR)/search.c \
428453
$(SRCDIR)/setup.c \
429454
$(SRCDIR)/sha1.c \
430455
$(SRCDIR)/shun.c \
456
+ $(SRCDIR)/sitemap.c \
431457
$(SRCDIR)/skins.c \
432458
$(SRCDIR)/sqlcmd.c \
433459
$(SRCDIR)/stash.c \
434460
$(SRCDIR)/stat.c \
435461
$(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469495
$(OBJDIR)/bisect_.c \
470496
$(OBJDIR)/blob_.c \
471497
$(OBJDIR)/branch_.c \
472498
$(OBJDIR)/browse_.c \
473499
$(OBJDIR)/builtin_.c \
500
+ $(OBJDIR)/bundle_.c \
474501
$(OBJDIR)/cache_.c \
475502
$(OBJDIR)/captcha_.c \
476503
$(OBJDIR)/cgi_.c \
477504
$(OBJDIR)/checkin_.c \
478505
$(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491518
$(OBJDIR)/encode_.c \
492519
$(OBJDIR)/event_.c \
493520
$(OBJDIR)/export_.c \
494521
$(OBJDIR)/file_.c \
495522
$(OBJDIR)/finfo_.c \
523
+ $(OBJDIR)/foci_.c \
496524
$(OBJDIR)/fusefs_.c \
497525
$(OBJDIR)/glob_.c \
498526
$(OBJDIR)/graph_.c \
499527
$(OBJDIR)/gzip_.c \
500528
$(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534562
$(OBJDIR)/path_.c \
535563
$(OBJDIR)/pivot_.c \
536564
$(OBJDIR)/popen_.c \
537565
$(OBJDIR)/pqueue_.c \
538566
$(OBJDIR)/printf_.c \
567
+ $(OBJDIR)/publish_.c \
568
+ $(OBJDIR)/purge_.c \
539569
$(OBJDIR)/rebuild_.c \
540570
$(OBJDIR)/regexp_.c \
541571
$(OBJDIR)/report_.c \
542572
$(OBJDIR)/rss_.c \
543573
$(OBJDIR)/schema_.c \
544574
$(OBJDIR)/search_.c \
545575
$(OBJDIR)/setup_.c \
546576
$(OBJDIR)/sha1_.c \
547577
$(OBJDIR)/shun_.c \
578
+ $(OBJDIR)/sitemap_.c \
548579
$(OBJDIR)/skins_.c \
549580
$(OBJDIR)/sqlcmd_.c \
550581
$(OBJDIR)/stash_.c \
551582
$(OBJDIR)/stat_.c \
552583
$(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583614
$(OBJDIR)/bisect.o \
584615
$(OBJDIR)/blob.o \
585616
$(OBJDIR)/branch.o \
586617
$(OBJDIR)/browse.o \
587618
$(OBJDIR)/builtin.o \
619
+ $(OBJDIR)/bundle.o \
588620
$(OBJDIR)/cache.o \
589621
$(OBJDIR)/captcha.o \
590622
$(OBJDIR)/cgi.o \
591623
$(OBJDIR)/checkin.o \
592624
$(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605637
$(OBJDIR)/encode.o \
606638
$(OBJDIR)/event.o \
607639
$(OBJDIR)/export.o \
608640
$(OBJDIR)/file.o \
609641
$(OBJDIR)/finfo.o \
642
+ $(OBJDIR)/foci.o \
610643
$(OBJDIR)/fusefs.o \
611644
$(OBJDIR)/glob.o \
612645
$(OBJDIR)/graph.o \
613646
$(OBJDIR)/gzip.o \
614647
$(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648681
$(OBJDIR)/path.o \
649682
$(OBJDIR)/pivot.o \
650683
$(OBJDIR)/popen.o \
651684
$(OBJDIR)/pqueue.o \
652685
$(OBJDIR)/printf.o \
686
+ $(OBJDIR)/publish.o \
687
+ $(OBJDIR)/purge.o \
653688
$(OBJDIR)/rebuild.o \
654689
$(OBJDIR)/regexp.o \
655690
$(OBJDIR)/report.o \
656691
$(OBJDIR)/rss.o \
657692
$(OBJDIR)/schema.o \
658693
$(OBJDIR)/search.o \
659694
$(OBJDIR)/setup.o \
660695
$(OBJDIR)/sha1.o \
661696
$(OBJDIR)/shun.o \
697
+ $(OBJDIR)/sitemap.o \
662698
$(OBJDIR)/skins.o \
663699
$(OBJDIR)/sqlcmd.o \
664700
$(OBJDIR)/stash.o \
665701
$(OBJDIR)/stat.o \
666702
$(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890926
$(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891927
$(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892928
$(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893929
$(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894930
$(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931
+ $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
895932
$(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896933
$(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897934
$(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898935
$(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899936
$(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912949
$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913950
$(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914951
$(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915952
$(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916953
$(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954
+ $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
917955
$(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918956
$(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919957
$(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920958
$(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921959
$(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955993
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956994
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957995
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958996
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959997
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998
+ $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999
+ $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
9601000
$(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
9611001
$(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
9621002
$(OBJDIR)/report_.c:$(OBJDIR)/report.h \
9631003
$(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
9641004
$(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
9651005
$(OBJDIR)/search_.c:$(OBJDIR)/search.h \
9661006
$(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
9671007
$(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
9681008
$(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009
+ $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
9691010
$(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
9701011
$(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
9711012
$(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
9721013
$(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
9731014
$(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
10731114
10741115
$(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
10751116
$(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
10761117
10771118
$(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
+
1120
+$(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121
+ $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
+
1123
+$(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124
+ $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
+
1126
+$(OBJDIR)/bundle.h: $(OBJDIR)/headers
10781127
10791128
$(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
10801129
$(TRANSLATE) $(SRCDIR)/cache.c >$@
10811130
10821131
$(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
12491298
12501299
$(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
12511300
$(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
12521301
12531302
$(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
+
1304
+$(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305
+ $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
+
1307
+$(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308
+ $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
+
1310
+$(OBJDIR)/foci.h: $(OBJDIR)/headers
12541311
12551312
$(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
12561313
$(TRANSLATE) $(SRCDIR)/fusefs.c >$@
12571314
12581315
$(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
15931650
15941651
$(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
15951652
$(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
15961653
15971654
$(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
+
1656
+$(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657
+ $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
+
1659
+$(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660
+ $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
+
1662
+$(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
+
1664
+$(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665
+ $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
+
1667
+$(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668
+ $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
+
1670
+$(OBJDIR)/purge.h: $(OBJDIR)/headers
15981671
15991672
$(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
16001673
$(TRANSLATE) $(SRCDIR)/rebuild.c >$@
16011674
16021675
$(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
16651738
16661739
$(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
16671740
$(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
16681741
16691742
$(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
+
1744
+$(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745
+ $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
+
1747
+$(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748
+ $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
+
1750
+$(OBJDIR)/sitemap.h: $(OBJDIR)/headers
16701751
16711752
$(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
16721753
$(TRANSLATE) $(SRCDIR)/skins.c >$@
16731754
16741755
$(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
16751756
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
46 #
47 # FOSSIL_ENABLE_JSON = 1
48
49 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
50 #
51 # FOSSIL_ENABLE_SSL = 1
52
53 #### Automatically build OpenSSL when building Fossil (causes rebuild
54 # issues when building incrementally).
55 #
56 # FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default.
 
93 #
94 ifndef MINGW_IS_32BIT_ONLY
95 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
96 MINGW_IS_32BIT_ONLY = 1
97 endif
@@ -100,26 +101,46 @@
100 #### The directories where the zlib include and library files are located.
101 #
102 ZINCDIR = $(SRCDIR)/../compat/zlib
103 ZLIBDIR = $(SRCDIR)/../compat/zlib
104
 
 
 
105 ifndef X64
106 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107 X64 = 1
108 endif
109 endif
110
 
 
 
 
111 ifndef X64
112 SSLCONFIG = mingw
 
113 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
 
 
 
 
115 else
116 SSLCONFIG = mingw64
117 ZLIBCONFIG =
118 LIBTARGETS =
119 endif
120
 
 
 
 
 
 
 
 
121 ifndef FOSSIL_ENABLE_MINIZ
122 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123 endif
124
125 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352 $(SRCDIR)/bisect.c \
353 $(SRCDIR)/blob.c \
354 $(SRCDIR)/branch.c \
355 $(SRCDIR)/browse.c \
356 $(SRCDIR)/builtin.c \
 
357 $(SRCDIR)/cache.c \
358 $(SRCDIR)/captcha.c \
359 $(SRCDIR)/cgi.c \
360 $(SRCDIR)/checkin.c \
361 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374 $(SRCDIR)/encode.c \
375 $(SRCDIR)/event.c \
376 $(SRCDIR)/export.c \
377 $(SRCDIR)/file.c \
378 $(SRCDIR)/finfo.c \
 
379 $(SRCDIR)/fusefs.c \
380 $(SRCDIR)/glob.c \
381 $(SRCDIR)/graph.c \
382 $(SRCDIR)/gzip.c \
383 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417 $(SRCDIR)/path.c \
418 $(SRCDIR)/pivot.c \
419 $(SRCDIR)/popen.c \
420 $(SRCDIR)/pqueue.c \
421 $(SRCDIR)/printf.c \
 
 
422 $(SRCDIR)/rebuild.c \
423 $(SRCDIR)/regexp.c \
424 $(SRCDIR)/report.c \
425 $(SRCDIR)/rss.c \
426 $(SRCDIR)/schema.c \
427 $(SRCDIR)/search.c \
428 $(SRCDIR)/setup.c \
429 $(SRCDIR)/sha1.c \
430 $(SRCDIR)/shun.c \
 
431 $(SRCDIR)/skins.c \
432 $(SRCDIR)/sqlcmd.c \
433 $(SRCDIR)/stash.c \
434 $(SRCDIR)/stat.c \
435 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469 $(OBJDIR)/bisect_.c \
470 $(OBJDIR)/blob_.c \
471 $(OBJDIR)/branch_.c \
472 $(OBJDIR)/browse_.c \
473 $(OBJDIR)/builtin_.c \
 
474 $(OBJDIR)/cache_.c \
475 $(OBJDIR)/captcha_.c \
476 $(OBJDIR)/cgi_.c \
477 $(OBJDIR)/checkin_.c \
478 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491 $(OBJDIR)/encode_.c \
492 $(OBJDIR)/event_.c \
493 $(OBJDIR)/export_.c \
494 $(OBJDIR)/file_.c \
495 $(OBJDIR)/finfo_.c \
 
496 $(OBJDIR)/fusefs_.c \
497 $(OBJDIR)/glob_.c \
498 $(OBJDIR)/graph_.c \
499 $(OBJDIR)/gzip_.c \
500 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534 $(OBJDIR)/path_.c \
535 $(OBJDIR)/pivot_.c \
536 $(OBJDIR)/popen_.c \
537 $(OBJDIR)/pqueue_.c \
538 $(OBJDIR)/printf_.c \
 
 
539 $(OBJDIR)/rebuild_.c \
540 $(OBJDIR)/regexp_.c \
541 $(OBJDIR)/report_.c \
542 $(OBJDIR)/rss_.c \
543 $(OBJDIR)/schema_.c \
544 $(OBJDIR)/search_.c \
545 $(OBJDIR)/setup_.c \
546 $(OBJDIR)/sha1_.c \
547 $(OBJDIR)/shun_.c \
 
548 $(OBJDIR)/skins_.c \
549 $(OBJDIR)/sqlcmd_.c \
550 $(OBJDIR)/stash_.c \
551 $(OBJDIR)/stat_.c \
552 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583 $(OBJDIR)/bisect.o \
584 $(OBJDIR)/blob.o \
585 $(OBJDIR)/branch.o \
586 $(OBJDIR)/browse.o \
587 $(OBJDIR)/builtin.o \
 
588 $(OBJDIR)/cache.o \
589 $(OBJDIR)/captcha.o \
590 $(OBJDIR)/cgi.o \
591 $(OBJDIR)/checkin.o \
592 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605 $(OBJDIR)/encode.o \
606 $(OBJDIR)/event.o \
607 $(OBJDIR)/export.o \
608 $(OBJDIR)/file.o \
609 $(OBJDIR)/finfo.o \
 
610 $(OBJDIR)/fusefs.o \
611 $(OBJDIR)/glob.o \
612 $(OBJDIR)/graph.o \
613 $(OBJDIR)/gzip.o \
614 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648 $(OBJDIR)/path.o \
649 $(OBJDIR)/pivot.o \
650 $(OBJDIR)/popen.o \
651 $(OBJDIR)/pqueue.o \
652 $(OBJDIR)/printf.o \
 
 
653 $(OBJDIR)/rebuild.o \
654 $(OBJDIR)/regexp.o \
655 $(OBJDIR)/report.o \
656 $(OBJDIR)/rss.o \
657 $(OBJDIR)/schema.o \
658 $(OBJDIR)/search.o \
659 $(OBJDIR)/setup.o \
660 $(OBJDIR)/sha1.o \
661 $(OBJDIR)/shun.o \
 
662 $(OBJDIR)/skins.o \
663 $(OBJDIR)/sqlcmd.o \
664 $(OBJDIR)/stash.o \
665 $(OBJDIR)/stat.o \
666 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
 
895 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
 
917 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
 
 
960 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
961 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
962 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
963 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
964 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
965 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
966 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
967 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
968 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
 
969 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
970 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
971 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
972 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
973 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1073
1074 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1075 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1076
1077 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1078
1079 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1080 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1081
1082 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1249
1250 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1251 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1252
1253 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1254
1255 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1256 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1257
1258 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1593
1594 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1595 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1596
1597 $(OBJDIR)/printf.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1598
1599 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1600 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1601
1602 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1665
1666 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1667 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1668
1669 $(OBJDIR)/shun.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1670
1671 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1672 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1673
1674 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1675
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -46,11 +46,11 @@
46 #
47 # FOSSIL_ENABLE_JSON = 1
48
49 #### Enable HTTPS support via OpenSSL (links to libssl and libcrypto)
50 #
51 FOSSIL_ENABLE_SSL = 1
52
53 #### Automatically build OpenSSL when building Fossil (causes rebuild
54 # issues when building incrementally).
55 #
56 # FOSSIL_BUILD_SSL = 1
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default. This check may be somewhat fragile due to the
93 # use of "findstring".
94 #
95 ifndef MINGW_IS_32BIT_ONLY
96 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
97 MINGW_IS_32BIT_ONLY = 1
98 endif
@@ -100,26 +101,46 @@
101 #### The directories where the zlib include and library files are located.
102 #
103 ZINCDIR = $(SRCDIR)/../compat/zlib
104 ZLIBDIR = $(SRCDIR)/../compat/zlib
105
106 #### Make an attempt to detect if Fossil is being built for the x64 processor
107 # architecture. This check may be somewhat fragile due to "findstring".
108 #
109 ifndef X64
110 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
111 X64 = 1
112 endif
113 endif
114
115 #### Determine if the optimized assembly routines provided with zlib should be
116 # used, taking into account whether zlib is actually enabled and the target
117 # processor architecture.
118 #
119 ifndef X64
120 SSLCONFIG = mingw
121 ifndef FOSSIL_ENABLE_MINIZ
122 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
123 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124 else
125 ZLIBCONFIG =
126 LIBTARGETS =
127 endif
128 else
129 SSLCONFIG = mingw64
130 ZLIBCONFIG =
131 LIBTARGETS =
132 endif
133
134 #### Disable creation of the OpenSSL shared libraries. Also, disable support
135 # for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136 #
137 SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
139 #### When using zlib, make sure that OpenSSL is configured to use the zlib
140 # that Fossil knows about (i.e. the one within the source tree).
141 #
142 ifndef FOSSIL_ENABLE_MINIZ
143 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
144 endif
145
146 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
373 $(SRCDIR)/bisect.c \
374 $(SRCDIR)/blob.c \
375 $(SRCDIR)/branch.c \
376 $(SRCDIR)/browse.c \
377 $(SRCDIR)/builtin.c \
378 $(SRCDIR)/bundle.c \
379 $(SRCDIR)/cache.c \
380 $(SRCDIR)/captcha.c \
381 $(SRCDIR)/cgi.c \
382 $(SRCDIR)/checkin.c \
383 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
396 $(SRCDIR)/encode.c \
397 $(SRCDIR)/event.c \
398 $(SRCDIR)/export.c \
399 $(SRCDIR)/file.c \
400 $(SRCDIR)/finfo.c \
401 $(SRCDIR)/foci.c \
402 $(SRCDIR)/fusefs.c \
403 $(SRCDIR)/glob.c \
404 $(SRCDIR)/graph.c \
405 $(SRCDIR)/gzip.c \
406 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
440 $(SRCDIR)/path.c \
441 $(SRCDIR)/pivot.c \
442 $(SRCDIR)/popen.c \
443 $(SRCDIR)/pqueue.c \
444 $(SRCDIR)/printf.c \
445 $(SRCDIR)/publish.c \
446 $(SRCDIR)/purge.c \
447 $(SRCDIR)/rebuild.c \
448 $(SRCDIR)/regexp.c \
449 $(SRCDIR)/report.c \
450 $(SRCDIR)/rss.c \
451 $(SRCDIR)/schema.c \
452 $(SRCDIR)/search.c \
453 $(SRCDIR)/setup.c \
454 $(SRCDIR)/sha1.c \
455 $(SRCDIR)/shun.c \
456 $(SRCDIR)/sitemap.c \
457 $(SRCDIR)/skins.c \
458 $(SRCDIR)/sqlcmd.c \
459 $(SRCDIR)/stash.c \
460 $(SRCDIR)/stat.c \
461 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
495 $(OBJDIR)/bisect_.c \
496 $(OBJDIR)/blob_.c \
497 $(OBJDIR)/branch_.c \
498 $(OBJDIR)/browse_.c \
499 $(OBJDIR)/builtin_.c \
500 $(OBJDIR)/bundle_.c \
501 $(OBJDIR)/cache_.c \
502 $(OBJDIR)/captcha_.c \
503 $(OBJDIR)/cgi_.c \
504 $(OBJDIR)/checkin_.c \
505 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
518 $(OBJDIR)/encode_.c \
519 $(OBJDIR)/event_.c \
520 $(OBJDIR)/export_.c \
521 $(OBJDIR)/file_.c \
522 $(OBJDIR)/finfo_.c \
523 $(OBJDIR)/foci_.c \
524 $(OBJDIR)/fusefs_.c \
525 $(OBJDIR)/glob_.c \
526 $(OBJDIR)/graph_.c \
527 $(OBJDIR)/gzip_.c \
528 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
562 $(OBJDIR)/path_.c \
563 $(OBJDIR)/pivot_.c \
564 $(OBJDIR)/popen_.c \
565 $(OBJDIR)/pqueue_.c \
566 $(OBJDIR)/printf_.c \
567 $(OBJDIR)/publish_.c \
568 $(OBJDIR)/purge_.c \
569 $(OBJDIR)/rebuild_.c \
570 $(OBJDIR)/regexp_.c \
571 $(OBJDIR)/report_.c \
572 $(OBJDIR)/rss_.c \
573 $(OBJDIR)/schema_.c \
574 $(OBJDIR)/search_.c \
575 $(OBJDIR)/setup_.c \
576 $(OBJDIR)/sha1_.c \
577 $(OBJDIR)/shun_.c \
578 $(OBJDIR)/sitemap_.c \
579 $(OBJDIR)/skins_.c \
580 $(OBJDIR)/sqlcmd_.c \
581 $(OBJDIR)/stash_.c \
582 $(OBJDIR)/stat_.c \
583 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
614 $(OBJDIR)/bisect.o \
615 $(OBJDIR)/blob.o \
616 $(OBJDIR)/branch.o \
617 $(OBJDIR)/browse.o \
618 $(OBJDIR)/builtin.o \
619 $(OBJDIR)/bundle.o \
620 $(OBJDIR)/cache.o \
621 $(OBJDIR)/captcha.o \
622 $(OBJDIR)/cgi.o \
623 $(OBJDIR)/checkin.o \
624 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
637 $(OBJDIR)/encode.o \
638 $(OBJDIR)/event.o \
639 $(OBJDIR)/export.o \
640 $(OBJDIR)/file.o \
641 $(OBJDIR)/finfo.o \
642 $(OBJDIR)/foci.o \
643 $(OBJDIR)/fusefs.o \
644 $(OBJDIR)/glob.o \
645 $(OBJDIR)/graph.o \
646 $(OBJDIR)/gzip.o \
647 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
681 $(OBJDIR)/path.o \
682 $(OBJDIR)/pivot.o \
683 $(OBJDIR)/popen.o \
684 $(OBJDIR)/pqueue.o \
685 $(OBJDIR)/printf.o \
686 $(OBJDIR)/publish.o \
687 $(OBJDIR)/purge.o \
688 $(OBJDIR)/rebuild.o \
689 $(OBJDIR)/regexp.o \
690 $(OBJDIR)/report.o \
691 $(OBJDIR)/rss.o \
692 $(OBJDIR)/schema.o \
693 $(OBJDIR)/search.o \
694 $(OBJDIR)/setup.o \
695 $(OBJDIR)/sha1.o \
696 $(OBJDIR)/shun.o \
697 $(OBJDIR)/sitemap.o \
698 $(OBJDIR)/skins.o \
699 $(OBJDIR)/sqlcmd.o \
700 $(OBJDIR)/stash.o \
701 $(OBJDIR)/stat.o \
702 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
926 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
927 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
928 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
929 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
930 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931 $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
932 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
933 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
934 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
935 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
936 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
949 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
950 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
951 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
952 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
953 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954 $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
955 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
956 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
957 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
958 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
959 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
993 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
994 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
995 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
996 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
997 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999 $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
1000 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
1001 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
1002 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
1003 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
1004 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
1005 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
1006 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
1007 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
1008 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009 $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
1010 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
1011 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
1012 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
1013 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
1014 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1114
1115 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1116 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1117
1118 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
1120 $(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121 $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
1123 $(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124 $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
1126 $(OBJDIR)/bundle.h: $(OBJDIR)/headers
1127
1128 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1129 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1130
1131 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1298
1299 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1300 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1301
1302 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
1304 $(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305 $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
1307 $(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308 $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
1310 $(OBJDIR)/foci.h: $(OBJDIR)/headers
1311
1312 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1313 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1314
1315 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1650
1651 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1652 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1653
1654 $(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
1656 $(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657 $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
1659 $(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660 $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
1662 $(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
1664 $(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665 $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
1667 $(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668 $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
1670 $(OBJDIR)/purge.h: $(OBJDIR)/headers
1671
1672 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1673 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1674
1675 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1738
1739 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1740 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1741
1742 $(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
1744 $(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745 $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
1747 $(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748 $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
1750 $(OBJDIR)/sitemap.h: $(OBJDIR)/headers
1751
1752 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1753 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1754
1755 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1756
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -87,11 +87,12 @@
8787
# This is useful when Tcl has been compiled statically with MinGW.
8888
#
8989
FOSSIL_TCL_SOURCE = 1
9090
9191
#### Check if the workaround for the MinGW command line handling needs to
92
-# be enabled by default.
92
+# be enabled by default. This check may be somewhat fragile due to the
93
+# use of "findstring".
9394
#
9495
ifndef MINGW_IS_32BIT_ONLY
9596
ifeq (,$(findstring w64-mingw32,$(PREFIX)))
9697
MINGW_IS_32BIT_ONLY = 1
9798
endif
@@ -100,26 +101,46 @@
100101
#### The directories where the zlib include and library files are located.
101102
#
102103
ZINCDIR = $(SRCDIR)/../compat/zlib
103104
ZLIBDIR = $(SRCDIR)/../compat/zlib
104105
106
+#### Make an attempt to detect if Fossil is being built for the x64 processor
107
+# architecture. This check may be somewhat fragile due to "findstring".
108
+#
105109
ifndef X64
106110
ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107111
X64 = 1
108112
endif
109113
endif
110114
115
+#### Determine if the optimized assembly routines provided with zlib should be
116
+# used, taking into account whether zlib is actually enabled and the target
117
+# processor architecture.
118
+#
111119
ifndef X64
112120
SSLCONFIG = mingw
121
+ifndef FOSSIL_ENABLE_MINIZ
113122
ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114123
LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124
+else
125
+ZLIBCONFIG =
126
+LIBTARGETS =
127
+endif
115128
else
116129
SSLCONFIG = mingw64
117
-ZLIBCONFIG =
130
+ZLIBCONFIG =
118131
LIBTARGETS =
119132
endif
120133
134
+#### Disable creation of the OpenSSL shared libraries. Also, disable support
135
+# for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136
+#
137
+SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
+
139
+#### When using zlib, make sure that OpenSSL is configured to use the zlib
140
+# that Fossil knows about (i.e. the one within the source tree).
141
+#
121142
ifndef FOSSIL_ENABLE_MINIZ
122143
SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123144
endif
124145
125146
#### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352373
$(SRCDIR)/bisect.c \
353374
$(SRCDIR)/blob.c \
354375
$(SRCDIR)/branch.c \
355376
$(SRCDIR)/browse.c \
356377
$(SRCDIR)/builtin.c \
378
+ $(SRCDIR)/bundle.c \
357379
$(SRCDIR)/cache.c \
358380
$(SRCDIR)/captcha.c \
359381
$(SRCDIR)/cgi.c \
360382
$(SRCDIR)/checkin.c \
361383
$(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374396
$(SRCDIR)/encode.c \
375397
$(SRCDIR)/event.c \
376398
$(SRCDIR)/export.c \
377399
$(SRCDIR)/file.c \
378400
$(SRCDIR)/finfo.c \
401
+ $(SRCDIR)/foci.c \
379402
$(SRCDIR)/fusefs.c \
380403
$(SRCDIR)/glob.c \
381404
$(SRCDIR)/graph.c \
382405
$(SRCDIR)/gzip.c \
383406
$(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417440
$(SRCDIR)/path.c \
418441
$(SRCDIR)/pivot.c \
419442
$(SRCDIR)/popen.c \
420443
$(SRCDIR)/pqueue.c \
421444
$(SRCDIR)/printf.c \
445
+ $(SRCDIR)/publish.c \
446
+ $(SRCDIR)/purge.c \
422447
$(SRCDIR)/rebuild.c \
423448
$(SRCDIR)/regexp.c \
424449
$(SRCDIR)/report.c \
425450
$(SRCDIR)/rss.c \
426451
$(SRCDIR)/schema.c \
427452
$(SRCDIR)/search.c \
428453
$(SRCDIR)/setup.c \
429454
$(SRCDIR)/sha1.c \
430455
$(SRCDIR)/shun.c \
456
+ $(SRCDIR)/sitemap.c \
431457
$(SRCDIR)/skins.c \
432458
$(SRCDIR)/sqlcmd.c \
433459
$(SRCDIR)/stash.c \
434460
$(SRCDIR)/stat.c \
435461
$(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469495
$(OBJDIR)/bisect_.c \
470496
$(OBJDIR)/blob_.c \
471497
$(OBJDIR)/branch_.c \
472498
$(OBJDIR)/browse_.c \
473499
$(OBJDIR)/builtin_.c \
500
+ $(OBJDIR)/bundle_.c \
474501
$(OBJDIR)/cache_.c \
475502
$(OBJDIR)/captcha_.c \
476503
$(OBJDIR)/cgi_.c \
477504
$(OBJDIR)/checkin_.c \
478505
$(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491518
$(OBJDIR)/encode_.c \
492519
$(OBJDIR)/event_.c \
493520
$(OBJDIR)/export_.c \
494521
$(OBJDIR)/file_.c \
495522
$(OBJDIR)/finfo_.c \
523
+ $(OBJDIR)/foci_.c \
496524
$(OBJDIR)/fusefs_.c \
497525
$(OBJDIR)/glob_.c \
498526
$(OBJDIR)/graph_.c \
499527
$(OBJDIR)/gzip_.c \
500528
$(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534562
$(OBJDIR)/path_.c \
535563
$(OBJDIR)/pivot_.c \
536564
$(OBJDIR)/popen_.c \
537565
$(OBJDIR)/pqueue_.c \
538566
$(OBJDIR)/printf_.c \
567
+ $(OBJDIR)/publish_.c \
568
+ $(OBJDIR)/purge_.c \
539569
$(OBJDIR)/rebuild_.c \
540570
$(OBJDIR)/regexp_.c \
541571
$(OBJDIR)/report_.c \
542572
$(OBJDIR)/rss_.c \
543573
$(OBJDIR)/schema_.c \
544574
$(OBJDIR)/search_.c \
545575
$(OBJDIR)/setup_.c \
546576
$(OBJDIR)/sha1_.c \
547577
$(OBJDIR)/shun_.c \
578
+ $(OBJDIR)/sitemap_.c \
548579
$(OBJDIR)/skins_.c \
549580
$(OBJDIR)/sqlcmd_.c \
550581
$(OBJDIR)/stash_.c \
551582
$(OBJDIR)/stat_.c \
552583
$(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583614
$(OBJDIR)/bisect.o \
584615
$(OBJDIR)/blob.o \
585616
$(OBJDIR)/branch.o \
586617
$(OBJDIR)/browse.o \
587618
$(OBJDIR)/builtin.o \
619
+ $(OBJDIR)/bundle.o \
588620
$(OBJDIR)/cache.o \
589621
$(OBJDIR)/captcha.o \
590622
$(OBJDIR)/cgi.o \
591623
$(OBJDIR)/checkin.o \
592624
$(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605637
$(OBJDIR)/encode.o \
606638
$(OBJDIR)/event.o \
607639
$(OBJDIR)/export.o \
608640
$(OBJDIR)/file.o \
609641
$(OBJDIR)/finfo.o \
642
+ $(OBJDIR)/foci.o \
610643
$(OBJDIR)/fusefs.o \
611644
$(OBJDIR)/glob.o \
612645
$(OBJDIR)/graph.o \
613646
$(OBJDIR)/gzip.o \
614647
$(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648681
$(OBJDIR)/path.o \
649682
$(OBJDIR)/pivot.o \
650683
$(OBJDIR)/popen.o \
651684
$(OBJDIR)/pqueue.o \
652685
$(OBJDIR)/printf.o \
686
+ $(OBJDIR)/publish.o \
687
+ $(OBJDIR)/purge.o \
653688
$(OBJDIR)/rebuild.o \
654689
$(OBJDIR)/regexp.o \
655690
$(OBJDIR)/report.o \
656691
$(OBJDIR)/rss.o \
657692
$(OBJDIR)/schema.o \
658693
$(OBJDIR)/search.o \
659694
$(OBJDIR)/setup.o \
660695
$(OBJDIR)/sha1.o \
661696
$(OBJDIR)/shun.o \
697
+ $(OBJDIR)/sitemap.o \
662698
$(OBJDIR)/skins.o \
663699
$(OBJDIR)/sqlcmd.o \
664700
$(OBJDIR)/stash.o \
665701
$(OBJDIR)/stat.o \
666702
$(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890926
$(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891927
$(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892928
$(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893929
$(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894930
$(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931
+ $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
895932
$(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896933
$(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897934
$(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898935
$(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899936
$(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912949
$(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913950
$(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914951
$(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915952
$(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916953
$(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954
+ $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
917955
$(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918956
$(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919957
$(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920958
$(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921959
$(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955993
$(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956994
$(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957995
$(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958996
$(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959997
$(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998
+ $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999
+ $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
9601000
$(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
9611001
$(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
9621002
$(OBJDIR)/report_.c:$(OBJDIR)/report.h \
9631003
$(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
9641004
$(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
9651005
$(OBJDIR)/search_.c:$(OBJDIR)/search.h \
9661006
$(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
9671007
$(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
9681008
$(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009
+ $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
9691010
$(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
9701011
$(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
9711012
$(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
9721013
$(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
9731014
$(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
10731114
10741115
$(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
10751116
$(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
10761117
10771118
$(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
+
1120
+$(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121
+ $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
+
1123
+$(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124
+ $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
+
1126
+$(OBJDIR)/bundle.h: $(OBJDIR)/headers
10781127
10791128
$(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
10801129
$(TRANSLATE) $(SRCDIR)/cache.c >$@
10811130
10821131
$(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
12491298
12501299
$(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
12511300
$(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
12521301
12531302
$(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
+
1304
+$(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305
+ $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
+
1307
+$(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308
+ $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
+
1310
+$(OBJDIR)/foci.h: $(OBJDIR)/headers
12541311
12551312
$(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
12561313
$(TRANSLATE) $(SRCDIR)/fusefs.c >$@
12571314
12581315
$(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
15931650
15941651
$(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
15951652
$(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
15961653
15971654
$(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
+
1656
+$(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657
+ $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
+
1659
+$(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660
+ $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
+
1662
+$(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
+
1664
+$(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665
+ $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
+
1667
+$(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668
+ $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
+
1670
+$(OBJDIR)/purge.h: $(OBJDIR)/headers
15981671
15991672
$(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
16001673
$(TRANSLATE) $(SRCDIR)/rebuild.c >$@
16011674
16021675
$(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
16651738
16661739
$(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
16671740
$(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
16681741
16691742
$(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
+
1744
+$(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745
+ $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
+
1747
+$(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748
+ $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
+
1750
+$(OBJDIR)/sitemap.h: $(OBJDIR)/headers
16701751
16711752
$(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
16721753
$(TRANSLATE) $(SRCDIR)/skins.c >$@
16731754
16741755
$(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
16751756
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default.
 
93 #
94 ifndef MINGW_IS_32BIT_ONLY
95 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
96 MINGW_IS_32BIT_ONLY = 1
97 endif
@@ -100,26 +101,46 @@
100 #### The directories where the zlib include and library files are located.
101 #
102 ZINCDIR = $(SRCDIR)/../compat/zlib
103 ZLIBDIR = $(SRCDIR)/../compat/zlib
104
 
 
 
105 ifndef X64
106 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
107 X64 = 1
108 endif
109 endif
110
 
 
 
 
111 ifndef X64
112 SSLCONFIG = mingw
 
113 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
114 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
 
 
 
 
115 else
116 SSLCONFIG = mingw64
117 ZLIBCONFIG =
118 LIBTARGETS =
119 endif
120
 
 
 
 
 
 
 
 
121 ifndef FOSSIL_ENABLE_MINIZ
122 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
123 endif
124
125 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
352 $(SRCDIR)/bisect.c \
353 $(SRCDIR)/blob.c \
354 $(SRCDIR)/branch.c \
355 $(SRCDIR)/browse.c \
356 $(SRCDIR)/builtin.c \
 
357 $(SRCDIR)/cache.c \
358 $(SRCDIR)/captcha.c \
359 $(SRCDIR)/cgi.c \
360 $(SRCDIR)/checkin.c \
361 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
374 $(SRCDIR)/encode.c \
375 $(SRCDIR)/event.c \
376 $(SRCDIR)/export.c \
377 $(SRCDIR)/file.c \
378 $(SRCDIR)/finfo.c \
 
379 $(SRCDIR)/fusefs.c \
380 $(SRCDIR)/glob.c \
381 $(SRCDIR)/graph.c \
382 $(SRCDIR)/gzip.c \
383 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
417 $(SRCDIR)/path.c \
418 $(SRCDIR)/pivot.c \
419 $(SRCDIR)/popen.c \
420 $(SRCDIR)/pqueue.c \
421 $(SRCDIR)/printf.c \
 
 
422 $(SRCDIR)/rebuild.c \
423 $(SRCDIR)/regexp.c \
424 $(SRCDIR)/report.c \
425 $(SRCDIR)/rss.c \
426 $(SRCDIR)/schema.c \
427 $(SRCDIR)/search.c \
428 $(SRCDIR)/setup.c \
429 $(SRCDIR)/sha1.c \
430 $(SRCDIR)/shun.c \
 
431 $(SRCDIR)/skins.c \
432 $(SRCDIR)/sqlcmd.c \
433 $(SRCDIR)/stash.c \
434 $(SRCDIR)/stat.c \
435 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
469 $(OBJDIR)/bisect_.c \
470 $(OBJDIR)/blob_.c \
471 $(OBJDIR)/branch_.c \
472 $(OBJDIR)/browse_.c \
473 $(OBJDIR)/builtin_.c \
 
474 $(OBJDIR)/cache_.c \
475 $(OBJDIR)/captcha_.c \
476 $(OBJDIR)/cgi_.c \
477 $(OBJDIR)/checkin_.c \
478 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
491 $(OBJDIR)/encode_.c \
492 $(OBJDIR)/event_.c \
493 $(OBJDIR)/export_.c \
494 $(OBJDIR)/file_.c \
495 $(OBJDIR)/finfo_.c \
 
496 $(OBJDIR)/fusefs_.c \
497 $(OBJDIR)/glob_.c \
498 $(OBJDIR)/graph_.c \
499 $(OBJDIR)/gzip_.c \
500 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
534 $(OBJDIR)/path_.c \
535 $(OBJDIR)/pivot_.c \
536 $(OBJDIR)/popen_.c \
537 $(OBJDIR)/pqueue_.c \
538 $(OBJDIR)/printf_.c \
 
 
539 $(OBJDIR)/rebuild_.c \
540 $(OBJDIR)/regexp_.c \
541 $(OBJDIR)/report_.c \
542 $(OBJDIR)/rss_.c \
543 $(OBJDIR)/schema_.c \
544 $(OBJDIR)/search_.c \
545 $(OBJDIR)/setup_.c \
546 $(OBJDIR)/sha1_.c \
547 $(OBJDIR)/shun_.c \
 
548 $(OBJDIR)/skins_.c \
549 $(OBJDIR)/sqlcmd_.c \
550 $(OBJDIR)/stash_.c \
551 $(OBJDIR)/stat_.c \
552 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
583 $(OBJDIR)/bisect.o \
584 $(OBJDIR)/blob.o \
585 $(OBJDIR)/branch.o \
586 $(OBJDIR)/browse.o \
587 $(OBJDIR)/builtin.o \
 
588 $(OBJDIR)/cache.o \
589 $(OBJDIR)/captcha.o \
590 $(OBJDIR)/cgi.o \
591 $(OBJDIR)/checkin.o \
592 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
605 $(OBJDIR)/encode.o \
606 $(OBJDIR)/event.o \
607 $(OBJDIR)/export.o \
608 $(OBJDIR)/file.o \
609 $(OBJDIR)/finfo.o \
 
610 $(OBJDIR)/fusefs.o \
611 $(OBJDIR)/glob.o \
612 $(OBJDIR)/graph.o \
613 $(OBJDIR)/gzip.o \
614 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
648 $(OBJDIR)/path.o \
649 $(OBJDIR)/pivot.o \
650 $(OBJDIR)/popen.o \
651 $(OBJDIR)/pqueue.o \
652 $(OBJDIR)/printf.o \
 
 
653 $(OBJDIR)/rebuild.o \
654 $(OBJDIR)/regexp.o \
655 $(OBJDIR)/report.o \
656 $(OBJDIR)/rss.o \
657 $(OBJDIR)/schema.o \
658 $(OBJDIR)/search.o \
659 $(OBJDIR)/setup.o \
660 $(OBJDIR)/sha1.o \
661 $(OBJDIR)/shun.o \
 
662 $(OBJDIR)/skins.o \
663 $(OBJDIR)/sqlcmd.o \
664 $(OBJDIR)/stash.o \
665 $(OBJDIR)/stat.o \
666 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
890 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
891 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
892 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
893 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
894 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
 
895 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
896 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
897 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
898 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
899 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
912 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
913 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
914 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
915 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
916 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
 
917 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
918 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
919 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
920 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
921 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
955 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
956 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
957 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
958 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
959 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
 
 
960 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
961 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
962 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
963 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
964 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
965 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
966 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
967 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
968 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
 
969 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
970 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
971 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
972 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
973 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1073
1074 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1075 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1076
1077 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1078
1079 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1080 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1081
1082 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1249
1250 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1251 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1252
1253 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1254
1255 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1256 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1257
1258 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1593
1594 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1595 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1596
1597 $(OBJDIR)/printf.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1598
1599 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1600 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1601
1602 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1665
1666 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1667 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1668
1669 $(OBJDIR)/shun.h: $(OBJDIR)/headers
 
 
 
 
 
 
 
 
1670
1671 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1672 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1673
1674 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1675
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -87,11 +87,12 @@
87 # This is useful when Tcl has been compiled statically with MinGW.
88 #
89 FOSSIL_TCL_SOURCE = 1
90
91 #### Check if the workaround for the MinGW command line handling needs to
92 # be enabled by default. This check may be somewhat fragile due to the
93 # use of "findstring".
94 #
95 ifndef MINGW_IS_32BIT_ONLY
96 ifeq (,$(findstring w64-mingw32,$(PREFIX)))
97 MINGW_IS_32BIT_ONLY = 1
98 endif
@@ -100,26 +101,46 @@
101 #### The directories where the zlib include and library files are located.
102 #
103 ZINCDIR = $(SRCDIR)/../compat/zlib
104 ZLIBDIR = $(SRCDIR)/../compat/zlib
105
106 #### Make an attempt to detect if Fossil is being built for the x64 processor
107 # architecture. This check may be somewhat fragile due to "findstring".
108 #
109 ifndef X64
110 ifneq (,$(findstring x86_64-w64-mingw32,$(PREFIX)))
111 X64 = 1
112 endif
113 endif
114
115 #### Determine if the optimized assembly routines provided with zlib should be
116 # used, taking into account whether zlib is actually enabled and the target
117 # processor architecture.
118 #
119 ifndef X64
120 SSLCONFIG = mingw
121 ifndef FOSSIL_ENABLE_MINIZ
122 ZLIBCONFIG = LOC="-DASMV -DASMINF" OBJA="inffas86.o match.o"
123 LIBTARGETS = $(ZLIBDIR)/inffas86.o $(ZLIBDIR)/match.o
124 else
125 ZLIBCONFIG =
126 LIBTARGETS =
127 endif
128 else
129 SSLCONFIG = mingw64
130 ZLIBCONFIG =
131 LIBTARGETS =
132 endif
133
134 #### Disable creation of the OpenSSL shared libraries. Also, disable support
135 # for both SSLv2 and SSLv3 (i.e. thereby forcing the use of TLS).
136 #
137 SSLCONFIG += no-ssl2 no-ssl3 no-shared
138
139 #### When using zlib, make sure that OpenSSL is configured to use the zlib
140 # that Fossil knows about (i.e. the one within the source tree).
141 #
142 ifndef FOSSIL_ENABLE_MINIZ
143 SSLCONFIG += --with-zlib-lib=$(PWD)/$(ZLIBDIR) --with-zlib-include=$(PWD)/$(ZLIBDIR) zlib
144 endif
145
146 #### The directories where the OpenSSL include and library files are located.
@@ -352,10 +373,11 @@
373 $(SRCDIR)/bisect.c \
374 $(SRCDIR)/blob.c \
375 $(SRCDIR)/branch.c \
376 $(SRCDIR)/browse.c \
377 $(SRCDIR)/builtin.c \
378 $(SRCDIR)/bundle.c \
379 $(SRCDIR)/cache.c \
380 $(SRCDIR)/captcha.c \
381 $(SRCDIR)/cgi.c \
382 $(SRCDIR)/checkin.c \
383 $(SRCDIR)/checkout.c \
@@ -374,10 +396,11 @@
396 $(SRCDIR)/encode.c \
397 $(SRCDIR)/event.c \
398 $(SRCDIR)/export.c \
399 $(SRCDIR)/file.c \
400 $(SRCDIR)/finfo.c \
401 $(SRCDIR)/foci.c \
402 $(SRCDIR)/fusefs.c \
403 $(SRCDIR)/glob.c \
404 $(SRCDIR)/graph.c \
405 $(SRCDIR)/gzip.c \
406 $(SRCDIR)/http.c \
@@ -417,19 +440,22 @@
440 $(SRCDIR)/path.c \
441 $(SRCDIR)/pivot.c \
442 $(SRCDIR)/popen.c \
443 $(SRCDIR)/pqueue.c \
444 $(SRCDIR)/printf.c \
445 $(SRCDIR)/publish.c \
446 $(SRCDIR)/purge.c \
447 $(SRCDIR)/rebuild.c \
448 $(SRCDIR)/regexp.c \
449 $(SRCDIR)/report.c \
450 $(SRCDIR)/rss.c \
451 $(SRCDIR)/schema.c \
452 $(SRCDIR)/search.c \
453 $(SRCDIR)/setup.c \
454 $(SRCDIR)/sha1.c \
455 $(SRCDIR)/shun.c \
456 $(SRCDIR)/sitemap.c \
457 $(SRCDIR)/skins.c \
458 $(SRCDIR)/sqlcmd.c \
459 $(SRCDIR)/stash.c \
460 $(SRCDIR)/stat.c \
461 $(SRCDIR)/style.c \
@@ -469,10 +495,11 @@
495 $(OBJDIR)/bisect_.c \
496 $(OBJDIR)/blob_.c \
497 $(OBJDIR)/branch_.c \
498 $(OBJDIR)/browse_.c \
499 $(OBJDIR)/builtin_.c \
500 $(OBJDIR)/bundle_.c \
501 $(OBJDIR)/cache_.c \
502 $(OBJDIR)/captcha_.c \
503 $(OBJDIR)/cgi_.c \
504 $(OBJDIR)/checkin_.c \
505 $(OBJDIR)/checkout_.c \
@@ -491,10 +518,11 @@
518 $(OBJDIR)/encode_.c \
519 $(OBJDIR)/event_.c \
520 $(OBJDIR)/export_.c \
521 $(OBJDIR)/file_.c \
522 $(OBJDIR)/finfo_.c \
523 $(OBJDIR)/foci_.c \
524 $(OBJDIR)/fusefs_.c \
525 $(OBJDIR)/glob_.c \
526 $(OBJDIR)/graph_.c \
527 $(OBJDIR)/gzip_.c \
528 $(OBJDIR)/http_.c \
@@ -534,19 +562,22 @@
562 $(OBJDIR)/path_.c \
563 $(OBJDIR)/pivot_.c \
564 $(OBJDIR)/popen_.c \
565 $(OBJDIR)/pqueue_.c \
566 $(OBJDIR)/printf_.c \
567 $(OBJDIR)/publish_.c \
568 $(OBJDIR)/purge_.c \
569 $(OBJDIR)/rebuild_.c \
570 $(OBJDIR)/regexp_.c \
571 $(OBJDIR)/report_.c \
572 $(OBJDIR)/rss_.c \
573 $(OBJDIR)/schema_.c \
574 $(OBJDIR)/search_.c \
575 $(OBJDIR)/setup_.c \
576 $(OBJDIR)/sha1_.c \
577 $(OBJDIR)/shun_.c \
578 $(OBJDIR)/sitemap_.c \
579 $(OBJDIR)/skins_.c \
580 $(OBJDIR)/sqlcmd_.c \
581 $(OBJDIR)/stash_.c \
582 $(OBJDIR)/stat_.c \
583 $(OBJDIR)/style_.c \
@@ -583,10 +614,11 @@
614 $(OBJDIR)/bisect.o \
615 $(OBJDIR)/blob.o \
616 $(OBJDIR)/branch.o \
617 $(OBJDIR)/browse.o \
618 $(OBJDIR)/builtin.o \
619 $(OBJDIR)/bundle.o \
620 $(OBJDIR)/cache.o \
621 $(OBJDIR)/captcha.o \
622 $(OBJDIR)/cgi.o \
623 $(OBJDIR)/checkin.o \
624 $(OBJDIR)/checkout.o \
@@ -605,10 +637,11 @@
637 $(OBJDIR)/encode.o \
638 $(OBJDIR)/event.o \
639 $(OBJDIR)/export.o \
640 $(OBJDIR)/file.o \
641 $(OBJDIR)/finfo.o \
642 $(OBJDIR)/foci.o \
643 $(OBJDIR)/fusefs.o \
644 $(OBJDIR)/glob.o \
645 $(OBJDIR)/graph.o \
646 $(OBJDIR)/gzip.o \
647 $(OBJDIR)/http.o \
@@ -648,19 +681,22 @@
681 $(OBJDIR)/path.o \
682 $(OBJDIR)/pivot.o \
683 $(OBJDIR)/popen.o \
684 $(OBJDIR)/pqueue.o \
685 $(OBJDIR)/printf.o \
686 $(OBJDIR)/publish.o \
687 $(OBJDIR)/purge.o \
688 $(OBJDIR)/rebuild.o \
689 $(OBJDIR)/regexp.o \
690 $(OBJDIR)/report.o \
691 $(OBJDIR)/rss.o \
692 $(OBJDIR)/schema.o \
693 $(OBJDIR)/search.o \
694 $(OBJDIR)/setup.o \
695 $(OBJDIR)/sha1.o \
696 $(OBJDIR)/shun.o \
697 $(OBJDIR)/sitemap.o \
698 $(OBJDIR)/skins.o \
699 $(OBJDIR)/sqlcmd.o \
700 $(OBJDIR)/stash.o \
701 $(OBJDIR)/stat.o \
702 $(OBJDIR)/style.o \
@@ -890,10 +926,11 @@
926 $(OBJDIR)/bisect_.c:$(OBJDIR)/bisect.h \
927 $(OBJDIR)/blob_.c:$(OBJDIR)/blob.h \
928 $(OBJDIR)/branch_.c:$(OBJDIR)/branch.h \
929 $(OBJDIR)/browse_.c:$(OBJDIR)/browse.h \
930 $(OBJDIR)/builtin_.c:$(OBJDIR)/builtin.h \
931 $(OBJDIR)/bundle_.c:$(OBJDIR)/bundle.h \
932 $(OBJDIR)/cache_.c:$(OBJDIR)/cache.h \
933 $(OBJDIR)/captcha_.c:$(OBJDIR)/captcha.h \
934 $(OBJDIR)/cgi_.c:$(OBJDIR)/cgi.h \
935 $(OBJDIR)/checkin_.c:$(OBJDIR)/checkin.h \
936 $(OBJDIR)/checkout_.c:$(OBJDIR)/checkout.h \
@@ -912,10 +949,11 @@
949 $(OBJDIR)/encode_.c:$(OBJDIR)/encode.h \
950 $(OBJDIR)/event_.c:$(OBJDIR)/event.h \
951 $(OBJDIR)/export_.c:$(OBJDIR)/export.h \
952 $(OBJDIR)/file_.c:$(OBJDIR)/file.h \
953 $(OBJDIR)/finfo_.c:$(OBJDIR)/finfo.h \
954 $(OBJDIR)/foci_.c:$(OBJDIR)/foci.h \
955 $(OBJDIR)/fusefs_.c:$(OBJDIR)/fusefs.h \
956 $(OBJDIR)/glob_.c:$(OBJDIR)/glob.h \
957 $(OBJDIR)/graph_.c:$(OBJDIR)/graph.h \
958 $(OBJDIR)/gzip_.c:$(OBJDIR)/gzip.h \
959 $(OBJDIR)/http_.c:$(OBJDIR)/http.h \
@@ -955,19 +993,22 @@
993 $(OBJDIR)/path_.c:$(OBJDIR)/path.h \
994 $(OBJDIR)/pivot_.c:$(OBJDIR)/pivot.h \
995 $(OBJDIR)/popen_.c:$(OBJDIR)/popen.h \
996 $(OBJDIR)/pqueue_.c:$(OBJDIR)/pqueue.h \
997 $(OBJDIR)/printf_.c:$(OBJDIR)/printf.h \
998 $(OBJDIR)/publish_.c:$(OBJDIR)/publish.h \
999 $(OBJDIR)/purge_.c:$(OBJDIR)/purge.h \
1000 $(OBJDIR)/rebuild_.c:$(OBJDIR)/rebuild.h \
1001 $(OBJDIR)/regexp_.c:$(OBJDIR)/regexp.h \
1002 $(OBJDIR)/report_.c:$(OBJDIR)/report.h \
1003 $(OBJDIR)/rss_.c:$(OBJDIR)/rss.h \
1004 $(OBJDIR)/schema_.c:$(OBJDIR)/schema.h \
1005 $(OBJDIR)/search_.c:$(OBJDIR)/search.h \
1006 $(OBJDIR)/setup_.c:$(OBJDIR)/setup.h \
1007 $(OBJDIR)/sha1_.c:$(OBJDIR)/sha1.h \
1008 $(OBJDIR)/shun_.c:$(OBJDIR)/shun.h \
1009 $(OBJDIR)/sitemap_.c:$(OBJDIR)/sitemap.h \
1010 $(OBJDIR)/skins_.c:$(OBJDIR)/skins.h \
1011 $(OBJDIR)/sqlcmd_.c:$(OBJDIR)/sqlcmd.h \
1012 $(OBJDIR)/stash_.c:$(OBJDIR)/stash.h \
1013 $(OBJDIR)/stat_.c:$(OBJDIR)/stat.h \
1014 $(OBJDIR)/style_.c:$(OBJDIR)/style.h \
@@ -1073,10 +1114,18 @@
1114
1115 $(OBJDIR)/builtin.o: $(OBJDIR)/builtin_.c $(OBJDIR)/builtin.h $(OBJDIR)/builtin_data.h $(SRCDIR)/config.h
1116 $(XTCC) -o $(OBJDIR)/builtin.o -c $(OBJDIR)/builtin_.c
1117
1118 $(OBJDIR)/builtin.h: $(OBJDIR)/headers
1119
1120 $(OBJDIR)/bundle_.c: $(SRCDIR)/bundle.c $(TRANSLATE)
1121 $(TRANSLATE) $(SRCDIR)/bundle.c >$@
1122
1123 $(OBJDIR)/bundle.o: $(OBJDIR)/bundle_.c $(OBJDIR)/bundle.h $(SRCDIR)/config.h
1124 $(XTCC) -o $(OBJDIR)/bundle.o -c $(OBJDIR)/bundle_.c
1125
1126 $(OBJDIR)/bundle.h: $(OBJDIR)/headers
1127
1128 $(OBJDIR)/cache_.c: $(SRCDIR)/cache.c $(TRANSLATE)
1129 $(TRANSLATE) $(SRCDIR)/cache.c >$@
1130
1131 $(OBJDIR)/cache.o: $(OBJDIR)/cache_.c $(OBJDIR)/cache.h $(SRCDIR)/config.h
@@ -1249,10 +1298,18 @@
1298
1299 $(OBJDIR)/finfo.o: $(OBJDIR)/finfo_.c $(OBJDIR)/finfo.h $(SRCDIR)/config.h
1300 $(XTCC) -o $(OBJDIR)/finfo.o -c $(OBJDIR)/finfo_.c
1301
1302 $(OBJDIR)/finfo.h: $(OBJDIR)/headers
1303
1304 $(OBJDIR)/foci_.c: $(SRCDIR)/foci.c $(TRANSLATE)
1305 $(TRANSLATE) $(SRCDIR)/foci.c >$@
1306
1307 $(OBJDIR)/foci.o: $(OBJDIR)/foci_.c $(OBJDIR)/foci.h $(SRCDIR)/config.h
1308 $(XTCC) -o $(OBJDIR)/foci.o -c $(OBJDIR)/foci_.c
1309
1310 $(OBJDIR)/foci.h: $(OBJDIR)/headers
1311
1312 $(OBJDIR)/fusefs_.c: $(SRCDIR)/fusefs.c $(TRANSLATE)
1313 $(TRANSLATE) $(SRCDIR)/fusefs.c >$@
1314
1315 $(OBJDIR)/fusefs.o: $(OBJDIR)/fusefs_.c $(OBJDIR)/fusefs.h $(SRCDIR)/config.h
@@ -1593,10 +1650,26 @@
1650
1651 $(OBJDIR)/printf.o: $(OBJDIR)/printf_.c $(OBJDIR)/printf.h $(SRCDIR)/config.h
1652 $(XTCC) -o $(OBJDIR)/printf.o -c $(OBJDIR)/printf_.c
1653
1654 $(OBJDIR)/printf.h: $(OBJDIR)/headers
1655
1656 $(OBJDIR)/publish_.c: $(SRCDIR)/publish.c $(TRANSLATE)
1657 $(TRANSLATE) $(SRCDIR)/publish.c >$@
1658
1659 $(OBJDIR)/publish.o: $(OBJDIR)/publish_.c $(OBJDIR)/publish.h $(SRCDIR)/config.h
1660 $(XTCC) -o $(OBJDIR)/publish.o -c $(OBJDIR)/publish_.c
1661
1662 $(OBJDIR)/publish.h: $(OBJDIR)/headers
1663
1664 $(OBJDIR)/purge_.c: $(SRCDIR)/purge.c $(TRANSLATE)
1665 $(TRANSLATE) $(SRCDIR)/purge.c >$@
1666
1667 $(OBJDIR)/purge.o: $(OBJDIR)/purge_.c $(OBJDIR)/purge.h $(SRCDIR)/config.h
1668 $(XTCC) -o $(OBJDIR)/purge.o -c $(OBJDIR)/purge_.c
1669
1670 $(OBJDIR)/purge.h: $(OBJDIR)/headers
1671
1672 $(OBJDIR)/rebuild_.c: $(SRCDIR)/rebuild.c $(TRANSLATE)
1673 $(TRANSLATE) $(SRCDIR)/rebuild.c >$@
1674
1675 $(OBJDIR)/rebuild.o: $(OBJDIR)/rebuild_.c $(OBJDIR)/rebuild.h $(SRCDIR)/config.h
@@ -1665,10 +1738,18 @@
1738
1739 $(OBJDIR)/shun.o: $(OBJDIR)/shun_.c $(OBJDIR)/shun.h $(SRCDIR)/config.h
1740 $(XTCC) -o $(OBJDIR)/shun.o -c $(OBJDIR)/shun_.c
1741
1742 $(OBJDIR)/shun.h: $(OBJDIR)/headers
1743
1744 $(OBJDIR)/sitemap_.c: $(SRCDIR)/sitemap.c $(TRANSLATE)
1745 $(TRANSLATE) $(SRCDIR)/sitemap.c >$@
1746
1747 $(OBJDIR)/sitemap.o: $(OBJDIR)/sitemap_.c $(OBJDIR)/sitemap.h $(SRCDIR)/config.h
1748 $(XTCC) -o $(OBJDIR)/sitemap.o -c $(OBJDIR)/sitemap_.c
1749
1750 $(OBJDIR)/sitemap.h: $(OBJDIR)/headers
1751
1752 $(OBJDIR)/skins_.c: $(SRCDIR)/skins.c $(TRANSLATE)
1753 $(TRANSLATE) $(SRCDIR)/skins.c >$@
1754
1755 $(OBJDIR)/skins.o: $(OBJDIR)/skins_.c $(OBJDIR)/skins.h $(SRCDIR)/config.h
1756
+64 -5
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,23 +62,32 @@
6262
SSLLIBDIR = $(SSLDIR)\out32
6363
SSLLFLAGS = /nologo /opt:ref /debug
6464
SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
6565
!if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
6666
!message Using 'x64' platform for OpenSSL...
67
-SSLCONFIG = VC-WIN64A no-asm
67
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
68
+# SSLCONFIG = VC-WIN64A no-asm no-ssl2 no-ssl3 no-shared
69
+SSLCONFIG = VC-WIN64A no-asm no-shared
6870
SSLSETUP = ms\do_win64a.bat
6971
SSLNMAKE = ms\nt.mak all
72
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
7073
!elseif "$(PLATFORM)"=="ia64"
7174
!message Using 'ia64' platform for OpenSSL...
72
-SSLCONFIG = VC-WIN64I no-asm
75
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
76
+# SSLCONFIG = VC-WIN64I no-asm no-ssl2 no-ssl3 no-shared
77
+SSLCONFIG = VC-WIN64I no-asm no-shared
7378
SSLSETUP = ms\do_win64i.bat
7479
SSLNMAKE = ms\nt.mak all
80
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
7581
!else
7682
!message Assuming 'x86' platform for OpenSSL...
77
-SSLCONFIG = VC-WIN32 no-asm
83
+# BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
84
+# SSLCONFIG = VC-WIN32 no-asm no-ssl2 no-ssl3 no-shared
85
+SSLCONFIG = VC-WIN32 no-asm no-shared
7886
SSLSETUP = ms\do_ms.bat
7987
SSLNMAKE = ms\nt.mak all
88
+SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
8089
!endif
8190
!endif
8291
8392
!ifdef FOSSIL_ENABLE_TCL
8493
TCLDIR = $(B)\compat\tcl-8.6
@@ -204,10 +213,11 @@
204213
bisect_.c \
205214
blob_.c \
206215
branch_.c \
207216
browse_.c \
208217
builtin_.c \
218
+ bundle_.c \
209219
cache_.c \
210220
captcha_.c \
211221
cgi_.c \
212222
checkin_.c \
213223
checkout_.c \
@@ -226,10 +236,11 @@
226236
encode_.c \
227237
event_.c \
228238
export_.c \
229239
file_.c \
230240
finfo_.c \
241
+ foci_.c \
231242
fusefs_.c \
232243
glob_.c \
233244
graph_.c \
234245
gzip_.c \
235246
http_.c \
@@ -269,19 +280,22 @@
269280
path_.c \
270281
pivot_.c \
271282
popen_.c \
272283
pqueue_.c \
273284
printf_.c \
285
+ publish_.c \
286
+ purge_.c \
274287
rebuild_.c \
275288
regexp_.c \
276289
report_.c \
277290
rss_.c \
278291
schema_.c \
279292
search_.c \
280293
setup_.c \
281294
sha1_.c \
282295
shun_.c \
296
+ sitemap_.c \
283297
skins_.c \
284298
sqlcmd_.c \
285299
stash_.c \
286300
stat_.c \
287301
style_.c \
@@ -319,10 +333,11 @@
319333
$(OX)\bisect$O \
320334
$(OX)\blob$O \
321335
$(OX)\branch$O \
322336
$(OX)\browse$O \
323337
$(OX)\builtin$O \
338
+ $(OX)\bundle$O \
324339
$(OX)\cache$O \
325340
$(OX)\captcha$O \
326341
$(OX)\cgi$O \
327342
$(OX)\checkin$O \
328343
$(OX)\checkout$O \
@@ -342,10 +357,11 @@
342357
$(OX)\encode$O \
343358
$(OX)\event$O \
344359
$(OX)\export$O \
345360
$(OX)\file$O \
346361
$(OX)\finfo$O \
362
+ $(OX)\foci$O \
347363
$(OX)\fusefs$O \
348364
$(OX)\glob$O \
349365
$(OX)\graph$O \
350366
$(OX)\gzip$O \
351367
$(OX)\http$O \
@@ -385,10 +401,12 @@
385401
$(OX)\path$O \
386402
$(OX)\pivot$O \
387403
$(OX)\popen$O \
388404
$(OX)\pqueue$O \
389405
$(OX)\printf$O \
406
+ $(OX)\publish$O \
407
+ $(OX)\purge$O \
390408
$(OX)\rebuild$O \
391409
$(OX)\regexp$O \
392410
$(OX)\report$O \
393411
$(OX)\rss$O \
394412
$(OX)\schema$O \
@@ -395,10 +413,11 @@
395413
$(OX)\search$O \
396414
$(OX)\setup$O \
397415
$(OX)\sha1$O \
398416
$(OX)\shell$O \
399417
$(OX)\shun$O \
418
+ $(OX)\sitemap$O \
400419
$(OX)\skins$O \
401420
$(OX)\sqlcmd$O \
402421
$(OX)\sqlite3$O \
403422
$(OX)\stash$O \
404423
$(OX)\stat$O \
@@ -457,13 +476,13 @@
457476
@set PATH=$(PERLDIR);$(PATH)
458477
!endif
459478
@pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
460479
@pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
461480
!ifdef FOSSIL_ENABLE_WINXP
462
- @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
481
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS) $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
463482
!else
464
- @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
483
+ @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
465484
!endif
466485
!endif
467486
468487
!ifndef FOSSIL_ENABLE_MINIZ
469488
APPTARGETS = $(APPTARGETS) zlib
@@ -488,10 +507,11 @@
488507
echo $(OX)\bisect.obj >> $@
489508
echo $(OX)\blob.obj >> $@
490509
echo $(OX)\branch.obj >> $@
491510
echo $(OX)\browse.obj >> $@
492511
echo $(OX)\builtin.obj >> $@
512
+ echo $(OX)\bundle.obj >> $@
493513
echo $(OX)\cache.obj >> $@
494514
echo $(OX)\captcha.obj >> $@
495515
echo $(OX)\cgi.obj >> $@
496516
echo $(OX)\checkin.obj >> $@
497517
echo $(OX)\checkout.obj >> $@
@@ -511,10 +531,11 @@
511531
echo $(OX)\encode.obj >> $@
512532
echo $(OX)\event.obj >> $@
513533
echo $(OX)\export.obj >> $@
514534
echo $(OX)\file.obj >> $@
515535
echo $(OX)\finfo.obj >> $@
536
+ echo $(OX)\foci.obj >> $@
516537
echo $(OX)\fusefs.obj >> $@
517538
echo $(OX)\glob.obj >> $@
518539
echo $(OX)\graph.obj >> $@
519540
echo $(OX)\gzip.obj >> $@
520541
echo $(OX)\http.obj >> $@
@@ -554,10 +575,12 @@
554575
echo $(OX)\path.obj >> $@
555576
echo $(OX)\pivot.obj >> $@
556577
echo $(OX)\popen.obj >> $@
557578
echo $(OX)\pqueue.obj >> $@
558579
echo $(OX)\printf.obj >> $@
580
+ echo $(OX)\publish.obj >> $@
581
+ echo $(OX)\purge.obj >> $@
559582
echo $(OX)\rebuild.obj >> $@
560583
echo $(OX)\regexp.obj >> $@
561584
echo $(OX)\report.obj >> $@
562585
echo $(OX)\rss.obj >> $@
563586
echo $(OX)\schema.obj >> $@
@@ -564,10 +587,11 @@
564587
echo $(OX)\search.obj >> $@
565588
echo $(OX)\setup.obj >> $@
566589
echo $(OX)\sha1.obj >> $@
567590
echo $(OX)\shell.obj >> $@
568591
echo $(OX)\shun.obj >> $@
592
+ echo $(OX)\sitemap.obj >> $@
569593
echo $(OX)\skins.obj >> $@
570594
echo $(OX)\sqlcmd.obj >> $@
571595
echo $(OX)\sqlite3.obj >> $@
572596
echo $(OX)\stash.obj >> $@
573597
echo $(OX)\stat.obj >> $@
@@ -749,10 +773,16 @@
749773
$(OX)\builtin$O : builtin_.c builtin.h
750774
$(TCC) /Fo$@ -c builtin_.c
751775
752776
builtin_.c : $(SRCDIR)\builtin.c
753777
translate$E $** > $@
778
+
779
+$(OX)\bundle$O : bundle_.c bundle.h
780
+ $(TCC) /Fo$@ -c bundle_.c
781
+
782
+bundle_.c : $(SRCDIR)\bundle.c
783
+ translate$E $** > $@
754784
755785
$(OX)\cache$O : cache_.c cache.h
756786
$(TCC) /Fo$@ -c cache_.c
757787
758788
cache_.c : $(SRCDIR)\cache.c
@@ -881,10 +911,16 @@
881911
$(OX)\finfo$O : finfo_.c finfo.h
882912
$(TCC) /Fo$@ -c finfo_.c
883913
884914
finfo_.c : $(SRCDIR)\finfo.c
885915
translate$E $** > $@
916
+
917
+$(OX)\foci$O : foci_.c foci.h
918
+ $(TCC) /Fo$@ -c foci_.c
919
+
920
+foci_.c : $(SRCDIR)\foci.c
921
+ translate$E $** > $@
886922
887923
$(OX)\fusefs$O : fusefs_.c fusefs.h
888924
$(TCC) /Fo$@ -c fusefs_.c
889925
890926
fusefs_.c : $(SRCDIR)\fusefs.c
@@ -1139,10 +1175,22 @@
11391175
$(OX)\printf$O : printf_.c printf.h
11401176
$(TCC) /Fo$@ -c printf_.c
11411177
11421178
printf_.c : $(SRCDIR)\printf.c
11431179
translate$E $** > $@
1180
+
1181
+$(OX)\publish$O : publish_.c publish.h
1182
+ $(TCC) /Fo$@ -c publish_.c
1183
+
1184
+publish_.c : $(SRCDIR)\publish.c
1185
+ translate$E $** > $@
1186
+
1187
+$(OX)\purge$O : purge_.c purge.h
1188
+ $(TCC) /Fo$@ -c purge_.c
1189
+
1190
+purge_.c : $(SRCDIR)\purge.c
1191
+ translate$E $** > $@
11441192
11451193
$(OX)\rebuild$O : rebuild_.c rebuild.h
11461194
$(TCC) /Fo$@ -c rebuild_.c
11471195
11481196
rebuild_.c : $(SRCDIR)\rebuild.c
@@ -1193,10 +1241,16 @@
11931241
$(OX)\shun$O : shun_.c shun.h
11941242
$(TCC) /Fo$@ -c shun_.c
11951243
11961244
shun_.c : $(SRCDIR)\shun.c
11971245
translate$E $** > $@
1246
+
1247
+$(OX)\sitemap$O : sitemap_.c sitemap.h
1248
+ $(TCC) /Fo$@ -c sitemap_.c
1249
+
1250
+sitemap_.c : $(SRCDIR)\sitemap.c
1251
+ translate$E $** > $@
11981252
11991253
$(OX)\skins$O : skins_.c skins.h
12001254
$(TCC) /Fo$@ -c skins_.c
12011255
12021256
skins_.c : $(SRCDIR)\skins.c
@@ -1381,10 +1435,11 @@
13811435
bisect_.c:bisect.h \
13821436
blob_.c:blob.h \
13831437
branch_.c:branch.h \
13841438
browse_.c:browse.h \
13851439
builtin_.c:builtin.h \
1440
+ bundle_.c:bundle.h \
13861441
cache_.c:cache.h \
13871442
captcha_.c:captcha.h \
13881443
cgi_.c:cgi.h \
13891444
checkin_.c:checkin.h \
13901445
checkout_.c:checkout.h \
@@ -1403,10 +1458,11 @@
14031458
encode_.c:encode.h \
14041459
event_.c:event.h \
14051460
export_.c:export.h \
14061461
file_.c:file.h \
14071462
finfo_.c:finfo.h \
1463
+ foci_.c:foci.h \
14081464
fusefs_.c:fusefs.h \
14091465
glob_.c:glob.h \
14101466
graph_.c:graph.h \
14111467
gzip_.c:gzip.h \
14121468
http_.c:http.h \
@@ -1446,19 +1502,22 @@
14461502
path_.c:path.h \
14471503
pivot_.c:pivot.h \
14481504
popen_.c:popen.h \
14491505
pqueue_.c:pqueue.h \
14501506
printf_.c:printf.h \
1507
+ publish_.c:publish.h \
1508
+ purge_.c:purge.h \
14511509
rebuild_.c:rebuild.h \
14521510
regexp_.c:regexp.h \
14531511
report_.c:report.h \
14541512
rss_.c:rss.h \
14551513
schema_.c:schema.h \
14561514
search_.c:search.h \
14571515
setup_.c:setup.h \
14581516
sha1_.c:sha1.h \
14591517
shun_.c:shun.h \
1518
+ sitemap_.c:sitemap.h \
14601519
skins_.c:skins.h \
14611520
sqlcmd_.c:sqlcmd.h \
14621521
stash_.c:stash.h \
14631522
stat_.c:stat.h \
14641523
style_.c:style.h \
14651524
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,23 +62,32 @@
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66 !message Using 'x64' platform for OpenSSL...
67 SSLCONFIG = VC-WIN64A no-asm
 
 
68 SSLSETUP = ms\do_win64a.bat
69 SSLNMAKE = ms\nt.mak all
 
70 !elseif "$(PLATFORM)"=="ia64"
71 !message Using 'ia64' platform for OpenSSL...
72 SSLCONFIG = VC-WIN64I no-asm
 
 
73 SSLSETUP = ms\do_win64i.bat
74 SSLNMAKE = ms\nt.mak all
 
75 !else
76 !message Assuming 'x86' platform for OpenSSL...
77 SSLCONFIG = VC-WIN32 no-asm
 
 
78 SSLSETUP = ms\do_ms.bat
79 SSLNMAKE = ms\nt.mak all
 
80 !endif
81 !endif
82
83 !ifdef FOSSIL_ENABLE_TCL
84 TCLDIR = $(B)\compat\tcl-8.6
@@ -204,10 +213,11 @@
204 bisect_.c \
205 blob_.c \
206 branch_.c \
207 browse_.c \
208 builtin_.c \
 
209 cache_.c \
210 captcha_.c \
211 cgi_.c \
212 checkin_.c \
213 checkout_.c \
@@ -226,10 +236,11 @@
226 encode_.c \
227 event_.c \
228 export_.c \
229 file_.c \
230 finfo_.c \
 
231 fusefs_.c \
232 glob_.c \
233 graph_.c \
234 gzip_.c \
235 http_.c \
@@ -269,19 +280,22 @@
269 path_.c \
270 pivot_.c \
271 popen_.c \
272 pqueue_.c \
273 printf_.c \
 
 
274 rebuild_.c \
275 regexp_.c \
276 report_.c \
277 rss_.c \
278 schema_.c \
279 search_.c \
280 setup_.c \
281 sha1_.c \
282 shun_.c \
 
283 skins_.c \
284 sqlcmd_.c \
285 stash_.c \
286 stat_.c \
287 style_.c \
@@ -319,10 +333,11 @@
319 $(OX)\bisect$O \
320 $(OX)\blob$O \
321 $(OX)\branch$O \
322 $(OX)\browse$O \
323 $(OX)\builtin$O \
 
324 $(OX)\cache$O \
325 $(OX)\captcha$O \
326 $(OX)\cgi$O \
327 $(OX)\checkin$O \
328 $(OX)\checkout$O \
@@ -342,10 +357,11 @@
342 $(OX)\encode$O \
343 $(OX)\event$O \
344 $(OX)\export$O \
345 $(OX)\file$O \
346 $(OX)\finfo$O \
 
347 $(OX)\fusefs$O \
348 $(OX)\glob$O \
349 $(OX)\graph$O \
350 $(OX)\gzip$O \
351 $(OX)\http$O \
@@ -385,10 +401,12 @@
385 $(OX)\path$O \
386 $(OX)\pivot$O \
387 $(OX)\popen$O \
388 $(OX)\pqueue$O \
389 $(OX)\printf$O \
 
 
390 $(OX)\rebuild$O \
391 $(OX)\regexp$O \
392 $(OX)\report$O \
393 $(OX)\rss$O \
394 $(OX)\schema$O \
@@ -395,10 +413,11 @@
395 $(OX)\search$O \
396 $(OX)\setup$O \
397 $(OX)\sha1$O \
398 $(OX)\shell$O \
399 $(OX)\shun$O \
 
400 $(OX)\skins$O \
401 $(OX)\sqlcmd$O \
402 $(OX)\sqlite3$O \
403 $(OX)\stash$O \
404 $(OX)\stat$O \
@@ -457,13 +476,13 @@
457 @set PATH=$(PERLDIR);$(PATH)
458 !endif
459 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
460 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
461 !ifdef FOSSIL_ENABLE_WINXP
462 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
463 !else
464 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) && popd
465 !endif
466 !endif
467
468 !ifndef FOSSIL_ENABLE_MINIZ
469 APPTARGETS = $(APPTARGETS) zlib
@@ -488,10 +507,11 @@
488 echo $(OX)\bisect.obj >> $@
489 echo $(OX)\blob.obj >> $@
490 echo $(OX)\branch.obj >> $@
491 echo $(OX)\browse.obj >> $@
492 echo $(OX)\builtin.obj >> $@
 
493 echo $(OX)\cache.obj >> $@
494 echo $(OX)\captcha.obj >> $@
495 echo $(OX)\cgi.obj >> $@
496 echo $(OX)\checkin.obj >> $@
497 echo $(OX)\checkout.obj >> $@
@@ -511,10 +531,11 @@
511 echo $(OX)\encode.obj >> $@
512 echo $(OX)\event.obj >> $@
513 echo $(OX)\export.obj >> $@
514 echo $(OX)\file.obj >> $@
515 echo $(OX)\finfo.obj >> $@
 
516 echo $(OX)\fusefs.obj >> $@
517 echo $(OX)\glob.obj >> $@
518 echo $(OX)\graph.obj >> $@
519 echo $(OX)\gzip.obj >> $@
520 echo $(OX)\http.obj >> $@
@@ -554,10 +575,12 @@
554 echo $(OX)\path.obj >> $@
555 echo $(OX)\pivot.obj >> $@
556 echo $(OX)\popen.obj >> $@
557 echo $(OX)\pqueue.obj >> $@
558 echo $(OX)\printf.obj >> $@
 
 
559 echo $(OX)\rebuild.obj >> $@
560 echo $(OX)\regexp.obj >> $@
561 echo $(OX)\report.obj >> $@
562 echo $(OX)\rss.obj >> $@
563 echo $(OX)\schema.obj >> $@
@@ -564,10 +587,11 @@
564 echo $(OX)\search.obj >> $@
565 echo $(OX)\setup.obj >> $@
566 echo $(OX)\sha1.obj >> $@
567 echo $(OX)\shell.obj >> $@
568 echo $(OX)\shun.obj >> $@
 
569 echo $(OX)\skins.obj >> $@
570 echo $(OX)\sqlcmd.obj >> $@
571 echo $(OX)\sqlite3.obj >> $@
572 echo $(OX)\stash.obj >> $@
573 echo $(OX)\stat.obj >> $@
@@ -749,10 +773,16 @@
749 $(OX)\builtin$O : builtin_.c builtin.h
750 $(TCC) /Fo$@ -c builtin_.c
751
752 builtin_.c : $(SRCDIR)\builtin.c
753 translate$E $** > $@
 
 
 
 
 
 
754
755 $(OX)\cache$O : cache_.c cache.h
756 $(TCC) /Fo$@ -c cache_.c
757
758 cache_.c : $(SRCDIR)\cache.c
@@ -881,10 +911,16 @@
881 $(OX)\finfo$O : finfo_.c finfo.h
882 $(TCC) /Fo$@ -c finfo_.c
883
884 finfo_.c : $(SRCDIR)\finfo.c
885 translate$E $** > $@
 
 
 
 
 
 
886
887 $(OX)\fusefs$O : fusefs_.c fusefs.h
888 $(TCC) /Fo$@ -c fusefs_.c
889
890 fusefs_.c : $(SRCDIR)\fusefs.c
@@ -1139,10 +1175,22 @@
1139 $(OX)\printf$O : printf_.c printf.h
1140 $(TCC) /Fo$@ -c printf_.c
1141
1142 printf_.c : $(SRCDIR)\printf.c
1143 translate$E $** > $@
 
 
 
 
 
 
 
 
 
 
 
 
1144
1145 $(OX)\rebuild$O : rebuild_.c rebuild.h
1146 $(TCC) /Fo$@ -c rebuild_.c
1147
1148 rebuild_.c : $(SRCDIR)\rebuild.c
@@ -1193,10 +1241,16 @@
1193 $(OX)\shun$O : shun_.c shun.h
1194 $(TCC) /Fo$@ -c shun_.c
1195
1196 shun_.c : $(SRCDIR)\shun.c
1197 translate$E $** > $@
 
 
 
 
 
 
1198
1199 $(OX)\skins$O : skins_.c skins.h
1200 $(TCC) /Fo$@ -c skins_.c
1201
1202 skins_.c : $(SRCDIR)\skins.c
@@ -1381,10 +1435,11 @@
1381 bisect_.c:bisect.h \
1382 blob_.c:blob.h \
1383 branch_.c:branch.h \
1384 browse_.c:browse.h \
1385 builtin_.c:builtin.h \
 
1386 cache_.c:cache.h \
1387 captcha_.c:captcha.h \
1388 cgi_.c:cgi.h \
1389 checkin_.c:checkin.h \
1390 checkout_.c:checkout.h \
@@ -1403,10 +1458,11 @@
1403 encode_.c:encode.h \
1404 event_.c:event.h \
1405 export_.c:export.h \
1406 file_.c:file.h \
1407 finfo_.c:finfo.h \
 
1408 fusefs_.c:fusefs.h \
1409 glob_.c:glob.h \
1410 graph_.c:graph.h \
1411 gzip_.c:gzip.h \
1412 http_.c:http.h \
@@ -1446,19 +1502,22 @@
1446 path_.c:path.h \
1447 pivot_.c:pivot.h \
1448 popen_.c:popen.h \
1449 pqueue_.c:pqueue.h \
1450 printf_.c:printf.h \
 
 
1451 rebuild_.c:rebuild.h \
1452 regexp_.c:regexp.h \
1453 report_.c:report.h \
1454 rss_.c:rss.h \
1455 schema_.c:schema.h \
1456 search_.c:search.h \
1457 setup_.c:setup.h \
1458 sha1_.c:sha1.h \
1459 shun_.c:shun.h \
 
1460 skins_.c:skins.h \
1461 sqlcmd_.c:sqlcmd.h \
1462 stash_.c:stash.h \
1463 stat_.c:stat.h \
1464 style_.c:style.h \
1465
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -62,23 +62,32 @@
62 SSLLIBDIR = $(SSLDIR)\out32
63 SSLLFLAGS = /nologo /opt:ref /debug
64 SSLLIB = ssleay32.lib libeay32.lib user32.lib gdi32.lib
65 !if "$(PLATFORM)"=="amd64" || "$(PLATFORM)"=="x64"
66 !message Using 'x64' platform for OpenSSL...
67 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
68 # SSLCONFIG = VC-WIN64A no-asm no-ssl2 no-ssl3 no-shared
69 SSLCONFIG = VC-WIN64A no-asm no-shared
70 SSLSETUP = ms\do_win64a.bat
71 SSLNMAKE = ms\nt.mak all
72 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
73 !elseif "$(PLATFORM)"=="ia64"
74 !message Using 'ia64' platform for OpenSSL...
75 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
76 # SSLCONFIG = VC-WIN64I no-asm no-ssl2 no-ssl3 no-shared
77 SSLCONFIG = VC-WIN64I no-asm no-shared
78 SSLSETUP = ms\do_win64i.bat
79 SSLNMAKE = ms\nt.mak all
80 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
81 !else
82 !message Assuming 'x86' platform for OpenSSL...
83 # BUGBUG (OpenSSL): Apparently, using "no-ssl*" here breaks the build.
84 # SSLCONFIG = VC-WIN32 no-asm no-ssl2 no-ssl3 no-shared
85 SSLCONFIG = VC-WIN32 no-asm no-shared
86 SSLSETUP = ms\do_ms.bat
87 SSLNMAKE = ms\nt.mak all
88 SSLCFLAGS = -DOPENSSL_NO_SSL2 -DOPENSSL_NO_SSL3
89 !endif
90 !endif
91
92 !ifdef FOSSIL_ENABLE_TCL
93 TCLDIR = $(B)\compat\tcl-8.6
@@ -204,10 +213,11 @@
213 bisect_.c \
214 blob_.c \
215 branch_.c \
216 browse_.c \
217 builtin_.c \
218 bundle_.c \
219 cache_.c \
220 captcha_.c \
221 cgi_.c \
222 checkin_.c \
223 checkout_.c \
@@ -226,10 +236,11 @@
236 encode_.c \
237 event_.c \
238 export_.c \
239 file_.c \
240 finfo_.c \
241 foci_.c \
242 fusefs_.c \
243 glob_.c \
244 graph_.c \
245 gzip_.c \
246 http_.c \
@@ -269,19 +280,22 @@
280 path_.c \
281 pivot_.c \
282 popen_.c \
283 pqueue_.c \
284 printf_.c \
285 publish_.c \
286 purge_.c \
287 rebuild_.c \
288 regexp_.c \
289 report_.c \
290 rss_.c \
291 schema_.c \
292 search_.c \
293 setup_.c \
294 sha1_.c \
295 shun_.c \
296 sitemap_.c \
297 skins_.c \
298 sqlcmd_.c \
299 stash_.c \
300 stat_.c \
301 style_.c \
@@ -319,10 +333,11 @@
333 $(OX)\bisect$O \
334 $(OX)\blob$O \
335 $(OX)\branch$O \
336 $(OX)\browse$O \
337 $(OX)\builtin$O \
338 $(OX)\bundle$O \
339 $(OX)\cache$O \
340 $(OX)\captcha$O \
341 $(OX)\cgi$O \
342 $(OX)\checkin$O \
343 $(OX)\checkout$O \
@@ -342,10 +357,11 @@
357 $(OX)\encode$O \
358 $(OX)\event$O \
359 $(OX)\export$O \
360 $(OX)\file$O \
361 $(OX)\finfo$O \
362 $(OX)\foci$O \
363 $(OX)\fusefs$O \
364 $(OX)\glob$O \
365 $(OX)\graph$O \
366 $(OX)\gzip$O \
367 $(OX)\http$O \
@@ -385,10 +401,12 @@
401 $(OX)\path$O \
402 $(OX)\pivot$O \
403 $(OX)\popen$O \
404 $(OX)\pqueue$O \
405 $(OX)\printf$O \
406 $(OX)\publish$O \
407 $(OX)\purge$O \
408 $(OX)\rebuild$O \
409 $(OX)\regexp$O \
410 $(OX)\report$O \
411 $(OX)\rss$O \
412 $(OX)\schema$O \
@@ -395,10 +413,11 @@
413 $(OX)\search$O \
414 $(OX)\setup$O \
415 $(OX)\sha1$O \
416 $(OX)\shell$O \
417 $(OX)\shun$O \
418 $(OX)\sitemap$O \
419 $(OX)\skins$O \
420 $(OX)\sqlcmd$O \
421 $(OX)\sqlite3$O \
422 $(OX)\stash$O \
423 $(OX)\stat$O \
@@ -457,13 +476,13 @@
476 @set PATH=$(PERLDIR);$(PATH)
477 !endif
478 @pushd "$(SSLDIR)" && $(PERL) Configure $(SSLCONFIG) && popd
479 @pushd "$(SSLDIR)" && call $(SSLSETUP) && popd
480 !ifdef FOSSIL_ENABLE_WINXP
481 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS) $(XPCFLAGS)" "LFLAGS=$(SSLLFLAGS) $(XPLDFLAGS)" && popd
482 !else
483 @pushd "$(SSLDIR)" && $(MAKE) /f $(SSLNMAKE) "CC=cl $(SSLCFLAGS)" && popd
484 !endif
485 !endif
486
487 !ifndef FOSSIL_ENABLE_MINIZ
488 APPTARGETS = $(APPTARGETS) zlib
@@ -488,10 +507,11 @@
507 echo $(OX)\bisect.obj >> $@
508 echo $(OX)\blob.obj >> $@
509 echo $(OX)\branch.obj >> $@
510 echo $(OX)\browse.obj >> $@
511 echo $(OX)\builtin.obj >> $@
512 echo $(OX)\bundle.obj >> $@
513 echo $(OX)\cache.obj >> $@
514 echo $(OX)\captcha.obj >> $@
515 echo $(OX)\cgi.obj >> $@
516 echo $(OX)\checkin.obj >> $@
517 echo $(OX)\checkout.obj >> $@
@@ -511,10 +531,11 @@
531 echo $(OX)\encode.obj >> $@
532 echo $(OX)\event.obj >> $@
533 echo $(OX)\export.obj >> $@
534 echo $(OX)\file.obj >> $@
535 echo $(OX)\finfo.obj >> $@
536 echo $(OX)\foci.obj >> $@
537 echo $(OX)\fusefs.obj >> $@
538 echo $(OX)\glob.obj >> $@
539 echo $(OX)\graph.obj >> $@
540 echo $(OX)\gzip.obj >> $@
541 echo $(OX)\http.obj >> $@
@@ -554,10 +575,12 @@
575 echo $(OX)\path.obj >> $@
576 echo $(OX)\pivot.obj >> $@
577 echo $(OX)\popen.obj >> $@
578 echo $(OX)\pqueue.obj >> $@
579 echo $(OX)\printf.obj >> $@
580 echo $(OX)\publish.obj >> $@
581 echo $(OX)\purge.obj >> $@
582 echo $(OX)\rebuild.obj >> $@
583 echo $(OX)\regexp.obj >> $@
584 echo $(OX)\report.obj >> $@
585 echo $(OX)\rss.obj >> $@
586 echo $(OX)\schema.obj >> $@
@@ -564,10 +587,11 @@
587 echo $(OX)\search.obj >> $@
588 echo $(OX)\setup.obj >> $@
589 echo $(OX)\sha1.obj >> $@
590 echo $(OX)\shell.obj >> $@
591 echo $(OX)\shun.obj >> $@
592 echo $(OX)\sitemap.obj >> $@
593 echo $(OX)\skins.obj >> $@
594 echo $(OX)\sqlcmd.obj >> $@
595 echo $(OX)\sqlite3.obj >> $@
596 echo $(OX)\stash.obj >> $@
597 echo $(OX)\stat.obj >> $@
@@ -749,10 +773,16 @@
773 $(OX)\builtin$O : builtin_.c builtin.h
774 $(TCC) /Fo$@ -c builtin_.c
775
776 builtin_.c : $(SRCDIR)\builtin.c
777 translate$E $** > $@
778
779 $(OX)\bundle$O : bundle_.c bundle.h
780 $(TCC) /Fo$@ -c bundle_.c
781
782 bundle_.c : $(SRCDIR)\bundle.c
783 translate$E $** > $@
784
785 $(OX)\cache$O : cache_.c cache.h
786 $(TCC) /Fo$@ -c cache_.c
787
788 cache_.c : $(SRCDIR)\cache.c
@@ -881,10 +911,16 @@
911 $(OX)\finfo$O : finfo_.c finfo.h
912 $(TCC) /Fo$@ -c finfo_.c
913
914 finfo_.c : $(SRCDIR)\finfo.c
915 translate$E $** > $@
916
917 $(OX)\foci$O : foci_.c foci.h
918 $(TCC) /Fo$@ -c foci_.c
919
920 foci_.c : $(SRCDIR)\foci.c
921 translate$E $** > $@
922
923 $(OX)\fusefs$O : fusefs_.c fusefs.h
924 $(TCC) /Fo$@ -c fusefs_.c
925
926 fusefs_.c : $(SRCDIR)\fusefs.c
@@ -1139,10 +1175,22 @@
1175 $(OX)\printf$O : printf_.c printf.h
1176 $(TCC) /Fo$@ -c printf_.c
1177
1178 printf_.c : $(SRCDIR)\printf.c
1179 translate$E $** > $@
1180
1181 $(OX)\publish$O : publish_.c publish.h
1182 $(TCC) /Fo$@ -c publish_.c
1183
1184 publish_.c : $(SRCDIR)\publish.c
1185 translate$E $** > $@
1186
1187 $(OX)\purge$O : purge_.c purge.h
1188 $(TCC) /Fo$@ -c purge_.c
1189
1190 purge_.c : $(SRCDIR)\purge.c
1191 translate$E $** > $@
1192
1193 $(OX)\rebuild$O : rebuild_.c rebuild.h
1194 $(TCC) /Fo$@ -c rebuild_.c
1195
1196 rebuild_.c : $(SRCDIR)\rebuild.c
@@ -1193,10 +1241,16 @@
1241 $(OX)\shun$O : shun_.c shun.h
1242 $(TCC) /Fo$@ -c shun_.c
1243
1244 shun_.c : $(SRCDIR)\shun.c
1245 translate$E $** > $@
1246
1247 $(OX)\sitemap$O : sitemap_.c sitemap.h
1248 $(TCC) /Fo$@ -c sitemap_.c
1249
1250 sitemap_.c : $(SRCDIR)\sitemap.c
1251 translate$E $** > $@
1252
1253 $(OX)\skins$O : skins_.c skins.h
1254 $(TCC) /Fo$@ -c skins_.c
1255
1256 skins_.c : $(SRCDIR)\skins.c
@@ -1381,10 +1435,11 @@
1435 bisect_.c:bisect.h \
1436 blob_.c:blob.h \
1437 branch_.c:branch.h \
1438 browse_.c:browse.h \
1439 builtin_.c:builtin.h \
1440 bundle_.c:bundle.h \
1441 cache_.c:cache.h \
1442 captcha_.c:captcha.h \
1443 cgi_.c:cgi.h \
1444 checkin_.c:checkin.h \
1445 checkout_.c:checkout.h \
@@ -1403,10 +1458,11 @@
1458 encode_.c:encode.h \
1459 event_.c:event.h \
1460 export_.c:export.h \
1461 file_.c:file.h \
1462 finfo_.c:finfo.h \
1463 foci_.c:foci.h \
1464 fusefs_.c:fusefs.h \
1465 glob_.c:glob.h \
1466 graph_.c:graph.h \
1467 gzip_.c:gzip.h \
1468 http_.c:http.h \
@@ -1446,19 +1502,22 @@
1502 path_.c:path.h \
1503 pivot_.c:pivot.h \
1504 popen_.c:popen.h \
1505 pqueue_.c:pqueue.h \
1506 printf_.c:printf.h \
1507 publish_.c:publish.h \
1508 purge_.c:purge.h \
1509 rebuild_.c:rebuild.h \
1510 regexp_.c:regexp.h \
1511 report_.c:report.h \
1512 rss_.c:rss.h \
1513 schema_.c:schema.h \
1514 search_.c:search.h \
1515 setup_.c:setup.h \
1516 sha1_.c:sha1.h \
1517 shun_.c:shun.h \
1518 sitemap_.c:sitemap.h \
1519 skins_.c:skins.h \
1520 sqlcmd_.c:sqlcmd.h \
1521 stash_.c:stash.h \
1522 stat_.c:stat.h \
1523 style_.c:style.h \
1524
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -115,10 +115,31 @@
115115
116116
The "tag:deed2" name will refer to the most recent check-in
117117
tagged with "deed2" not to the
118118
check-in whose canonical name begins with "deed2".
119119
120
+<h2>Whole Branches</h2>
121
+
122
+Usually whan a branch name is specified, it means the latest checkin on
123
+that branch. But for some commands (ex: [/help/purge|purge]) a branch name
124
+on the argument means the earliest connected checkin on the branch. This
125
+seems confusing when being explained here, but it works out to be intuitive
126
+in practice.
127
+
128
+For example, the command "fossil purge XYZ" means to purge the checkin XYZ
129
+and all of its descendents. But when XYZ is in the form of a branch name, one
130
+generally wants to purge the entire branch, not just the last checkin on the
131
+branch. And so for this reason, commands like purge will interpret a branch
132
+name to be the first checkin of the branch rather than the last. If there
133
+are two or more branches with the same name, then these commands will select
134
+the first check-in of the branch that has the most recent checkin. What
135
+happens is that Fossil searches for the most recent checkin with the given
136
+tag, just as it always does. But if that tag is a branch name, it then walks
137
+back down the branch looking for the first check-in of that branch.
138
+
139
+Again, this behavior only occurs on a few commands where it make sense.
140
+
120141
<h2>Timestamps</h2>
121142
122143
A timestamp in one of the formats shown below means the most recent
123144
check-in that occurs no later than the timestamp given:
124145
125146
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -115,10 +115,31 @@
115
116 The "tag:deed2" name will refer to the most recent check-in
117 tagged with "deed2" not to the
118 check-in whose canonical name begins with "deed2".
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120 <h2>Timestamps</h2>
121
122 A timestamp in one of the formats shown below means the most recent
123 check-in that occurs no later than the timestamp given:
124
125
--- www/checkin_names.wiki
+++ www/checkin_names.wiki
@@ -115,10 +115,31 @@
115
116 The "tag:deed2" name will refer to the most recent check-in
117 tagged with "deed2" not to the
118 check-in whose canonical name begins with "deed2".
119
120 <h2>Whole Branches</h2>
121
122 Usually whan a branch name is specified, it means the latest checkin on
123 that branch. But for some commands (ex: [/help/purge|purge]) a branch name
124 on the argument means the earliest connected checkin on the branch. This
125 seems confusing when being explained here, but it works out to be intuitive
126 in practice.
127
128 For example, the command "fossil purge XYZ" means to purge the checkin XYZ
129 and all of its descendents. But when XYZ is in the form of a branch name, one
130 generally wants to purge the entire branch, not just the last checkin on the
131 branch. And so for this reason, commands like purge will interpret a branch
132 name to be the first checkin of the branch rather than the last. If there
133 are two or more branches with the same name, then these commands will select
134 the first check-in of the branch that has the most recent checkin. What
135 happens is that Fossil searches for the most recent checkin with the given
136 tag, just as it always does. But if that tag is a branch name, it then walks
137 back down the branch looking for the first check-in of that branch.
138
139 Again, this behavior only occurs on a few commands where it make sense.
140
141 <h2>Timestamps</h2>
142
143 A timestamp in one of the formats shown below means the most recent
144 check-in that occurs no later than the timestamp given:
145
146
--- www/concepts.wiki
+++ www/concepts.wiki
@@ -405,11 +405,11 @@
405405
can do pushes or pulls against your server. Use the <b>--port</b>
406406
option to the server command to specify a different TCP port. If
407407
you do not have a local source tree, use the <b>-R</b> command-line
408408
option to specify the repository file.
409409
410
-A stand-alone server is a great way to set of transient connections
410
+The "fossil server" command is a great way to set of transient connections
411411
between coworkers for doing quick pushes or pulls. But you can also
412412
set up a permanent stand-alone server if you prefer. Just make
413413
arrangements for fossil to be launched with appropriate arguments
414414
after every reboot.
415415
416416
--- www/concepts.wiki
+++ www/concepts.wiki
@@ -405,11 +405,11 @@
405 can do pushes or pulls against your server. Use the <b>--port</b>
406 option to the server command to specify a different TCP port. If
407 you do not have a local source tree, use the <b>-R</b> command-line
408 option to specify the repository file.
409
410 A stand-alone server is a great way to set of transient connections
411 between coworkers for doing quick pushes or pulls. But you can also
412 set up a permanent stand-alone server if you prefer. Just make
413 arrangements for fossil to be launched with appropriate arguments
414 after every reboot.
415
416
--- www/concepts.wiki
+++ www/concepts.wiki
@@ -405,11 +405,11 @@
405 can do pushes or pulls against your server. Use the <b>--port</b>
406 option to the server command to specify a different TCP port. If
407 you do not have a local source tree, use the <b>-R</b> command-line
408 option to specify the repository file.
409
410 The "fossil server" command is a great way to set of transient connections
411 between coworkers for doing quick pushes or pulls. But you can also
412 set up a permanent stand-alone server if you prefer. Just make
413 arrangements for fossil to be launched with appropriate arguments
414 after every reboot.
415
416
+8 -8
--- www/faq.tcl
+++ www/faq.tcl
@@ -55,12 +55,12 @@
5555
If you already have a fork in your check-in tree and you want to convert
5656
that fork to a branch, you can do this from the web interface.
5757
First locate the check-in that you want to be
5858
the initial check-in of your branch on the timeline and click on its
5959
link so that you are on the <b>ci</b> page. Then find the "<b>edit</b>"
60
- link (near the "Commands:" label) and click on that. On the
61
- "Edit Check-in" page, check the box beside "Branching:" and fill in
60
+ link (near the "Commands:" label) and click on that. On the
61
+ "Edit Check-in" page, check the box beside "Branching:" and fill in
6262
the name of your new branch to the right and press the "Apply Changes"
6363
button.
6464
}
6565
6666
faq {
@@ -83,31 +83,31 @@
8383
8484
The CHECK-IN in the previous line can be any
8585
[./checkin_names.wiki | valid check-in name format].
8686
8787
You can also add (and remove) tags from a check-in using the
88
- [./webui.wiki | web interface]. First locate the check-in that you
88
+ [./webui.wiki | web interface]. First locate the check-in that you
8989
what to tag on the tmline, then click on the link to go the detailed
9090
information page for that check-in. Then find the "<b>edit</b>"
9191
link (near the "Commands:" label) and click on that. There are
9292
controls on the edit page that allow new tags to be added and existing
9393
tags to be removed.
94
-}
94
+}
9595
9696
faq {
9797
How do I create a private branch that won't get pushed back to the
9898
main repository.
9999
} {
100
- Use the <b>--private</b> command-line option on the
100
+ Use the <b>--private</b> command-line option on the
101101
<b>commit</b> command. The result will be a check-in which exists on
102
- your local repository only and is never pushed to other repositories.
102
+ your local repository only and is never pushed to other repositories.
103103
All descendents of a private check-in are also private.
104
-
104
+
105105
Unless you specify something different using the <b>--branch</b> and/or
106106
<b>--bgcolor</b> options, the new private check-in will be put on a branch
107107
named "private" with an orange background color.
108
-
108
+
109109
You can merge from the trunk into your private branch in order to keep
110110
your private branch in sync with the latest changes on the trunk. Once
111111
you have everything in your private branch the way you want it, you can
112112
then merge your private branch back into the trunk and push. Only the
113113
final merge operation will appear in other repositories. It will seem
114114
--- www/faq.tcl
+++ www/faq.tcl
@@ -55,12 +55,12 @@
55 If you already have a fork in your check-in tree and you want to convert
56 that fork to a branch, you can do this from the web interface.
57 First locate the check-in that you want to be
58 the initial check-in of your branch on the timeline and click on its
59 link so that you are on the <b>ci</b> page. Then find the "<b>edit</b>"
60 link (near the "Commands:" label) and click on that. On the
61 "Edit Check-in" page, check the box beside "Branching:" and fill in
62 the name of your new branch to the right and press the "Apply Changes"
63 button.
64 }
65
66 faq {
@@ -83,31 +83,31 @@
83
84 The CHECK-IN in the previous line can be any
85 [./checkin_names.wiki | valid check-in name format].
86
87 You can also add (and remove) tags from a check-in using the
88 [./webui.wiki | web interface]. First locate the check-in that you
89 what to tag on the tmline, then click on the link to go the detailed
90 information page for that check-in. Then find the "<b>edit</b>"
91 link (near the "Commands:" label) and click on that. There are
92 controls on the edit page that allow new tags to be added and existing
93 tags to be removed.
94 }
95
96 faq {
97 How do I create a private branch that won't get pushed back to the
98 main repository.
99 } {
100 Use the <b>--private</b> command-line option on the
101 <b>commit</b> command. The result will be a check-in which exists on
102 your local repository only and is never pushed to other repositories.
103 All descendents of a private check-in are also private.
104
105 Unless you specify something different using the <b>--branch</b> and/or
106 <b>--bgcolor</b> options, the new private check-in will be put on a branch
107 named "private" with an orange background color.
108
109 You can merge from the trunk into your private branch in order to keep
110 your private branch in sync with the latest changes on the trunk. Once
111 you have everything in your private branch the way you want it, you can
112 then merge your private branch back into the trunk and push. Only the
113 final merge operation will appear in other repositories. It will seem
114
--- www/faq.tcl
+++ www/faq.tcl
@@ -55,12 +55,12 @@
55 If you already have a fork in your check-in tree and you want to convert
56 that fork to a branch, you can do this from the web interface.
57 First locate the check-in that you want to be
58 the initial check-in of your branch on the timeline and click on its
59 link so that you are on the <b>ci</b> page. Then find the "<b>edit</b>"
60 link (near the "Commands:" label) and click on that. On the
61 "Edit Check-in" page, check the box beside "Branching:" and fill in
62 the name of your new branch to the right and press the "Apply Changes"
63 button.
64 }
65
66 faq {
@@ -83,31 +83,31 @@
83
84 The CHECK-IN in the previous line can be any
85 [./checkin_names.wiki | valid check-in name format].
86
87 You can also add (and remove) tags from a check-in using the
88 [./webui.wiki | web interface]. First locate the check-in that you
89 what to tag on the tmline, then click on the link to go the detailed
90 information page for that check-in. Then find the "<b>edit</b>"
91 link (near the "Commands:" label) and click on that. There are
92 controls on the edit page that allow new tags to be added and existing
93 tags to be removed.
94 }
95
96 faq {
97 How do I create a private branch that won't get pushed back to the
98 main repository.
99 } {
100 Use the <b>--private</b> command-line option on the
101 <b>commit</b> command. The result will be a check-in which exists on
102 your local repository only and is never pushed to other repositories.
103 All descendents of a private check-in are also private.
104
105 Unless you specify something different using the <b>--branch</b> and/or
106 <b>--bgcolor</b> options, the new private check-in will be put on a branch
107 named "private" with an orange background color.
108
109 You can merge from the trunk into your private branch in order to keep
110 your private branch in sync with the latest changes on the trunk. Once
111 you have everything in your private branch the way you want it, you can
112 then merge your private branch back into the trunk and push. Only the
113 final merge operation will appear in other repositories. It will seem
114
--- www/foss-cklist.wiki
+++ www/foss-cklist.wiki
@@ -5,11 +5,11 @@
55
blog post <a href="http://spot.livejournal.com/308370.html">
66
http://spot.livejournal.com/308370.html</a> (see also
77
<a href="http://www.theopensourceway.org/book/The_Open_Source_Way-How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL.html">[1]</a> and
88
<a href="https://www.theopensourceway.org/wiki/How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL">[2]</a>).
99
Tom's original post assigned point scores to the various elements and
10
-by adding together the individual points, the reader is suppose to be able
10
+by adding together the individual points, the reader is supposed to be able
1111
to judge the likelihood that the project will fail.
1212
The point scores, and the items on the list, clearly reflect Tom's
1313
biases and are not necessarily those of the larger open-source community.
1414
Nevertheless, the policy of the Fossil shall be to strive for a perfect
1515
score.</p>
1616
--- www/foss-cklist.wiki
+++ www/foss-cklist.wiki
@@ -5,11 +5,11 @@
5 blog post <a href="http://spot.livejournal.com/308370.html">
6 http://spot.livejournal.com/308370.html</a> (see also
7 <a href="http://www.theopensourceway.org/book/The_Open_Source_Way-How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL.html">[1]</a> and
8 <a href="https://www.theopensourceway.org/wiki/How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL">[2]</a>).
9 Tom's original post assigned point scores to the various elements and
10 by adding together the individual points, the reader is suppose to be able
11 to judge the likelihood that the project will fail.
12 The point scores, and the items on the list, clearly reflect Tom's
13 biases and are not necessarily those of the larger open-source community.
14 Nevertheless, the policy of the Fossil shall be to strive for a perfect
15 score.</p>
16
--- www/foss-cklist.wiki
+++ www/foss-cklist.wiki
@@ -5,11 +5,11 @@
5 blog post <a href="http://spot.livejournal.com/308370.html">
6 http://spot.livejournal.com/308370.html</a> (see also
7 <a href="http://www.theopensourceway.org/book/The_Open_Source_Way-How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL.html">[1]</a> and
8 <a href="https://www.theopensourceway.org/wiki/How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL">[2]</a>).
9 Tom's original post assigned point scores to the various elements and
10 by adding together the individual points, the reader is supposed to be able
11 to judge the likelihood that the project will fail.
12 The point scores, and the items on the list, clearly reflect Tom's
13 biases and are not necessarily those of the larger open-source community.
14 Nevertheless, the policy of the Fossil shall be to strive for a perfect
15 score.</p>
16
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -185,11 +185,11 @@
185185
between repositories and working checkouts. A power-loss or system crash
186186
in the middle of Git operation can damage or corrupt the Git repository.
187187
188188
A Fossil repository consists of a single disk file. A single Fossil
189189
repository can serve multiple simultaneous working checkouts.
190
-A Fossil repository is an SQLite database, so it highly resistant
190
+A Fossil repository is an SQLite database, so it is highly resistant
191191
to damage from a power-loss or system crash - incomplete transactions
192192
are simply rolled back after the system reboots.
193193
194194
<h3>3.8 Audit Trail</h3>
195195
196196
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -185,11 +185,11 @@
185 between repositories and working checkouts. A power-loss or system crash
186 in the middle of Git operation can damage or corrupt the Git repository.
187
188 A Fossil repository consists of a single disk file. A single Fossil
189 repository can serve multiple simultaneous working checkouts.
190 A Fossil repository is an SQLite database, so it highly resistant
191 to damage from a power-loss or system crash - incomplete transactions
192 are simply rolled back after the system reboots.
193
194 <h3>3.8 Audit Trail</h3>
195
196
--- www/fossil-v-git.wiki
+++ www/fossil-v-git.wiki
@@ -185,11 +185,11 @@
185 between repositories and working checkouts. A power-loss or system crash
186 in the middle of Git operation can damage or corrupt the Git repository.
187
188 A Fossil repository consists of a single disk file. A single Fossil
189 repository can serve multiple simultaneous working checkouts.
190 A Fossil repository is an SQLite database, so it is highly resistant
191 to damage from a power-loss or system crash - incomplete transactions
192 are simply rolled back after the system reboots.
193
194 <h3>3.8 Audit Trail</h3>
195
196
--- www/index.wiki
+++ www/index.wiki
@@ -110,10 +110,14 @@
110110
a Fossil repository.
111111
112112
<hr>
113113
<h3>Links For Fossil Users:</h3>
114114
115
+ * "Fuel" is cross-platform GUI front-end for Fossil
116
+ written in Qt. [http://fuelscm.org/].
117
+ Fuel is an independent project run by a different group of
118
+ developers.
115119
* [./reviews.wiki | Testimonials] from satisfied fossil users and
116120
[./quotes.wiki | Quotes] about Fossil and other DVCSes.
117121
* [./faq.wiki | FAQ]
118122
* The [./concepts.wiki | concepts] behind fossil
119123
* [./quickstart.wiki | Quick Start] guide to using fossil
120124
--- www/index.wiki
+++ www/index.wiki
@@ -110,10 +110,14 @@
110 a Fossil repository.
111
112 <hr>
113 <h3>Links For Fossil Users:</h3>
114
 
 
 
 
115 * [./reviews.wiki | Testimonials] from satisfied fossil users and
116 [./quotes.wiki | Quotes] about Fossil and other DVCSes.
117 * [./faq.wiki | FAQ]
118 * The [./concepts.wiki | concepts] behind fossil
119 * [./quickstart.wiki | Quick Start] guide to using fossil
120
--- www/index.wiki
+++ www/index.wiki
@@ -110,10 +110,14 @@
110 a Fossil repository.
111
112 <hr>
113 <h3>Links For Fossil Users:</h3>
114
115 * "Fuel" is cross-platform GUI front-end for Fossil
116 written in Qt. [http://fuelscm.org/].
117 Fuel is an independent project run by a different group of
118 developers.
119 * [./reviews.wiki | Testimonials] from satisfied fossil users and
120 [./quotes.wiki | Quotes] about Fossil and other DVCSes.
121 * [./faq.wiki | FAQ]
122 * The [./concepts.wiki | concepts] behind fossil
123 * [./quickstart.wiki | Quick Start] guide to using fossil
124
+1 -1
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -1,8 +1,8 @@
11
#!/bin/sh
22
#
3
-# Run this TCL script to generate a WIKI page that contains a
3
+# Run this TCL script to generate a WIKI page that contains a
44
# permuted index of the various documentation files.
55
#
66
# tclsh mkindex.tcl >permutedindex.wiki
77
#
88
99
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -1,8 +1,8 @@
1 #!/bin/sh
2 #
3 # Run this TCL script to generate a WIKI page that contains a
4 # permuted index of the various documentation files.
5 #
6 # tclsh mkindex.tcl >permutedindex.wiki
7 #
8
9
--- www/mkindex.tcl
+++ www/mkindex.tcl
@@ -1,8 +1,8 @@
1 #!/bin/sh
2 #
3 # Run this TCL script to generate a WIKI page that contains a
4 # permuted index of the various documentation files.
5 #
6 # tclsh mkindex.tcl >permutedindex.wiki
7 #
8
9
+1 -1
--- www/server.wiki
+++ www/server.wiki
@@ -70,11 +70,11 @@
7070
need to modify the pathnames for your particular setup.
7171
The final argument is either the name of the fossil repository to be served,
7272
or a directory containing multiple repositories.
7373
</p>
7474
<p>
75
-If you system is running xinetd, then the configuration is likely to be
75
+If your system is running xinetd, then the configuration is likely to be
7676
in the file "/etc/xinetd.conf" or in a subfile of "/etc/xinetd.d".
7777
An xinetd configuration file will appear like this:</p>
7878
<blockquote>
7979
<pre>
8080
service http-alt
8181
--- www/server.wiki
+++ www/server.wiki
@@ -70,11 +70,11 @@
70 need to modify the pathnames for your particular setup.
71 The final argument is either the name of the fossil repository to be served,
72 or a directory containing multiple repositories.
73 </p>
74 <p>
75 If you system is running xinetd, then the configuration is likely to be
76 in the file "/etc/xinetd.conf" or in a subfile of "/etc/xinetd.d".
77 An xinetd configuration file will appear like this:</p>
78 <blockquote>
79 <pre>
80 service http-alt
81
--- www/server.wiki
+++ www/server.wiki
@@ -70,11 +70,11 @@
70 need to modify the pathnames for your particular setup.
71 The final argument is either the name of the fossil repository to be served,
72 or a directory containing multiple repositories.
73 </p>
74 <p>
75 If your system is running xinetd, then the configuration is likely to be
76 in the file "/etc/xinetd.conf" or in a subfile of "/etc/xinetd.d".
77 An xinetd configuration file will appear like this:</p>
78 <blockquote>
79 <pre>
80 service http-alt
81

Keyboard Shortcuts

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