Fossil SCM

Merge trunk. Some more comments.

jan.nijtmans 2013-12-20 12:04 win32-longpath merge
Commit 4e3f4d26d86a9e47ec8cb1aef2d468c67173a4c9
+6 -4
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711711
*/
712712
LOCAL sqlite3 *db_open(const char *zDbName){
713713
int rc;
714714
sqlite3 *db;
715715
716
-#if defined(__CYGWIN__) || defined(_WIN32)
716
+#if defined(__CYGWIN__)
717
+ /* Necessary if we want Cygwin fossil to recognize win32 file
718
+ * paths, as SQLite doesn't handle that (yet) */
719
+ zDbName = fossil_utf8_to_filename(zDbName);
720
+#elif defined(_WIN32)
721
+ /* Only necessary when SQLite doesn't handle Extended paths. */
717722
zDbName = fossil_utf8_to_filename(zDbName);
718
-#ifdef _WIN32
719
- /* Convert back to utf-8. TODO: SQLite should handle this */
720723
zDbName = fossil_filename_to_utf8(zDbName);
721
-#endif
722724
#endif
723725
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724726
rc = sqlite3_open_v2(
725727
zDbName, &db,
726728
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
727729
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__) || defined(_WIN32)
 
 
 
 
 
717 zDbName = fossil_utf8_to_filename(zDbName);
718 #ifdef _WIN32
719 /* Convert back to utf-8. TODO: SQLite should handle this */
720 zDbName = fossil_filename_to_utf8(zDbName);
721 #endif
722 #endif
723 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724 rc = sqlite3_open_v2(
725 zDbName, &db,
726 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
727
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__)
717 /* Necessary if we want Cygwin fossil to recognize win32 file
718 * paths, as SQLite doesn't handle that (yet) */
719 zDbName = fossil_utf8_to_filename(zDbName);
720 #elif defined(_WIN32)
721 /* Only necessary when SQLite doesn't handle Extended paths. */
722 zDbName = fossil_utf8_to_filename(zDbName);
 
 
723 zDbName = fossil_filename_to_utf8(zDbName);
 
724 #endif
725 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
726 rc = sqlite3_open_v2(
727 zDbName, &db,
728 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
729
+6 -4
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711711
*/
712712
LOCAL sqlite3 *db_open(const char *zDbName){
713713
int rc;
714714
sqlite3 *db;
715715
716
-#if defined(__CYGWIN__) || defined(_WIN32)
716
+#if defined(__CYGWIN__)
717
+ /* Necessary if we want Cygwin fossil to recognize win32 file
718
+ * paths, as SQLite doesn't handle that (yet) */
719
+ zDbName = fossil_utf8_to_filename(zDbName);
720
+#elif defined(_WIN32)
721
+ /* Only necessary when SQLite doesn't handle Extended paths. */
717722
zDbName = fossil_utf8_to_filename(zDbName);
718
-#ifdef _WIN32
719
- /* Convert back to utf-8. TODO: SQLite should handle this */
720723
zDbName = fossil_filename_to_utf8(zDbName);
721
-#endif
722724
#endif
723725
if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724726
rc = sqlite3_open_v2(
725727
zDbName, &db,
726728
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
727729
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__) || defined(_WIN32)
 
 
 
 
 
717 zDbName = fossil_utf8_to_filename(zDbName);
718 #ifdef _WIN32
719 /* Convert back to utf-8. TODO: SQLite should handle this */
720 zDbName = fossil_filename_to_utf8(zDbName);
721 #endif
722 #endif
723 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
724 rc = sqlite3_open_v2(
725 zDbName, &db,
726 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
727
--- src/db.c
+++ src/db.c
@@ -711,16 +711,18 @@
711 */
712 LOCAL sqlite3 *db_open(const char *zDbName){
713 int rc;
714 sqlite3 *db;
715
716 #if defined(__CYGWIN__)
717 /* Necessary if we want Cygwin fossil to recognize win32 file
718 * paths, as SQLite doesn't handle that (yet) */
719 zDbName = fossil_utf8_to_filename(zDbName);
720 #elif defined(_WIN32)
721 /* Only necessary when SQLite doesn't handle Extended paths. */
722 zDbName = fossil_utf8_to_filename(zDbName);
 
 
723 zDbName = fossil_filename_to_utf8(zDbName);
 
724 #endif
725 if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
726 rc = sqlite3_open_v2(
727 zDbName, &db,
728 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
729
+22 -1
--- src/info.c
+++ src/info.c
@@ -524,11 +524,12 @@
524524
525525
style_header(zTitle);
526526
login_anonymous_available();
527527
free(zTitle);
528528
zEUser = db_text(0,
529
- "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
529
+ "SELECT value FROM tagxref"
530
+ " WHERE tagid=%d AND rid=%d AND tagtype>0",
530531
TAG_USER, rid);
531532
zEComment = db_text(0,
532533
"SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
533534
TAG_COMMENT, rid);
534535
zUser = db_column_text(&q1, 2);
@@ -2051,12 +2052,14 @@
20512052
const char *zNewTagFlag;
20522053
const char *zNewTag;
20532054
const char *zNewBrFlag;
20542055
const char *zNewBranch;
20552056
const char *zCloseFlag;
2057
+ const char *zHideFlag;
20562058
int fPropagateColor; /* True if color propagates before edit */
20572059
int fNewPropagateColor; /* True if color propagates after edit */
2060
+ int fHasHidden = 0; /* True if hidden tag already set */
20582061
int fHasClosed = 0; /* True if closed tag already set */
20592062
const char *zChngTime = 0; /* Value of chngtime= query param, if any */
20602063
char *zUuid;
20612064
Blob comment;
20622065
char *zBranchName = 0;
@@ -2095,10 +2098,11 @@
20952098
zNewTagFlag = P("newtag") ? " checked" : "";
20962099
zNewTag = PDT("tagname","");
20972100
zNewBrFlag = P("newbr") ? " checked" : "";
20982101
zNewBranch = PDT("brname","");
20992102
zCloseFlag = P("close") ? " checked" : "";
2103
+ zHideFlag = P("hide") ? " checked" : "";
21002104
if( P("apply") ){
21012105
Blob ctrl;
21022106
char *zNow;
21032107
int nChng = 0;
21042108
@@ -2145,10 +2149,13 @@
21452149
if( P(zLabel) ){
21462150
db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
21472151
}
21482152
}
21492153
db_finalize(&q);
2154
+ if( zHideFlag[0] ){
2155
+ db_multi_exec("REPLACE INTO newtags VALUES('hidden','*',NULL)");
2156
+ }
21502157
if( zCloseFlag[0] ){
21512158
db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
21522159
is_a_leaf(rid)?"+":"*");
21532160
}
21542161
if( zNewTagFlag[0] && zNewTag[0] ){
@@ -2206,16 +2213,19 @@
22062213
*/
22072214
@ <script>
22082215
@ function chgcbn(checked, branch){
22092216
@ val = gebi('brname').value.trim();
22102217
@ if( !val || !checked ) val = branch;
2218
+ @ if( checked ) gebi('brname').select();
2219
+ @ gebi('hbranch').textContent = val;
22112220
@ cidbrid = document.getElementById('cbranch');
22122221
@ if( cidbrid ) cidbrid.textContent = val;
22132222
@ }
22142223
@ function chgbn(val, branch){
22152224
@ if( !val ) val = branch;
22162225
@ gebi('newbr').checked = (val!=branch);
2226
+ @ gebi('hbranch').textContent = val;
22172227
@ cidbrid = document.getElementById('cbranch');
22182228
@ if( cidbrid ) cidbrid.textContent = val;
22192229
@ }
22202230
@ </script>
22212231
if( P("preview") ){
@@ -2315,10 +2325,12 @@
23152325
23162326
if( tagid == TAG_CLOSED ){
23172327
fHasClosed = 1;
23182328
}else if( (tagid == TAG_COMMENT) || (tagid == TAG_BRANCH) ){
23192329
continue;
2330
+ }else if( tagid==TAG_HIDDEN ){
2331
+ fHasHidden = 1;
23202332
}else if( !isSpecialTag && zTagName &&
23212333
fossil_strcmp(&zTagName[4], zBranchName)==0){
23222334
continue;
23232335
}
23242336
sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
@@ -2349,10 +2361,19 @@
23492361
@ onchange="chgcbn(this.checked,'%h(zBranchName)')" />
23502362
@ Make this check-in the start of a new branch named:</label>
23512363
@ <input id="brname" type="text" style="width:15;" name="brname"
23522364
@ value="%h(zNewBranch)"
23532365
@ onkeyup="chgbn(this.value.trim(),'%h(zBranchName)')" /></td></tr>
2366
+ if( !fHasHidden ){
2367
+ @ <tr><th align="right" valign="top">Branch Hiding:</th>
2368
+ @ <td valign="top">
2369
+ @ <label><input type="checkbox" id="hidebr" name="hide"%s(zHideFlag) />
2370
+ @ Hide branch
2371
+ @ <span style="font-weight:bold" id="hbranch">%h(zBranchName)</span>
2372
+ @ from the timeline starting from this check-in</label>
2373
+ @ </td></tr>
2374
+ }
23542375
if( !fHasClosed ){
23552376
if( is_a_leaf(rid) ){
23562377
@ <tr><th align="right" valign="top">Leaf Closure:</th>
23572378
@ <td valign="top">
23582379
@ <label><input type="checkbox" name="close"%s(zCloseFlag) />
23592380
--- src/info.c
+++ src/info.c
@@ -524,11 +524,12 @@
524
525 style_header(zTitle);
526 login_anonymous_available();
527 free(zTitle);
528 zEUser = db_text(0,
529 "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
 
530 TAG_USER, rid);
531 zEComment = db_text(0,
532 "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
533 TAG_COMMENT, rid);
534 zUser = db_column_text(&q1, 2);
@@ -2051,12 +2052,14 @@
2051 const char *zNewTagFlag;
2052 const char *zNewTag;
2053 const char *zNewBrFlag;
2054 const char *zNewBranch;
2055 const char *zCloseFlag;
 
2056 int fPropagateColor; /* True if color propagates before edit */
2057 int fNewPropagateColor; /* True if color propagates after edit */
 
2058 int fHasClosed = 0; /* True if closed tag already set */
2059 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2060 char *zUuid;
2061 Blob comment;
2062 char *zBranchName = 0;
@@ -2095,10 +2098,11 @@
2095 zNewTagFlag = P("newtag") ? " checked" : "";
2096 zNewTag = PDT("tagname","");
2097 zNewBrFlag = P("newbr") ? " checked" : "";
2098 zNewBranch = PDT("brname","");
2099 zCloseFlag = P("close") ? " checked" : "";
 
2100 if( P("apply") ){
2101 Blob ctrl;
2102 char *zNow;
2103 int nChng = 0;
2104
@@ -2145,10 +2149,13 @@
2145 if( P(zLabel) ){
2146 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2147 }
2148 }
2149 db_finalize(&q);
 
 
 
2150 if( zCloseFlag[0] ){
2151 db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2152 is_a_leaf(rid)?"+":"*");
2153 }
2154 if( zNewTagFlag[0] && zNewTag[0] ){
@@ -2206,16 +2213,19 @@
2206 */
2207 @ <script>
2208 @ function chgcbn(checked, branch){
2209 @ val = gebi('brname').value.trim();
2210 @ if( !val || !checked ) val = branch;
 
 
2211 @ cidbrid = document.getElementById('cbranch');
2212 @ if( cidbrid ) cidbrid.textContent = val;
2213 @ }
2214 @ function chgbn(val, branch){
2215 @ if( !val ) val = branch;
2216 @ gebi('newbr').checked = (val!=branch);
 
2217 @ cidbrid = document.getElementById('cbranch');
2218 @ if( cidbrid ) cidbrid.textContent = val;
2219 @ }
2220 @ </script>
2221 if( P("preview") ){
@@ -2315,10 +2325,12 @@
2315
2316 if( tagid == TAG_CLOSED ){
2317 fHasClosed = 1;
2318 }else if( (tagid == TAG_COMMENT) || (tagid == TAG_BRANCH) ){
2319 continue;
 
 
2320 }else if( !isSpecialTag && zTagName &&
2321 fossil_strcmp(&zTagName[4], zBranchName)==0){
2322 continue;
2323 }
2324 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
@@ -2349,10 +2361,19 @@
2349 @ onchange="chgcbn(this.checked,'%h(zBranchName)')" />
2350 @ Make this check-in the start of a new branch named:</label>
2351 @ <input id="brname" type="text" style="width:15;" name="brname"
2352 @ value="%h(zNewBranch)"
2353 @ onkeyup="chgbn(this.value.trim(),'%h(zBranchName)')" /></td></tr>
 
 
 
 
 
 
 
 
 
2354 if( !fHasClosed ){
2355 if( is_a_leaf(rid) ){
2356 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2357 @ <td valign="top">
2358 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2359
--- src/info.c
+++ src/info.c
@@ -524,11 +524,12 @@
524
525 style_header(zTitle);
526 login_anonymous_available();
527 free(zTitle);
528 zEUser = db_text(0,
529 "SELECT value FROM tagxref"
530 " WHERE tagid=%d AND rid=%d AND tagtype>0",
531 TAG_USER, rid);
532 zEComment = db_text(0,
533 "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
534 TAG_COMMENT, rid);
535 zUser = db_column_text(&q1, 2);
@@ -2051,12 +2052,14 @@
2052 const char *zNewTagFlag;
2053 const char *zNewTag;
2054 const char *zNewBrFlag;
2055 const char *zNewBranch;
2056 const char *zCloseFlag;
2057 const char *zHideFlag;
2058 int fPropagateColor; /* True if color propagates before edit */
2059 int fNewPropagateColor; /* True if color propagates after edit */
2060 int fHasHidden = 0; /* True if hidden tag already set */
2061 int fHasClosed = 0; /* True if closed tag already set */
2062 const char *zChngTime = 0; /* Value of chngtime= query param, if any */
2063 char *zUuid;
2064 Blob comment;
2065 char *zBranchName = 0;
@@ -2095,10 +2098,11 @@
2098 zNewTagFlag = P("newtag") ? " checked" : "";
2099 zNewTag = PDT("tagname","");
2100 zNewBrFlag = P("newbr") ? " checked" : "";
2101 zNewBranch = PDT("brname","");
2102 zCloseFlag = P("close") ? " checked" : "";
2103 zHideFlag = P("hide") ? " checked" : "";
2104 if( P("apply") ){
2105 Blob ctrl;
2106 char *zNow;
2107 int nChng = 0;
2108
@@ -2145,10 +2149,13 @@
2149 if( P(zLabel) ){
2150 db_multi_exec("REPLACE INTO newtags VALUES(%Q,'-',NULL)", zTag);
2151 }
2152 }
2153 db_finalize(&q);
2154 if( zHideFlag[0] ){
2155 db_multi_exec("REPLACE INTO newtags VALUES('hidden','*',NULL)");
2156 }
2157 if( zCloseFlag[0] ){
2158 db_multi_exec("REPLACE INTO newtags VALUES('closed','%s',NULL)",
2159 is_a_leaf(rid)?"+":"*");
2160 }
2161 if( zNewTagFlag[0] && zNewTag[0] ){
@@ -2206,16 +2213,19 @@
2213 */
2214 @ <script>
2215 @ function chgcbn(checked, branch){
2216 @ val = gebi('brname').value.trim();
2217 @ if( !val || !checked ) val = branch;
2218 @ if( checked ) gebi('brname').select();
2219 @ gebi('hbranch').textContent = val;
2220 @ cidbrid = document.getElementById('cbranch');
2221 @ if( cidbrid ) cidbrid.textContent = val;
2222 @ }
2223 @ function chgbn(val, branch){
2224 @ if( !val ) val = branch;
2225 @ gebi('newbr').checked = (val!=branch);
2226 @ gebi('hbranch').textContent = val;
2227 @ cidbrid = document.getElementById('cbranch');
2228 @ if( cidbrid ) cidbrid.textContent = val;
2229 @ }
2230 @ </script>
2231 if( P("preview") ){
@@ -2315,10 +2325,12 @@
2325
2326 if( tagid == TAG_CLOSED ){
2327 fHasClosed = 1;
2328 }else if( (tagid == TAG_COMMENT) || (tagid == TAG_BRANCH) ){
2329 continue;
2330 }else if( tagid==TAG_HIDDEN ){
2331 fHasHidden = 1;
2332 }else if( !isSpecialTag && zTagName &&
2333 fossil_strcmp(&zTagName[4], zBranchName)==0){
2334 continue;
2335 }
2336 sqlite3_snprintf(sizeof(zLabel), zLabel, "c%d", tagid);
@@ -2349,10 +2361,19 @@
2361 @ onchange="chgcbn(this.checked,'%h(zBranchName)')" />
2362 @ Make this check-in the start of a new branch named:</label>
2363 @ <input id="brname" type="text" style="width:15;" name="brname"
2364 @ value="%h(zNewBranch)"
2365 @ onkeyup="chgbn(this.value.trim(),'%h(zBranchName)')" /></td></tr>
2366 if( !fHasHidden ){
2367 @ <tr><th align="right" valign="top">Branch Hiding:</th>
2368 @ <td valign="top">
2369 @ <label><input type="checkbox" id="hidebr" name="hide"%s(zHideFlag) />
2370 @ Hide branch
2371 @ <span style="font-weight:bold" id="hbranch">%h(zBranchName)</span>
2372 @ from the timeline starting from this check-in</label>
2373 @ </td></tr>
2374 }
2375 if( !fHasClosed ){
2376 if( is_a_leaf(rid) ){
2377 @ <tr><th align="right" valign="top">Leaf Closure:</th>
2378 @ <td valign="top">
2379 @ <label><input type="checkbox" name="close"%s(zCloseFlag) />
2380
+4 -3
--- src/shell.c
+++ src/shell.c
@@ -1834,11 +1834,11 @@
18341834
** + Store the character that terminates the field in p->cTerm. Store
18351835
** EOF on end-of-file.
18361836
** + Report syntax errors on stderr
18371837
*/
18381838
static char *csv_read_one_field(CSVReader *p){
1839
- int c, pc;
1839
+ int c, pc, ppc;
18401840
int cSep = p->cSeparator;
18411841
p->n = 0;
18421842
c = fgetc(p->in);
18431843
if( c==EOF || seenInterrupt ){
18441844
p->cTerm = EOF;
@@ -1845,11 +1845,11 @@
18451845
return 0;
18461846
}
18471847
if( c=='"' ){
18481848
int startLine = p->nLine;
18491849
int cQuote = c;
1850
- pc = 0;
1850
+ pc = ppc = 0;
18511851
while( 1 ){
18521852
c = fgetc(p->in);
18531853
if( c=='\n' ) p->nLine++;
18541854
if( c==cQuote ){
18551855
if( pc==cQuote ){
@@ -1857,11 +1857,11 @@
18571857
continue;
18581858
}
18591859
}
18601860
if( (c==cSep && pc==cQuote)
18611861
|| (c=='\n' && pc==cQuote)
1862
- || (c=='\n' && pc=='\r' && p->n>=2 && p->z[p->n-2]==cQuote)
1862
+ || (c=='\n' && pc=='\r' && ppc==cQuote)
18631863
|| (c==EOF && pc==cQuote)
18641864
){
18651865
do{ p->n--; }while( p->z[p->n]!=cQuote );
18661866
p->cTerm = c;
18671867
break;
@@ -1875,10 +1875,11 @@
18751875
p->zFile, startLine, cQuote);
18761876
p->cTerm = EOF;
18771877
break;
18781878
}
18791879
csv_append_char(p, c);
1880
+ ppc = pc;
18801881
pc = c;
18811882
}
18821883
}else{
18831884
while( c!=EOF && c!=cSep && c!='\n' ){
18841885
csv_append_char(p, c);
18851886
--- src/shell.c
+++ src/shell.c
@@ -1834,11 +1834,11 @@
1834 ** + Store the character that terminates the field in p->cTerm. Store
1835 ** EOF on end-of-file.
1836 ** + Report syntax errors on stderr
1837 */
1838 static char *csv_read_one_field(CSVReader *p){
1839 int c, pc;
1840 int cSep = p->cSeparator;
1841 p->n = 0;
1842 c = fgetc(p->in);
1843 if( c==EOF || seenInterrupt ){
1844 p->cTerm = EOF;
@@ -1845,11 +1845,11 @@
1845 return 0;
1846 }
1847 if( c=='"' ){
1848 int startLine = p->nLine;
1849 int cQuote = c;
1850 pc = 0;
1851 while( 1 ){
1852 c = fgetc(p->in);
1853 if( c=='\n' ) p->nLine++;
1854 if( c==cQuote ){
1855 if( pc==cQuote ){
@@ -1857,11 +1857,11 @@
1857 continue;
1858 }
1859 }
1860 if( (c==cSep && pc==cQuote)
1861 || (c=='\n' && pc==cQuote)
1862 || (c=='\n' && pc=='\r' && p->n>=2 && p->z[p->n-2]==cQuote)
1863 || (c==EOF && pc==cQuote)
1864 ){
1865 do{ p->n--; }while( p->z[p->n]!=cQuote );
1866 p->cTerm = c;
1867 break;
@@ -1875,10 +1875,11 @@
1875 p->zFile, startLine, cQuote);
1876 p->cTerm = EOF;
1877 break;
1878 }
1879 csv_append_char(p, c);
 
1880 pc = c;
1881 }
1882 }else{
1883 while( c!=EOF && c!=cSep && c!='\n' ){
1884 csv_append_char(p, c);
1885
--- src/shell.c
+++ src/shell.c
@@ -1834,11 +1834,11 @@
1834 ** + Store the character that terminates the field in p->cTerm. Store
1835 ** EOF on end-of-file.
1836 ** + Report syntax errors on stderr
1837 */
1838 static char *csv_read_one_field(CSVReader *p){
1839 int c, pc, ppc;
1840 int cSep = p->cSeparator;
1841 p->n = 0;
1842 c = fgetc(p->in);
1843 if( c==EOF || seenInterrupt ){
1844 p->cTerm = EOF;
@@ -1845,11 +1845,11 @@
1845 return 0;
1846 }
1847 if( c=='"' ){
1848 int startLine = p->nLine;
1849 int cQuote = c;
1850 pc = ppc = 0;
1851 while( 1 ){
1852 c = fgetc(p->in);
1853 if( c=='\n' ) p->nLine++;
1854 if( c==cQuote ){
1855 if( pc==cQuote ){
@@ -1857,11 +1857,11 @@
1857 continue;
1858 }
1859 }
1860 if( (c==cSep && pc==cQuote)
1861 || (c=='\n' && pc==cQuote)
1862 || (c=='\n' && pc=='\r' && ppc==cQuote)
1863 || (c==EOF && pc==cQuote)
1864 ){
1865 do{ p->n--; }while( p->z[p->n]!=cQuote );
1866 p->cTerm = c;
1867 break;
@@ -1875,10 +1875,11 @@
1875 p->zFile, startLine, cQuote);
1876 p->cTerm = EOF;
1877 break;
1878 }
1879 csv_append_char(p, c);
1880 ppc = pc;
1881 pc = c;
1882 }
1883 }else{
1884 while( c!=EOF && c!=cSep && c!='\n' ){
1885 csv_append_char(p, c);
1886
+314 -151
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.3"
139139
#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
140
+#define SQLITE_SOURCE_ID "2013-12-17 16:32:56 93121d3097a43997af3c0de65bd9bd7663845fa2"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -817,19 +817,33 @@
817817
** to the [sqlite3_file] object associated with a particular database
818818
** connection. See the [sqlite3_file_control()] documentation for
819819
** additional information.
820820
**
821821
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
822
-** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
823
-** SQLite and sent to all VFSes in place of a call to the xSync method
824
-** when the database connection has [PRAGMA synchronous] set to OFF.)^
825
-** Some specialized VFSes need this signal in order to operate correctly
826
-** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
827
-** VFSes do not need this signal and should silently ignore this opcode.
828
-** Applications should not call [sqlite3_file_control()] with this
829
-** opcode as doing so may disrupt the operation of the specialized VFSes
830
-** that do require it.
822
+** No longer in use.
823
+**
824
+** <li>[[SQLITE_FCNTL_SYNC]]
825
+** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
826
+** sent to the VFS immediately before the xSync method is invoked on a
827
+** database file descriptor. Or, if the xSync method is not invoked
828
+** because the user has configured SQLite with
829
+** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
830
+** of the xSync method. In most cases, the pointer argument passed with
831
+** this file-control is NULL. However, if the database file is being synced
832
+** as part of a multi-database commit, the argument points to a nul-terminated
833
+** string containing the transactions master-journal file name. VFSes that
834
+** do not need this signal should silently ignore this opcode. Applications
835
+** should not call [sqlite3_file_control()] with this opcode as doing so may
836
+** disrupt the operation of the specialized VFSes that do require it.
837
+**
838
+** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
839
+** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
840
+** and sent to the VFS after a transaction has been committed immediately
841
+** but before the database is unlocked. VFSes that do not need this signal
842
+** should silently ignore this opcode. Applications should not call
843
+** [sqlite3_file_control()] with this opcode as doing so may disrupt the
844
+** operation of the specialized VFSes that do require it.
831845
**
832846
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
833847
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
834848
** retry counts and intervals for certain disk I/O operations for the
835849
** windows [VFS] in order to provide robustness in the presence of
@@ -976,10 +990,12 @@
976990
#define SQLITE_FCNTL_BUSYHANDLER 15
977991
#define SQLITE_FCNTL_TEMPFILENAME 16
978992
#define SQLITE_FCNTL_MMAP_SIZE 18
979993
#define SQLITE_FCNTL_TRACE 19
980994
#define SQLITE_FCNTL_HAS_MOVED 20
995
+#define SQLITE_FCNTL_SYNC 21
996
+#define SQLITE_FCNTL_COMMIT_PHASETWO 22
981997
982998
/*
983999
** CAPI3REF: Mutex Handle
9841000
**
9851001
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3992,19 +4008,28 @@
39924008
** parameter is less than -1 or greater than 127 then the behavior is
39934009
** undefined.
39944010
**
39954011
** ^The fourth parameter, eTextRep, specifies what
39964012
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3997
-** its parameters. Every SQL function implementation must be able to work
3998
-** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3999
-** more efficient with one encoding than another. ^An application may
4000
-** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
4001
-** times with the same function but with different values of eTextRep.
4013
+** its parameters. The application should set this parameter to
4014
+** [SQLITE_UTF16LE] if the function implementation invokes
4015
+** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4016
+** implementation invokes [sqlite3_value_text16be()] on an input, or
4017
+** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4018
+** otherwise. ^The same SQL function may be registered multiple times using
4019
+** different preferred text encodings, with different implementations for
4020
+** each encoding.
40024021
** ^When multiple implementations of the same function are available, SQLite
40034022
** will pick the one that involves the least amount of data conversion.
4004
-** If there is only a single implementation which does not care what text
4005
-** encoding is used, then the fourth argument should be [SQLITE_ANY].
4023
+**
4024
+** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4025
+** to signal that the function will always return the same result given
4026
+** the same inputs within a single SQL statement. Most SQL functions are
4027
+** deterministic. The built-in [random()] SQL function is an example of a
4028
+** function that is not deterministic. The SQLite query planner is able to
4029
+** perform additional optimizations on deterministic functions, so use
4030
+** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
40064031
**
40074032
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
40084033
** function can gain access to this pointer using [sqlite3_user_data()].)^
40094034
**
40104035
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4086,13 +4111,23 @@
40864111
*/
40874112
#define SQLITE_UTF8 1
40884113
#define SQLITE_UTF16LE 2
40894114
#define SQLITE_UTF16BE 3
40904115
#define SQLITE_UTF16 4 /* Use native byte order */
4091
-#define SQLITE_ANY 5 /* sqlite3_create_function only */
4116
+#define SQLITE_ANY 5 /* Deprecated */
40924117
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
40934118
4119
+/*
4120
+** CAPI3REF: Function Flags
4121
+**
4122
+** These constants may be ORed together with the
4123
+** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4124
+** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4125
+** [sqlite3_create_function_v2()].
4126
+*/
4127
+#define SQLITE_DETERMINISTIC 0x800
4128
+
40944129
/*
40954130
** CAPI3REF: Deprecated Functions
40964131
** DEPRECATED
40974132
**
40984133
** These functions are [deprecated]. In order to maintain
@@ -8590,10 +8625,11 @@
85908625
typedef struct Lookaside Lookaside;
85918626
typedef struct LookasideSlot LookasideSlot;
85928627
typedef struct Module Module;
85938628
typedef struct NameContext NameContext;
85948629
typedef struct Parse Parse;
8630
+typedef struct PrintfArguments PrintfArguments;
85958631
typedef struct RowSet RowSet;
85968632
typedef struct Savepoint Savepoint;
85978633
typedef struct Select Select;
85988634
typedef struct SelectDest SelectDest;
85998635
typedef struct SrcList SrcList;
@@ -9448,10 +9484,11 @@
94489484
SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
94499485
#define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
94509486
SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
94519487
SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
94529488
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
9489
+SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
94539490
94549491
/* Operations on page references. */
94559492
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
94569493
SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
94579494
SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9462,11 +9499,11 @@
94629499
/* Functions used to manage pager transactions and savepoints. */
94639500
SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
94649501
SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
94659502
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
94669503
SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9467
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
9504
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
94689505
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
94699506
SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
94709507
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
94719508
SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
94729509
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -12043,14 +12080,24 @@
1204312080
SQLITE_PRIVATE int sqlite3IsNaN(double);
1204412081
#else
1204512082
# define sqlite3IsNaN(X) 0
1204612083
#endif
1204712084
12048
-SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
12049
-#ifndef SQLITE_OMIT_TRACE
12050
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
12051
-#endif
12085
+/*
12086
+** An instance of the following structure holds information about SQL
12087
+** functions arguments that are the parameters to the printf() function.
12088
+*/
12089
+struct PrintfArguments {
12090
+ int nArg; /* Total number of arguments */
12091
+ int nUsed; /* Number of arguments used so far */
12092
+ sqlite3_value **apArg; /* The argument values */
12093
+};
12094
+
12095
+#define SQLITE_PRINTF_INTERNAL 0x01
12096
+#define SQLITE_PRINTF_SQLFUNC 0x02
12097
+SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12098
+SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
1205212099
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1205312100
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1205412101
SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
1205512102
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
1205612103
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12436,10 +12483,11 @@
1243612483
1243712484
SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
1243812485
SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
1243912486
SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
1244012487
void(*)(void*));
12488
+SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*);
1244112489
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
1244212490
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
1244312491
SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
1244412492
SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
1244512493
SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -19894,14 +19942,31 @@
1989419942
}
1989519943
1989619944
/*
1989719945
** Set the StrAccum object to an error mode.
1989819946
*/
19899
-void setStrAccumError(StrAccum *p, u8 eError){
19947
+static void setStrAccumError(StrAccum *p, u8 eError){
1990019948
p->accError = eError;
1990119949
p->nAlloc = 0;
1990219950
}
19951
+
19952
+/*
19953
+** Extra argument values from a PrintfArguments object
19954
+*/
19955
+static sqlite3_int64 getIntArg(PrintfArguments *p){
19956
+ if( p->nArg<=p->nUsed ) return 0;
19957
+ return sqlite3_value_int64(p->apArg[p->nUsed++]);
19958
+}
19959
+static double getDoubleArg(PrintfArguments *p){
19960
+ if( p->nArg<=p->nUsed ) return 0.0;
19961
+ return sqlite3_value_double(p->apArg[p->nUsed++]);
19962
+}
19963
+static char *getTextArg(PrintfArguments *p){
19964
+ if( p->nArg<=p->nUsed ) return 0;
19965
+ return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
19966
+}
19967
+
1990319968
1990419969
/*
1990519970
** On machines with a small stack size, you can redefine the
1990619971
** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
1990719972
*/
@@ -19912,14 +19977,14 @@
1991219977
1991319978
/*
1991419979
** Render a string given by "fmt" into the StrAccum object.
1991519980
*/
1991619981
SQLITE_PRIVATE void sqlite3VXPrintf(
19917
- StrAccum *pAccum, /* Accumulate results here */
19918
- int useExtended, /* Allow extended %-conversions */
19919
- const char *fmt, /* Format string */
19920
- va_list ap /* arguments */
19982
+ StrAccum *pAccum, /* Accumulate results here */
19983
+ u32 bFlags, /* SQLITE_PRINTF_* flags */
19984
+ const char *fmt, /* Format string */
19985
+ va_list ap /* arguments */
1992119986
){
1992219987
int c; /* Next character in the format string */
1992319988
char *bufpt; /* Pointer to the conversion buffer */
1992419989
int precision; /* Precision of the current field */
1992519990
int length; /* Length of the field */
@@ -19933,10 +19998,12 @@
1993319998
etByte flag_zeropad; /* True if field width constant starts with zero */
1993419999
etByte flag_long; /* True if "l" flag is present */
1993520000
etByte flag_longlong; /* True if the "ll" flag is present */
1993620001
etByte done; /* Loop termination flag */
1993720002
etByte xtype = 0; /* Conversion paradigm */
20003
+ u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
20004
+ u8 useIntern; /* Ok to use internal conversions (ex: %T) */
1993820005
char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
1993920006
sqlite_uint64 longvalue; /* Value for integer types */
1994020007
LONGDOUBLE_TYPE realvalue; /* Value for real types */
1994120008
const et_info *infop; /* Pointer to the appropriate info structure */
1994220009
char *zOut; /* Rendering buffer */
@@ -19947,13 +20014,22 @@
1994720014
int nsd; /* Number of significant digits returned */
1994820015
double rounder; /* Used for rounding floating point values */
1994920016
etByte flag_dp; /* True if decimal point should be shown */
1995020017
etByte flag_rtz; /* True if trailing zeros should be removed */
1995120018
#endif
20019
+ PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
1995220020
char buf[etBUFSIZE]; /* Conversion buffer */
1995320021
1995420022
bufpt = 0;
20023
+ if( bFlags ){
20024
+ if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20025
+ pArgList = va_arg(ap, PrintfArguments*);
20026
+ }
20027
+ useIntern = bFlags & SQLITE_PRINTF_INTERNAL;
20028
+ }else{
20029
+ bArgList = useIntern = 0;
20030
+ }
1995520031
for(; (c=(*fmt))!=0; ++fmt){
1995620032
if( c!='%' ){
1995720033
int amt;
1995820034
bufpt = (char *)fmt;
1995920035
amt = 1;
@@ -19981,11 +20057,15 @@
1998120057
}
1998220058
}while( !done && (c=(*++fmt))!=0 );
1998320059
/* Get the field width */
1998420060
width = 0;
1998520061
if( c=='*' ){
19986
- width = va_arg(ap,int);
20062
+ if( bArgList ){
20063
+ width = (int)getIntArg(pArgList);
20064
+ }else{
20065
+ width = va_arg(ap,int);
20066
+ }
1998720067
if( width<0 ){
1998820068
flag_leftjustify = 1;
1998920069
width = -width;
1999020070
}
1999120071
c = *++fmt;
@@ -19998,11 +20078,15 @@
1999820078
/* Get the precision */
1999920079
if( c=='.' ){
2000020080
precision = 0;
2000120081
c = *++fmt;
2000220082
if( c=='*' ){
20003
- precision = va_arg(ap,int);
20083
+ if( bArgList ){
20084
+ precision = (int)getIntArg(pArgList);
20085
+ }else{
20086
+ precision = va_arg(ap,int);
20087
+ }
2000420088
if( precision<0 ) precision = -precision;
2000520089
c = *++fmt;
2000620090
}else{
2000720091
while( c>='0' && c<='9' ){
2000820092
precision = precision*10 + c - '0';
@@ -20029,11 +20113,11 @@
2002920113
infop = &fmtinfo[0];
2003020114
xtype = etINVALID;
2003120115
for(idx=0; idx<ArraySize(fmtinfo); idx++){
2003220116
if( c==fmtinfo[idx].fmttype ){
2003320117
infop = &fmtinfo[idx];
20034
- if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
20118
+ if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
2003520119
xtype = infop->type;
2003620120
}else{
2003720121
return;
2003820122
}
2003920123
break;
@@ -20069,11 +20153,13 @@
2006920153
/* Fall through into the next case */
2007020154
case etORDINAL:
2007120155
case etRADIX:
2007220156
if( infop->flags & FLAG_SIGNED ){
2007320157
i64 v;
20074
- if( flag_longlong ){
20158
+ if( bArgList ){
20159
+ v = getIntArg(pArgList);
20160
+ }else if( flag_longlong ){
2007520161
v = va_arg(ap,i64);
2007620162
}else if( flag_long ){
2007720163
v = va_arg(ap,long int);
2007820164
}else{
2007920165
v = va_arg(ap,int);
@@ -20090,11 +20176,13 @@
2009020176
if( flag_plussign ) prefix = '+';
2009120177
else if( flag_blanksign ) prefix = ' ';
2009220178
else prefix = 0;
2009320179
}
2009420180
}else{
20095
- if( flag_longlong ){
20181
+ if( bArgList ){
20182
+ longvalue = (u64)getIntArg(pArgList);
20183
+ }else if( flag_longlong ){
2009620184
longvalue = va_arg(ap,u64);
2009720185
}else if( flag_long ){
2009820186
longvalue = va_arg(ap,unsigned long int);
2009920187
}else{
2010020188
longvalue = va_arg(ap,unsigned int);
@@ -20150,11 +20238,15 @@
2015020238
length = (int)(&zOut[nOut-1]-bufpt);
2015120239
break;
2015220240
case etFLOAT:
2015320241
case etEXP:
2015420242
case etGENERIC:
20155
- realvalue = va_arg(ap,double);
20243
+ if( bArgList ){
20244
+ realvalue = getDoubleArg(pArgList);
20245
+ }else{
20246
+ realvalue = va_arg(ap,double);
20247
+ }
2015620248
#ifdef SQLITE_OMIT_FLOATING_POINT
2015720249
length = 0;
2015820250
#else
2015920251
if( precision<0 ) precision = 6; /* Set default precision */
2016020252
if( realvalue<0.0 ){
@@ -20305,20 +20397,27 @@
2030520397
length = width;
2030620398
}
2030720399
#endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
2030820400
break;
2030920401
case etSIZE:
20310
- *(va_arg(ap,int*)) = pAccum->nChar;
20402
+ if( !bArgList ){
20403
+ *(va_arg(ap,int*)) = pAccum->nChar;
20404
+ }
2031120405
length = width = 0;
2031220406
break;
2031320407
case etPERCENT:
2031420408
buf[0] = '%';
2031520409
bufpt = buf;
2031620410
length = 1;
2031720411
break;
2031820412
case etCHARX:
20319
- c = va_arg(ap,int);
20413
+ if( bArgList ){
20414
+ bufpt = getTextArg(pArgList);
20415
+ c = bufpt ? bufpt[0] : 0;
20416
+ }else{
20417
+ c = va_arg(ap,int);
20418
+ }
2032020419
buf[0] = (char)c;
2032120420
if( precision>=0 ){
2032220421
for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
2032320422
length = precision;
2032420423
}else{
@@ -20326,14 +20425,18 @@
2032620425
}
2032720426
bufpt = buf;
2032820427
break;
2032920428
case etSTRING:
2033020429
case etDYNSTRING:
20331
- bufpt = va_arg(ap,char*);
20430
+ if( bArgList ){
20431
+ bufpt = getTextArg(pArgList);
20432
+ }else{
20433
+ bufpt = va_arg(ap,char*);
20434
+ }
2033220435
if( bufpt==0 ){
2033320436
bufpt = "";
20334
- }else if( xtype==etDYNSTRING ){
20437
+ }else if( xtype==etDYNSTRING && !bArgList ){
2033520438
zExtra = bufpt;
2033620439
}
2033720440
if( precision>=0 ){
2033820441
for(length=0; length<precision && bufpt[length]; length++){}
2033920442
}else{
@@ -20345,11 +20448,17 @@
2034520448
case etSQLESCAPE3: {
2034620449
int i, j, k, n, isnull;
2034720450
int needQuote;
2034820451
char ch;
2034920452
char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20350
- char *escarg = va_arg(ap,char*);
20453
+ char *escarg;
20454
+
20455
+ if( bArgList ){
20456
+ escarg = getTextArg(pArgList);
20457
+ }else{
20458
+ escarg = va_arg(ap,char*);
20459
+ }
2035120460
isnull = escarg==0;
2035220461
if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
2035320462
k = precision;
2035420463
for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
2035520464
if( ch==q ) n++;
@@ -20380,10 +20489,11 @@
2038020489
** if( precision>=0 && precision<length ) length = precision; */
2038120490
break;
2038220491
}
2038320492
case etTOKEN: {
2038420493
Token *pToken = va_arg(ap, Token*);
20494
+ assert( bArgList==0 );
2038520495
if( pToken && pToken->n ){
2038620496
sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
2038720497
}
2038820498
length = width = 0;
2038920499
break;
@@ -20390,10 +20500,11 @@
2039020500
}
2039120501
case etSRCLIST: {
2039220502
SrcList *pSrc = va_arg(ap, SrcList*);
2039320503
int k = va_arg(ap, int);
2039420504
struct SrcList_item *pItem = &pSrc->a[k];
20505
+ assert( bArgList==0 );
2039520506
assert( k>=0 && k<pSrc->nSrc );
2039620507
if( pItem->zDatabase ){
2039720508
sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
2039820509
sqlite3StrAccumAppend(pAccum, ".", 1);
2039920510
}
@@ -20426,11 +20537,11 @@
2042620537
nspace = width-length;
2042720538
if( nspace>0 ){
2042820539
sqlite3AppendSpace(pAccum, nspace);
2042920540
}
2043020541
}
20431
- sqlite3_free(zExtra);
20542
+ if( zExtra ) sqlite3_free(zExtra);
2043220543
}/* End for loop over the format string */
2043320544
} /* End of function */
2043420545
2043520546
/*
2043620547
** Append N bytes of text from z to the StrAccum object.
@@ -20553,11 +20664,11 @@
2055320664
StrAccum acc;
2055420665
assert( db!=0 );
2055520666
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
2055620667
db->aLimit[SQLITE_LIMIT_LENGTH]);
2055720668
acc.db = db;
20558
- sqlite3VXPrintf(&acc, 1, zFormat, ap);
20669
+ sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
2055920670
z = sqlite3StrAccumFinish(&acc);
2056020671
if( acc.accError==STRACCUM_NOMEM ){
2056120672
db->mallocFailed = 1;
2056220673
}
2056320674
return z;
@@ -20709,21 +20820,19 @@
2070920820
fprintf(stdout,"%s", zBuf);
2071020821
fflush(stdout);
2071120822
}
2071220823
#endif
2071320824
20714
-#ifndef SQLITE_OMIT_TRACE
2071520825
/*
2071620826
** variable-argument wrapper around sqlite3VXPrintf().
2071720827
*/
20718
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
20828
+SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
2071920829
va_list ap;
2072020830
va_start(ap,zFormat);
20721
- sqlite3VXPrintf(p, 1, zFormat, ap);
20831
+ sqlite3VXPrintf(p, bFlags, zFormat, ap);
2072220832
va_end(ap);
2072320833
}
20724
-#endif
2072520834
2072620835
/************** End of printf.c **********************************************/
2072720836
/************** Begin file random.c ******************************************/
2072820837
/*
2072920838
** 2001 September 15
@@ -21494,22 +21603,21 @@
2149421603
** To clear the most recent error for sqlite handle "db", sqlite3Error
2149521604
** should be called with err_code set to SQLITE_OK and zFormat set
2149621605
** to NULL.
2149721606
*/
2149821607
SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21499
- if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21500
- db->errCode = err_code;
21501
- if( zFormat ){
21502
- char *z;
21503
- va_list ap;
21504
- va_start(ap, zFormat);
21505
- z = sqlite3VMPrintf(db, zFormat, ap);
21506
- va_end(ap);
21507
- sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21508
- }else{
21509
- sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21510
- }
21608
+ assert( db!=0 );
21609
+ db->errCode = err_code;
21610
+ if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21611
+ char *z;
21612
+ va_list ap;
21613
+ va_start(ap, zFormat);
21614
+ z = sqlite3VMPrintf(db, zFormat, ap);
21615
+ va_end(ap);
21616
+ sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21617
+ }else if( db->pErr ){
21618
+ sqlite3ValueSetNull(db->pErr);
2151121619
}
2151221620
}
2151321621
2151421622
/*
2151521623
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -37558,10 +37666,11 @@
3755837666
** in memory.
3755937667
*/
3756037668
struct PgHdr1 {
3756137669
sqlite3_pcache_page page;
3756237670
unsigned int iKey; /* Key value (page number) */
37671
+ u8 isPinned; /* Page in use, not on the LRU list */
3756337672
PgHdr1 *pNext; /* Next in hash table chain */
3756437673
PCache1 *pCache; /* Cache that currently owns this page */
3756537674
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
3756637675
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
3756737676
};
@@ -37886,38 +37995,36 @@
3788637995
** This function is used internally to remove the page pPage from the
3788737996
** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
3788837997
** LRU list, then this function is a no-op.
3788937998
**
3789037999
** The PGroup mutex must be held when this function is called.
37891
-**
37892
-** If pPage is NULL then this routine is a no-op.
3789338000
*/
3789438001
static void pcache1PinPage(PgHdr1 *pPage){
3789538002
PCache1 *pCache;
3789638003
PGroup *pGroup;
3789738004
37898
- if( pPage==0 ) return;
38005
+ assert( pPage!=0 );
38006
+ assert( pPage->isPinned==0 );
3789938007
pCache = pPage->pCache;
3790038008
pGroup = pCache->pGroup;
38009
+ assert( pPage->pLruNext || pPage==pGroup->pLruTail );
38010
+ assert( pPage->pLruPrev || pPage==pGroup->pLruHead );
3790138011
assert( sqlite3_mutex_held(pGroup->mutex) );
37902
- if( pPage->pLruNext || pPage==pGroup->pLruTail ){
37903
- if( pPage->pLruPrev ){
37904
- pPage->pLruPrev->pLruNext = pPage->pLruNext;
37905
- }
37906
- if( pPage->pLruNext ){
37907
- pPage->pLruNext->pLruPrev = pPage->pLruPrev;
37908
- }
37909
- if( pGroup->pLruHead==pPage ){
37910
- pGroup->pLruHead = pPage->pLruNext;
37911
- }
37912
- if( pGroup->pLruTail==pPage ){
37913
- pGroup->pLruTail = pPage->pLruPrev;
37914
- }
37915
- pPage->pLruNext = 0;
37916
- pPage->pLruPrev = 0;
37917
- pPage->pCache->nRecyclable--;
37918
- }
38012
+ if( pPage->pLruPrev ){
38013
+ pPage->pLruPrev->pLruNext = pPage->pLruNext;
38014
+ }else{
38015
+ pGroup->pLruHead = pPage->pLruNext;
38016
+ }
38017
+ if( pPage->pLruNext ){
38018
+ pPage->pLruNext->pLruPrev = pPage->pLruPrev;
38019
+ }else{
38020
+ pGroup->pLruTail = pPage->pLruPrev;
38021
+ }
38022
+ pPage->pLruNext = 0;
38023
+ pPage->pLruPrev = 0;
38024
+ pPage->isPinned = 1;
38025
+ pCache->nRecyclable--;
3791938026
}
3792038027
3792138028
3792238029
/*
3792338030
** Remove the page supplied as an argument from the hash table
@@ -37945,10 +38052,11 @@
3794538052
static void pcache1EnforceMaxPage(PGroup *pGroup){
3794638053
assert( sqlite3_mutex_held(pGroup->mutex) );
3794738054
while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
3794838055
PgHdr1 *p = pGroup->pLruTail;
3794938056
assert( p->pCache->pGroup==pGroup );
38057
+ assert( p->isPinned==0 );
3795038058
pcache1PinPage(p);
3795138059
pcache1RemoveFromHash(p);
3795238060
pcache1FreePage(p);
3795338061
}
3795438062
}
@@ -37972,11 +38080,11 @@
3797238080
PgHdr1 *pPage;
3797338081
while( (pPage = *pp)!=0 ){
3797438082
if( pPage->iKey>=iLimit ){
3797538083
pCache->nPage--;
3797638084
*pp = pPage->pNext;
37977
- pcache1PinPage(pPage);
38085
+ if( !pPage->isPinned ) pcache1PinPage(pPage);
3797838086
pcache1FreePage(pPage);
3797938087
}else{
3798038088
pp = &pPage->pNext;
3798138089
TESTONLY( nPage++; )
3798238090
}
@@ -38195,12 +38303,15 @@
3819538303
unsigned int h = iKey % pCache->nHash;
3819638304
for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
3819738305
}
3819838306
3819938307
/* Step 2: Abort if no existing page is found and createFlag is 0 */
38200
- if( pPage || createFlag==0 ){
38201
- pcache1PinPage(pPage);
38308
+ if( pPage ){
38309
+ if( !pPage->isPinned ) pcache1PinPage(pPage);
38310
+ goto fetch_out;
38311
+ }
38312
+ if( createFlag==0 ){
3820238313
goto fetch_out;
3820338314
}
3820438315
3820538316
/* The pGroup local variable will normally be initialized by the
3820638317
** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38237,10 +38348,11 @@
3823738348
|| pGroup->nCurrentPage>=pGroup->nMaxPage
3823838349
|| pcache1UnderMemoryPressure(pCache)
3823938350
)){
3824038351
PCache1 *pOther;
3824138352
pPage = pGroup->pLruTail;
38353
+ assert( pPage->isPinned==0 );
3824238354
pcache1RemoveFromHash(pPage);
3824338355
pcache1PinPage(pPage);
3824438356
pOther = pPage->pCache;
3824538357
3824638358
/* We want to verify that szPage and szExtra are the same for pOther
@@ -38273,10 +38385,11 @@
3827338385
pPage->iKey = iKey;
3827438386
pPage->pNext = pCache->apHash[h];
3827538387
pPage->pCache = pCache;
3827638388
pPage->pLruPrev = 0;
3827738389
pPage->pLruNext = 0;
38390
+ pPage->isPinned = 1;
3827838391
*(void **)pPage->page.pExtra = 0;
3827938392
pCache->apHash[h] = pPage;
3828038393
}
3828138394
3828238395
fetch_out:
@@ -38308,10 +38421,11 @@
3830838421
/* It is an error to call this function if the page is already
3830938422
** part of the PGroup LRU list.
3831038423
*/
3831138424
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
3831238425
assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
38426
+ assert( pPage->isPinned==1 );
3831338427
3831438428
if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
3831538429
pcache1RemoveFromHash(pPage);
3831638430
pcache1FreePage(pPage);
3831738431
}else{
@@ -38323,10 +38437,11 @@
3832338437
}else{
3832438438
pGroup->pLruTail = pPage;
3832538439
pGroup->pLruHead = pPage;
3832638440
}
3832738441
pCache->nRecyclable++;
38442
+ pPage->isPinned = 0;
3832838443
}
3832938444
3833038445
pcache1LeaveMutex(pCache->pGroup);
3833138446
}
3833238447
@@ -38449,10 +38564,11 @@
3844938564
while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
3845038565
nFree += pcache1MemSize(p->page.pBuf);
3845138566
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
3845238567
nFree += sqlite3MemSize(p);
3845338568
#endif
38569
+ assert( p->isPinned==0 );
3845438570
pcache1PinPage(p);
3845538571
pcache1RemoveFromHash(p);
3845638572
pcache1FreePage(p);
3845738573
}
3845838574
pcache1LeaveMutex(&pcache1.grp);
@@ -38473,10 +38589,11 @@
3847338589
int *pnRecyclable /* OUT: Total number of pages available for recycling */
3847438590
){
3847538591
PgHdr1 *p;
3847638592
int nRecyclable = 0;
3847738593
for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
38594
+ assert( p->isPinned==0 );
3847838595
nRecyclable++;
3847938596
}
3848038597
*pnCurrent = pcache1.grp.nCurrentPage;
3848138598
*pnMax = (int)pcache1.grp.nMaxPage;
3848238599
*pnMin = (int)pcache1.grp.nMinPage;
@@ -40159,29 +40276,26 @@
4015940276
** PagerSavepoint.pInSavepoint.
4016040277
*/
4016140278
static int subjRequiresPage(PgHdr *pPg){
4016240279
Pager *pPager = pPg->pPager;
4016340280
PagerSavepoint *p;
40164
- Pgno pgno;
40281
+ Pgno pgno = pPg->pgno;
4016540282
int i;
40166
- if( pPager->nSavepoint ){
40167
- pgno = pPg->pgno;
40168
- for(i=0; i<pPager->nSavepoint; i++){
40169
- p = &pPager->aSavepoint[i];
40170
- if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40171
- return 1;
40172
- }
40283
+ for(i=0; i<pPager->nSavepoint; i++){
40284
+ p = &pPager->aSavepoint[i];
40285
+ if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40286
+ return 1;
4017340287
}
4017440288
}
4017540289
return 0;
4017640290
}
4017740291
4017840292
/*
4017940293
** Return true if the page is already in the journal file.
4018040294
*/
40181
-static int pageInJournal(PgHdr *pPg){
40182
- return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
40295
+static int pageInJournal(Pager *pPager, PgHdr *pPg){
40296
+ return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
4018340297
}
4018440298
4018540299
/*
4018640300
** Read a 32-bit integer from the given file descriptor. Store the integer
4018740301
** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40384,10 +40498,11 @@
4038440498
4038540499
if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
4038640500
|| szJ<16
4038740501
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
4038840502
|| len>=nMaster
40503
+ || len==0
4038940504
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
4039040505
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
4039140506
|| memcmp(aMagic, aJournalMagic, 8)
4039240507
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
4039340508
){
@@ -41124,11 +41239,11 @@
4112441239
sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
4112541240
if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
4112641241
PgHdr *p = pager_lookup(pPager, 1);
4112741242
if( p ){
4112841243
p->pageHash = 0;
41129
- sqlite3PagerUnref(p);
41244
+ sqlite3PagerUnrefNotNull(p);
4113041245
}
4113141246
}
4113241247
#endif
4113341248
4113441249
sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41152,10 +41267,15 @@
4115241267
** file. So it is safe to truncate the database file to its minimum
4115341268
** required size. */
4115441269
assert( pPager->eLock==EXCLUSIVE_LOCK );
4115541270
rc = pager_truncate(pPager, pPager->dbSize);
4115641271
}
41272
+
41273
+ if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){
41274
+ rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
41275
+ if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
41276
+ }
4115741277
4115841278
if( !pPager->exclusiveMode
4115941279
&& (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
4116041280
){
4116141281
rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
@@ -41966,11 +42086,11 @@
4196642086
testcase( rc!=SQLITE_OK );
4196742087
}
4196842088
if( rc==SQLITE_OK
4196942089
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
4197042090
){
41971
- rc = sqlite3PagerSync(pPager);
42091
+ rc = sqlite3PagerSync(pPager, 0);
4197242092
}
4197342093
if( rc==SQLITE_OK ){
4197442094
rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
4197542095
testcase( rc!=SQLITE_OK );
4197642096
}
@@ -42112,11 +42232,11 @@
4211242232
rc = readDbPage(pPg, iFrame);
4211342233
}
4211442234
if( rc==SQLITE_OK ){
4211542235
pPager->xReiniter(pPg);
4211642236
}
42117
- sqlite3PagerUnref(pPg);
42237
+ sqlite3PagerUnrefNotNull(pPg);
4211842238
}
4211942239
}
4212042240
4212142241
/* Normally, if a transaction is rolled back, any backup processes are
4212242242
** updated as data is copied out of the rollback journal and into the
@@ -43467,11 +43587,11 @@
4346743587
/* Open the sub-journal, if it has not already been opened */
4346843588
assert( pPager->useJournal );
4346943589
assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
4347043590
assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
4347143591
assert( pagerUseWal(pPager)
43472
- || pageInJournal(pPg)
43592
+ || pageInJournal(pPager, pPg)
4347343593
|| pPg->pgno>pPager->dbOrigSize
4347443594
);
4347543595
rc = openSubJournal(pPager);
4347643596
4347743597
/* If the sub-journal was opened successfully (or was already open),
@@ -44568,20 +44688,23 @@
4456844688
** If the number of references to the page drop to zero, then the
4456944689
** page is added to the LRU list. When all references to all pages
4457044690
** are released, a rollback occurs and the lock on the database is
4457144691
** removed.
4457244692
*/
44693
+SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
44694
+ Pager *pPager;
44695
+ assert( pPg!=0 );
44696
+ pPager = pPg->pPager;
44697
+ if( pPg->flags & PGHDR_MMAP ){
44698
+ pagerReleaseMapPage(pPg);
44699
+ }else{
44700
+ sqlite3PcacheRelease(pPg);
44701
+ }
44702
+ pagerUnlockIfUnused(pPager);
44703
+}
4457344704
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44574
- if( pPg ){
44575
- Pager *pPager = pPg->pPager;
44576
- if( pPg->flags & PGHDR_MMAP ){
44577
- pagerReleaseMapPage(pPg);
44578
- }else{
44579
- sqlite3PcacheRelease(pPg);
44580
- }
44581
- pagerUnlockIfUnused(pPager);
44582
- }
44705
+ if( pPg ) sqlite3PagerUnrefNotNull(pPg);
4458344706
}
4458444707
4458544708
/*
4458644709
** This function is called at the start of every write transaction.
4458744710
** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44765,13 +44888,13 @@
4476544888
** one of the journals, the corresponding bit is set in the
4476644889
** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
4476744890
** of any open savepoints as appropriate.
4476844891
*/
4476944892
static int pager_write(PgHdr *pPg){
44770
- void *pData = pPg->pData;
4477144893
Pager *pPager = pPg->pPager;
4477244894
int rc = SQLITE_OK;
44895
+ int inJournal;
4477344896
4477444897
/* This routine is not called unless a write-transaction has already
4477544898
** been started. The journal file may or may not be open at this point.
4477644899
** It is never called in the ERROR state.
4477744900
*/
@@ -44803,19 +44926,20 @@
4480344926
4480444927
/* Mark the page as dirty. If the page has already been written
4480544928
** to the journal then we can return right away.
4480644929
*/
4480744930
sqlite3PcacheMakeDirty(pPg);
44808
- if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
44931
+ inJournal = pageInJournal(pPager, pPg);
44932
+ if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){
4480944933
assert( !pagerUseWal(pPager) );
4481044934
}else{
4481144935
4481244936
/* The transaction journal now exists and we have a RESERVED or an
4481344937
** EXCLUSIVE lock on the main database file. Write the current page to
4481444938
** the transaction journal if it is not there already.
4481544939
*/
44816
- if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){
44940
+ if( !inJournal && !pagerUseWal(pPager) ){
4481744941
assert( pagerUseWal(pPager)==0 );
4481844942
if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
4481944943
u32 cksum;
4482044944
char *pData2;
4482144945
i64 iOff = pPager->journalOff;
@@ -44824,11 +44948,11 @@
4482444948
** contains the database locks. The following assert verifies
4482544949
** that we do not. */
4482644950
assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
4482744951
4482844952
assert( pPager->journalHdr<=pPager->journalOff );
44829
- CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44953
+ CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
4483044954
cksum = pager_cksum(pPager, (u8*)pData2);
4483144955
4483244956
/* Even if an IO or diskfull error occurs while journalling the
4483344957
** page in the block above, set the need-sync flag for the page.
4483444958
** Otherwise, when the transaction is rolled back, the logic in
@@ -44876,11 +45000,11 @@
4487645000
/* If the statement journal is open and the page is not in it,
4487745001
** then write the current page to the statement journal. Note that
4487845002
** the statement journal format differs from the standard journal format
4487945003
** in that it omits the checksums and the header.
4488045004
*/
44881
- if( subjRequiresPage(pPg) ){
45005
+ if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){
4488245006
rc = subjournalPage(pPg);
4488345007
}
4488445008
}
4488545009
4488645010
/* Update the database size and return.
@@ -44959,18 +45083,18 @@
4495945083
if( rc==SQLITE_OK ){
4496045084
rc = pager_write(pPage);
4496145085
if( pPage->flags&PGHDR_NEED_SYNC ){
4496245086
needSync = 1;
4496345087
}
44964
- sqlite3PagerUnref(pPage);
45088
+ sqlite3PagerUnrefNotNull(pPage);
4496545089
}
4496645090
}
4496745091
}else if( (pPage = pager_lookup(pPager, pg))!=0 ){
4496845092
if( pPage->flags&PGHDR_NEED_SYNC ){
4496945093
needSync = 1;
4497045094
}
44971
- sqlite3PagerUnref(pPage);
45095
+ sqlite3PagerUnrefNotNull(pPage);
4497245096
}
4497345097
}
4497445098
4497545099
/* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
4497645100
** starting at pg1, then it needs to be set for all of them. Because
@@ -44982,11 +45106,11 @@
4498245106
assert( !MEMDB );
4498345107
for(ii=0; ii<nPage; ii++){
4498445108
PgHdr *pPage = pager_lookup(pPager, pg1+ii);
4498545109
if( pPage ){
4498645110
pPage->flags |= PGHDR_NEED_SYNC;
44987
- sqlite3PagerUnref(pPage);
45111
+ sqlite3PagerUnrefNotNull(pPage);
4498845112
}
4498945113
}
4499045114
}
4499145115
4499245116
assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45135,21 +45259,21 @@
4513545259
** or pages with the Pager.noSync flag set.
4513645260
**
4513745261
** If successful, or if called on a pager for which it is a no-op, this
4513845262
** function returns SQLITE_OK. Otherwise, an IO error code is returned.
4513945263
*/
45140
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
45264
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
4514145265
int rc = SQLITE_OK;
45142
- if( !pPager->noSync ){
45266
+
45267
+ if( isOpen(pPager->fd) ){
45268
+ void *pArg = (void*)zMaster;
45269
+ rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
45270
+ if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
45271
+ }
45272
+ if( rc==SQLITE_OK && !pPager->noSync ){
4514345273
assert( !MEMDB );
4514445274
rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
45145
- }else if( isOpen(pPager->fd) ){
45146
- assert( !MEMDB );
45147
- rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0);
45148
- if( rc==SQLITE_NOTFOUND ){
45149
- rc = SQLITE_OK;
45150
- }
4515145275
}
4515245276
return rc;
4515345277
}
4515445278
4515545279
/*
@@ -45344,11 +45468,11 @@
4534445468
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
4534545469
}
4534645470
4534745471
/* Finally, sync the database file. */
4534845472
if( !noSync ){
45349
- rc = sqlite3PagerSync(pPager);
45473
+ rc = sqlite3PagerSync(pPager, zMaster);
4535045474
}
4535145475
IOTRACE(("DBSYNC %p\n", pPager))
4535245476
}
4535345477
}
4535445478
@@ -45473,11 +45597,13 @@
4547345597
rc = pager_playback(pPager, 0);
4547445598
}
4547545599
4547645600
assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
4547745601
assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45478
- || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
45602
+ || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
45603
+ || rc==SQLITE_CANTOPEN
45604
+ );
4547945605
4548045606
/* If an error occurs during a ROLLBACK, we can no longer trust the pager
4548145607
** cache. So call pager_error() on the way out to make any error persistent.
4548245608
*/
4548345609
return pager_error(pPager, rc);
@@ -45876,11 +46002,11 @@
4587646002
** can be written to. The caller has already promised not to write to it.
4587746003
*/
4587846004
if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
4587946005
needSyncPgno = pPg->pgno;
4588046006
assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
45881
- pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
46007
+ pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
4588246008
assert( pPg->flags&PGHDR_DIRTY );
4588346009
}
4588446010
4588546011
/* If the cache contains a page with page-number pgno, remove it
4588646012
** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -45910,11 +46036,11 @@
4591046036
** as the original page since it has already been allocated.
4591146037
*/
4591246038
if( MEMDB ){
4591346039
assert( pPgOld );
4591446040
sqlite3PcacheMove(pPgOld, origPgno);
45915
- sqlite3PagerUnref(pPgOld);
46041
+ sqlite3PagerUnrefNotNull(pPgOld);
4591646042
}
4591746043
4591846044
if( needSyncPgno ){
4591946045
/* If needSyncPgno is non-zero, then the journal file needs to be
4592046046
** sync()ed before any data is written to database file page needSyncPgno.
@@ -45939,11 +46065,11 @@
4593946065
}
4594046066
return rc;
4594146067
}
4594246068
pPgHdr->flags |= PGHDR_NEED_SYNC;
4594346069
sqlite3PcacheMakeDirty(pPgHdr);
45944
- sqlite3PagerUnref(pPgHdr);
46070
+ sqlite3PagerUnrefNotNull(pPgHdr);
4594546071
}
4594646072
4594746073
return SQLITE_OK;
4594846074
}
4594946075
#endif
@@ -52079,14 +52205,15 @@
5207952205
*/
5208052206
static void releasePage(MemPage *pPage){
5208152207
if( pPage ){
5208252208
assert( pPage->aData );
5208352209
assert( pPage->pBt );
52210
+ assert( pPage->pDbPage!=0 );
5208452211
assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
5208552212
assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
5208652213
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52087
- sqlite3PagerUnref(pPage->pDbPage);
52214
+ sqlite3PagerUnrefNotNull(pPage->pDbPage);
5208852215
}
5208952216
}
5209052217
5209152218
/*
5209252219
** During a rollback, when the pager reloads information into the cache
@@ -59413,11 +59540,11 @@
5941359540
rc = backupTruncateFile(pFile, iSize);
5941459541
}
5941559542
5941659543
/* Sync the database file to disk. */
5941759544
if( rc==SQLITE_OK ){
59418
- rc = sqlite3PagerSync(pDestPager);
59545
+ rc = sqlite3PagerSync(pDestPager, 0);
5941959546
}
5942059547
}else{
5942159548
sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
5942259549
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
5942359550
}
@@ -59488,14 +59615,14 @@
5948859615
/* If a transaction is still open on the Btree, roll it back. */
5948959616
sqlite3BtreeRollback(p->pDest, SQLITE_OK);
5949059617
5949159618
/* Set the error code of the destination database handle. */
5949259619
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
59493
- sqlite3Error(p->pDestDb, rc, 0);
59494
-
59495
- /* Exit the mutexes and free the backup context structure. */
5949659620
if( p->pDestDb ){
59621
+ sqlite3Error(p->pDestDb, rc, 0);
59622
+
59623
+ /* Exit the mutexes and free the backup context structure. */
5949759624
sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
5949859625
}
5949959626
sqlite3BtreeLeave(p->pSrc);
5950059627
if( p->pDestDb ){
5950159628
/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -60117,10 +60244,13 @@
6011760244
if( pMem->flags & MEM_RowSet ){
6011860245
sqlite3RowSetClear(pMem->u.pRowSet);
6011960246
}
6012060247
MemSetTypeFlag(pMem, MEM_Null);
6012160248
pMem->type = SQLITE_NULL;
60249
+}
60250
+SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60251
+ sqlite3VdbeMemSetNull((Mem*)p);
6012260252
}
6012360253
6012460254
/*
6012560255
** Delete any previous value and set the value to be a BLOB of length
6012660256
** n containing all zeros.
@@ -63440,10 +63570,11 @@
6344063570
sqlite3 *db = p->db;
6344163571
int rc = p->rc;
6344263572
if( p->zErrMsg ){
6344363573
u8 mallocFailed = db->mallocFailed;
6344463574
sqlite3BeginBenignMalloc();
63575
+ if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
6344563576
sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
6344663577
sqlite3EndBenignMalloc();
6344763578
db->mallocFailed = mallocFailed;
6344863579
db->errCode = rc;
6344963580
}else{
@@ -63508,12 +63639,11 @@
6350863639
}else if( p->rc && p->expired ){
6350963640
/* The expired flag was set on the VDBE before the first call
6351063641
** to sqlite3_step(). For consistency (since sqlite3_step() was
6351163642
** called), set the database error in this case as well.
6351263643
*/
63513
- sqlite3Error(db, p->rc, 0);
63514
- sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63644
+ sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
6351563645
sqlite3DbFree(db, p->zErrMsg);
6351663646
p->zErrMsg = 0;
6351763647
}
6351863648
6351963649
/* Reclaim all memory used by the VDBE
@@ -64883,20 +65013,21 @@
6488365013
&& (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
6488465014
sqlite3_reset(pStmt);
6488565015
v->doingRerun = 1;
6488665016
assert( v->expired==0 );
6488765017
}
64888
- if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
65018
+ if( rc2!=SQLITE_OK ){
6488965019
/* This case occurs after failing to recompile an sql statement.
6489065020
** The error message from the SQL compiler has already been loaded
6489165021
** into the database handle. This block copies the error message
6489265022
** from the database handle into the statement and sets the statement
6489365023
** program counter to 0 to ensure that when the statement is
6489465024
** finalized or reset the parser error message is available via
6489565025
** sqlite3_errmsg() and sqlite3_errcode().
6489665026
*/
6489765027
const char *zErr = (const char *)sqlite3_value_text(db->pErr);
65028
+ assert( zErr!=0 || db->mallocFailed );
6489865029
sqlite3DbFree(db, v->zErrMsg);
6489965030
if( !db->mallocFailed ){
6490065031
v->zErrMsg = sqlite3DbStrDup(db, zErr);
6490165032
v->rc = rc2;
6490265033
} else {
@@ -65841,13 +65972,13 @@
6584165972
assert( idx>0 && idx<=p->nVar );
6584265973
pVar = &p->aVar[idx-1];
6584365974
if( pVar->flags & MEM_Null ){
6584465975
sqlite3StrAccumAppend(&out, "NULL", 4);
6584565976
}else if( pVar->flags & MEM_Int ){
65846
- sqlite3XPrintf(&out, "%lld", pVar->u.i);
65977
+ sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
6584765978
}else if( pVar->flags & MEM_Real ){
65848
- sqlite3XPrintf(&out, "%!.15g", pVar->r);
65979
+ sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
6584965980
}else if( pVar->flags & MEM_Str ){
6585065981
int nOut; /* Number of bytes of the string text to include in output */
6585165982
#ifndef SQLITE_OMIT_UTF16
6585265983
u8 enc = ENC(db);
6585365984
Mem utf8;
@@ -65864,33 +65995,37 @@
6586465995
if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
6586565996
nOut = SQLITE_TRACE_SIZE_LIMIT;
6586665997
while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
6586765998
}
6586865999
#endif
65869
- sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
66000
+ sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z);
6587066001
#ifdef SQLITE_TRACE_SIZE_LIMIT
65871
- if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
66002
+ if( nOut<pVar->n ){
66003
+ sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66004
+ }
6587266005
#endif
6587366006
#ifndef SQLITE_OMIT_UTF16
6587466007
if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
6587566008
#endif
6587666009
}else if( pVar->flags & MEM_Zero ){
65877
- sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
66010
+ sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero);
6587866011
}else{
6587966012
int nOut; /* Number of bytes of the blob to include in output */
6588066013
assert( pVar->flags & MEM_Blob );
6588166014
sqlite3StrAccumAppend(&out, "x'", 2);
6588266015
nOut = pVar->n;
6588366016
#ifdef SQLITE_TRACE_SIZE_LIMIT
6588466017
if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
6588566018
#endif
6588666019
for(i=0; i<nOut; i++){
65887
- sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
66020
+ sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff);
6588866021
}
6588966022
sqlite3StrAccumAppend(&out, "'", 1);
6589066023
#ifdef SQLITE_TRACE_SIZE_LIMIT
65891
- if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
66024
+ if( nOut<pVar->n ){
66025
+ sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66026
+ }
6589266027
#endif
6589366028
}
6589466029
}
6589566030
}
6589666031
return sqlite3StrAccumFinish(&out);
@@ -65945,11 +66080,11 @@
6594566080
int n = p->nIndent;
6594666081
if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
6594766082
sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
6594866083
}
6594966084
va_start(ap, zFormat);
65950
- sqlite3VXPrintf(&p->str, 1, zFormat, ap);
66085
+ sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
6595166086
va_end(ap);
6595266087
}
6595366088
}
6595466089
6595566090
/*
@@ -88246,11 +88381,10 @@
8824688381
int bestScore = 0; /* Score of best match */
8824788382
int h; /* Hash value */
8824888383
8824988384
assert( nArg>=(-2) );
8825088385
assert( nArg>=(-1) || createFlag==0 );
88251
- assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
8825288386
h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
8825388387
8825488388
/* First search for a match amongst the application-defined functions.
8825588389
*/
8825688390
p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89397,10 +89531,36 @@
8939789531
}while( isText && (zHaystack[0]&0xc0)==0x80 );
8939889532
}
8939989533
if( nNeedle>nHaystack ) N = 0;
8940089534
sqlite3_result_int(context, N);
8940189535
}
89536
+
89537
+/*
89538
+** Implementation of the printf() function.
89539
+*/
89540
+static void printfFunc(
89541
+ sqlite3_context *context,
89542
+ int argc,
89543
+ sqlite3_value **argv
89544
+){
89545
+ PrintfArguments x;
89546
+ StrAccum str;
89547
+ const char *zFormat;
89548
+ int n;
89549
+
89550
+ if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
89551
+ x.nArg = argc-1;
89552
+ x.nUsed = 0;
89553
+ x.apArg = argv+1;
89554
+ sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
89555
+ str.db = sqlite3_context_db_handle(context);
89556
+ sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
89557
+ n = str.nChar;
89558
+ sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
89559
+ SQLITE_DYNAMIC);
89560
+ }
89561
+}
8940289562
8940389563
/*
8940489564
** Implementation of the substr() function.
8940589565
**
8940689566
** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -90828,10 +90988,11 @@
9082890988
FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
9082990989
FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
9083090990
FUNCTION(instr, 2, 0, 0, instrFunc ),
9083190991
FUNCTION(substr, 2, 0, 0, substrFunc ),
9083290992
FUNCTION(substr, 3, 0, 0, substrFunc ),
90993
+ FUNCTION(printf, -1, 0, 0, printfFunc ),
9083390994
FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
9083490995
FUNCTION(char, -1, 0, 0, charFunc ),
9083590996
FUNCTION(abs, 1, 0, 0, absFunc ),
9083690997
#ifndef SQLITE_OMIT_FLOATING_POINT
9083790998
FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -119433,13 +119594,11 @@
119433119594
}
119434119595
sqlite3HashClear(&db->aModule);
119435119596
#endif
119436119597
119437119598
sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119438
- if( db->pErr ){
119439
- sqlite3ValueFree(db->pErr);
119440
- }
119599
+ sqlite3ValueFree(db->pErr);
119441119600
sqlite3CloseExtensions(db);
119442119601
119443119602
db->magic = SQLITE_MAGIC_ERROR;
119444119603
119445119604
/* The temp-database schema is allocated differently from the other schema
@@ -119818,10 +119977,11 @@
119818119977
void (*xFinal)(sqlite3_context*),
119819119978
FuncDestructor *pDestructor
119820119979
){
119821119980
FuncDef *p;
119822119981
int nName;
119982
+ int extraFlags;
119823119983
119824119984
assert( sqlite3_mutex_held(db->mutex) );
119825119985
if( zFunctionName==0 ||
119826119986
(xFunc && (xFinal || xStep)) ||
119827119987
(!xFunc && (xFinal && !xStep)) ||
@@ -119828,10 +119988,14 @@
119828119988
(!xFunc && (!xFinal && xStep)) ||
119829119989
(nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
119830119990
(255<(nName = sqlite3Strlen30( zFunctionName))) ){
119831119991
return SQLITE_MISUSE_BKPT;
119832119992
}
119993
+
119994
+ assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
119995
+ extraFlags = enc & SQLITE_DETERMINISTIC;
119996
+ enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
119833119997
119834119998
#ifndef SQLITE_OMIT_UTF16
119835119999
/* If SQLITE_UTF16 is specified as the encoding type, transform this
119836120000
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
119837120001
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -119841,14 +120005,14 @@
119841120005
*/
119842120006
if( enc==SQLITE_UTF16 ){
119843120007
enc = SQLITE_UTF16NATIVE;
119844120008
}else if( enc==SQLITE_ANY ){
119845120009
int rc;
119846
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
120010
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
119847120011
pUserData, xFunc, xStep, xFinal, pDestructor);
119848120012
if( rc==SQLITE_OK ){
119849
- rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
120013
+ rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
119850120014
pUserData, xFunc, xStep, xFinal, pDestructor);
119851120015
}
119852120016
if( rc!=SQLITE_OK ){
119853120017
return rc;
119854120018
}
@@ -119887,11 +120051,12 @@
119887120051
119888120052
if( pDestructor ){
119889120053
pDestructor->nRef++;
119890120054
}
119891120055
p->pDestructor = pDestructor;
119892
- p->funcFlags &= SQLITE_FUNC_ENCMASK;
120056
+ p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
120057
+ testcase( p->funcFlags & SQLITE_DETERMINISTIC );
119893120058
p->xFunc = xFunc;
119894120059
p->xStep = xStep;
119895120060
p->xFinalize = xFinal;
119896120061
p->pUserData = pUserData;
119897120062
p->nArg = (u16)nArg;
@@ -120317,10 +120482,11 @@
120317120482
}
120318120483
sqlite3_mutex_enter(db->mutex);
120319120484
if( db->mallocFailed ){
120320120485
z = sqlite3ErrStr(SQLITE_NOMEM);
120321120486
}else{
120487
+ testcase( db->pErr==0 );
120322120488
z = (char*)sqlite3_value_text(db->pErr);
120323120489
assert( !db->mallocFailed );
120324120490
if( z==0 ){
120325120491
z = sqlite3ErrStr(db->errCode);
120326120492
}
@@ -120358,12 +120524,11 @@
120358120524
if( db->mallocFailed ){
120359120525
z = (void *)outOfMem;
120360120526
}else{
120361120527
z = sqlite3_value_text16(db->pErr);
120362120528
if( z==0 ){
120363
- sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
120364
- SQLITE_UTF8, SQLITE_STATIC);
120529
+ sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode));
120365120530
z = sqlite3_value_text16(db->pErr);
120366120531
}
120367120532
/* A malloc() may have failed within the call to sqlite3_value_text16()
120368120533
** above. If this is the case, then the db->mallocFailed flag needs to
120369120534
** be cleared before returning. Do this directly, instead of via
@@ -121073,12 +121238,10 @@
121073121238
if( !db->mallocFailed && rc==SQLITE_OK){
121074121239
rc = sqlite3RtreeInit(db);
121075121240
}
121076121241
#endif
121077121242
121078
- sqlite3Error(db, rc, 0);
121079
-
121080121243
/* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121081121244
** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121082121245
** mode. Doing nothing at all also makes NORMAL the default.
121083121246
*/
121084121247
#ifdef SQLITE_DEFAULT_LOCKING_MODE
121085121248
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -817,19 +817,33 @@
817 ** to the [sqlite3_file] object associated with a particular database
818 ** connection. See the [sqlite3_file_control()] documentation for
819 ** additional information.
820 **
821 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
822 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
823 ** SQLite and sent to all VFSes in place of a call to the xSync method
824 ** when the database connection has [PRAGMA synchronous] set to OFF.)^
825 ** Some specialized VFSes need this signal in order to operate correctly
826 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
827 ** VFSes do not need this signal and should silently ignore this opcode.
828 ** Applications should not call [sqlite3_file_control()] with this
829 ** opcode as doing so may disrupt the operation of the specialized VFSes
830 ** that do require it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
831 **
832 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
833 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
834 ** retry counts and intervals for certain disk I/O operations for the
835 ** windows [VFS] in order to provide robustness in the presence of
@@ -976,10 +990,12 @@
976 #define SQLITE_FCNTL_BUSYHANDLER 15
977 #define SQLITE_FCNTL_TEMPFILENAME 16
978 #define SQLITE_FCNTL_MMAP_SIZE 18
979 #define SQLITE_FCNTL_TRACE 19
980 #define SQLITE_FCNTL_HAS_MOVED 20
 
 
981
982 /*
983 ** CAPI3REF: Mutex Handle
984 **
985 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3992,19 +4008,28 @@
3992 ** parameter is less than -1 or greater than 127 then the behavior is
3993 ** undefined.
3994 **
3995 ** ^The fourth parameter, eTextRep, specifies what
3996 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3997 ** its parameters. Every SQL function implementation must be able to work
3998 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3999 ** more efficient with one encoding than another. ^An application may
4000 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
4001 ** times with the same function but with different values of eTextRep.
 
 
 
4002 ** ^When multiple implementations of the same function are available, SQLite
4003 ** will pick the one that involves the least amount of data conversion.
4004 ** If there is only a single implementation which does not care what text
4005 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
 
 
 
 
 
 
4006 **
4007 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4008 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4009 **
4010 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4086,13 +4111,23 @@
4086 */
4087 #define SQLITE_UTF8 1
4088 #define SQLITE_UTF16LE 2
4089 #define SQLITE_UTF16BE 3
4090 #define SQLITE_UTF16 4 /* Use native byte order */
4091 #define SQLITE_ANY 5 /* sqlite3_create_function only */
4092 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4093
 
 
 
 
 
 
 
 
 
 
4094 /*
4095 ** CAPI3REF: Deprecated Functions
4096 ** DEPRECATED
4097 **
4098 ** These functions are [deprecated]. In order to maintain
@@ -8590,10 +8625,11 @@
8590 typedef struct Lookaside Lookaside;
8591 typedef struct LookasideSlot LookasideSlot;
8592 typedef struct Module Module;
8593 typedef struct NameContext NameContext;
8594 typedef struct Parse Parse;
 
8595 typedef struct RowSet RowSet;
8596 typedef struct Savepoint Savepoint;
8597 typedef struct Select Select;
8598 typedef struct SelectDest SelectDest;
8599 typedef struct SrcList SrcList;
@@ -9448,10 +9484,11 @@
9448 SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
9449 #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
9450 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
9451 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
9452 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
 
9453
9454 /* Operations on page references. */
9455 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
9456 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
9457 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9462,11 +9499,11 @@
9462 /* Functions used to manage pager transactions and savepoints. */
9463 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
9464 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
9465 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
9466 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9467 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
9468 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
9469 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
9470 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
9471 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
9472 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -12043,14 +12080,24 @@
12043 SQLITE_PRIVATE int sqlite3IsNaN(double);
12044 #else
12045 # define sqlite3IsNaN(X) 0
12046 #endif
12047
12048 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list);
12049 #ifndef SQLITE_OMIT_TRACE
12050 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
12051 #endif
 
 
 
 
 
 
 
 
 
 
12052 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12053 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12054 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12055 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12056 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12436,10 +12483,11 @@
12436
12437 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12438 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12439 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12440 void(*)(void*));
 
