Fossil SCM

Merge trunk

jan.nijtmans 2019-02-24 14:35 openssl-1.1 merge
Commit af9dabcbf06d9bbf3094fe0516e422c5b506570eeb05cb352994bd0d72002938
+2 -1
--- src/blob.c
+++ src/blob.c
@@ -1263,11 +1263,12 @@
12631263
#else
12641264
const char cQuote = '\''; /* Use '...' quoting on unix */
12651265
#endif
12661266
12671267
for(i=0; (c = zIn[i])!=0; i++){
1268
- if( c==cQuote || c=='\\' || c<' ' || c==';' || c=='*' || c=='?' || c=='[') {
1268
+ if( c==cQuote || (unsigned char)c<' ' ||
1269
+ c=='\\' || c==';' || c=='*' || c=='?' || c=='[' ){
12691270
Blob bad;
12701271
blob_token(pBlob, &bad);
12711272
fossil_fatal("the [%s] argument to the \"%s\" command contains "
12721273
"a character (ascii 0x%02x) that is a security risk",
12731274
zIn, blob_str(&bad), c);
12741275
--- src/blob.c
+++ src/blob.c
@@ -1263,11 +1263,12 @@
1263 #else
1264 const char cQuote = '\''; /* Use '...' quoting on unix */
1265 #endif
1266
1267 for(i=0; (c = zIn[i])!=0; i++){
1268 if( c==cQuote || c=='\\' || c<' ' || c==';' || c=='*' || c=='?' || c=='[') {
 
1269 Blob bad;
1270 blob_token(pBlob, &bad);
1271 fossil_fatal("the [%s] argument to the \"%s\" command contains "
1272 "a character (ascii 0x%02x) that is a security risk",
1273 zIn, blob_str(&bad), c);
1274
--- src/blob.c
+++ src/blob.c
@@ -1263,11 +1263,12 @@
1263 #else
1264 const char cQuote = '\''; /* Use '...' quoting on unix */
1265 #endif
1266
1267 for(i=0; (c = zIn[i])!=0; i++){
1268 if( c==cQuote || (unsigned char)c<' ' ||
1269 c=='\\' || c==';' || c=='*' || c=='?' || c=='[' ){
1270 Blob bad;
1271 blob_token(pBlob, &bad);
1272 fossil_fatal("the [%s] argument to the \"%s\" command contains "
1273 "a character (ascii 0x%02x) that is a security risk",
1274 zIn, blob_str(&bad), c);
1275
+2 -2
--- src/diff.c
+++ src/diff.c
@@ -440,12 +440,12 @@
440440
* If the patch changes an empty file or results in an empty file,
441441
* the block header must use 0,0 as position indicator and not 1,0.
442442
* Otherwise, patch would be confused and may reject the diff.
443443
*/
444444
blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
445
- na ? a+skip+1 : 0, na,
446
- nb ? b+skip+1 : 0, nb);
445
+ na ? a+skip+1 : a+skip, na,
446
+ nb ? b+skip+1 : b+skip, nb);
447447
if( html ) blob_appendf(pOut, "</span>");
448448
blob_append(pOut, "\n", 1);
449449
}
450450
451451
/* Show the initial common area */
452452
--- src/diff.c
+++ src/diff.c
@@ -440,12 +440,12 @@
440 * If the patch changes an empty file or results in an empty file,
441 * the block header must use 0,0 as position indicator and not 1,0.
442 * Otherwise, patch would be confused and may reject the diff.
443 */
444 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
445 na ? a+skip+1 : 0, na,
446 nb ? b+skip+1 : 0, nb);
447 if( html ) blob_appendf(pOut, "</span>");
448 blob_append(pOut, "\n", 1);
449 }
450
451 /* Show the initial common area */
452
--- src/diff.c
+++ src/diff.c
@@ -440,12 +440,12 @@
440 * If the patch changes an empty file or results in an empty file,
441 * the block header must use 0,0 as position indicator and not 1,0.
442 * Otherwise, patch would be confused and may reject the diff.
443 */
444 blob_appendf(pOut,"@@ -%d,%d +%d,%d @@",
445 na ? a+skip+1 : a+skip, na,
446 nb ? b+skip+1 : b+skip, nb);
447 if( html ) blob_appendf(pOut, "</span>");
448 blob_append(pOut, "\n", 1);
449 }
450
451 /* Show the initial common area */
452
+14 -4
--- src/info.c
+++ src/info.c
@@ -1325,10 +1325,11 @@
13251325
/*
13261326
** Possible flags for the second parameter to
13271327
** object_description()
13281328
*/
13291329
#define OBJDESC_DETAIL 0x0001 /* more detail */
1330
+#define OBJDESC_BASE 0x0002 /* Set <base> using this object */
13301331
#endif
13311332
13321333
/*
13331334
** Write a description of an object to the www reply.
13341335
**
@@ -1354,10 +1355,11 @@
13541355
int nWiki = 0;
13551356
int objType = 0;
13561357
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
13571358
int showDetail = (objdescFlags & OBJDESC_DETAIL)!=0;
13581359
char *prevName = 0;
1360
+ int bNeedBase = (objdescFlags & OBJDESC_BASE)!=0;
13591361
13601362
db_prepare(&q,
13611363
"SELECT filename.name, datetime(event.mtime,toLocal()),"
13621364
" coalesce(event.ecomment,event.comment),"
13631365
" coalesce(event.euser,event.user),"
@@ -1402,10 +1404,14 @@
14021404
}else if( mPerm==PERM_EXE ){
14031405
@ <li>Executable file
14041406
objType |= OBJTYPE_EXE;
14051407
}else{
14061408
@ <li>File
1409
+ if( bNeedBase ){
1410
+ bNeedBase = 0;
1411
+ style_set_current_page("doc/%S/%s",zVers,zName);
1412
+ }
14071413
}
14081414
objType |= OBJTYPE_CONTENT;
14091415
@ %z(href("%R/finfo?name=%T&m=%!S",zName,zUuid))%h(zName)</a>
14101416
tag_private_status(rid);
14111417
if( showDetail ){
@@ -2068,11 +2074,11 @@
20682074
int renderAsWiki = 0;
20692075
int renderAsHtml = 0;
20702076
int objType;
20712077
int asText;
20722078
const char *zUuid;
2073
- u32 objdescFlags = 0;
2079
+ u32 objdescFlags = OBJDESC_BASE;
20742080
int descOnly = fossil_strcmp(g.zPath,"whatis")==0;
20752081
int isFile = fossil_strcmp(g.zPath,"file")==0;
20762082
const char *zLn = P("ln");
20772083
const char *zName = P("name");
20782084
HQuery url;
@@ -2145,10 +2151,12 @@
21452151
@ <h2>Artifact %s(zUuid) (%d(rid)):</h2>
21462152
}else{
21472153
@ <h2>Artifact %s(zUuid):</h2>
21482154
}
21492155
blob_zero(&downloadName);
2156
+ asText = P("txt")!=0;
2157
+ if( asText ) objdescFlags &= ~OBJDESC_BASE;
21502158
objType = object_description(rid, objdescFlags, &downloadName);
21512159
if( !descOnly && P("download")!=0 ){
21522160
cgi_redirectf("%R/raw/%T?name=%s", blob_str(&downloadName),
21532161
db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid));
21542162
/*NOTREACHED*/
@@ -2183,11 +2191,10 @@
21832191
style_submenu_element("Download", "%R/raw/%T?name=%s",
21842192
blob_str(&downloadName), zUuid);
21852193
if( db_exists("SELECT 1 FROM mlink WHERE fid=%d", rid) ){
21862194
style_submenu_element("Check-ins Using", "%R/timeline?n=200&uf=%s", zUuid);
21872195
}
2188
- asText = P("txt")!=0;
21892196
zMime = mimetype_from_name(blob_str(&downloadName));
21902197
if( zMime ){
21912198
if( fossil_strcmp(zMime, "text/html")==0 ){
21922199
if( asText ){
21932200
style_submenu_element("Html", "%s", url_render(&url, "txt", 0, 0, 0));
@@ -2244,12 +2251,12 @@
22442251
@ <pre>
22452252
@ %h(z)
22462253
@ </pre>
22472254
}
22482255
}else if( strncmp(zMime, "image/", 6)==0 ){
2249
- @ <i>(file is %d(blob_size(&content)) bytes of image data)</i><br />
2250
- @ <img src="%R/raw/%s(zUuid)?m=%s(zMime)" />
2256
+ @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p>
2257
+ @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p>
22512258
style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
22522259
}else{
22532260
@ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
22542261
}
22552262
@ </blockquote>
@@ -3171,6 +3178,9 @@
31713178
if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
31723179
apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fDryRun);
31733180
if( fDryRun==0 ){
31743181
show_common_info(rid, "uuid:", 1, 0);
31753182
}
3183
+ if( g.localOpen ){
3184
+ manifest_to_disk(rid);
3185
+ }
31763186
}
31773187
--- src/info.c
+++ src/info.c
@@ -1325,10 +1325,11 @@
1325 /*
1326 ** Possible flags for the second parameter to
1327 ** object_description()
1328 */
1329 #define OBJDESC_DETAIL 0x0001 /* more detail */
 
1330 #endif
1331
1332 /*
1333 ** Write a description of an object to the www reply.
1334 **
@@ -1354,10 +1355,11 @@
1354 int nWiki = 0;
1355 int objType = 0;
1356 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1357 int showDetail = (objdescFlags & OBJDESC_DETAIL)!=0;
1358 char *prevName = 0;
 
1359
1360 db_prepare(&q,
1361 "SELECT filename.name, datetime(event.mtime,toLocal()),"
1362 " coalesce(event.ecomment,event.comment),"
1363 " coalesce(event.euser,event.user),"
@@ -1402,10 +1404,14 @@
1402 }else if( mPerm==PERM_EXE ){
1403 @ <li>Executable file
1404 objType |= OBJTYPE_EXE;
1405 }else{
1406 @ <li>File
 
 
 
 
1407 }
1408 objType |= OBJTYPE_CONTENT;
1409 @ %z(href("%R/finfo?name=%T&m=%!S",zName,zUuid))%h(zName)</a>
1410 tag_private_status(rid);
1411 if( showDetail ){
@@ -2068,11 +2074,11 @@
2068 int renderAsWiki = 0;
2069 int renderAsHtml = 0;
2070 int objType;
2071 int asText;
2072 const char *zUuid;
2073 u32 objdescFlags = 0;
2074 int descOnly = fossil_strcmp(g.zPath,"whatis")==0;
2075 int isFile = fossil_strcmp(g.zPath,"file")==0;
2076 const char *zLn = P("ln");
2077 const char *zName = P("name");
2078 HQuery url;
@@ -2145,10 +2151,12 @@
2145 @ <h2>Artifact %s(zUuid) (%d(rid)):</h2>
2146 }else{
2147 @ <h2>Artifact %s(zUuid):</h2>
2148 }
2149 blob_zero(&downloadName);
 
 
2150 objType = object_description(rid, objdescFlags, &downloadName);
2151 if( !descOnly && P("download")!=0 ){
2152 cgi_redirectf("%R/raw/%T?name=%s", blob_str(&downloadName),
2153 db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid));
2154 /*NOTREACHED*/
@@ -2183,11 +2191,10 @@
2183 style_submenu_element("Download", "%R/raw/%T?name=%s",
2184 blob_str(&downloadName), zUuid);
2185 if( db_exists("SELECT 1 FROM mlink WHERE fid=%d", rid) ){
2186 style_submenu_element("Check-ins Using", "%R/timeline?n=200&uf=%s", zUuid);
2187 }
2188 asText = P("txt")!=0;
2189 zMime = mimetype_from_name(blob_str(&downloadName));
2190 if( zMime ){
2191 if( fossil_strcmp(zMime, "text/html")==0 ){
2192 if( asText ){
2193 style_submenu_element("Html", "%s", url_render(&url, "txt", 0, 0, 0));
@@ -2244,12 +2251,12 @@
2244 @ <pre>
2245 @ %h(z)
2246 @ </pre>
2247 }
2248 }else if( strncmp(zMime, "image/", 6)==0 ){
2249 @ <i>(file is %d(blob_size(&content)) bytes of image data)</i><br />
2250 @ <img src="%R/raw/%s(zUuid)?m=%s(zMime)" />
2251 style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
2252 }else{
2253 @ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
2254 }
2255 @ </blockquote>
@@ -3171,6 +3178,9 @@
3171 if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
3172 apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fDryRun);
3173 if( fDryRun==0 ){
3174 show_common_info(rid, "uuid:", 1, 0);
3175 }
 
 
 
3176 }
3177
--- src/info.c
+++ src/info.c
@@ -1325,10 +1325,11 @@
1325 /*
1326 ** Possible flags for the second parameter to
1327 ** object_description()
1328 */
1329 #define OBJDESC_DETAIL 0x0001 /* more detail */
1330 #define OBJDESC_BASE 0x0002 /* Set <base> using this object */
1331 #endif
1332
1333 /*
1334 ** Write a description of an object to the www reply.
1335 **
@@ -1354,10 +1355,11 @@
1355 int nWiki = 0;
1356 int objType = 0;
1357 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
1358 int showDetail = (objdescFlags & OBJDESC_DETAIL)!=0;
1359 char *prevName = 0;
1360 int bNeedBase = (objdescFlags & OBJDESC_BASE)!=0;
1361
1362 db_prepare(&q,
1363 "SELECT filename.name, datetime(event.mtime,toLocal()),"
1364 " coalesce(event.ecomment,event.comment),"
1365 " coalesce(event.euser,event.user),"
@@ -1402,10 +1404,14 @@
1404 }else if( mPerm==PERM_EXE ){
1405 @ <li>Executable file
1406 objType |= OBJTYPE_EXE;
1407 }else{
1408 @ <li>File
1409 if( bNeedBase ){
1410 bNeedBase = 0;
1411 style_set_current_page("doc/%S/%s",zVers,zName);
1412 }
1413 }
1414 objType |= OBJTYPE_CONTENT;
1415 @ %z(href("%R/finfo?name=%T&m=%!S",zName,zUuid))%h(zName)</a>
1416 tag_private_status(rid);
1417 if( showDetail ){
@@ -2068,11 +2074,11 @@
2074 int renderAsWiki = 0;
2075 int renderAsHtml = 0;
2076 int objType;
2077 int asText;
2078 const char *zUuid;
2079 u32 objdescFlags = OBJDESC_BASE;
2080 int descOnly = fossil_strcmp(g.zPath,"whatis")==0;
2081 int isFile = fossil_strcmp(g.zPath,"file")==0;
2082 const char *zLn = P("ln");
2083 const char *zName = P("name");
2084 HQuery url;
@@ -2145,10 +2151,12 @@
2151 @ <h2>Artifact %s(zUuid) (%d(rid)):</h2>
2152 }else{
2153 @ <h2>Artifact %s(zUuid):</h2>
2154 }
2155 blob_zero(&downloadName);
2156 asText = P("txt")!=0;
2157 if( asText ) objdescFlags &= ~OBJDESC_BASE;
2158 objType = object_description(rid, objdescFlags, &downloadName);
2159 if( !descOnly && P("download")!=0 ){
2160 cgi_redirectf("%R/raw/%T?name=%s", blob_str(&downloadName),
2161 db_text("?", "SELECT uuid FROM blob WHERE rid=%d", rid));
2162 /*NOTREACHED*/
@@ -2183,11 +2191,10 @@
2191 style_submenu_element("Download", "%R/raw/%T?name=%s",
2192 blob_str(&downloadName), zUuid);
2193 if( db_exists("SELECT 1 FROM mlink WHERE fid=%d", rid) ){
2194 style_submenu_element("Check-ins Using", "%R/timeline?n=200&uf=%s", zUuid);
2195 }
 