12441 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
12442 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
12443 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
12444 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
12445 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -19894,14 +19942,31 @@
19894 }
19895
19896 /*
19897 ** Set the StrAccum object to an error mode.
19898 */
19899 void setStrAccumError(StrAccum *p, u8 eError){
19900 p->accError = eError;
19901 p->nAlloc = 0;
19902 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19903
19904 /*
19905 ** On machines with a small stack size, you can redefine the
19906 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19907 */
@@ -19912,14 +19977,14 @@
19912
19913 /*
19914 ** Render a string given by "fmt" into the StrAccum object.
19915 */
19916 SQLITE_PRIVATE void sqlite3VXPrintf(
19917 StrAccum *pAccum, /* Accumulate results here */
19918 int useExtended, /* Allow extended %-conversions */
19919 const char *fmt, /* Format string */
19920 va_list ap /* arguments */
19921 ){
19922 int c; /* Next character in the format string */
19923 char *bufpt; /* Pointer to the conversion buffer */
19924 int precision; /* Precision of the current field */
19925 int length; /* Length of the field */
@@ -19933,10 +19998,12 @@
19933 etByte flag_zeropad; /* True if field width constant starts with zero */
19934 etByte flag_long; /* True if "l" flag is present */
19935 etByte flag_longlong; /* True if the "ll" flag is present */
19936 etByte done; /* Loop termination flag */
19937 etByte xtype = 0; /* Conversion paradigm */
 
 
19938 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
19939 sqlite_uint64 longvalue; /* Value for integer types */
19940 LONGDOUBLE_TYPE realvalue; /* Value for real types */
19941 const et_info *infop; /* Pointer to the appropriate info structure */
19942 char *zOut; /* Rendering buffer */
@@ -19947,13 +20014,22 @@
19947 int nsd; /* Number of significant digits returned */
19948 double rounder; /* Used for rounding floating point values */
19949 etByte flag_dp; /* True if decimal point should be shown */
19950 etByte flag_rtz; /* True if trailing zeros should be removed */
19951 #endif
 
19952 char buf[etBUFSIZE]; /* Conversion buffer */
19953
19954 bufpt = 0;
 
 
 
 
 
 
 
 
19955 for(; (c=(*fmt))!=0; ++fmt){
19956 if( c!='%' ){
19957 int amt;
19958 bufpt = (char *)fmt;
19959 amt = 1;
@@ -19981,11 +20057,15 @@
19981 }
19982 }while( !done && (c=(*++fmt))!=0 );
19983 /* Get the field width */
19984 width = 0;
19985 if( c=='*' ){
19986 width = va_arg(ap,int);
 
 
 
 
19987 if( width<0 ){
19988 flag_leftjustify = 1;
19989 width = -width;
19990 }
19991 c = *++fmt;
@@ -19998,11 +20078,15 @@
19998 /* Get the precision */
19999 if( c=='.' ){
20000 precision = 0;
20001 c = *++fmt;
20002 if( c=='*' ){
20003 precision = va_arg(ap,int);
 
 
 
 
20004 if( precision<0 ) precision = -precision;
20005 c = *++fmt;
20006 }else{
20007 while( c>='0' && c<='9' ){
20008 precision = precision*10 + c - '0';
@@ -20029,11 +20113,11 @@
20029 infop = &fmtinfo[0];
20030 xtype = etINVALID;
20031 for(idx=0; idx<ArraySize(fmtinfo); idx++){
20032 if( c==fmtinfo[idx].fmttype ){
20033 infop = &fmtinfo[idx];
20034 if( useExtended || (infop->flags & FLAG_INTERN)==0 ){
20035 xtype = infop->type;
20036 }else{
20037 return;
20038 }
20039 break;
@@ -20069,11 +20153,13 @@
20069 /* Fall through into the next case */
20070 case etORDINAL:
20071 case etRADIX:
20072 if( infop->flags & FLAG_SIGNED ){
20073 i64 v;
20074 if( flag_longlong ){
 
 
20075 v = va_arg(ap,i64);
20076 }else if( flag_long ){
20077 v = va_arg(ap,long int);
20078 }else{
20079 v = va_arg(ap,int);
@@ -20090,11 +20176,13 @@
20090 if( flag_plussign ) prefix = '+';
20091 else if( flag_blanksign ) prefix = ' ';
20092 else prefix = 0;
20093 }
20094 }else{
20095 if( flag_longlong ){
 
 
20096 longvalue = va_arg(ap,u64);
20097 }else if( flag_long ){
20098 longvalue = va_arg(ap,unsigned long int);
20099 }else{
20100 longvalue = va_arg(ap,unsigned int);
@@ -20150,11 +20238,15 @@
20150 length = (int)(&zOut[nOut-1]-bufpt);
20151 break;
20152 case etFLOAT:
20153 case etEXP:
20154 case etGENERIC:
20155 realvalue = va_arg(ap,double);
 
 
 
 
20156 #ifdef SQLITE_OMIT_FLOATING_POINT
20157 length = 0;
20158 #else
20159 if( precision<0 ) precision = 6; /* Set default precision */
20160 if( realvalue<0.0 ){
@@ -20305,20 +20397,27 @@
20305 length = width;
20306 }
20307 #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
20308 break;
20309 case etSIZE:
20310 *(va_arg(ap,int*)) = pAccum->nChar;
 
 
20311 length = width = 0;
20312 break;
20313 case etPERCENT:
20314 buf[0] = '%';
20315 bufpt = buf;
20316 length = 1;
20317 break;
20318 case etCHARX:
20319 c = va_arg(ap,int);
 
 
 
 
 
20320 buf[0] = (char)c;
20321 if( precision>=0 ){
20322 for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
20323 length = precision;
20324 }else{
@@ -20326,14 +20425,18 @@
20326 }
20327 bufpt = buf;
20328 break;
20329 case etSTRING:
20330 case etDYNSTRING:
20331 bufpt = va_arg(ap,char*);
 
 
 
 
20332 if( bufpt==0 ){
20333 bufpt = "";
20334 }else if( xtype==etDYNSTRING ){
20335 zExtra = bufpt;
20336 }
20337 if( precision>=0 ){
20338 for(length=0; length<precision && bufpt[length]; length++){}
20339 }else{
@@ -20345,11 +20448,17 @@
20345 case etSQLESCAPE3: {
20346 int i, j, k, n, isnull;
20347 int needQuote;
20348 char ch;
20349 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20350 char *escarg = va_arg(ap,char*);
 
 
 
 
 
 
20351 isnull = escarg==0;
20352 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
20353 k = precision;
20354 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
20355 if( ch==q ) n++;
@@ -20380,10 +20489,11 @@
20380 ** if( precision>=0 && precision<length ) length = precision; */
20381 break;
20382 }
20383 case etTOKEN: {
20384 Token *pToken = va_arg(ap, Token*);
 
20385 if( pToken && pToken->n ){
20386 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20387 }
20388 length = width = 0;
20389 break;
@@ -20390,10 +20500,11 @@
20390 }
20391 case etSRCLIST: {
20392 SrcList *pSrc = va_arg(ap, SrcList*);
20393 int k = va_arg(ap, int);
20394 struct SrcList_item *pItem = &pSrc->a[k];
 
20395 assert( k>=0 && k<pSrc->nSrc );
20396 if( pItem->zDatabase ){
20397 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20398 sqlite3StrAccumAppend(pAccum, ".", 1);
20399 }
@@ -20426,11 +20537,11 @@
20426 nspace = width-length;
20427 if( nspace>0 ){
20428 sqlite3AppendSpace(pAccum, nspace);
20429 }
20430 }
20431 sqlite3_free(zExtra);
20432 }/* End for loop over the format string */
20433 } /* End of function */
20434
20435 /*
20436 ** Append N bytes of text from z to the StrAccum object.
@@ -20553,11 +20664,11 @@
20553 StrAccum acc;
20554 assert( db!=0 );
20555 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20556 db->aLimit[SQLITE_LIMIT_LENGTH]);
20557 acc.db = db;
20558 sqlite3VXPrintf(&acc, 1, zFormat, ap);
20559 z = sqlite3StrAccumFinish(&acc);
20560 if( acc.accError==STRACCUM_NOMEM ){
20561 db->mallocFailed = 1;
20562 }
20563 return z;
@@ -20709,21 +20820,19 @@
20709 fprintf(stdout,"%s", zBuf);
20710 fflush(stdout);
20711 }
20712 #endif
20713
20714 #ifndef SQLITE_OMIT_TRACE
20715 /*
20716 ** variable-argument wrapper around sqlite3VXPrintf().
20717 */
20718 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
20719 va_list ap;
20720 va_start(ap,zFormat);
20721 sqlite3VXPrintf(p, 1, zFormat, ap);
20722 va_end(ap);
20723 }
20724 #endif
20725
20726 /************** End of printf.c **********************************************/
20727 /************** Begin file random.c ******************************************/
20728 /*
20729 ** 2001 September 15
@@ -21494,22 +21603,21 @@
21494 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21495 ** should be called with err_code set to SQLITE_OK and zFormat set
21496 ** to NULL.
21497 */
21498 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21499 if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21500 db->errCode = err_code;
21501 if( zFormat ){
21502 char *z;
21503 va_list ap;
21504 va_start(ap, zFormat);
21505 z = sqlite3VMPrintf(db, zFormat, ap);
21506 va_end(ap);
21507 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21508 }else{
21509 sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC);
21510 }
21511 }
21512 }
21513
21514 /*
21515 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -37558,10 +37666,11 @@
37558 ** in memory.
37559 */
37560 struct PgHdr1 {
37561 sqlite3_pcache_page page;
37562 unsigned int iKey; /* Key value (page number) */
 
37563 PgHdr1 *pNext; /* Next in hash table chain */
37564 PCache1 *pCache; /* Cache that currently owns this page */
37565 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
37566 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
37567 };
@@ -37886,38 +37995,36 @@
37886 ** This function is used internally to remove the page pPage from the
37887 ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
37888 ** LRU list, then this function is a no-op.
37889 **
37890 ** The PGroup mutex must be held when this function is called.
37891 **
37892 ** If pPage is NULL then this routine is a no-op.
37893 */
37894 static void pcache1PinPage(PgHdr1 *pPage){
37895 PCache1 *pCache;
37896 PGroup *pGroup;
37897
37898 if( pPage==0 ) return;
 
37899 pCache = pPage->pCache;
37900 pGroup = pCache->pGroup;
 
 
37901 assert( sqlite3_mutex_held(pGroup->mutex) );
37902 if( pPage->pLruNext || pPage==pGroup->pLruTail ){
37903 if( pPage->pLruPrev ){
37904 pPage->pLruPrev->pLruNext = pPage->pLruNext;
37905 }
37906 if( pPage->pLruNext ){
37907 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
37908 }
37909 if( pGroup->pLruHead==pPage ){
37910 pGroup->pLruHead = pPage->pLruNext;
37911 }
37912 if( pGroup->pLruTail==pPage ){
37913 pGroup->pLruTail = pPage->pLruPrev;
37914 }
37915 pPage->pLruNext = 0;
37916 pPage->pLruPrev = 0;
37917 pPage->pCache->nRecyclable--;
37918 }
37919 }
37920
37921
37922 /*
37923 ** Remove the page supplied as an argument from the hash table
@@ -37945,10 +38052,11 @@
37945 static void pcache1EnforceMaxPage(PGroup *pGroup){
37946 assert( sqlite3_mutex_held(pGroup->mutex) );
37947 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
37948 PgHdr1 *p = pGroup->pLruTail;
37949 assert( p->pCache->pGroup==pGroup );
 
37950 pcache1PinPage(p);
37951 pcache1RemoveFromHash(p);
37952 pcache1FreePage(p);
37953 }
37954 }
@@ -37972,11 +38080,11 @@
37972 PgHdr1 *pPage;
37973 while( (pPage = *pp)!=0 ){
37974 if( pPage->iKey>=iLimit ){
37975 pCache->nPage--;
37976 *pp = pPage->pNext;
37977 pcache1PinPage(pPage);
37978 pcache1FreePage(pPage);
37979 }else{
37980 pp = &pPage->pNext;
37981 TESTONLY( nPage++; )
37982 }
@@ -38195,12 +38303,15 @@
38195 unsigned int h = iKey % pCache->nHash;
38196 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
38197 }
38198
38199 /* Step 2: Abort if no existing page is found and createFlag is 0 */
38200 if( pPage || createFlag==0 ){
38201 pcache1PinPage(pPage);
 
 
 
38202 goto fetch_out;
38203 }
38204
38205 /* The pGroup local variable will normally be initialized by the
38206 ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38237,10 +38348,11 @@
38237 || pGroup->nCurrentPage>=pGroup->nMaxPage
38238 || pcache1UnderMemoryPressure(pCache)
38239 )){
38240 PCache1 *pOther;
38241 pPage = pGroup->pLruTail;
 
38242 pcache1RemoveFromHash(pPage);
38243 pcache1PinPage(pPage);
38244 pOther = pPage->pCache;
38245
38246 /* We want to verify that szPage and szExtra are the same for pOther
@@ -38273,10 +38385,11 @@
38273 pPage->iKey = iKey;
38274 pPage->pNext = pCache->apHash[h];
38275 pPage->pCache = pCache;
38276 pPage->pLruPrev = 0;
38277 pPage->pLruNext = 0;
 
38278 *(void **)pPage->page.pExtra = 0;
38279 pCache->apHash[h] = pPage;
38280 }
38281
38282 fetch_out:
@@ -38308,10 +38421,11 @@
38308 /* It is an error to call this function if the page is already
38309 ** part of the PGroup LRU list.
38310 */
38311 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
38312 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
 
38313
38314 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
38315 pcache1RemoveFromHash(pPage);
38316 pcache1FreePage(pPage);
38317 }else{
@@ -38323,10 +38437,11 @@
38323 }else{
38324 pGroup->pLruTail = pPage;
38325 pGroup->pLruHead = pPage;
38326 }
38327 pCache->nRecyclable++;
 
38328 }
38329
38330 pcache1LeaveMutex(pCache->pGroup);
38331 }
38332
@@ -38449,10 +38564,11 @@
38449 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
38450 nFree += pcache1MemSize(p->page.pBuf);
38451 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
38452 nFree += sqlite3MemSize(p);
38453 #endif
 
38454 pcache1PinPage(p);
38455 pcache1RemoveFromHash(p);
38456 pcache1FreePage(p);
38457 }
38458 pcache1LeaveMutex(&pcache1.grp);
@@ -38473,10 +38589,11 @@
38473 int *pnRecyclable /* OUT: Total number of pages available for recycling */
38474 ){
38475 PgHdr1 *p;
38476 int nRecyclable = 0;
38477 for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
 
38478 nRecyclable++;
38479 }
38480 *pnCurrent = pcache1.grp.nCurrentPage;
38481 *pnMax = (int)pcache1.grp.nMaxPage;
38482 *pnMin = (int)pcache1.grp.nMinPage;
@@ -40159,29 +40276,26 @@
40159 ** PagerSavepoint.pInSavepoint.
40160 */
40161 static int subjRequiresPage(PgHdr *pPg){
40162 Pager *pPager = pPg->pPager;
40163 PagerSavepoint *p;
40164 Pgno pgno;
40165 int i;
40166 if( pPager->nSavepoint ){
40167 pgno = pPg->pgno;
40168 for(i=0; i<pPager->nSavepoint; i++){
40169 p = &pPager->aSavepoint[i];
40170 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40171 return 1;
40172 }
40173 }
40174 }
40175 return 0;
40176 }
40177
40178 /*
40179 ** Return true if the page is already in the journal file.
40180 */
40181 static int pageInJournal(PgHdr *pPg){
40182 return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno);
40183 }
40184
40185 /*
40186 ** Read a 32-bit integer from the given file descriptor. Store the integer
40187 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40384,10 +40498,11 @@
40384
40385 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
40386 || szJ<16
40387 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
40388 || len>=nMaster
 
40389 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
40390 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
40391 || memcmp(aMagic, aJournalMagic, 8)
40392 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
40393 ){
@@ -41124,11 +41239,11 @@
41124 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
41125 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
41126 PgHdr *p = pager_lookup(pPager, 1);
41127 if( p ){
41128 p->pageHash = 0;
41129 sqlite3PagerUnref(p);
41130 }
41131 }
41132 #endif
41133
41134 sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41152,10 +41267,15 @@
41152 ** file. So it is safe to truncate the database file to its minimum
41153 ** required size. */
41154 assert( pPager->eLock==EXCLUSIVE_LOCK );
41155 rc = pager_truncate(pPager, pPager->dbSize);
41156 }
 
 
 
 
 