2196 zMime = mimetype_from_name(blob_str(&downloadName));
2197 if( zMime ){
2198 if( fossil_strcmp(zMime, "text/html")==0 ){
2199 if( asText ){
2200 style_submenu_element("Html", "%s", url_render(&url, "txt", 0, 0, 0));
@@ -2244,12 +2251,12 @@
2251 @ <pre>
2252 @ %h(z)
2253 @ </pre>
2254 }
2255 }else if( strncmp(zMime, "image/", 6)==0 ){
2256 @ <p>(file is %d(blob_size(&content)) bytes of image data)</i></p>
2257 @ <p><img src="%R/raw/%s(zUuid)?m=%s(zMime)"></p>
2258 style_submenu_element("Image", "%R/raw/%s?m=%s", zUuid, zMime);
2259 }else{
2260 @ <i>(file is %d(blob_size(&content)) bytes of binary data)</i>
2261 }
2262 @ </blockquote>
@@ -3171,6 +3178,9 @@
3178 if( zNewBranch && zNewBranch[0] ) change_branch(rid,zNewBranch);
3179 apply_newtags(&ctrl, rid, zUuid, zUserOvrd, fDryRun);
3180 if( fDryRun==0 ){
3181 show_common_info(rid, "uuid:", 1, 0);
3182 }
3183 if( g.localOpen ){
3184 manifest_to_disk(rid);
3185 }
3186 }
3187
+172 -6
--- src/rebuild.c
+++ src/rebuild.c
@@ -182,11 +182,14 @@
182182
static int processCnt; /* Number processed so far */
183183
static int ttyOutput; /* Do progress output */
184184
static Bag bagDone; /* Bag of records rebuilt */
185185
186186
static char *zFNameFormat; /* Format string for filenames on deconstruct */
187
+static int cchFNamePrefix; /* Length of directory prefix in zFNameFormat */
188
+static char *zDestDir; /* Destination directory on deconstruct */
187189
static int prefixLength; /* Length of directory prefix for deconstruct */
190
+static int fKeepRid1; /* Flag to preserve RID=1 on de- and reconstruct */
188191
189192
190193
/*
191194
** Draw the percent-complete message.
192195
** The input is actually the permill complete.
@@ -274,10 +277,21 @@
274277
/* We are doing "fossil deconstruct" */
275278
char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
276279
char *zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/,
277280
zUuid, zUuid+prefixLength);
278281
blob_write_to_file(pUse,zFile);
282
+ if( rid==1 && fKeepRid1!=0 ){
283
+ char *zFnDotRid1 = mprintf("%s/.rid1", zDestDir);
284
+ char *zFnRid1 = zFile + cchFNamePrefix + 1; /* Skip directory slash */
285
+ Blob bFileContents = empty_blob;
286
+ blob_appendf(&bFileContents,
287
+ "# The file holding the artifact with RID=1\n"
288
+ "%s\n", zFnRid1);
289
+ blob_write_to_file(&bFileContents, zFnDotRid1);
290
+ blob_reset(&bFileContents);
291
+ free(zFnDotRid1);
292
+ }
279293
free(zFile);
280294
free(zUuid);
281295
blob_reset(pUse);
282296
}
283297
assert( blob_is_reset(pUse) );
@@ -931,11 +945,50 @@
931945
struct dirent *pEntry;
932946
Blob aContent; /* content of the just read artifact */
933947
static int nFileRead = 0;
934948
void *zUnicodePath;
935949
char *zUtf8Name;
950
+ static int recursionLevel = 0; /* Bookkeeping about the recursion level */
951
+ static char *zFnRid1 = 0; /* The file holding the artifact with RID=1 */
952
+ static int cchPathInitial = 0; /* The length of zPath on first recursion */
936953
954
+ recursionLevel++;
955
+ if( recursionLevel==1 ){
956
+ cchPathInitial = strlen(zPath);
957
+ if( fKeepRid1!=0 ){
958
+ char *zFnDotRid1 = mprintf("%s/.rid1", zPath);
959
+ Blob bFileContents;
960
+ if( blob_read_from_file(&bFileContents, zFnDotRid1, ExtFILE)!=-1 ){
961
+ Blob line, value;
962
+ while( blob_line(&bFileContents, &line)>0 ){
963
+ if( blob_token(&line, &value)==0 ) continue; /* Empty line */
964
+ if( blob_buffer(&value)[0]=='#' ) continue; /* Comment */
965
+ blob_trim(&value);
966
+ zFnRid1 = mprintf("%s/%s", zPath, blob_str(&value));
967
+ break;
968
+ }
969
+ blob_reset(&bFileContents);
970
+ if( zFnRid1 ){
971
+ if( blob_read_from_file(&aContent, zFnRid1, ExtFILE)==-1 ){
972
+ fossil_fatal("some unknown error occurred while reading \"%s\"",
973
+ zFnRid1);
974
+ }else{
975
+ recon_set_hash_policy(0, zFnRid1);
976
+ content_put(&aContent);
977
+ recon_restore_hash_policy();
978
+ blob_reset(&aContent);
979
+ fossil_print("\r%d", ++nFileRead);
980
+ fflush(stdout);
981
+ }
982
+ }else{
983
+ fossil_fatal("an error occurred while reading or parsing \"%s\"",
984
+ zFnDotRid1);
985
+ }
986
+ }
987
+ free(zFnDotRid1);
988
+ }
989
+ }
937990
zUnicodePath = fossil_utf8_to_path(zPath, 1);
938991
d = opendir(zUnicodePath);
939992
if( d ){
940993
while( (pEntry=readdir(d))!=0 ){
941994
Blob path;
@@ -953,18 +1006,20 @@
9531006
#else
9541007
if( file_isdir(zSubpath, ExtFILE)==1 )
9551008
#endif
9561009
{
9571010
recon_read_dir(zSubpath);
958
- }else{
1011
+ }else if( fossil_strcmp(zSubpath, zFnRid1)!=0 ){
9591012
blob_init(&path, 0, 0);
9601013
blob_appendf(&path, "%s", zSubpath);
9611014
if( blob_read_from_file(&aContent, blob_str(&path), ExtFILE)==-1 ){
9621015
fossil_fatal("some unknown error occurred while reading \"%s\"",
9631016
blob_str(&path));
9641017
}
1018
+ recon_set_hash_policy(cchPathInitial, blob_str(&path));
9651019
content_put(&aContent);
1020
+ recon_restore_hash_policy();
9661021
blob_reset(&path);
9671022
blob_reset(&aContent);
9681023
fossil_print("\r%d", ++nFileRead);
9691024
fflush(stdout);
9701025
}
@@ -974,26 +1029,134 @@
9741029
}else {
9751030
fossil_fatal("encountered error %d while trying to open \"%s\".",
9761031
errno, g.argv[3]);
9771032
}
9781033
fossil_path_free(zUnicodePath);
1034
+ if( recursionLevel==1 && zFnRid1!=0 ) free(zFnRid1);
1035
+ recursionLevel--;
1036
+}
1037
+
1038
+/*
1039
+** Helper functions called from recon_read_dir() to set and restore the correct
1040
+** hash policy for an artifact read from disk, inferred from the length of the
1041
+** path name.
1042
+*/
1043
+static int saved_eHashPolicy = -1;
1044
+
1045
+void recon_set_hash_policy(
1046
+ const int cchPathPrefix, /* Directory prefix length for zUuidAsFilePath */
1047
+ const char *zUuidAsFilePath /* Relative, well-formed, from recon_read_dir() */
1048
+){
1049
+ int cchUuidAsFilePath;
1050
+ const char *zHashPart;
1051
+ int cchHashPart = 0;
1052
+ int new_eHashPolicy = -1;
1053
+ assert( HNAME_COUNT==2 ); /* Review function if new hashes are implemented. */
1054
+ if( zUuidAsFilePath==0 ) return;
1055
+ cchUuidAsFilePath = strlen(zUuidAsFilePath);
1056
+ if( cchUuidAsFilePath==0 ) return;
1057
+ if( cchPathPrefix>=cchUuidAsFilePath ) return;
1058
+ for( zHashPart = zUuidAsFilePath + cchPathPrefix; *zHashPart; zHashPart++ ){
1059
+ if( *zHashPart!='/' ) cchHashPart++;
1060
+ }
1061
+ if( cchHashPart>=HNAME_LEN_K256 ){
1062
+ new_eHashPolicy = HPOLICY_SHA3;
1063
+ }else if( cchHashPart>=HNAME_LEN_SHA1 ){
1064
+ new_eHashPolicy = HPOLICY_SHA1;
1065
+ }
1066
+ if( new_eHashPolicy!=-1 ){
1067
+ saved_eHashPolicy = g.eHashPolicy;
1068
+ g.eHashPolicy = new_eHashPolicy;
1069
+ }
1070
+}
1071
+
1072
+void recon_restore_hash_policy(){
1073
+ if( saved_eHashPolicy!=-1 ){
1074
+ g.eHashPolicy = saved_eHashPolicy;
1075
+ saved_eHashPolicy = -1;
1076
+ }
1077
+}
1078
+
1079
+#if 0
1080
+/*
1081
+** COMMAND: test-hash-from-path*
1082
+**
1083
+** Usage: %fossil test-hash-from-path ?OPTIONS? DESTINATION UUID
1084
+**
1085
+** Generate a sample path name from DESTINATION and UUID, as the `deconstruct'
1086
+** command would do. Then try to guess the hash policy from the path name, as
1087
+** the `reconstruct' command would do.
1088
+**
1089
+** No files or directories will be created.
1090
+**
1091
+** Options:
1092
+** -L|--prefixlength N Set the length of the names of the DESTINATION
1093
+** subdirectories to N.
1094
+*/
1095
+void test_hash_from_path_cmd(void) {
1096
+ char *zDest;
1097
+ char *zUuid;
1098
+ char *zFile;
1099
+ const char *zHashPolicy = "unknown";
1100
+ const char *zPrefixOpt = find_option("prefixlength","L",1);
1101
+ int iPrefixLength;
1102
+ if( !zPrefixOpt ){
1103
+ iPrefixLength = 2;
1104
+ }else{
1105
+ iPrefixLength = atoi(zPrefixOpt);
1106
+ if( iPrefixLength<0 || iPrefixLength>9 ){
1107
+ fossil_fatal("N(%s) is not a valid prefix length!",zPrefixOpt);
1108
+ }
1109
+ }
1110
+ if( g.argc!=4 ){
1111
+ usage ("?OPTIONS? DESTINATION UUID");
1112
+ }
1113
+ zDest = g.argv[2];
1114
+ zUuid = g.argv[3];
1115
+ if( iPrefixLength ){
1116
+ zFNameFormat = mprintf("%s/%%.%ds/%%s",zDest,iPrefixLength);
1117
+ }else{
1118
+ zFNameFormat = mprintf("%s/%%s",zDest);
1119
+ }
1120
+ cchFNamePrefix = strlen(zDest);
1121
+ zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/,
1122
+ zUuid, zUuid+iPrefixLength);
1123
+ recon_set_hash_policy(cchFNamePrefix,zFile);
1124
+ if( saved_eHashPolicy!=-1 ){
1125
+ zHashPolicy = hpolicy_name();
1126
+ }
1127
+ recon_restore_hash_policy();
1128
+ fossil_print(
1129
+ "\nPath Name: %s"
1130
+ "\nHash Policy: %s\n",
1131
+ zFile,zHashPolicy);
1132
+ free(zFile);
1133
+ free(zFNameFormat);
1134
+ zFNameFormat = 0;
1135
+ cchFNamePrefix = 0;
9791136
}
1137
+#endif
9801138
9811139
/*
9821140
** COMMAND: reconstruct*
9831141
**
984
-** Usage: %fossil reconstruct FILENAME DIRECTORY
1142
+** Usage: %fossil reconstruct ?OPTIONS? FILENAME DIRECTORY
9851143
**
9861144
** This command studies the artifacts (files) in DIRECTORY and
9871145
** reconstructs the fossil record from them. It places the new
9881146
** fossil repository in FILENAME. Subdirectories are read, files
9891147
** with leading '.' in the filename are ignored.
9901148
**
1149
+** Options:
1150
+** -K|--keep-rid1 Read the filename of the artifact with
1151
+** RID=1 from the file .rid in DIRECTORY.
1152
+**
9911153
** See also: deconstruct, rebuild
9921154
*/
9931155
void reconstruct_cmd(void) {
9941156
char *zPassword;
1157
+ fKeepRid1 = find_option("keep-rid1","K",0)!=0;
9951158
if( g.argc!=4 ){
9961159
usage("FILENAME DIRECTORY");
9971160
}
9981161
if( file_isdir(g.argv[3], ExtFILE)!=1 ){
9991162
fossil_print("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -1041,23 +1204,25 @@
10411204
** AABBBBBBBBB.. is the 40+ character artifact ID, AA the first 2 characters.
10421205
** If -L|--prefixlength is given, the length (default 2) of the directory
10431206
** prefix can be set to 0,1,..,9 characters.
10441207
**
10451208
** Options:
1046
-** -R|--repository REPOSITORY deconstruct given REPOSITORY
1047
-** -L|--prefixlength N set the length of the names of the DESTINATION
1048
-** subdirectories to N
1209
+** -R|--repository REPOSITORY Deconstruct given REPOSITORY.
1210
+** -K|--keep-rid1 Save the filename of the artifact with RID=1 to
1211
+** the file .rid1 in the DESTINATION directory.
1212
+** -L|--prefixlength N Set the length of the names of the DESTINATION
1213
+** subdirectories to N.
10491214
** --private Include private artifacts.
10501215
**
10511216
** See also: rebuild, reconstruct
10521217
*/
10531218
void deconstruct_cmd(void){
1054
- const char *zDestDir;
10551219
const char *zPrefixOpt;
10561220
Stmt s;
10571221
int privateFlag;
10581222
1223
+ fKeepRid1 = find_option("keep-rid1","K",0)!=0;
10591224
/* get and check prefix length argument and build format string */
10601225
zPrefixOpt=find_option("prefixlength","L",1);
10611226
if( !zPrefixOpt ){
10621227
prefixLength = 2;
10631228
}else{
@@ -1092,10 +1257,11 @@
10921257
if( prefixLength ){
10931258
zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength);
10941259
}else{
10951260
zFNameFormat = mprintf("%s/%%s",zDestDir);
10961261
}
1262
+ cchFNamePrefix = strlen(zDestDir);
10971263
10981264
bag_init(&bagDone);
10991265
ttyOutput = 1;
11001266
processCnt = 0;
11011267
if (!g.fQuiet) {
11021268
--- src/rebuild.c
+++ src/rebuild.c
@@ -182,11 +182,14 @@
182 static int processCnt; /* Number processed so far */
183 static int ttyOutput; /* Do progress output */
184 static Bag bagDone; /* Bag of records rebuilt */
185
186 static char *zFNameFormat; /* Format string for filenames on deconstruct */
 
 
187 static int prefixLength; /* Length of directory prefix for deconstruct */
 
188
189
190 /*
191 ** Draw the percent-complete message.
192 ** The input is actually the permill complete.
@@ -274,10 +277,21 @@
274 /* We are doing "fossil deconstruct" */
275 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
276 char *zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/,
277 zUuid, zUuid+prefixLength);
278 blob_write_to_file(pUse,zFile);
 
 
 
 
 
 
 
 
 
 
 
279 free(zFile);
280 free(zUuid);
281 blob_reset(pUse);
282 }
283 assert( blob_is_reset(pUse) );
@@ -931,11 +945,50 @@
931 struct dirent *pEntry;
932 Blob aContent; /* content of the just read artifact */
933 static int nFileRead = 0;
934 void *zUnicodePath;
935 char *zUtf8Name;
 
 
 
936
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
937 zUnicodePath = fossil_utf8_to_path(zPath, 1);
938 d = opendir(zUnicodePath);
939 if( d ){
940 while( (pEntry=readdir(d))!=0 ){
941 Blob path;
@@ -953,18 +1006,20 @@
953 #else
954 if( file_isdir(zSubpath, ExtFILE)==1 )
955 #endif
956 {
957 recon_read_dir(zSubpath);
958 }else{
959 blob_init(&path, 0, 0);
960 blob_appendf(&path, "%s", zSubpath);
961 if( blob_read_from_file(&aContent, blob_str(&path), ExtFILE)==-1 ){
962 fossil_fatal("some unknown error occurred while reading \"%s\"",
963 blob_str(&path));
964 }
 
965 content_put(&aContent);
 
966 blob_reset(&path);
967 blob_reset(&aContent);
968 fossil_print("\r%d", ++nFileRead);
969 fflush(stdout);
970 }
@@ -974,26 +1029,134 @@
974 }else {
975 fossil_fatal("encountered error %d while trying to open \"%s\".",
976 errno, g.argv[3]);
977 }
978 fossil_path_free(zUnicodePath);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
979 }
 
980
981 /*
982 ** COMMAND: reconstruct*
983 **
984 ** Usage: %fossil reconstruct FILENAME DIRECTORY
985 **
986 ** This command studies the artifacts (files) in DIRECTORY and
987 ** reconstructs the fossil record from them. It places the new
988 ** fossil repository in FILENAME. Subdirectories are read, files
989 ** with leading '.' in the filename are ignored.
990 **
 
 
 
 
991 ** See also: deconstruct, rebuild
992 */
993 void reconstruct_cmd(void) {
994 char *zPassword;
 
995 if( g.argc!=4 ){
996 usage("FILENAME DIRECTORY");
997 }
998 if( file_isdir(g.argv[3], ExtFILE)!=1 ){
999 fossil_print("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -1041,23 +1204,25 @@
1041 ** AABBBBBBBBB.. is the 40+ character artifact ID, AA the first 2 characters.
1042 ** If -L|--prefixlength is given, the length (default 2) of the directory
1043 ** prefix can be set to 0,1,..,9 characters.
1044 **
1045 ** Options:
1046 ** -R|--repository REPOSITORY deconstruct given REPOSITORY
1047 ** -L|--prefixlength N set the length of the names of the DESTINATION
1048 ** subdirectories to N
 
 
1049 ** --private Include private artifacts.
1050 **
1051 ** See also: rebuild, reconstruct
1052 */
1053 void deconstruct_cmd(void){
1054 const char *zDestDir;
1055 const char *zPrefixOpt;
1056 Stmt s;
1057 int privateFlag;
1058
 
1059 /* get and check prefix length argument and build format string */
1060 zPrefixOpt=find_option("prefixlength","L",1);
1061 if( !zPrefixOpt ){
1062 prefixLength = 2;
1063 }else{
@@ -1092,10 +1257,11 @@
1092 if( prefixLength ){
1093 zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength);
1094 }else{
1095 zFNameFormat = mprintf("%s/%%s",zDestDir);
1096 }
 
1097
1098 bag_init(&bagDone);
1099 ttyOutput = 1;
1100 processCnt = 0;
1101 if (!g.fQuiet) {
1102
--- src/rebuild.c
+++ src/rebuild.c
@@ -182,11 +182,14 @@
182 static int processCnt; /* Number processed so far */
183 static int ttyOutput; /* Do progress output */
184 static Bag bagDone; /* Bag of records rebuilt */
185
186 static char *zFNameFormat; /* Format string for filenames on deconstruct */
187 static int cchFNamePrefix; /* Length of directory prefix in zFNameFormat */
188 static char *zDestDir; /* Destination directory on deconstruct */
189 static int prefixLength; /* Length of directory prefix for deconstruct */
190 static int fKeepRid1; /* Flag to preserve RID=1 on de- and reconstruct */
191
192
193 /*
194 ** Draw the percent-complete message.
195 ** The input is actually the permill complete.
@@ -274,10 +277,21 @@
277 /* We are doing "fossil deconstruct" */
278 char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid);
279 char *zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/,
280 zUuid, zUuid+prefixLength);
281 blob_write_to_file(pUse,zFile);
282 if( rid==1 && fKeepRid1!=0 ){
283 char *zFnDotRid1 = mprintf("%s/.rid1", zDestDir);
284 char *zFnRid1 = zFile + cchFNamePrefix + 1; /* Skip directory slash */
285 Blob bFileContents = empty_blob;
286 blob_appendf(&bFileContents,
287 "# The file holding the artifact with RID=1\n"
288 "%s\n", zFnRid1);
289 blob_write_to_file(&bFileContents, zFnDotRid1);
290 blob_reset(&bFileContents);
291 free(zFnDotRid1);
292 }
293 free(zFile);
294 free(zUuid);
295 blob_reset(pUse);
296 }
297 assert( blob_is_reset(pUse) );
@@ -931,11 +945,50 @@
945 struct dirent *pEntry;
946 Blob aContent; /* content of the just read artifact */
947 static int nFileRead = 0;
948 void *zUnicodePath;
949 char *zUtf8Name;
950 static int recursionLevel = 0; /* Bookkeeping about the recursion level */
951 static char *zFnRid1 = 0; /* The file holding the artifact with RID=1 */
952 static int cchPathInitial = 0; /* The length of zPath on first recursion */
953
954 recursionLevel++;
955 if( recursionLevel==1 ){
956 cchPathInitial = strlen(zPath);
957 if( fKeepRid1!=0 ){
958 char *zFnDotRid1 = mprintf("%s/.rid1", zPath);
959 Blob bFileContents;
960 if( blob_read_from_file(&bFileContents, zFnDotRid1, ExtFILE)!=-1 ){
961 Blob line, value;
962 while( blob_line(&bFileContents, &line)>0 ){
963 if( blob_token(&line, &value)==0 ) continue; /* Empty line */
964 if( blob_buffer(&value)[0]=='#' ) continue; /* Comment */
965 blob_trim(&value);
966 zFnRid1 = mprintf("%s/%s", zPath, blob_str(&value));
967 break;
968 }
969 blob_reset(&bFileContents);
970 if( zFnRid1 ){
971 if( blob_read_from_file(&aContent, zFnRid1, ExtFILE)==-1 ){
972 fossil_fatal("some unknown error occurred while reading \"%s\"",
973 zFnRid1);
974 }else{
975 recon_set_hash_policy(0, zFnRid1);
976 content_put(&aContent);
977 recon_restore_hash_policy();
978 blob_reset(&aContent);
979 fossil_print("\r%d", ++nFileRead);
980 fflush(stdout);
981 }
982 }else{
983 fossil_fatal("an error occurred while reading or parsing \"%s\"",
984 zFnDotRid1);
985 }
986 }
987 free(zFnDotRid1);
988 }
989 }
990 zUnicodePath = fossil_utf8_to_path(zPath, 1);
991 d = opendir(zUnicodePath);
992 if( d ){
993 while( (pEntry=readdir(d))!=0 ){
994 Blob path;
@@ -953,18 +1006,20 @@
1006 #else
1007 if( file_isdir(zSubpath, ExtFILE)==1 )
1008 #endif
1009 {
1010 recon_read_dir(zSubpath);
1011 }else if( fossil_strcmp(zSubpath, zFnRid1)!=0 ){
1012 blob_init(&path, 0, 0);
1013 blob_appendf(&path, "%s", zSubpath);
1014 if( blob_read_from_file(&aContent, blob_str(&path), ExtFILE)==-1 ){
1015 fossil_fatal("some unknown error occurred while reading \"%s\"",
1016 blob_str(&path));
1017 }
1018 recon_set_hash_policy(cchPathInitial, blob_str(&path));
1019 content_put(&aContent);
1020 recon_restore_hash_policy();
1021 blob_reset(&path);
1022 blob_reset(&aContent);
1023 fossil_print("\r%d", ++nFileRead);
1024 fflush(stdout);
1025 }
@@ -974,26 +1029,134 @@
1029 }else {
1030 fossil_fatal("encountered error %d while trying to open \"%s\".",
1031 errno, g.argv[3]);
1032 }
1033 fossil_path_free(zUnicodePath);
1034 if( recursionLevel==1 && zFnRid1!=0 ) free(zFnRid1);
1035 recursionLevel--;
1036 }
1037
1038 /*
1039 ** Helper functions called from recon_read_dir() to set and restore the correct
1040 ** hash policy for an artifact read from disk, inferred from the length of the
1041 ** path name.
1042 */
1043 static int saved_eHashPolicy = -1;
1044
1045 void recon_set_hash_policy(
1046 const int cchPathPrefix, /* Directory prefix length for zUuidAsFilePath */
1047 const char *zUuidAsFilePath /* Relative, well-formed, from recon_read_dir() */
1048 ){
1049 int cchUuidAsFilePath;
1050 const char *zHashPart;
1051 int cchHashPart = 0;
1052 int new_eHashPolicy = -1;
1053 assert( HNAME_COUNT==2 ); /* Review function if new hashes are implemented. */
1054 if( zUuidAsFilePath==0 ) return;
1055 cchUuidAsFilePath = strlen(zUuidAsFilePath);
1056 if( cchUuidAsFilePath==0 ) return;
1057 if( cchPathPrefix>=cchUuidAsFilePath ) return;
1058 for( zHashPart = zUuidAsFilePath + cchPathPrefix; *zHashPart; zHashPart++ ){
1059 if( *zHashPart!='/' ) cchHashPart++;
1060 }
1061 if( cchHashPart>=HNAME_LEN_K256 ){
1062 new_eHashPolicy = HPOLICY_SHA3;
1063 }else if( cchHashPart>=HNAME_LEN_SHA1 ){
1064 new_eHashPolicy = HPOLICY_SHA1;
1065 }
1066 if( new_eHashPolicy!=-1 ){
1067 saved_eHashPolicy = g.eHashPolicy;
1068 g.eHashPolicy = new_eHashPolicy;
1069 }
1070 }
1071
1072 void recon_restore_hash_policy(){
1073 if( saved_eHashPolicy!=-1 ){
1074 g.eHashPolicy = saved_eHashPolicy;
1075 saved_eHashPolicy = -1;
1076 }
1077 }
1078
1079 #if 0
1080 /*
1081 ** COMMAND: test-hash-from-path*
1082 **
1083 ** Usage: %fossil test-hash-from-path ?OPTIONS? DESTINATION UUID
1084 **
1085 ** Generate a sample path name from DESTINATION and UUID, as the `deconstruct'
1086 ** command would do. Then try to guess the hash policy from the path name, as
1087 ** the `reconstruct' command would do.
1088 **
1089 ** No files or directories will be created.
1090 **
1091 ** Options:
1092 ** -L|--prefixlength N Set the length of the names of the DESTINATION
1093 ** subdirectories to N.
1094 */
1095 void test_hash_from_path_cmd(void) {
1096 char *zDest;
1097 char *zUuid;
1098 char *zFile;
1099 const char *zHashPolicy = "unknown";
1100 const char *zPrefixOpt = find_option("prefixlength","L",1);
1101 int iPrefixLength;
1102 if( !zPrefixOpt ){
1103 iPrefixLength = 2;
1104 }else{
1105 iPrefixLength = atoi(zPrefixOpt);
1106 if( iPrefixLength<0 || iPrefixLength>9 ){
1107 fossil_fatal("N(%s) is not a valid prefix length!",zPrefixOpt);
1108 }
1109 }
1110 if( g.argc!=4 ){
1111 usage ("?OPTIONS? DESTINATION UUID");
1112 }
1113 zDest = g.argv[2];
1114 zUuid = g.argv[3];
1115 if( iPrefixLength ){
1116 zFNameFormat = mprintf("%s/%%.%ds/%%s",zDest,iPrefixLength);
1117 }else{
1118 zFNameFormat = mprintf("%s/%%s",zDest);
1119 }
1120 cchFNamePrefix = strlen(zDest);
1121 zFile = mprintf(zFNameFormat /*works-like:"%s:%s"*/,
1122 zUuid, zUuid+iPrefixLength);
1123 recon_set_hash_policy(cchFNamePrefix,zFile);
1124 if( saved_eHashPolicy!=-1 ){
1125 zHashPolicy = hpolicy_name();
1126 }
1127 recon_restore_hash_policy();
1128 fossil_print(
1129 "\nPath Name: %s"
1130 "\nHash Policy: %s\n",
1131 zFile,zHashPolicy);
1132 free(zFile);
1133 free(zFNameFormat);
1134 zFNameFormat = 0;
1135 cchFNamePrefix = 0;
1136 }
1137 #endif
1138
1139 /*
1140 ** COMMAND: reconstruct*
1141 **
1142 ** Usage: %fossil reconstruct ?OPTIONS? FILENAME DIRECTORY
1143 **
1144 ** This command studies the artifacts (files) in DIRECTORY and
1145 ** reconstructs the fossil record from them. It places the new
1146 ** fossil repository in FILENAME. Subdirectories are read, files
1147 ** with leading '.' in the filename are ignored.
1148 **
1149 ** Options:
1150 ** -K|--keep-rid1 Read the filename of the artifact with
1151 ** RID=1 from the file .rid in DIRECTORY.
1152 **
1153 ** See also: deconstruct, rebuild
1154 */
1155 void reconstruct_cmd(void) {
1156 char *zPassword;
1157 fKeepRid1 = find_option("keep-rid1","K",0)!=0;
1158 if( g.argc!=4 ){
1159 usage("FILENAME DIRECTORY");
1160 }
1161 if( file_isdir(g.argv[3], ExtFILE)!=1 ){
1162 fossil_print("\"%s\" is not a directory\n\n", g.argv[3]);
@@ -1041,23 +1204,25 @@
1204 ** AABBBBBBBBB.. is the 40+ character artifact ID, AA the first 2 characters.
1205 ** If -L|--prefixlength is given, the length (default 2) of the directory
1206 ** prefix can be set to 0,1,..,9 characters.
1207 **
1208 ** Options:
1209 ** -R|--repository REPOSITORY Deconstruct given REPOSITORY.
1210 ** -K|--keep-rid1 Save the filename of the artifact with RID=1 to
1211 ** the file .rid1 in the DESTINATION directory.
1212 ** -L|--prefixlength N Set the length of the names of the DESTINATION
1213 ** subdirectories to N.
1214 ** --private Include private artifacts.
1215 **
1216 ** See also: rebuild, reconstruct
1217 */
1218 void deconstruct_cmd(void){
 
1219 const char *zPrefixOpt;
1220 Stmt s;
1221 int privateFlag;
1222
1223 fKeepRid1 = find_option("keep-rid1","K",0)!=0;
1224 /* get and check prefix length argument and build format string */
1225 zPrefixOpt=find_option("prefixlength","L",1);
1226 if( !zPrefixOpt ){
1227 prefixLength = 2;
1228 }else{
@@ -1092,10 +1257,11 @@
1257 if( prefixLength ){
1258 zFNameFormat = mprintf("%s/%%.%ds/%%s",zDestDir,prefixLength);
1259 }else{
1260 zFNameFormat = mprintf("%s/%%s",zDestDir);
1261 }
1262 cchFNamePrefix = strlen(zDestDir);
1263
1264 bag_init(&bagDone);
1265 ttyOutput = 1;
1266 processCnt = 0;
1267 if (!g.fQuiet) {
1268
+87 -1
--- src/shell.c
+++ src/shell.c
@@ -4167,11 +4167,12 @@
41674167
memtraceFree,
41684168
memtraceRealloc,
41694169
memtraceSize,
41704170
memtraceRoundup,
41714171
memtraceInit,
4172
- memtraceShutdown
4172
+ memtraceShutdown,
4173
+ 0
41734174
};
41744175
41754176
/* Begin tracing memory allocations to out. */
41764177
int sqlite3MemTraceActivate(FILE *out){
41774178
int rc = SQLITE_OK;
@@ -8708,10 +8709,13 @@
87088709
int cMode; /* temporary output mode for the current query */
87098710
int normalMode; /* Output mode before ".explain on" */
87108711
int writableSchema; /* True if PRAGMA writable_schema=ON */
87118712
int showHeader; /* True to show column names in List or Column mode */
87128713
int nCheck; /* Number of ".check" commands run */
8714
+ unsigned nProgress; /* Number of progress callbacks encountered */
8715
+ unsigned mxProgress; /* Maximum progress callbacks before failing */
8716
+ unsigned flgProgress; /* Flags for the progress callback */
87138717
unsigned shellFlgs; /* Various flags */
87148718
sqlite3_int64 szMax; /* --maxsize argument to .open */
87158719
char *zDestTable; /* Name of destination table when MODE_Insert */
87168720
char *zTempFile; /* Temporary file that might need deleting */
87178721
char zTestcase[30]; /* Name of current test case */
@@ -8762,10 +8766,17 @@
87628766
*/
87638767
#define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
87648768
#define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
87658769
#define SHELL_TRACE_NORMALIZED 2 /* Show normalized SQL text */
87668770
8771
+/* Bits in the ShellState.flgProgress variable */
8772
+#define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
8773
+#define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progres
8774
+ ** callback limit is reached, and for each
8775
+ ** top-level SQL statement */
8776
+#define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
8777
+
87678778
/*
87688779
** These are the allowed shellFlgs values
87698780
*/
87708781
#define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
87718782
#define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -9462,10 +9473,30 @@
94629473
eqp_render_level(p, 0);
94639474
eqp_reset(p);
94649475
}
94659476
}
94669477
9478
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
9479
+/*
9480
+** Progress handler callback.
9481
+*/
9482
+static int progress_handler(void *pClientData) {
9483
+ ShellState *p = (ShellState*)pClientData;
9484
+ p->nProgress++;
9485
+ if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
9486
+ raw_printf(p->out, "Progress limit reached (%u)\n", p->nProgress);
9487
+ if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
9488
+ if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
9489
+ return 1;
9490
+ }
9491
+ if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){
9492
+ raw_printf(p->out, "Progress %u\n", p->nProgress);
9493
+ }
9494
+ return 0;
9495
+}
9496
+#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
9497
+
94679498
/*
94689499
** This is the callback routine that the shell
94699500
** invokes for each row of a query result.
94709501
*/
94719502
static int shell_callback(
@@ -11148,10 +11179,17 @@
1114811179
" --readonly Open FILE readonly",
1114911180
" --zip FILE is a ZIP archive",
1115011181
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1115111182
" If FILE begins with '|' then open it as a pipe.",
1115211183
".print STRING... Print literal STRING",
11184
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11185
+ ".progress N Invoke progress handler after every N opcodes",
11186
+ " --limit N Interrupt after N progress callbacks",
11187
+ " --once Do no more than one progress interrupt",
11188
+ " --quiet|-q No output except at interrupts",
11189
+ " --reset Reset the count for each input and interrupt",
11190
+#endif
1115311191
".prompt MAIN CONTINUE Replace the standard prompts",
1115411192
".quit Exit this program",
1115511193
".read FILE Read input from FILE",
1115611194
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1115711195
".save FILE Write in-memory database into FILE",
@@ -14680,10 +14718,56 @@
1468014718
utf8_printf(p->out, "%s", azArg[i]);
1468114719
}
1468214720
raw_printf(p->out, "\n");
1468314721
}else
1468414722
14723
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
14724
+ if( c=='p' && n>=3 && strncmp(azArg[0], "progress", n)==0 ){
14725
+ int i;
14726
+ int nn = 0;
14727
+ p->flgProgress = 0;
14728
+ p->mxProgress = 0;
14729
+ p->nProgress = 0;
14730
+ for(i=1; i<nArg; i++){
14731
+ const char *z = azArg[i];
14732
+ if( z[0]=='-' ){
14733
+ z++;
14734
+ if( z[0]=='-' ) z++;
14735
+ if( strcmp(z,"quiet")==0 || strcmp(z,"q")==0 ){
14736
+ p->flgProgress |= SHELL_PROGRESS_QUIET;
14737
+ continue;
14738
+ }
14739
+ if( strcmp(z,"reset")==0 ){
14740
+ p->flgProgress |= SHELL_PROGRESS_RESET;
14741
+ continue;
14742
+ }
14743
+ if( strcmp(z,"once")==0 ){
14744
+ p->flgProgress |= SHELL_PROGRESS_ONCE;
14745
+ continue;
14746
+ }
14747
+ if( strcmp(z,"limit")==0 ){
14748
+ if( i+1>=nArg ){
14749
+ utf8_printf(stderr, "Error: missing argument on --limit\n");
14750
+ rc = 1;
14751
+ goto meta_command_exit;
14752
+ }else{
14753
+ p->mxProgress = (int)integerValue(azArg[++i]);
14754
+ }
14755
+ continue;
14756
+ }
14757
+ utf8_printf(stderr, "Error: unknown option: \"%s\"\n", azArg[i]);
14758
+ rc = 1;
14759
+ goto meta_command_exit;
14760
+ }else{
14761
+ nn = (int)integerValue(z);
14762
+ }
14763
+ }
14764
+ open_db(p, 0);
14765
+ sqlite3_progress_handler(p->db, nn, progress_handler, p);
14766
+ }else
14767
+#endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
14768
+
1468514769
if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
1468614770
if( nArg >= 2) {
1468714771
strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
1468814772
}
1468914773
if( nArg >= 3) {
@@ -16015,10 +16099,11 @@
1601516099
int rc;
1601616100
char *zErrMsg = 0;
1601716101
1601816102
open_db(p, 0);
1601916103
if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
16104
+ if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
1602016105
BEGIN_TIMER;
1602116106
rc = shell_exec(p, zSql, &zErrMsg);
1602216107
END_TIMER;
1602316108
if( rc || zErrMsg ){
1602416109
char zPrefix[100];
@@ -16277,10 +16362,11 @@
1627716362
" -list set output mode to 'list'\n"
1627816363
" -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
1627916364
#if defined(SQLITE_ENABLE_DESERIALIZE)
1628016365
" -maxsize N maximum size for a --deserialize database\n"
1628116366
#endif
16367
+ " -memtrace trace all memory allocations and deallocations\n"
1628216368
" -mmap N default mmap size set to N\n"
1628316369
#ifdef SQLITE_ENABLE_MULTIPLEX
1628416370
" -multiplex enable the multiplexor VFS\n"
1628516371
#endif
1628616372
" -newline SEP set output row separator. Default: '\\n'\n"
1628716373
--- src/shell.c
+++ src/shell.c
@@ -4167,11 +4167,12 @@
4167 memtraceFree,
4168 memtraceRealloc,
4169 memtraceSize,
4170 memtraceRoundup,
4171 memtraceInit,
4172 memtraceShutdown
 
4173 };
4174
4175 /* Begin tracing memory allocations to out. */
4176 int sqlite3MemTraceActivate(FILE *out){
4177 int rc = SQLITE_OK;
@@ -8708,10 +8709,13 @@
8708 int cMode; /* temporary output mode for the current query */
8709 int normalMode; /* Output mode before ".explain on" */
8710 int writableSchema; /* True if PRAGMA writable_schema=ON */
8711 int showHeader; /* True to show column names in List or Column mode */
8712 int nCheck; /* Number of ".check" commands run */
 
 
 
8713 unsigned shellFlgs; /* Various flags */
8714 sqlite3_int64 szMax; /* --maxsize argument to .open */
8715 char *zDestTable; /* Name of destination table when MODE_Insert */
8716 char *zTempFile; /* Temporary file that might need deleting */
8717 char zTestcase[30]; /* Name of current test case */
@@ -8762,10 +8766,17 @@
8762 */
8763 #define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
8764 #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
8765 #define SHELL_TRACE_NORMALIZED 2 /* Show normalized SQL text */
8766
 
 
 
 
 
 
 
8767 /*
8768 ** These are the allowed shellFlgs values
8769 */
8770 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
8771 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -9462,10 +9473,30 @@
9462 eqp_render_level(p, 0);
9463 eqp_reset(p);
9464 }
9465 }
9466
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9467 /*
9468 ** This is the callback routine that the shell
9469 ** invokes for each row of a query result.
9470 */
9471 static int shell_callback(
@@ -11148,10 +11179,17 @@
11148 " --readonly Open FILE readonly",
11149 " --zip FILE is a ZIP archive",
11150 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11151 " If FILE begins with '|' then open it as a pipe.",
11152 ".print STRING... Print literal STRING",
 
 
 
 
 
 
 
11153 ".prompt MAIN CONTINUE Replace the standard prompts",
11154 ".quit Exit this program",
11155 ".read FILE Read input from FILE",
11156 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
11157 ".save FILE Write in-memory database into FILE",
@@ -14680,10 +14718,56 @@
14680 utf8_printf(p->out, "%s", azArg[i]);
14681 }
14682 raw_printf(p->out, "\n");
14683 }else
14684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14685 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
14686 if( nArg >= 2) {
14687 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
14688 }
14689 if( nArg >= 3) {
@@ -16015,10 +16099,11 @@
16015 int rc;
16016 char *zErrMsg = 0;
16017
16018 open_db(p, 0);
16019 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
 
16020 BEGIN_TIMER;
16021 rc = shell_exec(p, zSql, &zErrMsg);
16022 END_TIMER;
16023 if( rc || zErrMsg ){
16024 char zPrefix[100];
@@ -16277,10 +16362,11 @@
16277 " -list set output mode to 'list'\n"
16278 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
16279 #if defined(SQLITE_ENABLE_DESERIALIZE)
16280 " -maxsize N maximum size for a --deserialize database\n"
16281 #endif
 
16282 " -mmap N default mmap size set to N\n"
16283 #ifdef SQLITE_ENABLE_MULTIPLEX
16284 " -multiplex enable the multiplexor VFS\n"
16285 #endif
16286 " -newline SEP set output row separator. Default: '\\n'\n"
16287
--- src/shell.c
+++ src/shell.c
@@ -4167,11 +4167,12 @@
4167 memtraceFree,
4168 memtraceRealloc,
4169 memtraceSize,
4170 memtraceRoundup,
4171 memtraceInit,
4172 memtraceShutdown,
4173 0
4174 };
4175
4176 /* Begin tracing memory allocations to out. */
4177 int sqlite3MemTraceActivate(FILE *out){
4178 int rc = SQLITE_OK;
@@ -8708,10 +8709,13 @@
8709 int cMode; /* temporary output mode for the current query */
8710 int normalMode; /* Output mode before ".explain on" */
8711 int writableSchema; /* True if PRAGMA writable_schema=ON */
8712 int showHeader; /* True to show column names in List or Column mode */
8713 int nCheck; /* Number of ".check" commands run */
8714 unsigned nProgress; /* Number of progress callbacks encountered */
8715 unsigned mxProgress; /* Maximum progress callbacks before failing */
8716 unsigned flgProgress; /* Flags for the progress callback */
8717 unsigned shellFlgs; /* Various flags */
8718 sqlite3_int64 szMax; /* --maxsize argument to .open */
8719 char *zDestTable; /* Name of destination table when MODE_Insert */
8720 char *zTempFile; /* Temporary file that might need deleting */
8721 char zTestcase[30]; /* Name of current test case */
@@ -8762,10 +8766,17 @@
8766 */
8767 #define SHELL_TRACE_PLAIN 0 /* Show input SQL text */
8768 #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */
8769 #define SHELL_TRACE_NORMALIZED 2 /* Show normalized SQL text */
8770
8771 /* Bits in the ShellState.flgProgress variable */
8772 #define SHELL_PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */
8773 #define SHELL_PROGRESS_RESET 0x02 /* Reset the count when the progres
8774 ** callback limit is reached, and for each
8775 ** top-level SQL statement */
8776 #define SHELL_PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */
8777
8778 /*
8779 ** These are the allowed shellFlgs values
8780 */
8781 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
8782 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
@@ -9462,10 +9473,30 @@
9473 eqp_render_level(p, 0);
9474 eqp_reset(p);
9475 }
9476 }
9477
9478 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
9479 /*
9480 ** Progress handler callback.
9481 */
9482 static int progress_handler(void *pClientData) {
9483 ShellState *p = (ShellState*)pClientData;
9484 p->nProgress++;
9485 if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){
9486 raw_printf(p->out, "Progress limit reached (%u)\n", p->nProgress);
9487 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
9488 if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0;
9489 return 1;
9490 }
9491 if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){
9492 raw_printf(p->out, "Progress %u\n", p->nProgress);
9493 }
9494 return 0;
9495 }
9496 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
9497
9498 /*
9499 ** This is the callback routine that the shell
9500 ** invokes for each row of a query result.
9501 */
9502 static int shell_callback(
@@ -11148,10 +11179,17 @@
11179 " --readonly Open FILE readonly",
11180 " --zip FILE is a ZIP archive",
11181 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11182 " If FILE begins with '|' then open it as a pipe.",
11183 ".print STRING... Print literal STRING",
11184 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11185 ".progress N Invoke progress handler after every N opcodes",
11186 " --limit N Interrupt after N progress callbacks",
11187 " --once Do no more than one progress interrupt",
11188 " --quiet|-q No output except at interrupts",
11189 " --reset Reset the count for each input and interrupt",
11190 #endif
11191 ".prompt MAIN CONTINUE Replace the standard prompts",
11192 ".quit Exit this program",
11193 ".read FILE Read input from FILE",
11194 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
11195 ".save FILE Write in-memory database into FILE",
@@ -14680,10 +14718,56 @@
14718 utf8_printf(p->out, "%s", azArg[i]);
14719 }
14720 raw_printf(p->out, "\n");
14721 }else
14722
14723 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
14724 if( c=='p' && n>=3 && strncmp(azArg[0], "progress", n)==0 ){
14725 int i;
14726 int nn = 0;
14727 p->flgProgress = 0;
14728 p->mxProgress = 0;
14729 p->nProgress = 0;
14730 for(i=1; i<nArg; i++){
14731 const char *z = azArg[i];
14732 if( z[0]=='-' ){
14733 z++;
14734 if( z[0]=='-' ) z++;
14735 if( strcmp(z,"quiet")==0 || strcmp(z,"q")==0 ){
14736 p->flgProgress |= SHELL_PROGRESS_QUIET;
14737 continue;
14738 }
14739 if( strcmp(z,"reset")==0 ){
14740 p->flgProgress |= SHELL_PROGRESS_RESET;
14741 continue;
14742 }
14743 if( strcmp(z,"once")==0 ){
14744 p->flgProgress |= SHELL_PROGRESS_ONCE;
14745 continue;
14746 }
14747 if( strcmp(z,"limit")==0 ){
14748 if( i+1>=nArg ){
14749 utf8_printf(stderr, "Error: missing argument on --limit\n");
14750 rc = 1;
14751 goto meta_command_exit;
14752 }else{
14753 p->mxProgress = (int)integerValue(azArg[++i]);
14754 }
14755 continue;
14756 }
14757 utf8_printf(stderr, "Error: unknown option: \"%s\"\n", azArg[i]);
14758 rc = 1;
14759 goto meta_command_exit;
14760 }else{
14761 nn = (int)integerValue(z);
14762 }
14763 }
14764 open_db(p, 0);
14765 sqlite3_progress_handler(p->db, nn, progress_handler, p);
14766 }else
14767 #endif /* SQLITE_OMIT_PROGRESS_CALLBACK */
14768
14769 if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){
14770 if( nArg >= 2) {
14771 strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1);
14772 }
14773 if( nArg >= 3) {
@@ -16015,10 +16099,11 @@
16099 int rc;
16100 char *zErrMsg = 0;
16101
16102 open_db(p, 0);
16103 if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql);
16104 if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0;
16105 BEGIN_TIMER;
16106 rc = shell_exec(p, zSql, &zErrMsg);
16107 END_TIMER;
16108 if( rc || zErrMsg ){
16109 char zPrefix[100];
@@ -16277,10 +16362,11 @@
16362 " -list set output mode to 'list'\n"
16363 " -lookaside SIZE N use N entries of SZ bytes for lookaside memory\n"
16364 #if defined(SQLITE_ENABLE_DESERIALIZE)
16365 " -maxsize N maximum size for a --deserialize database\n"
16366 #endif
16367 " -memtrace trace all memory allocations and deallocations\n"
16368 " -mmap N default mmap size set to N\n"
16369 #ifdef SQLITE_ENABLE_MULTIPLEX
16370 " -multiplex enable the multiplexor VFS\n"
16371 #endif
16372 " -newline SEP set output row separator. Default: '\\n'\n"
16373
+411 -238
--- 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.27.0. By combining all the individual C code files into this
3
+** version 3.27.1. 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.
@@ -1160,13 +1160,13 @@
11601160
**
11611161
** See also: [sqlite3_libversion()],
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
1165
-#define SQLITE_VERSION "3.27.0"
1166
-#define SQLITE_VERSION_NUMBER 3027000
1167
-#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
1165
+#define SQLITE_VERSION "3.27.1"
1166
+#define SQLITE_VERSION_NUMBER 3027001
1167
+#define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -3019,10 +3019,21 @@
30193019
** from the database as records are returned in sorted order. The default
30203020
** value for this option is to never use this optimization. Specifying a
30213021
** negative value for this option restores the default behaviour.
30223022
** This option is only available if SQLite is compiled with the
30233023
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
3024
+**
3025
+** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
3026
+** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
3027
+** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
3028
+** [sqlite3_int64] parameter which is the default maximum size for an in-memory
3029
+** database created using [sqlite3_deserialize()]. This default maximum
3030
+** size can be adjusted up or down for individual databases using the
3031
+** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
3032
+** configuration setting is never used, then the default maximum is determined
3033
+** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
3034
+** compile-time option is not set, then the default maximum is 1073741824.
30243035
** </dl>
30253036
*/
30263037
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
30273038
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
30283039
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -3049,10 +3060,11 @@
30493060
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
30503061
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
30513062
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
30523063
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
30533064
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
3065
+#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
30543066
30553067
/*
30563068
** CAPI3REF: Database Connection Configuration Options
30573069
**
30583070
** These constants are the available integer configuration options that
@@ -4454,10 +4466,12 @@
44544466
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
44554467
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
44564468
** is not a database file pathname pointer that SQLite passed into the xOpen
44574469
** VFS method, then the behavior of this routine is undefined and probably
44584470
** undesirable.
4471
+**
4472
+** See the [URI filename] documentation for additional information.
44594473
*/
44604474
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
44614475
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
44624476
SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
44634477
@@ -14544,10 +14558,11 @@
1454414558
SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
1454514559
#endif
1454614560
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
1454714561
SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
1454814562
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
14563
+SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
1454914564
1455014565
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
1455114566
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
1455214567
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
1455314568
@@ -16433,10 +16448,11 @@
1643316448
#define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */
1643416449
#define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */
1643516450
#define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */
1643616451
#define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */
1643716452
#define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */
16453
+#define SQLITE_ParserTrace HI(0x0020) /* PRAGMA parser_trace=ON */
1643816454
#endif
1643916455
1644016456
/*
1644116457
** Allowed values for sqlite3.mDbFlags
1644216458
*/
@@ -18305,10 +18321,13 @@
1830518321
** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
1830618322
*/
1830718323
void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
1830818324
void *pVdbeBranchArg; /* 1st argument */
1830918325
#endif
18326
+#ifdef SQLITE_ENABLE_DESERIALIZE
18327
+ sqlite3_int64 mxMemdbSize; /* Default max memdb size */
18328
+#endif
1831018329
#ifndef SQLITE_UNTESTABLE
1831118330
int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
1831218331
#endif
1831318332
int bLocaltimeFault; /* True to fail localtime() calls */
1831418333
int bInternalFunctions; /* Internal SQL functions are visible */
@@ -18722,10 +18741,11 @@
1872218741
SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
1872318742
SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
1872418743
SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
1872518744
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1872618745
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
18746
+SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
1872718747
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1872818748
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1872918749
SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
1873018750
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
1873118751
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -18755,10 +18775,15 @@
1875518775
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
1875618776
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
1875718777
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
1875818778
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1875918779
sqlite3_vfs**,char**,char **);
18780
+#ifdef SQLITE_HAS_CODEC
18781
+SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
18782
+#else
18783
+# define sqlite3CodecQueryParameters(A,B,C) 0
18784
+#endif
1876018785
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
1876118786
1876218787
#ifdef SQLITE_UNTESTABLE
1876318788
# define sqlite3FaultSim(X) SQLITE_OK
1876418789
#else
@@ -19716,10 +19741,17 @@
1971619741
#ifndef SQLITE_DEFAULT_LOOKASIDE
1971719742
# define SQLITE_DEFAULT_LOOKASIDE 1200,100
1971819743
#endif
1971919744
1972019745
19746
+/* The default maximum size of an in-memory database created using
19747
+** sqlite3_deserialize()
19748
+*/
19749
+#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
19750
+# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
19751
+#endif
19752
+
1972119753
/*
1972219754
** The following singleton contains the global configuration for
1972319755
** the SQLite library.
1972419756
*/
1972519757
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -19763,17 +19795,20 @@
1976319795
#endif
1976419796
#ifdef SQLITE_VDBE_COVERAGE
1976519797
0, /* xVdbeBranch */
1976619798
0, /* pVbeBranchArg */
1976719799
#endif
19800
+#ifdef SQLITE_ENABLE_DESERIALIZE
19801
+ SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
19802
+#endif
1976819803
#ifndef SQLITE_UNTESTABLE
1976919804
0, /* xTestCallback */
1977019805
#endif
1977119806
0, /* bLocaltimeFault */
1977219807
0, /* bInternalFunctions */
1977319808
0x7ffffffe, /* iOnceResetThreshold */
19774
- SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */
19809
+ SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
1977519810
};
1977619811
1977719812
/*
1977819813
** Hash table for global functions - functions common to all
1977919814
** database connections. After initialization, this table is
@@ -27296,10 +27331,31 @@
2729627331
static char *getTextArg(PrintfArguments *p){
2729727332
if( p->nArg<=p->nUsed ) return 0;
2729827333
return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
2729927334
}
2730027335
27336
+/*
27337
+** Allocate memory for a temporary buffer needed for printf rendering.
27338
+**
27339
+** If the requested size of the temp buffer is larger than the size
27340
+** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
27341
+** Do the size check before the memory allocation to prevent rogue
27342
+** SQL from requesting large allocations using the precision or width
27343
+** field of the printf() function.
27344
+*/
27345
+static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
27346
+ char *z;
27347
+ if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
27348
+ setStrAccumError(pAccum, SQLITE_TOOBIG);
27349
+ return 0;
27350
+ }
27351
+ z = sqlite3DbMallocRaw(pAccum->db, n);
27352
+ if( z==0 ){
27353
+ setStrAccumError(pAccum, SQLITE_NOMEM);
27354
+ }
27355
+ return z;
27356
+}
2730127357
2730227358
/*
2730327359
** On machines with a small stack size, you can redefine the
2730427360
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
2730527361
*/
@@ -27378,10 +27434,13 @@
2737827434
}
2737927435
/* Find out what flags are present */
2738027436
flag_leftjustify = flag_prefix = cThousand =
2738127437
flag_alternateform = flag_altform2 = flag_zeropad = 0;
2738227438
done = 0;
27439
+ width = 0;
27440
+ flag_long = 0;
27441
+ precision = -1;
2738327442
do{
2738427443
switch( c ){
2738527444
case '-': flag_leftjustify = 1; break;
2738627445
case '+': flag_prefix = '+'; break;
2738727446
case ' ': flag_prefix = ' '; break;
@@ -27388,84 +27447,97 @@
2738827447
case '#': flag_alternateform = 1; break;
2738927448
case '!': flag_altform2 = 1; break;
2739027449
case '0': flag_zeropad = 1; break;
2739127450
case ',': cThousand = ','; break;
2739227451
default: done = 1; break;
27452
+ case 'l': {
27453
+ flag_long = 1;
27454
+ c = *++fmt;
27455
+ if( c=='l' ){
27456
+ c = *++fmt;
27457
+ flag_long = 2;
27458
+ }
27459
+ done = 1;
27460
+ break;
27461
+ }
27462
+ case '1': case '2': case '3': case '4': case '5':
27463
+ case '6': case '7': case '8': case '9': {
27464
+ unsigned wx = c - '0';
27465
+ while( (c = *++fmt)>='0' && c<='9' ){
27466
+ wx = wx*10 + c - '0';
27467
+ }
27468
+ testcase( wx>0x7fffffff );
27469
+ width = wx & 0x7fffffff;
27470
+#ifdef SQLITE_PRINTF_PRECISION_LIMIT
27471
+ if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27472
+ width = SQLITE_PRINTF_PRECISION_LIMIT;
27473
+ }
27474
+#endif
27475
+ if( c!='.' && c!='l' ){
27476
+ done = 1;
27477
+ }else{
27478
+ fmt--;
27479
+ }
27480
+ break;
27481
+ }
27482
+ case '*': {
27483
+ if( bArgList ){
27484
+ width = (int)getIntArg(pArgList);
27485
+ }else{
27486
+ width = va_arg(ap,int);
27487
+ }
27488
+ if( width<0 ){
27489
+ flag_leftjustify = 1;
27490
+ width = width >= -2147483647 ? -width : 0;
27491
+ }
27492
+#ifdef SQLITE_PRINTF_PRECISION_LIMIT
27493
+ if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27494
+ width = SQLITE_PRINTF_PRECISION_LIMIT;
27495
+ }
27496
+#endif
27497
+ if( (c = fmt[1])!='.' && c!='l' ){
27498
+ c = *++fmt;
27499
+ done = 1;
27500
+ }
27501
+ break;
27502
+ }
27503
+ case '.': {
27504
+ c = *++fmt;
27505
+ if( c=='*' ){
27506
+ if( bArgList ){
27507
+ precision = (int)getIntArg(pArgList);
27508
+ }else{
27509
+ precision = va_arg(ap,int);
27510
+ }
27511
+ if( precision<0 ){
27512
+ precision = precision >= -2147483647 ? -precision : -1;
27513
+ }
27514
+ c = *++fmt;
27515
+ }else{
27516
+ unsigned px = 0;
27517
+ while( c>='0' && c<='9' ){
27518
+ px = px*10 + c - '0';
27519
+ c = *++fmt;
27520
+ }
27521
+ testcase( px>0x7fffffff );
27522
+ precision = px & 0x7fffffff;
27523
+ }
27524
+#ifdef SQLITE_PRINTF_PRECISION_LIMIT
27525
+ if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){
27526
+ precision = SQLITE_PRINTF_PRECISION_LIMIT;
27527
+ }
27528
+#endif
27529
+ if( c=='l' ){
27530
+ --fmt;
27531
+ }else{
27532
+ done = 1;
27533
+ }
27534
+ break;
27535
+ }
2739327536
}
2739427537
}while( !done && (c=(*++fmt))!=0 );
27395
- /* Get the field width */
27396
- if( c=='*' ){
27397
- if( bArgList ){
27398
- width = (int)getIntArg(pArgList);
27399
- }else{
27400
- width = va_arg(ap,int);
27401
- }
27402
- if( width<0 ){
27403
- flag_leftjustify = 1;
27404
- width = width >= -2147483647 ? -width : 0;
27405
- }
27406
- c = *++fmt;
27407
- }else{
27408
- unsigned wx = 0;
27409
- while( c>='0' && c<='9' ){
27410
- wx = wx*10 + c - '0';
27411
- c = *++fmt;
27412
- }
27413
- testcase( wx>0x7fffffff );
27414
- width = wx & 0x7fffffff;
27415
- }
27416
- assert( width>=0 );
27417
-#ifdef SQLITE_PRINTF_PRECISION_LIMIT
27418
- if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27419
- width = SQLITE_PRINTF_PRECISION_LIMIT;
27420
- }
27421
-#endif
27422
-
27423
- /* Get the precision */
27424
- if( c=='.' ){
27425
- c = *++fmt;
27426
- if( c=='*' ){
27427
- if( bArgList ){
27428
- precision = (int)getIntArg(pArgList);
27429
- }else{
27430
- precision = va_arg(ap,int);
27431
- }
27432
- c = *++fmt;
27433
- if( precision<0 ){
27434
- precision = precision >= -2147483647 ? -precision : -1;
27435
- }
27436
- }else{
27437
- unsigned px = 0;
27438
- while( c>='0' && c<='9' ){
27439
- px = px*10 + c - '0';
27440
- c = *++fmt;
27441
- }
27442
- testcase( px>0x7fffffff );
27443
- precision = px & 0x7fffffff;
27444
- }
27445
- }else{
27446
- precision = -1;
27447
- }
27448
- assert( precision>=(-1) );
27449
-#ifdef SQLITE_PRINTF_PRECISION_LIMIT
27450
- if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){
27451
- precision = SQLITE_PRINTF_PRECISION_LIMIT;
27452
- }
27453
-#endif
27454
-
27455
-
27456
- /* Get the conversion type modifier */
27457
- if( c=='l' ){
27458
- flag_long = 1;
27459
- c = *++fmt;
27460
- if( c=='l' ){
27461
- flag_long = 2;
27462
- c = *++fmt;
27463
- }
27464
- }else{
27465
- flag_long = 0;
27466
- }
27538
+
2746727539
/* Fetch the info entry for the field */
2746827540
infop = &fmtinfo[0];
2746927541
xtype = etINVALID;
2747027542
for(idx=0; idx<ArraySize(fmtinfo); idx++){
2747127543
if( c==fmtinfo[idx].fmttype ){
@@ -27546,16 +27618,15 @@
2754627618
}
2754727619
if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
2754827620
nOut = etBUFSIZE;
2754927621
zOut = buf;
2755027622
}else{
27551
- u64 n = (u64)precision + 10 + precision/3;
27552
- zOut = zExtra = sqlite3Malloc( n );
27553
- if( zOut==0 ){
27554
- setStrAccumError(pAccum, SQLITE_NOMEM);
27555
- return;
27556
- }
27623
+ u64 n;
27624
+ n = (u64)precision + 10;
27625
+ if( cThousand ) n += precision/3;
27626
+ zOut = zExtra = printfTempBuf(pAccum, n);
27627
+ if( zOut==0 ) return;
2755727628
nOut = (int)n;
2755827629
}
2755927630
bufpt = &zOut[nOut-1];
2756027631
if( xtype==etORDINAL ){
2756127632
static const char zOrd[] = "thstndrd";
@@ -27670,16 +27741,16 @@
2767027741
if( xtype==etEXP ){
2767127742
e2 = 0;
2767227743
}else{
2767327744
e2 = exp;
2767427745
}
27675
- if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){
27676
- bufpt = zExtra
27677
- = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
27678
- if( bufpt==0 ){
27679
- setStrAccumError(pAccum, SQLITE_NOMEM);
27680
- return;
27746
+ {
27747
+ i64 szBufNeeded; /* Size of a temporary buffer needed */
27748
+ szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
27749
+ if( szBufNeeded > etBUFSIZE ){
27750
+ bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
27751
+ if( bufpt==0 ) return;
2768127752
}
2768227753
}
2768327754
zOut = bufpt;
2768427755
nsd = 16 + flag_altform2*10;
2768527756
flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2;
@@ -27899,15 +27970,12 @@
2789927970
}
2790027971
}
2790127972
needQuote = !isnull && xtype==etSQLESCAPE2;
2790227973
n += i + 3;
2790327974
if( n>etBUFSIZE ){
27904
- bufpt = zExtra = sqlite3Malloc( n );
27905
- if( bufpt==0 ){
27906
- setStrAccumError(pAccum, SQLITE_NOMEM);
27907
- return;
27908
- }
27975
+ bufpt = zExtra = printfTempBuf(pAccum, n);
27976
+ if( bufpt==0 ) return;
2790927977
}else{
2791027978
bufpt = buf;
2791127979
}
2791227980
j = 0;
2791327981
if( needQuote ) bufpt[j++] = q;
@@ -46578,15 +46646,10 @@
4657846646
int nMmap; /* Number of memory mapped pages */
4657946647
unsigned mFlags; /* Flags */
4658046648
int eLock; /* Most recent lock against this file */
4658146649
};
4658246650
46583
-/* The default maximum size of an in-memory database */
46584
-#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
46585
-# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
46586
-#endif
46587
-
4658846651
/*
4658946652
** Methods for MemFile
4659046653
*/
4659146654
static int memdbClose(sqlite3_file*);
4659246655
static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -46847,11 +46910,10 @@
4684746910
int iAmt,
4684846911
void **pp
4684946912
){
4685046913
MemFile *p = (MemFile *)pFile;
4685146914
if( iOfst+iAmt>p->sz ){
46852
- assert( CORRUPT_DB );
4685346915
*pp = 0;
4685446916
}else{
4685546917
p->nMmap++;
4685646918
*pp = (void*)(p->aData + iOfst);
4685746919
}
@@ -46882,11 +46944,11 @@
4688246944
memset(p, 0, sizeof(*p));
4688346945
p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
4688446946
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
4688546947
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
4688646948
p->base.pMethods = &memdb_io_methods;
46887
- p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
46949
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4688846950
return SQLITE_OK;
4688946951
}
4689046952
4689146953
#if 0 /* Only used to delete rollback journals, master journals, and WAL
4689246954
** files, none of which exist in memdb. So this routine is never used */
@@ -47134,12 +47196,12 @@
4713447196
}else{
4713547197
p->aData = pData;
4713647198
p->sz = szDb;
4713747199
p->szAlloc = szBuf;
4713847200
p->szMax = szBuf;
47139
- if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){
47140
- p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
47201
+ if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
47202
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4714147203
}
4714247204
p->mFlags = mFlags;
4714347205
rc = SQLITE_OK;
4714447206
}
4714547207
@@ -48557,16 +48619,26 @@
4855748619
/*
4855848620
** Each cache entry is represented by an instance of the following
4855948621
** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
4856048622
** PgHdr1.pCache->szPage bytes is allocated directly before this structure
4856148623
** in memory.
48624
+**
48625
+** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
48626
+** but causes a 2-byte gap in the structure for most architectures (since
48627
+** pointers must be either 4 or 8-byte aligned). As this structure is located
48628
+** in memory directly after the associated page data, if the database is
48629
+** corrupt, code at the b-tree layer may overread the page buffer and
48630
+** read part of this structure before the corruption is detected. This
48631
+** can cause a valgrind error if the unitialized gap is accessed. Using u16
48632
+** ensures there is no such gap, and therefore no bytes of unitialized memory
48633
+** in the structure.
4856248634
*/
4856348635
struct PgHdr1 {
4856448636
sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
4856548637
unsigned int iKey; /* Key value (page number) */
48566
- u8 isBulkLocal; /* This page from bulk local storage */
48567
- u8 isAnchor; /* This is the PGroup.lru element */
48638
+ u16 isBulkLocal; /* This page from bulk local storage */
48639
+ u16 isAnchor; /* This is the PGroup.lru element */
4856848640
PgHdr1 *pNext; /* Next in hash table chain */
4856948641
PCache1 *pCache; /* Cache that currently owns this page */
4857048642
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
4857148643
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
4857248644
/* NB: pLruPrev is only valid if pLruNext!=0 */
@@ -48768,10 +48840,11 @@
4876848840
pX->page.pBuf = zBulk;
4876948841
pX->page.pExtra = &pX[1];
4877048842
pX->isBulkLocal = 1;
4877148843
pX->isAnchor = 0;
4877248844
pX->pNext = pCache->pFree;
48845
+ pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
4877348846
pCache->pFree = pX;
4877448847
zBulk += pCache->szAlloc;
4877548848
}while( --nBulk );
4877648849
}
4877748850
return pCache->pFree!=0;
@@ -62473,13 +62546,20 @@
6247362546
**
6247462547
** Fields in this structure are accessed under the BtShared.mutex
6247562548
** found at self->pBt->mutex.
6247662549
**
6247762550
** skipNext meaning:
62478
-** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
62479
-** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
62480
-** eState==FAULT: Cursor fault with skipNext as error code.
62551
+** The meaning of skipNext depends on the value of eState:
62552
+**
62553
+** eState Meaning of skipNext
62554
+** VALID skipNext is meaningless and is ignored
62555
+** INVALID skipNext is meaningless and is ignored
62556
+** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
62557
+** sqlite3BtreePrevious() is no-op if skipNext<0.
62558
+** REQUIRESEEK restoreCursorPosition() restores the cursor to
62559
+** eState=SKIPNEXT if skipNext!=0
62560
+** FAULT skipNext holds the cursor fault error code.
6248162561
*/
6248262562
struct BtCursor {
6248362563
u8 eState; /* One of the CURSOR_XXX constants (see below) */
6248462564
u8 curFlags; /* zero or more BTCF_* flags defined below */
6248562565
u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
@@ -63824,11 +63904,11 @@
6382463904
rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
6382563905
if( rc==SQLITE_OK ){
6382663906
sqlite3_free(pCur->pKey);
6382763907
pCur->pKey = 0;
6382863908
assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
63829
- pCur->skipNext |= skipNext;
63909
+ if( skipNext ) pCur->skipNext = skipNext;
6383063910
if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
6383163911
pCur->eState = CURSOR_SKIPNEXT;
6383263912
}
6383363913
}
6383463914
return rc;
@@ -63894,11 +63974,10 @@
6389463974
return rc;
6389563975
}
6389663976
if( pCur->eState!=CURSOR_VALID ){
6389763977
*pDifferentRow = 1;
6389863978
}else{
63899
- assert( pCur->skipNext==0 );
6390063979
*pDifferentRow = 0;
6390163980
}
6390263981
return SQLITE_OK;
6390363982
}
6390463983
@@ -67498,10 +67577,29 @@
6749867577
assert( cursorHoldsMutex(pCur) );
6749967578
assert( pCur->eState==CURSOR_VALID );
6750067579
getCellInfo(pCur);
6750167580
return pCur->info.nPayload;
6750267581
}
67582
+
67583
+/*
67584
+** Return an upper bound on the size of any record for the table
67585
+** that the cursor is pointing into.
67586
+**
67587
+** This is an optimization. Everything will still work if this
67588
+** routine always returns 2147483647 (which is the largest record
67589
+** that SQLite can handle) or more. But returning a smaller value might
67590
+** prevent large memory allocations when trying to interpret a
67591
+** corrupt datrabase.
67592
+**
67593
+** The current implementation merely returns the size of the underlying
67594
+** database file.
67595
+*/
67596
+SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
67597
+ assert( cursorHoldsMutex(pCur) );
67598
+ assert( pCur->eState==CURSOR_VALID );
67599
+ return pCur->pBt->pageSize * (sqlite3_int64)pCur->pBt->nPage;
67600
+}
6750367601
6750467602
/*
6750567603
** Given the page number of an overflow page in the database (parameter
6750667604
** ovfl), this function finds the page number of the next page in the
6750767605
** linked list of overflow pages. If possible, it uses the auto-vacuum
@@ -68313,11 +68411,11 @@
6831368411
}
6831468412
/* If the requested key is one more than the previous key, then
6831568413
** try to get there using sqlite3BtreeNext() rather than a full
6831668414
** binary search. This is an optimization only. The correct answer
6831768415
** is still obtained without this case, only a little more slowely */
68318
- if( pCur->info.nKey+1==intKey && !pCur->skipNext ){
68416
+ if( pCur->info.nKey+1==intKey ){
6831968417
*pRes = 0;
6832068418
rc = sqlite3BtreeNext(pCur, 0);
6832168419
if( rc==SQLITE_OK ){
6832268420
getCellInfo(pCur);
6832368421
if( pCur->info.nKey==intKey ){
@@ -68587,28 +68685,22 @@
6858768685
int rc;
6858868686
int idx;
6858968687
MemPage *pPage;
6859068688
6859168689
assert( cursorOwnsBtShared(pCur) );
68592
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6859368690
if( pCur->eState!=CURSOR_VALID ){
6859468691
assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
6859568692
rc = restoreCursorPosition(pCur);
6859668693
if( rc!=SQLITE_OK ){
6859768694
return rc;
6859868695
}
6859968696
if( CURSOR_INVALID==pCur->eState ){
6860068697
return SQLITE_DONE;
6860168698
}
68602
- if( pCur->skipNext ){
68603
- assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68699
+ if( pCur->eState==CURSOR_SKIPNEXT ){
6860468700
pCur->eState = CURSOR_VALID;
68605
- if( pCur->skipNext>0 ){
68606
- pCur->skipNext = 0;
68607
- return SQLITE_OK;
68608
- }
68609
- pCur->skipNext = 0;
68701
+ if( pCur->skipNext>0 ) return SQLITE_OK;
6861068702
}
6861168703
}
6861268704
6861368705
pPage = pCur->pPage;
6861468706
idx = ++pCur->ix;
@@ -68659,11 +68751,10 @@
6865968751
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){
6866068752
MemPage *pPage;
6866168753
UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
6866268754
assert( cursorOwnsBtShared(pCur) );
6866368755
assert( flags==0 || flags==1 );
68664
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6866568756
pCur->info.nSize = 0;
6866668757
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6866768758
if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
6866868759
pPage = pCur->pPage;
6866968760
if( (++pCur->ix)>=pPage->nCell ){
@@ -68700,11 +68791,10 @@
6870068791
static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){
6870168792
int rc;
6870268793
MemPage *pPage;
6870368794
6870468795
assert( cursorOwnsBtShared(pCur) );
68705
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6870668796
assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
6870768797
assert( pCur->info.nSize==0 );
6870868798
if( pCur->eState!=CURSOR_VALID ){
6870968799
rc = restoreCursorPosition(pCur);
6871068800
if( rc!=SQLITE_OK ){
@@ -68711,18 +68801,13 @@
6871168801
return rc;
6871268802
}
6871368803
if( CURSOR_INVALID==pCur->eState ){
6871468804
return SQLITE_DONE;
6871568805
}
68716
- if( pCur->skipNext ){
68717
- assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68806
+ if( CURSOR_SKIPNEXT==pCur->eState ){
6871868807
pCur->eState = CURSOR_VALID;
68719
- if( pCur->skipNext<0 ){
68720
- pCur->skipNext = 0;
68721
- return SQLITE_OK;
68722
- }
68723
- pCur->skipNext = 0;
68808
+ if( pCur->skipNext<0 ) return SQLITE_OK;
6872468809
}
6872568810
}
6872668811
6872768812
pPage = pCur->pPage;
6872868813
assert( pPage->isInit );
@@ -68753,11 +68838,10 @@
6875368838
return rc;
6875468839
}
6875568840
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){
6875668841
assert( cursorOwnsBtShared(pCur) );
6875768842
assert( flags==0 || flags==1 );
68758
- assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6875968843
UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
6876068844
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
6876168845
pCur->info.nSize = 0;
6876268846
if( pCur->eState!=CURSOR_VALID
6876368847
|| pCur->ix==0
@@ -69722,27 +69806,38 @@
6972269806
** / | \
6972369807
** --------- --------- ---------
6972469808
** |Child-1| |Child-2| |Child-3|
6972569809
** --------- --------- ---------
6972669810
**
69727
-** The order of cells is in the array is:
69811
+** The order of cells is in the array is for an index btree is:
6972869812
**
6972969813
** 1. All cells from Child-1 in order
6973069814
** 2. The first divider cell from Parent
6973169815
** 3. All cells from Child-2 in order
6973269816
** 4. The second divider cell from Parent
6973369817
** 5. All cells from Child-3 in order
6973469818
**
69735
-** The apEnd[] array holds pointer to the end of page for Child-1, the
69736
-** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array
69737
-** holds the number of cells contained in each of these 5 stages, and
69738
-** all stages to the left. Hence:
69819
+** For a table-btree (with rowids) the items 2 and 4 are empty because
69820
+** content exists only in leaves and there are no divider cells.
69821
+**
69822
+** For an index btree, the apEnd[] array holds pointer to the end of page
69823
+** for Child-1, the Parent, Child-2, the Parent (again), and Child-3,
69824
+** respectively. The ixNx[] array holds the number of cells contained in
69825
+** each of these 5 stages, and all stages to the left. Hence:
69826
+**
6973969827
** ixNx[0] = Number of cells in Child-1.
6974069828
** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
6974169829
** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
6974269830
** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
6974369831
** ixNx[4] = Total number of cells.
69832
+**
69833
+** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
69834
+** are used and they point to the leaf pages only, and the ixNx value are:
69835
+**
69836
+** ixNx[0] = Number of cells in Child-1.
69837
+** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69838
+** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
6974469839
*/
6974569840
typedef struct CellArray CellArray;
6974669841
struct CellArray {
6974769842
int nCell; /* Number of cells in apCell[] */
6974869843
MemPage *pRef; /* Reference page */
@@ -69808,20 +69903,21 @@
6980869903
const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
6980969904
u8 * const aData = pPg->aData; /* Pointer to data for pPg */
6981069905
const int usableSize = pPg->pBt->usableSize;
6981169906
u8 * const pEnd = &aData[usableSize];
6981269907
int i = iFirst; /* Which cell to copy from pCArray*/
69813
- int j; /* Start of cell content area */
69908
+ u32 j; /* Start of cell content area */
6981469909
int iEnd = i+nCell; /* Loop terminator */
6981569910
u8 *pCellptr = pPg->aCellIdx;
6981669911
u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
6981769912
u8 *pData;
6981869913
int k; /* Current slot in pCArray->apEnd[] */
6981969914
u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
6982069915
6982169916
assert( i<iEnd );
6982269917
j = get2byte(&aData[hdr+5]);
69918
+ if( NEVER(j>(u32)usableSize) ){ j = 0; }
6982369919
memcpy(&pTmp[j], &aData[j], usableSize - j);
6982469920
6982569921
for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
6982669922
pSrcEnd = pCArray->apEnd[k];
6982769923
@@ -69997,11 +70093,11 @@
6999770093
}
6999870094
return nRet;
6999970095
}
7000070096
7000170097
/*
70002
-** pCArray contains pointers to and sizes of all cells in the pages being
70098
+** pCArray contains pointers to and sizes of all cells in the page being
7000370099
** balanced. The current page, pPg, has pPg->nCell cells starting with
7000470100
** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
7000570101
** starting at apCell[iNew].
7000670102
**
7000770103
** This routine makes the necessary adjustments to pPg so that it contains
@@ -70031,26 +70127,31 @@
7003170127
u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
7003270128
memcpy(pTmp, aData, pPg->pBt->usableSize);
7003370129
#endif
7003470130
7003570131
/* Remove cells from the start and end of the page */
70132
+ assert( nCell>=0 );
7003670133
if( iOld<iNew ){
7003770134
int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
70135
+ if( nShift>nCell ) return SQLITE_CORRUPT_BKPT;
7003870136
memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
7003970137
nCell -= nShift;
7004070138
}
7004170139
if( iNewEnd < iOldEnd ){
70042
- nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
70140
+ int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
70141
+ assert( nCell>=nTail );
70142
+ nCell -= nTail;
7004370143
}
7004470144
7004570145
pData = &aData[get2byteNotZero(&aData[hdr+5])];
7004670146
if( pData<pBegin ) goto editpage_fail;
7004770147
7004870148
/* Add cells to the start of the page */
7004970149
if( iNew<iOld ){
7005070150
int nAdd = MIN(nNew,iOld-iNew);
7005170151
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
70152
+ assert( nAdd>=0 );
7005270153
pCellptr = pPg->aCellIdx;
7005370154
memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
7005470155
if( pageInsertArray(
7005570156
pPg, pBegin, &pData, pCellptr,
7005670157
iNew, nAdd, pCArray
@@ -70061,10 +70162,11 @@
7006170162
/* Add any overflow cells */
7006270163
for(i=0; i<pPg->nOverflow; i++){
7006370164
int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
7006470165
if( iCell>=0 && iCell<nNew ){
7006570166
pCellptr = &pPg->aCellIdx[iCell * 2];
70167
+ assert( nCell>=iCell );
7006670168
memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
7006770169
nCell++;
7006870170
if( pageInsertArray(
7006970171
pPg, pBegin, &pData, pCellptr,
7007070172
iCell+iNew, 1, pCArray
@@ -70071,10 +70173,11 @@
7007170173
) ) goto editpage_fail;
7007270174
}
7007370175
}
7007470176
7007570177
/* Append cells to the end of the page */
70178
+ assert( nCell>=0 );
7007670179
pCellptr = &pPg->aCellIdx[nCell*2];
7007770180
if( pageInsertArray(
7007870181
pPg, pBegin, &pData, pCellptr,
7007970182
iNew+nCell, nNew-nCell, pCArray
7008070183
) ) goto editpage_fail;
@@ -70644,16 +70747,19 @@
7064470747
** the right of the i-th sibling page.
7064570748
** usableSpace: Number of bytes of space available on each sibling.
7064670749
**
7064770750
*/
7064870751
usableSpace = pBt->usableSize - 12 + leafCorrection;
70649
- for(i=0; i<nOld; i++){
70752
+ for(i=k=0; i<nOld; i++, k++){
7065070753
MemPage *p = apOld[i];
70651
- b.apEnd[i*2] = p->aDataEnd;
70652
- b.apEnd[i*2+1] = pParent->aDataEnd;
70653
- b.ixNx[i*2] = cntOld[i];
70654
- b.ixNx[i*2+1] = cntOld[i]+1;
70754
+ b.apEnd[k] = p->aDataEnd;
70755
+ b.ixNx[k] = cntOld[i];
70756
+ if( !leafData ){
70757
+ k++;
70758
+ b.apEnd[k] = pParent->aDataEnd;
70759
+ b.ixNx[k] = cntOld[i]+1;
70760
+ }
7065570761
szNew[i] = usableSpace - p->nFree;
7065670762
for(j=0; j<p->nOverflow; j++){
7065770763
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
7065870764
}
7065970765
cntNew[i] = cntOld[i];
@@ -71749,11 +71855,10 @@
7174971855
** from the internal node. The 'previous' entry is used for this instead
7175071856
** of the 'next' entry, as the previous entry is always a part of the
7175171857
** sub-tree headed by the child page of the cell being deleted. This makes
7175271858
** balancing the tree following the delete operation easier. */
7175371859
if( !pPage->leaf ){
71754
- pCur->skipNext = 0;
7175571860
rc = sqlite3BtreePrevious(pCur, 0);
7175671861
assert( rc!=SQLITE_DONE );
7175771862
if( rc ) return rc;
7175871863
}
7175971864
@@ -75234,10 +75339,13 @@
7523475339
u32 amt, /* Number of bytes to return. */
7523575340
Mem *pMem /* OUT: Return data in this Mem structure. */
7523675341
){
7523775342
int rc;
7523875343
pMem->flags = MEM_Null;
75344
+ if( sqlite3BtreeMaxRecordSize(pCur)<offset+amt ){
75345
+ return SQLITE_CORRUPT_BKPT;
75346
+ }
7523975347
if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){
7524075348
rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
7524175349
if( rc==SQLITE_OK ){
7524275350
pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
7524375351
pMem->flags = MEM_Blob;
@@ -97882,10 +97990,11 @@
9788297990
static void gatherSelectWindows(Select *p){
9788397991
Walker w;
9788497992
w.xExprCallback = gatherSelectWindowsCallback;
9788597993
w.xSelectCallback = gatherSelectWindowsSelectCallback;
9788697994
w.xSelectCallback2 = 0;
97995
+ w.pParse = 0;
9788797996
w.u.pSelect = p;
9788897997
sqlite3WalkSelect(&w, p);
9788997998
}
9789097999
#endif
9789198000
@@ -101504,18 +101613,20 @@
101504101613
if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
101505101614
switch( pExpr->op ){
101506101615
case TK_ISNOT:
101507101616
case TK_NOT:
101508101617
case TK_ISNULL:
101618
+ case TK_NOTNULL:
101509101619
case TK_IS:
101510101620
case TK_OR:
101511101621
case TK_CASE:
101512101622
case TK_IN:
101513101623
case TK_FUNCTION:
101514101624
testcase( pExpr->op==TK_ISNOT );
101515101625
testcase( pExpr->op==TK_NOT );
101516101626
testcase( pExpr->op==TK_ISNULL );
101627
+ testcase( pExpr->op==TK_NOTNULL );
101517101628
testcase( pExpr->op==TK_IS );
101518101629
testcase( pExpr->op==TK_OR );
101519101630
testcase( pExpr->op==TK_CASE );
101520101631
testcase( pExpr->op==TK_IN );
101521101632
testcase( pExpr->op==TK_FUNCTION );
@@ -105728,12 +105839,12 @@
105728105839
return;
105729105840
}
105730105841
assert( pVfs );
105731105842
flags |= SQLITE_OPEN_MAIN_DB;
105732105843
rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
105733
- sqlite3_free( zPath );
105734105844
db->nDb++;
105845
+ pNew->zDbSName = sqlite3DbStrDup(db, zName);
105735105846
}
105736105847
db->noSharedCache = 0;
105737105848
if( rc==SQLITE_CONSTRAINT ){
105738105849
rc = SQLITE_ERROR;
105739105850
zErrDyn = sqlite3MPrintf(db, "database is already attached");
@@ -105757,11 +105868,10 @@
105757105868
PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
105758105869
#endif
105759105870
sqlite3BtreeLeave(pNew->pBt);
105760105871
}
105761105872
pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
105762
- if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName);
105763105873
if( rc==SQLITE_OK && pNew->zDbSName==0 ){
105764105874
rc = SQLITE_NOMEM_BKPT;
105765105875
}
105766105876
105767105877
@@ -105785,19 +105895,23 @@
105785105895
zKey = (char *)sqlite3_value_blob(argv[2]);
105786105896
rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105787105897
break;
105788105898
105789105899
case SQLITE_NULL:
105790
- /* No key specified. Use the key from the main database */
105791
- sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
105792
- if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
105793
- rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105900
+ /* No key specified. Use the key from URI filename, or if none,
105901
+ ** use the key from the main database. */
105902
+ if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){
105903
+ sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
105904
+ if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
105905
+ rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105906
+ }
105794105907
}
105795105908
break;
105796105909
}
105797105910
}
105798105911
#endif
105912
+ sqlite3_free( zPath );
105799105913
105800105914
/* If the file was opened successfully, read the schema for the new database.
105801105915
** If this fails, or if opening the file failed, then close the file and
105802105916
** remove the entry from the db->aDb[] array. i.e. put everything back the
105803105917
** way we found it.
@@ -109965,21 +110079,26 @@
109965110079
assert( pParse->nErr==0 );
109966110080
if( db->init.busy ){
109967110081
Index *p;
109968110082
assert( !IN_SPECIAL_PARSE );
109969110083
assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
110084
+ if( pTblName!=0 ){
110085
+ pIndex->tnum = db->init.newTnum;
110086
+ if( sqlite3IndexHasDuplicateRootPage(pIndex) ){
110087
+ sqlite3ErrorMsg(pParse, "invalid rootpage");
110088
+ pParse->rc = SQLITE_CORRUPT_BKPT;
110089
+ goto exit_create_index;
110090
+ }
110091
+ }
109970110092
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
109971110093
pIndex->zName, pIndex);
109972110094
if( p ){
109973110095
assert( p==pIndex ); /* Malloc must have failed */
109974110096
sqlite3OomFault(db);
109975110097
goto exit_create_index;
109976110098
}
109977110099
db->mDbFlags |= DBFLAG_SchemaChange;
109978
- if( pTblName!=0 ){
109979
- pIndex->tnum = db->init.newTnum;
109980
- }
109981110100
}
109982110101
109983110102
/* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
109984110103
** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
109985110104
** emit code to allocate the index rootpage on disk and make an entry for
@@ -110351,11 +110470,10 @@
110351110470
110352110471
/* Allocate additional space if needed */
110353110472
if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110354110473
SrcList *pNew;
110355110474
int nAlloc = pSrc->nSrc*2+nExtra;
110356
- int nGot;
110357110475
sqlite3 *db = pParse->db;
110358110476
110359110477
if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110360110478
sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110361110479
SQLITE_MAX_SRCLIST);
@@ -110367,12 +110485,11 @@
110367110485
if( pNew==0 ){
110368110486
assert( db->mallocFailed );
110369110487
return 0;
110370110488
}
110371110489
pSrc = pNew;
110372
- nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
110373
- pSrc->nAlloc = nGot;
110490
+ pSrc->nAlloc = nAlloc;
110374110491
}
110375110492
110376110493
/* Move existing slots that come after the newly inserted slots
110377110494
** out of the way */
110378110495
for(i=pSrc->nSrc-1; i>=iStart; i--){
@@ -118554,11 +118671,11 @@
118554118671
if( zSql==0 ) zSql = "";
118555118672
118556118673
sqlite3_mutex_enter(db->mutex);
118557118674
sqlite3Error(db, SQLITE_OK);
118558118675
while( rc==SQLITE_OK && zSql[0] ){
118559
- int nCol;
118676
+ int nCol = 0;
118560118677
char **azVals = 0;
118561118678
118562118679
pStmt = 0;
118563118680
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
118564118681
assert( rc==SQLITE_OK || pStmt==0 );
@@ -118568,13 +118685,11 @@
118568118685
if( !pStmt ){
118569118686
/* this happens for a comment or white-space */
118570118687
zSql = zLeftover;
118571118688
continue;
118572118689
}
118573
-
118574118690
callbackIsInit = 0;
118575
- nCol = sqlite3_column_count(pStmt);
118576118691
118577118692
while( 1 ){
118578118693
int i;
118579118694
rc = sqlite3_step(pStmt);
118580118695
@@ -118581,10 +118696,11 @@
118581118696
/* Invoke the callback function if required */
118582118697
if( xCallback && (SQLITE_ROW==rc ||
118583118698
(SQLITE_DONE==rc && !callbackIsInit
118584118699
&& db->flags&SQLITE_NullCallback)) ){
118585118700
if( !callbackIsInit ){
118701
+ nCol = sqlite3_column_count(pStmt);
118586118702
azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
118587118703
if( azCols==0 ){
118588118704
goto exec_out;
118589118705
}
118590118706
for(i=0; i<nCol; i++){
@@ -120194,12 +120310,11 @@
120194120310
#define PragTyp_WAL_CHECKPOINT 39
120195120311
#define PragTyp_ACTIVATE_EXTENSIONS 40
120196120312
#define PragTyp_HEXKEY 41
120197120313
#define PragTyp_KEY 42
120198120314
#define PragTyp_LOCK_STATUS 43
120199
-#define PragTyp_PARSER_TRACE 44
120200
-#define PragTyp_STATS 45
120315
+#define PragTyp_STATS 44
120201120316
120202120317
/* Property flags associated with various pragma. */
120203120318
#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
120204120319
#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
120205120320
#define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -120356,26 +120471,22 @@
120356120471
/* ePragFlg: */ PragFlg_Result0,
120357120472
/* ColNames: */ 0, 0,
120358120473
/* iArg: */ 0 },
120359120474
#endif
120360120475
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120361
-#if !defined(SQLITE_OMIT_DEPRECATED)
120362120476
{/* zName: */ "count_changes",
120363120477
/* ePragTyp: */ PragTyp_FLAG,
120364120478
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120365120479
/* ColNames: */ 0, 0,
120366120480
/* iArg: */ SQLITE_CountRows },
120367120481
#endif
120368
-#endif
120369120482
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
120370
-#if !defined(SQLITE_OMIT_DEPRECATED)
120371120483
{/* zName: */ "data_store_directory",
120372120484
/* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120373120485
/* ePragFlg: */ PragFlg_NoColumns1,
120374120486
/* ColNames: */ 0, 0,
120375120487
/* iArg: */ 0 },
120376
-#endif
120377120488
#endif
120378120489
#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120379120490
{/* zName: */ "data_version",
120380120491
/* ePragTyp: */ PragTyp_HEADER_VALUE,
120381120492
/* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120387,18 +120498,16 @@
120387120498
/* ePragTyp: */ PragTyp_DATABASE_LIST,
120388120499
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120389120500
/* ColNames: */ 35, 3,
120390120501
/* iArg: */ 0 },
120391120502
#endif
120392
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120393
-#if !defined(SQLITE_OMIT_DEPRECATED)
120503
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
120394120504
{/* zName: */ "default_cache_size",
120395120505
/* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120396120506
/* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120397120507
/* ColNames: */ 45, 1,
120398120508
/* iArg: */ 0 },
120399
-#endif
120400120509
#endif
120401120510
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120402120511
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120403120512
{/* zName: */ "defer_foreign_keys",
120404120513
/* ePragTyp: */ PragTyp_FLAG,
@@ -120406,17 +120515,15 @@
120406120515
/* ColNames: */ 0, 0,
120407120516
/* iArg: */ SQLITE_DeferFKs },
120408120517
#endif
120409120518
#endif
120410120519
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120411
-#if !defined(SQLITE_OMIT_DEPRECATED)
120412120520
{/* zName: */ "empty_result_callbacks",
120413120521
/* ePragTyp: */ PragTyp_FLAG,
120414120522
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120415120523
/* ColNames: */ 0, 0,
120416120524
/* iArg: */ SQLITE_NullCallback },
120417
-#endif
120418120525
#endif
120419120526
#if !defined(SQLITE_OMIT_UTF16)
120420120527
{/* zName: */ "encoding",
120421120528
/* ePragTyp: */ PragTyp_ENCODING,
120422120529
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120452,19 +120559,15 @@
120452120559
/* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120453120560
/* ColNames: */ 0, 0,
120454120561
/* iArg: */ BTREE_FREE_PAGE_COUNT },
120455120562
#endif
120456120563
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120457
-#if !defined(SQLITE_OMIT_DEPRECATED)
120458120564
{/* zName: */ "full_column_names",
120459120565
/* ePragTyp: */ PragTyp_FLAG,
120460120566
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120461120567
/* ColNames: */ 0, 0,
120462120568
/* iArg: */ SQLITE_FullColNames },
120463
-#endif
120464
-#endif
120465
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120466120569
{/* zName: */ "fullfsync",
120467120570
/* ePragTyp: */ PragTyp_FLAG,
120468120571
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120469120572
/* ColNames: */ 0, 0,
120470120573
/* iArg: */ SQLITE_FullFSync },
@@ -120618,16 +120721,18 @@
120618120721
/* ePragTyp: */ PragTyp_PAGE_SIZE,
120619120722
/* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120620120723
/* ColNames: */ 0, 0,
120621120724
/* iArg: */ 0 },
120622120725
#endif
120623
-#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
120726
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120727
+#if defined(SQLITE_DEBUG)
120624120728
{/* zName: */ "parser_trace",
120625
- /* ePragTyp: */ PragTyp_PARSER_TRACE,
120626
- /* ePragFlg: */ 0,
120729
+ /* ePragTyp: */ PragTyp_FLAG,
120730
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120627120731
/* ColNames: */ 0, 0,
120628
- /* iArg: */ 0 },
120732
+ /* iArg: */ SQLITE_ParserTrace },
120733
+#endif
120629120734
#endif
120630120735
#if defined(SQLITE_INTROSPECTION_PRAGMAS)
120631120736
{/* zName: */ "pragma_list",
120632120737
/* ePragTyp: */ PragTyp_PRAGMA_LIST,
120633120738
/* ePragFlg: */ PragFlg_Result0,
@@ -120687,17 +120792,15 @@
120687120792
/* ePragFlg: */ PragFlg_Result0,
120688120793
/* ColNames: */ 0, 0,
120689120794
/* iArg: */ 0 },
120690120795
#endif
120691120796
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120692
-#if !defined(SQLITE_OMIT_DEPRECATED)
120693120797
{/* zName: */ "short_column_names",
120694120798
/* ePragTyp: */ PragTyp_FLAG,
120695120799
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120696120800
/* ColNames: */ 0, 0,
120697120801
/* iArg: */ SQLITE_ShortColNames },
120698
-#endif
120699120802
#endif
120700120803
{/* zName: */ "shrink_memory",
120701120804
/* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120702120805
/* ePragFlg: */ PragFlg_NoColumns,
120703120806
/* ColNames: */ 0, 0,
@@ -120746,19 +120849,15 @@
120746120849
{/* zName: */ "temp_store",
120747120850
/* ePragTyp: */ PragTyp_TEMP_STORE,
120748120851
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120749120852
/* ColNames: */ 0, 0,
120750120853
/* iArg: */ 0 },
120751
-#endif
120752
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120753
-#if !defined(SQLITE_OMIT_DEPRECATED)
120754120854
{/* zName: */ "temp_store_directory",
120755120855
/* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120756120856
/* ePragFlg: */ PragFlg_NoColumns1,
120757120857
/* ColNames: */ 0, 0,
120758120858
/* iArg: */ 0 },
120759
-#endif
120760120859
#endif
120761120860
#if defined(SQLITE_HAS_CODEC)
120762120861
{/* zName: */ "textkey",
120763120862
/* ePragTyp: */ PragTyp_KEY,
120764120863
/* ePragFlg: */ 0,
@@ -122225,23 +122324,10 @@
122225122324
}
122226122325
break;
122227122326
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
122228122327
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
122229122328
122230
-#ifndef NDEBUG
122231
- case PragTyp_PARSER_TRACE: {
122232
- if( zRight ){
122233
- if( sqlite3GetBoolean(zRight, 0) ){
122234
- sqlite3ParserTrace(stdout, "parser: ");
122235
- }else{
122236
- sqlite3ParserTrace(0, 0);
122237
- }
122238
- }
122239
- }
122240
- break;
122241
-#endif
122242
-
122243122329
/* Reinstall the LIKE and GLOB functions. The variant of LIKE
122244122330
** used will be case sensitive or not depending on the RHS.
122245122331
*/
122246122332
case PragTyp_CASE_SENSITIVE_LIKE: {
122247122333
if( zRight ){
@@ -123358,10 +123444,23 @@
123358123444
if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
123359123445
*pData->pzErrMsg = z;
123360123446
pData->rc = SQLITE_CORRUPT_BKPT;
123361123447
}
123362123448
}
123449
+
123450
+/*
123451
+** Check to see if any sibling index (another index on the same table)
123452
+** of pIndex has the same root page number, and if it does, return true.
123453
+** This would indicate a corrupt schema.
123454
+*/
123455
+SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index *pIndex){
123456
+ Index *p;
123457
+ for(p=pIndex->pTable->pIndex; p; p=p->pNext){
123458
+ if( p->tnum==pIndex->tnum && p!=pIndex ) return 1;
123459
+ }
123460
+ return 0;
123461
+}
123363123462
123364123463
/*
123365123464
** This is the callback routine for the code that initializes the
123366123465
** database. See sqlite3Init() below for additional information.
123367123466
** This routine is also called from the OP_ParseSchema opcode of the VDBE.
@@ -123437,10 +123536,11 @@
123437123536
Index *pIndex;
123438123537
pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
123439123538
if( pIndex==0
123440123539
|| sqlite3GetInt32(argv[1],&pIndex->tnum)==0
123441123540
|| pIndex->tnum<2
123541
+ || sqlite3IndexHasDuplicateRootPage(pIndex)
123442123542
){
123443123543
corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index");
123444123544
}
123445123545
}
123446123546
return 0;
@@ -129976,10 +130076,11 @@
129976130076
){
129977130077
continue;
129978130078
}
129979130079
129980130080
if( flattenSubquery(pParse, p, i, isAgg) ){
130081
+ if( pParse->nErr ) goto select_end;
129981130082
/* This subquery can be absorbed into its parent. */
129982130083
i = -1;
129983130084
}
129984130085
pTabList = p->pSrc;
129985130086
if( db->mallocFailed ) goto select_end;
@@ -134903,10 +135004,11 @@
134903135004
for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
134904135005
VTable *pVTab = db->aVTrans[i];
134905135006
const sqlite3_module *pMod = pVTab->pMod->pModule;
134906135007
if( pVTab->pVtab && pMod->iVersion>=2 ){
134907135008
int (*xMethod)(sqlite3_vtab *, int);
135009
+ sqlite3VtabLock(pVTab);
134908135010
switch( op ){
134909135011
case SAVEPOINT_BEGIN:
134910135012
xMethod = pMod->xSavepoint;
134911135013
pVTab->iSavepoint = iSavepoint+1;
134912135014
break;
@@ -134918,10 +135020,11 @@
134918135020
break;
134919135021
}
134920135022
if( xMethod && pVTab->iSavepoint>iSavepoint ){
134921135023
rc = xMethod(pVTab->pVtab, iSavepoint);
134922135024
}
135025
+ sqlite3VtabUnlock(pVTab);
134923135026
}
134924135027
}
134925135028
}
134926135029
return rc;
134927135030
}
@@ -137496,12 +137599,17 @@
137496137599
** Do not do this for the RHS of a LEFT JOIN. This is because the
137497137600
** expression may be evaluated after OP_NullRow has been executed on
137498137601
** the cursor. In this case it is important to do the full evaluation,
137499137602
** as the result of the expression may not be NULL, even if all table
137500137603
** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a
137604
+ **
137605
+ ** Also, do not do this when processing one index an a multi-index
137606
+ ** OR clause, since the transformation will become invalid once we
137607
+ ** move forward to the next index.
137608
+ ** https://sqlite.org/src/info/4e8e4857d32d401f
137501137609
*/
137502
- if( pLevel->iLeftJoin==0 ){
137610
+ if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137503137611
whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137504137612
}
137505137613
137506137614
/* Record the instruction used to terminate the loop. */
137507137615
if( pLoop->wsFlags & WHERE_ONEROW ){
@@ -139887,10 +139995,21 @@
139887139995
k = 0;
139888139996
pScan->iEquiv++;
139889139997
}
139890139998
return 0;
139891139999
}
140000
+
140001
+/*
140002
+** This is whereScanInit() for the case of an index on an expression.
140003
+** It is factored out into a separate tail-recursion subroutine so that
140004
+** the normal whereScanInit() routine, which is a high-runner, does not
140005
+** need to push registers onto the stack as part of its prologue.
140006
+*/
140007
+static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){
140008
+ pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr);
140009
+ return whereScanNext(pScan);
140010
+}
139892140011
139893140012
/*
139894140013
** Initialize a WHERE clause scanner object. Return a pointer to the
139895140014
** first match. Return NULL if there are no matches.
139896140015
**
@@ -139920,31 +140039,33 @@
139920140039
pScan->pOrigWC = pWC;
139921140040
pScan->pWC = pWC;
139922140041
pScan->pIdxExpr = 0;
139923140042
pScan->idxaff = 0;
139924140043
pScan->zCollName = 0;
140044
+ pScan->opMask = opMask;
140045
+ pScan->k = 0;
140046
+ pScan->aiCur[0] = iCur;
140047
+ pScan->nEquiv = 1;
140048
+ pScan->iEquiv = 1;
139925140049
if( pIdx ){
139926140050
int j = iColumn;
139927140051
iColumn = pIdx->aiColumn[j];
139928140052
if( iColumn==XN_EXPR ){
139929140053
pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
139930140054
pScan->zCollName = pIdx->azColl[j];
140055
+ pScan->aiColumn[0] = XN_EXPR;
140056
+ return whereScanInitIndexExpr(pScan);
139931140057
}else if( iColumn==pIdx->pTable->iPKey ){
139932140058
iColumn = XN_ROWID;
139933140059
}else if( iColumn>=0 ){
139934140060
pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
139935140061
pScan->zCollName = pIdx->azColl[j];
139936140062
}
139937140063
}else if( iColumn==XN_EXPR ){
139938140064
return 0;
139939140065
}
139940
- pScan->opMask = opMask;
139941
- pScan->k = 0;
139942
- pScan->aiCur[0] = iCur;
139943140066
pScan->aiColumn[0] = iColumn;
139944
- pScan->nEquiv = 1;
139945
- pScan->iEquiv = 1;
139946140067
return whereScanNext(pScan);
139947140068
}
139948140069
139949140070
/*
139950140071
** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
@@ -152900,11 +153021,18 @@
152900153021
db->u1.isInterrupted = 0;
152901153022
}
152902153023
pParse->rc = SQLITE_OK;
152903153024
pParse->zTail = zSql;
152904153025
assert( pzErrMsg!=0 );
152905
- /* sqlite3ParserTrace(stdout, "parser: "); */
153026
+#ifdef SQLITE_DEBUG
153027
+ if( db->flags & SQLITE_ParserTrace ){
153028
+ printf("parser: [[[%s]]]\n", zSql);
153029
+ sqlite3ParserTrace(stdout, "parser: ");
153030
+ }else{
153031
+ sqlite3ParserTrace(0, 0);
153032
+ }
153033
+#endif
152906153034
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
152907153035
pEngine = &sEngine;
152908153036
sqlite3ParserInit(pEngine, pParse);
152909153037
#else
152910153038
pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse);
@@ -153068,11 +153196,11 @@
153068153196
){
153069153197
sqlite3 *db; /* The database connection */
153070153198
int i; /* Next unread byte of zSql[] */
153071153199
int n; /* length of current token */
153072153200
int tokenType; /* type of current token */
153073
- int prevType; /* Previous non-whitespace token */
153201
+ int prevType = 0; /* Previous non-whitespace token */
153074153202
int nParen; /* Number of nested levels of parentheses */
153075153203
int iStartIN; /* Start of RHS of IN operator in z[] */
153076153204
int nParenAtIN; /* Value of nParent at start of RHS of IN operator */
153077153205
int j; /* Bytes of normalized SQL generated so far */
153078153206
sqlite3_str *pStr; /* The normalized SQL string under construction */
@@ -154223,10 +154351,17 @@
154223154351
sqlite3GlobalConfig.szSorterRef = (u32)iVal;
154224154352
break;
154225154353
}
154226154354
#endif /* SQLITE_ENABLE_SORTER_REFERENCES */
154227154355
154356
+#ifdef SQLITE_ENABLE_DESERIALIZE
154357
+ case SQLITE_CONFIG_MEMDB_MAXSIZE: {
154358
+ sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
154359
+ break;
154360
+ }
154361
+#endif /* SQLITE_ENABLE_DESERIALIZE */
154362
+
154228154363
default: {
154229154364
rc = SQLITE_ERROR;
154230154365
break;
154231154366
}
154232154367
}
@@ -156505,10 +156640,44 @@
156505156640
*pFlags = flags;
156506156641
*pzFile = zFile;
156507156642
return rc;
156508156643
}
156509156644
156645
+#if defined(SQLITE_HAS_CODEC)
156646
+/*
156647
+** Process URI filename query parameters relevant to the SQLite Encryption
156648
+** Extension. Return true if any of the relevant query parameters are
156649
+** seen and return false if not.
156650
+*/
156651
+SQLITE_PRIVATE int sqlite3CodecQueryParameters(
156652
+ sqlite3 *db, /* Database connection */
156653
+ const char *zDb, /* Which schema is being created/attached */
156654
+ const char *zUri /* URI filename */
156655
+){
156656
+ const char *zKey;
156657
+ if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){
156658
+ u8 iByte;
156659
+ int i;
156660
+ char zDecoded[40];
156661
+ for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
156662
+ iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
156663
+ if( (i&1)!=0 ) zDecoded[i/2] = iByte;
156664
+ }
156665
+ sqlite3_key_v2(db, zDb, zDecoded, i/2);
156666
+ return 1;
156667
+ }else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){
156668
+ sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey));
156669
+ return 1;
156670
+ }else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){
156671
+ sqlite3_key_v2(db, zDb, zKey, -1);
156672
+ return 1;
156673
+ }else{
156674
+ return 0;
156675
+ }
156676
+}
156677
+#endif
156678
+
156510156679
156511156680
/*
156512156681
** This routine does the work of opening a database on behalf of
156513156682
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
156514156683
** is UTF-8 encoded.
@@ -156850,29 +157019,16 @@
156850157019
void *pArg = sqlite3GlobalConfig.pSqllogArg;
156851157020
sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
156852157021
}
156853157022
#endif
156854157023
#if defined(SQLITE_HAS_CODEC)
156855
- if( rc==SQLITE_OK ){
156856
- const char *zKey;
156857
- if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
156858
- u8 iByte;
156859
- int i;
156860
- char zDecoded[40];
156861
- for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
156862
- iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
156863
- if( (i&1)!=0 ) zDecoded[i/2] = iByte;
156864
- }
156865
- sqlite3_key_v2(db, 0, zDecoded, i/2);
156866
- }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
156867
- sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
156868
- }
156869
- }
157024
+ if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen);
156870157025
#endif
156871157026
sqlite3_free(zOpen);
156872157027
return rc & 0xff;
156873157028
}
157029
+
156874157030
156875157031
/*
156876157032
** Open a new database handle.
156877157033
*/
156878157034
SQLITE_API int sqlite3_open(
@@ -161990,10 +162146,11 @@
161990162146
*/
161991162147
pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
161992162148
pTS->anOutput[0] = nDoclist;
161993162149
if( pTS->aaOutput[0] ){
161994162150
memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
162151
+ memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
161995162152
}else{
161996162153
return SQLITE_NOMEM;
161997162154
}
161998162155
}else{
161999162156
char *aMerge = aDoclist;
@@ -165603,19 +165760,19 @@
165603165760
if( iEq>=0 || iGe>=0 ){
165604165761
const unsigned char *zStr = sqlite3_value_text(apVal[0]);
165605165762
assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
165606165763
if( zStr ){
165607165764
pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
165608
- pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
165609165765
if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
165766
+ pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
165610165767
}
165611165768
}
165612165769
165613165770
if( iLe>=0 ){
165614165771
pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
165615
- pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
165616165772
if( pCsr->zStop==0 ) return SQLITE_NOMEM;
165773
+ pCsr->nStop = (int)strlen(pCsr->zStop);
165617165774
}
165618165775
165619165776
if( iLangid>=0 ){
165620165777
iLangVal = sqlite3_value_int(apVal[iLangid]);
165621165778
@@ -175488,15 +175645,18 @@
175488175645
assert( rc==SQLITE_OK || pCsr==0 );
175489175646
if( pCsr ){
175490175647
int iFirst = 0;
175491175648
pPhrase->pList = pCsr;
175492175649
fts3GetDeltaPosition(&pCsr, &iFirst);
175493
- assert( iFirst>=0 );
175494
- pPhrase->pHead = pCsr;
175495
- pPhrase->pTail = pCsr;
175496
- pPhrase->iHead = iFirst;
175497
- pPhrase->iTail = iFirst;
175650
+ if( iFirst<0 ){
175651
+ rc = FTS_CORRUPT_VTAB;
175652
+ }else{
175653
+ pPhrase->pHead = pCsr;
175654
+ pPhrase->pTail = pCsr;
175655
+ pPhrase->iHead = iFirst;
175656
+ pPhrase->iTail = iFirst;
175657
+ }
175498175658
}else{
175499175659
assert( rc!=SQLITE_OK || (
175500175660
pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
175501175661
));
175502175662
}
@@ -202679,11 +202839,13 @@
202679202839
int iAdj;
202680202840
int nScore;
202681202841
int jj;
202682202842
202683202843
rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
202684
- if( ic!=i || rc!=SQLITE_OK ) continue;
202844
+ if( ic!=i ) continue;
202845
+ if( io>nDocsize ) rc = FTS5_CORRUPT;
202846
+ if( rc!=SQLITE_OK ) continue;
202685202847
memset(aSeen, 0, nPhrase);
202686202848
rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
202687202849
io, nToken, &nScore, &iAdj
202688202850
);
202689202851
if( rc==SQLITE_OK && nScore>nBestScore ){
@@ -209352,11 +209514,11 @@
209352209514
u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
209353209515
int iOff = pIter->iLeafOffset; /* Offset to read at */
209354209516
int nNew; /* Bytes of new data */
209355209517
209356209518
iOff += fts5GetVarint32(&a[iOff], nNew);
209357
- if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n ){
209519
+ if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
209358209520
p->rc = FTS5_CORRUPT;
209359209521
return;
209360209522
}
209361209523
pIter->term.n = nKeep;
209362209524
fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
@@ -210026,11 +210188,11 @@
210026210188
}while( 1 );
210027210189
}
210028210190
210029210191
search_success:
210030210192
pIter->iLeafOffset = iOff + nNew;
210031
- if( pIter->iLeafOffset>n ){
210193
+ if( pIter->iLeafOffset>n || nNew<1 ){
210032210194
p->rc = FTS5_CORRUPT;
210033210195
return;
210034210196
}
210035210197
pIter->iTermLeafOffset = pIter->iLeafOffset;
210036210198
pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -210804,11 +210966,12 @@
210804210966
Fts5Index *p,
210805210967
Fts5SegIter *pSeg,
210806210968
Fts5Colset *pColset,
210807210969
Fts5Buffer *pBuf
210808210970
){
210809
- if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){
210971
+ if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
210972
+ memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
210810210973
if( pColset==0 ){
210811210974
fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
210812210975
}else{
210813210976
if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){
210814210977
PoslistCallbackCtx sCtx;
@@ -211845,11 +212008,11 @@
211845212008
Fts5Data *pData;
211846212009
int iId = pSeg->pSeg->iSegid;
211847212010
u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211848212011
211849212012
iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211850
- pData = fts5DataRead(p, iLeafRowid);
212013
+ pData = fts5LeafRead(p, iLeafRowid);
211851212014
if( pData ){
211852212015
if( iOff>pData->szLeaf ){
211853212016
/* This can occur if the pages that the segments occupy overlap - if
211854212017
** a single page has been assigned to more than one segment. In
211855212018
** this case a prior iteration of this loop may have corrupted the
@@ -212251,10 +212414,11 @@
212251212414
if( writer.bFirstRowidInPage ){
212252212415
fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
212253212416
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
212254212417
writer.bFirstRowidInPage = 0;
212255212418
fts5WriteDlidxAppend(p, &writer, iRowid);
212419
+ if( p->rc!=SQLITE_OK ) break;
212256212420
}else{
212257212421
pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
212258212422
}
212259212423
assert( pBuf->n<=pBuf->nSpace );
212260212424
@@ -212482,15 +212646,17 @@
212482212646
i64 iDelta,
212483212647
Fts5Iter *pMulti,
212484212648
Fts5Buffer *pBuf
212485212649
){
212486212650
int nData = pMulti->base.nData;
212651
+ int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
212487212652
assert( nData>0 );
212488
- if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nData+9+9) ){
212653
+ if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
212489212654
fts5BufferSafeAppendVarint(pBuf, iDelta);
212490212655
fts5BufferSafeAppendVarint(pBuf, nData*2);
212491212656
fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData);
212657
+ memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
212492212658
}
212493212659
}
212494212660
212495212661
212496212662
static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
@@ -212700,11 +212866,11 @@
212700212866
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
212701212867
}
212702212868
sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
212703212869
if( iPos1<0 ) break;
212704212870
}else{
212705
- assert( iPos2!=iPrev );
212871
+ assert_nc( iPos2!=iPrev );
212706212872
sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
212707212873
sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
212708212874
if( iPos2<0 ) break;
212709212875
}
212710212876
}
@@ -214126,10 +214292,14 @@
214126214292
fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
214127214293
214128214294
/* Decode any more doclist data that appears on the page before the
214129214295
** first term. */
214130214296
nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff;
214297
+ if( nDoclist+iOff>n ){
214298
+ rc = FTS5_CORRUPT;
214299
+ goto decode_out;
214300
+ }
214131214301
fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist);
214132214302
214133214303
while( iPgidxOff<n && rc==SQLITE_OK ){
214134214304
int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */
214135214305
int nByte; /* Bytes of data */
@@ -214544,11 +214714,11 @@
214544214714
p->ts.iSavepoint = iSavepoint-1;
214545214715
break;
214546214716
214547214717
case FTS5_ROLLBACKTO:
214548214718
assert( p->ts.eState==1 );
214549
- assert( iSavepoint>=0 );
214719
+ assert( iSavepoint>=-1 );
214550214720
assert( iSavepoint<=p->ts.iSavepoint );
214551214721
p->ts.iSavepoint = iSavepoint;
214552214722
break;
214553214723
}
214554214724
}
@@ -215964,11 +216134,13 @@
215964216134
const char **pz,
215965216135
int *pn
215966216136
){
215967216137
int rc = SQLITE_OK;
215968216138
Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
215969
- if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) ){
216139
+ if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab))
216140
+ || pCsr->ePlan==FTS5_PLAN_SPECIAL
216141
+ ){
215970216142
*pz = 0;
215971216143
*pn = 0;
215972216144
}else{
215973216145
rc = fts5SeekCursor(pCsr, 0);
215974216146
if( rc==SQLITE_OK ){
@@ -216902,11 +217074,11 @@
216902217074
int nArg, /* Number of args */
216903217075
sqlite3_value **apUnused /* Function arguments */
216904217076
){
216905217077
assert( nArg==0 );
216906217078
UNUSED_PARAM2(nArg, apUnused);
216907
- sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT);
217079
+ sqlite3_result_text(pCtx, "fts5: 2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd", -1, SQLITE_TRANSIENT);
216908217080
}
216909217081
216910217082
/*
216911217083
** Return true if zName is the extension on one of the shadow tables used
216912217084
** by this module.
@@ -221072,10 +221244,11 @@
221072221244
}else{
221073221245
const char *zTerm;
221074221246
int nTerm;
221075221247
221076221248
zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
221249
+ assert( nTerm>=0 );
221077221250
if( pCsr->nLeTerm>=0 ){
221078221251
int nCmp = MIN(nTerm, pCsr->nLeTerm);
221079221252
int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
221080221253
if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
221081221254
pCsr->bEof = 1;
@@ -221665,12 +221838,12 @@
221665221838
}
221666221839
#endif /* SQLITE_CORE */
221667221840
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221668221841
221669221842
/************** End of stmt.c ************************************************/
221670
-#if __LINE__!=221670
221843
+#if __LINE__!=221843
221671221844
#undef SQLITE_SOURCE_ID
221672
-#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2"
221845
+#define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959alt2"
221673221846
#endif
221674221847
/* Return the source-id for this library */
221675221848
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221676221849
/************************** End of sqlite3.c ******************************/
221677221850
--- 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.27.0. 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.
@@ -1160,13 +1160,13 @@
1160 **
1161 ** See also: [sqlite3_libversion()],
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.27.0"
1166 #define SQLITE_VERSION_NUMBER 3027000
1167 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -3019,10 +3019,21 @@
3019 ** from the database as records are returned in sorted order. The default
3020 ** value for this option is to never use this optimization. Specifying a
3021 ** negative value for this option restores the default behaviour.
3022 ** This option is only available if SQLite is compiled with the
3023 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
 
 
 
 
 
 
 
 
 
 
 
3024 ** </dl>
3025 */
3026 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
3027 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
3028 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -3049,10 +3060,11 @@
3049 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
3050 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
3051 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
3052 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
3053 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
 
3054
3055 /*
3056 ** CAPI3REF: Database Connection Configuration Options
3057 **
3058 ** These constants are the available integer configuration options that
@@ -4454,10 +4466,12 @@
4454 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4455 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
4456 ** is not a database file pathname pointer that SQLite passed into the xOpen
4457 ** VFS method, then the behavior of this routine is undefined and probably
4458 ** undesirable.
 
 
4459 */
4460 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
4461 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
4462 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
4463
@@ -14544,10 +14558,11 @@
14544 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
14545 #endif
14546 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
14547 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
14548 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
 
14549
14550 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
14551 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
14552 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
14553
@@ -16433,10 +16448,11 @@
16433 #define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */
16434 #define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */
16435 #define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */
16436 #define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */
16437 #define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */
 
16438 #endif
16439
16440 /*
16441 ** Allowed values for sqlite3.mDbFlags
16442 */
@@ -18305,10 +18321,13 @@
18305 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
18306 */
18307 void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
18308 void *pVdbeBranchArg; /* 1st argument */
18309 #endif
 
 
 
18310 #ifndef SQLITE_UNTESTABLE
18311 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
18312 #endif
18313 int bLocaltimeFault; /* True to fail localtime() calls */
18314 int bInternalFunctions; /* Internal SQL functions are visible */
@@ -18722,10 +18741,11 @@
18722 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
18723 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
18724 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
18725 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
18726 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
 