41157
41158 if( !pPager->exclusiveMode
41159 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
41160 ){
41161 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
@@ -41966,11 +42086,11 @@
41966 testcase( rc!=SQLITE_OK );
41967 }
41968 if( rc==SQLITE_OK
41969 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
41970 ){
41971 rc = sqlite3PagerSync(pPager);
41972 }
41973 if( rc==SQLITE_OK ){
41974 rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
41975 testcase( rc!=SQLITE_OK );
41976 }
@@ -42112,11 +42232,11 @@
42112 rc = readDbPage(pPg, iFrame);
42113 }
42114 if( rc==SQLITE_OK ){
42115 pPager->xReiniter(pPg);
42116 }
42117 sqlite3PagerUnref(pPg);
42118 }
42119 }
42120
42121 /* Normally, if a transaction is rolled back, any backup processes are
42122 ** updated as data is copied out of the rollback journal and into the
@@ -43467,11 +43587,11 @@
43467 /* Open the sub-journal, if it has not already been opened */
43468 assert( pPager->useJournal );
43469 assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
43470 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
43471 assert( pagerUseWal(pPager)
43472 || pageInJournal(pPg)
43473 || pPg->pgno>pPager->dbOrigSize
43474 );
43475 rc = openSubJournal(pPager);
43476
43477 /* If the sub-journal was opened successfully (or was already open),
@@ -44568,20 +44688,23 @@
44568 ** If the number of references to the page drop to zero, then the
44569 ** page is added to the LRU list. When all references to all pages
44570 ** are released, a rollback occurs and the lock on the database is
44571 ** removed.
44572 */
 
 
 
 
 
 
 
 
 
 
 