18727 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
18728 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
18729 SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
18730 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
18731 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -18755,10 +18775,15 @@
18755 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
18756 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
18757 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
18758 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
18759 sqlite3_vfs**,char**,char **);
 
 
 
 
 
18760 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
18761
18762 #ifdef SQLITE_UNTESTABLE
18763 # define sqlite3FaultSim(X) SQLITE_OK
18764 #else
@@ -19716,10 +19741,17 @@
19716 #ifndef SQLITE_DEFAULT_LOOKASIDE
19717 # define SQLITE_DEFAULT_LOOKASIDE 1200,100
19718 #endif
19719
19720
 
 
 
 
 
 
 
19721 /*
19722 ** The following singleton contains the global configuration for
19723 ** the SQLite library.
19724 */
19725 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -19763,17 +19795,20 @@
19763 #endif
19764 #ifdef SQLITE_VDBE_COVERAGE
19765 0, /* xVdbeBranch */
19766 0, /* pVbeBranchArg */
19767 #endif
 
 
 
19768 #ifndef SQLITE_UNTESTABLE
19769 0, /* xTestCallback */
19770 #endif
19771 0, /* bLocaltimeFault */
19772 0, /* bInternalFunctions */
19773 0x7ffffffe, /* iOnceResetThreshold */
19774 SQLITE_DEFAULT_SORTERREF_SIZE /* szSorterRef */
19775 };
19776
19777 /*
19778 ** Hash table for global functions - functions common to all
19779 ** database connections. After initialization, this table is
@@ -27296,10 +27331,31 @@
27296 static char *getTextArg(PrintfArguments *p){
27297 if( p->nArg<=p->nUsed ) return 0;
27298 return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
27299 }
27300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27301
27302 /*
27303 ** On machines with a small stack size, you can redefine the
27304 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
27305 */
@@ -27378,10 +27434,13 @@
27378 }
27379 /* Find out what flags are present */
27380 flag_leftjustify = flag_prefix = cThousand =
27381 flag_alternateform = flag_altform2 = flag_zeropad = 0;
27382 done = 0;
 
 
 
27383 do{
27384 switch( c ){
27385 case '-': flag_leftjustify = 1; break;
27386 case '+': flag_prefix = '+'; break;
27387 case ' ': flag_prefix = ' '; break;
@@ -27388,84 +27447,97 @@
27388 case '#': flag_alternateform = 1; break;
27389 case '!': flag_altform2 = 1; break;
27390 case '0': flag_zeropad = 1; break;
27391 case ',': cThousand = ','; break;
27392 default: done = 1; break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27393 }
27394 }while( !done && (c=(*++fmt))!=0 );
27395 /* Get the field width */
27396 if( c=='*' ){
27397 if( bArgList ){
27398 width = (int)getIntArg(pArgList);
27399 }else{
27400 width = va_arg(ap,int);
27401 }
27402 if( width<0 ){
27403 flag_leftjustify = 1;
27404 width = width >= -2147483647 ? -width : 0;
27405 }
27406 c = *++fmt;
27407 }else{
27408 unsigned wx = 0;
27409 while( c>='0' && c<='9' ){
27410 wx = wx*10 + c - '0';
27411 c = *++fmt;
27412 }
27413 testcase( wx>0x7fffffff );
27414 width = wx & 0x7fffffff;
27415 }
27416 assert( width>=0 );
27417 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
27418 if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27419 width = SQLITE_PRINTF_PRECISION_LIMIT;
27420 }
27421 #endif
27422
27423 /* Get the precision */
27424 if( c=='.' ){
27425 c = *++fmt;
27426 if( c=='*' ){
27427 if( bArgList ){
27428 precision = (int)getIntArg(pArgList);
27429 }else{
27430 precision = va_arg(ap,int);
27431 }
27432 c = *++fmt;
27433 if( precision<0 ){
27434 precision = precision >= -2147483647 ? -precision : -1;
27435 }
27436 }else{
27437 unsigned px = 0;
27438 while( c>='0' && c<='9' ){
27439 px = px*10 + c - '0';
27440 c = *++fmt;
27441 }
27442 testcase( px>0x7fffffff );
27443 precision = px & 0x7fffffff;
27444 }
27445 }else{
27446 precision = -1;
27447 }
27448 assert( precision>=(-1) );
27449 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
27450 if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){
27451 precision = SQLITE_PRINTF_PRECISION_LIMIT;
27452 }
27453 #endif
27454
27455
27456 /* Get the conversion type modifier */
27457 if( c=='l' ){
27458 flag_long = 1;
27459 c = *++fmt;
27460 if( c=='l' ){
27461 flag_long = 2;
27462 c = *++fmt;
27463 }
27464 }else{
27465 flag_long = 0;
27466 }
27467 /* Fetch the info entry for the field */
27468 infop = &fmtinfo[0];
27469 xtype = etINVALID;
27470 for(idx=0; idx<ArraySize(fmtinfo); idx++){
27471 if( c==fmtinfo[idx].fmttype ){
@@ -27546,16 +27618,15 @@
27546 }
27547 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
27548 nOut = etBUFSIZE;
27549 zOut = buf;
27550 }else{
27551 u64 n = (u64)precision + 10 + precision/3;
27552 zOut = zExtra = sqlite3Malloc( n );
27553 if( zOut==0 ){
27554 setStrAccumError(pAccum, SQLITE_NOMEM);
27555 return;
27556 }
27557 nOut = (int)n;
27558 }
27559 bufpt = &zOut[nOut-1];
27560 if( xtype==etORDINAL ){
27561 static const char zOrd[] = "thstndrd";
@@ -27670,16 +27741,16 @@
27670 if( xtype==etEXP ){
27671 e2 = 0;
27672 }else{
27673 e2 = exp;
27674 }
27675 if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){
27676 bufpt = zExtra
27677 = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
27678 if( bufpt==0 ){
27679 setStrAccumError(pAccum, SQLITE_NOMEM);
27680 return;
27681 }
27682 }
27683 zOut = bufpt;
27684 nsd = 16 + flag_altform2*10;
27685 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2;
@@ -27899,15 +27970,12 @@
27899 }
27900 }
27901 needQuote = !isnull && xtype==etSQLESCAPE2;
27902 n += i + 3;
27903 if( n>etBUFSIZE ){
27904 bufpt = zExtra = sqlite3Malloc( n );
27905 if( bufpt==0 ){
27906 setStrAccumError(pAccum, SQLITE_NOMEM);
27907 return;
27908 }
27909 }else{
27910 bufpt = buf;
27911 }
27912 j = 0;
27913 if( needQuote ) bufpt[j++] = q;
@@ -46578,15 +46646,10 @@
46578 int nMmap; /* Number of memory mapped pages */
46579 unsigned mFlags; /* Flags */
46580 int eLock; /* Most recent lock against this file */
46581 };
46582
46583 /* The default maximum size of an in-memory database */
46584 #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
46585 # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
46586 #endif
46587
46588 /*
46589 ** Methods for MemFile
46590 */
46591 static int memdbClose(sqlite3_file*);
46592 static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -46847,11 +46910,10 @@
46847 int iAmt,
46848 void **pp
46849 ){
46850 MemFile *p = (MemFile *)pFile;
46851 if( iOfst+iAmt>p->sz ){
46852 assert( CORRUPT_DB );
46853 *pp = 0;
46854 }else{
46855 p->nMmap++;
46856 *pp = (void*)(p->aData + iOfst);
46857 }
@@ -46882,11 +46944,11 @@
46882 memset(p, 0, sizeof(*p));
46883 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
46884 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
46885 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
46886 p->base.pMethods = &memdb_io_methods;
46887 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
46888 return SQLITE_OK;
46889 }
46890
46891 #if 0 /* Only used to delete rollback journals, master journals, and WAL
46892 ** files, none of which exist in memdb. So this routine is never used */
@@ -47134,12 +47196,12 @@
47134 }else{
47135 p->aData = pData;
47136 p->sz = szDb;
47137 p->szAlloc = szBuf;
47138 p->szMax = szBuf;
47139 if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){
47140 p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
47141 }
47142 p->mFlags = mFlags;
47143 rc = SQLITE_OK;
47144 }
47145
@@ -48557,16 +48619,26 @@
48557 /*
48558 ** Each cache entry is represented by an instance of the following
48559 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
48560 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
48561 ** in memory.
 
 
 
 
 
 
 
 
 
 
48562 */
48563 struct PgHdr1 {
48564 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
48565 unsigned int iKey; /* Key value (page number) */
48566 u8 isBulkLocal; /* This page from bulk local storage */
48567 u8 isAnchor; /* This is the PGroup.lru element */
48568 PgHdr1 *pNext; /* Next in hash table chain */
48569 PCache1 *pCache; /* Cache that currently owns this page */
48570 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
48571 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
48572 /* NB: pLruPrev is only valid if pLruNext!=0 */
@@ -48768,10 +48840,11 @@
48768 pX->page.pBuf = zBulk;
48769 pX->page.pExtra = &pX[1];
48770 pX->isBulkLocal = 1;
48771 pX->isAnchor = 0;
48772 pX->pNext = pCache->pFree;
 
48773 pCache->pFree = pX;
48774 zBulk += pCache->szAlloc;
48775 }while( --nBulk );
48776 }
48777 return pCache->pFree!=0;
@@ -62473,13 +62546,20 @@
62473 **
62474 ** Fields in this structure are accessed under the BtShared.mutex
62475 ** found at self->pBt->mutex.
62476 **
62477 ** skipNext meaning:
62478 ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
62479 ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
62480 ** eState==FAULT: Cursor fault with skipNext as error code.
 
 
 
 
 
 
 
62481 */
62482 struct BtCursor {
62483 u8 eState; /* One of the CURSOR_XXX constants (see below) */
62484 u8 curFlags; /* zero or more BTCF_* flags defined below */
62485 u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
@@ -63824,11 +63904,11 @@
63824 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
63825 if( rc==SQLITE_OK ){
63826 sqlite3_free(pCur->pKey);
63827 pCur->pKey = 0;
63828 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
63829 pCur->skipNext |= skipNext;
63830 if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
63831 pCur->eState = CURSOR_SKIPNEXT;
63832 }
63833 }
63834 return rc;
@@ -63894,11 +63974,10 @@
63894 return rc;
63895 }
63896 if( pCur->eState!=CURSOR_VALID ){
63897 *pDifferentRow = 1;
63898 }else{
63899 assert( pCur->skipNext==0 );
63900 *pDifferentRow = 0;
63901 }
63902 return SQLITE_OK;
63903 }
63904
@@ -67498,10 +67577,29 @@
67498 assert( cursorHoldsMutex(pCur) );
67499 assert( pCur->eState==CURSOR_VALID );
67500 getCellInfo(pCur);
67501 return pCur->info.nPayload;
67502 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67503
67504 /*
67505 ** Given the page number of an overflow page in the database (parameter
67506 ** ovfl), this function finds the page number of the next page in the
67507 ** linked list of overflow pages. If possible, it uses the auto-vacuum
@@ -68313,11 +68411,11 @@
68313 }
68314 /* If the requested key is one more than the previous key, then
68315 ** try to get there using sqlite3BtreeNext() rather than a full
68316 ** binary search. This is an optimization only. The correct answer
68317 ** is still obtained without this case, only a little more slowely */
68318 if( pCur->info.nKey+1==intKey && !pCur->skipNext ){
68319 *pRes = 0;
68320 rc = sqlite3BtreeNext(pCur, 0);
68321 if( rc==SQLITE_OK ){
68322 getCellInfo(pCur);
68323 if( pCur->info.nKey==intKey ){
@@ -68587,28 +68685,22 @@
68587 int rc;
68588 int idx;
68589 MemPage *pPage;
68590
68591 assert( cursorOwnsBtShared(pCur) );
68592 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
68593 if( pCur->eState!=CURSOR_VALID ){
68594 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
68595 rc = restoreCursorPosition(pCur);
68596 if( rc!=SQLITE_OK ){
68597 return rc;
68598 }
68599 if( CURSOR_INVALID==pCur->eState ){
68600 return SQLITE_DONE;
68601 }
68602 if( pCur->skipNext ){
68603 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68604 pCur->eState = CURSOR_VALID;
68605 if( pCur->skipNext>0 ){
68606 pCur->skipNext = 0;
68607 return SQLITE_OK;
68608 }
68609 pCur->skipNext = 0;
68610 }
68611 }
68612
68613 pPage = pCur->pPage;
68614 idx = ++pCur->ix;
@@ -68659,11 +68751,10 @@
68659 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){
68660 MemPage *pPage;
68661 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
68662 assert( cursorOwnsBtShared(pCur) );
68663 assert( flags==0 || flags==1 );
68664 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
68665 pCur->info.nSize = 0;
68666 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
68667 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
68668 pPage = pCur->pPage;
68669 if( (++pCur->ix)>=pPage->nCell ){
@@ -68700,11 +68791,10 @@
68700 static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){
68701 int rc;
68702 MemPage *pPage;
68703
68704 assert( cursorOwnsBtShared(pCur) );
68705 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
68706 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
68707 assert( pCur->info.nSize==0 );
68708 if( pCur->eState!=CURSOR_VALID ){
68709 rc = restoreCursorPosition(pCur);
68710 if( rc!=SQLITE_OK ){
@@ -68711,18 +68801,13 @@
68711 return rc;
68712 }
68713 if( CURSOR_INVALID==pCur->eState ){
68714 return SQLITE_DONE;
68715 }
68716 if( pCur->skipNext ){
68717 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
68718 pCur->eState = CURSOR_VALID;
68719 if( pCur->skipNext<0 ){
68720 pCur->skipNext = 0;
68721 return SQLITE_OK;
68722 }
68723 pCur->skipNext = 0;
68724 }
68725 }
68726
68727 pPage = pCur->pPage;
68728 assert( pPage->isInit );
@@ -68753,11 +68838,10 @@
68753 return rc;
68754 }
68755 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){
68756 assert( cursorOwnsBtShared(pCur) );
68757 assert( flags==0 || flags==1 );
68758 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
68759 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
68760 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
68761 pCur->info.nSize = 0;
68762 if( pCur->eState!=CURSOR_VALID
68763 || pCur->ix==0
@@ -69722,27 +69806,38 @@
69722 ** / | \
69723 ** --------- --------- ---------
69724 ** |Child-1| |Child-2| |Child-3|
69725 ** --------- --------- ---------
69726 **
69727 ** The order of cells is in the array is:
69728 **
69729 ** 1. All cells from Child-1 in order
69730 ** 2. The first divider cell from Parent
69731 ** 3. All cells from Child-2 in order
69732 ** 4. The second divider cell from Parent
69733 ** 5. All cells from Child-3 in order
69734 **
69735 ** The apEnd[] array holds pointer to the end of page for Child-1, the
69736 ** Parent, Child-2, the Parent (again), and Child-3. The ixNx[] array
69737 ** holds the number of cells contained in each of these 5 stages, and
69738 ** all stages to the left. Hence:
 
 
 
 
69739 ** ixNx[0] = Number of cells in Child-1.
69740 ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
69741 ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69742 ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
69743 ** ixNx[4] = Total number of cells.
 
 
 
 
 
 
 
69744 */
69745 typedef struct CellArray CellArray;
69746 struct CellArray {
69747 int nCell; /* Number of cells in apCell[] */
69748 MemPage *pRef; /* Reference page */
@@ -69808,20 +69903,21 @@
69808 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
69809 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
69810 const int usableSize = pPg->pBt->usableSize;
69811 u8 * const pEnd = &aData[usableSize];
69812 int i = iFirst; /* Which cell to copy from pCArray*/
69813 int j; /* Start of cell content area */
69814 int iEnd = i+nCell; /* Loop terminator */
69815 u8 *pCellptr = pPg->aCellIdx;
69816 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
69817 u8 *pData;
69818 int k; /* Current slot in pCArray->apEnd[] */
69819 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
69820
69821 assert( i<iEnd );
69822 j = get2byte(&aData[hdr+5]);
 
69823 memcpy(&pTmp[j], &aData[j], usableSize - j);
69824
69825 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69826 pSrcEnd = pCArray->apEnd[k];
69827
@@ -69997,11 +70093,11 @@
69997 }
69998 return nRet;
69999 }
70000
70001 /*
70002 ** pCArray contains pointers to and sizes of all cells in the pages being
70003 ** balanced. The current page, pPg, has pPg->nCell cells starting with
70004 ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
70005 ** starting at apCell[iNew].
70006 **
70007 ** This routine makes the necessary adjustments to pPg so that it contains
@@ -70031,26 +70127,31 @@
70031 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
70032 memcpy(pTmp, aData, pPg->pBt->usableSize);
70033 #endif
70034
70035 /* Remove cells from the start and end of the page */
 
70036 if( iOld<iNew ){
70037 int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
 
70038 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
70039 nCell -= nShift;
70040 }
70041 if( iNewEnd < iOldEnd ){
70042 nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
 
 
70043 }
70044
70045 pData = &aData[get2byteNotZero(&aData[hdr+5])];
70046 if( pData<pBegin ) goto editpage_fail;
70047
70048 /* Add cells to the start of the page */
70049 if( iNew<iOld ){
70050 int nAdd = MIN(nNew,iOld-iNew);
70051 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
 
70052 pCellptr = pPg->aCellIdx;
70053 memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
70054 if( pageInsertArray(
70055 pPg, pBegin, &pData, pCellptr,
70056 iNew, nAdd, pCArray
@@ -70061,10 +70162,11 @@
70061 /* Add any overflow cells */
70062 for(i=0; i<pPg->nOverflow; i++){
70063 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70064 if( iCell>=0 && iCell<nNew ){
70065 pCellptr = &pPg->aCellIdx[iCell * 2];
 
70066 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70067 nCell++;
70068 if( pageInsertArray(
70069 pPg, pBegin, &pData, pCellptr,
70070 iCell+iNew, 1, pCArray
@@ -70071,10 +70173,11 @@
70071 ) ) goto editpage_fail;
70072 }
70073 }
70074
70075 /* Append cells to the end of the page */
 
70076 pCellptr = &pPg->aCellIdx[nCell*2];
70077 if( pageInsertArray(
70078 pPg, pBegin, &pData, pCellptr,
70079 iNew+nCell, nNew-nCell, pCArray
70080 ) ) goto editpage_fail;
@@ -70644,16 +70747,19 @@
70644 ** the right of the i-th sibling page.
70645 ** usableSpace: Number of bytes of space available on each sibling.
70646 **
70647 */
70648 usableSpace = pBt->usableSize - 12 + leafCorrection;
70649 for(i=0; i<nOld; i++){
70650 MemPage *p = apOld[i];
70651 b.apEnd[i*2] = p->aDataEnd;
70652 b.apEnd[i*2+1] = pParent->aDataEnd;
70653 b.ixNx[i*2] = cntOld[i];
70654 b.ixNx[i*2+1] = cntOld[i]+1;
 
 
 
70655 szNew[i] = usableSpace - p->nFree;
70656 for(j=0; j<p->nOverflow; j++){
70657 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70658 }
70659 cntNew[i] = cntOld[i];
@@ -71749,11 +71855,10 @@
71749 ** from the internal node. The 'previous' entry is used for this instead
71750 ** of the 'next' entry, as the previous entry is always a part of the
71751 ** sub-tree headed by the child page of the cell being deleted. This makes
71752 ** balancing the tree following the delete operation easier. */
71753 if( !pPage->leaf ){
71754 pCur->skipNext = 0;
71755 rc = sqlite3BtreePrevious(pCur, 0);
71756 assert( rc!=SQLITE_DONE );
71757 if( rc ) return rc;
71758 }
71759
@@ -75234,10 +75339,13 @@
75234 u32 amt, /* Number of bytes to return. */
75235 Mem *pMem /* OUT: Return data in this Mem structure. */
75236 ){
75237 int rc;
75238 pMem->flags = MEM_Null;
 
 
 
75239 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){
75240 rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
75241 if( rc==SQLITE_OK ){
75242 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
75243 pMem->flags = MEM_Blob;
@@ -97882,10 +97990,11 @@
97882 static void gatherSelectWindows(Select *p){
97883 Walker w;
97884 w.xExprCallback = gatherSelectWindowsCallback;
97885 w.xSelectCallback = gatherSelectWindowsSelectCallback;
97886 w.xSelectCallback2 = 0;
 
97887 w.u.pSelect = p;
97888 sqlite3WalkSelect(&w, p);
97889 }
97890 #endif
97891
@@ -101504,18 +101613,20 @@
101504 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
101505 switch( pExpr->op ){
101506 case TK_ISNOT:
101507 case TK_NOT:
101508 case TK_ISNULL:
 
101509 case TK_IS:
101510 case TK_OR:
101511 case TK_CASE:
101512 case TK_IN:
101513 case TK_FUNCTION:
101514 testcase( pExpr->op==TK_ISNOT );
101515 testcase( pExpr->op==TK_NOT );
101516 testcase( pExpr->op==TK_ISNULL );
 
101517 testcase( pExpr->op==TK_IS );
101518 testcase( pExpr->op==TK_OR );
101519 testcase( pExpr->op==TK_CASE );
101520 testcase( pExpr->op==TK_IN );
101521 testcase( pExpr->op==TK_FUNCTION );
@@ -105728,12 +105839,12 @@
105728 return;
105729 }
105730 assert( pVfs );
105731 flags |= SQLITE_OPEN_MAIN_DB;
105732 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
105733 sqlite3_free( zPath );
105734 db->nDb++;
 
105735 }
105736 db->noSharedCache = 0;
105737 if( rc==SQLITE_CONSTRAINT ){
105738 rc = SQLITE_ERROR;
105739 zErrDyn = sqlite3MPrintf(db, "database is already attached");
@@ -105757,11 +105868,10 @@
105757 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
105758 #endif
105759 sqlite3BtreeLeave(pNew->pBt);
105760 }
105761 pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
105762 if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName);
105763 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
105764 rc = SQLITE_NOMEM_BKPT;
105765 }
105766
105767
@@ -105785,19 +105895,23 @@
105785 zKey = (char *)sqlite3_value_blob(argv[2]);
105786 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105787 break;
105788
105789 case SQLITE_NULL:
105790 /* No key specified. Use the key from the main database */
105791 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
105792 if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
105793 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
 
 
 
105794 }
105795 break;
105796 }
105797 }
105798 #endif
 
105799
105800 /* If the file was opened successfully, read the schema for the new database.
105801 ** If this fails, or if opening the file failed, then close the file and
105802 ** remove the entry from the db->aDb[] array. i.e. put everything back the
105803 ** way we found it.
@@ -109965,21 +110079,26 @@
109965 assert( pParse->nErr==0 );
109966 if( db->init.busy ){
109967 Index *p;
109968 assert( !IN_SPECIAL_PARSE );
109969 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
 
 
 
 
 
 
 
 
109970 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
109971 pIndex->zName, pIndex);
109972 if( p ){
109973 assert( p==pIndex ); /* Malloc must have failed */
109974 sqlite3OomFault(db);
109975 goto exit_create_index;
109976 }
109977 db->mDbFlags |= DBFLAG_SchemaChange;
109978 if( pTblName!=0 ){
109979 pIndex->tnum = db->init.newTnum;
109980 }
109981 }
109982
109983 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
109984 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
109985 ** emit code to allocate the index rootpage on disk and make an entry for
@@ -110351,11 +110470,10 @@
110351
110352 /* Allocate additional space if needed */
110353 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110354 SrcList *pNew;
110355 int nAlloc = pSrc->nSrc*2+nExtra;
110356 int nGot;
110357 sqlite3 *db = pParse->db;
110358
110359 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110360 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110361 SQLITE_MAX_SRCLIST);
@@ -110367,12 +110485,11 @@
110367 if( pNew==0 ){
110368 assert( db->mallocFailed );
110369 return 0;
110370 }
110371 pSrc = pNew;
110372 nGot = (sqlite3DbMallocSize(db, pNew) - sizeof(*pSrc))/sizeof(pSrc->a[0])+1;
110373 pSrc->nAlloc = nGot;
110374 }
110375
110376 /* Move existing slots that come after the newly inserted slots
110377 ** out of the way */
110378 for(i=pSrc->nSrc-1; i>=iStart; i--){
@@ -118554,11 +118671,11 @@
118554 if( zSql==0 ) zSql = "";
118555
118556 sqlite3_mutex_enter(db->mutex);
118557 sqlite3Error(db, SQLITE_OK);
118558 while( rc==SQLITE_OK && zSql[0] ){
118559 int nCol;
118560 char **azVals = 0;
118561
118562 pStmt = 0;
118563 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
118564 assert( rc==SQLITE_OK || pStmt==0 );
@@ -118568,13 +118685,11 @@
118568 if( !pStmt ){
118569 /* this happens for a comment or white-space */
118570 zSql = zLeftover;
118571 continue;
118572 }
118573
118574 callbackIsInit = 0;
118575 nCol = sqlite3_column_count(pStmt);
118576
118577 while( 1 ){
118578 int i;
118579 rc = sqlite3_step(pStmt);
118580
@@ -118581,10 +118696,11 @@
118581 /* Invoke the callback function if required */
118582 if( xCallback && (SQLITE_ROW==rc ||
118583 (SQLITE_DONE==rc && !callbackIsInit
118584 && db->flags&SQLITE_NullCallback)) ){
118585 if( !callbackIsInit ){
 
118586 azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
118587 if( azCols==0 ){
118588 goto exec_out;
118589 }
118590 for(i=0; i<nCol; i++){
@@ -120194,12 +120310,11 @@
120194 #define PragTyp_WAL_CHECKPOINT 39
120195 #define PragTyp_ACTIVATE_EXTENSIONS 40
120196 #define PragTyp_HEXKEY 41
120197 #define PragTyp_KEY 42
120198 #define PragTyp_LOCK_STATUS 43
120199 #define PragTyp_PARSER_TRACE 44
120200 #define PragTyp_STATS 45
120201
120202 /* Property flags associated with various pragma. */
120203 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
120204 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
120205 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -120356,26 +120471,22 @@
120356 /* ePragFlg: */ PragFlg_Result0,
120357 /* ColNames: */ 0, 0,
120358 /* iArg: */ 0 },
120359 #endif
120360 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120361 #if !defined(SQLITE_OMIT_DEPRECATED)
120362 {/* zName: */ "count_changes",
120363 /* ePragTyp: */ PragTyp_FLAG,
120364 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120365 /* ColNames: */ 0, 0,
120366 /* iArg: */ SQLITE_CountRows },
120367 #endif
120368 #endif
120369 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
120370 #if !defined(SQLITE_OMIT_DEPRECATED)
120371 {/* zName: */ "data_store_directory",
120372 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120373 /* ePragFlg: */ PragFlg_NoColumns1,
120374 /* ColNames: */ 0, 0,
120375 /* iArg: */ 0 },
120376 #endif
120377 #endif
120378 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120379 {/* zName: */ "data_version",
120380 /* ePragTyp: */ PragTyp_HEADER_VALUE,
120381 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120387,18 +120498,16 @@
120387 /* ePragTyp: */ PragTyp_DATABASE_LIST,
120388 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120389 /* ColNames: */ 35, 3,
120390 /* iArg: */ 0 },
120391 #endif
120392 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120393 #if !defined(SQLITE_OMIT_DEPRECATED)
120394 {/* zName: */ "default_cache_size",
120395 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120396 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120397 /* ColNames: */ 45, 1,
120398 /* iArg: */ 0 },
120399 #endif
120400 #endif
120401 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120402 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120403 {/* zName: */ "defer_foreign_keys",
120404 /* ePragTyp: */ PragTyp_FLAG,
@@ -120406,17 +120515,15 @@
120406 /* ColNames: */ 0, 0,
120407 /* iArg: */ SQLITE_DeferFKs },
120408 #endif
120409 #endif
120410 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120411 #if !defined(SQLITE_OMIT_DEPRECATED)
120412 {/* zName: */ "empty_result_callbacks",
120413 /* ePragTyp: */ PragTyp_FLAG,
120414 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120415 /* ColNames: */ 0, 0,
120416 /* iArg: */ SQLITE_NullCallback },
120417 #endif
120418 #endif
120419 #if !defined(SQLITE_OMIT_UTF16)
120420 {/* zName: */ "encoding",
120421 /* ePragTyp: */ PragTyp_ENCODING,
120422 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120452,19 +120559,15 @@
120452 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120453 /* ColNames: */ 0, 0,
120454 /* iArg: */ BTREE_FREE_PAGE_COUNT },
120455 #endif
120456 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120457 #if !defined(SQLITE_OMIT_DEPRECATED)
120458 {/* zName: */ "full_column_names",
120459 /* ePragTyp: */ PragTyp_FLAG,
120460 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120461 /* ColNames: */ 0, 0,
120462 /* iArg: */ SQLITE_FullColNames },
120463 #endif
120464 #endif
120465 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120466 {/* zName: */ "fullfsync",
120467 /* ePragTyp: */ PragTyp_FLAG,
120468 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120469 /* ColNames: */ 0, 0,
120470 /* iArg: */ SQLITE_FullFSync },
@@ -120618,16 +120721,18 @@
120618 /* ePragTyp: */ PragTyp_PAGE_SIZE,
120619 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120620 /* ColNames: */ 0, 0,
120621 /* iArg: */ 0 },
120622 #endif
120623 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
 
120624 {/* zName: */ "parser_trace",
120625 /* ePragTyp: */ PragTyp_PARSER_TRACE,
120626 /* ePragFlg: */ 0,
120627 /* ColNames: */ 0, 0,
120628 /* iArg: */ 0 },
 
120629 #endif
120630 #if defined(SQLITE_INTROSPECTION_PRAGMAS)
120631 {/* zName: */ "pragma_list",
120632 /* ePragTyp: */ PragTyp_PRAGMA_LIST,
120633 /* ePragFlg: */ PragFlg_Result0,
@@ -120687,17 +120792,15 @@
120687 /* ePragFlg: */ PragFlg_Result0,
120688 /* ColNames: */ 0, 0,
120689 /* iArg: */ 0 },
120690 #endif
120691 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120692 #if !defined(SQLITE_OMIT_DEPRECATED)
120693 {/* zName: */ "short_column_names",
120694 /* ePragTyp: */ PragTyp_FLAG,
120695 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120696 /* ColNames: */ 0, 0,
120697 /* iArg: */ SQLITE_ShortColNames },
120698 #endif
120699 #endif
120700 {/* zName: */ "shrink_memory",
120701 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120702 /* ePragFlg: */ PragFlg_NoColumns,
120703 /* ColNames: */ 0, 0,
@@ -120746,19 +120849,15 @@
120746 {/* zName: */ "temp_store",
120747 /* ePragTyp: */ PragTyp_TEMP_STORE,
120748 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120749 /* ColNames: */ 0, 0,
120750 /* iArg: */ 0 },
120751 #endif
120752 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
120753 #if !defined(SQLITE_OMIT_DEPRECATED)
120754 {/* zName: */ "temp_store_directory",
120755 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120756 /* ePragFlg: */ PragFlg_NoColumns1,
120757 /* ColNames: */ 0, 0,
120758 /* iArg: */ 0 },
120759 #endif
120760 #endif
120761 #if defined(SQLITE_HAS_CODEC)
120762 {/* zName: */ "textkey",
120763 /* ePragTyp: */ PragTyp_KEY,
120764 /* ePragFlg: */ 0,
@@ -122225,23 +122324,10 @@
122225 }
122226 break;
122227 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
122228 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
122229
122230 #ifndef NDEBUG
122231 case PragTyp_PARSER_TRACE: {
122232 if( zRight ){
122233 if( sqlite3GetBoolean(zRight, 0) ){
122234 sqlite3ParserTrace(stdout, "parser: ");
122235 }else{
122236 sqlite3ParserTrace(0, 0);
122237 }
122238 }
122239 }
122240 break;
122241 #endif
122242
122243 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
122244 ** used will be case sensitive or not depending on the RHS.
122245 */
122246 case PragTyp_CASE_SENSITIVE_LIKE: {
122247 if( zRight ){
@@ -123358,10 +123444,23 @@
123358 if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
123359 *pData->pzErrMsg = z;
123360 pData->rc = SQLITE_CORRUPT_BKPT;
123361 }
123362 }
 
 
 
 
 
 
 
 
 
 
 
 
 
123363
123364 /*
123365 ** This is the callback routine for the code that initializes the
123366 ** database. See sqlite3Init() below for additional information.
123367 ** This routine is also called from the OP_ParseSchema opcode of the VDBE.
@@ -123437,10 +123536,11 @@
123437 Index *pIndex;
123438 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
123439 if( pIndex==0
123440 || sqlite3GetInt32(argv[1],&pIndex->tnum)==0
123441 || pIndex->tnum<2
 
123442 ){
123443 corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index");
123444 }
123445 }
123446 return 0;
@@ -129976,10 +130076,11 @@
129976 ){
129977 continue;
129978 }
129979
129980 if( flattenSubquery(pParse, p, i, isAgg) ){
 
129981 /* This subquery can be absorbed into its parent. */
129982 i = -1;
129983 }
129984 pTabList = p->pSrc;
129985 if( db->mallocFailed ) goto select_end;
@@ -134903,10 +135004,11 @@
134903 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
134904 VTable *pVTab = db->aVTrans[i];
134905 const sqlite3_module *pMod = pVTab->pMod->pModule;
134906 if( pVTab->pVtab && pMod->iVersion>=2 ){
134907 int (*xMethod)(sqlite3_vtab *, int);
 
134908 switch( op ){
134909 case SAVEPOINT_BEGIN:
134910 xMethod = pMod->xSavepoint;
134911 pVTab->iSavepoint = iSavepoint+1;
134912 break;
@@ -134918,10 +135020,11 @@
134918 break;
134919 }
134920 if( xMethod && pVTab->iSavepoint>iSavepoint ){
134921 rc = xMethod(pVTab->pVtab, iSavepoint);
134922 }
 
134923 }
134924 }
134925 }
134926 return rc;
134927 }
@@ -137496,12 +137599,17 @@
137496 ** Do not do this for the RHS of a LEFT JOIN. This is because the
137497 ** expression may be evaluated after OP_NullRow has been executed on
137498 ** the cursor. In this case it is important to do the full evaluation,
137499 ** as the result of the expression may not be NULL, even if all table
137500 ** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a
 
 
 
 
 
137501 */
137502 if( pLevel->iLeftJoin==0 ){
137503 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137504 }
137505
137506 /* Record the instruction used to terminate the loop. */
137507 if( pLoop->wsFlags & WHERE_ONEROW ){
@@ -139887,10 +139995,21 @@
139887 k = 0;
139888 pScan->iEquiv++;
139889 }
139890 return 0;
139891 }
 
 
 
 
 
 
 
 
 
 
 
139892
139893 /*
139894 ** Initialize a WHERE clause scanner object. Return a pointer to the
139895 ** first match. Return NULL if there are no matches.
139896 **
@@ -139920,31 +140039,33 @@
139920 pScan->pOrigWC = pWC;
139921 pScan->pWC = pWC;
139922 pScan->pIdxExpr = 0;
139923 pScan->idxaff = 0;
139924 pScan->zCollName = 0;
 
 
 
 
 
139925 if( pIdx ){
139926 int j = iColumn;
139927 iColumn = pIdx->aiColumn[j];
139928 if( iColumn==XN_EXPR ){
139929 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
139930 pScan->zCollName = pIdx->azColl[j];
 
 
139931 }else if( iColumn==pIdx->pTable->iPKey ){
139932 iColumn = XN_ROWID;
139933 }else if( iColumn>=0 ){
139934 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
139935 pScan->zCollName = pIdx->azColl[j];
139936 }
139937 }else if( iColumn==XN_EXPR ){
139938 return 0;
139939 }
139940 pScan->opMask = opMask;
139941 pScan->k = 0;
139942 pScan->aiCur[0] = iCur;
139943 pScan->aiColumn[0] = iColumn;
139944 pScan->nEquiv = 1;
139945 pScan->iEquiv = 1;
139946 return whereScanNext(pScan);
139947 }
139948
139949 /*
139950 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
@@ -152900,11 +153021,18 @@
152900 db->u1.isInterrupted = 0;
152901 }
152902 pParse->rc = SQLITE_OK;
152903 pParse->zTail = zSql;
152904 assert( pzErrMsg!=0 );
152905 /* sqlite3ParserTrace(stdout, "parser: "); */
 
 
 
 
 
 
 
152906 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
152907 pEngine = &sEngine;
152908 sqlite3ParserInit(pEngine, pParse);
152909 #else
152910 pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse);
@@ -153068,11 +153196,11 @@
153068 ){
153069 sqlite3 *db; /* The database connection */
153070 int i; /* Next unread byte of zSql[] */
153071 int n; /* length of current token */
153072 int tokenType; /* type of current token */
153073 int prevType; /* Previous non-whitespace token */
153074 int nParen; /* Number of nested levels of parentheses */
153075 int iStartIN; /* Start of RHS of IN operator in z[] */
153076 int nParenAtIN; /* Value of nParent at start of RHS of IN operator */
153077 int j; /* Bytes of normalized SQL generated so far */
153078 sqlite3_str *pStr; /* The normalized SQL string under construction */
@@ -154223,10 +154351,17 @@
154223 sqlite3GlobalConfig.szSorterRef = (u32)iVal;
154224 break;
154225 }
154226 #endif /* SQLITE_ENABLE_SORTER_REFERENCES */
154227
 
 
 
 
 
 
 
154228 default: {
154229 rc = SQLITE_ERROR;
154230 break;
154231 }
154232 }
@@ -156505,10 +156640,44 @@
156505 *pFlags = flags;
156506 *pzFile = zFile;
156507 return rc;
156508 }
156509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156510
156511 /*
156512 ** This routine does the work of opening a database on behalf of
156513 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
156514 ** is UTF-8 encoded.
@@ -156850,29 +157019,16 @@
156850 void *pArg = sqlite3GlobalConfig.pSqllogArg;
156851 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
156852 }
156853 #endif
156854 #if defined(SQLITE_HAS_CODEC)
156855 if( rc==SQLITE_OK ){
156856 const char *zKey;
156857 if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){
156858 u8 iByte;
156859 int i;
156860 char zDecoded[40];
156861 for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
156862 iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
156863 if( (i&1)!=0 ) zDecoded[i/2] = iByte;
156864 }
156865 sqlite3_key_v2(db, 0, zDecoded, i/2);
156866 }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
156867 sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
156868 }
156869 }
156870 #endif
156871 sqlite3_free(zOpen);
156872 return rc & 0xff;
156873 }
 
156874
156875 /*
156876 ** Open a new database handle.
156877 */
156878 SQLITE_API int sqlite3_open(
@@ -161990,10 +162146,11 @@
161990 */
161991 pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
161992 pTS->anOutput[0] = nDoclist;
161993 if( pTS->aaOutput[0] ){
161994 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
 
161995 }else{
161996 return SQLITE_NOMEM;
161997 }
161998 }else{
161999 char *aMerge = aDoclist;
@@ -165603,19 +165760,19 @@
165603 if( iEq>=0 || iGe>=0 ){
165604 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
165605 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
165606 if( zStr ){
165607 pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
165608 pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
165609 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
 
165610 }
165611 }
165612
165613 if( iLe>=0 ){
165614 pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
165615 pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
165616 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
 
165617 }
165618
165619 if( iLangid>=0 ){
165620 iLangVal = sqlite3_value_int(apVal[iLangid]);
165621
@@ -175488,15 +175645,18 @@
175488 assert( rc==SQLITE_OK || pCsr==0 );
175489 if( pCsr ){
175490 int iFirst = 0;
175491 pPhrase->pList = pCsr;
175492 fts3GetDeltaPosition(&pCsr, &iFirst);
175493 assert( iFirst>=0 );
175494 pPhrase->pHead = pCsr;
175495 pPhrase->pTail = pCsr;
175496 pPhrase->iHead = iFirst;
175497 pPhrase->iTail = iFirst;
 
 
 
175498 }else{
175499 assert( rc!=SQLITE_OK || (
175500 pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
175501 ));
175502 }
@@ -202679,11 +202839,13 @@
202679 int iAdj;
202680 int nScore;
202681 int jj;
202682
202683 rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
202684 if( ic!=i || rc!=SQLITE_OK ) continue;
 
 
202685 memset(aSeen, 0, nPhrase);
202686 rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
202687 io, nToken, &nScore, &iAdj
202688 );
202689 if( rc==SQLITE_OK && nScore>nBestScore ){
@@ -209352,11 +209514,11 @@
209352 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
209353 int iOff = pIter->iLeafOffset; /* Offset to read at */
209354 int nNew; /* Bytes of new data */
209355
209356 iOff += fts5GetVarint32(&a[iOff], nNew);
209357 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n ){
209358 p->rc = FTS5_CORRUPT;
209359 return;
209360 }
209361 pIter->term.n = nKeep;
209362 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
@@ -210026,11 +210188,11 @@
210026 }while( 1 );
210027 }
210028
210029 search_success:
210030 pIter->iLeafOffset = iOff + nNew;
210031 if( pIter->iLeafOffset>n ){
210032 p->rc = FTS5_CORRUPT;
210033 return;
210034 }
210035 pIter->iTermLeafOffset = pIter->iLeafOffset;
210036 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -210804,11 +210966,12 @@
210804 Fts5Index *p,
210805 Fts5SegIter *pSeg,
210806 Fts5Colset *pColset,
210807 Fts5Buffer *pBuf
210808 ){
210809 if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){
 
210810 if( pColset==0 ){
210811 fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
210812 }else{
210813 if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){
210814 PoslistCallbackCtx sCtx;
@@ -211845,11 +212008,11 @@
211845 Fts5Data *pData;
211846 int iId = pSeg->pSeg->iSegid;
211847 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
211848
211849 iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
211850 pData = fts5DataRead(p, iLeafRowid);
211851 if( pData ){
211852 if( iOff>pData->szLeaf ){
211853 /* This can occur if the pages that the segments occupy overlap - if
211854 ** a single page has been assigned to more than one segment. In
211855 ** this case a prior iteration of this loop may have corrupted the
@@ -212251,10 +212414,11 @@
212251 if( writer.bFirstRowidInPage ){
212252 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
212253 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
212254 writer.bFirstRowidInPage = 0;
212255 fts5WriteDlidxAppend(p, &writer, iRowid);
 
212256 }else{
212257 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
212258 }
212259 assert( pBuf->n<=pBuf->nSpace );
212260
@@ -212482,15 +212646,17 @@
212482 i64 iDelta,
212483 Fts5Iter *pMulti,
212484 Fts5Buffer *pBuf
212485 ){
212486 int nData = pMulti->base.nData;
 
212487 assert( nData>0 );
212488 if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nData+9+9) ){
212489 fts5BufferSafeAppendVarint(pBuf, iDelta);
212490 fts5BufferSafeAppendVarint(pBuf, nData*2);
212491 fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData);
 
212492 }
212493 }
212494
212495
212496 static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
@@ -212700,11 +212866,11 @@
212700 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
212701 }
212702 sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
212703 if( iPos1<0 ) break;
212704 }else{
212705 assert( iPos2!=iPrev );
212706 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
212707 sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
212708 if( iPos2<0 ) break;
212709 }
212710 }
@@ -214126,10 +214292,14 @@
214126 fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
214127
214128 /* Decode any more doclist data that appears on the page before the
214129 ** first term. */
214130 nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff;
 
 
 
 
214131 fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist);
214132
214133 while( iPgidxOff<n && rc==SQLITE_OK ){
214134 int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */
214135 int nByte; /* Bytes of data */
@@ -214544,11 +214714,11 @@
214544 p->ts.iSavepoint = iSavepoint-1;
214545 break;
214546
214547 case FTS5_ROLLBACKTO:
214548 assert( p->ts.eState==1 );
214549 assert( iSavepoint>=0 );
214550 assert( iSavepoint<=p->ts.iSavepoint );
214551 p->ts.iSavepoint = iSavepoint;
214552 break;
214553 }
214554 }
@@ -215964,11 +216134,13 @@
215964 const char **pz,
215965 int *pn
215966 ){
215967 int rc = SQLITE_OK;
215968 Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
215969 if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) ){
 
 
215970 *pz = 0;
215971 *pn = 0;
215972 }else{
215973 rc = fts5SeekCursor(pCsr, 0);
215974 if( rc==SQLITE_OK ){
@@ -216902,11 +217074,11 @@
216902 int nArg, /* Number of args */
216903 sqlite3_value **apUnused /* Function arguments */
216904 ){
216905 assert( nArg==0 );
216906 UNUSED_PARAM2(nArg, apUnused);
216907 sqlite3_result_text(pCtx, "fts5: 2019-01-26 23:34:50 a3ea1a822d3a110f4f186f2fc8550f435c8c98635d058096b7be9d4df7066b8b", -1, SQLITE_TRANSIENT);
216908 }
216909
216910 /*
216911 ** Return true if zName is the extension on one of the shadow tables used
216912 ** by this module.
@@ -221072,10 +221244,11 @@
221072 }else{
221073 const char *zTerm;
221074 int nTerm;
221075
221076 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
 
221077 if( pCsr->nLeTerm>=0 ){
221078 int nCmp = MIN(nTerm, pCsr->nLeTerm);
221079 int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
221080 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
221081 pCsr->bEof = 1;
@@ -221665,12 +221838,12 @@
221665 }
221666 #endif /* SQLITE_CORE */
221667 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221668
221669 /************** End of stmt.c ************************************************/
221670 #if __LINE__!=221670
221671 #undef SQLITE_SOURCE_ID
221672 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt2"
221673 #endif
221674 /* Return the source-id for this library */
221675 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221676 /************************** End of sqlite3.c ******************************/
221677
--- 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.27.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.
@@ -1160,13 +1160,13 @@
1160 **
1161 ** See also: [sqlite3_libversion()],
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.27.1"
1166 #define SQLITE_VERSION_NUMBER 3027001
1167 #define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -3019,10 +3019,21 @@
3019 ** from the database as records are returned in sorted order. The default
3020 ** value for this option is to never use this optimization. Specifying a
3021 ** negative value for this option restores the default behaviour.
3022 ** This option is only available if SQLite is compiled with the
3023 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
3024 **
3025 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
3026 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
3027 ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
3028 ** [sqlite3_int64] parameter which is the default maximum size for an in-memory
3029 ** database created using [sqlite3_deserialize()]. This default maximum
3030 ** size can be adjusted up or down for individual databases using the
3031 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
3032 ** configuration setting is never used, then the default maximum is determined
3033 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
3034 ** compile-time option is not set, then the default maximum is 1073741824.
3035 ** </dl>
3036 */
3037 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
3038 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
3039 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -3049,10 +3060,11 @@
3060 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
3061 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
3062 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
3063 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
3064 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
3065 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
3066
3067 /*
3068 ** CAPI3REF: Database Connection Configuration Options
3069 **
3070 ** These constants are the available integer configuration options that
@@ -4454,10 +4466,12 @@
4466 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4467 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
4468 ** is not a database file pathname pointer that SQLite passed into the xOpen
4469 ** VFS method, then the behavior of this routine is undefined and probably
4470 ** undesirable.
4471 **
4472 ** See the [URI filename] documentation for additional information.
4473 */
4474 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
4475 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
4476 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
4477
@@ -14544,10 +14558,11 @@
14558 SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*);
14559 #endif
14560 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*);
14561 SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
14562 SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
14563 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
14564
14565 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
14566 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
14567 SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
14568
@@ -16433,10 +16448,11 @@
16448 #define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */
16449 #define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */
16450 #define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */
16451 #define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */
16452 #define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */
16453 #define SQLITE_ParserTrace HI(0x0020) /* PRAGMA parser_trace=ON */
16454 #endif
16455
16456 /*
16457 ** Allowed values for sqlite3.mDbFlags
16458 */
@@ -18305,10 +18321,13 @@
18321 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
18322 */
18323 void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
18324 void *pVdbeBranchArg; /* 1st argument */
18325 #endif
18326 #ifdef SQLITE_ENABLE_DESERIALIZE
18327 sqlite3_int64 mxMemdbSize; /* Default max memdb size */
18328 #endif
18329 #ifndef SQLITE_UNTESTABLE
18330 int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */
18331 #endif
18332 int bLocaltimeFault; /* True to fail localtime() calls */
18333 int bInternalFunctions; /* Internal SQL functions are visible */
@@ -18722,10 +18741,11 @@
18741 SQLITE_PRIVATE void sqlite3ExprListSetSortOrder(ExprList*,int);
18742 SQLITE_PRIVATE void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
18743 SQLITE_PRIVATE void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);
18744 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
18745 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
18746 SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index*);
18747 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
18748 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
18749 SQLITE_PRIVATE int sqlite3InitOne(sqlite3*, int, char**, u32);
18750 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
18751 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -18755,10 +18775,15 @@
18775 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
18776 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
18777 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
18778 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
18779 sqlite3_vfs**,char**,char **);
18780 #ifdef SQLITE_HAS_CODEC
18781 SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
18782 #else
18783 # define sqlite3CodecQueryParameters(A,B,C) 0
18784 #endif
18785 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*);
18786
18787 #ifdef SQLITE_UNTESTABLE
18788 # define sqlite3FaultSim(X) SQLITE_OK
18789 #else
@@ -19716,10 +19741,17 @@
19741 #ifndef SQLITE_DEFAULT_LOOKASIDE
19742 # define SQLITE_DEFAULT_LOOKASIDE 1200,100
19743 #endif
19744
19745
19746 /* The default maximum size of an in-memory database created using
19747 ** sqlite3_deserialize()
19748 */
19749 #ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
19750 # define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
19751 #endif
19752
19753 /*
19754 ** The following singleton contains the global configuration for
19755 ** the SQLite library.
19756 */
19757 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
@@ -19763,17 +19795,20 @@
19795 #endif
19796 #ifdef SQLITE_VDBE_COVERAGE
19797 0, /* xVdbeBranch */
19798 0, /* pVbeBranchArg */
19799 #endif
19800 #ifdef SQLITE_ENABLE_DESERIALIZE
19801 SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
19802 #endif
19803 #ifndef SQLITE_UNTESTABLE
19804 0, /* xTestCallback */
19805 #endif
19806 0, /* bLocaltimeFault */
19807 0, /* bInternalFunctions */
19808 0x7ffffffe, /* iOnceResetThreshold */
19809 SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */
19810 };
19811
19812 /*
19813 ** Hash table for global functions - functions common to all
19814 ** database connections. After initialization, this table is
@@ -27296,10 +27331,31 @@
27331 static char *getTextArg(PrintfArguments *p){
27332 if( p->nArg<=p->nUsed ) return 0;
27333 return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
27334 }
27335
27336 /*
27337 ** Allocate memory for a temporary buffer needed for printf rendering.
27338 **
27339 ** If the requested size of the temp buffer is larger than the size
27340 ** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error.
27341 ** Do the size check before the memory allocation to prevent rogue
27342 ** SQL from requesting large allocations using the precision or width
27343 ** field of the printf() function.
27344 */
27345 static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
27346 char *z;
27347 if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
27348 setStrAccumError(pAccum, SQLITE_TOOBIG);
27349 return 0;
27350 }
27351 z = sqlite3DbMallocRaw(pAccum->db, n);
27352 if( z==0 ){
27353 setStrAccumError(pAccum, SQLITE_NOMEM);
27354 }
27355 return z;
27356 }
27357
27358 /*
27359 ** On machines with a small stack size, you can redefine the
27360 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
27361 */
@@ -27378,10 +27434,13 @@
27434 }
27435 /* Find out what flags are present */
27436 flag_leftjustify = flag_prefix = cThousand =
27437 flag_alternateform = flag_altform2 = flag_zeropad = 0;
27438 done = 0;
27439 width = 0;
27440 flag_long = 0;
27441 precision = -1;
27442 do{
27443 switch( c ){
27444 case '-': flag_leftjustify = 1; break;
27445 case '+': flag_prefix = '+'; break;
27446 case ' ': flag_prefix = ' '; break;
@@ -27388,84 +27447,97 @@
27447 case '#': flag_alternateform = 1; break;
27448 case '!': flag_altform2 = 1; break;
27449 case '0': flag_zeropad = 1; break;
27450 case ',': cThousand = ','; break;
27451 default: done = 1; break;
27452 case 'l': {
27453 flag_long = 1;
27454 c = *++fmt;
27455 if( c=='l' ){
27456 c = *++fmt;
27457 flag_long = 2;
27458 }
27459 done = 1;
27460 break;
27461 }
27462 case '1': case '2': case '3': case '4': case '5':
27463 case '6': case '7': case '8': case '9': {
27464 unsigned wx = c - '0';
27465 while( (c = *++fmt)>='0' && c<='9' ){
27466 wx = wx*10 + c - '0';
27467 }
27468 testcase( wx>0x7fffffff );
27469 width = wx & 0x7fffffff;
27470 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
27471 if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27472 width = SQLITE_PRINTF_PRECISION_LIMIT;
27473 }
27474 #endif
27475 if( c!='.' && c!='l' ){
27476 done = 1;
27477 }else{
27478 fmt--;
27479 }
27480 break;
27481 }
27482 case '*': {
27483 if( bArgList ){
27484 width = (int)getIntArg(pArgList);
27485 }else{
27486 width = va_arg(ap,int);
27487 }
27488 if( width<0 ){
27489 flag_leftjustify = 1;
27490 width = width >= -2147483647 ? -width : 0;
27491 }
27492 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
27493 if( width>SQLITE_PRINTF_PRECISION_LIMIT ){
27494 width = SQLITE_PRINTF_PRECISION_LIMIT;
27495 }
27496 #endif
27497 if( (c = fmt[1])!='.' && c!='l' ){
27498 c = *++fmt;
27499 done = 1;
27500 }
27501 break;
27502 }
27503 case '.': {
27504 c = *++fmt;
27505 if( c=='*' ){
27506 if( bArgList ){
27507 precision = (int)getIntArg(pArgList);
27508 }else{
27509 precision = va_arg(ap,int);
27510 }
27511 if( precision<0 ){
27512 precision = precision >= -2147483647 ? -precision : -1;
27513 }
27514 c = *++fmt;
27515 }else{
27516 unsigned px = 0;
27517 while( c>='0' && c<='9' ){
27518 px = px*10 + c - '0';
27519 c = *++fmt;
27520 }
27521 testcase( px>0x7fffffff );
27522 precision = px & 0x7fffffff;
27523 }
27524 #ifdef SQLITE_PRINTF_PRECISION_LIMIT
27525 if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){
27526 precision = SQLITE_PRINTF_PRECISION_LIMIT;
27527 }
27528 #endif
27529 if( c=='l' ){
27530 --fmt;
27531 }else{
27532 done = 1;
27533 }
27534 break;
27535 }
27536 }
27537 }while( !done && (c=(*++fmt))!=0 );
27538
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27539 /* Fetch the info entry for the field */
27540 infop = &fmtinfo[0];
27541 xtype = etINVALID;
27542 for(idx=0; idx<ArraySize(fmtinfo); idx++){
27543 if( c==fmtinfo[idx].fmttype ){
@@ -27546,16 +27618,15 @@
27618 }
27619 if( precision<etBUFSIZE-10-etBUFSIZE/3 ){
27620 nOut = etBUFSIZE;
27621 zOut = buf;
27622 }else{
27623 u64 n;
27624 n = (u64)precision + 10;
27625 if( cThousand ) n += precision/3;
27626 zOut = zExtra = printfTempBuf(pAccum, n);
27627 if( zOut==0 ) return;
 
27628 nOut = (int)n;
27629 }
27630 bufpt = &zOut[nOut-1];
27631 if( xtype==etORDINAL ){
27632 static const char zOrd[] = "thstndrd";
@@ -27670,16 +27741,16 @@
27741 if( xtype==etEXP ){
27742 e2 = 0;
27743 }else{
27744 e2 = exp;
27745 }
27746 {
27747 i64 szBufNeeded; /* Size of a temporary buffer needed */
27748 szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15;
27749 if( szBufNeeded > etBUFSIZE ){
27750 bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded);
27751 if( bufpt==0 ) return;
27752 }
27753 }
27754 zOut = bufpt;
27755 nsd = 16 + flag_altform2*10;
27756 flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2;
@@ -27899,15 +27970,12 @@
27970 }
27971 }
27972 needQuote = !isnull && xtype==etSQLESCAPE2;
27973 n += i + 3;
27974 if( n>etBUFSIZE ){
27975 bufpt = zExtra = printfTempBuf(pAccum, n);
27976 if( bufpt==0 ) return;
 
 
 
27977 }else{
27978 bufpt = buf;
27979 }
27980 j = 0;
27981 if( needQuote ) bufpt[j++] = q;
@@ -46578,15 +46646,10 @@
46646 int nMmap; /* Number of memory mapped pages */
46647 unsigned mFlags; /* Flags */
46648 int eLock; /* Most recent lock against this file */
46649 };
46650
 
 
 
 
 