44573 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44574 if( pPg ){
44575 Pager *pPager = pPg->pPager;
44576 if( pPg->flags & PGHDR_MMAP ){
44577 pagerReleaseMapPage(pPg);
44578 }else{
44579 sqlite3PcacheRelease(pPg);
44580 }
44581 pagerUnlockIfUnused(pPager);
44582 }
44583 }
44584
44585 /*
44586 ** This function is called at the start of every write transaction.
44587 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44765,13 +44888,13 @@
44765 ** one of the journals, the corresponding bit is set in the
44766 ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
44767 ** of any open savepoints as appropriate.
44768 */
44769 static int pager_write(PgHdr *pPg){
44770 void *pData = pPg->pData;
44771 Pager *pPager = pPg->pPager;
44772 int rc = SQLITE_OK;
 
44773
44774 /* This routine is not called unless a write-transaction has already
44775 ** been started. The journal file may or may not be open at this point.
44776 ** It is never called in the ERROR state.
44777 */
@@ -44803,19 +44926,20 @@
44803
44804 /* Mark the page as dirty. If the page has already been written
44805 ** to the journal then we can return right away.
44806 */
44807 sqlite3PcacheMakeDirty(pPg);
44808 if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
 
44809 assert( !pagerUseWal(pPager) );
44810 }else{
44811
44812 /* The transaction journal now exists and we have a RESERVED or an
44813 ** EXCLUSIVE lock on the main database file. Write the current page to
44814 ** the transaction journal if it is not there already.
44815 */
44816 if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){
44817 assert( pagerUseWal(pPager)==0 );
44818 if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
44819 u32 cksum;
44820 char *pData2;
44821 i64 iOff = pPager->journalOff;
@@ -44824,11 +44948,11 @@
44824 ** contains the database locks. The following assert verifies
44825 ** that we do not. */
44826 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
44827
44828 assert( pPager->journalHdr<=pPager->journalOff );
44829 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44830 cksum = pager_cksum(pPager, (u8*)pData2);
44831
44832 /* Even if an IO or diskfull error occurs while journalling the
44833 ** page in the block above, set the need-sync flag for the page.
44834 ** Otherwise, when the transaction is rolled back, the logic in
@@ -44876,11 +45000,11 @@
44876 /* If the statement journal is open and the page is not in it,
44877 ** then write the current page to the statement journal. Note that
44878 ** the statement journal format differs from the standard journal format
44879 ** in that it omits the checksums and the header.
44880 */
44881 if( subjRequiresPage(pPg) ){
44882 rc = subjournalPage(pPg);
44883 }
44884 }
44885
44886 /* Update the database size and return.
@@ -44959,18 +45083,18 @@
44959 if( rc==SQLITE_OK ){
44960 rc = pager_write(pPage);
44961 if( pPage->flags&PGHDR_NEED_SYNC ){
44962 needSync = 1;
44963 }
44964 sqlite3PagerUnref(pPage);
44965 }
44966 }
44967 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
44968 if( pPage->flags&PGHDR_NEED_SYNC ){
44969 needSync = 1;
44970 }
44971 sqlite3PagerUnref(pPage);
44972 }
44973 }
44974
44975 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
44976 ** starting at pg1, then it needs to be set for all of them. Because
@@ -44982,11 +45106,11 @@
44982 assert( !MEMDB );
44983 for(ii=0; ii<nPage; ii++){
44984 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
44985 if( pPage ){
44986 pPage->flags |= PGHDR_NEED_SYNC;
44987 sqlite3PagerUnref(pPage);
44988 }
44989 }
44990 }
44991
44992 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45135,21 +45259,21 @@
45135 ** or pages with the Pager.noSync flag set.
45136 **
45137 ** If successful, or if called on a pager for which it is a no-op, this
45138 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
45139 */
45140 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
45141 int rc = SQLITE_OK;
45142 if( !pPager->noSync ){
 
 
 
 
 
 
45143 assert( !MEMDB );
45144 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
45145 }else if( isOpen(pPager->fd) ){
45146 assert( !MEMDB );
45147 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0);
45148 if( rc==SQLITE_NOTFOUND ){
45149 rc = SQLITE_OK;
45150 }
45151 }
45152 return rc;
45153 }
45154
45155 /*
@@ -45344,11 +45468,11 @@
45344 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
45345 }
45346
45347 /* Finally, sync the database file. */
45348 if( !noSync ){
45349 rc = sqlite3PagerSync(pPager);
45350 }
45351 IOTRACE(("DBSYNC %p\n", pPager))
45352 }
45353 }
45354
@@ -45473,11 +45597,13 @@
45473 rc = pager_playback(pPager, 0);
45474 }
45475
45476 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
45477 assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45478 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR );
 
 
45479
45480 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
45481 ** cache. So call pager_error() on the way out to make any error persistent.
45482 */
45483 return pager_error(pPager, rc);
@@ -45876,11 +46002,11 @@
45876 ** can be written to. The caller has already promised not to write to it.
45877 */
45878 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
45879 needSyncPgno = pPg->pgno;
45880 assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
45881 pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize );
45882 assert( pPg->flags&PGHDR_DIRTY );
45883 }
45884
45885 /* If the cache contains a page with page-number pgno, remove it
45886 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -45910,11 +46036,11 @@
45910 ** as the original page since it has already been allocated.
45911 */
45912 if( MEMDB ){
45913 assert( pPgOld );
45914 sqlite3PcacheMove(pPgOld, origPgno);
45915 sqlite3PagerUnref(pPgOld);
45916 }
45917
45918 if( needSyncPgno ){
45919 /* If needSyncPgno is non-zero, then the journal file needs to be
45920 ** sync()ed before any data is written to database file page needSyncPgno.
@@ -45939,11 +46065,11 @@
45939 }
45940 return rc;
45941 }
45942 pPgHdr->flags |= PGHDR_NEED_SYNC;
45943 sqlite3PcacheMakeDirty(pPgHdr);
45944 sqlite3PagerUnref(pPgHdr);
45945 }
45946
45947 return SQLITE_OK;
45948 }
45949 #endif
@@ -52079,14 +52205,15 @@
52079 */
52080 static void releasePage(MemPage *pPage){
52081 if( pPage ){
52082 assert( pPage->aData );
52083 assert( pPage->pBt );
 
52084 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
52085 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
52086 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52087 sqlite3PagerUnref(pPage->pDbPage);
52088 }
52089 }
52090
52091 /*
52092 ** During a rollback, when the pager reloads information into the cache
@@ -59413,11 +59540,11 @@
59413 rc = backupTruncateFile(pFile, iSize);
59414 }
59415
59416 /* Sync the database file to disk. */
59417 if( rc==SQLITE_OK ){
59418 rc = sqlite3PagerSync(pDestPager);
59419 }
59420 }else{
59421 sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
59422 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
59423 }
@@ -59488,14 +59615,14 @@
59488 /* If a transaction is still open on the Btree, roll it back. */
59489 sqlite3BtreeRollback(p->pDest, SQLITE_OK);
59490
59491 /* Set the error code of the destination database handle. */
59492 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
59493 sqlite3Error(p->pDestDb, rc, 0);
59494
59495 /* Exit the mutexes and free the backup context structure. */
59496 if( p->pDestDb ){
 
 
 
59497 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
59498 }
59499 sqlite3BtreeLeave(p->pSrc);
59500 if( p->pDestDb ){
59501 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -60117,10 +60244,13 @@
60117 if( pMem->flags & MEM_RowSet ){
60118 sqlite3RowSetClear(pMem->u.pRowSet);
60119 }
60120 MemSetTypeFlag(pMem, MEM_Null);
60121 pMem->type = SQLITE_NULL;
 
 
 
60122 }
60123
60124 /*
60125 ** Delete any previous value and set the value to be a BLOB of length
60126 ** n containing all zeros.
@@ -63440,10 +63570,11 @@
63440 sqlite3 *db = p->db;
63441 int rc = p->rc;
63442 if( p->zErrMsg ){
63443 u8 mallocFailed = db->mallocFailed;
63444 sqlite3BeginBenignMalloc();
 
63445 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63446 sqlite3EndBenignMalloc();
63447 db->mallocFailed = mallocFailed;
63448 db->errCode = rc;
63449 }else{
@@ -63508,12 +63639,11 @@
63508 }else if( p->rc && p->expired ){
63509 /* The expired flag was set on the VDBE before the first call
63510 ** to sqlite3_step(). For consistency (since sqlite3_step() was
63511 ** called), set the database error in this case as well.
63512 */
63513 sqlite3Error(db, p->rc, 0);
63514 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63515 sqlite3DbFree(db, p->zErrMsg);
63516 p->zErrMsg = 0;
63517 }
63518
63519 /* Reclaim all memory used by the VDBE
@@ -64883,20 +65013,21 @@
64883 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
64884 sqlite3_reset(pStmt);
64885 v->doingRerun = 1;
64886 assert( v->expired==0 );
64887 }
64888 if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
64889 /* This case occurs after failing to recompile an sql statement.
64890 ** The error message from the SQL compiler has already been loaded
64891 ** into the database handle. This block copies the error message
64892 ** from the database handle into the statement and sets the statement
64893 ** program counter to 0 to ensure that when the statement is
64894 ** finalized or reset the parser error message is available via
64895 ** sqlite3_errmsg() and sqlite3_errcode().
64896 */
64897 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
 
64898 sqlite3DbFree(db, v->zErrMsg);
64899 if( !db->mallocFailed ){
64900 v->zErrMsg = sqlite3DbStrDup(db, zErr);
64901 v->rc = rc2;
64902 } else {
@@ -65841,13 +65972,13 @@
65841 assert( idx>0 && idx<=p->nVar );
65842 pVar = &p->aVar[idx-1];
65843 if( pVar->flags & MEM_Null ){
65844 sqlite3StrAccumAppend(&out, "NULL", 4);
65845 }else if( pVar->flags & MEM_Int ){
65846 sqlite3XPrintf(&out, "%lld", pVar->u.i);
65847 }else if( pVar->flags & MEM_Real ){
65848 sqlite3XPrintf(&out, "%!.15g", pVar->r);
65849 }else if( pVar->flags & MEM_Str ){
65850 int nOut; /* Number of bytes of the string text to include in output */
65851 #ifndef SQLITE_OMIT_UTF16
65852 u8 enc = ENC(db);
65853 Mem utf8;
@@ -65864,33 +65995,37 @@
65864 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
65865 nOut = SQLITE_TRACE_SIZE_LIMIT;
65866 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
65867 }
65868 #endif
65869 sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
65870 #ifdef SQLITE_TRACE_SIZE_LIMIT
65871 if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
 
 
65872 #endif
65873 #ifndef SQLITE_OMIT_UTF16
65874 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
65875 #endif
65876 }else if( pVar->flags & MEM_Zero ){
65877 sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
65878 }else{
65879 int nOut; /* Number of bytes of the blob to include in output */
65880 assert( pVar->flags & MEM_Blob );
65881 sqlite3StrAccumAppend(&out, "x'", 2);
65882 nOut = pVar->n;
65883 #ifdef SQLITE_TRACE_SIZE_LIMIT
65884 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
65885 #endif
65886 for(i=0; i<nOut; i++){
65887 sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
65888 }
65889 sqlite3StrAccumAppend(&out, "'", 1);
65890 #ifdef SQLITE_TRACE_SIZE_LIMIT
65891 if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
 
 
65892 #endif
65893 }
65894 }
65895 }
65896 return sqlite3StrAccumFinish(&out);
@@ -65945,11 +66080,11 @@
65945 int n = p->nIndent;
65946 if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
65947 sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
65948 }
65949 va_start(ap, zFormat);
65950 sqlite3VXPrintf(&p->str, 1, zFormat, ap);
65951 va_end(ap);
65952 }
65953 }
65954
65955 /*
@@ -88246,11 +88381,10 @@
88246 int bestScore = 0; /* Score of best match */
88247 int h; /* Hash value */
88248
88249 assert( nArg>=(-2) );
88250 assert( nArg>=(-1) || createFlag==0 );
88251 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
88252 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
88253
88254 /* First search for a match amongst the application-defined functions.
88255 */
88256 p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89397,10 +89531,36 @@
89397 }while( isText && (zHaystack[0]&0xc0)==0x80 );
89398 }
89399 if( nNeedle>nHaystack ) N = 0;
89400 sqlite3_result_int(context, N);
89401 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89402
89403 /*
89404 ** Implementation of the substr() function.
89405 **
89406 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -90828,10 +90988,11 @@
90828 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
90829 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
90830 FUNCTION(instr, 2, 0, 0, instrFunc ),
90831 FUNCTION(substr, 2, 0, 0, substrFunc ),
90832 FUNCTION(substr, 3, 0, 0, substrFunc ),
 
90833 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
90834 FUNCTION(char, -1, 0, 0, charFunc ),
90835 FUNCTION(abs, 1, 0, 0, absFunc ),
90836 #ifndef SQLITE_OMIT_FLOATING_POINT
90837 FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -119433,13 +119594,11 @@
119433 }
119434 sqlite3HashClear(&db->aModule);
119435 #endif
119436
119437 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119438 if( db->pErr ){
119439 sqlite3ValueFree(db->pErr);
119440 }
119441 sqlite3CloseExtensions(db);
119442
119443 db->magic = SQLITE_MAGIC_ERROR;
119444
119445 /* The temp-database schema is allocated differently from the other schema
@@ -119818,10 +119977,11 @@
119818 void (*xFinal)(sqlite3_context*),
119819 FuncDestructor *pDestructor
119820 ){
119821 FuncDef *p;
119822 int nName;
 
119823
119824 assert( sqlite3_mutex_held(db->mutex) );
119825 if( zFunctionName==0 ||
119826 (xFunc && (xFinal || xStep)) ||
119827 (!xFunc && (xFinal && !xStep)) ||
@@ -119828,10 +119988,14 @@
119828 (!xFunc && (!xFinal && xStep)) ||
119829 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
119830 (255<(nName = sqlite3Strlen30( zFunctionName))) ){
119831 return SQLITE_MISUSE_BKPT;
119832 }
 
 
 
 
119833
119834 #ifndef SQLITE_OMIT_UTF16
119835 /* If SQLITE_UTF16 is specified as the encoding type, transform this
119836 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
119837 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -119841,14 +120005,14 @@
119841 */
119842 if( enc==SQLITE_UTF16 ){
119843 enc = SQLITE_UTF16NATIVE;
119844 }else if( enc==SQLITE_ANY ){
119845 int rc;
119846 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
119847 pUserData, xFunc, xStep, xFinal, pDestructor);
119848 if( rc==SQLITE_OK ){
119849 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
119850 pUserData, xFunc, xStep, xFinal, pDestructor);
119851 }
119852 if( rc!=SQLITE_OK ){
119853 return rc;
119854 }
@@ -119887,11 +120051,12 @@
119887
119888 if( pDestructor ){
119889 pDestructor->nRef++;
119890 }
119891 p->pDestructor = pDestructor;
119892 p->funcFlags &= SQLITE_FUNC_ENCMASK;
 