46651 /*
46652 ** Methods for MemFile
46653 */
46654 static int memdbClose(sqlite3_file*);
46655 static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
@@ -46847,11 +46910,10 @@
46910 int iAmt,
46911 void **pp
46912 ){
46913 MemFile *p = (MemFile *)pFile;
46914 if( iOfst+iAmt>p->sz ){
 
46915 *pp = 0;
46916 }else{
46917 p->nMmap++;
46918 *pp = (void*)(p->aData + iOfst);
46919 }
@@ -46882,11 +46944,11 @@
46944 memset(p, 0, sizeof(*p));
46945 p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
46946 assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
46947 *pOutFlags = flags | SQLITE_OPEN_MEMORY;
46948 p->base.pMethods = &memdb_io_methods;
46949 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
46950 return SQLITE_OK;
46951 }
46952
46953 #if 0 /* Only used to delete rollback journals, master journals, and WAL
46954 ** files, none of which exist in memdb. So this routine is never used */
@@ -47134,12 +47196,12 @@
47196 }else{
47197 p->aData = pData;
47198 p->sz = szDb;
47199 p->szAlloc = szBuf;
47200 p->szMax = szBuf;
47201 if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
47202 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
47203 }
47204 p->mFlags = mFlags;
47205 rc = SQLITE_OK;
47206 }
47207
@@ -48557,16 +48619,26 @@
48619 /*
48620 ** Each cache entry is represented by an instance of the following
48621 ** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
48622 ** PgHdr1.pCache->szPage bytes is allocated directly before this structure
48623 ** in memory.
48624 **
48625 ** Note: Variables isBulkLocal and isAnchor were once type "u8". That works,
48626 ** but causes a 2-byte gap in the structure for most architectures (since
48627 ** pointers must be either 4 or 8-byte aligned). As this structure is located
48628 ** in memory directly after the associated page data, if the database is
48629 ** corrupt, code at the b-tree layer may overread the page buffer and
48630 ** read part of this structure before the corruption is detected. This
48631 ** can cause a valgrind error if the unitialized gap is accessed. Using u16
48632 ** ensures there is no such gap, and therefore no bytes of unitialized memory
48633 ** in the structure.
48634 */
48635 struct PgHdr1 {
48636 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
48637 unsigned int iKey; /* Key value (page number) */
48638 u16 isBulkLocal; /* This page from bulk local storage */
48639 u16 isAnchor; /* This is the PGroup.lru element */
48640 PgHdr1 *pNext; /* Next in hash table chain */
48641 PCache1 *pCache; /* Cache that currently owns this page */
48642 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
48643 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
48644 /* NB: pLruPrev is only valid if pLruNext!=0 */
@@ -48768,10 +48840,11 @@
48840 pX->page.pBuf = zBulk;
48841 pX->page.pExtra = &pX[1];
48842 pX->isBulkLocal = 1;
48843 pX->isAnchor = 0;
48844 pX->pNext = pCache->pFree;
48845 pX->pLruPrev = 0; /* Initializing this saves a valgrind error */
48846 pCache->pFree = pX;
48847 zBulk += pCache->szAlloc;
48848 }while( --nBulk );
48849 }
48850 return pCache->pFree!=0;
@@ -62473,13 +62546,20 @@
62546 **
62547 ** Fields in this structure are accessed under the BtShared.mutex
62548 ** found at self->pBt->mutex.
62549 **
62550 ** skipNext meaning:
62551 ** The meaning of skipNext depends on the value of eState:
62552 **
62553 ** eState Meaning of skipNext
62554 ** VALID skipNext is meaningless and is ignored
62555 ** INVALID skipNext is meaningless and is ignored
62556 ** SKIPNEXT sqlite3BtreeNext() is a no-op if skipNext>0 and
62557 ** sqlite3BtreePrevious() is no-op if skipNext<0.
62558 ** REQUIRESEEK restoreCursorPosition() restores the cursor to
62559 ** eState=SKIPNEXT if skipNext!=0
62560 ** FAULT skipNext holds the cursor fault error code.
62561 */
62562 struct BtCursor {
62563 u8 eState; /* One of the CURSOR_XXX constants (see below) */
62564 u8 curFlags; /* zero or more BTCF_* flags defined below */
62565 u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
@@ -63824,11 +63904,11 @@
63904 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
63905 if( rc==SQLITE_OK ){
63906 sqlite3_free(pCur->pKey);
63907 pCur->pKey = 0;
63908 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
63909 if( skipNext ) pCur->skipNext = skipNext;
63910 if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
63911 pCur->eState = CURSOR_SKIPNEXT;
63912 }
63913 }
63914 return rc;
@@ -63894,11 +63974,10 @@
63974 return rc;
63975 }
63976 if( pCur->eState!=CURSOR_VALID ){
63977 *pDifferentRow = 1;
63978 }else{
 
63979 *pDifferentRow = 0;
63980 }
63981 return SQLITE_OK;
63982 }
63983
@@ -67498,10 +67577,29 @@
67577 assert( cursorHoldsMutex(pCur) );
67578 assert( pCur->eState==CURSOR_VALID );
67579 getCellInfo(pCur);
67580 return pCur->info.nPayload;
67581 }
67582
67583 /*
67584 ** Return an upper bound on the size of any record for the table
67585 ** that the cursor is pointing into.
67586 **
67587 ** This is an optimization. Everything will still work if this
67588 ** routine always returns 2147483647 (which is the largest record
67589 ** that SQLite can handle) or more. But returning a smaller value might
67590 ** prevent large memory allocations when trying to interpret a
67591 ** corrupt datrabase.
67592 **
67593 ** The current implementation merely returns the size of the underlying
67594 ** database file.
67595 */
67596 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
67597 assert( cursorHoldsMutex(pCur) );
67598 assert( pCur->eState==CURSOR_VALID );
67599 return pCur->pBt->pageSize * (sqlite3_int64)pCur->pBt->nPage;
67600 }
67601
67602 /*
67603 ** Given the page number of an overflow page in the database (parameter
67604 ** ovfl), this function finds the page number of the next page in the
67605 ** linked list of overflow pages. If possible, it uses the auto-vacuum
@@ -68313,11 +68411,11 @@
68411 }
68412 /* If the requested key is one more than the previous key, then
68413 ** try to get there using sqlite3BtreeNext() rather than a full
68414 ** binary search. This is an optimization only. The correct answer
68415 ** is still obtained without this case, only a little more slowely */
68416 if( pCur->info.nKey+1==intKey ){
68417 *pRes = 0;
68418 rc = sqlite3BtreeNext(pCur, 0);
68419 if( rc==SQLITE_OK ){
68420 getCellInfo(pCur);
68421 if( pCur->info.nKey==intKey ){
@@ -68587,28 +68685,22 @@
68685 int rc;
68686 int idx;
68687 MemPage *pPage;
68688
68689 assert( cursorOwnsBtShared(pCur) );
 
68690 if( pCur->eState!=CURSOR_VALID ){
68691 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
68692 rc = restoreCursorPosition(pCur);
68693 if( rc!=SQLITE_OK ){
68694 return rc;
68695 }
68696 if( CURSOR_INVALID==pCur->eState ){
68697 return SQLITE_DONE;
68698 }
68699 if( pCur->eState==CURSOR_SKIPNEXT ){
 
68700 pCur->eState = CURSOR_VALID;
68701 if( pCur->skipNext>0 ) return SQLITE_OK;
 
 
 
 
68702 }
68703 }
68704
68705 pPage = pCur->pPage;
68706 idx = ++pCur->ix;
@@ -68659,11 +68751,10 @@
68751 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int flags){
68752 MemPage *pPage;
68753 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
68754 assert( cursorOwnsBtShared(pCur) );
68755 assert( flags==0 || flags==1 );
 
68756 pCur->info.nSize = 0;
68757 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
68758 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
68759 pPage = pCur->pPage;
68760 if( (++pCur->ix)>=pPage->nCell ){
@@ -68700,11 +68791,10 @@
68791 static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){
68792 int rc;
68793 MemPage *pPage;
68794
68795 assert( cursorOwnsBtShared(pCur) );
 
68796 assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
68797 assert( pCur->info.nSize==0 );
68798 if( pCur->eState!=CURSOR_VALID ){
68799 rc = restoreCursorPosition(pCur);
68800 if( rc!=SQLITE_OK ){
@@ -68711,18 +68801,13 @@
68801 return rc;
68802 }
68803 if( CURSOR_INVALID==pCur->eState ){
68804 return SQLITE_DONE;
68805 }
68806 if( CURSOR_SKIPNEXT==pCur->eState ){
 
68807 pCur->eState = CURSOR_VALID;
68808 if( pCur->skipNext<0 ) return SQLITE_OK;
 
 
 
 
68809 }
68810 }
68811
68812 pPage = pCur->pPage;
68813 assert( pPage->isInit );
@@ -68753,11 +68838,10 @@
68838 return rc;
68839 }
68840 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int flags){
68841 assert( cursorOwnsBtShared(pCur) );
68842 assert( flags==0 || flags==1 );
 
68843 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
68844 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
68845 pCur->info.nSize = 0;
68846 if( pCur->eState!=CURSOR_VALID
68847 || pCur->ix==0
@@ -69722,27 +69806,38 @@
69806 ** / | \
69807 ** --------- --------- ---------
69808 ** |Child-1| |Child-2| |Child-3|
69809 ** --------- --------- ---------
69810 **
69811 ** The order of cells is in the array is for an index btree is:
69812 **
69813 ** 1. All cells from Child-1 in order
69814 ** 2. The first divider cell from Parent
69815 ** 3. All cells from Child-2 in order
69816 ** 4. The second divider cell from Parent
69817 ** 5. All cells from Child-3 in order
69818 **
69819 ** For a table-btree (with rowids) the items 2 and 4 are empty because
69820 ** content exists only in leaves and there are no divider cells.
69821 **
69822 ** For an index btree, the apEnd[] array holds pointer to the end of page
69823 ** for Child-1, the Parent, Child-2, the Parent (again), and Child-3,
69824 ** respectively. The ixNx[] array holds the number of cells contained in
69825 ** each of these 5 stages, and all stages to the left. Hence:
69826 **
69827 ** ixNx[0] = Number of cells in Child-1.
69828 ** ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
69829 ** ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69830 ** ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
69831 ** ixNx[4] = Total number of cells.
69832 **
69833 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
69834 ** are used and they point to the leaf pages only, and the ixNx value are:
69835 **
69836 ** ixNx[0] = Number of cells in Child-1.
69837 ** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69838 ** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
69839 */
69840 typedef struct CellArray CellArray;
69841 struct CellArray {
69842 int nCell; /* Number of cells in apCell[] */
69843 MemPage *pRef; /* Reference page */
@@ -69808,20 +69903,21 @@
69903 const int hdr = pPg->hdrOffset; /* Offset of header on pPg */
69904 u8 * const aData = pPg->aData; /* Pointer to data for pPg */
69905 const int usableSize = pPg->pBt->usableSize;
69906 u8 * const pEnd = &aData[usableSize];
69907 int i = iFirst; /* Which cell to copy from pCArray*/
69908 u32 j; /* Start of cell content area */
69909 int iEnd = i+nCell; /* Loop terminator */
69910 u8 *pCellptr = pPg->aCellIdx;
69911 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
69912 u8 *pData;
69913 int k; /* Current slot in pCArray->apEnd[] */
69914 u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */
69915
69916 assert( i<iEnd );
69917 j = get2byte(&aData[hdr+5]);
69918 if( NEVER(j>(u32)usableSize) ){ j = 0; }
69919 memcpy(&pTmp[j], &aData[j], usableSize - j);
69920
69921 for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
69922 pSrcEnd = pCArray->apEnd[k];
69923
@@ -69997,11 +70093,11 @@
70093 }
70094 return nRet;
70095 }
70096
70097 /*
70098 ** pCArray contains pointers to and sizes of all cells in the page being
70099 ** balanced. The current page, pPg, has pPg->nCell cells starting with
70100 ** pCArray->apCell[iOld]. After balancing, this page should hold nNew cells
70101 ** starting at apCell[iNew].
70102 **
70103 ** This routine makes the necessary adjustments to pPg so that it contains
@@ -70031,26 +70127,31 @@
70127 u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
70128 memcpy(pTmp, aData, pPg->pBt->usableSize);
70129 #endif
70130
70131 /* Remove cells from the start and end of the page */
70132 assert( nCell>=0 );
70133 if( iOld<iNew ){
70134 int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
70135 if( nShift>nCell ) return SQLITE_CORRUPT_BKPT;
70136 memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
70137 nCell -= nShift;
70138 }
70139 if( iNewEnd < iOldEnd ){
70140 int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
70141 assert( nCell>=nTail );
70142 nCell -= nTail;
70143 }
70144
70145 pData = &aData[get2byteNotZero(&aData[hdr+5])];
70146 if( pData<pBegin ) goto editpage_fail;
70147
70148 /* Add cells to the start of the page */
70149 if( iNew<iOld ){
70150 int nAdd = MIN(nNew,iOld-iNew);
70151 assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
70152 assert( nAdd>=0 );
70153 pCellptr = pPg->aCellIdx;
70154 memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
70155 if( pageInsertArray(
70156 pPg, pBegin, &pData, pCellptr,
70157 iNew, nAdd, pCArray
@@ -70061,10 +70162,11 @@
70162 /* Add any overflow cells */
70163 for(i=0; i<pPg->nOverflow; i++){
70164 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70165 if( iCell>=0 && iCell<nNew ){
70166 pCellptr = &pPg->aCellIdx[iCell * 2];
70167 assert( nCell>=iCell );
70168 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70169 nCell++;
70170 if( pageInsertArray(
70171 pPg, pBegin, &pData, pCellptr,
70172 iCell+iNew, 1, pCArray
@@ -70071,10 +70173,11 @@
70173 ) ) goto editpage_fail;
70174 }
70175 }
70176
70177 /* Append cells to the end of the page */
70178 assert( nCell>=0 );
70179 pCellptr = &pPg->aCellIdx[nCell*2];
70180 if( pageInsertArray(
70181 pPg, pBegin, &pData, pCellptr,
70182 iNew+nCell, nNew-nCell, pCArray
70183 ) ) goto editpage_fail;
@@ -70644,16 +70747,19 @@
70747 ** the right of the i-th sibling page.
70748 ** usableSpace: Number of bytes of space available on each sibling.
70749 **
70750 */
70751 usableSpace = pBt->usableSize - 12 + leafCorrection;
70752 for(i=k=0; i<nOld; i++, k++){
70753 MemPage *p = apOld[i];
70754 b.apEnd[k] = p->aDataEnd;
70755 b.ixNx[k] = cntOld[i];
70756 if( !leafData ){
70757 k++;
70758 b.apEnd[k] = pParent->aDataEnd;
70759 b.ixNx[k] = cntOld[i]+1;
70760 }
70761 szNew[i] = usableSpace - p->nFree;
70762 for(j=0; j<p->nOverflow; j++){
70763 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70764 }
70765 cntNew[i] = cntOld[i];
@@ -71749,11 +71855,10 @@
71855 ** from the internal node. The 'previous' entry is used for this instead
71856 ** of the 'next' entry, as the previous entry is always a part of the
71857 ** sub-tree headed by the child page of the cell being deleted. This makes
71858 ** balancing the tree following the delete operation easier. */
71859 if( !pPage->leaf ){
 
71860 rc = sqlite3BtreePrevious(pCur, 0);
71861 assert( rc!=SQLITE_DONE );
71862 if( rc ) return rc;
71863 }
71864
@@ -75234,10 +75339,13 @@
75339 u32 amt, /* Number of bytes to return. */
75340 Mem *pMem /* OUT: Return data in this Mem structure. */
75341 ){
75342 int rc;
75343 pMem->flags = MEM_Null;
75344 if( sqlite3BtreeMaxRecordSize(pCur)<offset+amt ){
75345 return SQLITE_CORRUPT_BKPT;
75346 }
75347 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){
75348 rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
75349 if( rc==SQLITE_OK ){
75350 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
75351 pMem->flags = MEM_Blob;
@@ -97882,10 +97990,11 @@
97990 static void gatherSelectWindows(Select *p){
97991 Walker w;
97992 w.xExprCallback = gatherSelectWindowsCallback;
97993 w.xSelectCallback = gatherSelectWindowsSelectCallback;
97994 w.xSelectCallback2 = 0;
97995 w.pParse = 0;
97996 w.u.pSelect = p;
97997 sqlite3WalkSelect(&w, p);
97998 }
97999 #endif
98000
@@ -101504,18 +101613,20 @@
101613 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
101614 switch( pExpr->op ){
101615 case TK_ISNOT:
101616 case TK_NOT:
101617 case TK_ISNULL:
101618 case TK_NOTNULL:
101619 case TK_IS:
101620 case TK_OR:
101621 case TK_CASE:
101622 case TK_IN:
101623 case TK_FUNCTION:
101624 testcase( pExpr->op==TK_ISNOT );
101625 testcase( pExpr->op==TK_NOT );
101626 testcase( pExpr->op==TK_ISNULL );
101627 testcase( pExpr->op==TK_NOTNULL );
101628 testcase( pExpr->op==TK_IS );
101629 testcase( pExpr->op==TK_OR );
101630 testcase( pExpr->op==TK_CASE );
101631 testcase( pExpr->op==TK_IN );
101632 testcase( pExpr->op==TK_FUNCTION );
@@ -105728,12 +105839,12 @@
105839 return;
105840 }
105841 assert( pVfs );
105842 flags |= SQLITE_OPEN_MAIN_DB;
105843 rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
 
105844 db->nDb++;
105845 pNew->zDbSName = sqlite3DbStrDup(db, zName);
105846 }
105847 db->noSharedCache = 0;
105848 if( rc==SQLITE_CONSTRAINT ){
105849 rc = SQLITE_ERROR;
105850 zErrDyn = sqlite3MPrintf(db, "database is already attached");
@@ -105757,11 +105868,10 @@
105868 PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK));
105869 #endif
105870 sqlite3BtreeLeave(pNew->pBt);
105871 }
105872 pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1;
 
105873 if( rc==SQLITE_OK && pNew->zDbSName==0 ){
105874 rc = SQLITE_NOMEM_BKPT;
105875 }
105876
105877
@@ -105785,19 +105895,23 @@
105895 zKey = (char *)sqlite3_value_blob(argv[2]);
105896 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105897 break;
105898
105899 case SQLITE_NULL:
105900 /* No key specified. Use the key from URI filename, or if none,
105901 ** use the key from the main database. */
105902 if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){
105903 sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey);
105904 if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){
105905 rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey);
105906 }
105907 }
105908 break;
105909 }
105910 }
105911 #endif
105912 sqlite3_free( zPath );
105913
105914 /* If the file was opened successfully, read the schema for the new database.
105915 ** If this fails, or if opening the file failed, then close the file and
105916 ** remove the entry from the db->aDb[] array. i.e. put everything back the
105917 ** way we found it.
@@ -109965,21 +110079,26 @@
110079 assert( pParse->nErr==0 );
110080 if( db->init.busy ){
110081 Index *p;
110082 assert( !IN_SPECIAL_PARSE );
110083 assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
110084 if( pTblName!=0 ){
110085 pIndex->tnum = db->init.newTnum;
110086 if( sqlite3IndexHasDuplicateRootPage(pIndex) ){
110087 sqlite3ErrorMsg(pParse, "invalid rootpage");
110088 pParse->rc = SQLITE_CORRUPT_BKPT;
110089 goto exit_create_index;
110090 }
110091 }
110092 p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
110093 pIndex->zName, pIndex);
110094 if( p ){
110095 assert( p==pIndex ); /* Malloc must have failed */
110096 sqlite3OomFault(db);
110097 goto exit_create_index;
110098 }
110099 db->mDbFlags |= DBFLAG_SchemaChange;
 
 
 
110100 }
110101
110102 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
110103 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
110104 ** emit code to allocate the index rootpage on disk and make an entry for
@@ -110351,11 +110470,10 @@
110470
110471 /* Allocate additional space if needed */
110472 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110473 SrcList *pNew;
110474 int nAlloc = pSrc->nSrc*2+nExtra;
 
110475 sqlite3 *db = pParse->db;
110476
110477 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110478 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110479 SQLITE_MAX_SRCLIST);
@@ -110367,12 +110485,11 @@
110485 if( pNew==0 ){
110486 assert( db->mallocFailed );
110487 return 0;
110488 }
110489 pSrc = pNew;
110490 pSrc->nAlloc = nAlloc;
 