119893 p->xFunc = xFunc;
119894 p->xStep = xStep;
119895 p->xFinalize = xFinal;
119896 p->pUserData = pUserData;
119897 p->nArg = (u16)nArg;
@@ -120317,10 +120482,11 @@
120317 }
120318 sqlite3_mutex_enter(db->mutex);
120319 if( db->mallocFailed ){
120320 z = sqlite3ErrStr(SQLITE_NOMEM);
120321 }else{
 
120322 z = (char*)sqlite3_value_text(db->pErr);
120323 assert( !db->mallocFailed );
120324 if( z==0 ){
120325 z = sqlite3ErrStr(db->errCode);
120326 }
@@ -120358,12 +120524,11 @@
120358 if( db->mallocFailed ){
120359 z = (void *)outOfMem;
120360 }else{
120361 z = sqlite3_value_text16(db->pErr);
120362 if( z==0 ){
120363 sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode),
120364 SQLITE_UTF8, SQLITE_STATIC);
120365 z = sqlite3_value_text16(db->pErr);
120366 }
120367 /* A malloc() may have failed within the call to sqlite3_value_text16()
120368 ** above. If this is the case, then the db->mallocFailed flag needs to
120369 ** be cleared before returning. Do this directly, instead of via
@@ -121073,12 +121238,10 @@
121073 if( !db->mallocFailed && rc==SQLITE_OK){
121074 rc = sqlite3RtreeInit(db);
121075 }
121076 #endif
121077
121078 sqlite3Error(db, rc, 0);
121079
121080 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121081 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121082 ** mode. Doing nothing at all also makes NORMAL the default.
121083 */
121084 #ifdef SQLITE_DEFAULT_LOCKING_MODE
121085
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2013-12-17 16:32:56 93121d3097a43997af3c0de65bd9bd7663845fa2"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -817,19 +817,33 @@
817 ** to the [sqlite3_file] object associated with a particular database
818 ** connection. See the [sqlite3_file_control()] documentation for
819 ** additional information.
820 **
821 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
822 ** No longer in use.
823 **
824 ** <li>[[SQLITE_FCNTL_SYNC]]
825 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
826 ** sent to the VFS immediately before the xSync method is invoked on a
827 ** database file descriptor. Or, if the xSync method is not invoked
828 ** because the user has configured SQLite with
829 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
830 ** of the xSync method. In most cases, the pointer argument passed with
831 ** this file-control is NULL. However, if the database file is being synced
832 ** as part of a multi-database commit, the argument points to a nul-terminated
833 ** string containing the transactions master-journal file name. VFSes that
834 ** do not need this signal should silently ignore this opcode. Applications
835 ** should not call [sqlite3_file_control()] with this opcode as doing so may
836 ** disrupt the operation of the specialized VFSes that do require it.
837 **
838 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
839 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
840 ** and sent to the VFS after a transaction has been committed immediately
841 ** but before the database is unlocked. VFSes that do not need this signal
842 ** should silently ignore this opcode. Applications should not call
843 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
844 ** operation of the specialized VFSes that do require it.
845 **
846 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
847 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
848 ** retry counts and intervals for certain disk I/O operations for the
849 ** windows [VFS] in order to provide robustness in the presence of
@@ -976,10 +990,12 @@
990 #define SQLITE_FCNTL_BUSYHANDLER 15
991 #define SQLITE_FCNTL_TEMPFILENAME 16
992 #define SQLITE_FCNTL_MMAP_SIZE 18
993 #define SQLITE_FCNTL_TRACE 19
994 #define SQLITE_FCNTL_HAS_MOVED 20
995 #define SQLITE_FCNTL_SYNC 21
996 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
997
998 /*
999 ** CAPI3REF: Mutex Handle
1000 **
1001 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3992,19 +4008,28 @@
4008 ** parameter is less than -1 or greater than 127 then the behavior is
4009 ** undefined.
4010 **
4011 ** ^The fourth parameter, eTextRep, specifies what
4012 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
4013 ** its parameters. The application should set this parameter to
4014 ** [SQLITE_UTF16LE] if the function implementation invokes
4015 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
4016 ** implementation invokes [sqlite3_value_text16be()] on an input, or
4017 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
4018 ** otherwise. ^The same SQL function may be registered multiple times using
4019 ** different preferred text encodings, with different implementations for
4020 ** each encoding.
4021 ** ^When multiple implementations of the same function are available, SQLite
4022 ** will pick the one that involves the least amount of data conversion.
4023 **
4024 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
4025 ** to signal that the function will always return the same result given
4026 ** the same inputs within a single SQL statement. Most SQL functions are
4027 ** deterministic. The built-in [random()] SQL function is an example of a
4028 ** function that is not deterministic. The SQLite query planner is able to
4029 ** perform additional optimizations on deterministic functions, so use
4030 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4031 **
4032 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4033 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4034 **
4035 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4086,13 +4111,23 @@
4111 */
4112 #define SQLITE_UTF8 1
4113 #define SQLITE_UTF16LE 2
4114 #define SQLITE_UTF16BE 3
4115 #define SQLITE_UTF16 4 /* Use native byte order */
4116 #define SQLITE_ANY 5 /* Deprecated */
4117 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4118
4119 /*
4120 ** CAPI3REF: Function Flags
4121 **
4122 ** These constants may be ORed together with the
4123 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4124 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4125 ** [sqlite3_create_function_v2()].
4126 */
4127 #define SQLITE_DETERMINISTIC 0x800
4128
4129 /*
4130 ** CAPI3REF: Deprecated Functions
4131 ** DEPRECATED
4132 **
4133 ** These functions are [deprecated]. In order to maintain
@@ -8590,10 +8625,11 @@
8625 typedef struct Lookaside Lookaside;
8626 typedef struct LookasideSlot LookasideSlot;
8627 typedef struct Module Module;
8628 typedef struct NameContext NameContext;
8629 typedef struct Parse Parse;
8630 typedef struct PrintfArguments PrintfArguments;
8631 typedef struct RowSet RowSet;
8632 typedef struct Savepoint Savepoint;
8633 typedef struct Select Select;
8634 typedef struct SelectDest SelectDest;
8635 typedef struct SrcList SrcList;
@@ -9448,10 +9484,11 @@
9484 SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
9485 #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
9486 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
9487 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
9488 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
9489 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
9490
9491 /* Operations on page references. */
9492 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
9493 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
9494 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -9462,11 +9499,11 @@
9499 /* Functions used to manage pager transactions and savepoints. */
9500 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
9501 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
9502 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
9503 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
9504 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
9505 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
9506 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
9507 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
9508 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
9509 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -12043,14 +12080,24 @@
12080 SQLITE_PRIVATE int sqlite3IsNaN(double);
12081 #else
12082 # define sqlite3IsNaN(X) 0
12083 #endif
12084
12085 /*
12086 ** An instance of the following structure holds information about SQL
12087 ** functions arguments that are the parameters to the printf() function.
12088 */
12089 struct PrintfArguments {
12090 int nArg; /* Total number of arguments */
12091 int nUsed; /* Number of arguments used so far */
12092 sqlite3_value **apArg; /* The argument values */
12093 };
12094
12095 #define SQLITE_PRINTF_INTERNAL 0x01
12096 #define SQLITE_PRINTF_SQLFUNC 0x02
12097 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list);
12098 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...);
12099 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
12100 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
12101 SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...);
12102 #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
12103 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
@@ -12436,10 +12483,11 @@
12483
12484 SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8);
12485 SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8);
12486 SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
12487 void(*)(void*));
12488 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*);
12489 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*);
12490 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *);
12491 SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8);
12492 SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **);
12493 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
@@ -19894,14 +19942,31 @@
19942 }
19943
19944 /*
19945 ** Set the StrAccum object to an error mode.
19946 */
19947 static void setStrAccumError(StrAccum *p, u8 eError){
19948 p->accError = eError;
19949 p->nAlloc = 0;
19950 }
19951
19952 /*
19953 ** Extra argument values from a PrintfArguments object
19954 */
19955 static sqlite3_int64 getIntArg(PrintfArguments *p){
19956 if( p->nArg<=p->nUsed ) return 0;
19957 return sqlite3_value_int64(p->apArg[p->nUsed++]);
19958 }
19959 static double getDoubleArg(PrintfArguments *p){
19960 if( p->nArg<=p->nUsed ) return 0.0;
19961 return sqlite3_value_double(p->apArg[p->nUsed++]);
19962 }
19963 static char *getTextArg(PrintfArguments *p){
19964 if( p->nArg<=p->nUsed ) return 0;
19965 return (char*)sqlite3_value_text(p->apArg[p->nUsed++]);
19966 }
19967
19968
19969 /*
19970 ** On machines with a small stack size, you can redefine the
19971 ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired.
19972 */
@@ -19912,14 +19977,14 @@
19977
19978 /*
19979 ** Render a string given by "fmt" into the StrAccum object.
19980 */
19981 SQLITE_PRIVATE void sqlite3VXPrintf(
19982 StrAccum *pAccum, /* Accumulate results here */
19983 u32 bFlags, /* SQLITE_PRINTF_* flags */
19984 const char *fmt, /* Format string */
19985 va_list ap /* arguments */
19986 ){
19987 int c; /* Next character in the format string */
19988 char *bufpt; /* Pointer to the conversion buffer */
19989 int precision; /* Precision of the current field */
19990 int length; /* Length of the field */
@@ -19933,10 +19998,12 @@
19998 etByte flag_zeropad; /* True if field width constant starts with zero */
19999 etByte flag_long; /* True if "l" flag is present */
20000 etByte flag_longlong; /* True if the "ll" flag is present */
20001 etByte done; /* Loop termination flag */
20002 etByte xtype = 0; /* Conversion paradigm */
20003 u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */
20004 u8 useIntern; /* Ok to use internal conversions (ex: %T) */
20005 char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */
20006 sqlite_uint64 longvalue; /* Value for integer types */
20007 LONGDOUBLE_TYPE realvalue; /* Value for real types */
20008 const et_info *infop; /* Pointer to the appropriate info structure */
20009 char *zOut; /* Rendering buffer */
@@ -19947,13 +20014,22 @@
20014 int nsd; /* Number of significant digits returned */
20015 double rounder; /* Used for rounding floating point values */
20016 etByte flag_dp; /* True if decimal point should be shown */
20017 etByte flag_rtz; /* True if trailing zeros should be removed */
20018 #endif
20019 PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */
20020 char buf[etBUFSIZE]; /* Conversion buffer */
20021
20022 bufpt = 0;
20023 if( bFlags ){
20024 if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){
20025 pArgList = va_arg(ap, PrintfArguments*);
20026 }
20027 useIntern = bFlags & SQLITE_PRINTF_INTERNAL;
20028 }else{
20029 bArgList = useIntern = 0;
20030 }
20031 for(; (c=(*fmt))!=0; ++fmt){
20032 if( c!='%' ){
20033 int amt;
20034 bufpt = (char *)fmt;
20035 amt = 1;
@@ -19981,11 +20057,15 @@
20057 }
20058 }while( !done && (c=(*++fmt))!=0 );
20059 /* Get the field width */
20060 width = 0;
20061 if( c=='*' ){
20062 if( bArgList ){
20063 width = (int)getIntArg(pArgList);
20064 }else{
20065 width = va_arg(ap,int);
20066 }
20067 if( width<0 ){
20068 flag_leftjustify = 1;
20069 width = -width;
20070 }
20071 c = *++fmt;
@@ -19998,11 +20078,15 @@
20078 /* Get the precision */
20079 if( c=='.' ){
20080 precision = 0;
20081 c = *++fmt;
20082 if( c=='*' ){
20083 if( bArgList ){
20084 precision = (int)getIntArg(pArgList);
20085 }else{
20086 precision = va_arg(ap,int);
20087 }
20088 if( precision<0 ) precision = -precision;
20089 c = *++fmt;
20090 }else{
20091 while( c>='0' && c<='9' ){
20092 precision = precision*10 + c - '0';
@@ -20029,11 +20113,11 @@
20113 infop = &fmtinfo[0];
20114 xtype = etINVALID;
20115 for(idx=0; idx<ArraySize(fmtinfo); idx++){
20116 if( c==fmtinfo[idx].fmttype ){
20117 infop = &fmtinfo[idx];
20118 if( useIntern || (infop->flags & FLAG_INTERN)==0 ){
20119 xtype = infop->type;
20120 }else{
20121 return;
20122 }
20123 break;
@@ -20069,11 +20153,13 @@
20153 /* Fall through into the next case */
20154 case etORDINAL:
20155 case etRADIX:
20156 if( infop->flags & FLAG_SIGNED ){
20157 i64 v;
20158 if( bArgList ){
20159 v = getIntArg(pArgList);
20160 }else if( flag_longlong ){
20161 v = va_arg(ap,i64);
20162 }else if( flag_long ){
20163 v = va_arg(ap,long int);
20164 }else{
20165 v = va_arg(ap,int);
@@ -20090,11 +20176,13 @@
20176 if( flag_plussign ) prefix = '+';
20177 else if( flag_blanksign ) prefix = ' ';
20178 else prefix = 0;
20179 }
20180 }else{
20181 if( bArgList ){
20182 longvalue = (u64)getIntArg(pArgList);
20183 }else if( flag_longlong ){
20184 longvalue = va_arg(ap,u64);
20185 }else if( flag_long ){
20186 longvalue = va_arg(ap,unsigned long int);
20187 }else{
20188 longvalue = va_arg(ap,unsigned int);
@@ -20150,11 +20238,15 @@
20238 length = (int)(&zOut[nOut-1]-bufpt);
20239 break;
20240 case etFLOAT:
20241 case etEXP:
20242 case etGENERIC:
20243 if( bArgList ){
20244 realvalue = getDoubleArg(pArgList);
20245 }else{
20246 realvalue = va_arg(ap,double);
20247 }
20248 #ifdef SQLITE_OMIT_FLOATING_POINT
20249 length = 0;
20250 #else
20251 if( precision<0 ) precision = 6; /* Set default precision */
20252 if( realvalue<0.0 ){
@@ -20305,20 +20397,27 @@
20397 length = width;
20398 }
20399 #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */
20400 break;
20401 case etSIZE:
20402 if( !bArgList ){
20403 *(va_arg(ap,int*)) = pAccum->nChar;
20404 }
20405 length = width = 0;
20406 break;
20407 case etPERCENT:
20408 buf[0] = '%';
20409 bufpt = buf;
20410 length = 1;
20411 break;
20412 case etCHARX:
20413 if( bArgList ){
20414 bufpt = getTextArg(pArgList);
20415 c = bufpt ? bufpt[0] : 0;
20416 }else{
20417 c = va_arg(ap,int);
20418 }
20419 buf[0] = (char)c;
20420 if( precision>=0 ){
20421 for(idx=1; idx<precision; idx++) buf[idx] = (char)c;
20422 length = precision;
20423 }else{
@@ -20326,14 +20425,18 @@
20425 }
20426 bufpt = buf;
20427 break;
20428 case etSTRING:
20429 case etDYNSTRING:
20430 if( bArgList ){
20431 bufpt = getTextArg(pArgList);
20432 }else{
20433 bufpt = va_arg(ap,char*);
20434 }
20435 if( bufpt==0 ){
20436 bufpt = "";
20437 }else if( xtype==etDYNSTRING && !bArgList ){
20438 zExtra = bufpt;
20439 }
20440 if( precision>=0 ){
20441 for(length=0; length<precision && bufpt[length]; length++){}
20442 }else{
@@ -20345,11 +20448,17 @@
20448 case etSQLESCAPE3: {
20449 int i, j, k, n, isnull;
20450 int needQuote;
20451 char ch;
20452 char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */
20453 char *escarg;
20454
20455 if( bArgList ){
20456 escarg = getTextArg(pArgList);
20457 }else{
20458 escarg = va_arg(ap,char*);
20459 }
20460 isnull = escarg==0;
20461 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
20462 k = precision;
20463 for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){
20464 if( ch==q ) n++;
@@ -20380,10 +20489,11 @@
20489 ** if( precision>=0 && precision<length ) length = precision; */
20490 break;
20491 }
20492 case etTOKEN: {
20493 Token *pToken = va_arg(ap, Token*);
20494 assert( bArgList==0 );
20495 if( pToken && pToken->n ){
20496 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
20497 }
20498 length = width = 0;
20499 break;
@@ -20390,10 +20500,11 @@
20500 }
20501 case etSRCLIST: {
20502 SrcList *pSrc = va_arg(ap, SrcList*);
20503 int k = va_arg(ap, int);
20504 struct SrcList_item *pItem = &pSrc->a[k];
20505 assert( bArgList==0 );
20506 assert( k>=0 && k<pSrc->nSrc );
20507 if( pItem->zDatabase ){
20508 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
20509 sqlite3StrAccumAppend(pAccum, ".", 1);
20510 }
@@ -20426,11 +20537,11 @@
20537 nspace = width-length;
20538 if( nspace>0 ){
20539 sqlite3AppendSpace(pAccum, nspace);
20540 }
20541 }
20542 if( zExtra ) sqlite3_free(zExtra);
20543 }/* End for loop over the format string */
20544 } /* End of function */
20545
20546 /*
20547 ** Append N bytes of text from z to the StrAccum object.
@@ -20553,11 +20664,11 @@
20664 StrAccum acc;
20665 assert( db!=0 );
20666 sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
20667 db->aLimit[SQLITE_LIMIT_LENGTH]);
20668 acc.db = db;
20669 sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap);
20670 z = sqlite3StrAccumFinish(&acc);
20671 if( acc.accError==STRACCUM_NOMEM ){
20672 db->mallocFailed = 1;
20673 }
20674 return z;
@@ -20709,21 +20820,19 @@
20820 fprintf(stdout,"%s", zBuf);
20821 fflush(stdout);
20822 }
20823 #endif
20824
 
20825 /*
20826 ** variable-argument wrapper around sqlite3VXPrintf().
20827 */
20828 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){
20829 va_list ap;
20830 va_start(ap,zFormat);
20831 sqlite3VXPrintf(p, bFlags, zFormat, ap);
20832 va_end(ap);
20833 }
 
20834
20835 /************** End of printf.c **********************************************/
20836 /************** Begin file random.c ******************************************/
20837 /*
20838 ** 2001 September 15
@@ -21494,22 +21603,21 @@
21603 ** To clear the most recent error for sqlite handle "db", sqlite3Error
21604 ** should be called with err_code set to SQLITE_OK and zFormat set
21605 ** to NULL.
21606 */
21607 SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){
21608 assert( db!=0 );
21609 db->errCode = err_code;
21610 if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){
21611 char *z;
21612 va_list ap;
21613 va_start(ap, zFormat);
21614 z = sqlite3VMPrintf(db, zFormat, ap);
21615 va_end(ap);
21616 sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC);
21617 }else if( db->pErr ){
21618 sqlite3ValueSetNull(db->pErr);
 
21619 }
21620 }
21621
21622 /*
21623 ** Add an error message to pParse->zErrMsg and increment pParse->nErr.
@@ -37558,10 +37666,11 @@
37666 ** in memory.
37667 */
37668 struct PgHdr1 {
37669 sqlite3_pcache_page page;
37670 unsigned int iKey; /* Key value (page number) */
37671 u8 isPinned; /* Page in use, not on the LRU list */
37672 PgHdr1 *pNext; /* Next in hash table chain */
37673 PCache1 *pCache; /* Cache that currently owns this page */
37674 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
37675 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
37676 };
@@ -37886,38 +37995,36 @@
37995 ** This function is used internally to remove the page pPage from the
37996 ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup
37997 ** LRU list, then this function is a no-op.
37998 **
37999 ** The PGroup mutex must be held when this function is called.
 
 
38000 */
38001 static void pcache1PinPage(PgHdr1 *pPage){
38002 PCache1 *pCache;
38003 PGroup *pGroup;
38004
38005 assert( pPage!=0 );
38006 assert( pPage->isPinned==0 );
38007 pCache = pPage->pCache;
38008 pGroup = pCache->pGroup;
38009 assert( pPage->pLruNext || pPage==pGroup->pLruTail );
38010 assert( pPage->pLruPrev || pPage==pGroup->pLruHead );
38011 assert( sqlite3_mutex_held(pGroup->mutex) );
38012 if( pPage->pLruPrev ){
38013 pPage->pLruPrev->pLruNext = pPage->pLruNext;
38014 }else{
38015 pGroup->pLruHead = pPage->pLruNext;
38016 }
38017 if( pPage->pLruNext ){
38018 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
38019 }else{
38020 pGroup->pLruTail = pPage->pLruPrev;
38021 }
38022 pPage->pLruNext = 0;
38023 pPage->pLruPrev = 0;
38024 pPage->isPinned = 1;
38025 pCache->nRecyclable--;
 
 
 
38026 }
38027
38028
38029 /*
38030 ** Remove the page supplied as an argument from the hash table
@@ -37945,10 +38052,11 @@
38052 static void pcache1EnforceMaxPage(PGroup *pGroup){
38053 assert( sqlite3_mutex_held(pGroup->mutex) );
38054 while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){
38055 PgHdr1 *p = pGroup->pLruTail;
38056 assert( p->pCache->pGroup==pGroup );
38057 assert( p->isPinned==0 );
38058 pcache1PinPage(p);
38059 pcache1RemoveFromHash(p);
38060 pcache1FreePage(p);
38061 }
38062 }
@@ -37972,11 +38080,11 @@
38080 PgHdr1 *pPage;
38081 while( (pPage = *pp)!=0 ){
38082 if( pPage->iKey>=iLimit ){
38083 pCache->nPage--;
38084 *pp = pPage->pNext;
38085 if( !pPage->isPinned ) pcache1PinPage(pPage);
38086 pcache1FreePage(pPage);
38087 }else{
38088 pp = &pPage->pNext;
38089 TESTONLY( nPage++; )
38090 }
@@ -38195,12 +38303,15 @@
38303 unsigned int h = iKey % pCache->nHash;
38304 for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext);
38305 }
38306
38307 /* Step 2: Abort if no existing page is found and createFlag is 0 */
38308 if( pPage ){
38309 if( !pPage->isPinned ) pcache1PinPage(pPage);
38310 goto fetch_out;
38311 }
38312 if( createFlag==0 ){
38313 goto fetch_out;
38314 }
38315
38316 /* The pGroup local variable will normally be initialized by the
38317 ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined,
@@ -38237,10 +38348,11 @@
38348 || pGroup->nCurrentPage>=pGroup->nMaxPage
38349 || pcache1UnderMemoryPressure(pCache)
38350 )){
38351 PCache1 *pOther;
38352 pPage = pGroup->pLruTail;
38353 assert( pPage->isPinned==0 );
38354 pcache1RemoveFromHash(pPage);
38355 pcache1PinPage(pPage);
38356 pOther = pPage->pCache;
38357
38358 /* We want to verify that szPage and szExtra are the same for pOther
@@ -38273,10 +38385,11 @@
38385 pPage->iKey = iKey;
38386 pPage->pNext = pCache->apHash[h];
38387 pPage->pCache = pCache;
38388 pPage->pLruPrev = 0;
38389 pPage->pLruNext = 0;
38390 pPage->isPinned = 1;
38391 *(void **)pPage->page.pExtra = 0;
38392 pCache->apHash[h] = pPage;
38393 }
38394
38395 fetch_out:
@@ -38308,10 +38421,11 @@
38421 /* It is an error to call this function if the page is already
38422 ** part of the PGroup LRU list.
38423 */
38424 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
38425 assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage );
38426 assert( pPage->isPinned==1 );
38427
38428 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
38429 pcache1RemoveFromHash(pPage);
38430 pcache1FreePage(pPage);
38431 }else{
@@ -38323,10 +38437,11 @@
38437 }else{
38438 pGroup->pLruTail = pPage;
38439 pGroup->pLruHead = pPage;
38440 }
38441 pCache->nRecyclable++;
38442 pPage->isPinned = 0;
38443 }
38444
38445 pcache1LeaveMutex(pCache->pGroup);
38446 }
38447
@@ -38449,10 +38564,11 @@
38564 while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
38565 nFree += pcache1MemSize(p->page.pBuf);
38566 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
38567 nFree += sqlite3MemSize(p);
38568 #endif
38569 assert( p->isPinned==0 );
38570 pcache1PinPage(p);
38571 pcache1RemoveFromHash(p);
38572 pcache1FreePage(p);
38573 }
38574 pcache1LeaveMutex(&pcache1.grp);
@@ -38473,10 +38589,11 @@
38589 int *pnRecyclable /* OUT: Total number of pages available for recycling */
38590 ){
38591 PgHdr1 *p;
38592 int nRecyclable = 0;
38593 for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){
38594 assert( p->isPinned==0 );
38595 nRecyclable++;
38596 }
38597 *pnCurrent = pcache1.grp.nCurrentPage;
38598 *pnMax = (int)pcache1.grp.nMaxPage;
38599 *pnMin = (int)pcache1.grp.nMinPage;
@@ -40159,29 +40276,26 @@
40276 ** PagerSavepoint.pInSavepoint.
40277 */
40278 static int subjRequiresPage(PgHdr *pPg){
40279 Pager *pPager = pPg->pPager;
40280 PagerSavepoint *p;
40281 Pgno pgno = pPg->pgno;
40282 int i;
40283 for(i=0; i<pPager->nSavepoint; i++){
40284 p = &pPager->aSavepoint[i];
40285 if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){
40286 return 1;
 
 
 
40287 }
40288 }
40289 return 0;
40290 }
40291
40292 /*
40293 ** Return true if the page is already in the journal file.
40294 */
40295 static int pageInJournal(Pager *pPager, PgHdr *pPg){
40296 return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno);
40297 }
40298
40299 /*
40300 ** Read a 32-bit integer from the given file descriptor. Store the integer
40301 ** that is read in *pRes. Return SQLITE_OK if everything worked, or an
@@ -40384,10 +40498,11 @@
40498
40499 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
40500 || szJ<16
40501 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
40502 || len>=nMaster
40503 || len==0
40504 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
40505 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
40506 || memcmp(aMagic, aJournalMagic, 8)
40507 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
40508 ){
@@ -41124,11 +41239,11 @@
41239 sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
41240 if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
41241 PgHdr *p = pager_lookup(pPager, 1);
41242 if( p ){
41243 p->pageHash = 0;
41244 sqlite3PagerUnrefNotNull(p);
41245 }
41246 }
41247 #endif
41248
41249 sqlite3BitvecDestroy(pPager->pInJournal);
@@ -41152,10 +41267,15 @@
41267 ** file. So it is safe to truncate the database file to its minimum
41268 ** required size. */
41269 assert( pPager->eLock==EXCLUSIVE_LOCK );
41270 rc = pager_truncate(pPager, pPager->dbSize);
41271 }
41272
41273 if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){
41274 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
41275 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
41276 }
41277
41278 if( !pPager->exclusiveMode
41279 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
41280 ){
41281 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
@@ -41966,11 +42086,11 @@
42086 testcase( rc!=SQLITE_OK );
42087 }
42088 if( rc==SQLITE_OK
42089 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
42090 ){
42091 rc = sqlite3PagerSync(pPager, 0);
42092 }
42093 if( rc==SQLITE_OK ){
42094 rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
42095 testcase( rc!=SQLITE_OK );
42096 }
@@ -42112,11 +42232,11 @@
42232 rc = readDbPage(pPg, iFrame);
42233 }
42234 if( rc==SQLITE_OK ){
42235 pPager->xReiniter(pPg);
42236 }
42237 sqlite3PagerUnrefNotNull(pPg);
42238 }
42239 }
42240
42241 /* Normally, if a transaction is rolled back, any backup processes are
42242 ** updated as data is copied out of the rollback journal and into the
@@ -43467,11 +43587,11 @@
43587 /* Open the sub-journal, if it has not already been opened */
43588 assert( pPager->useJournal );
43589 assert( isOpen(pPager->jfd) || pagerUseWal(pPager) );
43590 assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 );
43591 assert( pagerUseWal(pPager)
43592 || pageInJournal(pPager, pPg)
43593 || pPg->pgno>pPager->dbOrigSize
43594 );
43595 rc = openSubJournal(pPager);
43596
43597 /* If the sub-journal was opened successfully (or was already open),
@@ -44568,20 +44688,23 @@
44688 ** If the number of references to the page drop to zero, then the
44689 ** page is added to the LRU list. When all references to all pages
44690 ** are released, a rollback occurs and the lock on the database is
44691 ** removed.
44692 */
44693 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
44694 Pager *pPager;
44695 assert( pPg!=0 );
44696 pPager = pPg->pPager;
44697 if( pPg->flags & PGHDR_MMAP ){
44698 pagerReleaseMapPage(pPg);
44699 }else{
44700 sqlite3PcacheRelease(pPg);
44701 }
44702 pagerUnlockIfUnused(pPager);
44703 }
44704 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
44705 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
 
 
 
 
 
 
 
 
44706 }
44707
44708 /*
44709 ** This function is called at the start of every write transaction.
44710 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -44765,13 +44888,13 @@
44888 ** one of the journals, the corresponding bit is set in the
44889 ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
44890 ** of any open savepoints as appropriate.
44891 */
44892 static int pager_write(PgHdr *pPg){
 
44893 Pager *pPager = pPg->pPager;
44894 int rc = SQLITE_OK;
44895 int inJournal;
44896
44897 /* This routine is not called unless a write-transaction has already
44898 ** been started. The journal file may or may not be open at this point.
44899 ** It is never called in the ERROR state.
44900 */
@@ -44803,19 +44926,20 @@
44926
44927 /* Mark the page as dirty. If the page has already been written
44928 ** to the journal then we can return right away.
44929 */
44930 sqlite3PcacheMakeDirty(pPg);
44931 inJournal = pageInJournal(pPager, pPg);
44932 if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){
44933 assert( !pagerUseWal(pPager) );
44934 }else{
44935
44936 /* The transaction journal now exists and we have a RESERVED or an
44937 ** EXCLUSIVE lock on the main database file. Write the current page to
44938 ** the transaction journal if it is not there already.
44939 */
44940 if( !inJournal && !pagerUseWal(pPager) ){
44941 assert( pagerUseWal(pPager)==0 );
44942 if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){
44943 u32 cksum;
44944 char *pData2;
44945 i64 iOff = pPager->journalOff;
@@ -44824,11 +44948,11 @@
44948 ** contains the database locks. The following assert verifies
44949 ** that we do not. */
44950 assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) );
44951
44952 assert( pPager->journalHdr<=pPager->journalOff );
44953 CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
44954 cksum = pager_cksum(pPager, (u8*)pData2);
44955
44956 /* Even if an IO or diskfull error occurs while journalling the
44957 ** page in the block above, set the need-sync flag for the page.
44958 ** Otherwise, when the transaction is rolled back, the logic in
@@ -44876,11 +45000,11 @@
45000 /* If the statement journal is open and the page is not in it,
45001 ** then write the current page to the statement journal. Note that
45002 ** the statement journal format differs from the standard journal format
45003 ** in that it omits the checksums and the header.
45004 */
45005 if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){
45006 rc = subjournalPage(pPg);
45007 }
45008 }
45009
45010 /* Update the database size and return.
@@ -44959,18 +45083,18 @@
45083 if( rc==SQLITE_OK ){
45084 rc = pager_write(pPage);
45085 if( pPage->flags&PGHDR_NEED_SYNC ){
45086 needSync = 1;
45087 }
45088 sqlite3PagerUnrefNotNull(pPage);
45089 }
45090 }
45091 }else if( (pPage = pager_lookup(pPager, pg))!=0 ){
45092 if( pPage->flags&PGHDR_NEED_SYNC ){
45093 needSync = 1;
45094 }
45095 sqlite3PagerUnrefNotNull(pPage);
45096 }
45097 }
45098
45099 /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages
45100 ** starting at pg1, then it needs to be set for all of them. Because
@@ -44982,11 +45106,11 @@
45106 assert( !MEMDB );
45107 for(ii=0; ii<nPage; ii++){
45108 PgHdr *pPage = pager_lookup(pPager, pg1+ii);
45109 if( pPage ){
45110 pPage->flags |= PGHDR_NEED_SYNC;
45111 sqlite3PagerUnrefNotNull(pPage);
45112 }
45113 }
45114 }
45115
45116 assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 );
@@ -45135,21 +45259,21 @@
45259 ** or pages with the Pager.noSync flag set.
45260 **
45261 ** If successful, or if called on a pager for which it is a no-op, this
45262 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
45263 */
45264 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
45265 int rc = SQLITE_OK;
45266
45267 if( isOpen(pPager->fd) ){
45268 void *pArg = (void*)zMaster;
45269 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
45270 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
45271 }
45272 if( rc==SQLITE_OK && !pPager->noSync ){
45273 assert( !MEMDB );
45274 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
 
 
 
 
 
 
45275 }
45276 return rc;
45277 }
45278
45279 /*
@@ -45344,11 +45468,11 @@
45468 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
45469 }
45470
45471 /* Finally, sync the database file. */
45472 if( !noSync ){
45473 rc = sqlite3PagerSync(pPager, zMaster);
45474 }
45475 IOTRACE(("DBSYNC %p\n", pPager))
45476 }
45477 }
45478
@@ -45473,11 +45597,13 @@
45597 rc = pager_playback(pPager, 0);
45598 }
45599
45600 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
45601 assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT
45602 || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR
45603 || rc==SQLITE_CANTOPEN
45604 );
45605
45606 /* If an error occurs during a ROLLBACK, we can no longer trust the pager
45607 ** cache. So call pager_error() on the way out to make any error persistent.
45608 */
45609 return pager_error(pPager, rc);
@@ -45876,11 +46002,11 @@
46002 ** can be written to. The caller has already promised not to write to it.
46003 */
46004 if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){
46005 needSyncPgno = pPg->pgno;
46006 assert( pPager->journalMode==PAGER_JOURNALMODE_OFF ||
46007 pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize );
46008 assert( pPg->flags&PGHDR_DIRTY );
46009 }
46010
46011 /* If the cache contains a page with page-number pgno, remove it
46012 ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for
@@ -45910,11 +46036,11 @@
46036 ** as the original page since it has already been allocated.
46037 */
46038 if( MEMDB ){
46039 assert( pPgOld );
46040 sqlite3PcacheMove(pPgOld, origPgno);
46041 sqlite3PagerUnrefNotNull(pPgOld);
46042 }
46043
46044 if( needSyncPgno ){
46045 /* If needSyncPgno is non-zero, then the journal file needs to be
46046 ** sync()ed before any data is written to database file page needSyncPgno.
@@ -45939,11 +46065,11 @@
46065 }
46066 return rc;
46067 }
46068 pPgHdr->flags |= PGHDR_NEED_SYNC;
46069 sqlite3PcacheMakeDirty(pPgHdr);
46070 sqlite3PagerUnrefNotNull(pPgHdr);
46071 }
46072
46073 return SQLITE_OK;
46074 }
46075 #endif
@@ -52079,14 +52205,15 @@
52205 */
52206 static void releasePage(MemPage *pPage){
52207 if( pPage ){
52208 assert( pPage->aData );
52209 assert( pPage->pBt );
52210 assert( pPage->pDbPage!=0 );
52211 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
52212 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
52213 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
52214 sqlite3PagerUnrefNotNull(pPage->pDbPage);
52215 }
52216 }
52217
52218 /*
52219 ** During a rollback, when the pager reloads information into the cache
@@ -59413,11 +59540,11 @@
59540 rc = backupTruncateFile(pFile, iSize);
59541 }
59542
59543 /* Sync the database file to disk. */
59544 if( rc==SQLITE_OK ){
59545 rc = sqlite3PagerSync(pDestPager, 0);
59546 }
59547 }else{
59548 sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
59549 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
59550 }
@@ -59488,14 +59615,14 @@
59615 /* If a transaction is still open on the Btree, roll it back. */
59616 sqlite3BtreeRollback(p->pDest, SQLITE_OK);
59617
59618 /* Set the error code of the destination database handle. */
59619 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
 
 
 
59620 if( p->pDestDb ){
59621 sqlite3Error(p->pDestDb, rc, 0);
59622
59623 /* Exit the mutexes and free the backup context structure. */
59624 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
59625 }
59626 sqlite3BtreeLeave(p->pSrc);
59627 if( p->pDestDb ){
59628 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
@@ -60117,10 +60244,13 @@
60244 if( pMem->flags & MEM_RowSet ){
60245 sqlite3RowSetClear(pMem->u.pRowSet);
60246 }
60247 MemSetTypeFlag(pMem, MEM_Null);
60248 pMem->type = SQLITE_NULL;
60249 }
60250 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60251 sqlite3VdbeMemSetNull((Mem*)p);
60252 }
60253
60254 /*
60255 ** Delete any previous value and set the value to be a BLOB of length
60256 ** n containing all zeros.
@@ -63440,10 +63570,11 @@
63570 sqlite3 *db = p->db;
63571 int rc = p->rc;
63572 if( p->zErrMsg ){
63573 u8 mallocFailed = db->mallocFailed;
63574 sqlite3BeginBenignMalloc();
63575 if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db);
63576 sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT);
63577 sqlite3EndBenignMalloc();
63578 db->mallocFailed = mallocFailed;
63579 db->errCode = rc;
63580 }else{
@@ -63508,12 +63639,11 @@
63639 }else if( p->rc && p->expired ){
63640 /* The expired flag was set on the VDBE before the first call
63641 ** to sqlite3_step(). For consistency (since sqlite3_step() was
63642 ** called), set the database error in this case as well.
63643 */
63644 sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
 
63645 sqlite3DbFree(db, p->zErrMsg);
63646 p->zErrMsg = 0;
63647 }
63648
63649 /* Reclaim all memory used by the VDBE
@@ -64883,20 +65013,21 @@
65013 && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
65014 sqlite3_reset(pStmt);
65015 v->doingRerun = 1;
65016 assert( v->expired==0 );
65017 }
65018 if( rc2!=SQLITE_OK ){
65019 /* This case occurs after failing to recompile an sql statement.
65020 ** The error message from the SQL compiler has already been loaded
65021 ** into the database handle. This block copies the error message
65022 ** from the database handle into the statement and sets the statement
65023 ** program counter to 0 to ensure that when the statement is
65024 ** finalized or reset the parser error message is available via
65025 ** sqlite3_errmsg() and sqlite3_errcode().
65026 */
65027 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
65028 assert( zErr!=0 || db->mallocFailed );
65029 sqlite3DbFree(db, v->zErrMsg);
65030 if( !db->mallocFailed ){
65031 v->zErrMsg = sqlite3DbStrDup(db, zErr);
65032 v->rc = rc2;
65033 } else {
@@ -65841,13 +65972,13 @@
65972 assert( idx>0 && idx<=p->nVar );
65973 pVar = &p->aVar[idx-1];
65974 if( pVar->flags & MEM_Null ){
65975 sqlite3StrAccumAppend(&out, "NULL", 4);
65976 }else if( pVar->flags & MEM_Int ){
65977 sqlite3XPrintf(&out, 0, "%lld", pVar->u.i);
65978 }else if( pVar->flags & MEM_Real ){
65979 sqlite3XPrintf(&out, 0, "%!.15g", pVar->r);
65980 }else if( pVar->flags & MEM_Str ){
65981 int nOut; /* Number of bytes of the string text to include in output */
65982 #ifndef SQLITE_OMIT_UTF16
65983 u8 enc = ENC(db);
65984 Mem utf8;
@@ -65864,33 +65995,37 @@
65995 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
65996 nOut = SQLITE_TRACE_SIZE_LIMIT;
65997 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
65998 }
65999 #endif
66000 sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z);
66001 #ifdef SQLITE_TRACE_SIZE_LIMIT
66002 if( nOut<pVar->n ){
66003 sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66004 }
66005 #endif
66006 #ifndef SQLITE_OMIT_UTF16
66007 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
66008 #endif
66009 }else if( pVar->flags & MEM_Zero ){
66010 sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero);
66011 }else{
66012 int nOut; /* Number of bytes of the blob to include in output */
66013 assert( pVar->flags & MEM_Blob );
66014 sqlite3StrAccumAppend(&out, "x'", 2);
66015 nOut = pVar->n;
66016 #ifdef SQLITE_TRACE_SIZE_LIMIT
66017 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
66018 #endif
66019 for(i=0; i<nOut; i++){
66020 sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff);
66021 }
66022 sqlite3StrAccumAppend(&out, "'", 1);
66023 #ifdef SQLITE_TRACE_SIZE_LIMIT
66024 if( nOut<pVar->n ){
66025 sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut);
66026 }
66027 #endif
66028 }
66029 }
66030 }
66031 return sqlite3StrAccumFinish(&out);
@@ -65945,11 +66080,11 @@
66080 int n = p->nIndent;
66081 if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent);
66082 sqlite3AppendSpace(&p->str, p->aIndent[n-1]);
66083 }
66084 va_start(ap, zFormat);
66085 sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap);
66086 va_end(ap);
66087 }
66088 }
66089
66090 /*
@@ -88246,11 +88381,10 @@
88381 int bestScore = 0; /* Score of best match */
88382 int h; /* Hash value */
88383
88384 assert( nArg>=(-2) );
88385 assert( nArg>=(-1) || createFlag==0 );
 