110491 }
110492
110493 /* Move existing slots that come after the newly inserted slots
110494 ** out of the way */
110495 for(i=pSrc->nSrc-1; i>=iStart; i--){
@@ -118554,11 +118671,11 @@
118671 if( zSql==0 ) zSql = "";
118672
118673 sqlite3_mutex_enter(db->mutex);
118674 sqlite3Error(db, SQLITE_OK);
118675 while( rc==SQLITE_OK && zSql[0] ){
118676 int nCol = 0;
118677 char **azVals = 0;
118678
118679 pStmt = 0;
118680 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
118681 assert( rc==SQLITE_OK || pStmt==0 );
@@ -118568,13 +118685,11 @@
118685 if( !pStmt ){
118686 /* this happens for a comment or white-space */
118687 zSql = zLeftover;
118688 continue;
118689 }
 
118690 callbackIsInit = 0;
 
118691
118692 while( 1 ){
118693 int i;
118694 rc = sqlite3_step(pStmt);
118695
@@ -118581,10 +118696,11 @@
118696 /* Invoke the callback function if required */
118697 if( xCallback && (SQLITE_ROW==rc ||
118698 (SQLITE_DONE==rc && !callbackIsInit
118699 && db->flags&SQLITE_NullCallback)) ){
118700 if( !callbackIsInit ){
118701 nCol = sqlite3_column_count(pStmt);
118702 azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*));
118703 if( azCols==0 ){
118704 goto exec_out;
118705 }
118706 for(i=0; i<nCol; i++){
@@ -120194,12 +120310,11 @@
120310 #define PragTyp_WAL_CHECKPOINT 39
120311 #define PragTyp_ACTIVATE_EXTENSIONS 40
120312 #define PragTyp_HEXKEY 41
120313 #define PragTyp_KEY 42
120314 #define PragTyp_LOCK_STATUS 43
120315 #define PragTyp_STATS 44
 
120316
120317 /* Property flags associated with various pragma. */
120318 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
120319 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
120320 #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
@@ -120356,26 +120471,22 @@
120471 /* ePragFlg: */ PragFlg_Result0,
120472 /* ColNames: */ 0, 0,
120473 /* iArg: */ 0 },
120474 #endif
120475 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120476 {/* zName: */ "count_changes",
120477 /* ePragTyp: */ PragTyp_FLAG,
120478 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120479 /* ColNames: */ 0, 0,
120480 /* iArg: */ SQLITE_CountRows },
120481 #endif
 
120482 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
 
120483 {/* zName: */ "data_store_directory",
120484 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
120485 /* ePragFlg: */ PragFlg_NoColumns1,
120486 /* ColNames: */ 0, 0,
120487 /* iArg: */ 0 },
 
120488 #endif
120489 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
120490 {/* zName: */ "data_version",
120491 /* ePragTyp: */ PragTyp_HEADER_VALUE,
120492 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
@@ -120387,18 +120498,16 @@
120498 /* ePragTyp: */ PragTyp_DATABASE_LIST,
120499 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
120500 /* ColNames: */ 35, 3,
120501 /* iArg: */ 0 },
120502 #endif
120503 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
 
120504 {/* zName: */ "default_cache_size",
120505 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
120506 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120507 /* ColNames: */ 45, 1,
120508 /* iArg: */ 0 },
 
120509 #endif
120510 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120511 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
120512 {/* zName: */ "defer_foreign_keys",
120513 /* ePragTyp: */ PragTyp_FLAG,
@@ -120406,17 +120515,15 @@
120515 /* ColNames: */ 0, 0,
120516 /* iArg: */ SQLITE_DeferFKs },
120517 #endif
120518 #endif
120519 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120520 {/* zName: */ "empty_result_callbacks",
120521 /* ePragTyp: */ PragTyp_FLAG,
120522 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120523 /* ColNames: */ 0, 0,
120524 /* iArg: */ SQLITE_NullCallback },
 
120525 #endif
120526 #if !defined(SQLITE_OMIT_UTF16)
120527 {/* zName: */ "encoding",
120528 /* ePragTyp: */ PragTyp_ENCODING,
120529 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
@@ -120452,19 +120559,15 @@
120559 /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0,
120560 /* ColNames: */ 0, 0,
120561 /* iArg: */ BTREE_FREE_PAGE_COUNT },
120562 #endif
120563 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120564 {/* zName: */ "full_column_names",
120565 /* ePragTyp: */ PragTyp_FLAG,
120566 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120567 /* ColNames: */ 0, 0,
120568 /* iArg: */ SQLITE_FullColNames },
 
 
 
120569 {/* zName: */ "fullfsync",
120570 /* ePragTyp: */ PragTyp_FLAG,
120571 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120572 /* ColNames: */ 0, 0,
120573 /* iArg: */ SQLITE_FullFSync },
@@ -120618,16 +120721,18 @@
120721 /* ePragTyp: */ PragTyp_PAGE_SIZE,
120722 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
120723 /* ColNames: */ 0, 0,
120724 /* iArg: */ 0 },
120725 #endif
120726 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
120727 #if defined(SQLITE_DEBUG)
120728 {/* zName: */ "parser_trace",
120729 /* ePragTyp: */ PragTyp_FLAG,
120730 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120731 /* ColNames: */ 0, 0,
120732 /* iArg: */ SQLITE_ParserTrace },
120733 #endif
120734 #endif
120735 #if defined(SQLITE_INTROSPECTION_PRAGMAS)
120736 {/* zName: */ "pragma_list",
120737 /* ePragTyp: */ PragTyp_PRAGMA_LIST,
120738 /* ePragFlg: */ PragFlg_Result0,
@@ -120687,17 +120792,15 @@
120792 /* ePragFlg: */ PragFlg_Result0,
120793 /* ColNames: */ 0, 0,
120794 /* iArg: */ 0 },
120795 #endif
120796 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
 
120797 {/* zName: */ "short_column_names",
120798 /* ePragTyp: */ PragTyp_FLAG,
120799 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120800 /* ColNames: */ 0, 0,
120801 /* iArg: */ SQLITE_ShortColNames },
 
120802 #endif
120803 {/* zName: */ "shrink_memory",
120804 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
120805 /* ePragFlg: */ PragFlg_NoColumns,
120806 /* ColNames: */ 0, 0,
@@ -120746,19 +120849,15 @@
120849 {/* zName: */ "temp_store",
120850 /* ePragTyp: */ PragTyp_TEMP_STORE,
120851 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
120852 /* ColNames: */ 0, 0,
120853 /* iArg: */ 0 },
 
 
 
120854 {/* zName: */ "temp_store_directory",
120855 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
120856 /* ePragFlg: */ PragFlg_NoColumns1,
120857 /* ColNames: */ 0, 0,
120858 /* iArg: */ 0 },
 
120859 #endif
120860 #if defined(SQLITE_HAS_CODEC)
120861 {/* zName: */ "textkey",
120862 /* ePragTyp: */ PragTyp_KEY,
120863 /* ePragFlg: */ 0,
@@ -122225,23 +122324,10 @@
122324 }
122325 break;
122326 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
122327 #endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
122328
 
 
 
 
 
 
 
 
 
 
 
 
 
122329 /* Reinstall the LIKE and GLOB functions. The variant of LIKE
122330 ** used will be case sensitive or not depending on the RHS.
122331 */
122332 case PragTyp_CASE_SENSITIVE_LIKE: {
122333 if( zRight ){
@@ -123358,10 +123444,23 @@
123444 if( zExtra && zExtra[0] ) z = sqlite3MPrintf(db, "%z - %s", z, zExtra);
123445 *pData->pzErrMsg = z;
123446 pData->rc = SQLITE_CORRUPT_BKPT;
123447 }
123448 }
123449
123450 /*
123451 ** Check to see if any sibling index (another index on the same table)
123452 ** of pIndex has the same root page number, and if it does, return true.
123453 ** This would indicate a corrupt schema.
123454 */
123455 SQLITE_PRIVATE int sqlite3IndexHasDuplicateRootPage(Index *pIndex){
123456 Index *p;
123457 for(p=pIndex->pTable->pIndex; p; p=p->pNext){
123458 if( p->tnum==pIndex->tnum && p!=pIndex ) return 1;
123459 }
123460 return 0;
123461 }
123462
123463 /*
123464 ** This is the callback routine for the code that initializes the
123465 ** database. See sqlite3Init() below for additional information.
123466 ** This routine is also called from the OP_ParseSchema opcode of the VDBE.
@@ -123437,10 +123536,11 @@
123536 Index *pIndex;
123537 pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zDbSName);
123538 if( pIndex==0
123539 || sqlite3GetInt32(argv[1],&pIndex->tnum)==0
123540 || pIndex->tnum<2
123541 || sqlite3IndexHasDuplicateRootPage(pIndex)
123542 ){
123543 corruptSchema(pData, argv[0], pIndex?"invalid rootpage":"orphan index");
123544 }
123545 }
123546 return 0;
@@ -129976,10 +130076,11 @@
130076 ){
130077 continue;
130078 }
130079
130080 if( flattenSubquery(pParse, p, i, isAgg) ){
130081 if( pParse->nErr ) goto select_end;
130082 /* This subquery can be absorbed into its parent. */
130083 i = -1;
130084 }
130085 pTabList = p->pSrc;
130086 if( db->mallocFailed ) goto select_end;
@@ -134903,10 +135004,11 @@
135004 for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){
135005 VTable *pVTab = db->aVTrans[i];
135006 const sqlite3_module *pMod = pVTab->pMod->pModule;
135007 if( pVTab->pVtab && pMod->iVersion>=2 ){
135008 int (*xMethod)(sqlite3_vtab *, int);
135009 sqlite3VtabLock(pVTab);
135010 switch( op ){
135011 case SAVEPOINT_BEGIN:
135012 xMethod = pMod->xSavepoint;
135013 pVTab->iSavepoint = iSavepoint+1;
135014 break;
@@ -134918,10 +135020,11 @@
135020 break;
135021 }
135022 if( xMethod && pVTab->iSavepoint>iSavepoint ){
135023 rc = xMethod(pVTab->pVtab, iSavepoint);
135024 }
135025 sqlite3VtabUnlock(pVTab);
135026 }
135027 }
135028 }
135029 return rc;
135030 }
@@ -137496,12 +137599,17 @@
137599 ** Do not do this for the RHS of a LEFT JOIN. This is because the
137600 ** expression may be evaluated after OP_NullRow has been executed on
137601 ** the cursor. In this case it is important to do the full evaluation,
137602 ** as the result of the expression may not be NULL, even if all table
137603 ** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a
137604 **
137605 ** Also, do not do this when processing one index an a multi-index
137606 ** OR clause, since the transformation will become invalid once we
137607 ** move forward to the next index.
137608 ** https://sqlite.org/src/info/4e8e4857d32d401f
137609 */
137610 if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137611 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137612 }
137613
137614 /* Record the instruction used to terminate the loop. */
137615 if( pLoop->wsFlags & WHERE_ONEROW ){
@@ -139887,10 +139995,21 @@
139995 k = 0;
139996 pScan->iEquiv++;
139997 }
139998 return 0;
139999 }
140000
140001 /*
140002 ** This is whereScanInit() for the case of an index on an expression.
140003 ** It is factored out into a separate tail-recursion subroutine so that
140004 ** the normal whereScanInit() routine, which is a high-runner, does not
140005 ** need to push registers onto the stack as part of its prologue.
140006 */
140007 static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){
140008 pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr);
140009 return whereScanNext(pScan);
140010 }
140011
140012 /*
140013 ** Initialize a WHERE clause scanner object. Return a pointer to the
140014 ** first match. Return NULL if there are no matches.
140015 **
@@ -139920,31 +140039,33 @@
140039 pScan->pOrigWC = pWC;
140040 pScan->pWC = pWC;
140041 pScan->pIdxExpr = 0;
140042 pScan->idxaff = 0;
140043 pScan->zCollName = 0;
140044 pScan->opMask = opMask;
140045 pScan->k = 0;
140046 pScan->aiCur[0] = iCur;
140047 pScan->nEquiv = 1;
140048 pScan->iEquiv = 1;
140049 if( pIdx ){
140050 int j = iColumn;
140051 iColumn = pIdx->aiColumn[j];
140052 if( iColumn==XN_EXPR ){
140053 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
140054 pScan->zCollName = pIdx->azColl[j];
140055 pScan->aiColumn[0] = XN_EXPR;
140056 return whereScanInitIndexExpr(pScan);
140057 }else if( iColumn==pIdx->pTable->iPKey ){
140058 iColumn = XN_ROWID;
140059 }else if( iColumn>=0 ){
140060 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
140061 pScan->zCollName = pIdx->azColl[j];
140062 }
140063 }else if( iColumn==XN_EXPR ){
140064 return 0;
140065 }
 
 
 
140066 pScan->aiColumn[0] = iColumn;
 
 
140067 return whereScanNext(pScan);
140068 }
140069
140070 /*
140071 ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
@@ -152900,11 +153021,18 @@
153021 db->u1.isInterrupted = 0;
153022 }
153023 pParse->rc = SQLITE_OK;
153024 pParse->zTail = zSql;
153025 assert( pzErrMsg!=0 );
153026 #ifdef SQLITE_DEBUG
153027 if( db->flags & SQLITE_ParserTrace ){
153028 printf("parser: [[[%s]]]\n", zSql);
153029 sqlite3ParserTrace(stdout, "parser: ");
153030 }else{
153031 sqlite3ParserTrace(0, 0);
153032 }
153033 #endif
153034 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153035 pEngine = &sEngine;
153036 sqlite3ParserInit(pEngine, pParse);
153037 #else
153038 pEngine = sqlite3ParserAlloc(sqlite3Malloc, pParse);
@@ -153068,11 +153196,11 @@
153196 ){
153197 sqlite3 *db; /* The database connection */
153198 int i; /* Next unread byte of zSql[] */
153199 int n; /* length of current token */
153200 int tokenType; /* type of current token */
153201 int prevType = 0; /* Previous non-whitespace token */
153202 int nParen; /* Number of nested levels of parentheses */
153203 int iStartIN; /* Start of RHS of IN operator in z[] */
153204 int nParenAtIN; /* Value of nParent at start of RHS of IN operator */
153205 int j; /* Bytes of normalized SQL generated so far */
153206 sqlite3_str *pStr; /* The normalized SQL string under construction */
@@ -154223,10 +154351,17 @@
154351 sqlite3GlobalConfig.szSorterRef = (u32)iVal;
154352 break;
154353 }
154354 #endif /* SQLITE_ENABLE_SORTER_REFERENCES */
154355
154356 #ifdef SQLITE_ENABLE_DESERIALIZE
154357 case SQLITE_CONFIG_MEMDB_MAXSIZE: {
154358 sqlite3GlobalConfig.mxMemdbSize = va_arg(ap, sqlite3_int64);
154359 break;
154360 }
154361 #endif /* SQLITE_ENABLE_DESERIALIZE */
154362
154363 default: {
154364 rc = SQLITE_ERROR;
154365 break;
154366 }
154367 }
@@ -156505,10 +156640,44 @@
156640 *pFlags = flags;
156641 *pzFile = zFile;
156642 return rc;
156643 }
156644
156645 #if defined(SQLITE_HAS_CODEC)
156646 /*
156647 ** Process URI filename query parameters relevant to the SQLite Encryption
156648 ** Extension. Return true if any of the relevant query parameters are
156649 ** seen and return false if not.
156650 */
156651 SQLITE_PRIVATE int sqlite3CodecQueryParameters(
156652 sqlite3 *db, /* Database connection */
156653 const char *zDb, /* Which schema is being created/attached */
156654 const char *zUri /* URI filename */
156655 ){
156656 const char *zKey;
156657 if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){
156658 u8 iByte;
156659 int i;
156660 char zDecoded[40];
156661 for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
156662 iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
156663 if( (i&1)!=0 ) zDecoded[i/2] = iByte;
156664 }
156665 sqlite3_key_v2(db, zDb, zDecoded, i/2);
156666 return 1;
156667 }else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){
156668 sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey));
156669 return 1;
156670 }else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){
156671 sqlite3_key_v2(db, zDb, zKey, -1);
156672 return 1;
156673 }else{
156674 return 0;
156675 }
156676 }
156677 #endif
156678
156679
156680 /*
156681 ** This routine does the work of opening a database on behalf of
156682 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
156683 ** is UTF-8 encoded.
@@ -156850,29 +157019,16 @@
157019 void *pArg = sqlite3GlobalConfig.pSqllogArg;
157020 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
157021 }
157022 #endif
157023 #if defined(SQLITE_HAS_CODEC)
157024 if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157025 #endif
157026 sqlite3_free(zOpen);
157027 return rc & 0xff;
157028 }
157029
157030
157031 /*
157032 ** Open a new database handle.
157033 */
157034 SQLITE_API int sqlite3_open(
@@ -161990,10 +162146,11 @@
162146 */
162147 pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
162148 pTS->anOutput[0] = nDoclist;
162149 if( pTS->aaOutput[0] ){
162150 memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
162151 memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
162152 }else{
162153 return SQLITE_NOMEM;
162154 }
162155 }else{
162156 char *aMerge = aDoclist;
@@ -165603,19 +165760,19 @@
165760 if( iEq>=0 || iGe>=0 ){
165761 const unsigned char *zStr = sqlite3_value_text(apVal[0]);
165762 assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
165763 if( zStr ){
165764 pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
 
165765 if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
165766 pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
165767 }
165768 }
165769
165770 if( iLe>=0 ){
165771 pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
 
165772 if( pCsr->zStop==0 ) return SQLITE_NOMEM;
165773 pCsr->nStop = (int)strlen(pCsr->zStop);
165774 }
165775
165776 if( iLangid>=0 ){
165777 iLangVal = sqlite3_value_int(apVal[iLangid]);
165778
@@ -175488,15 +175645,18 @@
175645 assert( rc==SQLITE_OK || pCsr==0 );
175646 if( pCsr ){
175647 int iFirst = 0;
175648 pPhrase->pList = pCsr;
175649 fts3GetDeltaPosition(&pCsr, &iFirst);
175650 if( iFirst<0 ){
175651 rc = FTS_CORRUPT_VTAB;
175652 }else{
175653 pPhrase->pHead = pCsr;
175654 pPhrase->pTail = pCsr;
175655 pPhrase->iHead = iFirst;
175656 pPhrase->iTail = iFirst;
175657 }
175658 }else{
175659 assert( rc!=SQLITE_OK || (
175660 pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0
175661 ));
175662 }
@@ -202679,11 +202839,13 @@
202839 int iAdj;
202840 int nScore;
202841 int jj;
202842
202843 rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
202844 if( ic!=i ) continue;
202845 if( io>nDocsize ) rc = FTS5_CORRUPT;
202846 if( rc!=SQLITE_OK ) continue;
202847 memset(aSeen, 0, nPhrase);
202848 rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
202849 io, nToken, &nScore, &iAdj
202850 );
202851 if( rc==SQLITE_OK && nScore>nBestScore ){
@@ -209352,11 +209514,11 @@
209514 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
209515 int iOff = pIter->iLeafOffset; /* Offset to read at */
209516 int nNew; /* Bytes of new data */
209517
209518 iOff += fts5GetVarint32(&a[iOff], nNew);
209519 if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
209520 p->rc = FTS5_CORRUPT;
209521 return;
209522 }
209523 pIter->term.n = nKeep;
209524 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
@@ -210026,11 +210188,11 @@
210188 }while( 1 );
210189 }
210190
210191 search_success:
210192 pIter->iLeafOffset = iOff + nNew;
210193 if( pIter->iLeafOffset>n || nNew<1 ){
210194 p->rc = FTS5_CORRUPT;
210195 return;
210196 }
210197 pIter->iTermLeafOffset = pIter->iLeafOffset;
210198 pIter->iTermLeafPgno = pIter->iLeafPgno;
@@ -210804,11 +210966,12 @@
210966 Fts5Index *p,
210967 Fts5SegIter *pSeg,
210968 Fts5Colset *pColset,
210969 Fts5Buffer *pBuf
210970 ){
210971 if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
210972 memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
210973 if( pColset==0 ){
210974 fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
210975 }else{
210976 if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){
210977 PoslistCallbackCtx sCtx;
@@ -211845,11 +212008,11 @@
212008 Fts5Data *pData;
212009 int iId = pSeg->pSeg->iSegid;
212010 u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
212011
212012 iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
212013 pData = fts5LeafRead(p, iLeafRowid);
212014 if( pData ){
212015 if( iOff>pData->szLeaf ){
212016 /* This can occur if the pages that the segments occupy overlap - if
212017 ** a single page has been assigned to more than one segment. In
212018 ** this case a prior iteration of this loop may have corrupted the
@@ -212251,10 +212414,11 @@
212414 if( writer.bFirstRowidInPage ){
212415 fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */
212416 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
212417 writer.bFirstRowidInPage = 0;
212418 fts5WriteDlidxAppend(p, &writer, iRowid);
212419 if( p->rc!=SQLITE_OK ) break;
212420 }else{
212421 pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
212422 }
212423 assert( pBuf->n<=pBuf->nSpace );
212424
@@ -212482,15 +212646,17 @@
212646 i64 iDelta,
212647 Fts5Iter *pMulti,
212648 Fts5Buffer *pBuf
212649 ){
212650 int nData = pMulti->base.nData;
212651 int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
212652 assert( nData>0 );
212653 if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
212654 fts5BufferSafeAppendVarint(pBuf, iDelta);
212655 fts5BufferSafeAppendVarint(pBuf, nData*2);
212656 fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData);
212657 memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
212658 }
212659 }
212660
212661
212662 static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
@@ -212700,11 +212866,11 @@
212866 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
212867 }
212868 sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
212869 if( iPos1<0 ) break;
212870 }else{
212871 assert_nc( iPos2!=iPrev );
212872 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
212873 sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
212874 if( iPos2<0 ) break;
212875 }
212876 }
@@ -214126,10 +214292,14 @@
214292 fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
214293
214294 /* Decode any more doclist data that appears on the page before the
214295 ** first term. */
214296 nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff;
214297 if( nDoclist+iOff>n ){
214298 rc = FTS5_CORRUPT;
214299 goto decode_out;
214300 }
214301 fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist);
214302
214303 while( iPgidxOff<n && rc==SQLITE_OK ){
214304 int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */
214305 int nByte; /* Bytes of data */
@@ -214544,11 +214714,11 @@
214714 p->ts.iSavepoint = iSavepoint-1;
214715 break;
214716
214717 case FTS5_ROLLBACKTO:
214718 assert( p->ts.eState==1 );
214719 assert( iSavepoint>=-1 );
214720 assert( iSavepoint<=p->ts.iSavepoint );
214721 p->ts.iSavepoint = iSavepoint;
214722 break;
214723 }
214724 }
@@ -215964,11 +216134,13 @@
216134 const char **pz,
216135 int *pn
216136 ){
216137 int rc = SQLITE_OK;
216138 Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
216139 if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab))
216140 || pCsr->ePlan==FTS5_PLAN_SPECIAL
216141 ){
216142 *pz = 0;
216143 *pn = 0;
216144 }else{
216145 rc = fts5SeekCursor(pCsr, 0);
216146 if( rc==SQLITE_OK ){
@@ -216902,11 +217074,11 @@
217074 int nArg, /* Number of args */
217075 sqlite3_value **apUnused /* Function arguments */
217076 ){
217077 assert( nArg==0 );
217078 UNUSED_PARAM2(nArg, apUnused);
217079 sqlite3_result_text(pCtx, "fts5: 2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd", -1, SQLITE_TRANSIENT);
217080 }
217081
217082 /*
217083 ** Return true if zName is the extension on one of the shadow tables used
217084 ** by this module.
@@ -221072,10 +221244,11 @@
221244 }else{
221245 const char *zTerm;
221246 int nTerm;
221247
221248 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
221249 assert( nTerm>=0 );
221250 if( pCsr->nLeTerm>=0 ){
221251 int nCmp = MIN(nTerm, pCsr->nLeTerm);
221252 int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
221253 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
221254 pCsr->bEof = 1;
@@ -221665,12 +221838,12 @@
221838 }
221839 #endif /* SQLITE_CORE */
221840 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221841
221842 /************** End of stmt.c ************************************************/
221843 #if __LINE__!=221843
221844 #undef SQLITE_SOURCE_ID
221845 #define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959alt2"
221846 #endif
221847 /* Return the source-id for this library */
221848 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221849 /************************** End of sqlite3.c ******************************/
221850
+17 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121121
**
122122
** See also: [sqlite3_libversion()],
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126
-#define SQLITE_VERSION "3.27.0"
127
-#define SQLITE_VERSION_NUMBER 3027000
128
-#define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
126
+#define SQLITE_VERSION "3.27.1"
127
+#define SQLITE_VERSION_NUMBER 3027001
128
+#define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1980,10 +1980,21 @@
19801980
** from the database as records are returned in sorted order. The default
19811981
** value for this option is to never use this optimization. Specifying a
19821982
** negative value for this option restores the default behaviour.
19831983
** This option is only available if SQLite is compiled with the
19841984
** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
1985
+**
1986
+** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
1987
+** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
1988
+** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
1989
+** [sqlite3_int64] parameter which is the default maximum size for an in-memory
1990
+** database created using [sqlite3_deserialize()]. This default maximum
1991
+** size can be adjusted up or down for individual databases using the
1992
+** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
1993
+** configuration setting is never used, then the default maximum is determined
1994
+** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
1995
+** compile-time option is not set, then the default maximum is 1073741824.
19851996
** </dl>
19861997
*/
19871998
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
19881999
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
19892000
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2010,10 +2021,11 @@
20102021
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
20112022
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
20122023
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
20132024
#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
20142025
#define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2026
+#define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
20152027
20162028
/*
20172029
** CAPI3REF: Database Connection Configuration Options
20182030
**
20192031
** These constants are the available integer configuration options that
@@ -3415,10 +3427,12 @@
34153427
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
34163428
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
34173429
** is not a database file pathname pointer that SQLite passed into the xOpen
34183430
** VFS method, then the behavior of this routine is undefined and probably
34193431
** undesirable.
3432
+**
3433
+** See the [URI filename] documentation for additional information.
34203434
*/
34213435
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
34223436
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
34233437
SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
34243438
34253439
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.27.0"
127 #define SQLITE_VERSION_NUMBER 3027000
128 #define SQLITE_SOURCE_ID "2019-01-27 02:45:32 9cf8ebd141aa2eb661d457624c76433bd9e4abfdef04aa52e28bc169172calt1"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1980,10 +1980,21 @@
1980 ** from the database as records are returned in sorted order. The default
1981 ** value for this option is to never use this optimization. Specifying a
1982 ** negative value for this option restores the default behaviour.
1983 ** This option is only available if SQLite is compiled with the
1984 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
 
 
 
 
 
 
 
 
 
 
 
1985 ** </dl>
1986 */
1987 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1988 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1989 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2010,10 +2021,11 @@
2010 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2011 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2012 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2013 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2014 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
 
2015
2016 /*
2017 ** CAPI3REF: Database Connection Configuration Options
2018 **
2019 ** These constants are the available integer configuration options that
@@ -3415,10 +3427,12 @@
3415 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3416 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3417 ** is not a database file pathname pointer that SQLite passed into the xOpen
3418 ** VFS method, then the behavior of this routine is undefined and probably
3419 ** undesirable.
 
 
3420 */
3421 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3422 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3423 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3424
3425
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.27.1"
127 #define SQLITE_VERSION_NUMBER 3027001
128 #define SQLITE_SOURCE_ID "2019-02-08 13:17:39 0eca3dd3d38b31c92b49ca2d311128b74584714d9e7de895b1a6286ef959a1dd"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1980,10 +1980,21 @@
1980 ** from the database as records are returned in sorted order. The default
1981 ** value for this option is to never use this optimization. Specifying a
1982 ** negative value for this option restores the default behaviour.
1983 ** This option is only available if SQLite is compiled with the
1984 ** [SQLITE_ENABLE_SORTER_REFERENCES] compile-time option.
1985 **
1986 ** [[SQLITE_CONFIG_MEMDB_MAXSIZE]]
1987 ** <dt>SQLITE_CONFIG_MEMDB_MAXSIZE
1988 ** <dd>The SQLITE_CONFIG_MEMDB_MAXSIZE option accepts a single parameter
1989 ** [sqlite3_int64] parameter which is the default maximum size for an in-memory
1990 ** database created using [sqlite3_deserialize()]. This default maximum
1991 ** size can be adjusted up or down for individual databases using the
1992 ** [SQLITE_FCNTL_SIZE_LIMIT] [sqlite3_file_control|file-control]. If this
1993 ** configuration setting is never used, then the default maximum is determined
1994 ** by the [SQLITE_MEMDB_DEFAULT_MAXSIZE] compile-time option. If that
1995 ** compile-time option is not set, then the default maximum is 1073741824.
1996 ** </dl>
1997 */
1998 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1999 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2000 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
@@ -2010,10 +2021,11 @@
2021 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2022 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2023 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2024 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2025 #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */
2026 #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */
2027
2028 /*
2029 ** CAPI3REF: Database Connection Configuration Options
2030 **
2031 ** These constants are the available integer configuration options that
@@ -3415,10 +3427,12 @@
3427 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3428 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3429 ** is not a database file pathname pointer that SQLite passed into the xOpen
3430 ** VFS method, then the behavior of this routine is undefined and probably
3431 ** undesirable.
3432 **
3433 ** See the [URI filename] documentation for additional information.
3434 */
3435 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3436 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3437 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3438
3439
+16 -7
--- src/style.c
+++ src/style.c
@@ -389,14 +389,11 @@
389389
*/
390390
static char zDfltHeader[] =
391391
@ <html>
392392
@ <head>
393393
@ <base href="$baseurl/$current_page" />
394
-@ <meta http-equiv="Content-Security-Policy" \
395
-@ content="default-src 'self' data: ; \
396
-@ script-src 'self' 'nonce-$<nonce>' ;\
397
-@ style-src 'self' 'unsafe-inline'" />
394
+@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
398395
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
399396
@ <title>$<project_name>: $<title></title>
400397
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
401398
@ href="$home/timeline.rss" />
402399
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" \
@@ -407,11 +404,23 @@
407404
408405
/*
409406
** Initialize all the default TH1 variables
410407
*/
411408
static void style_init_th1_vars(const char *zTitle){
412
- Th_Store("nonce", style_nonce());
409
+ const char *zNonce = style_nonce();
410
+ /*
411
+ ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
412
+ ** allows it to be properly overridden via the TH1 setup script (i.e. it
413
+ ** is evaluated before the header is rendered).
414
+ */
415
+ char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
416
+ "script-src 'self' 'nonce-%s' ; "
417
+ "style-src 'self' 'unsafe-inline'",
418
+ zNonce);
419
+ Th_MaybeStore("default_csp", zDfltCsp);
420
+ sqlite3_free(zDfltCsp);
421
+ Th_Store("nonce", zNonce);
413422
Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
414423
Th_Store("project_description", db_get("project-description",""));
415424
if( zTitle ) Th_Store("title", zTitle);
416425
Th_Store("baseurl", g.zBaseURL);
417426
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
@@ -1031,11 +1040,11 @@
10311040
int showAll;
10321041
char *zErr = 0;
10331042
int isAuth = 0;
10341043
char zCap[100];
10351044
static const char *const azCgiVars[] = {
1036
- "COMSPEC", "DOCUMENT_ROOT", "GATEWAY_INTERFACE",
1045
+ "COMSPEC", "DOCUMENT_ROOT", "GATEWAY_INTERFACE", "SCGI",
10371046
"HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET", "HTTP_ACCEPT_ENCODING",
10381047
"HTTP_ACCEPT_LANGUAGE", "HTTP_AUTHENICATION",
10391048
"HTTP_CONNECTION", "HTTP_HOST",
10401049
"HTTP_IF_NONE_MATCH", "HTTP_IF_MODIFIED_SINCE",
10411050
"HTTP_USER_AGENT", "HTTP_REFERER", "PATH_INFO", "PATH_TRANSLATED",
@@ -1045,11 +1054,11 @@
10451054
"HOME", "FOSSIL_HOME", "USERNAME", "USER", "FOSSIL_USER",
10461055
"SQLITE_TMPDIR", "TMPDIR",
10471056
"TEMP", "TMP", "FOSSIL_VFS",
10481057
"FOSSIL_FORCE_TICKET_MODERATION", "FOSSIL_FORCE_WIKI_MODERATION",
10491058
"FOSSIL_TCL_PATH", "TH1_DELETE_INTERP", "TH1_ENABLE_DOCS",
1050
- "TH1_ENABLE_HOOKS", "TH1_ENABLE_TCL", "REMOTE_HOST"
1059
+ "TH1_ENABLE_HOOKS", "TH1_ENABLE_TCL", "REMOTE_HOST",
10511060
};
10521061
10531062
login_check_credentials();
10541063
if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
10551064
isAuth = 1;
10561065
--- src/style.c
+++ src/style.c
@@ -389,14 +389,11 @@
389 */
390 static char zDfltHeader[] =
391 @ <html>
392 @ <head>
393 @ <base href="$baseurl/$current_page" />
394 @ <meta http-equiv="Content-Security-Policy" \
395 @ content="default-src 'self' data: ; \
396 @ script-src 'self' 'nonce-$<nonce>' ;\
397 @ style-src 'self' 'unsafe-inline'" />
398 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
399 @ <title>$<project_name>: $<title></title>
400 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
401 @ href="$home/timeline.rss" />
402 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" \
@@ -407,11 +404,23 @@
407
408 /*
409 ** Initialize all the default TH1 variables
410 */
411 static void style_init_th1_vars(const char *zTitle){
412 Th_Store("nonce", style_nonce());
 
 
 
 
 
 
 
 
 
 
 
 
413 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
414 Th_Store("project_description", db_get("project-description",""));
415 if( zTitle ) Th_Store("title", zTitle);
416 Th_Store("baseurl", g.zBaseURL);
417 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
@@ -1031,11 +1040,11 @@
1031 int showAll;
1032 char *zErr = 0;
1033 int isAuth = 0;
1034 char zCap[100];
1035 static const char *const azCgiVars[] = {
1036 "COMSPEC", "DOCUMENT_ROOT", "GATEWAY_INTERFACE",
1037 "HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET", "HTTP_ACCEPT_ENCODING",
1038 "HTTP_ACCEPT_LANGUAGE", "HTTP_AUTHENICATION",
1039 "HTTP_CONNECTION", "HTTP_HOST",
1040 "HTTP_IF_NONE_MATCH", "HTTP_IF_MODIFIED_SINCE",
1041 "HTTP_USER_AGENT", "HTTP_REFERER", "PATH_INFO", "PATH_TRANSLATED",
@@ -1045,11 +1054,11 @@
1045 "HOME", "FOSSIL_HOME", "USERNAME", "USER", "FOSSIL_USER",
1046 "SQLITE_TMPDIR", "TMPDIR",
1047 "TEMP", "TMP", "FOSSIL_VFS",
1048 "FOSSIL_FORCE_TICKET_MODERATION", "FOSSIL_FORCE_WIKI_MODERATION",
1049 "FOSSIL_TCL_PATH", "TH1_DELETE_INTERP", "TH1_ENABLE_DOCS",
1050 "TH1_ENABLE_HOOKS", "TH1_ENABLE_TCL", "REMOTE_HOST"
1051 };
1052
1053 login_check_credentials();
1054 if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
1055 isAuth = 1;
1056
--- src/style.c
+++ src/style.c
@@ -389,14 +389,11 @@
389 */
390 static char zDfltHeader[] =
391 @ <html>
392 @ <head>
393 @ <base href="$baseurl/$current_page" />
394 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
 
 
 
395 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
396 @ <title>$<project_name>: $<title></title>
397 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
398 @ href="$home/timeline.rss" />
399 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" \
@@ -407,11 +404,23 @@
404
405 /*
406 ** Initialize all the default TH1 variables
407 */
408 static void style_init_th1_vars(const char *zTitle){
409 const char *zNonce = style_nonce();
410 /*
411 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
412 ** allows it to be properly overridden via the TH1 setup script (i.e. it
413 ** is evaluated before the header is rendered).
414 */
415 char *zDfltCsp = sqlite3_mprintf("default-src 'self' data: ; "
416 "script-src 'self' 'nonce-%s' ; "
417 "style-src 'self' 'unsafe-inline'",
418 zNonce);
419 Th_MaybeStore("default_csp", zDfltCsp);
420 sqlite3_free(zDfltCsp);
421 Th_Store("nonce", zNonce);
422 Th_Store("project_name", db_get("project-name","Unnamed Fossil Project"));
423 Th_Store("project_description", db_get("project-description",""));
424 if( zTitle ) Th_Store("title", zTitle);
425 Th_Store("baseurl", g.zBaseURL);
426 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
@@ -1031,11 +1040,11 @@
1040 int showAll;
1041 char *zErr = 0;
1042 int isAuth = 0;
1043 char zCap[100];
1044 static const char *const azCgiVars[] = {
1045 "COMSPEC", "DOCUMENT_ROOT", "GATEWAY_INTERFACE", "SCGI",
1046 "HTTP_ACCEPT", "HTTP_ACCEPT_CHARSET", "HTTP_ACCEPT_ENCODING",
1047 "HTTP_ACCEPT_LANGUAGE", "HTTP_AUTHENICATION",
1048 "HTTP_CONNECTION", "HTTP_HOST",
1049 "HTTP_IF_NONE_MATCH", "HTTP_IF_MODIFIED_SINCE",
1050 "HTTP_USER_AGENT", "HTTP_REFERER", "PATH_INFO", "PATH_TRANSLATED",
@@ -1045,11 +1054,11 @@
1054 "HOME", "FOSSIL_HOME", "USERNAME", "USER", "FOSSIL_USER",
1055 "SQLITE_TMPDIR", "TMPDIR",
1056 "TEMP", "TMP", "FOSSIL_VFS",
1057 "FOSSIL_FORCE_TICKET_MODERATION", "FOSSIL_FORCE_WIKI_MODERATION",
1058 "FOSSIL_TCL_PATH", "TH1_DELETE_INTERP", "TH1_ENABLE_DOCS",
1059 "TH1_ENABLE_HOOKS", "TH1_ENABLE_TCL", "REMOTE_HOST",
1060 };
1061
1062 login_check_credentials();
1063 if( g.perm.Admin || g.perm.Setup || db_get_boolean("test_env_enable",0) ){
1064 isAuth = 1;
1065
+4 -2
--- src/tag.c
+++ src/tag.c
@@ -359,11 +359,13 @@
359359
}else{
360360
nrid = content_put(&ctrl);
361361
manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
362362
}
363363
assert( blob_is_reset(&ctrl) );
364
- manifest_to_disk(rid);
364
+ if( g.localOpen ){
365
+ manifest_to_disk(rid);
366
+ }
365367
}
366368
367369
/*
368370
** COMMAND: tag
369371
**
@@ -633,14 +635,14 @@
633635
char *zUuid;
634636
int dryRun = 0;
635637
const char *zDateOvrd; /* The change time on the control artifact */
636638
const char *zUserOvrd; /* The user name on the control artifact */
637639
638
- db_must_be_within_tree();
639640
if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
640641
zDateOvrd = find_option("date-override",0,1);
641642
zUserOvrd = find_option("user-override",0,1);
643
+ db_find_and_open_repository(0, 0);
642644
verify_all_options();
643645
if( g.argc<4 ){
644646
usage("[OPTIONS] CHECK-IN PARENT ...");
645647
}
646648
rid = name_to_typed_rid(g.argv[2], "ci");
647649
--- src/tag.c
+++ src/tag.c
@@ -359,11 +359,13 @@
359 }else{
360 nrid = content_put(&ctrl);
361 manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
362 }
363 assert( blob_is_reset(&ctrl) );
364 manifest_to_disk(rid);
 
 
365 }
366
367 /*
368 ** COMMAND: tag
369 **
@@ -633,14 +635,14 @@
633 char *zUuid;
634 int dryRun = 0;
635 const char *zDateOvrd; /* The change time on the control artifact */
636 const char *zUserOvrd; /* The user name on the control artifact */
637
638 db_must_be_within_tree();
639 if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
640 zDateOvrd = find_option("date-override",0,1);
641 zUserOvrd = find_option("user-override",0,1);
 
642 verify_all_options();
643 if( g.argc<4 ){
644 usage("[OPTIONS] CHECK-IN PARENT ...");
645 }
646 rid = name_to_typed_rid(g.argv[2], "ci");
647
--- src/tag.c
+++ src/tag.c
@@ -359,11 +359,13 @@
359 }else{
360 nrid = content_put(&ctrl);
361 manifest_crosslink(nrid, &ctrl, MC_PERMIT_HOOKS);
362 }
363 assert( blob_is_reset(&ctrl) );
364 if( g.localOpen ){
365 manifest_to_disk(rid);
366 }
367 }
368
369 /*
370 ** COMMAND: tag
371 **
@@ -633,14 +635,14 @@
635 char *zUuid;
636 int dryRun = 0;
637 const char *zDateOvrd; /* The change time on the control artifact */
638 const char *zUserOvrd; /* The user name on the control artifact */
639
 