88386 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a);
88387
88388 /* First search for a match amongst the application-defined functions.
88389 */
88390 p = functionSearch(&db->aFunc, h, zName, nName);
@@ -89397,10 +89531,36 @@
89531 }while( isText && (zHaystack[0]&0xc0)==0x80 );
89532 }
89533 if( nNeedle>nHaystack ) N = 0;
89534 sqlite3_result_int(context, N);
89535 }
89536
89537 /*
89538 ** Implementation of the printf() function.
89539 */
89540 static void printfFunc(
89541 sqlite3_context *context,
89542 int argc,
89543 sqlite3_value **argv
89544 ){
89545 PrintfArguments x;
89546 StrAccum str;
89547 const char *zFormat;
89548 int n;
89549
89550 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
89551 x.nArg = argc-1;
89552 x.nUsed = 0;
89553 x.apArg = argv+1;
89554 sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH);
89555 str.db = sqlite3_context_db_handle(context);
89556 sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x);
89557 n = str.nChar;
89558 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
89559 SQLITE_DYNAMIC);
89560 }
89561 }
89562
89563 /*
89564 ** Implementation of the substr() function.
89565 **
89566 ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1.
@@ -90828,10 +90988,11 @@
90988 FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF),
90989 FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH),
90990 FUNCTION(instr, 2, 0, 0, instrFunc ),
90991 FUNCTION(substr, 2, 0, 0, substrFunc ),
90992 FUNCTION(substr, 3, 0, 0, substrFunc ),
90993 FUNCTION(printf, -1, 0, 0, printfFunc ),
90994 FUNCTION(unicode, 1, 0, 0, unicodeFunc ),
90995 FUNCTION(char, -1, 0, 0, charFunc ),
90996 FUNCTION(abs, 1, 0, 0, absFunc ),
90997 #ifndef SQLITE_OMIT_FLOATING_POINT
90998 FUNCTION(round, 1, 0, 0, roundFunc ),
@@ -119433,13 +119594,11 @@
119594 }
119595 sqlite3HashClear(&db->aModule);
119596 #endif
119597
119598 sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */
119599 sqlite3ValueFree(db->pErr);
 
 
119600 sqlite3CloseExtensions(db);
119601
119602 db->magic = SQLITE_MAGIC_ERROR;
119603
119604 /* The temp-database schema is allocated differently from the other schema
@@ -119818,10 +119977,11 @@
119977 void (*xFinal)(sqlite3_context*),
119978 FuncDestructor *pDestructor
119979 ){
119980 FuncDef *p;
119981 int nName;
119982 int extraFlags;
119983
119984 assert( sqlite3_mutex_held(db->mutex) );
119985 if( zFunctionName==0 ||
119986 (xFunc && (xFinal || xStep)) ||
119987 (!xFunc && (xFinal && !xStep)) ||
@@ -119828,10 +119988,14 @@
119988 (!xFunc && (!xFinal && xStep)) ||
119989 (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) ||
119990 (255<(nName = sqlite3Strlen30( zFunctionName))) ){
119991 return SQLITE_MISUSE_BKPT;
119992 }
119993
119994 assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC );
119995 extraFlags = enc & SQLITE_DETERMINISTIC;
119996 enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY);
119997
119998 #ifndef SQLITE_OMIT_UTF16
119999 /* If SQLITE_UTF16 is specified as the encoding type, transform this
120000 ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
120001 ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
@@ -119841,14 +120005,14 @@
120005 */
120006 if( enc==SQLITE_UTF16 ){
120007 enc = SQLITE_UTF16NATIVE;
120008 }else if( enc==SQLITE_ANY ){
120009 int rc;
120010 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags,
120011 pUserData, xFunc, xStep, xFinal, pDestructor);
120012 if( rc==SQLITE_OK ){
120013 rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags,
120014 pUserData, xFunc, xStep, xFinal, pDestructor);
120015 }
120016 if( rc!=SQLITE_OK ){
120017 return rc;
120018 }
@@ -119887,11 +120051,12 @@
120051
120052 if( pDestructor ){
120053 pDestructor->nRef++;
120054 }
120055 p->pDestructor = pDestructor;
120056 p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags;
120057 testcase( p->funcFlags & SQLITE_DETERMINISTIC );
120058 p->xFunc = xFunc;
120059 p->xStep = xStep;
120060 p->xFinalize = xFinal;
120061 p->pUserData = pUserData;
120062 p->nArg = (u16)nArg;
@@ -120317,10 +120482,11 @@
120482 }
120483 sqlite3_mutex_enter(db->mutex);
120484 if( db->mallocFailed ){
120485 z = sqlite3ErrStr(SQLITE_NOMEM);
120486 }else{
120487 testcase( db->pErr==0 );
120488 z = (char*)sqlite3_value_text(db->pErr);
120489 assert( !db->mallocFailed );
120490 if( z==0 ){
120491 z = sqlite3ErrStr(db->errCode);
120492 }
@@ -120358,12 +120524,11 @@
120524 if( db->mallocFailed ){
120525 z = (void *)outOfMem;
120526 }else{
120527 z = sqlite3_value_text16(db->pErr);
120528 if( z==0 ){
120529 sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode));
 
120530 z = sqlite3_value_text16(db->pErr);
120531 }
120532 /* A malloc() may have failed within the call to sqlite3_value_text16()
120533 ** above. If this is the case, then the db->mallocFailed flag needs to
120534 ** be cleared before returning. Do this directly, instead of via
@@ -121073,12 +121238,10 @@
121238 if( !db->mallocFailed && rc==SQLITE_OK){
121239 rc = sqlite3RtreeInit(db);
121240 }
121241 #endif
121242
 
 
121243 /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking
121244 ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking
121245 ** mode. Doing nothing at all also makes NORMAL the default.
121246 */
121247 #ifdef SQLITE_DEFAULT_LOCKING_MODE
121248
+53 -18
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.3"
111111
#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
112
+#define SQLITE_SOURCE_ID "2013-12-17 16:32:56 93121d3097a43997af3c0de65bd9bd7663845fa2"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -789,19 +789,33 @@
789789
** to the [sqlite3_file] object associated with a particular database
790790
** connection. See the [sqlite3_file_control()] documentation for
791791
** additional information.
792792
**
793793
** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
794
-** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
795
-** SQLite and sent to all VFSes in place of a call to the xSync method
796
-** when the database connection has [PRAGMA synchronous] set to OFF.)^
797
-** Some specialized VFSes need this signal in order to operate correctly
798
-** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
799
-** VFSes do not need this signal and should silently ignore this opcode.
800
-** Applications should not call [sqlite3_file_control()] with this
801
-** opcode as doing so may disrupt the operation of the specialized VFSes
802
-** that do require it.
794
+** No longer in use.
795
+**
796
+** <li>[[SQLITE_FCNTL_SYNC]]
797
+** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
798
+** sent to the VFS immediately before the xSync method is invoked on a
799
+** database file descriptor. Or, if the xSync method is not invoked
800
+** because the user has configured SQLite with
801
+** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
802
+** of the xSync method. In most cases, the pointer argument passed with
803
+** this file-control is NULL. However, if the database file is being synced
804
+** as part of a multi-database commit, the argument points to a nul-terminated
805
+** string containing the transactions master-journal file name. VFSes that
806
+** do not need this signal should silently ignore this opcode. Applications
807
+** should not call [sqlite3_file_control()] with this opcode as doing so may
808
+** disrupt the operation of the specialized VFSes that do require it.
809
+**
810
+** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
811
+** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
812
+** and sent to the VFS after a transaction has been committed immediately
813
+** but before the database is unlocked. VFSes that do not need this signal
814
+** should silently ignore this opcode. Applications should not call
815
+** [sqlite3_file_control()] with this opcode as doing so may disrupt the
816
+** operation of the specialized VFSes that do require it.
803817
**
804818
** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
805819
** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
806820
** retry counts and intervals for certain disk I/O operations for the
807821
** windows [VFS] in order to provide robustness in the presence of
@@ -948,10 +962,12 @@
948962
#define SQLITE_FCNTL_BUSYHANDLER 15
949963
#define SQLITE_FCNTL_TEMPFILENAME 16
950964
#define SQLITE_FCNTL_MMAP_SIZE 18
951965
#define SQLITE_FCNTL_TRACE 19
952966
#define SQLITE_FCNTL_HAS_MOVED 20
967
+#define SQLITE_FCNTL_SYNC 21
968
+#define SQLITE_FCNTL_COMMIT_PHASETWO 22
953969
954970
/*
955971
** CAPI3REF: Mutex Handle
956972
**
957973
** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3964,19 +3980,28 @@
39643980
** parameter is less than -1 or greater than 127 then the behavior is
39653981
** undefined.
39663982
**
39673983
** ^The fourth parameter, eTextRep, specifies what
39683984
** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3969
-** its parameters. Every SQL function implementation must be able to work
3970
-** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3971
-** more efficient with one encoding than another. ^An application may
3972
-** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3973
-** times with the same function but with different values of eTextRep.
3985
+** its parameters. The application should set this parameter to
3986
+** [SQLITE_UTF16LE] if the function implementation invokes
3987
+** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
3988
+** implementation invokes [sqlite3_value_text16be()] on an input, or
3989
+** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
3990
+** otherwise. ^The same SQL function may be registered multiple times using
3991
+** different preferred text encodings, with different implementations for
3992
+** each encoding.
39743993
** ^When multiple implementations of the same function are available, SQLite
39753994
** will pick the one that involves the least amount of data conversion.
3976
-** If there is only a single implementation which does not care what text
3977
-** encoding is used, then the fourth argument should be [SQLITE_ANY].
3995
+**
3996
+** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
3997
+** to signal that the function will always return the same result given
3998
+** the same inputs within a single SQL statement. Most SQL functions are
3999
+** deterministic. The built-in [random()] SQL function is an example of a
4000
+** function that is not deterministic. The SQLite query planner is able to
4001
+** perform additional optimizations on deterministic functions, so use
4002
+** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
39784003
**
39794004
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
39804005
** function can gain access to this pointer using [sqlite3_user_data()].)^
39814006
**
39824007
** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4058,13 +4083,23 @@
40584083
*/
40594084
#define SQLITE_UTF8 1
40604085
#define SQLITE_UTF16LE 2
40614086
#define SQLITE_UTF16BE 3
40624087
#define SQLITE_UTF16 4 /* Use native byte order */
4063
-#define SQLITE_ANY 5 /* sqlite3_create_function only */
4088
+#define SQLITE_ANY 5 /* Deprecated */
40644089
#define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
40654090
4091
+/*
4092
+** CAPI3REF: Function Flags
4093
+**
4094
+** These constants may be ORed together with the
4095
+** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4096
+** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4097
+** [sqlite3_create_function_v2()].
4098
+*/
4099
+#define SQLITE_DETERMINISTIC 0x800
4100
+
40664101
/*
40674102
** CAPI3REF: Deprecated Functions
40684103
** DEPRECATED
40694104
**
40704105
** These functions are [deprecated]. In order to maintain
40714106
40724107
ADDED win/buildmsvc.bat
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2013-12-11 12:02:55 3e1d55f0bd84810a035bd6c54583eb373784a9a3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -789,19 +789,33 @@
789 ** to the [sqlite3_file] object associated with a particular database
790 ** connection. See the [sqlite3_file_control()] documentation for
791 ** additional information.
792 **
793 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
794 ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by
795 ** SQLite and sent to all VFSes in place of a call to the xSync method
796 ** when the database connection has [PRAGMA synchronous] set to OFF.)^
797 ** Some specialized VFSes need this signal in order to operate correctly
798 ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most
799 ** VFSes do not need this signal and should silently ignore this opcode.
800 ** Applications should not call [sqlite3_file_control()] with this
801 ** opcode as doing so may disrupt the operation of the specialized VFSes
802 ** that do require it.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
803 **
804 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
805 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
806 ** retry counts and intervals for certain disk I/O operations for the
807 ** windows [VFS] in order to provide robustness in the presence of
@@ -948,10 +962,12 @@
948 #define SQLITE_FCNTL_BUSYHANDLER 15
949 #define SQLITE_FCNTL_TEMPFILENAME 16
950 #define SQLITE_FCNTL_MMAP_SIZE 18
951 #define SQLITE_FCNTL_TRACE 19
952 #define SQLITE_FCNTL_HAS_MOVED 20
 
 
953
954 /*
955 ** CAPI3REF: Mutex Handle
956 **
957 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3964,19 +3980,28 @@
3964 ** parameter is less than -1 or greater than 127 then the behavior is
3965 ** undefined.
3966 **
3967 ** ^The fourth parameter, eTextRep, specifies what
3968 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3969 ** its parameters. Every SQL function implementation must be able to work
3970 ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be
3971 ** more efficient with one encoding than another. ^An application may
3972 ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple
3973 ** times with the same function but with different values of eTextRep.
 
 
 
3974 ** ^When multiple implementations of the same function are available, SQLite
3975 ** will pick the one that involves the least amount of data conversion.
3976 ** If there is only a single implementation which does not care what text
3977 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
 
 
 
 
 
 
3978 **
3979 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3980 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3981 **
3982 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4058,13 +4083,23 @@
4058 */
4059 #define SQLITE_UTF8 1
4060 #define SQLITE_UTF16LE 2
4061 #define SQLITE_UTF16BE 3
4062 #define SQLITE_UTF16 4 /* Use native byte order */
4063 #define SQLITE_ANY 5 /* sqlite3_create_function only */
4064 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4065
 
 
 
 
 
 
 
 
 
 
4066 /*
4067 ** CAPI3REF: Deprecated Functions
4068 ** DEPRECATED
4069 **
4070 ** These functions are [deprecated]. In order to maintain
4071
4072 DDED win/buildmsvc.bat
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2013-12-17 16:32:56 93121d3097a43997af3c0de65bd9bd7663845fa2"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -789,19 +789,33 @@
789 ** to the [sqlite3_file] object associated with a particular database
790 ** connection. See the [sqlite3_file_control()] documentation for
791 ** additional information.
792 **
793 ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]]
794 ** No longer in use.
795 **
796 ** <li>[[SQLITE_FCNTL_SYNC]]
797 ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and
798 ** sent to the VFS immediately before the xSync method is invoked on a
799 ** database file descriptor. Or, if the xSync method is not invoked
800 ** because the user has configured SQLite with
801 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
802 ** of the xSync method. In most cases, the pointer argument passed with
803 ** this file-control is NULL. However, if the database file is being synced
804 ** as part of a multi-database commit, the argument points to a nul-terminated
805 ** string containing the transactions master-journal file name. VFSes that
806 ** do not need this signal should silently ignore this opcode. Applications
807 ** should not call [sqlite3_file_control()] with this opcode as doing so may
808 ** disrupt the operation of the specialized VFSes that do require it.
809 **
810 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
811 ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite
812 ** and sent to the VFS after a transaction has been committed immediately
813 ** but before the database is unlocked. VFSes that do not need this signal
814 ** should silently ignore this opcode. Applications should not call
815 ** [sqlite3_file_control()] with this opcode as doing so may disrupt the
816 ** operation of the specialized VFSes that do require it.
817 **
818 ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]]
819 ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic
820 ** retry counts and intervals for certain disk I/O operations for the
821 ** windows [VFS] in order to provide robustness in the presence of
@@ -948,10 +962,12 @@
962 #define SQLITE_FCNTL_BUSYHANDLER 15
963 #define SQLITE_FCNTL_TEMPFILENAME 16
964 #define SQLITE_FCNTL_MMAP_SIZE 18
965 #define SQLITE_FCNTL_TRACE 19
966 #define SQLITE_FCNTL_HAS_MOVED 20
967 #define SQLITE_FCNTL_SYNC 21
968 #define SQLITE_FCNTL_COMMIT_PHASETWO 22
969
970 /*
971 ** CAPI3REF: Mutex Handle
972 **
973 ** The mutex module within SQLite defines [sqlite3_mutex] to be an
@@ -3964,19 +3980,28 @@
3980 ** parameter is less than -1 or greater than 127 then the behavior is
3981 ** undefined.
3982 **
3983 ** ^The fourth parameter, eTextRep, specifies what
3984 ** [SQLITE_UTF8 | text encoding] this SQL function prefers for
3985 ** its parameters. The application should set this parameter to
3986 ** [SQLITE_UTF16LE] if the function implementation invokes
3987 ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the
3988 ** implementation invokes [sqlite3_value_text16be()] on an input, or
3989 ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8]
3990 ** otherwise. ^The same SQL function may be registered multiple times using
3991 ** different preferred text encodings, with different implementations for
3992 ** each encoding.
3993 ** ^When multiple implementations of the same function are available, SQLite
3994 ** will pick the one that involves the least amount of data conversion.
3995 **
3996 ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC]
3997 ** to signal that the function will always return the same result given
3998 ** the same inputs within a single SQL statement. Most SQL functions are
3999 ** deterministic. The built-in [random()] SQL function is an example of a
4000 ** function that is not deterministic. The SQLite query planner is able to
4001 ** perform additional optimizations on deterministic functions, so use
4002 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4003 **
4004 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4005 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4006 **
4007 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
@@ -4058,13 +4083,23 @@
4083 */
4084 #define SQLITE_UTF8 1
4085 #define SQLITE_UTF16LE 2
4086 #define SQLITE_UTF16BE 3
4087 #define SQLITE_UTF16 4 /* Use native byte order */
4088 #define SQLITE_ANY 5 /* Deprecated */
4089 #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */
4090
4091 /*
4092 ** CAPI3REF: Function Flags
4093 **
4094 ** These constants may be ORed together with the
4095 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
4096 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
4097 ** [sqlite3_create_function_v2()].
4098 */
4099 #define SQLITE_DETERMINISTIC 0x800
4100
4101 /*
4102 ** CAPI3REF: Deprecated Functions
4103 ** DEPRECATED
4104 **
4105 ** These functions are [deprecated]. In order to maintain
4106
4107 DDED win/buildmsvc.bat

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

No diff available

--- a/win/buildmsvc.bat
+++ b/win/buildmsvc.bat
@@ -0,0 +1 @@
1
+\x64*\x64*Root = '%ROOT%'
--- a/win/buildmsvc.bat
+++ b/win/buildmsvc.bat
@@ -0,0 +1 @@
 
--- a/win/buildmsvc.bat
+++ b/win/buildmsvc.bat
@@ -0,0 +1 @@
1 \x64*\x64*Root = '%ROOT%'
+4 -2
--- www/build.wiki
+++ www/build.wiki
@@ -92,13 +92,15 @@
9292
"<b>make -f win/Makefile.mingw</b>". On a Windows box you will
9393
need either Cygwin or Msys as build environment. On Cygwin, Linux
9494
or Darwin you may want to make minor edits to win/Makefile.mingw
9595
to configure the cross-compile environment.
9696
97
-<li><p><i>VC++</i> → Use the msc makefile. First
97
+<li><p><i>MSVC</i> → Use the msc makefile. First
9898
change to the "win/" subdirectory ("<b>cd win</b>") then run
99
-"<b>nmake /f Makefile.msc</b>".
99
+"<b>nmake /f Makefile.msc</b>". Alternatively, the batch file
100
+"<b>win\buildmsvc.bat</b>" may be used and it will attempt to
101
+detect and use the latest installed version of MSVC.
100102
</ol>
101103
</ol>
102104
103105
<h2>3.0 Installing</h2>
104106
105107
--- www/build.wiki
+++ www/build.wiki
@@ -92,13 +92,15 @@
92 "<b>make -f win/Makefile.mingw</b>". On a Windows box you will
93 need either Cygwin or Msys as build environment. On Cygwin, Linux
94 or Darwin you may want to make minor edits to win/Makefile.mingw
95 to configure the cross-compile environment.
96
97 <li><p><i>VC++</i> → Use the msc makefile. First
98 change to the "win/" subdirectory ("<b>cd win</b>") then run
99 "<b>nmake /f Makefile.msc</b>".
 
 
100 </ol>
101 </ol>
102
103 <h2>3.0 Installing</h2>
104
105
--- www/build.wiki
+++ www/build.wiki
@@ -92,13 +92,15 @@
92 "<b>make -f win/Makefile.mingw</b>". On a Windows box you will
93 need either Cygwin or Msys as build environment. On Cygwin, Linux
94 or Darwin you may want to make minor edits to win/Makefile.mingw
95 to configure the cross-compile environment.
96
97 <li><p><i>MSVC</i> → Use the msc makefile. First
98 change to the "win/" subdirectory ("<b>cd win</b>") then run
99 "<b>nmake /f Makefile.msc</b>". Alternatively, the batch file
100 "<b>win\buildmsvc.bat</b>" may be used and it will attempt to
101 detect and use the latest installed version of MSVC.
102 </ol>
103 </ol>
104
105 <h2>3.0 Installing</h2>
106
107
--- www/changes.wiki
+++ www/changes.wiki
@@ -26,13 +26,16 @@
2626
specifies the number of entries, just like all other commands which
2727
have the -n|--limit option. The various timeline-related functions
2828
now output "--- ?? limit (??) reached ---" at the end whenever
2929
appropriate. Use "-n 0" if no limit is desired.
3030
* Fix handling of password embedded in Fossil URL.
31
- * New --once option to [/help?cmd=clone | fossil clone] command which does
32
- not store the URL or password when cloning.
33
- * Modify [/help?cmd=ui | fossil ui] to respect "default user" in open repository.
31
+ * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
32
+ which does not store the URL or password when cloning.
33
+ * Modify [/help?cmd=ui | fossil ui] to respect "default user" in an open
34
+ repository.
35
+ * Fossil now hides check-ins that have the "hidden" tag in timeline webpages.
36
+ * Enhance <tt>/ci_edit</tt> page to add the "hidden" tag to check-ins.
3437
3538
<h2>Changes For Version 1.27 (2013-09-11)</h2>
3639
* Enhance the [/help?cmd=changes | fossil changes],
3740
[/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
3841
[/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
3942
--- www/changes.wiki
+++ www/changes.wiki
@@ -26,13 +26,16 @@
26 specifies the number of entries, just like all other commands which
27 have the -n|--limit option. The various timeline-related functions
28 now output "--- ?? limit (??) reached ---" at the end whenever
29 appropriate. Use "-n 0" if no limit is desired.
30 * Fix handling of password embedded in Fossil URL.
31 * New --once option to [/help?cmd=clone | fossil clone] command which does
32 not store the URL or password when cloning.
33 * Modify [/help?cmd=ui | fossil ui] to respect "default user" in open repository.
 
 
 
34
35 <h2>Changes For Version 1.27 (2013-09-11)</h2>
36 * Enhance the [/help?cmd=changes | fossil changes],
37 [/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
38 [/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
39
--- www/changes.wiki
+++ www/changes.wiki
@@ -26,13 +26,16 @@
26 specifies the number of entries, just like all other commands which
27 have the -n|--limit option. The various timeline-related functions
28 now output "--- ?? limit (??) reached ---" at the end whenever
29 appropriate. Use "-n 0" if no limit is desired.
30 * Fix handling of password embedded in Fossil URL.
31 * New <tt>--once</tt> option to [/help?cmd=clone | fossil clone] command
32 which does not store the URL or password when cloning.
33 * Modify [/help?cmd=ui | fossil ui] to respect "default user" in an open
34 repository.
35 * Fossil now hides check-ins that have the "hidden" tag in timeline webpages.
36 * Enhance <tt>/ci_edit</tt> page to add the "hidden" tag to check-ins.
37
38 <h2>Changes For Version 1.27 (2013-09-11)</h2>
39 * Enhance the [/help?cmd=changes | fossil changes],
40 [/help?cmd=clean | fossil clean], [/help?cmd=extras | fossil extras],
41 [/help?cmd=ls | fossil ls] and [/help?cmd=status | fossil status] commands
42

Keyboard Shortcuts

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