640 if( find_option("dryrun","n",0)!=0 ) dryRun = TAG_ADD_DRYRUN;
641 zDateOvrd = find_option("date-override",0,1);
642 zUserOvrd = find_option("user-override",0,1);
643 db_find_and_open_repository(0, 0);
644 verify_all_options();
645 if( g.argc<4 ){
646 usage("[OPTIONS] CHECK-IN PARENT ...");
647 }
648 rid = name_to_typed_rid(g.argv[2], "ci");
649
--- src/th_main.c
+++ src/th_main.c
@@ -411,10 +411,30 @@
411411
}
412412
}
413413
Th_SetResult(interp, "file name not found in manifest", -1);
414414
return 0;
415415
}
416
+
417
+/*
418
+** TH1 command: nonce
419
+**
420
+** Returns the value of the cryptographic nonce for the request being
421
+** processed.
422
+*/
423
+static int nonceCmd(
424
+ Th_Interp *interp,
425
+ void *pConvert,
426
+ int argc,
427
+ const char **argv,
428
+ int *argl
429
+){
430
+ if( argc!=1 ){
431
+ return Th_WrongNumArgs(interp, "nonce");
432
+ }
433
+ Th_SetResult(interp, style_nonce(), -1);
434
+ return TH_OK;
435
+}
416436
417437
/*
418438
** TH1 command: puts STRING
419439
** TH1 command: html STRING
420440
**
@@ -2021,10 +2041,11 @@
20212041
{"htmlize", htmlizeCmd, 0},
20222042
{"http", httpCmd, 0},
20232043
{"insertCsrf", insertCsrfCmd, 0},
20242044
{"linecount", linecntCmd, 0},
20252045
{"markdown", markdownCmd, 0},
2046
+ {"nonce", nonceCmd, 0},
20262047
{"puts", putsCmd, (void*)&aFlags[1]},
20272048
{"query", queryCmd, 0},
20282049
{"randhex", randhexCmd, 0},
20292050
{"redirect", redirectCmd, 0},
20302051
{"regexp", regexpCmd, 0},
@@ -2104,10 +2125,24 @@
21042125
}
21052126
}
21062127
g.th1Flags &= ~TH_INIT_MASK;
21072128
g.th1Flags |= (flags & TH_INIT_MASK);
21082129
}
2130
+
2131
+/*
2132
+** Store a string value in a variable in the interpreter if the variable
2133
+** does not already exist.
2134
+*/
2135
+void Th_MaybeStore(const char *zName, const char *zValue){
2136
+ Th_FossilInit(TH_INIT_DEFAULT);
2137
+ if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){
2138
+ if( g.thTrace ){
2139
+ Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue);
2140
+ }
2141
+ Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
2142
+ }
2143
+}
21092144
21102145
/*
21112146
** Store a string value in a variable in the interpreter.
21122147
*/
21132148
void Th_Store(const char *zName, const char *zValue){
21142149
--- src/th_main.c
+++ src/th_main.c
@@ -411,10 +411,30 @@
411 }
412 }
413 Th_SetResult(interp, "file name not found in manifest", -1);
414 return 0;
415 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
417 /*
418 ** TH1 command: puts STRING
419 ** TH1 command: html STRING
420 **
@@ -2021,10 +2041,11 @@
2021 {"htmlize", htmlizeCmd, 0},
2022 {"http", httpCmd, 0},
2023 {"insertCsrf", insertCsrfCmd, 0},
2024 {"linecount", linecntCmd, 0},
2025 {"markdown", markdownCmd, 0},
 
2026 {"puts", putsCmd, (void*)&aFlags[1]},
2027 {"query", queryCmd, 0},
2028 {"randhex", randhexCmd, 0},
2029 {"redirect", redirectCmd, 0},
2030 {"regexp", regexpCmd, 0},
@@ -2104,10 +2125,24 @@
2104 }
2105 }
2106 g.th1Flags &= ~TH_INIT_MASK;
2107 g.th1Flags |= (flags & TH_INIT_MASK);
2108 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2109
2110 /*
2111 ** Store a string value in a variable in the interpreter.
2112 */
2113 void Th_Store(const char *zName, const char *zValue){
2114
--- src/th_main.c
+++ src/th_main.c
@@ -411,10 +411,30 @@
411 }
412 }
413 Th_SetResult(interp, "file name not found in manifest", -1);
414 return 0;
415 }
416
417 /*
418 ** TH1 command: nonce
419 **
420 ** Returns the value of the cryptographic nonce for the request being
421 ** processed.
422 */
423 static int nonceCmd(
424 Th_Interp *interp,
425 void *pConvert,
426 int argc,
427 const char **argv,
428 int *argl
429 ){
430 if( argc!=1 ){
431 return Th_WrongNumArgs(interp, "nonce");
432 }
433 Th_SetResult(interp, style_nonce(), -1);
434 return TH_OK;
435 }
436
437 /*
438 ** TH1 command: puts STRING
439 ** TH1 command: html STRING
440 **
@@ -2021,10 +2041,11 @@
2041 {"htmlize", htmlizeCmd, 0},
2042 {"http", httpCmd, 0},
2043 {"insertCsrf", insertCsrfCmd, 0},
2044 {"linecount", linecntCmd, 0},
2045 {"markdown", markdownCmd, 0},
2046 {"nonce", nonceCmd, 0},
2047 {"puts", putsCmd, (void*)&aFlags[1]},
2048 {"query", queryCmd, 0},
2049 {"randhex", randhexCmd, 0},
2050 {"redirect", redirectCmd, 0},
2051 {"regexp", regexpCmd, 0},
@@ -2104,10 +2125,24 @@
2125 }
2126 }
2127 g.th1Flags &= ~TH_INIT_MASK;
2128 g.th1Flags |= (flags & TH_INIT_MASK);
2129 }
2130
2131 /*
2132 ** Store a string value in a variable in the interpreter if the variable
2133 ** does not already exist.
2134 */
2135 void Th_MaybeStore(const char *zName, const char *zValue){
2136 Th_FossilInit(TH_INIT_DEFAULT);
2137 if( zValue && !Th_ExistsVar(g.interp, zName, -1) ){
2138 if( g.thTrace ){
2139 Th_Trace("maybe_set %h {%h}<br />\n", zName, zValue);
2140 }
2141 Th_SetVar(g.interp, zName, -1, zValue, strlen(zValue));
2142 }
2143 }
2144
2145 /*
2146 ** Store a string value in a variable in the interpreter.
2147 */
2148 void Th_Store(const char *zName, const char *zValue){
2149
+7 -7
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -98,11 +98,11 @@
9898
# include <windows.h>
9999
# ifndef TCL_DIRECTORY_SEP
100100
# define TCL_DIRECTORY_SEP '\\'
101101
# endif
102102
# ifndef TCL_LIBRARY_NAME
103
-# define TCL_LIBRARY_NAME "tcl86.dll\0"
103
+# define TCL_LIBRARY_NAME "tcl87.dll\0"
104104
# endif
105105
# ifndef TCL_MINOR_OFFSET
106106
# define TCL_MINOR_OFFSET (4)
107107
# endif
108108
# ifndef dlopen
@@ -119,32 +119,32 @@
119119
# ifndef TCL_DIRECTORY_SEP
120120
# define TCL_DIRECTORY_SEP '/'
121121
# endif
122122
# if defined(__CYGWIN__)
123123
# ifndef TCL_LIBRARY_NAME
124
-# define TCL_LIBRARY_NAME "libtcl8.6.dll\0"
124
+# define TCL_LIBRARY_NAME "libtcl8.7.dll\0"
125125
# endif
126126
# ifndef TCL_MINOR_OFFSET
127127
# define TCL_MINOR_OFFSET (8)
128128
# endif
129129
# elif defined(__APPLE__)
130130
# ifndef TCL_LIBRARY_NAME
131
-# define TCL_LIBRARY_NAME "libtcl8.6.dylib\0"
131
+# define TCL_LIBRARY_NAME "libtcl8.7.dylib\0"
132132
# endif
133133
# ifndef TCL_MINOR_OFFSET
134134
# define TCL_MINOR_OFFSET (8)
135135
# endif
136136
# elif defined(__FreeBSD__)
137137
# ifndef TCL_LIBRARY_NAME
138
-# define TCL_LIBRARY_NAME "libtcl86.so\0"
138
+# define TCL_LIBRARY_NAME "libtcl87.so\0"
139139
# endif
140140
# ifndef TCL_MINOR_OFFSET
141141
# define TCL_MINOR_OFFSET (7)
142142
# endif
143143
# else
144144
# ifndef TCL_LIBRARY_NAME
145
-# define TCL_LIBRARY_NAME "libtcl8.6.so\0"
145
+# define TCL_LIBRARY_NAME "libtcl8.7.so\0"
146146
# endif
147147
# ifndef TCL_MINOR_OFFSET
148148
# define TCL_MINOR_OFFSET (8)
149149
# endif
150150
# endif /* defined(__CYGWIN__) */
@@ -1010,11 +1010,11 @@
10101010
TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
10111011
Tcl_DecrRefCount(objPtr); objPtr = 0;
10121012
if( !resultObjPtr ){
10131013
return TCL_ERROR;
10141014
}
1015
- objPtr = Tcl_NewIntObj(argc - 1);
1015
+ objPtr = Tcl_NewWideIntObj(argc - 1);
10161016
Tcl_IncrRefCount(objPtr);
10171017
resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
10181018
TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
10191019
Tcl_DecrRefCount(objPtr); objPtr = 0;
10201020
if( !resultObjPtr ){
@@ -1192,11 +1192,11 @@
11921192
Tcl_CallWhenDeleted(tclInterp, Th1DeleteProc, interp);
11931193
Tcl_CreateObjCommand(tclInterp, "th1Eval", Th1EvalObjCmd, interp, NULL);
11941194
Tcl_CreateObjCommand(tclInterp, "th1Expr", Th1ExprObjCmd, interp, NULL);
11951195
/* If necessary, evaluate the custom Tcl setup script. */
11961196
setup = tclContext->setup;
1197
- if( setup && Tcl_Eval(tclInterp, setup)!=TCL_OK ){
1197
+ if( setup && Tcl_EvalEx(tclInterp, setup, -1, 0)!=TCL_OK ){
11981198
Th_ErrorMessage(interp,
11991199
"Tcl setup script error:", Tcl_GetStringResult(tclInterp), -1);
12001200
Tcl_DeleteInterp(tclInterp);
12011201
tclContext->interp = tclInterp = 0;
12021202
return TH_ERROR;
12031203
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -98,11 +98,11 @@
98 # include <windows.h>
99 # ifndef TCL_DIRECTORY_SEP
100 # define TCL_DIRECTORY_SEP '\\'
101 # endif
102 # ifndef TCL_LIBRARY_NAME
103 # define TCL_LIBRARY_NAME "tcl86.dll\0"
104 # endif
105 # ifndef TCL_MINOR_OFFSET
106 # define TCL_MINOR_OFFSET (4)
107 # endif
108 # ifndef dlopen
@@ -119,32 +119,32 @@
119 # ifndef TCL_DIRECTORY_SEP
120 # define TCL_DIRECTORY_SEP '/'
121 # endif
122 # if defined(__CYGWIN__)
123 # ifndef TCL_LIBRARY_NAME
124 # define TCL_LIBRARY_NAME "libtcl8.6.dll\0"
125 # endif
126 # ifndef TCL_MINOR_OFFSET
127 # define TCL_MINOR_OFFSET (8)
128 # endif
129 # elif defined(__APPLE__)
130 # ifndef TCL_LIBRARY_NAME
131 # define TCL_LIBRARY_NAME "libtcl8.6.dylib\0"
132 # endif
133 # ifndef TCL_MINOR_OFFSET
134 # define TCL_MINOR_OFFSET (8)
135 # endif
136 # elif defined(__FreeBSD__)
137 # ifndef TCL_LIBRARY_NAME
138 # define TCL_LIBRARY_NAME "libtcl86.so\0"
139 # endif
140 # ifndef TCL_MINOR_OFFSET
141 # define TCL_MINOR_OFFSET (7)
142 # endif
143 # else
144 # ifndef TCL_LIBRARY_NAME
145 # define TCL_LIBRARY_NAME "libtcl8.6.so\0"
146 # endif
147 # ifndef TCL_MINOR_OFFSET
148 # define TCL_MINOR_OFFSET (8)
149 # endif
150 # endif /* defined(__CYGWIN__) */
@@ -1010,11 +1010,11 @@
1010 TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
1011 Tcl_DecrRefCount(objPtr); objPtr = 0;
1012 if( !resultObjPtr ){
1013 return TCL_ERROR;
1014 }
1015 objPtr = Tcl_NewIntObj(argc - 1);
1016 Tcl_IncrRefCount(objPtr);
1017 resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
1018 TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
1019 Tcl_DecrRefCount(objPtr); objPtr = 0;
1020 if( !resultObjPtr ){
@@ -1192,11 +1192,11 @@
1192 Tcl_CallWhenDeleted(tclInterp, Th1DeleteProc, interp);
1193 Tcl_CreateObjCommand(tclInterp, "th1Eval", Th1EvalObjCmd, interp, NULL);
1194 Tcl_CreateObjCommand(tclInterp, "th1Expr", Th1ExprObjCmd, interp, NULL);
1195 /* If necessary, evaluate the custom Tcl setup script. */
1196 setup = tclContext->setup;
1197 if( setup && Tcl_Eval(tclInterp, setup)!=TCL_OK ){
1198 Th_ErrorMessage(interp,
1199 "Tcl setup script error:", Tcl_GetStringResult(tclInterp), -1);
1200 Tcl_DeleteInterp(tclInterp);
1201 tclContext->interp = tclInterp = 0;
1202 return TH_ERROR;
1203
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -98,11 +98,11 @@
98 # include <windows.h>
99 # ifndef TCL_DIRECTORY_SEP
100 # define TCL_DIRECTORY_SEP '\\'
101 # endif
102 # ifndef TCL_LIBRARY_NAME
103 # define TCL_LIBRARY_NAME "tcl87.dll\0"
104 # endif
105 # ifndef TCL_MINOR_OFFSET
106 # define TCL_MINOR_OFFSET (4)
107 # endif
108 # ifndef dlopen
@@ -119,32 +119,32 @@
119 # ifndef TCL_DIRECTORY_SEP
120 # define TCL_DIRECTORY_SEP '/'
121 # endif
122 # if defined(__CYGWIN__)
123 # ifndef TCL_LIBRARY_NAME
124 # define TCL_LIBRARY_NAME "libtcl8.7.dll\0"
125 # endif
126 # ifndef TCL_MINOR_OFFSET
127 # define TCL_MINOR_OFFSET (8)
128 # endif
129 # elif defined(__APPLE__)
130 # ifndef TCL_LIBRARY_NAME
131 # define TCL_LIBRARY_NAME "libtcl8.7.dylib\0"
132 # endif
133 # ifndef TCL_MINOR_OFFSET
134 # define TCL_MINOR_OFFSET (8)
135 # endif
136 # elif defined(__FreeBSD__)
137 # ifndef TCL_LIBRARY_NAME
138 # define TCL_LIBRARY_NAME "libtcl87.so\0"
139 # endif
140 # ifndef TCL_MINOR_OFFSET
141 # define TCL_MINOR_OFFSET (7)
142 # endif
143 # else
144 # ifndef TCL_LIBRARY_NAME
145 # define TCL_LIBRARY_NAME "libtcl8.7.so\0"
146 # endif
147 # ifndef TCL_MINOR_OFFSET
148 # define TCL_MINOR_OFFSET (8)
149 # endif
150 # endif /* defined(__CYGWIN__) */
@@ -1010,11 +1010,11 @@
1010 TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
1011 Tcl_DecrRefCount(objPtr); objPtr = 0;
1012 if( !resultObjPtr ){
1013 return TCL_ERROR;
1014 }
1015 objPtr = Tcl_NewWideIntObj(argc - 1);
1016 Tcl_IncrRefCount(objPtr);
1017 resultObjPtr = Tcl_SetVar2Ex(pInterp, "argc", NULL, objPtr,
1018 TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG);
1019 Tcl_DecrRefCount(objPtr); objPtr = 0;
1020 if( !resultObjPtr ){
@@ -1192,11 +1192,11 @@
1192 Tcl_CallWhenDeleted(tclInterp, Th1DeleteProc, interp);
1193 Tcl_CreateObjCommand(tclInterp, "th1Eval", Th1EvalObjCmd, interp, NULL);
1194 Tcl_CreateObjCommand(tclInterp, "th1Expr", Th1ExprObjCmd, interp, NULL);
1195 /* If necessary, evaluate the custom Tcl setup script. */
1196 setup = tclContext->setup;
1197 if( setup && Tcl_EvalEx(tclInterp, setup, -1, 0)!=TCL_OK ){
1198 Th_ErrorMessage(interp,
1199 "Tcl setup script error:", Tcl_GetStringResult(tclInterp), -1);
1200 Tcl_DeleteInterp(tclInterp);
1201 tclContext->interp = tclInterp = 0;
1202 return TH_ERROR;
1203
+1 -1
--- src/wiki.c
+++ src/wiki.c
@@ -761,11 +761,11 @@
761761
@ <input type="submit" name="edit-markup" value="Markup Editor"
762762
@ onclick='return confirm("Switching to markup-mode\nwill erase your WYSIWYG\nedits. Continue?")' />
763763
}
764764
login_insert_csrf_secret();
765765
if( havePreview ){
766
- if( zBody[0] ){
766
+ if( isWysiwyg || zBody[0] ){
767767
@ <input type="submit" name="submit" value="Apply These Changes" />
768768
}else{
769769
@ <input type="submit" name="submit" value="Delete This Wiki Page" />
770770
}
771771
}
772772
--- src/wiki.c
+++ src/wiki.c
@@ -761,11 +761,11 @@
761 @ <input type="submit" name="edit-markup" value="Markup Editor"
762 @ onclick='return confirm("Switching to markup-mode\nwill erase your WYSIWYG\nedits. Continue?")' />
763 }
764 login_insert_csrf_secret();
765 if( havePreview ){
766 if( zBody[0] ){
767 @ <input type="submit" name="submit" value="Apply These Changes" />
768 }else{
769 @ <input type="submit" name="submit" value="Delete This Wiki Page" />
770 }
771 }
772
--- src/wiki.c
+++ src/wiki.c
@@ -761,11 +761,11 @@
761 @ <input type="submit" name="edit-markup" value="Markup Editor"
762 @ onclick='return confirm("Switching to markup-mode\nwill erase your WYSIWYG\nedits. Continue?")' />
763 }
764 login_insert_csrf_secret();
765 if( havePreview ){
766 if( isWysiwyg || zBody[0] ){
767 @ <input type="submit" name="submit" value="Apply These Changes" />
768 }else{
769 @ <input type="submit" name="submit" value="Delete This Wiki Page" />
770 }
771 }
772
+2 -3
--- test/th1.test
+++ test/th1.test
@@ -1032,21 +1032,20 @@
10321032
protOut "Sorted: $sorted_result"
10331033
set base_commands {anoncap anycap array artifact break breakpoint catch\
10341034
cgiHeaderLine checkout combobox continue date decorate dir enable_output \
10351035
encode64 error expr for getParameter glob_match globalState hascap \
10361036
hasfeature html htmlize http httpize if info insertCsrf lindex linecount \
1037
- list llength lsearch markdown proc puts query randhex redirect regexp\
1038
- reinitialize rename render repository return searchable set\
1037
+ list llength lsearch markdown nonce proc puts query randhex redirect\
1038
+ regexp reinitialize rename render repository return searchable set\
10391039
setParameter setting stime string styleFooter styleHeader styleScript\
10401040
tclReady trace unset unversioned uplevel upvar utime verifyCsrf wiki}
10411041
set tcl_commands {tclEval tclExpr tclInvoke tclIsSafe tclMakeSafe}
10421042
if {$th1Tcl} {
10431043
test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands $tcl_commands"]}
10441044
} else {
10451045
test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands"]}
10461046
}
1047
-
10481047
10491048
###############################################################################
10501049
10511050
fossil test-th-eval "info vars"
10521051
10531052
--- test/th1.test
+++ test/th1.test
@@ -1032,21 +1032,20 @@
1032 protOut "Sorted: $sorted_result"
1033 set base_commands {anoncap anycap array artifact break breakpoint catch\
1034 cgiHeaderLine checkout combobox continue date decorate dir enable_output \
1035 encode64 error expr for getParameter glob_match globalState hascap \
1036 hasfeature html htmlize http httpize if info insertCsrf lindex linecount \
1037 list llength lsearch markdown proc puts query randhex redirect regexp\
1038 reinitialize rename render repository return searchable set\
1039 setParameter setting stime string styleFooter styleHeader styleScript\
1040 tclReady trace unset unversioned uplevel upvar utime verifyCsrf wiki}
1041 set tcl_commands {tclEval tclExpr tclInvoke tclIsSafe tclMakeSafe}
1042 if {$th1Tcl} {
1043 test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands $tcl_commands"]}
1044 } else {
1045 test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands"]}
1046 }
1047
1048
1049 ###############################################################################
1050
1051 fossil test-th-eval "info vars"
1052
1053
--- test/th1.test
+++ test/th1.test
@@ -1032,21 +1032,20 @@
1032 protOut "Sorted: $sorted_result"
1033 set base_commands {anoncap anycap array artifact break breakpoint catch\
1034 cgiHeaderLine checkout combobox continue date decorate dir enable_output \
1035 encode64 error expr for getParameter glob_match globalState hascap \
1036 hasfeature html htmlize http httpize if info insertCsrf lindex linecount \
1037 list llength lsearch markdown nonce proc puts query randhex redirect\
1038 regexp reinitialize rename render repository return searchable set\
1039 setParameter setting stime string styleFooter styleHeader styleScript\
1040 tclReady trace unset unversioned uplevel upvar utime verifyCsrf wiki}
1041 set tcl_commands {tclEval tclExpr tclInvoke tclIsSafe tclMakeSafe}
1042 if {$th1Tcl} {
1043 test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands $tcl_commands"]}
1044 } else {
1045 test th1-info-commands-1 {$sorted_result eq [lsort "$base_commands"]}
1046 }
 
1047
1048 ###############################################################################
1049
1050 fossil test-th-eval "info vars"
1051
1052
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,9 +1,14 @@
11
<title>Change Log</title>
22
3
+<a name='v2_9'></a>
4
+<h2>Changes for Version 2.9 (pending)</h2>
5
+
6
+ * Improved handling of relative hyperlinks on the /artifact page
7
+
38
<a name='v2_8'></a>
4
-<h2>Changes for Version 2.8 (pending)</h2>
9
+<h2>Changes for Version 2.8 (2019-02-20)</h2>
510
611
* Show cherry-pick merges as dotted lines on the timeline graph.
712
&rarr; The "fossil rebuild" command must be run to create and
813
populate the new "cherrypick" table in the repository in order
914
for this feature to operate.
@@ -23,10 +28,12 @@
2328
Write Trusted permission ('4') to users as they are approving a
2429
forum post by that user.
2530
* When running a bisect, report the number of check-ins still in
2631
the search range and the estimated number of bisect steps remaining.
2732
Do this at each step of the bisect.
33
+ * Provide a permanent link to a bisect timeline using the bid= query
34
+ parameter.
2835
* Make the chronological forum display feature available to all users,
2936
and make it the default format on mobile devices.
3037
* Break out Wiki setup into a separate /setup_wiki page, accessible
3138
on the standard menus through Admin/Wiki.
3239
* Add "Next" and "Previous" buttons on the /wdiff page, allowing
@@ -59,11 +66,11 @@
5966
* Detect when the repository used by a checkout is swapped out for
6067
a clone that uses different RID values, and make appropriate adjustments
6168
to the checkout database to avoid any problems.
6269
* Add the backoffice-disable setting to completely disable the
6370
backoffice feature.
64
- * Update the built-in SQLite to version 3.27.0 alpha.
71
+ * Update the built-in SQLite to version 3.27.1.
6572
* Various other small enhancements to webpages and documentation.
6673
6774
6875
<a name='v2_7'></a>
6976
<h2>Changes for Version 2.7 (2018-09-22)</h2>
7077
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,9 +1,14 @@
1 <title>Change Log</title>
2
 
 
 
 
 
3 <a name='v2_8'></a>
4 <h2>Changes for Version 2.8 (pending)</h2>
5
6 * Show cherry-pick merges as dotted lines on the timeline graph.
7 &rarr; The "fossil rebuild" command must be run to create and
8 populate the new "cherrypick" table in the repository in order
9 for this feature to operate.
@@ -23,10 +28,12 @@
23 Write Trusted permission ('4') to users as they are approving a
24 forum post by that user.
25 * When running a bisect, report the number of check-ins still in
26 the search range and the estimated number of bisect steps remaining.
27 Do this at each step of the bisect.
 
 
28 * Make the chronological forum display feature available to all users,
29 and make it the default format on mobile devices.
30 * Break out Wiki setup into a separate /setup_wiki page, accessible
31 on the standard menus through Admin/Wiki.
32 * Add "Next" and "Previous" buttons on the /wdiff page, allowing
@@ -59,11 +66,11 @@
59 * Detect when the repository used by a checkout is swapped out for
60 a clone that uses different RID values, and make appropriate adjustments
61 to the checkout database to avoid any problems.
62 * Add the backoffice-disable setting to completely disable the
63 backoffice feature.
64 * Update the built-in SQLite to version 3.27.0 alpha.
65 * Various other small enhancements to webpages and documentation.
66
67
68 <a name='v2_7'></a>
69 <h2>Changes for Version 2.7 (2018-09-22)</h2>
70
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,9 +1,14 @@
1 <title>Change Log</title>
2
3 <a name='v2_9'></a>
4 <h2>Changes for Version 2.9 (pending)</h2>
5
6 * Improved handling of relative hyperlinks on the /artifact page
7
8 <a name='v2_8'></a>
9 <h2>Changes for Version 2.8 (2019-02-20)</h2>
10
11 * Show cherry-pick merges as dotted lines on the timeline graph.
12 &rarr; The "fossil rebuild" command must be run to create and
13 populate the new "cherrypick" table in the repository in order
14 for this feature to operate.
@@ -23,10 +28,12 @@
28 Write Trusted permission ('4') to users as they are approving a
29 forum post by that user.
30 * When running a bisect, report the number of check-ins still in
31 the search range and the estimated number of bisect steps remaining.
32 Do this at each step of the bisect.
33 * Provide a permanent link to a bisect timeline using the bid= query
34 parameter.
35 * Make the chronological forum display feature available to all users,
36 and make it the default format on mobile devices.
37 * Break out Wiki setup into a separate /setup_wiki page, accessible
38 on the standard menus through Admin/Wiki.
39 * Add "Next" and "Previous" buttons on the /wdiff page, allowing
@@ -59,11 +66,11 @@
66 * Detect when the repository used by a checkout is swapped out for
67 a clone that uses different RID values, and make appropriate adjustments
68 to the checkout database to avoid any problems.
69 * Add the backoffice-disable setting to completely disable the
70 backoffice feature.
71 * Update the built-in SQLite to version 3.27.1.
72 * Various other small enhancements to webpages and documentation.
73
74
75 <a name='v2_7'></a>
76 <h2>Changes for Version 2.7 (2018-09-22)</h2>
77
--- www/customskin.md
+++ www/customskin.md
@@ -233,10 +233,16 @@
233233
* **current_page** - The name of the page currently being processed,
234234
without the leading "/" and without query parameters.
235235
Examples: "timeline", "doc/trunk/README.txt", "wiki".
236236
237237
* **csrf_token** - A token used to prevent cross-site request forgery.
238
+
239
+ * **default_csp** - The content to be used within the default header
240
+ for the "Content-Security-Policy" meta tag.
241
+
242
+ * **nonce** - The value of the cryptographic nonce for the request
243
+ being processed.
238244
239245
* **release_version** - The release version of Fossil. Ex: "1.31"
240246
241247
* **manifest_version** - A prefix on the check-in hash of the
242248
specific version of fossil that is running. Ex: "\[47bb6432a1\]"
243249
--- www/customskin.md
+++ www/customskin.md
@@ -233,10 +233,16 @@
233 * **current_page** - The name of the page currently being processed,
234 without the leading "/" and without query parameters.
235 Examples: "timeline", "doc/trunk/README.txt", "wiki".
236
237 * **csrf_token** - A token used to prevent cross-site request forgery.
 
 
 
 
 
 
238
239 * **release_version** - The release version of Fossil. Ex: "1.31"
240
241 * **manifest_version** - A prefix on the check-in hash of the
242 specific version of fossil that is running. Ex: "\[47bb6432a1\]"
243
--- www/customskin.md
+++ www/customskin.md
@@ -233,10 +233,16 @@
233 * **current_page** - The name of the page currently being processed,
234 without the leading "/" and without query parameters.
235 Examples: "timeline", "doc/trunk/README.txt", "wiki".
236
237 * **csrf_token** - A token used to prevent cross-site request forgery.
238
239 * **default_csp** - The content to be used within the default header
240 for the "Content-Security-Policy" meta tag.
241
242 * **nonce** - The value of the cryptographic nonce for the request
243 being processed.
244
245 * **release_version** - The release version of Fossil. Ex: "1.31"
246
247 * **manifest_version** - A prefix on the check-in hash of the
248 specific version of fossil that is running. Ex: "\[47bb6432a1\]"
249
+32 -24
--- www/ssl.wiki
+++ www/ssl.wiki
@@ -25,16 +25,20 @@
2525
is to say, you can build it against [https://www.openssl.org/|the
2626
OpenSSL library], which will allow it to clone and sync with a remote
2727
Fossil repository via <tt>https</tt> URIs.
2828
2929
30
-<h3 id="openssl-bin">Building Against a Binary Version of OpenSSL</h3>
30
+<h3 id="openssl-bin">Building Against OpenSSL Automatically</h3>
3131
3232
The <tt>configure</tt> script will attempt to find OpenSSL on your
33
-system automatically. If it can't find the files it needs, the most
34
-common solution is to install the OpenSSL development package on your
35
-system via your OS's package manager. Examples:
33
+system automatically. It first tries asking the <tt>pkg-config</tt>
34
+system where the OpenSSL development files are, and if that fails, it
35
+falls back to looking through a list of likely directories.
36
+
37
+If it can't find the files it needs, the most common solution is to
38
+install the OpenSSL development package on your system via your OS's
39
+package manager. Examples:
3640
3741
* <b>RHEL & Fedora</b>: <tt>sudo yum install openssl-devel</tt>
3842
* <b>Debian & Ubuntu</b>: <tt>sudo apt install libssl-dev</tt>
3943
* <b>FreeBSD</b>: <tt>su -c 'pkg install openssl'</tt>
4044
* <b>macOS</b>: <tt>sudo brew install openssl</tt>
@@ -54,35 +58,39 @@
5458
5559
5660
<h3 id="openssl-src">Building Against a Non-Platform Version of
5761
OpenSSL</h3>
5862
59
-The Fossil build system can also use OpenSSL when installed in
60
-nonstandard locations.
61
-
62
-If you've installed OpenSSL via a method that Fossil's build system
63
-cannot find on its own, you can clue it in by passing the
64
-<tt>--with-openssl</tt> option to the <tt>configure</tt> script. Type
65
-<tt>./configure --help</tt> for details.
66
-
67
-It is possible for the Fossil build system to find a functioning version
68
-of OpenSSL which is nevertheless unsuitable. One common case is that
69
-your OS is sufficiently outdated that the platform version of OpenSSL
70
-can no longer communicate with remote systems adhering to the latest
71
-advice on secure communications. Your local OpenSSL might not support
72
-any of the [https://en.wikipedia.org/wiki/Cipher_suite|cipher suites]
73
-the remote Fossil repository's HTTPS proxy is willing to offer, for
74
-example, so that even though both sides are speaking a variant of
75
-TLS/SSL, they can't come to an agreement on the cryptography.
76
-
77
-In such cases, you may want to link Fossil to a version of OpenSSL built
78
-from source. The easiest way to do that is:
63
+The Fossil build system has a few other methods for finding OpenSSL when
64
+the automatic methods fail or when you'd prefer that Fossil use a
65
+different version of OpenSSL than the one Fossil's build system picks on
66
+its own.
67
+
68
+A good reason to do this is when the Fossil build system finds a
69
+functioning version of OpenSSL which is nevertheless unsuitable. One
70
+common case is that your OS is sufficiently outdated that the platform
71
+version of OpenSSL can no longer communicate with remote systems
72
+adhering to the latest advice on secure communications. An old OpenSSL
73
+might not support any of the
74
+[https://en.wikipedia.org/wiki/Cipher_suite|cipher suites] the remote
75
+Fossil repository's HTTPS proxy is willing to offer, for example, so
76
+that even though both sides are speaking a variant of TLS/SSL, the peers
77
+cannot come to an agreement on the cryptography.
78
+
79
+If you've installed the OpenSSL development files somewhere that
80
+Fossil's build system cannot find on its own, you can clue it in by
81
+passing the <tt>--with-openssl</tt> option to the <tt>configure</tt>
82
+script. Type <tt>./configure --help</tt> for details.
83
+
84
+Another option is to download the source code to OpenSSL and build
85
+Fossil against that private version of OpenSSL:
7986
8087
<pre>
8188
cd compat # relative to the Fossil source tree root
8289
tar xf /path/to/openssl-*.tar.gz
8390
ln -fs openssl-x.y.z openssl
91
+ cd openssl
8492
./config # or, e.g. ./Configure darwin64-x86_64-cc
8593
make -j11
8694
cd ../..
8795
./configure --with-openssl=tree
8896
make -j11
8997
--- www/ssl.wiki
+++ www/ssl.wiki
@@ -25,16 +25,20 @@
25 is to say, you can build it against [https://www.openssl.org/|the
26 OpenSSL library], which will allow it to clone and sync with a remote
27 Fossil repository via <tt>https</tt> URIs.
28
29
30 <h3 id="openssl-bin">Building Against a Binary Version of OpenSSL</h3>
31
32 The <tt>configure</tt> script will attempt to find OpenSSL on your
33 system automatically. If it can't find the files it needs, the most
34 common solution is to install the OpenSSL development package on your
35 system via your OS's package manager. Examples:
 
 
 
 
36
37 * <b>RHEL & Fedora</b>: <tt>sudo yum install openssl-devel</tt>
38 * <b>Debian & Ubuntu</b>: <tt>sudo apt install libssl-dev</tt>
39 * <b>FreeBSD</b>: <tt>su -c 'pkg install openssl'</tt>
40 * <b>macOS</b>: <tt>sudo brew install openssl</tt>
@@ -54,35 +58,39 @@
54
55
56 <h3 id="openssl-src">Building Against a Non-Platform Version of
57 OpenSSL</h3>
58
59 The Fossil build system can also use OpenSSL when installed in
60 nonstandard locations.
61
62 If you've installed OpenSSL via a method that Fossil's build system
63 cannot find on its own, you can clue it in by passing the
64 <tt>--with-openssl</tt> option to the <tt>configure</tt> script. Type
65 <tt>./configure --help</tt> for details.
66
67 It is possible for the Fossil build system to find a functioning version
68 of OpenSSL which is nevertheless unsuitable. One common case is that
69 your OS is sufficiently outdated that the platform version of OpenSSL
70 can no longer communicate with remote systems adhering to the latest
71 advice on secure communications. Your local OpenSSL might not support
72 any of the [https://en.wikipedia.org/wiki/Cipher_suite|cipher suites]
73 the remote Fossil repository's HTTPS proxy is willing to offer, for
74 example, so that even though both sides are speaking a variant of
75 TLS/SSL, they can't come to an agreement on the cryptography.
76
77 In such cases, you may want to link Fossil to a version of OpenSSL built
78 from source. The easiest way to do that is:
 
 
 
79
80 <pre>
81 cd compat # relative to the Fossil source tree root
82 tar xf /path/to/openssl-*.tar.gz
83 ln -fs openssl-x.y.z openssl
 
84 ./config # or, e.g. ./Configure darwin64-x86_64-cc
85 make -j11
86 cd ../..
87 ./configure --with-openssl=tree
88 make -j11
89
--- www/ssl.wiki
+++ www/ssl.wiki
@@ -25,16 +25,20 @@
25 is to say, you can build it against [https://www.openssl.org/|the
26 OpenSSL library], which will allow it to clone and sync with a remote
27 Fossil repository via <tt>https</tt> URIs.
28
29
30 <h3 id="openssl-bin">Building Against OpenSSL Automatically</h3>
31
32 The <tt>configure</tt> script will attempt to find OpenSSL on your
33 system automatically. It first tries asking the <tt>pkg-config</tt>
34 system where the OpenSSL development files are, and if that fails, it
35 falls back to looking through a list of likely directories.
36
37 If it can't find the files it needs, the most common solution is to
38 install the OpenSSL development package on your system via your OS's
39 package manager. Examples:
40
41 * <b>RHEL & Fedora</b>: <tt>sudo yum install openssl-devel</tt>
42 * <b>Debian & Ubuntu</b>: <tt>sudo apt install libssl-dev</tt>
43 * <b>FreeBSD</b>: <tt>su -c 'pkg install openssl'</tt>
44 * <b>macOS</b>: <tt>sudo brew install openssl</tt>
@@ -54,35 +58,39 @@
58
59
60 <h3 id="openssl-src">Building Against a Non-Platform Version of
61 OpenSSL</h3>
62
63 The Fossil build system has a few other methods for finding OpenSSL when
64 the automatic methods fail or when you'd prefer that Fossil use a
65 different version of OpenSSL than the one Fossil's build system picks on
66 its own.
67
68 A good reason to do this is when the Fossil build system finds a
69 functioning version of OpenSSL which is nevertheless unsuitable. One
70 common case is that your OS is sufficiently outdated that the platform
71 version of OpenSSL can no longer communicate with remote systems
72 adhering to the latest advice on secure communications. An old OpenSSL
73 might not support any of the
74 [https://en.wikipedia.org/wiki/Cipher_suite|cipher suites] the remote
75 Fossil repository's HTTPS proxy is willing to offer, for example, so
76 that even though both sides are speaking a variant of TLS/SSL, the peers
77 cannot come to an agreement on the cryptography.
78
79 If you've installed the OpenSSL development files somewhere that
80 Fossil's build system cannot find on its own, you can clue it in by
81 passing the <tt>--with-openssl</tt> option to the <tt>configure</tt>
82 script. Type <tt>./configure --help</tt> for details.
83
84 Another option is to download the source code to OpenSSL and build
85 Fossil against that private version of OpenSSL:
86
87 <pre>
88 cd compat # relative to the Fossil source tree root
89 tar xf /path/to/openssl-*.tar.gz
90 ln -fs openssl-x.y.z openssl
91 cd openssl
92 ./config # or, e.g. ./Configure darwin64-x86_64-cc
93 make -j11
94 cd ../..
95 ./configure --with-openssl=tree
96 make -j11
97
+8
--- www/th1.md
+++ www/th1.md
@@ -187,10 +187,11 @@
187187
* http
188188
* httpize
189189
* insertCsrf
190190
* linecount
191191
* markdown
192
+ * nonce
192193
* puts
193194
* query
194195
* randhex
195196
* redirect
196197
* regexp
@@ -453,10 +454,17 @@
453454
454455
Renders the input string as markdown. The result is a two-element list.
455456
The first element contains the body, rendered as HTML. The second element
456457
is the text-only title string.
457458
459
+<a name="nonce"></a>TH1 nonce Command
460
+-------------------------------------
461
+
462
+ * nonce
463
+
464
+Returns the value of the cryptographic nonce for the request being processed.
465
+
458466
<a name="puts"></a>TH1 puts Command
459467
-----------------------------------
460468
461469
* puts STRING
462470
463471
--- www/th1.md
+++ www/th1.md
@@ -187,10 +187,11 @@
187 * http
188 * httpize
189 * insertCsrf
190 * linecount
191 * markdown
 
192 * puts
193 * query
194 * randhex
195 * redirect
196 * regexp
@@ -453,10 +454,17 @@
453
454 Renders the input string as markdown. The result is a two-element list.
455 The first element contains the body, rendered as HTML. The second element
456 is the text-only title string.
457
 
 
 
 
 
 
 
458 <a name="puts"></a>TH1 puts Command
459 -----------------------------------
460
461 * puts STRING
462
463
--- www/th1.md
+++ www/th1.md
@@ -187,10 +187,11 @@
187 * http
188 * httpize
189 * insertCsrf
190 * linecount
191 * markdown
192 * nonce
193 * puts
194 * query
195 * randhex
196 * redirect
197 * regexp
@@ -453,10 +454,17 @@
454
455 Renders the input string as markdown. The result is a two-element list.
456 The first element contains the body, rendered as HTML. The second element
457 is the text-only title string.
458
459 <a name="nonce"></a>TH1 nonce Command
460 -------------------------------------
461
462 * nonce
463
464 Returns the value of the cryptographic nonce for the request being processed.
465
466 <a name="puts"></a>TH1 puts Command
467 -----------------------------------
468
469 * puts STRING
470
471

Keyboard Shortcuts

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