Fossil SCM

Update the built-in SQLite to the latest trunk version for testing.

drh 2025-03-27 23:35 trunk
Commit da34b906edbdf738a4d369066cff0c08549d16606bda208b604ddcf81a4a1e32
+86 -24
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1162,10 +1162,27 @@
11621162
}
11631163
}
11641164
return n;
11651165
}
11661166
#endif
1167
+
1168
+/*
1169
+** Check to see if z[] is a valid VT100 escape. If it is, then
1170
+** return the number of bytes in the escape sequence. Return 0 if
1171
+** z[] is not a VT100 escape.
1172
+**
1173
+** This routine assumes that z[0] is \033 (ESC).
1174
+*/
1175
+static int isVt100(const unsigned char *z){
1176
+ int i;
1177
+ if( z[1]!='[' ) return 0;
1178
+ i = 2;
1179
+ while( z[i]>=0x30 && z[i]<=0x3f ){ i++; }
1180
+ while( z[i]>=0x20 && z[i]<=0x2f ){ i++; }
1181
+ if( z[i]<0x40 || z[i]>0x7e ) return 0;
1182
+ return i+1;
1183
+}
11671184
11681185
/*
11691186
** Output string zUtf to stdout as w characters. If w is negative,
11701187
** then right-justify the text. W is the width in UTF-8 characters, not
11711188
** in bytes. This is different from the %*.*s specification in printf
@@ -1178,10 +1195,11 @@
11781195
static void utf8_width_print(FILE *out, int w, const char *zUtf){
11791196
const unsigned char *a = (const unsigned char*)zUtf;
11801197
unsigned char c;
11811198
int i = 0;
11821199
int n = 0;
1200
+ int k;
11831201
int aw = w<0 ? -w : w;
11841202
if( zUtf==0 ) zUtf = "";
11851203
while( (c = a[i])!=0 ){
11861204
if( (c&0xc0)==0xc0 ){
11871205
int u;
@@ -1190,10 +1208,12 @@
11901208
if( x+n>aw ){
11911209
break;
11921210
}
11931211
i += len;
11941212
n += x;
1213
+ }else if( c==0x1b && (k = isVt100(&a[i]))>0 ){
1214
+ i += k;
11951215
}else if( n>=aw ){
11961216
break;
11971217
}else{
11981218
n++;
11991219
i++;
@@ -6270,12 +6290,11 @@
62706290
** start HIDDEN,
62716291
** stop HIDDEN,
62726292
** step HIDDEN
62736293
** );
62746294
**
6275
-** The virtual table also has a rowid, logically equivalent to n+1 where
6276
-** "n" is the ascending integer in the aforesaid production definition.
6295
+** The virtual table also has a rowid which is an alias for the value.
62776296
**
62786297
** Function arguments in queries against this virtual table are translated
62796298
** into equality constraints against successive hidden columns. In other
62806299
** words, the following pairs of queries are equivalent to each other:
62816300
**
@@ -6326,10 +6345,11 @@
63266345
/* #include "sqlite3ext.h" */
63276346
SQLITE_EXTENSION_INIT1
63286347
#include <assert.h>
63296348
#include <string.h>
63306349
#include <limits.h>
6350
+#include <math.h>
63316351
63326352
#ifndef SQLITE_OMIT_VIRTUALTABLE
63336353
/*
63346354
** Return that member of a generate_series(...) sequence whose 0-based
63356355
** index is ix. The 0th member is given by smBase. The sequence members
@@ -6486,10 +6506,11 @@
64866506
){
64876507
sqlite3_vtab *pNew;
64886508
int rc;
64896509
64906510
/* Column numbers */
6511
+#define SERIES_COLUMN_ROWID (-1)
64916512
#define SERIES_COLUMN_VALUE 0
64926513
#define SERIES_COLUMN_START 1
64936514
#define SERIES_COLUMN_STOP 2
64946515
#define SERIES_COLUMN_STEP 3
64956516
@@ -6573,17 +6594,15 @@
65736594
#define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
65746595
#define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
65756596
#endif
65766597
65776598
/*
6578
-** Return the rowid for the current row, logically equivalent to n+1 where
6579
-** "n" is the ascending integer in the aforesaid production definition.
6599
+** The rowid is the same as the value.
65806600
*/
65816601
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
65826602
series_cursor *pCur = (series_cursor*)cur;
6583
- sqlite3_uint64 n = pCur->ss.uSeqIndexNow;
6584
- *pRowid = (sqlite3_int64)((n<LARGEST_UINT64)? n+1 : 0);
6603
+ *pRowid = pCur->ss.iValueNow;
65856604
return SQLITE_OK;
65866605
}
65876606
65886607
/*
65896608
** Return TRUE if the cursor has been moved off of the last
@@ -6692,29 +6711,56 @@
66926711
if( idxNum & 0x3380 ){
66936712
/* Extract the maximum range of output values determined by
66946713
** constraints on the "value" column.
66956714
*/
66966715
if( idxNum & 0x0080 ){
6697
- iMin = iMax = sqlite3_value_int64(argv[i++]);
6716
+ if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6717
+ double r = sqlite3_value_double(argv[i++]);
6718
+ if( r==ceil(r) ){
6719
+ iMin = iMax = (sqlite3_int64)r;
6720
+ }else{
6721
+ returnNoRows = 1;
6722
+ }
6723
+ }else{
6724
+ iMin = iMax = sqlite3_value_int64(argv[i++]);
6725
+ }
66986726
}else{
66996727
if( idxNum & 0x0300 ){
6700
- iMin = sqlite3_value_int64(argv[i++]);
6701
- if( idxNum & 0x0200 ){
6702
- if( iMin==LARGEST_INT64 ){
6703
- returnNoRows = 1;
6728
+ if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6729
+ double r = sqlite3_value_double(argv[i++]);
6730
+ if( idxNum & 0x0200 && r==ceil(r) ){
6731
+ iMin = (sqlite3_int64)ceil(r+1.0);
67046732
}else{
6705
- iMin++;
6733
+ iMin = (sqlite3_int64)ceil(r);
6734
+ }
6735
+ }else{
6736
+ iMin = sqlite3_value_int64(argv[i++]);
6737
+ if( idxNum & 0x0200 ){
6738
+ if( iMin==LARGEST_INT64 ){
6739
+ returnNoRows = 1;
6740
+ }else{
6741
+ iMin++;
6742
+ }
67066743
}
67076744
}
67086745
}
67096746
if( idxNum & 0x3000 ){
6710
- iMax = sqlite3_value_int64(argv[i++]);
6711
- if( idxNum & 0x2000 ){
6712
- if( iMax==SMALLEST_INT64 ){
6713
- returnNoRows = 1;
6747
+ if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6748
+ double r = sqlite3_value_double(argv[i++]);
6749
+ if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6750
+ iMax = (sqlite3_int64)(r-1.0);
67146751
}else{
6715
- iMax--;
6752
+ iMax = (sqlite3_int64)floor(r);
6753
+ }
6754
+ }else{
6755
+ iMax = sqlite3_value_int64(argv[i++]);
6756
+ if( idxNum & 0x2000 ){
6757
+ if( iMax==SMALLEST_INT64 ){
6758
+ returnNoRows = 1;
6759
+ }else{
6760
+ iMax--;
6761
+ }
67166762
}
67176763
}
67186764
}
67196765
if( iMin>iMax ){
67206766
returnNoRows = 1;
@@ -6867,11 +6913,14 @@
68676913
idxNum |= 0x40;
68686914
}
68696915
continue;
68706916
}
68716917
if( pConstraint->iColumn<SERIES_COLUMN_START ){
6872
- if( pConstraint->iColumn==SERIES_COLUMN_VALUE && pConstraint->usable ){
6918
+ if( (pConstraint->iColumn==SERIES_COLUMN_VALUE ||
6919
+ pConstraint->iColumn==SERIES_COLUMN_ROWID)
6920
+ && pConstraint->usable
6921
+ ){
68736922
switch( op ){
68746923
case SQLITE_INDEX_CONSTRAINT_EQ:
68756924
case SQLITE_INDEX_CONSTRAINT_IS: {
68766925
idxNum |= 0x0080;
68776926
idxNum &= ~0x3300;
@@ -24197,13 +24246,18 @@
2419724246
j++;
2419824247
}while( (n&7)!=0 && n<mxWidth );
2419924248
i++;
2420024249
continue;
2420124250
}
24202
- n++;
24203
- j += 3;
24204
- i++;
24251
+ if( c==0x1b && p->eEscMode==SHELL_ESC_OFF && (k = isVt100(&z[i]))>0 ){
24252
+ i += k;
24253
+ j += k;
24254
+ }else{
24255
+ n++;
24256
+ j += 3;
24257
+ i++;
24258
+ }
2420524259
}
2420624260
if( n>=mxWidth && bWordWrap ){
2420724261
/* Perhaps try to back up to a better place to break the line */
2420824262
for(k=i; k>i/2; k--){
2420924263
if( IsSpace(z[k-1]) ) break;
@@ -24265,13 +24319,21 @@
2426524319
break;
2426624320
case SHELL_ESC_ASCII:
2426724321
zOut[j++] = '^';
2426824322
zOut[j++] = 0x40 + c;
2426924323
break;
24270
- case SHELL_ESC_OFF:
24271
- zOut[j++] = c;
24324
+ case SHELL_ESC_OFF: {
24325
+ int nn;
24326
+ if( c==0x1b && (nn = isVt100(&z[i]))>0 ){
24327
+ memcpy(&zOut[j], &z[i], nn);
24328
+ j += nn;
24329
+ i += nn - 1;
24330
+ }else{
24331
+ zOut[j++] = c;
24332
+ }
2427224333
break;
24334
+ }
2427324335
}
2427424336
i++;
2427524337
}
2427624338
zOut[j] = 0;
2427724339
return (char*)zOut;
@@ -27021,11 +27083,11 @@
2702127083
for(i=0; i<pgSz; i+=16){
2702227084
const u8 *aLine = aData+i;
2702327085
for(j=0; j<16 && aLine[j]==0; j++){}
2702427086
if( j==16 ) continue;
2702527087
if( !seenPageLabel ){
27026
- sqlite3_fprintf(p->out, "| page %lld offset %lld\n", pgno, pgno*pgSz);
27088
+ sqlite3_fprintf(p->out, "| page %lld offset %lld\n",pgno,(pgno-1)*pgSz);
2702727089
seenPageLabel = 1;
2702827090
}
2702927091
sqlite3_fprintf(p->out, "| %5d:", i);
2703027092
for(j=0; j<16; j++) sqlite3_fprintf(p->out, " %02x", aLine[j]);
2703127093
sqlite3_fprintf(p->out, " ");
2703227094
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1162,10 +1162,27 @@
1162 }
1163 }
1164 return n;
1165 }
1166 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1167
1168 /*
1169 ** Output string zUtf to stdout as w characters. If w is negative,
1170 ** then right-justify the text. W is the width in UTF-8 characters, not
1171 ** in bytes. This is different from the %*.*s specification in printf
@@ -1178,10 +1195,11 @@
1178 static void utf8_width_print(FILE *out, int w, const char *zUtf){
1179 const unsigned char *a = (const unsigned char*)zUtf;
1180 unsigned char c;
1181 int i = 0;
1182 int n = 0;
 
1183 int aw = w<0 ? -w : w;
1184 if( zUtf==0 ) zUtf = "";
1185 while( (c = a[i])!=0 ){
1186 if( (c&0xc0)==0xc0 ){
1187 int u;
@@ -1190,10 +1208,12 @@
1190 if( x+n>aw ){
1191 break;
1192 }
1193 i += len;
1194 n += x;
 
 
1195 }else if( n>=aw ){
1196 break;
1197 }else{
1198 n++;
1199 i++;
@@ -6270,12 +6290,11 @@
6270 ** start HIDDEN,
6271 ** stop HIDDEN,
6272 ** step HIDDEN
6273 ** );
6274 **
6275 ** The virtual table also has a rowid, logically equivalent to n+1 where
6276 ** "n" is the ascending integer in the aforesaid production definition.
6277 **
6278 ** Function arguments in queries against this virtual table are translated
6279 ** into equality constraints against successive hidden columns. In other
6280 ** words, the following pairs of queries are equivalent to each other:
6281 **
@@ -6326,10 +6345,11 @@
6326 /* #include "sqlite3ext.h" */
6327 SQLITE_EXTENSION_INIT1
6328 #include <assert.h>
6329 #include <string.h>
6330 #include <limits.h>
 
6331
6332 #ifndef SQLITE_OMIT_VIRTUALTABLE
6333 /*
6334 ** Return that member of a generate_series(...) sequence whose 0-based
6335 ** index is ix. The 0th member is given by smBase. The sequence members
@@ -6486,10 +6506,11 @@
6486 ){
6487 sqlite3_vtab *pNew;
6488 int rc;
6489
6490 /* Column numbers */
 
6491 #define SERIES_COLUMN_VALUE 0
6492 #define SERIES_COLUMN_START 1
6493 #define SERIES_COLUMN_STOP 2
6494 #define SERIES_COLUMN_STEP 3
6495
@@ -6573,17 +6594,15 @@
6573 #define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
6574 #define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
6575 #endif
6576
6577 /*
6578 ** Return the rowid for the current row, logically equivalent to n+1 where
6579 ** "n" is the ascending integer in the aforesaid production definition.
6580 */
6581 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6582 series_cursor *pCur = (series_cursor*)cur;
6583 sqlite3_uint64 n = pCur->ss.uSeqIndexNow;
6584 *pRowid = (sqlite3_int64)((n<LARGEST_UINT64)? n+1 : 0);
6585 return SQLITE_OK;
6586 }
6587
6588 /*
6589 ** Return TRUE if the cursor has been moved off of the last
@@ -6692,29 +6711,56 @@
6692 if( idxNum & 0x3380 ){
6693 /* Extract the maximum range of output values determined by
6694 ** constraints on the "value" column.
6695 */
6696 if( idxNum & 0x0080 ){
6697 iMin = iMax = sqlite3_value_int64(argv[i++]);
 
 
 
 
 
 
 
 
 
6698 }else{
6699 if( idxNum & 0x0300 ){
6700 iMin = sqlite3_value_int64(argv[i++]);
6701 if( idxNum & 0x0200 ){
6702 if( iMin==LARGEST_INT64 ){
6703 returnNoRows = 1;
6704 }else{
6705 iMin++;
 
 
 
 
 
 
 
 
 
6706 }
6707 }
6708 }
6709 if( idxNum & 0x3000 ){
6710 iMax = sqlite3_value_int64(argv[i++]);
6711 if( idxNum & 0x2000 ){
6712 if( iMax==SMALLEST_INT64 ){
6713 returnNoRows = 1;
6714 }else{
6715 iMax--;
 
 
 
 
 
 
 
 
 
6716 }
6717 }
6718 }
6719 if( iMin>iMax ){
6720 returnNoRows = 1;
@@ -6867,11 +6913,14 @@
6867 idxNum |= 0x40;
6868 }
6869 continue;
6870 }
6871 if( pConstraint->iColumn<SERIES_COLUMN_START ){
6872 if( pConstraint->iColumn==SERIES_COLUMN_VALUE && pConstraint->usable ){
 
 
 
6873 switch( op ){
6874 case SQLITE_INDEX_CONSTRAINT_EQ:
6875 case SQLITE_INDEX_CONSTRAINT_IS: {
6876 idxNum |= 0x0080;
6877 idxNum &= ~0x3300;
@@ -24197,13 +24246,18 @@
24197 j++;
24198 }while( (n&7)!=0 && n<mxWidth );
24199 i++;
24200 continue;
24201 }
24202 n++;
24203 j += 3;
24204 i++;
 
 
 
 
 
24205 }
24206 if( n>=mxWidth && bWordWrap ){
24207 /* Perhaps try to back up to a better place to break the line */
24208 for(k=i; k>i/2; k--){
24209 if( IsSpace(z[k-1]) ) break;
@@ -24265,13 +24319,21 @@
24265 break;
24266 case SHELL_ESC_ASCII:
24267 zOut[j++] = '^';
24268 zOut[j++] = 0x40 + c;
24269 break;
24270 case SHELL_ESC_OFF:
24271 zOut[j++] = c;
 
 
 
 
 
 
 
24272 break;
 
24273 }
24274 i++;
24275 }
24276 zOut[j] = 0;
24277 return (char*)zOut;
@@ -27021,11 +27083,11 @@
27021 for(i=0; i<pgSz; i+=16){
27022 const u8 *aLine = aData+i;
27023 for(j=0; j<16 && aLine[j]==0; j++){}
27024 if( j==16 ) continue;
27025 if( !seenPageLabel ){
27026 sqlite3_fprintf(p->out, "| page %lld offset %lld\n", pgno, pgno*pgSz);
27027 seenPageLabel = 1;
27028 }
27029 sqlite3_fprintf(p->out, "| %5d:", i);
27030 for(j=0; j<16; j++) sqlite3_fprintf(p->out, " %02x", aLine[j]);
27031 sqlite3_fprintf(p->out, " ");
27032
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -1162,10 +1162,27 @@
1162 }
1163 }
1164 return n;
1165 }
1166 #endif
1167
1168 /*
1169 ** Check to see if z[] is a valid VT100 escape. If it is, then
1170 ** return the number of bytes in the escape sequence. Return 0 if
1171 ** z[] is not a VT100 escape.
1172 **
1173 ** This routine assumes that z[0] is \033 (ESC).
1174 */
1175 static int isVt100(const unsigned char *z){
1176 int i;
1177 if( z[1]!='[' ) return 0;
1178 i = 2;
1179 while( z[i]>=0x30 && z[i]<=0x3f ){ i++; }
1180 while( z[i]>=0x20 && z[i]<=0x2f ){ i++; }
1181 if( z[i]<0x40 || z[i]>0x7e ) return 0;
1182 return i+1;
1183 }
1184
1185 /*
1186 ** Output string zUtf to stdout as w characters. If w is negative,
1187 ** then right-justify the text. W is the width in UTF-8 characters, not
1188 ** in bytes. This is different from the %*.*s specification in printf
@@ -1178,10 +1195,11 @@
1195 static void utf8_width_print(FILE *out, int w, const char *zUtf){
1196 const unsigned char *a = (const unsigned char*)zUtf;
1197 unsigned char c;
1198 int i = 0;
1199 int n = 0;
1200 int k;
1201 int aw = w<0 ? -w : w;
1202 if( zUtf==0 ) zUtf = "";
1203 while( (c = a[i])!=0 ){
1204 if( (c&0xc0)==0xc0 ){
1205 int u;
@@ -1190,10 +1208,12 @@
1208 if( x+n>aw ){
1209 break;
1210 }
1211 i += len;
1212 n += x;
1213 }else if( c==0x1b && (k = isVt100(&a[i]))>0 ){
1214 i += k;
1215 }else if( n>=aw ){
1216 break;
1217 }else{
1218 n++;
1219 i++;
@@ -6270,12 +6290,11 @@
6290 ** start HIDDEN,
6291 ** stop HIDDEN,
6292 ** step HIDDEN
6293 ** );
6294 **
6295 ** The virtual table also has a rowid which is an alias for the value.
 
6296 **
6297 ** Function arguments in queries against this virtual table are translated
6298 ** into equality constraints against successive hidden columns. In other
6299 ** words, the following pairs of queries are equivalent to each other:
6300 **
@@ -6326,10 +6345,11 @@
6345 /* #include "sqlite3ext.h" */
6346 SQLITE_EXTENSION_INIT1
6347 #include <assert.h>
6348 #include <string.h>
6349 #include <limits.h>
6350 #include <math.h>
6351
6352 #ifndef SQLITE_OMIT_VIRTUALTABLE
6353 /*
6354 ** Return that member of a generate_series(...) sequence whose 0-based
6355 ** index is ix. The 0th member is given by smBase. The sequence members
@@ -6486,10 +6506,11 @@
6506 ){
6507 sqlite3_vtab *pNew;
6508 int rc;
6509
6510 /* Column numbers */
6511 #define SERIES_COLUMN_ROWID (-1)
6512 #define SERIES_COLUMN_VALUE 0
6513 #define SERIES_COLUMN_START 1
6514 #define SERIES_COLUMN_STOP 2
6515 #define SERIES_COLUMN_STEP 3
6516
@@ -6573,17 +6594,15 @@
6594 #define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
6595 #define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
6596 #endif
6597
6598 /*
6599 ** The rowid is the same as the value.
 
6600 */
6601 static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
6602 series_cursor *pCur = (series_cursor*)cur;
6603 *pRowid = pCur->ss.iValueNow;
 
6604 return SQLITE_OK;
6605 }
6606
6607 /*
6608 ** Return TRUE if the cursor has been moved off of the last
@@ -6692,29 +6711,56 @@
6711 if( idxNum & 0x3380 ){
6712 /* Extract the maximum range of output values determined by
6713 ** constraints on the "value" column.
6714 */
6715 if( idxNum & 0x0080 ){
6716 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6717 double r = sqlite3_value_double(argv[i++]);
6718 if( r==ceil(r) ){
6719 iMin = iMax = (sqlite3_int64)r;
6720 }else{
6721 returnNoRows = 1;
6722 }
6723 }else{
6724 iMin = iMax = sqlite3_value_int64(argv[i++]);
6725 }
6726 }else{
6727 if( idxNum & 0x0300 ){
6728 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6729 double r = sqlite3_value_double(argv[i++]);
6730 if( idxNum & 0x0200 && r==ceil(r) ){
6731 iMin = (sqlite3_int64)ceil(r+1.0);
6732 }else{
6733 iMin = (sqlite3_int64)ceil(r);
6734 }
6735 }else{
6736 iMin = sqlite3_value_int64(argv[i++]);
6737 if( idxNum & 0x0200 ){
6738 if( iMin==LARGEST_INT64 ){
6739 returnNoRows = 1;
6740 }else{
6741 iMin++;
6742 }
6743 }
6744 }
6745 }
6746 if( idxNum & 0x3000 ){
6747 if( sqlite3_value_numeric_type(argv[i])==SQLITE_FLOAT ){
6748 double r = sqlite3_value_double(argv[i++]);
6749 if( (idxNum & 0x2000)!=0 && r==floor(r) ){
6750 iMax = (sqlite3_int64)(r-1.0);
6751 }else{
6752 iMax = (sqlite3_int64)floor(r);
6753 }
6754 }else{
6755 iMax = sqlite3_value_int64(argv[i++]);
6756 if( idxNum & 0x2000 ){
6757 if( iMax==SMALLEST_INT64 ){
6758 returnNoRows = 1;
6759 }else{
6760 iMax--;
6761 }
6762 }
6763 }
6764 }
6765 if( iMin>iMax ){
6766 returnNoRows = 1;
@@ -6867,11 +6913,14 @@
6913 idxNum |= 0x40;
6914 }
6915 continue;
6916 }
6917 if( pConstraint->iColumn<SERIES_COLUMN_START ){
6918 if( (pConstraint->iColumn==SERIES_COLUMN_VALUE ||
6919 pConstraint->iColumn==SERIES_COLUMN_ROWID)
6920 && pConstraint->usable
6921 ){
6922 switch( op ){
6923 case SQLITE_INDEX_CONSTRAINT_EQ:
6924 case SQLITE_INDEX_CONSTRAINT_IS: {
6925 idxNum |= 0x0080;
6926 idxNum &= ~0x3300;
@@ -24197,13 +24246,18 @@
24246 j++;
24247 }while( (n&7)!=0 && n<mxWidth );
24248 i++;
24249 continue;
24250 }
24251 if( c==0x1b && p->eEscMode==SHELL_ESC_OFF && (k = isVt100(&z[i]))>0 ){
24252 i += k;
24253 j += k;
24254 }else{
24255 n++;
24256 j += 3;
24257 i++;
24258 }
24259 }
24260 if( n>=mxWidth && bWordWrap ){
24261 /* Perhaps try to back up to a better place to break the line */
24262 for(k=i; k>i/2; k--){
24263 if( IsSpace(z[k-1]) ) break;
@@ -24265,13 +24319,21 @@
24319 break;
24320 case SHELL_ESC_ASCII:
24321 zOut[j++] = '^';
24322 zOut[j++] = 0x40 + c;
24323 break;
24324 case SHELL_ESC_OFF: {
24325 int nn;
24326 if( c==0x1b && (nn = isVt100(&z[i]))>0 ){
24327 memcpy(&zOut[j], &z[i], nn);
24328 j += nn;
24329 i += nn - 1;
24330 }else{
24331 zOut[j++] = c;
24332 }
24333 break;
24334 }
24335 }
24336 i++;
24337 }
24338 zOut[j] = 0;
24339 return (char*)zOut;
@@ -27021,11 +27083,11 @@
27083 for(i=0; i<pgSz; i+=16){
27084 const u8 *aLine = aData+i;
27085 for(j=0; j<16 && aLine[j]==0; j++){}
27086 if( j==16 ) continue;
27087 if( !seenPageLabel ){
27088 sqlite3_fprintf(p->out, "| page %lld offset %lld\n",pgno,(pgno-1)*pgSz);
27089 seenPageLabel = 1;
27090 }
27091 sqlite3_fprintf(p->out, "| %5d:", i);
27092 for(j=0; j<16; j++) sqlite3_fprintf(p->out, " %02x", aLine[j]);
27093 sqlite3_fprintf(p->out, " ");
27094
+428 -115
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 18bda13e197e4b4ec7464b3e70012f71edc0 with changes in files:
21
+** 121f4d97f9a855131859d342bc2ade5f8c34 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468468
#define SQLITE_VERSION "3.50.0"
469469
#define SQLITE_VERSION_NUMBER 3050000
470
-#define SQLITE_SOURCE_ID "2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185"
470
+#define SQLITE_SOURCE_ID "2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -30270,10 +30270,12 @@
3027030270
*/
3027130271
#include "windows.h"
3027230272
3027330273
#ifdef __CYGWIN__
3027430274
# include <sys/cygwin.h>
30275
+# include <sys/stat.h> /* amalgamator: dontcache */
30276
+# include <unistd.h> /* amalgamator: dontcache */
3027530277
# include <errno.h> /* amalgamator: dontcache */
3027630278
#endif
3027730279
3027830280
/*
3027930281
** Determine if we are dealing with Windows NT.
@@ -47726,20 +47728,20 @@
4772647728
{ "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
4772747729
#else
4772847730
{ "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
4772947731
#endif
4773047732
47731
-#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
47733
+#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(const FILETIME*, \
4773247734
LPFILETIME))aSyscall[11].pCurrent)
4773347735
4773447736
#if SQLITE_OS_WINCE
4773547737
{ "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
4773647738
#else
4773747739
{ "FileTimeToSystemTime", (SYSCALL)0, 0 },
4773847740
#endif
4773947741
47740
-#define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
47742
+#define osFileTimeToSystemTime ((BOOL(WINAPI*)(const FILETIME*, \
4774147743
LPSYSTEMTIME))aSyscall[12].pCurrent)
4774247744
4774347745
{ "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
4774447746
4774547747
#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
@@ -48015,11 +48017,11 @@
4801548017
{ "LockFile", (SYSCALL)LockFile, 0 },
4801648018
#else
4801748019
{ "LockFile", (SYSCALL)0, 0 },
4801848020
#endif
4801948021
48020
-#ifndef osLockFile
48022
+#if !defined(osLockFile) && defined(SQLITE_WIN32_HAS_ANSI)
4802148023
#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
4802248024
DWORD))aSyscall[47].pCurrent)
4802348025
#endif
4802448026
4802548027
#if !SQLITE_OS_WINCE
@@ -48079,20 +48081,20 @@
4807948081
4808048082
#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
4808148083
4808248084
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
4808348085
48084
-#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
48086
+#define osSystemTimeToFileTime ((BOOL(WINAPI*)(const SYSTEMTIME*, \
4808548087
LPFILETIME))aSyscall[56].pCurrent)
4808648088
4808748089
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
4808848090
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
4808948091
#else
4809048092
{ "UnlockFile", (SYSCALL)0, 0 },
4809148093
#endif
4809248094
48093
-#ifndef osUnlockFile
48095
+#if !defined(osUnlockFile) && defined(SQLITE_WIN32_HAS_ANSI)
4809448096
#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
4809548097
DWORD))aSyscall[57].pCurrent)
4809648098
#endif
4809748099
4809848100
#if !SQLITE_OS_WINCE
@@ -48316,10 +48318,67 @@
4831648318
{ "CancelIo", (SYSCALL)0, 0 },
4831748319
#endif
4831848320
4831948321
#define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
4832048322
48323
+#if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
48324
+ { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
48325
+#else
48326
+ { "GetModuleHandleW", (SYSCALL)0, 0 },
48327
+#endif
48328
+
48329
+#define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[82].pCurrent)
48330
+
48331
+#ifndef _WIN32
48332
+ { "getenv", (SYSCALL)getenv, 0 },
48333
+#else
48334
+ { "getenv", (SYSCALL)0, 0 },
48335
+#endif
48336
+
48337
+#define osGetenv ((const char *(*)(const char *))aSyscall[83].pCurrent)
48338
+
48339
+#ifndef _WIN32
48340
+ { "getcwd", (SYSCALL)getcwd, 0 },
48341
+#else
48342
+ { "getcwd", (SYSCALL)0, 0 },
48343
+#endif
48344
+
48345
+#define osGetcwd ((char*(*)(char*,size_t))aSyscall[84].pCurrent)
48346
+
48347
+#ifndef _WIN32
48348
+ { "readlink", (SYSCALL)readlink, 0 },
48349
+#else
48350
+ { "readlink", (SYSCALL)0, 0 },
48351
+#endif
48352
+
48353
+#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[85].pCurrent)
48354
+
48355
+#ifndef _WIN32
48356
+ { "lstat", (SYSCALL)lstat, 0 },
48357
+#else
48358
+ { "lstat", (SYSCALL)0, 0 },
48359
+#endif
48360
+
48361
+#define osLstat ((int(*)(const char*,struct stat*))aSyscall[86].pCurrent)
48362
+
48363
+#ifndef _WIN32
48364
+ { "__errno", (SYSCALL)__errno, 0 },
48365
+#else
48366
+ { "__errno", (SYSCALL)0, 0 },
48367
+#endif
48368
+
48369
+#define osErrno (*((int*(*)(void))aSyscall[87].pCurrent)())
48370
+
48371
+#ifndef _WIN32
48372
+ { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
48373
+#else
48374
+ { "cygwin_conv_path", (SYSCALL)0, 0 },
48375
+#endif
48376
+
48377
+#define osCygwin_conv_path ((size_t(*)(unsigned int, \
48378
+ const void *, void *, size_t))aSyscall[88].pCurrent)
48379
+
4832148380
}; /* End of the overrideable system calls */
4832248381
4832348382
/*
4832448383
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
4832548384
** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48489,10 +48548,11 @@
4848948548
sqlite3_mutex_leave(pMainMtx);
4849048549
return rc;
4849148550
}
4849248551
#endif /* SQLITE_WIN32_MALLOC */
4849348552
48553
+#ifdef _WIN32
4849448554
/*
4849548555
** This function outputs the specified (ANSI) string to the Win32 debugger
4849648556
** (if available).
4849748557
*/
4849848558
@@ -48531,10 +48591,11 @@
4853148591
}else{
4853248592
fprintf(stderr, "%s", zBuf);
4853348593
}
4853448594
#endif
4853548595
}
48596
+#endif /* _WIN32 */
4853648597
4853748598
/*
4853848599
** The following routine suspends the current thread for at least ms
4853948600
** milliseconds. This is equivalent to the Win32 Sleep() interface.
4854048601
*/
@@ -48831,10 +48892,11 @@
4883148892
SQLITE_PRIVATE void sqlite3MemSetDefault(void){
4883248893
sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
4883348894
}
4883448895
#endif /* SQLITE_WIN32_MALLOC */
4883548896
48897
+#ifdef _WIN32
4883648898
/*
4883748899
** Convert a UTF-8 string to Microsoft Unicode.
4883848900
**
4883948901
** Space to hold the returned string is obtained from sqlite3_malloc().
4884048902
*/
@@ -48856,10 +48918,11 @@
4885648918
sqlite3_free(zWideText);
4885748919
zWideText = 0;
4885848920
}
4885948921
return zWideText;
4886048922
}
48923
+#endif /* _WIN32 */
4886148924
4886248925
/*
4886348926
** Convert a Microsoft Unicode string to UTF-8.
4886448927
**
4886548928
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48890,32 +48953,33 @@
4889048953
** code page.
4889148954
**
4889248955
** Space to hold the returned string is obtained from sqlite3_malloc().
4889348956
*/
4889448957
static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){
48895
- int nByte;
48958
+ int nWideChar;
4889648959
LPWSTR zMbcsText;
4889748960
int codepage = useAnsi ? CP_ACP : CP_OEMCP;
4889848961
48899
- nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
48900
- 0)*sizeof(WCHAR);
48901
- if( nByte==0 ){
48962
+ nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
48963
+ 0);
48964
+ if( nWideChar==0 ){
4890248965
return 0;
4890348966
}
48904
- zMbcsText = sqlite3MallocZero( nByte*sizeof(WCHAR) );
48967
+ zMbcsText = sqlite3MallocZero( nWideChar*sizeof(WCHAR) );
4890548968
if( zMbcsText==0 ){
4890648969
return 0;
4890748970
}
48908
- nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
48909
- nByte);
48910
- if( nByte==0 ){
48971
+ nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
48972
+ nWideChar);
48973
+ if( nWideChar==0 ){
4891148974
sqlite3_free(zMbcsText);
4891248975
zMbcsText = 0;
4891348976
}
4891448977
return zMbcsText;
4891548978
}
4891648979
48980
+#ifdef _WIN32
4891748981
/*
4891848982
** Convert a Microsoft Unicode string to a multi-byte character string,
4891948983
** using the ANSI or OEM code page.
4892048984
**
4892148985
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48939,10 +49003,11 @@
4893949003
sqlite3_free(zText);
4894049004
zText = 0;
4894149005
}
4894249006
return zText;
4894349007
}
49008
+#endif /* _WIN32 */
4894449009
4894549010
/*
4894649011
** Convert a multi-byte character string to UTF-8.
4894749012
**
4894849013
** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48958,10 +49023,11 @@
4895849023
zTextUtf8 = winUnicodeToUtf8(zTmpWide);
4895949024
sqlite3_free(zTmpWide);
4896049025
return zTextUtf8;
4896149026
}
4896249027
49028
+#ifdef _WIN32
4896349029
/*
4896449030
** Convert a UTF-8 string to a multi-byte character string.
4896549031
**
4896649032
** Space to hold the returned string is obtained from sqlite3_malloc().
4896749033
*/
@@ -49007,10 +49073,11 @@
4900749073
#ifndef SQLITE_OMIT_AUTOINIT
4900849074
if( sqlite3_initialize() ) return 0;
4900949075
#endif
4901049076
return winUnicodeToUtf8(zWideText);
4901149077
}
49078
+#endif /* _WIN32 */
4901249079
4901349080
/*
4901449081
** This is a public wrapper for the winMbcsToUtf8() function.
4901549082
*/
4901649083
SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -49024,10 +49091,11 @@
4902449091
if( sqlite3_initialize() ) return 0;
4902549092
#endif
4902649093
return winMbcsToUtf8(zText, osAreFileApisANSI());
4902749094
}
4902849095
49096
+#ifdef _WIN32
4902949097
/*
4903049098
** This is a public wrapper for the winMbcsToUtf8() function.
4903149099
*/
4903249100
SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
4903349101
#ifdef SQLITE_ENABLE_API_ARMOR
@@ -49148,10 +49216,11 @@
4914849216
unsigned long type, /* Identifier for directory being set or reset */
4914949217
void *zValue /* New value for directory being set or reset */
4915049218
){
4915149219
return sqlite3_win32_set_directory16(type, zValue);
4915249220
}
49221
+#endif /* _WIN32 */
4915349222
4915449223
/*
4915549224
** The return value of winGetLastErrorMsg
4915649225
** is zero if the error message fits in the buffer, or non-zero
4915749226
** otherwise (if the message was truncated).
@@ -49696,13 +49765,15 @@
4969649765
OVERLAPPED ovlp;
4969749766
memset(&ovlp, 0, sizeof(OVERLAPPED));
4969849767
ovlp.Offset = offsetLow;
4969949768
ovlp.OffsetHigh = offsetHigh;
4970049769
return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
49770
+#ifdef SQLITE_WIN32_HAS_ANSI
4970149771
}else{
4970249772
return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
4970349773
numBytesHigh);
49774
+#endif
4970449775
}
4970549776
#endif
4970649777
}
4970749778
4970849779
/*
@@ -49806,13 +49877,15 @@
4980649877
OVERLAPPED ovlp;
4980749878
memset(&ovlp, 0, sizeof(OVERLAPPED));
4980849879
ovlp.Offset = offsetLow;
4980949880
ovlp.OffsetHigh = offsetHigh;
4981049881
return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
49882
+#ifdef SQLITE_WIN32_HAS_ANSI
4981149883
}else{
4981249884
return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
4981349885
numBytesHigh);
49886
+#endif
4981449887
}
4981549888
#endif
4981649889
}
4981749890
4981849891
/*
@@ -51222,18 +51295,95 @@
5122251295
5122351296
/*
5122451297
** Convert a UTF-8 filename into whatever form the underlying
5122551298
** operating system wants filenames in. Space to hold the result
5122651299
** is obtained from malloc and must be freed by the calling
51227
-** function.
51300
+** function
51301
+**
51302
+** On Cygwin, 3 possible input forms are accepted:
51303
+** - If the filename starts with "<drive>:/" or "<drive>:\",
51304
+** it is converted to UTF-16 as-is.
51305
+** - If the filename contains '/', it is assumed to be a
51306
+** Cygwin absolute path, it is converted to a win32
51307
+** absolute path in UTF-16.
51308
+** - Otherwise it must be a filename only, the win32 filename
51309
+** is returned in UTF-16.
51310
+** Note: If the function cygwin_conv_path() fails, only
51311
+** UTF-8 -> UTF-16 conversion will be done. This can only
51312
+** happen when the file path >32k, in which case winUtf8ToUnicode()
51313
+** will fail too.
5122851314
*/
5122951315
static void *winConvertFromUtf8Filename(const char *zFilename){
5123051316
void *zConverted = 0;
5123151317
if( osIsNT() ){
51318
+#ifdef __CYGWIN__
51319
+ int nChar;
51320
+ LPWSTR zWideFilename;
51321
+
51322
+ if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51323
+ && winIsDirSep(zFilename[2])) ){
51324
+ int nByte;
51325
+ int convertflag = CCP_POSIX_TO_WIN_W;
51326
+ if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51327
+ nByte = (int)osCygwin_conv_path(convertflag,
51328
+ zFilename, 0, 0);
51329
+ if( nByte>0 ){
51330
+ zConverted = sqlite3MallocZero(nByte+12);
51331
+ if ( zConverted==0 ){
51332
+ return zConverted;
51333
+ }
51334
+ zWideFilename = zConverted;
51335
+ /* Filenames should be prefixed, except when converted
51336
+ * full path already starts with "\\?\". */
51337
+ if( osCygwin_conv_path(convertflag, zFilename,
51338
+ zWideFilename+4, nByte)==0 ){
51339
+ if( (convertflag&CCP_RELATIVE) ){
51340
+ memmove(zWideFilename, zWideFilename+4, nByte);
51341
+ }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
51342
+ memcpy(zWideFilename, L"\\\\?\\", 8);
51343
+ }else if( zWideFilename[6]!='?' ){
51344
+ memmove(zWideFilename+6, zWideFilename+4, nByte);
51345
+ memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51346
+ }else{
51347
+ memmove(zWideFilename, zWideFilename+4, nByte);
51348
+ }
51349
+ return zConverted;
51350
+ }
51351
+ sqlite3_free(zConverted);
51352
+ }
51353
+ }
51354
+ nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51355
+ if( nChar==0 ){
51356
+ return 0;
51357
+ }
51358
+ zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
51359
+ if( zWideFilename==0 ){
51360
+ return 0;
51361
+ }
51362
+ nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51363
+ zWideFilename, nChar);
51364
+ if( nChar==0 ){
51365
+ sqlite3_free(zWideFilename);
51366
+ zWideFilename = 0;
51367
+ }else if( nChar>MAX_PATH
51368
+ && winIsDriveLetterAndColon(zFilename)
51369
+ && winIsDirSep(zFilename[2]) ){
51370
+ memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
51371
+ zWideFilename[2] = '\\';
51372
+ memcpy(zWideFilename, L"\\\\?\\", 8);
51373
+ }else if( nChar>MAX_PATH
51374
+ && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51375
+ && zFilename[2] != '?' ){
51376
+ memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
51377
+ memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51378
+ }
51379
+ zConverted = zWideFilename;
51380
+#else
5123251381
zConverted = winUtf8ToUnicode(zFilename);
51382
+#endif /* __CYGWIN__ */
5123351383
}
51234
-#ifdef SQLITE_WIN32_HAS_ANSI
51384
+#if defined(SQLITE_WIN32_HAS_ANSI) && defined(_WIN32)
5123551385
else{
5123651386
zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
5123751387
}
5123851388
#endif
5123951389
/* caller will handle out of memory */
@@ -52058,11 +52208,11 @@
5205852208
**
5205952209
** This division contains the implementation of methods on the
5206052210
** sqlite3_vfs object.
5206152211
*/
5206252212
52063
-#if defined(__CYGWIN__)
52213
+#if 0 /* No longer necessary */
5206452214
/*
5206552215
** Convert a filename from whatever the underlying operating system
5206652216
** supports for filenames into UTF-8. Space to hold the result is
5206752217
** obtained from malloc and must be freed by the calling function.
5206852218
*/
@@ -52091,11 +52241,18 @@
5209152241
int nLen = sqlite3Strlen30(zBuf);
5209252242
if( nLen>0 ){
5209352243
if( winIsDirSep(zBuf[nLen-1]) ){
5209452244
return 1;
5209552245
}else if( nLen+1<nBuf ){
52096
- zBuf[nLen] = winGetDirSep();
52246
+ if( !osGetenv ){
52247
+ zBuf[nLen] = winGetDirSep();
52248
+ }else if( winIsDriveLetterAndColon(zBuf) && winIsDirSep(zBuf[2]) ){
52249
+ zBuf[nLen] = '\\';
52250
+ zBuf[2]='\\';
52251
+ }else{
52252
+ zBuf[nLen] = '/';
52253
+ }
5209752254
zBuf[nLen+1] = '\0';
5209852255
return 1;
5209952256
}
5210052257
}
5210152258
}
@@ -52118,11 +52275,11 @@
5211852275
/*
5211952276
** Create a temporary file name and store the resulting pointer into pzBuf.
5212052277
** The pointer returned in pzBuf must be freed via sqlite3_free().
5212152278
*/
5212252279
static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
52123
- static char zChars[] =
52280
+ static const char zChars[] =
5212452281
"abcdefghijklmnopqrstuvwxyz"
5212552282
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
5212652283
"0123456789";
5212752284
size_t i, j;
5212852285
DWORD pid;
@@ -52169,11 +52326,11 @@
5216952326
}
5217052327
sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
5217152328
}
5217252329
5217352330
#if defined(__CYGWIN__)
52174
- else{
52331
+ else if( osGetenv!=NULL ){
5217552332
static const char *azDirs[] = {
5217652333
0, /* getenv("SQLITE_TMPDIR") */
5217752334
0, /* getenv("TMPDIR") */
5217852335
0, /* getenv("TMP") */
5217952336
0, /* getenv("TEMP") */
@@ -52185,24 +52342,24 @@
5218552342
0 /* List terminator */
5218652343
};
5218752344
unsigned int i;
5218852345
const char *zDir = 0;
5218952346
52190
- if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
52191
- if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
52192
- if( !azDirs[2] ) azDirs[2] = getenv("TMP");
52193
- if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
52194
- if( !azDirs[4] ) azDirs[4] = getenv("USERPROFILE");
52347
+ if( !azDirs[0] ) azDirs[0] = osGetenv("SQLITE_TMPDIR");
52348
+ if( !azDirs[1] ) azDirs[1] = osGetenv("TMPDIR");
52349
+ if( !azDirs[2] ) azDirs[2] = osGetenv("TMP");
52350
+ if( !azDirs[3] ) azDirs[3] = osGetenv("TEMP");
52351
+ if( !azDirs[4] ) azDirs[4] = osGetenv("USERPROFILE");
5219552352
for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
5219652353
void *zConverted;
5219752354
if( zDir==0 ) continue;
5219852355
/* If the path starts with a drive letter followed by the colon
5219952356
** character, assume it is already a native Win32 path; otherwise,
5220052357
** it must be converted to a native Win32 path via the Cygwin API
5220152358
** prior to using it.
5220252359
*/
52203
- if( winIsDriveLetterAndColon(zDir) ){
52360
+ {
5220452361
zConverted = winConvertFromUtf8Filename(zDir);
5220552362
if( !zConverted ){
5220652363
sqlite3_free(zBuf);
5220752364
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5220852365
return SQLITE_IOERR_NOMEM_BKPT;
@@ -52211,19 +52368,20 @@
5221152368
sqlite3_snprintf(nMax, zBuf, "%s", zDir);
5221252369
sqlite3_free(zConverted);
5221352370
break;
5221452371
}
5221552372
sqlite3_free(zConverted);
52373
+#if 0 /* No longer necessary */
5221652374
}else{
5221752375
zConverted = sqlite3MallocZero( nMax+1 );
5221852376
if( !zConverted ){
5221952377
sqlite3_free(zBuf);
5222052378
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
5222152379
return SQLITE_IOERR_NOMEM_BKPT;
5222252380
}
52223
- if( cygwin_conv_path(
52224
- osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
52381
+ if( osCygwin_conv_path(
52382
+ CCP_POSIX_TO_WIN_W, zDir,
5222552383
zConverted, nMax+1)<0 ){
5222652384
sqlite3_free(zConverted);
5222752385
sqlite3_free(zBuf);
5222852386
OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
5222952387
return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
@@ -52245,14 +52403,17 @@
5224552403
sqlite3_free(zUtf8);
5224652404
sqlite3_free(zConverted);
5224752405
break;
5224852406
}
5224952407
sqlite3_free(zConverted);
52408
+#endif /* No longer necessary */
5225052409
}
5225152410
}
5225252411
}
52253
-#elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
52412
+#endif
52413
+
52414
+#if !SQLITE_OS_WINRT && defined(_WIN32)
5225452415
else if( osIsNT() ){
5225552416
char *zMulti;
5225652417
LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
5225752418
if( !zWidePath ){
5225852419
sqlite3_free(zBuf);
@@ -52372,11 +52533,11 @@
5237252533
&sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
5237352534
if( !rc ){
5237452535
return 0; /* Invalid name? */
5237552536
}
5237652537
attr = sAttrData.dwFileAttributes;
52377
-#if SQLITE_OS_WINCE==0
52538
+#if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
5237852539
}else{
5237952540
attr = osGetFileAttributesA((char*)zConverted);
5238052541
#endif
5238152542
}
5238252543
return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
@@ -52388,10 +52549,16 @@
5238852549
const char *zFilename, /* Name of file to check */
5238952550
int flags, /* Type of test to make on this file */
5239052551
int *pResOut /* OUT: Result */
5239152552
);
5239252553
52554
+/*
52555
+** The Windows version of xAccess() accepts an extra bit in the flags
52556
+** parameter that prevents an anti-virus retry loop.
52557
+*/
52558
+#define NORETRY 0x4000
52559
+
5239352560
/*
5239452561
** Open a file.
5239552562
*/
5239652563
static int winOpen(
5239752564
sqlite3_vfs *pVfs, /* Used to get maximum path length and AppData */
@@ -52412,10 +52579,11 @@
5241252579
winVfsAppData *pAppData;
5241352580
winFile *pFile = (winFile*)id;
5241452581
void *zConverted; /* Filename in OS encoding */
5241552582
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
5241652583
int cnt = 0;
52584
+ int isRO = 0; /* file is known to be accessible readonly */
5241752585
5241852586
/* If argument zPath is a NULL pointer, this function is required to open
5241952587
** a temporary file. Use this buffer to store the file name in.
5242052588
*/
5242152589
char *zTmpname = 0; /* For temporary filename, if necessary. */
@@ -52576,13 +52744,13 @@
5257652744
dwShareMode,
5257752745
dwCreationDisposition,
5257852746
&extendedParameters);
5257952747
if( h!=INVALID_HANDLE_VALUE ) break;
5258052748
if( isReadWrite ){
52581
- int rc2, isRO = 0;
52749
+ int rc2;
5258252750
sqlite3BeginBenignMalloc();
52583
- rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52751
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
5258452752
sqlite3EndBenignMalloc();
5258552753
if( rc2==SQLITE_OK && isRO ) break;
5258652754
}
5258752755
}while( winRetryIoerr(&cnt, &lastErrno) );
5258852756
#else
@@ -52593,13 +52761,13 @@
5259352761
dwCreationDisposition,
5259452762
dwFlagsAndAttributes,
5259552763
NULL);
5259652764
if( h!=INVALID_HANDLE_VALUE ) break;
5259752765
if( isReadWrite ){
52598
- int rc2, isRO = 0;
52766
+ int rc2;
5259952767
sqlite3BeginBenignMalloc();
52600
- rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52768
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
5260152769
sqlite3EndBenignMalloc();
5260252770
if( rc2==SQLITE_OK && isRO ) break;
5260352771
}
5260452772
}while( winRetryIoerr(&cnt, &lastErrno) );
5260552773
#endif
@@ -52613,13 +52781,13 @@
5261352781
dwCreationDisposition,
5261452782
dwFlagsAndAttributes,
5261552783
NULL);
5261652784
if( h!=INVALID_HANDLE_VALUE ) break;
5261752785
if( isReadWrite ){
52618
- int rc2, isRO = 0;
52786
+ int rc2;
5261952787
sqlite3BeginBenignMalloc();
52620
- rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52788
+ rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
5262152789
sqlite3EndBenignMalloc();
5262252790
if( rc2==SQLITE_OK && isRO ) break;
5262352791
}
5262452792
}while( winRetryIoerr(&cnt, &lastErrno) );
5262552793
}
@@ -52630,11 +52798,11 @@
5263052798
dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
5263152799
5263252800
if( h==INVALID_HANDLE_VALUE ){
5263352801
sqlite3_free(zConverted);
5263452802
sqlite3_free(zTmpname);
52635
- if( isReadWrite && !isExclusive ){
52803
+ if( isReadWrite && isRO && !isExclusive ){
5263652804
return winOpen(pVfs, zName, id,
5263752805
((flags|SQLITE_OPEN_READONLY) &
5263852806
~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)),
5263952807
pOutFlags);
5264052808
}else{
@@ -52832,11 +53000,17 @@
5283253000
){
5283353001
DWORD attr;
5283453002
int rc = 0;
5283553003
DWORD lastErrno = 0;
5283653004
void *zConverted;
53005
+ int noRetry = 0; /* Do not use winRetryIoerr() */
5283753006
UNUSED_PARAMETER(pVfs);
53007
+
53008
+ if( (flags & NORETRY)!=0 ){
53009
+ noRetry = 1;
53010
+ flags &= ~NORETRY;
53011
+ }
5283853012
5283953013
SimulateIOError( return SQLITE_IOERR_ACCESS; );
5284053014
OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
5284153015
zFilename, flags, pResOut));
5284253016
@@ -52856,11 +53030,14 @@
5285653030
int cnt = 0;
5285753031
WIN32_FILE_ATTRIBUTE_DATA sAttrData;
5285853032
memset(&sAttrData, 0, sizeof(sAttrData));
5285953033
while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
5286053034
GetFileExInfoStandard,
52861
- &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
53035
+ &sAttrData))
53036
+ && !noRetry
53037
+ && winRetryIoerr(&cnt, &lastErrno)
53038
+ ){ /* Loop until true */}
5286253039
if( rc ){
5286353040
/* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
5286453041
** as if it does not exist.
5286553042
*/
5286653043
if( flags==SQLITE_ACCESS_EXISTS
@@ -52924,10 +53101,11 @@
5292453101
const char *zPathname
5292553102
){
5292653103
return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
5292753104
}
5292853105
53106
+#ifdef _WIN32
5292953107
/*
5293053108
** Returns non-zero if the specified path name should be used verbatim. If
5293153109
** non-zero is returned from this function, the calling function must simply
5293253110
** use the provided path name verbatim -OR- resolve it into a full path name
5293353111
** using the GetFullPathName Win32 API function (if available).
@@ -52960,10 +53138,74 @@
5296053138
** If we get to this point, the path name should almost certainly be a purely
5296153139
** relative one (i.e. not a UNC name, not absolute, and not volume relative).
5296253140
*/
5296353141
return FALSE;
5296453142
}
53143
+#endif /* _WIN32 */
53144
+
53145
+#ifdef __CYGWIN__
53146
+/*
53147
+** Simplify a filename into its canonical form
53148
+** by making the following changes:
53149
+**
53150
+** * convert any '/' to '\' (win32) or reverse (Cygwin)
53151
+** * removing any trailing and duplicate / (except for UNC paths)
53152
+** * convert /./ into just /
53153
+**
53154
+** Changes are made in-place. Return the new name length.
53155
+**
53156
+** The original filename is in z[0..]. If the path is shortened,
53157
+** no-longer used bytes will be written by '\0'.
53158
+*/
53159
+static void winSimplifyName(char *z){
53160
+ int i, j;
53161
+ for(i=j=0; z[i]; ++i){
53162
+ if( winIsDirSep(z[i]) ){
53163
+#if !defined(SQLITE_TEST)
53164
+ /* Some test-cases assume that "./foo" and "foo" are different */
53165
+ if( z[i+1]=='.' && winIsDirSep(z[i+2]) ){
53166
+ ++i;
53167
+ continue;
53168
+ }
53169
+#endif
53170
+ if( !z[i+1] || (winIsDirSep(z[i+1]) && (i!=0)) ){
53171
+ continue;
53172
+ }
53173
+ z[j++] = osGetenv?'/':'\\';
53174
+ }else{
53175
+ z[j++] = z[i];
53176
+ }
53177
+ }
53178
+ while(j<i) z[j++] = '\0';
53179
+}
53180
+
53181
+#define SQLITE_MAX_SYMLINKS 100
53182
+
53183
+static int mkFullPathname(
53184
+ const char *zPath, /* Input path */
53185
+ char *zOut, /* Output buffer */
53186
+ int nOut /* Allocated size of buffer zOut */
53187
+){
53188
+ int nPath = sqlite3Strlen30(zPath);
53189
+ int iOff = 0;
53190
+ if( zPath[0]!='/' ){
53191
+ if( osGetcwd(zOut, nOut-2)==0 ){
53192
+ return winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "getcwd", zPath);
53193
+ }
53194
+ iOff = sqlite3Strlen30(zOut);
53195
+ zOut[iOff++] = '/';
53196
+ }
53197
+ if( (iOff+nPath+1)>nOut ){
53198
+ /* SQLite assumes that xFullPathname() nul-terminates the output buffer
53199
+ ** even if it returns an error. */
53200
+ zOut[iOff] = '\0';
53201
+ return SQLITE_CANTOPEN_BKPT;
53202
+ }
53203
+ sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
53204
+ return SQLITE_OK;
53205
+}
53206
+#endif /* __CYGWIN__ */
5296553207
5296653208
/*
5296753209
** Turn a relative pathname into a full pathname. Write the full
5296853210
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
5296953211
** bytes in size.
@@ -52972,12 +53214,12 @@
5297253214
sqlite3_vfs *pVfs, /* Pointer to vfs object */
5297353215
const char *zRelative, /* Possibly relative input path */
5297453216
int nFull, /* Size of output buffer in bytes */
5297553217
char *zFull /* Output buffer */
5297653218
){
52977
-#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
52978
- DWORD nByte;
53219
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
53220
+ int nByte;
5297953221
void *zConverted;
5298053222
char *zOut;
5298153223
#endif
5298253224
5298353225
/* If this path name begins with "/X:" or "\\?\", where "X" is any
@@ -52986,68 +53228,114 @@
5298653228
if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
5298753229
|| winIsLongPathPrefix(zRelative+1)) ){
5298853230
zRelative++;
5298953231
}
5299053232
52991
-#if defined(__CYGWIN__)
53233
+ SimulateIOError( return SQLITE_ERROR );
53234
+
53235
+#ifdef __CYGWIN__
53236
+ if( osGetcwd ){
53237
+ zFull[nFull-1] = '\0';
53238
+ if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){
53239
+ int rc = SQLITE_OK;
53240
+ int nLink = 1; /* Number of symbolic links followed so far */
53241
+ const char *zIn = zRelative; /* Input path for each iteration of loop */
53242
+ char *zDel = 0;
53243
+ struct stat buf;
53244
+
53245
+ UNUSED_PARAMETER(pVfs);
53246
+
53247
+ do {
53248
+ /* Call lstat() on path zIn. Set bLink to true if the path is a symbolic
53249
+ ** link, or false otherwise. */
53250
+ int bLink = 0;
53251
+ if( osLstat && osReadlink ) {
53252
+ if( osLstat(zIn, &buf)!=0 ){
53253
+ int myErrno = osErrno;
53254
+ if( myErrno!=ENOENT ){
53255
+ rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, "lstat", zIn);
53256
+ }
53257
+ }else{
53258
+ bLink = ((buf.st_mode & 0170000) == 0120000);
53259
+ }
53260
+
53261
+ if( bLink ){
53262
+ if( zDel==0 ){
53263
+ zDel = sqlite3MallocZero(nFull);
53264
+ if( zDel==0 ) rc = SQLITE_NOMEM;
53265
+ }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
53266
+ rc = SQLITE_CANTOPEN_BKPT;
53267
+ }
53268
+
53269
+ if( rc==SQLITE_OK ){
53270
+ nByte = osReadlink(zIn, zDel, nFull-1);
53271
+ if( nByte ==(DWORD)-1 ){
53272
+ rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn);
53273
+ }else{
53274
+ if( zDel[0]!='/' ){
53275
+ int n;
53276
+ for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
53277
+ if( nByte+n+1>nFull ){
53278
+ rc = SQLITE_CANTOPEN_BKPT;
53279
+ }else{
53280
+ memmove(&zDel[n], zDel, nByte+1);
53281
+ memcpy(zDel, zIn, n);
53282
+ nByte += n;
53283
+ }
53284
+ }
53285
+ zDel[nByte] = '\0';
53286
+ }
53287
+ }
53288
+
53289
+ zIn = zDel;
53290
+ }
53291
+ }
53292
+
53293
+ assert( rc!=SQLITE_OK || zIn!=zFull || zIn[0]=='/' );
53294
+ if( rc==SQLITE_OK && zIn!=zFull ){
53295
+ rc = mkFullPathname(zIn, zFull, nFull);
53296
+ }
53297
+ if( bLink==0 ) break;
53298
+ zIn = zFull;
53299
+ }while( rc==SQLITE_OK );
53300
+
53301
+ sqlite3_free(zDel);
53302
+ winSimplifyName(zFull);
53303
+ return rc;
53304
+ }
53305
+ }
53306
+#endif /* __CYGWIN__ */
53307
+#if 0 /* This doesn't work correctly at all! See:
53308
+ <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53309
+*/
5299253310
SimulateIOError( return SQLITE_ERROR );
5299353311
UNUSED_PARAMETER(nFull);
5299453312
assert( nFull>=pVfs->mxPathname );
52995
- if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
52996
- /*
52997
- ** NOTE: We are dealing with a relative path name and the data
52998
- ** directory has been set. Therefore, use it as the basis
52999
- ** for converting the relative path name to an absolute
53000
- ** one by prepending the data directory and a slash.
53001
- */
53002
- char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname );
53003
- if( !zOut ){
53004
- return SQLITE_IOERR_NOMEM_BKPT;
53005
- }
53006
- if( cygwin_conv_path(
53007
- (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
53008
- CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
53009
- sqlite3_free(zOut);
53010
- return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53011
- "winFullPathname1", zRelative);
53012
- }else{
53013
- char *zUtf8 = winConvertToUtf8Filename(zOut);
53014
- if( !zUtf8 ){
53015
- sqlite3_free(zOut);
53016
- return SQLITE_IOERR_NOMEM_BKPT;
53017
- }
53018
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
53019
- sqlite3_data_directory, winGetDirSep(), zUtf8);
53020
- sqlite3_free(zUtf8);
53021
- sqlite3_free(zOut);
53022
- }
53023
- }else{
53024
- char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
53025
- if( !zOut ){
53026
- return SQLITE_IOERR_NOMEM_BKPT;
53027
- }
53028
- if( cygwin_conv_path(
53029
- (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
53030
- zRelative, zOut, pVfs->mxPathname+1)<0 ){
53031
- sqlite3_free(zOut);
53032
- return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53033
- "winFullPathname2", zRelative);
53034
- }else{
53035
- char *zUtf8 = winConvertToUtf8Filename(zOut);
53036
- if( !zUtf8 ){
53037
- sqlite3_free(zOut);
53038
- return SQLITE_IOERR_NOMEM_BKPT;
53039
- }
53040
- sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
53041
- sqlite3_free(zUtf8);
53042
- sqlite3_free(zOut);
53043
- }
53044
- }
53045
- return SQLITE_OK;
53046
-#endif
53047
-
53048
-#if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__)
53313
+ char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
53314
+ if( !zOut ){
53315
+ return SQLITE_IOERR_NOMEM_BKPT;
53316
+ }
53317
+ if( osCygwin_conv_path(
53318
+ CCP_POSIX_TO_WIN_W,
53319
+ zRelative, zOut, pVfs->mxPathname+1)<0 ){
53320
+ sqlite3_free(zOut);
53321
+ return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53322
+ "winFullPathname2", zRelative);
53323
+ }else{
53324
+ char *zUtf8 = winConvertToUtf8Filename(zOut);
53325
+ if( !zUtf8 ){
53326
+ sqlite3_free(zOut);
53327
+ return SQLITE_IOERR_NOMEM_BKPT;
53328
+ }
53329
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
53330
+ sqlite3_free(zUtf8);
53331
+ sqlite3_free(zOut);
53332
+ }
53333
+ return SQLITE_OK;
53334
+#endif
53335
+
53336
+#if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && defined(_WIN32)
5304953337
SimulateIOError( return SQLITE_ERROR );
5305053338
/* WinCE has no concept of a relative pathname, or so I am told. */
5305153339
/* WinRT has no way to convert a relative path to an absolute one. */
5305253340
if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
5305353341
/*
@@ -53062,11 +53350,12 @@
5306253350
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
5306353351
}
5306453352
return SQLITE_OK;
5306553353
#endif
5306653354
53067
-#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
53355
+#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
53356
+#if defined(_WIN32)
5306853357
/* It's odd to simulate an io-error here, but really this is just
5306953358
** using the io-error infrastructure to test that SQLite handles this
5307053359
** function failing. This function could fail if, for example, the
5307153360
** current working directory has been unlinked.
5307253361
*/
@@ -53080,10 +53369,11 @@
5308053369
*/
5308153370
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
5308253371
sqlite3_data_directory, winGetDirSep(), zRelative);
5308353372
return SQLITE_OK;
5308453373
}
53374
+#endif
5308553375
zConverted = winConvertFromUtf8Filename(zRelative);
5308653376
if( zConverted==0 ){
5308753377
return SQLITE_IOERR_NOMEM_BKPT;
5308853378
}
5308953379
if( osIsNT() ){
@@ -53092,16 +53382,17 @@
5309253382
if( nByte==0 ){
5309353383
sqlite3_free(zConverted);
5309453384
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5309553385
"winFullPathname1", zRelative);
5309653386
}
53097
- zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
53387
+ nByte += 3;
53388
+ zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
5309853389
if( zTemp==0 ){
5309953390
sqlite3_free(zConverted);
5310053391
return SQLITE_IOERR_NOMEM_BKPT;
5310153392
}
53102
- nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0);
53393
+ nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
5310353394
if( nByte==0 ){
5310453395
sqlite3_free(zConverted);
5310553396
sqlite3_free(zTemp);
5310653397
return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
5310753398
"winFullPathname2", zRelative);
@@ -53135,11 +53426,30 @@
5313553426
zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
5313653427
sqlite3_free(zTemp);
5313753428
}
5313853429
#endif
5313953430
if( zOut ){
53431
+#ifdef __CYGWIN__
53432
+ if( memcmp(zOut, "\\\\?\\", 4) ){
53433
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
53434
+ }else if( memcmp(zOut+4, "UNC\\", 4) ){
53435
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut+4);
53436
+ }else{
53437
+ char *p = zOut+6;
53438
+ *p = '\\';
53439
+ if( osGetcwd ){
53440
+ /* On Cygwin, UNC paths use forward slashes */
53441
+ while( *p ){
53442
+ if( *p=='\\' ) *p = '/';
53443
+ ++p;
53444
+ }
53445
+ }
53446
+ sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut+6);
53447
+ }
53448
+#else
5314053449
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
53450
+#endif /* __CYGWIN__ */
5314153451
sqlite3_free(zOut);
5314253452
return SQLITE_OK;
5314353453
}else{
5314453454
return SQLITE_IOERR_NOMEM_BKPT;
5314553455
}
@@ -53165,11 +53475,13 @@
5316553475
** Interfaces for opening a shared library, finding entry points
5316653476
** within the shared library, and closing the shared library.
5316753477
*/
5316853478
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
5316953479
HANDLE h;
53170
-#if defined(__CYGWIN__)
53480
+#if 0 /* This doesn't work correctly at all! See:
53481
+ <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53482
+*/
5317153483
int nFull = pVfs->mxPathname+1;
5317253484
char *zFull = sqlite3MallocZero( nFull );
5317353485
void *zConverted = 0;
5317453486
if( zFull==0 ){
5317553487
OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
@@ -53532,11 +53844,11 @@
5353253844
};
5353353845
#endif
5353453846
5353553847
/* Double-check that the aSyscall[] array has been constructed
5353653848
** correctly. See ticket [bb3a86e890c8e96ab] */
53537
- assert( ArraySize(aSyscall)==82 );
53849
+ assert( ArraySize(aSyscall)==89 );
5353853850
5353953851
/* get memory map allocation granularity */
5354053852
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
5354153853
#if SQLITE_OS_WINRT
5354253854
osGetNativeSystemInfo(&winSysInfo);
@@ -66508,14 +66820,12 @@
6650866820
s2 = aIn[1];
6650966821
}else{
6651066822
s1 = s2 = 0;
6651166823
}
6651266824
66513
- assert( nByte>=8 );
66514
- assert( (nByte&0x00000007)==0 );
66515
- assert( nByte<=65536 );
66516
- assert( nByte%4==0 );
66825
+ /* nByte is a multiple of 8 between 8 and 65536 */
66826
+ assert( nByte>=8 && (nByte&7)==0 && nByte<=65536 );
6651766827
6651866828
if( !nativeCksum ){
6651966829
do {
6652066830
s1 += BYTESWAP32(aData[0]) + s2;
6652166831
s2 += BYTESWAP32(aData[1]) + s1;
@@ -147785,10 +148095,11 @@
147785148095
}
147786148096
147787148097
multi_select_end:
147788148098
pDest->iSdst = dest.iSdst;
147789148099
pDest->nSdst = dest.nSdst;
148100
+ pDest->iSDParm2 = dest.iSDParm2;
147790148101
if( pDelete ){
147791148102
sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pDelete);
147792148103
}
147793148104
return rc;
147794148105
}
@@ -188065,10 +188376,17 @@
188065188376
******************************************************************************
188066188377
**
188067188378
*/
188068188379
#ifndef _FTSINT_H
188069188380
#define _FTSINT_H
188381
+
188382
+/* #include <assert.h> */
188383
+/* #include <stdlib.h> */
188384
+/* #include <stddef.h> */
188385
+/* #include <stdio.h> */
188386
+/* #include <string.h> */
188387
+/* #include <stdarg.h> */
188070188388
188071188389
#if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
188072188390
# define NDEBUG 1
188073188391
#endif
188074188392
@@ -189017,16 +189335,10 @@
189017189335
189018189336
#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
189019189337
# define SQLITE_CORE 1
189020189338
#endif
189021189339
189022
-/* #include <assert.h> */
189023
-/* #include <stdlib.h> */
189024
-/* #include <stddef.h> */
189025
-/* #include <stdio.h> */
189026
-/* #include <string.h> */
189027
-/* #include <stdarg.h> */
189028189340
189029189341
/* #include "fts3.h" */
189030189342
#ifndef SQLITE_CORE
189031189343
/* # include "sqlite3ext.h" */
189032189344
SQLITE_EXTENSION_INIT1
@@ -227533,12 +227845,12 @@
227533227845
){
227534227846
if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
227535227847
/* "INSERT INTO dbpage($PGNO,NULL)" causes page number $PGNO and
227536227848
** all subsequent pages to be deleted. */
227537227849
pTab->iDbTrunc = iDb;
227538
- pgno--;
227539
- pTab->pgnoTrunc = pgno;
227850
+ pTab->pgnoTrunc = pgno-1;
227851
+ pgno = 1;
227540227852
}else{
227541227853
zErr = "bad page value";
227542227854
goto update_fail;
227543227855
}
227544227856
}
@@ -241869,11 +242181,12 @@
241869242181
sqlite3Fts5ParseError(
241870242182
pParse, "expected integer, got \"%.*s\"", p->n, p->p
241871242183
);
241872242184
return;
241873242185
}
241874
- nNear = nNear * 10 + (p->p[i] - '0');
242186
+ if( nNear<214748363 ) nNear = nNear * 10 + (p->p[i] - '0');
242187
+ /* ^^^^^^^^^^^^^^^--- Prevent integer overflow */
241875242188
}
241876242189
}else{
241877242190
nNear = FTS5_DEFAULT_NEARDIST;
241878242191
}
241879242192
pNear->nNear = nNear;
@@ -256775,11 +257088,11 @@
256775257088
int nArg, /* Number of args */
256776257089
sqlite3_value **apUnused /* Function arguments */
256777257090
){
256778257091
assert( nArg==0 );
256779257092
UNUSED_PARAM2(nArg, apUnused);
256780
- sqlite3_result_text(pCtx, "fts5: 2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185", -1, SQLITE_TRANSIENT);
257093
+ sqlite3_result_text(pCtx, "fts5: 2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85", -1, SQLITE_TRANSIENT);
256781257094
}
256782257095
256783257096
/*
256784257097
** Implementation of fts5_locale(LOCALE, TEXT) function.
256785257098
**
256786257099
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 18bda13e197e4b4ec7464b3e70012f71edc0 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.50.0"
469 #define SQLITE_VERSION_NUMBER 3050000
470 #define SQLITE_SOURCE_ID "2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -30270,10 +30270,12 @@
30270 */
30271 #include "windows.h"
30272
30273 #ifdef __CYGWIN__
30274 # include <sys/cygwin.h>
 
 
30275 # include <errno.h> /* amalgamator: dontcache */
30276 #endif
30277
30278 /*
30279 ** Determine if we are dealing with Windows NT.
@@ -47726,20 +47728,20 @@
47726 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
47727 #else
47728 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
47729 #endif
47730
47731 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
47732 LPFILETIME))aSyscall[11].pCurrent)
47733
47734 #if SQLITE_OS_WINCE
47735 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
47736 #else
47737 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
47738 #endif
47739
47740 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
47741 LPSYSTEMTIME))aSyscall[12].pCurrent)
47742
47743 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
47744
47745 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
@@ -48015,11 +48017,11 @@
48015 { "LockFile", (SYSCALL)LockFile, 0 },
48016 #else
48017 { "LockFile", (SYSCALL)0, 0 },
48018 #endif
48019
48020 #ifndef osLockFile
48021 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
48022 DWORD))aSyscall[47].pCurrent)
48023 #endif
48024
48025 #if !SQLITE_OS_WINCE
@@ -48079,20 +48081,20 @@
48079
48080 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
48081
48082 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
48083
48084 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
48085 LPFILETIME))aSyscall[56].pCurrent)
48086
48087 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
48088 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
48089 #else
48090 { "UnlockFile", (SYSCALL)0, 0 },
48091 #endif
48092
48093 #ifndef osUnlockFile
48094 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
48095 DWORD))aSyscall[57].pCurrent)
48096 #endif
48097
48098 #if !SQLITE_OS_WINCE
@@ -48316,10 +48318,67 @@
48316 { "CancelIo", (SYSCALL)0, 0 },
48317 #endif
48318
48319 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
48320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48321 }; /* End of the overrideable system calls */
48322
48323 /*
48324 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
48325 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48489,10 +48548,11 @@
48489 sqlite3_mutex_leave(pMainMtx);
48490 return rc;
48491 }
48492 #endif /* SQLITE_WIN32_MALLOC */
48493
 
48494 /*
48495 ** This function outputs the specified (ANSI) string to the Win32 debugger
48496 ** (if available).
48497 */
48498
@@ -48531,10 +48591,11 @@
48531 }else{
48532 fprintf(stderr, "%s", zBuf);
48533 }
48534 #endif
48535 }
 
48536
48537 /*
48538 ** The following routine suspends the current thread for at least ms
48539 ** milliseconds. This is equivalent to the Win32 Sleep() interface.
48540 */
@@ -48831,10 +48892,11 @@
48831 SQLITE_PRIVATE void sqlite3MemSetDefault(void){
48832 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
48833 }
48834 #endif /* SQLITE_WIN32_MALLOC */
48835
 
48836 /*
48837 ** Convert a UTF-8 string to Microsoft Unicode.
48838 **
48839 ** Space to hold the returned string is obtained from sqlite3_malloc().
48840 */
@@ -48856,10 +48918,11 @@
48856 sqlite3_free(zWideText);
48857 zWideText = 0;
48858 }
48859 return zWideText;
48860 }
 
48861
48862 /*
48863 ** Convert a Microsoft Unicode string to UTF-8.
48864 **
48865 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48890,32 +48953,33 @@
48890 ** code page.
48891 **
48892 ** Space to hold the returned string is obtained from sqlite3_malloc().
48893 */
48894 static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){
48895 int nByte;
48896 LPWSTR zMbcsText;
48897 int codepage = useAnsi ? CP_ACP : CP_OEMCP;
48898
48899 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
48900 0)*sizeof(WCHAR);
48901 if( nByte==0 ){
48902 return 0;
48903 }
48904 zMbcsText = sqlite3MallocZero( nByte*sizeof(WCHAR) );
48905 if( zMbcsText==0 ){
48906 return 0;
48907 }
48908 nByte = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
48909 nByte);
48910 if( nByte==0 ){
48911 sqlite3_free(zMbcsText);
48912 zMbcsText = 0;
48913 }
48914 return zMbcsText;
48915 }
48916
 
48917 /*
48918 ** Convert a Microsoft Unicode string to a multi-byte character string,
48919 ** using the ANSI or OEM code page.
48920 **
48921 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48939,10 +49003,11 @@
48939 sqlite3_free(zText);
48940 zText = 0;
48941 }
48942 return zText;
48943 }
 
48944
48945 /*
48946 ** Convert a multi-byte character string to UTF-8.
48947 **
48948 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48958,10 +49023,11 @@
48958 zTextUtf8 = winUnicodeToUtf8(zTmpWide);
48959 sqlite3_free(zTmpWide);
48960 return zTextUtf8;
48961 }
48962
 
48963 /*
48964 ** Convert a UTF-8 string to a multi-byte character string.
48965 **
48966 ** Space to hold the returned string is obtained from sqlite3_malloc().
48967 */
@@ -49007,10 +49073,11 @@
49007 #ifndef SQLITE_OMIT_AUTOINIT
49008 if( sqlite3_initialize() ) return 0;
49009 #endif
49010 return winUnicodeToUtf8(zWideText);
49011 }
 
49012
49013 /*
49014 ** This is a public wrapper for the winMbcsToUtf8() function.
49015 */
49016 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -49024,10 +49091,11 @@
49024 if( sqlite3_initialize() ) return 0;
49025 #endif
49026 return winMbcsToUtf8(zText, osAreFileApisANSI());
49027 }
49028
 
49029 /*
49030 ** This is a public wrapper for the winMbcsToUtf8() function.
49031 */
49032 SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
49033 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -49148,10 +49216,11 @@
49148 unsigned long type, /* Identifier for directory being set or reset */
49149 void *zValue /* New value for directory being set or reset */
49150 ){
49151 return sqlite3_win32_set_directory16(type, zValue);
49152 }
 
49153
49154 /*
49155 ** The return value of winGetLastErrorMsg
49156 ** is zero if the error message fits in the buffer, or non-zero
49157 ** otherwise (if the message was truncated).
@@ -49696,13 +49765,15 @@
49696 OVERLAPPED ovlp;
49697 memset(&ovlp, 0, sizeof(OVERLAPPED));
49698 ovlp.Offset = offsetLow;
49699 ovlp.OffsetHigh = offsetHigh;
49700 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
 
49701 }else{
49702 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49703 numBytesHigh);
 
49704 }
49705 #endif
49706 }
49707
49708 /*
@@ -49806,13 +49877,15 @@
49806 OVERLAPPED ovlp;
49807 memset(&ovlp, 0, sizeof(OVERLAPPED));
49808 ovlp.Offset = offsetLow;
49809 ovlp.OffsetHigh = offsetHigh;
49810 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
 
49811 }else{
49812 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49813 numBytesHigh);
 
49814 }
49815 #endif
49816 }
49817
49818 /*
@@ -51222,18 +51295,95 @@
51222
51223 /*
51224 ** Convert a UTF-8 filename into whatever form the underlying
51225 ** operating system wants filenames in. Space to hold the result
51226 ** is obtained from malloc and must be freed by the calling
51227 ** function.
 
 
 
 
 
 
 
 
 
 
 
 
 
51228 */
51229 static void *winConvertFromUtf8Filename(const char *zFilename){
51230 void *zConverted = 0;
51231 if( osIsNT() ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51232 zConverted = winUtf8ToUnicode(zFilename);
 
51233 }
51234 #ifdef SQLITE_WIN32_HAS_ANSI
51235 else{
51236 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51237 }
51238 #endif
51239 /* caller will handle out of memory */
@@ -52058,11 +52208,11 @@
52058 **
52059 ** This division contains the implementation of methods on the
52060 ** sqlite3_vfs object.
52061 */
52062
52063 #if defined(__CYGWIN__)
52064 /*
52065 ** Convert a filename from whatever the underlying operating system
52066 ** supports for filenames into UTF-8. Space to hold the result is
52067 ** obtained from malloc and must be freed by the calling function.
52068 */
@@ -52091,11 +52241,18 @@
52091 int nLen = sqlite3Strlen30(zBuf);
52092 if( nLen>0 ){
52093 if( winIsDirSep(zBuf[nLen-1]) ){
52094 return 1;
52095 }else if( nLen+1<nBuf ){
52096 zBuf[nLen] = winGetDirSep();
 
 
 
 
 
 
 
52097 zBuf[nLen+1] = '\0';
52098 return 1;
52099 }
52100 }
52101 }
@@ -52118,11 +52275,11 @@
52118 /*
52119 ** Create a temporary file name and store the resulting pointer into pzBuf.
52120 ** The pointer returned in pzBuf must be freed via sqlite3_free().
52121 */
52122 static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
52123 static char zChars[] =
52124 "abcdefghijklmnopqrstuvwxyz"
52125 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
52126 "0123456789";
52127 size_t i, j;
52128 DWORD pid;
@@ -52169,11 +52326,11 @@
52169 }
52170 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
52171 }
52172
52173 #if defined(__CYGWIN__)
52174 else{
52175 static const char *azDirs[] = {
52176 0, /* getenv("SQLITE_TMPDIR") */
52177 0, /* getenv("TMPDIR") */
52178 0, /* getenv("TMP") */
52179 0, /* getenv("TEMP") */
@@ -52185,24 +52342,24 @@
52185 0 /* List terminator */
52186 };
52187 unsigned int i;
52188 const char *zDir = 0;
52189
52190 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
52191 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
52192 if( !azDirs[2] ) azDirs[2] = getenv("TMP");
52193 if( !azDirs[3] ) azDirs[3] = getenv("TEMP");
52194 if( !azDirs[4] ) azDirs[4] = getenv("USERPROFILE");
52195 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
52196 void *zConverted;
52197 if( zDir==0 ) continue;
52198 /* If the path starts with a drive letter followed by the colon
52199 ** character, assume it is already a native Win32 path; otherwise,
52200 ** it must be converted to a native Win32 path via the Cygwin API
52201 ** prior to using it.
52202 */
52203 if( winIsDriveLetterAndColon(zDir) ){
52204 zConverted = winConvertFromUtf8Filename(zDir);
52205 if( !zConverted ){
52206 sqlite3_free(zBuf);
52207 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52208 return SQLITE_IOERR_NOMEM_BKPT;
@@ -52211,19 +52368,20 @@
52211 sqlite3_snprintf(nMax, zBuf, "%s", zDir);
52212 sqlite3_free(zConverted);
52213 break;
52214 }
52215 sqlite3_free(zConverted);
 
52216 }else{
52217 zConverted = sqlite3MallocZero( nMax+1 );
52218 if( !zConverted ){
52219 sqlite3_free(zBuf);
52220 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52221 return SQLITE_IOERR_NOMEM_BKPT;
52222 }
52223 if( cygwin_conv_path(
52224 osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
52225 zConverted, nMax+1)<0 ){
52226 sqlite3_free(zConverted);
52227 sqlite3_free(zBuf);
52228 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
52229 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
@@ -52245,14 +52403,17 @@
52245 sqlite3_free(zUtf8);
52246 sqlite3_free(zConverted);
52247 break;
52248 }
52249 sqlite3_free(zConverted);
 
52250 }
52251 }
52252 }
52253 #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
 
 
52254 else if( osIsNT() ){
52255 char *zMulti;
52256 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
52257 if( !zWidePath ){
52258 sqlite3_free(zBuf);
@@ -52372,11 +52533,11 @@
52372 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
52373 if( !rc ){
52374 return 0; /* Invalid name? */
52375 }
52376 attr = sAttrData.dwFileAttributes;
52377 #if SQLITE_OS_WINCE==0
52378 }else{
52379 attr = osGetFileAttributesA((char*)zConverted);
52380 #endif
52381 }
52382 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
@@ -52388,10 +52549,16 @@
52388 const char *zFilename, /* Name of file to check */
52389 int flags, /* Type of test to make on this file */
52390 int *pResOut /* OUT: Result */
52391 );
52392
 
 
 
 
 
 
52393 /*
52394 ** Open a file.
52395 */
52396 static int winOpen(
52397 sqlite3_vfs *pVfs, /* Used to get maximum path length and AppData */
@@ -52412,10 +52579,11 @@
52412 winVfsAppData *pAppData;
52413 winFile *pFile = (winFile*)id;
52414 void *zConverted; /* Filename in OS encoding */
52415 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
52416 int cnt = 0;
 
52417
52418 /* If argument zPath is a NULL pointer, this function is required to open
52419 ** a temporary file. Use this buffer to store the file name in.
52420 */
52421 char *zTmpname = 0; /* For temporary filename, if necessary. */
@@ -52576,13 +52744,13 @@
52576 dwShareMode,
52577 dwCreationDisposition,
52578 &extendedParameters);
52579 if( h!=INVALID_HANDLE_VALUE ) break;
52580 if( isReadWrite ){
52581 int rc2, isRO = 0;
52582 sqlite3BeginBenignMalloc();
52583 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52584 sqlite3EndBenignMalloc();
52585 if( rc2==SQLITE_OK && isRO ) break;
52586 }
52587 }while( winRetryIoerr(&cnt, &lastErrno) );
52588 #else
@@ -52593,13 +52761,13 @@
52593 dwCreationDisposition,
52594 dwFlagsAndAttributes,
52595 NULL);
52596 if( h!=INVALID_HANDLE_VALUE ) break;
52597 if( isReadWrite ){
52598 int rc2, isRO = 0;
52599 sqlite3BeginBenignMalloc();
52600 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52601 sqlite3EndBenignMalloc();
52602 if( rc2==SQLITE_OK && isRO ) break;
52603 }
52604 }while( winRetryIoerr(&cnt, &lastErrno) );
52605 #endif
@@ -52613,13 +52781,13 @@
52613 dwCreationDisposition,
52614 dwFlagsAndAttributes,
52615 NULL);
52616 if( h!=INVALID_HANDLE_VALUE ) break;
52617 if( isReadWrite ){
52618 int rc2, isRO = 0;
52619 sqlite3BeginBenignMalloc();
52620 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ, &isRO);
52621 sqlite3EndBenignMalloc();
52622 if( rc2==SQLITE_OK && isRO ) break;
52623 }
52624 }while( winRetryIoerr(&cnt, &lastErrno) );
52625 }
@@ -52630,11 +52798,11 @@
52630 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
52631
52632 if( h==INVALID_HANDLE_VALUE ){
52633 sqlite3_free(zConverted);
52634 sqlite3_free(zTmpname);
52635 if( isReadWrite && !isExclusive ){
52636 return winOpen(pVfs, zName, id,
52637 ((flags|SQLITE_OPEN_READONLY) &
52638 ~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)),
52639 pOutFlags);
52640 }else{
@@ -52832,11 +53000,17 @@
52832 ){
52833 DWORD attr;
52834 int rc = 0;
52835 DWORD lastErrno = 0;
52836 void *zConverted;
 
52837 UNUSED_PARAMETER(pVfs);
 
 
 
 
 
52838
52839 SimulateIOError( return SQLITE_IOERR_ACCESS; );
52840 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
52841 zFilename, flags, pResOut));
52842
@@ -52856,11 +53030,14 @@
52856 int cnt = 0;
52857 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
52858 memset(&sAttrData, 0, sizeof(sAttrData));
52859 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
52860 GetFileExInfoStandard,
52861 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
 
 
 
52862 if( rc ){
52863 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
52864 ** as if it does not exist.
52865 */
52866 if( flags==SQLITE_ACCESS_EXISTS
@@ -52924,10 +53101,11 @@
52924 const char *zPathname
52925 ){
52926 return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
52927 }
52928
 
52929 /*
52930 ** Returns non-zero if the specified path name should be used verbatim. If
52931 ** non-zero is returned from this function, the calling function must simply
52932 ** use the provided path name verbatim -OR- resolve it into a full path name
52933 ** using the GetFullPathName Win32 API function (if available).
@@ -52960,10 +53138,74 @@
52960 ** If we get to this point, the path name should almost certainly be a purely
52961 ** relative one (i.e. not a UNC name, not absolute, and not volume relative).
52962 */
52963 return FALSE;
52964 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52965
52966 /*
52967 ** Turn a relative pathname into a full pathname. Write the full
52968 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
52969 ** bytes in size.
@@ -52972,12 +53214,12 @@
52972 sqlite3_vfs *pVfs, /* Pointer to vfs object */
52973 const char *zRelative, /* Possibly relative input path */
52974 int nFull, /* Size of output buffer in bytes */
52975 char *zFull /* Output buffer */
52976 ){
52977 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
52978 DWORD nByte;
52979 void *zConverted;
52980 char *zOut;
52981 #endif
52982
52983 /* If this path name begins with "/X:" or "\\?\", where "X" is any
@@ -52986,68 +53228,114 @@
52986 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
52987 || winIsLongPathPrefix(zRelative+1)) ){
52988 zRelative++;
52989 }
52990
52991 #if defined(__CYGWIN__)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52992 SimulateIOError( return SQLITE_ERROR );
52993 UNUSED_PARAMETER(nFull);
52994 assert( nFull>=pVfs->mxPathname );
52995 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
52996 /*
52997 ** NOTE: We are dealing with a relative path name and the data
52998 ** directory has been set. Therefore, use it as the basis
52999 ** for converting the relative path name to an absolute
53000 ** one by prepending the data directory and a slash.
53001 */
53002 char *zOut = sqlite3MallocZero( 1+(u64)pVfs->mxPathname );
53003 if( !zOut ){
53004 return SQLITE_IOERR_NOMEM_BKPT;
53005 }
53006 if( cygwin_conv_path(
53007 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A) |
53008 CCP_RELATIVE, zRelative, zOut, pVfs->mxPathname+1)<0 ){
53009 sqlite3_free(zOut);
53010 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53011 "winFullPathname1", zRelative);
53012 }else{
53013 char *zUtf8 = winConvertToUtf8Filename(zOut);
53014 if( !zUtf8 ){
53015 sqlite3_free(zOut);
53016 return SQLITE_IOERR_NOMEM_BKPT;
53017 }
53018 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
53019 sqlite3_data_directory, winGetDirSep(), zUtf8);
53020 sqlite3_free(zUtf8);
53021 sqlite3_free(zOut);
53022 }
53023 }else{
53024 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
53025 if( !zOut ){
53026 return SQLITE_IOERR_NOMEM_BKPT;
53027 }
53028 if( cygwin_conv_path(
53029 (osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A),
53030 zRelative, zOut, pVfs->mxPathname+1)<0 ){
53031 sqlite3_free(zOut);
53032 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53033 "winFullPathname2", zRelative);
53034 }else{
53035 char *zUtf8 = winConvertToUtf8Filename(zOut);
53036 if( !zUtf8 ){
53037 sqlite3_free(zOut);
53038 return SQLITE_IOERR_NOMEM_BKPT;
53039 }
53040 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
53041 sqlite3_free(zUtf8);
53042 sqlite3_free(zOut);
53043 }
53044 }
53045 return SQLITE_OK;
53046 #endif
53047
53048 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && !defined(__CYGWIN__)
53049 SimulateIOError( return SQLITE_ERROR );
53050 /* WinCE has no concept of a relative pathname, or so I am told. */
53051 /* WinRT has no way to convert a relative path to an absolute one. */
53052 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
53053 /*
@@ -53062,11 +53350,12 @@
53062 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
53063 }
53064 return SQLITE_OK;
53065 #endif
53066
53067 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && !defined(__CYGWIN__)
 
53068 /* It's odd to simulate an io-error here, but really this is just
53069 ** using the io-error infrastructure to test that SQLite handles this
53070 ** function failing. This function could fail if, for example, the
53071 ** current working directory has been unlinked.
53072 */
@@ -53080,10 +53369,11 @@
53080 */
53081 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
53082 sqlite3_data_directory, winGetDirSep(), zRelative);
53083 return SQLITE_OK;
53084 }
 
53085 zConverted = winConvertFromUtf8Filename(zRelative);
53086 if( zConverted==0 ){
53087 return SQLITE_IOERR_NOMEM_BKPT;
53088 }
53089 if( osIsNT() ){
@@ -53092,16 +53382,17 @@
53092 if( nByte==0 ){
53093 sqlite3_free(zConverted);
53094 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
53095 "winFullPathname1", zRelative);
53096 }
53097 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) + 3*sizeof(zTemp[0]) );
 
53098 if( zTemp==0 ){
53099 sqlite3_free(zConverted);
53100 return SQLITE_IOERR_NOMEM_BKPT;
53101 }
53102 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte+3, zTemp, 0);
53103 if( nByte==0 ){
53104 sqlite3_free(zConverted);
53105 sqlite3_free(zTemp);
53106 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
53107 "winFullPathname2", zRelative);
@@ -53135,11 +53426,30 @@
53135 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
53136 sqlite3_free(zTemp);
53137 }
53138 #endif
53139 if( zOut ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53140 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
 
53141 sqlite3_free(zOut);
53142 return SQLITE_OK;
53143 }else{
53144 return SQLITE_IOERR_NOMEM_BKPT;
53145 }
@@ -53165,11 +53475,13 @@
53165 ** Interfaces for opening a shared library, finding entry points
53166 ** within the shared library, and closing the shared library.
53167 */
53168 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53169 HANDLE h;
53170 #if defined(__CYGWIN__)
 
 
53171 int nFull = pVfs->mxPathname+1;
53172 char *zFull = sqlite3MallocZero( nFull );
53173 void *zConverted = 0;
53174 if( zFull==0 ){
53175 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
@@ -53532,11 +53844,11 @@
53532 };
53533 #endif
53534
53535 /* Double-check that the aSyscall[] array has been constructed
53536 ** correctly. See ticket [bb3a86e890c8e96ab] */
53537 assert( ArraySize(aSyscall)==82 );
53538
53539 /* get memory map allocation granularity */
53540 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53541 #if SQLITE_OS_WINRT
53542 osGetNativeSystemInfo(&winSysInfo);
@@ -66508,14 +66820,12 @@
66508 s2 = aIn[1];
66509 }else{
66510 s1 = s2 = 0;
66511 }
66512
66513 assert( nByte>=8 );
66514 assert( (nByte&0x00000007)==0 );
66515 assert( nByte<=65536 );
66516 assert( nByte%4==0 );
66517
66518 if( !nativeCksum ){
66519 do {
66520 s1 += BYTESWAP32(aData[0]) + s2;
66521 s2 += BYTESWAP32(aData[1]) + s1;
@@ -147785,10 +148095,11 @@
147785 }
147786
147787 multi_select_end:
147788 pDest->iSdst = dest.iSdst;
147789 pDest->nSdst = dest.nSdst;
 
147790 if( pDelete ){
147791 sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pDelete);
147792 }
147793 return rc;
147794 }
@@ -188065,10 +188376,17 @@
188065 ******************************************************************************
188066 **
188067 */
188068 #ifndef _FTSINT_H
188069 #define _FTSINT_H
 
 
 
 
 
 
 
188070
188071 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
188072 # define NDEBUG 1
188073 #endif
188074
@@ -189017,16 +189335,10 @@
189017
189018 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
189019 # define SQLITE_CORE 1
189020 #endif
189021
189022 /* #include <assert.h> */
189023 /* #include <stdlib.h> */
189024 /* #include <stddef.h> */
189025 /* #include <stdio.h> */
189026 /* #include <string.h> */
189027 /* #include <stdarg.h> */
189028
189029 /* #include "fts3.h" */
189030 #ifndef SQLITE_CORE
189031 /* # include "sqlite3ext.h" */
189032 SQLITE_EXTENSION_INIT1
@@ -227533,12 +227845,12 @@
227533 ){
227534 if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
227535 /* "INSERT INTO dbpage($PGNO,NULL)" causes page number $PGNO and
227536 ** all subsequent pages to be deleted. */
227537 pTab->iDbTrunc = iDb;
227538 pgno--;
227539 pTab->pgnoTrunc = pgno;
227540 }else{
227541 zErr = "bad page value";
227542 goto update_fail;
227543 }
227544 }
@@ -241869,11 +242181,12 @@
241869 sqlite3Fts5ParseError(
241870 pParse, "expected integer, got \"%.*s\"", p->n, p->p
241871 );
241872 return;
241873 }
241874 nNear = nNear * 10 + (p->p[i] - '0');
 
241875 }
241876 }else{
241877 nNear = FTS5_DEFAULT_NEARDIST;
241878 }
241879 pNear->nNear = nNear;
@@ -256775,11 +257088,11 @@
256775 int nArg, /* Number of args */
256776 sqlite3_value **apUnused /* Function arguments */
256777 ){
256778 assert( nArg==0 );
256779 UNUSED_PARAM2(nArg, apUnused);
256780 sqlite3_result_text(pCtx, "fts5: 2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185", -1, SQLITE_TRANSIENT);
256781 }
256782
256783 /*
256784 ** Implementation of fts5_locale(LOCALE, TEXT) function.
256785 **
256786
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 121f4d97f9a855131859d342bc2ade5f8c34 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.50.0"
469 #define SQLITE_VERSION_NUMBER 3050000
470 #define SQLITE_SOURCE_ID "2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -30270,10 +30270,12 @@
30270 */
30271 #include "windows.h"
30272
30273 #ifdef __CYGWIN__
30274 # include <sys/cygwin.h>
30275 # include <sys/stat.h> /* amalgamator: dontcache */
30276 # include <unistd.h> /* amalgamator: dontcache */
30277 # include <errno.h> /* amalgamator: dontcache */
30278 #endif
30279
30280 /*
30281 ** Determine if we are dealing with Windows NT.
@@ -47726,20 +47728,20 @@
47728 { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
47729 #else
47730 { "FileTimeToLocalFileTime", (SYSCALL)0, 0 },
47731 #endif
47732
47733 #define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(const FILETIME*, \
47734 LPFILETIME))aSyscall[11].pCurrent)
47735
47736 #if SQLITE_OS_WINCE
47737 { "FileTimeToSystemTime", (SYSCALL)FileTimeToSystemTime, 0 },
47738 #else
47739 { "FileTimeToSystemTime", (SYSCALL)0, 0 },
47740 #endif
47741
47742 #define osFileTimeToSystemTime ((BOOL(WINAPI*)(const FILETIME*, \
47743 LPSYSTEMTIME))aSyscall[12].pCurrent)
47744
47745 { "FlushFileBuffers", (SYSCALL)FlushFileBuffers, 0 },
47746
47747 #define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
@@ -48015,11 +48017,11 @@
48017 { "LockFile", (SYSCALL)LockFile, 0 },
48018 #else
48019 { "LockFile", (SYSCALL)0, 0 },
48020 #endif
48021
48022 #if !defined(osLockFile) && defined(SQLITE_WIN32_HAS_ANSI)
48023 #define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
48024 DWORD))aSyscall[47].pCurrent)
48025 #endif
48026
48027 #if !SQLITE_OS_WINCE
@@ -48079,20 +48081,20 @@
48081
48082 #define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[55].pCurrent)
48083
48084 { "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
48085
48086 #define osSystemTimeToFileTime ((BOOL(WINAPI*)(const SYSTEMTIME*, \
48087 LPFILETIME))aSyscall[56].pCurrent)
48088
48089 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
48090 { "UnlockFile", (SYSCALL)UnlockFile, 0 },
48091 #else
48092 { "UnlockFile", (SYSCALL)0, 0 },
48093 #endif
48094
48095 #if !defined(osUnlockFile) && defined(SQLITE_WIN32_HAS_ANSI)
48096 #define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
48097 DWORD))aSyscall[57].pCurrent)
48098 #endif
48099
48100 #if !SQLITE_OS_WINCE
@@ -48316,10 +48318,67 @@
48318 { "CancelIo", (SYSCALL)0, 0 },
48319 #endif
48320
48321 #define osCancelIo ((BOOL(WINAPI*)(HANDLE))aSyscall[81].pCurrent)
48322
48323 #if defined(SQLITE_WIN32_HAS_WIDE) && defined(_WIN32)
48324 { "GetModuleHandleW", (SYSCALL)GetModuleHandleW, 0 },
48325 #else
48326 { "GetModuleHandleW", (SYSCALL)0, 0 },
48327 #endif
48328
48329 #define osGetModuleHandleW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[82].pCurrent)
48330
48331 #ifndef _WIN32
48332 { "getenv", (SYSCALL)getenv, 0 },
48333 #else
48334 { "getenv", (SYSCALL)0, 0 },
48335 #endif
48336
48337 #define osGetenv ((const char *(*)(const char *))aSyscall[83].pCurrent)
48338
48339 #ifndef _WIN32
48340 { "getcwd", (SYSCALL)getcwd, 0 },
48341 #else
48342 { "getcwd", (SYSCALL)0, 0 },
48343 #endif
48344
48345 #define osGetcwd ((char*(*)(char*,size_t))aSyscall[84].pCurrent)
48346
48347 #ifndef _WIN32
48348 { "readlink", (SYSCALL)readlink, 0 },
48349 #else
48350 { "readlink", (SYSCALL)0, 0 },
48351 #endif
48352
48353 #define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[85].pCurrent)
48354
48355 #ifndef _WIN32
48356 { "lstat", (SYSCALL)lstat, 0 },
48357 #else
48358 { "lstat", (SYSCALL)0, 0 },
48359 #endif
48360
48361 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[86].pCurrent)
48362
48363 #ifndef _WIN32
48364 { "__errno", (SYSCALL)__errno, 0 },
48365 #else
48366 { "__errno", (SYSCALL)0, 0 },
48367 #endif
48368
48369 #define osErrno (*((int*(*)(void))aSyscall[87].pCurrent)())
48370
48371 #ifndef _WIN32
48372 { "cygwin_conv_path", (SYSCALL)cygwin_conv_path, 0 },
48373 #else
48374 { "cygwin_conv_path", (SYSCALL)0, 0 },
48375 #endif
48376
48377 #define osCygwin_conv_path ((size_t(*)(unsigned int, \
48378 const void *, void *, size_t))aSyscall[88].pCurrent)
48379
48380 }; /* End of the overrideable system calls */
48381
48382 /*
48383 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
48384 ** "win32" VFSes. Return SQLITE_OK upon successfully updating the
@@ -48489,10 +48548,11 @@
48548 sqlite3_mutex_leave(pMainMtx);
48549 return rc;
48550 }
48551 #endif /* SQLITE_WIN32_MALLOC */
48552
48553 #ifdef _WIN32
48554 /*
48555 ** This function outputs the specified (ANSI) string to the Win32 debugger
48556 ** (if available).
48557 */
48558
@@ -48531,10 +48591,11 @@
48591 }else{
48592 fprintf(stderr, "%s", zBuf);
48593 }
48594 #endif
48595 }
48596 #endif /* _WIN32 */
48597
48598 /*
48599 ** The following routine suspends the current thread for at least ms
48600 ** milliseconds. This is equivalent to the Win32 Sleep() interface.
48601 */
@@ -48831,10 +48892,11 @@
48892 SQLITE_PRIVATE void sqlite3MemSetDefault(void){
48893 sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
48894 }
48895 #endif /* SQLITE_WIN32_MALLOC */
48896
48897 #ifdef _WIN32
48898 /*
48899 ** Convert a UTF-8 string to Microsoft Unicode.
48900 **
48901 ** Space to hold the returned string is obtained from sqlite3_malloc().
48902 */
@@ -48856,10 +48918,11 @@
48918 sqlite3_free(zWideText);
48919 zWideText = 0;
48920 }
48921 return zWideText;
48922 }
48923 #endif /* _WIN32 */
48924
48925 /*
48926 ** Convert a Microsoft Unicode string to UTF-8.
48927 **
48928 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48890,32 +48953,33 @@
48953 ** code page.
48954 **
48955 ** Space to hold the returned string is obtained from sqlite3_malloc().
48956 */
48957 static LPWSTR winMbcsToUnicode(const char *zText, int useAnsi){
48958 int nWideChar;
48959 LPWSTR zMbcsText;
48960 int codepage = useAnsi ? CP_ACP : CP_OEMCP;
48961
48962 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, NULL,
48963 0);
48964 if( nWideChar==0 ){
48965 return 0;
48966 }
48967 zMbcsText = sqlite3MallocZero( nWideChar*sizeof(WCHAR) );
48968 if( zMbcsText==0 ){
48969 return 0;
48970 }
48971 nWideChar = osMultiByteToWideChar(codepage, 0, zText, -1, zMbcsText,
48972 nWideChar);
48973 if( nWideChar==0 ){
48974 sqlite3_free(zMbcsText);
48975 zMbcsText = 0;
48976 }
48977 return zMbcsText;
48978 }
48979
48980 #ifdef _WIN32
48981 /*
48982 ** Convert a Microsoft Unicode string to a multi-byte character string,
48983 ** using the ANSI or OEM code page.
48984 **
48985 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48939,10 +49003,11 @@
49003 sqlite3_free(zText);
49004 zText = 0;
49005 }
49006 return zText;
49007 }
49008 #endif /* _WIN32 */
49009
49010 /*
49011 ** Convert a multi-byte character string to UTF-8.
49012 **
49013 ** Space to hold the returned string is obtained from sqlite3_malloc().
@@ -48958,10 +49023,11 @@
49023 zTextUtf8 = winUnicodeToUtf8(zTmpWide);
49024 sqlite3_free(zTmpWide);
49025 return zTextUtf8;
49026 }
49027
49028 #ifdef _WIN32
49029 /*
49030 ** Convert a UTF-8 string to a multi-byte character string.
49031 **
49032 ** Space to hold the returned string is obtained from sqlite3_malloc().
49033 */
@@ -49007,10 +49073,11 @@
49073 #ifndef SQLITE_OMIT_AUTOINIT
49074 if( sqlite3_initialize() ) return 0;
49075 #endif
49076 return winUnicodeToUtf8(zWideText);
49077 }
49078 #endif /* _WIN32 */
49079
49080 /*
49081 ** This is a public wrapper for the winMbcsToUtf8() function.
49082 */
49083 SQLITE_API char *sqlite3_win32_mbcs_to_utf8(const char *zText){
@@ -49024,10 +49091,11 @@
49091 if( sqlite3_initialize() ) return 0;
49092 #endif
49093 return winMbcsToUtf8(zText, osAreFileApisANSI());
49094 }
49095
49096 #ifdef _WIN32
49097 /*
49098 ** This is a public wrapper for the winMbcsToUtf8() function.
49099 */
49100 SQLITE_API char *sqlite3_win32_mbcs_to_utf8_v2(const char *zText, int useAnsi){
49101 #ifdef SQLITE_ENABLE_API_ARMOR
@@ -49148,10 +49216,11 @@
49216 unsigned long type, /* Identifier for directory being set or reset */
49217 void *zValue /* New value for directory being set or reset */
49218 ){
49219 return sqlite3_win32_set_directory16(type, zValue);
49220 }
49221 #endif /* _WIN32 */
49222
49223 /*
49224 ** The return value of winGetLastErrorMsg
49225 ** is zero if the error message fits in the buffer, or non-zero
49226 ** otherwise (if the message was truncated).
@@ -49696,13 +49765,15 @@
49765 OVERLAPPED ovlp;
49766 memset(&ovlp, 0, sizeof(OVERLAPPED));
49767 ovlp.Offset = offsetLow;
49768 ovlp.OffsetHigh = offsetHigh;
49769 return osLockFileEx(*phFile, flags, 0, numBytesLow, numBytesHigh, &ovlp);
49770 #ifdef SQLITE_WIN32_HAS_ANSI
49771 }else{
49772 return osLockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49773 numBytesHigh);
49774 #endif
49775 }
49776 #endif
49777 }
49778
49779 /*
@@ -49806,13 +49877,15 @@
49877 OVERLAPPED ovlp;
49878 memset(&ovlp, 0, sizeof(OVERLAPPED));
49879 ovlp.Offset = offsetLow;
49880 ovlp.OffsetHigh = offsetHigh;
49881 return osUnlockFileEx(*phFile, 0, numBytesLow, numBytesHigh, &ovlp);
49882 #ifdef SQLITE_WIN32_HAS_ANSI
49883 }else{
49884 return osUnlockFile(*phFile, offsetLow, offsetHigh, numBytesLow,
49885 numBytesHigh);
49886 #endif
49887 }
49888 #endif
49889 }
49890
49891 /*
@@ -51222,18 +51295,95 @@
51295
51296 /*
51297 ** Convert a UTF-8 filename into whatever form the underlying
51298 ** operating system wants filenames in. Space to hold the result
51299 ** is obtained from malloc and must be freed by the calling
51300 ** function
51301 **
51302 ** On Cygwin, 3 possible input forms are accepted:
51303 ** - If the filename starts with "<drive>:/" or "<drive>:\",
51304 ** it is converted to UTF-16 as-is.
51305 ** - If the filename contains '/', it is assumed to be a
51306 ** Cygwin absolute path, it is converted to a win32
51307 ** absolute path in UTF-16.
51308 ** - Otherwise it must be a filename only, the win32 filename
51309 ** is returned in UTF-16.
51310 ** Note: If the function cygwin_conv_path() fails, only
51311 ** UTF-8 -> UTF-16 conversion will be done. This can only
51312 ** happen when the file path >32k, in which case winUtf8ToUnicode()
51313 ** will fail too.
51314 */
51315 static void *winConvertFromUtf8Filename(const char *zFilename){
51316 void *zConverted = 0;
51317 if( osIsNT() ){
51318 #ifdef __CYGWIN__
51319 int nChar;
51320 LPWSTR zWideFilename;
51321
51322 if( osCygwin_conv_path && !(winIsDriveLetterAndColon(zFilename)
51323 && winIsDirSep(zFilename[2])) ){
51324 int nByte;
51325 int convertflag = CCP_POSIX_TO_WIN_W;
51326 if( !strchr(zFilename, '/') ) convertflag |= CCP_RELATIVE;
51327 nByte = (int)osCygwin_conv_path(convertflag,
51328 zFilename, 0, 0);
51329 if( nByte>0 ){
51330 zConverted = sqlite3MallocZero(nByte+12);
51331 if ( zConverted==0 ){
51332 return zConverted;
51333 }
51334 zWideFilename = zConverted;
51335 /* Filenames should be prefixed, except when converted
51336 * full path already starts with "\\?\". */
51337 if( osCygwin_conv_path(convertflag, zFilename,
51338 zWideFilename+4, nByte)==0 ){
51339 if( (convertflag&CCP_RELATIVE) ){
51340 memmove(zWideFilename, zWideFilename+4, nByte);
51341 }else if( memcmp(zWideFilename+4, L"\\\\", 4) ){
51342 memcpy(zWideFilename, L"\\\\?\\", 8);
51343 }else if( zWideFilename[6]!='?' ){
51344 memmove(zWideFilename+6, zWideFilename+4, nByte);
51345 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51346 }else{
51347 memmove(zWideFilename, zWideFilename+4, nByte);
51348 }
51349 return zConverted;
51350 }
51351 sqlite3_free(zConverted);
51352 }
51353 }
51354 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
51355 if( nChar==0 ){
51356 return 0;
51357 }
51358 zWideFilename = sqlite3MallocZero( nChar*sizeof(WCHAR)+12 );
51359 if( zWideFilename==0 ){
51360 return 0;
51361 }
51362 nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1,
51363 zWideFilename, nChar);
51364 if( nChar==0 ){
51365 sqlite3_free(zWideFilename);
51366 zWideFilename = 0;
51367 }else if( nChar>MAX_PATH
51368 && winIsDriveLetterAndColon(zFilename)
51369 && winIsDirSep(zFilename[2]) ){
51370 memmove(zWideFilename+4, zWideFilename, nChar*sizeof(WCHAR));
51371 zWideFilename[2] = '\\';
51372 memcpy(zWideFilename, L"\\\\?\\", 8);
51373 }else if( nChar>MAX_PATH
51374 && winIsDirSep(zFilename[0]) && winIsDirSep(zFilename[1])
51375 && zFilename[2] != '?' ){
51376 memmove(zWideFilename+6, zWideFilename, nChar*sizeof(WCHAR));
51377 memcpy(zWideFilename, L"\\\\?\\UNC", 14);
51378 }
51379 zConverted = zWideFilename;
51380 #else
51381 zConverted = winUtf8ToUnicode(zFilename);
51382 #endif /* __CYGWIN__ */
51383 }
51384 #if defined(SQLITE_WIN32_HAS_ANSI) && defined(_WIN32)
51385 else{
51386 zConverted = winUtf8ToMbcs(zFilename, osAreFileApisANSI());
51387 }
51388 #endif
51389 /* caller will handle out of memory */
@@ -52058,11 +52208,11 @@
52208 **
52209 ** This division contains the implementation of methods on the
52210 ** sqlite3_vfs object.
52211 */
52212
52213 #if 0 /* No longer necessary */
52214 /*
52215 ** Convert a filename from whatever the underlying operating system
52216 ** supports for filenames into UTF-8. Space to hold the result is
52217 ** obtained from malloc and must be freed by the calling function.
52218 */
@@ -52091,11 +52241,18 @@
52241 int nLen = sqlite3Strlen30(zBuf);
52242 if( nLen>0 ){
52243 if( winIsDirSep(zBuf[nLen-1]) ){
52244 return 1;
52245 }else if( nLen+1<nBuf ){
52246 if( !osGetenv ){
52247 zBuf[nLen] = winGetDirSep();
52248 }else if( winIsDriveLetterAndColon(zBuf) && winIsDirSep(zBuf[2]) ){
52249 zBuf[nLen] = '\\';
52250 zBuf[2]='\\';
52251 }else{
52252 zBuf[nLen] = '/';
52253 }
52254 zBuf[nLen+1] = '\0';
52255 return 1;
52256 }
52257 }
52258 }
@@ -52118,11 +52275,11 @@
52275 /*
52276 ** Create a temporary file name and store the resulting pointer into pzBuf.
52277 ** The pointer returned in pzBuf must be freed via sqlite3_free().
52278 */
52279 static int winGetTempname(sqlite3_vfs *pVfs, char **pzBuf){
52280 static const char zChars[] =
52281 "abcdefghijklmnopqrstuvwxyz"
52282 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
52283 "0123456789";
52284 size_t i, j;
52285 DWORD pid;
@@ -52169,11 +52326,11 @@
52326 }
52327 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR));
52328 }
52329
52330 #if defined(__CYGWIN__)
52331 else if( osGetenv!=NULL ){
52332 static const char *azDirs[] = {
52333 0, /* getenv("SQLITE_TMPDIR") */
52334 0, /* getenv("TMPDIR") */
52335 0, /* getenv("TMP") */
52336 0, /* getenv("TEMP") */
@@ -52185,24 +52342,24 @@
52342 0 /* List terminator */
52343 };
52344 unsigned int i;
52345 const char *zDir = 0;
52346
52347 if( !azDirs[0] ) azDirs[0] = osGetenv("SQLITE_TMPDIR");
52348 if( !azDirs[1] ) azDirs[1] = osGetenv("TMPDIR");
52349 if( !azDirs[2] ) azDirs[2] = osGetenv("TMP");
52350 if( !azDirs[3] ) azDirs[3] = osGetenv("TEMP");
52351 if( !azDirs[4] ) azDirs[4] = osGetenv("USERPROFILE");
52352 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
52353 void *zConverted;
52354 if( zDir==0 ) continue;
52355 /* If the path starts with a drive letter followed by the colon
52356 ** character, assume it is already a native Win32 path; otherwise,
52357 ** it must be converted to a native Win32 path via the Cygwin API
52358 ** prior to using it.
52359 */
52360 {
52361 zConverted = winConvertFromUtf8Filename(zDir);
52362 if( !zConverted ){
52363 sqlite3_free(zBuf);
52364 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52365 return SQLITE_IOERR_NOMEM_BKPT;
@@ -52211,19 +52368,20 @@
52368 sqlite3_snprintf(nMax, zBuf, "%s", zDir);
52369 sqlite3_free(zConverted);
52370 break;
52371 }
52372 sqlite3_free(zConverted);
52373 #if 0 /* No longer necessary */
52374 }else{
52375 zConverted = sqlite3MallocZero( nMax+1 );
52376 if( !zConverted ){
52377 sqlite3_free(zBuf);
52378 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
52379 return SQLITE_IOERR_NOMEM_BKPT;
52380 }
52381 if( osCygwin_conv_path(
52382 CCP_POSIX_TO_WIN_W, zDir,
52383 zConverted, nMax+1)<0 ){
52384 sqlite3_free(zConverted);
52385 sqlite3_free(zBuf);
52386 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
52387 return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
@@ -52245,14 +52403,17 @@
52403 sqlite3_free(zUtf8);
52404 sqlite3_free(zConverted);
52405 break;
52406 }
52407 sqlite3_free(zConverted);
52408 #endif /* No longer necessary */
52409 }
52410 }
52411 }
52412 #endif
52413
52414 #if !SQLITE_OS_WINRT && defined(_WIN32)
52415 else if( osIsNT() ){
52416 char *zMulti;
52417 LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
52418 if( !zWidePath ){
52419 sqlite3_free(zBuf);
@@ -52372,11 +52533,11 @@
52533 &sAttrData)) && winRetryIoerr(&cnt, &lastErrno) ){}
52534 if( !rc ){
52535 return 0; /* Invalid name? */
52536 }
52537 attr = sAttrData.dwFileAttributes;
52538 #if SQLITE_OS_WINCE==0 && defined(SQLITE_WIN32_HAS_ANSI)
52539 }else{
52540 attr = osGetFileAttributesA((char*)zConverted);
52541 #endif
52542 }
52543 return (attr!=INVALID_FILE_ATTRIBUTES) && (attr&FILE_ATTRIBUTE_DIRECTORY);
@@ -52388,10 +52549,16 @@
52549 const char *zFilename, /* Name of file to check */
52550 int flags, /* Type of test to make on this file */
52551 int *pResOut /* OUT: Result */
52552 );
52553
52554 /*
52555 ** The Windows version of xAccess() accepts an extra bit in the flags
52556 ** parameter that prevents an anti-virus retry loop.
52557 */
52558 #define NORETRY 0x4000
52559
52560 /*
52561 ** Open a file.
52562 */
52563 static int winOpen(
52564 sqlite3_vfs *pVfs, /* Used to get maximum path length and AppData */
@@ -52412,10 +52579,11 @@
52579 winVfsAppData *pAppData;
52580 winFile *pFile = (winFile*)id;
52581 void *zConverted; /* Filename in OS encoding */
52582 const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
52583 int cnt = 0;
52584 int isRO = 0; /* file is known to be accessible readonly */
52585
52586 /* If argument zPath is a NULL pointer, this function is required to open
52587 ** a temporary file. Use this buffer to store the file name in.
52588 */
52589 char *zTmpname = 0; /* For temporary filename, if necessary. */
@@ -52576,13 +52744,13 @@
52744 dwShareMode,
52745 dwCreationDisposition,
52746 &extendedParameters);
52747 if( h!=INVALID_HANDLE_VALUE ) break;
52748 if( isReadWrite ){
52749 int rc2;
52750 sqlite3BeginBenignMalloc();
52751 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
52752 sqlite3EndBenignMalloc();
52753 if( rc2==SQLITE_OK && isRO ) break;
52754 }
52755 }while( winRetryIoerr(&cnt, &lastErrno) );
52756 #else
@@ -52593,13 +52761,13 @@
52761 dwCreationDisposition,
52762 dwFlagsAndAttributes,
52763 NULL);
52764 if( h!=INVALID_HANDLE_VALUE ) break;
52765 if( isReadWrite ){
52766 int rc2;
52767 sqlite3BeginBenignMalloc();
52768 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
52769 sqlite3EndBenignMalloc();
52770 if( rc2==SQLITE_OK && isRO ) break;
52771 }
52772 }while( winRetryIoerr(&cnt, &lastErrno) );
52773 #endif
@@ -52613,13 +52781,13 @@
52781 dwCreationDisposition,
52782 dwFlagsAndAttributes,
52783 NULL);
52784 if( h!=INVALID_HANDLE_VALUE ) break;
52785 if( isReadWrite ){
52786 int rc2;
52787 sqlite3BeginBenignMalloc();
52788 rc2 = winAccess(pVfs, zUtf8Name, SQLITE_ACCESS_READ|NORETRY, &isRO);
52789 sqlite3EndBenignMalloc();
52790 if( rc2==SQLITE_OK && isRO ) break;
52791 }
52792 }while( winRetryIoerr(&cnt, &lastErrno) );
52793 }
@@ -52630,11 +52798,11 @@
52798 dwDesiredAccess, (h==INVALID_HANDLE_VALUE) ? "failed" : "ok"));
52799
52800 if( h==INVALID_HANDLE_VALUE ){
52801 sqlite3_free(zConverted);
52802 sqlite3_free(zTmpname);
52803 if( isReadWrite && isRO && !isExclusive ){
52804 return winOpen(pVfs, zName, id,
52805 ((flags|SQLITE_OPEN_READONLY) &
52806 ~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)),
52807 pOutFlags);
52808 }else{
@@ -52832,11 +53000,17 @@
53000 ){
53001 DWORD attr;
53002 int rc = 0;
53003 DWORD lastErrno = 0;
53004 void *zConverted;
53005 int noRetry = 0; /* Do not use winRetryIoerr() */
53006 UNUSED_PARAMETER(pVfs);
53007
53008 if( (flags & NORETRY)!=0 ){
53009 noRetry = 1;
53010 flags &= ~NORETRY;
53011 }
53012
53013 SimulateIOError( return SQLITE_IOERR_ACCESS; );
53014 OSTRACE(("ACCESS name=%s, flags=%x, pResOut=%p\n",
53015 zFilename, flags, pResOut));
53016
@@ -52856,11 +53030,14 @@
53030 int cnt = 0;
53031 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
53032 memset(&sAttrData, 0, sizeof(sAttrData));
53033 while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
53034 GetFileExInfoStandard,
53035 &sAttrData))
53036 && !noRetry
53037 && winRetryIoerr(&cnt, &lastErrno)
53038 ){ /* Loop until true */}
53039 if( rc ){
53040 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
53041 ** as if it does not exist.
53042 */
53043 if( flags==SQLITE_ACCESS_EXISTS
@@ -52924,10 +53101,11 @@
53101 const char *zPathname
53102 ){
53103 return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
53104 }
53105
53106 #ifdef _WIN32
53107 /*
53108 ** Returns non-zero if the specified path name should be used verbatim. If
53109 ** non-zero is returned from this function, the calling function must simply
53110 ** use the provided path name verbatim -OR- resolve it into a full path name
53111 ** using the GetFullPathName Win32 API function (if available).
@@ -52960,10 +53138,74 @@
53138 ** If we get to this point, the path name should almost certainly be a purely
53139 ** relative one (i.e. not a UNC name, not absolute, and not volume relative).
53140 */
53141 return FALSE;
53142 }
53143 #endif /* _WIN32 */
53144
53145 #ifdef __CYGWIN__
53146 /*
53147 ** Simplify a filename into its canonical form
53148 ** by making the following changes:
53149 **
53150 ** * convert any '/' to '\' (win32) or reverse (Cygwin)
53151 ** * removing any trailing and duplicate / (except for UNC paths)
53152 ** * convert /./ into just /
53153 **
53154 ** Changes are made in-place. Return the new name length.
53155 **
53156 ** The original filename is in z[0..]. If the path is shortened,
53157 ** no-longer used bytes will be written by '\0'.
53158 */
53159 static void winSimplifyName(char *z){
53160 int i, j;
53161 for(i=j=0; z[i]; ++i){
53162 if( winIsDirSep(z[i]) ){
53163 #if !defined(SQLITE_TEST)
53164 /* Some test-cases assume that "./foo" and "foo" are different */
53165 if( z[i+1]=='.' && winIsDirSep(z[i+2]) ){
53166 ++i;
53167 continue;
53168 }
53169 #endif
53170 if( !z[i+1] || (winIsDirSep(z[i+1]) && (i!=0)) ){
53171 continue;
53172 }
53173 z[j++] = osGetenv?'/':'\\';
53174 }else{
53175 z[j++] = z[i];
53176 }
53177 }
53178 while(j<i) z[j++] = '\0';
53179 }
53180
53181 #define SQLITE_MAX_SYMLINKS 100
53182
53183 static int mkFullPathname(
53184 const char *zPath, /* Input path */
53185 char *zOut, /* Output buffer */
53186 int nOut /* Allocated size of buffer zOut */
53187 ){
53188 int nPath = sqlite3Strlen30(zPath);
53189 int iOff = 0;
53190 if( zPath[0]!='/' ){
53191 if( osGetcwd(zOut, nOut-2)==0 ){
53192 return winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "getcwd", zPath);
53193 }
53194 iOff = sqlite3Strlen30(zOut);
53195 zOut[iOff++] = '/';
53196 }
53197 if( (iOff+nPath+1)>nOut ){
53198 /* SQLite assumes that xFullPathname() nul-terminates the output buffer
53199 ** even if it returns an error. */
53200 zOut[iOff] = '\0';
53201 return SQLITE_CANTOPEN_BKPT;
53202 }
53203 sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
53204 return SQLITE_OK;
53205 }
53206 #endif /* __CYGWIN__ */
53207
53208 /*
53209 ** Turn a relative pathname into a full pathname. Write the full
53210 ** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
53211 ** bytes in size.
@@ -52972,12 +53214,12 @@
53214 sqlite3_vfs *pVfs, /* Pointer to vfs object */
53215 const char *zRelative, /* Possibly relative input path */
53216 int nFull, /* Size of output buffer in bytes */
53217 char *zFull /* Output buffer */
53218 ){
53219 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
53220 int nByte;
53221 void *zConverted;
53222 char *zOut;
53223 #endif
53224
53225 /* If this path name begins with "/X:" or "\\?\", where "X" is any
@@ -52986,68 +53228,114 @@
53228 if( zRelative[0]=='/' && (winIsDriveLetterAndColon(zRelative+1)
53229 || winIsLongPathPrefix(zRelative+1)) ){
53230 zRelative++;
53231 }
53232
53233 SimulateIOError( return SQLITE_ERROR );
53234
53235 #ifdef __CYGWIN__
53236 if( osGetcwd ){
53237 zFull[nFull-1] = '\0';
53238 if( !winIsDriveLetterAndColon(zRelative) || !winIsDirSep(zRelative[2]) ){
53239 int rc = SQLITE_OK;
53240 int nLink = 1; /* Number of symbolic links followed so far */
53241 const char *zIn = zRelative; /* Input path for each iteration of loop */
53242 char *zDel = 0;
53243 struct stat buf;
53244
53245 UNUSED_PARAMETER(pVfs);
53246
53247 do {
53248 /* Call lstat() on path zIn. Set bLink to true if the path is a symbolic
53249 ** link, or false otherwise. */
53250 int bLink = 0;
53251 if( osLstat && osReadlink ) {
53252 if( osLstat(zIn, &buf)!=0 ){
53253 int myErrno = osErrno;
53254 if( myErrno!=ENOENT ){
53255 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)myErrno, "lstat", zIn);
53256 }
53257 }else{
53258 bLink = ((buf.st_mode & 0170000) == 0120000);
53259 }
53260
53261 if( bLink ){
53262 if( zDel==0 ){
53263 zDel = sqlite3MallocZero(nFull);
53264 if( zDel==0 ) rc = SQLITE_NOMEM;
53265 }else if( ++nLink>SQLITE_MAX_SYMLINKS ){
53266 rc = SQLITE_CANTOPEN_BKPT;
53267 }
53268
53269 if( rc==SQLITE_OK ){
53270 nByte = osReadlink(zIn, zDel, nFull-1);
53271 if( nByte ==(DWORD)-1 ){
53272 rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn);
53273 }else{
53274 if( zDel[0]!='/' ){
53275 int n;
53276 for(n = sqlite3Strlen30(zIn); n>0 && zIn[n-1]!='/'; n--);
53277 if( nByte+n+1>nFull ){
53278 rc = SQLITE_CANTOPEN_BKPT;
53279 }else{
53280 memmove(&zDel[n], zDel, nByte+1);
53281 memcpy(zDel, zIn, n);
53282 nByte += n;
53283 }
53284 }
53285 zDel[nByte] = '\0';
53286 }
53287 }
53288
53289 zIn = zDel;
53290 }
53291 }
53292
53293 assert( rc!=SQLITE_OK || zIn!=zFull || zIn[0]=='/' );
53294 if( rc==SQLITE_OK && zIn!=zFull ){
53295 rc = mkFullPathname(zIn, zFull, nFull);
53296 }
53297 if( bLink==0 ) break;
53298 zIn = zFull;
53299 }while( rc==SQLITE_OK );
53300
53301 sqlite3_free(zDel);
53302 winSimplifyName(zFull);
53303 return rc;
53304 }
53305 }
53306 #endif /* __CYGWIN__ */
53307 #if 0 /* This doesn't work correctly at all! See:
53308 <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53309 */
53310 SimulateIOError( return SQLITE_ERROR );
53311 UNUSED_PARAMETER(nFull);
53312 assert( nFull>=pVfs->mxPathname );
53313 char *zOut = sqlite3MallocZero( pVfs->mxPathname+1 );
53314 if( !zOut ){
53315 return SQLITE_IOERR_NOMEM_BKPT;
53316 }
53317 if( osCygwin_conv_path(
53318 CCP_POSIX_TO_WIN_W,
53319 zRelative, zOut, pVfs->mxPathname+1)<0 ){
53320 sqlite3_free(zOut);
53321 return winLogError(SQLITE_CANTOPEN_CONVPATH, (DWORD)errno,
53322 "winFullPathname2", zRelative);
53323 }else{
53324 char *zUtf8 = winConvertToUtf8Filename(zOut);
53325 if( !zUtf8 ){
53326 sqlite3_free(zOut);
53327 return SQLITE_IOERR_NOMEM_BKPT;
53328 }
53329 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zUtf8);
53330 sqlite3_free(zUtf8);
53331 sqlite3_free(zOut);
53332 }
53333 return SQLITE_OK;
53334 #endif
53335
53336 #if (SQLITE_OS_WINCE || SQLITE_OS_WINRT) && defined(_WIN32)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53337 SimulateIOError( return SQLITE_ERROR );
53338 /* WinCE has no concept of a relative pathname, or so I am told. */
53339 /* WinRT has no way to convert a relative path to an absolute one. */
53340 if ( sqlite3_data_directory && !winIsVerbatimPathname(zRelative) ){
53341 /*
@@ -53062,11 +53350,12 @@
53350 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
53351 }
53352 return SQLITE_OK;
53353 #endif
53354
53355 #if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
53356 #if defined(_WIN32)
53357 /* It's odd to simulate an io-error here, but really this is just
53358 ** using the io-error infrastructure to test that SQLite handles this
53359 ** function failing. This function could fail if, for example, the
53360 ** current working directory has been unlinked.
53361 */
@@ -53080,10 +53369,11 @@
53369 */
53370 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s%c%s",
53371 sqlite3_data_directory, winGetDirSep(), zRelative);
53372 return SQLITE_OK;
53373 }
53374 #endif
53375 zConverted = winConvertFromUtf8Filename(zRelative);
53376 if( zConverted==0 ){
53377 return SQLITE_IOERR_NOMEM_BKPT;
53378 }
53379 if( osIsNT() ){
@@ -53092,16 +53382,17 @@
53382 if( nByte==0 ){
53383 sqlite3_free(zConverted);
53384 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
53385 "winFullPathname1", zRelative);
53386 }
53387 nByte += 3;
53388 zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
53389 if( zTemp==0 ){
53390 sqlite3_free(zConverted);
53391 return SQLITE_IOERR_NOMEM_BKPT;
53392 }
53393 nByte = osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
53394 if( nByte==0 ){
53395 sqlite3_free(zConverted);
53396 sqlite3_free(zTemp);
53397 return winLogError(SQLITE_CANTOPEN_FULLPATH, osGetLastError(),
53398 "winFullPathname2", zRelative);
@@ -53135,11 +53426,30 @@
53426 zOut = winMbcsToUtf8(zTemp, osAreFileApisANSI());
53427 sqlite3_free(zTemp);
53428 }
53429 #endif
53430 if( zOut ){
53431 #ifdef __CYGWIN__
53432 if( memcmp(zOut, "\\\\?\\", 4) ){
53433 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
53434 }else if( memcmp(zOut+4, "UNC\\", 4) ){
53435 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut+4);
53436 }else{
53437 char *p = zOut+6;
53438 *p = '\\';
53439 if( osGetcwd ){
53440 /* On Cygwin, UNC paths use forward slashes */
53441 while( *p ){
53442 if( *p=='\\' ) *p = '/';
53443 ++p;
53444 }
53445 }
53446 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut+6);
53447 }
53448 #else
53449 sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zOut);
53450 #endif /* __CYGWIN__ */
53451 sqlite3_free(zOut);
53452 return SQLITE_OK;
53453 }else{
53454 return SQLITE_IOERR_NOMEM_BKPT;
53455 }
@@ -53165,11 +53475,13 @@
53475 ** Interfaces for opening a shared library, finding entry points
53476 ** within the shared library, and closing the shared library.
53477 */
53478 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
53479 HANDLE h;
53480 #if 0 /* This doesn't work correctly at all! See:
53481 <https://marc.info/?l=sqlite-users&m=139299149416314&w=2>
53482 */
53483 int nFull = pVfs->mxPathname+1;
53484 char *zFull = sqlite3MallocZero( nFull );
53485 void *zConverted = 0;
53486 if( zFull==0 ){
53487 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
@@ -53532,11 +53844,11 @@
53844 };
53845 #endif
53846
53847 /* Double-check that the aSyscall[] array has been constructed
53848 ** correctly. See ticket [bb3a86e890c8e96ab] */
53849 assert( ArraySize(aSyscall)==89 );
53850
53851 /* get memory map allocation granularity */
53852 memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
53853 #if SQLITE_OS_WINRT
53854 osGetNativeSystemInfo(&winSysInfo);
@@ -66508,14 +66820,12 @@
66820 s2 = aIn[1];
66821 }else{
66822 s1 = s2 = 0;
66823 }
66824
66825 /* nByte is a multiple of 8 between 8 and 65536 */
66826 assert( nByte>=8 && (nByte&7)==0 && nByte<=65536 );
 
 
66827
66828 if( !nativeCksum ){
66829 do {
66830 s1 += BYTESWAP32(aData[0]) + s2;
66831 s2 += BYTESWAP32(aData[1]) + s1;
@@ -147785,10 +148095,11 @@
148095 }
148096
148097 multi_select_end:
148098 pDest->iSdst = dest.iSdst;
148099 pDest->nSdst = dest.nSdst;
148100 pDest->iSDParm2 = dest.iSDParm2;
148101 if( pDelete ){
148102 sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pDelete);
148103 }
148104 return rc;
148105 }
@@ -188065,10 +188376,17 @@
188376 ******************************************************************************
188377 **
188378 */
188379 #ifndef _FTSINT_H
188380 #define _FTSINT_H
188381
188382 /* #include <assert.h> */
188383 /* #include <stdlib.h> */
188384 /* #include <stddef.h> */
188385 /* #include <stdio.h> */
188386 /* #include <string.h> */
188387 /* #include <stdarg.h> */
188388
188389 #if !defined(NDEBUG) && !defined(SQLITE_DEBUG)
188390 # define NDEBUG 1
188391 #endif
188392
@@ -189017,16 +189335,10 @@
189335
189336 #if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
189337 # define SQLITE_CORE 1
189338 #endif
189339
 
 
 
 
 
 
189340
189341 /* #include "fts3.h" */
189342 #ifndef SQLITE_CORE
189343 /* # include "sqlite3ext.h" */
189344 SQLITE_EXTENSION_INIT1
@@ -227533,12 +227845,12 @@
227845 ){
227846 if( sqlite3_value_type(argv[3])==SQLITE_NULL && isInsert && pgno>1 ){
227847 /* "INSERT INTO dbpage($PGNO,NULL)" causes page number $PGNO and
227848 ** all subsequent pages to be deleted. */
227849 pTab->iDbTrunc = iDb;
227850 pTab->pgnoTrunc = pgno-1;
227851 pgno = 1;
227852 }else{
227853 zErr = "bad page value";
227854 goto update_fail;
227855 }
227856 }
@@ -241869,11 +242181,12 @@
242181 sqlite3Fts5ParseError(
242182 pParse, "expected integer, got \"%.*s\"", p->n, p->p
242183 );
242184 return;
242185 }
242186 if( nNear<214748363 ) nNear = nNear * 10 + (p->p[i] - '0');
242187 /* ^^^^^^^^^^^^^^^--- Prevent integer overflow */
242188 }
242189 }else{
242190 nNear = FTS5_DEFAULT_NEARDIST;
242191 }
242192 pNear->nNear = nNear;
@@ -256775,11 +257088,11 @@
257088 int nArg, /* Number of args */
257089 sqlite3_value **apUnused /* Function arguments */
257090 ){
257091 assert( nArg==0 );
257092 UNUSED_PARAM2(nArg, apUnused);
257093 sqlite3_result_text(pCtx, "fts5: 2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85", -1, SQLITE_TRANSIENT);
257094 }
257095
257096 /*
257097 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257098 **
257099
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.50.0"
150150
#define SQLITE_VERSION_NUMBER 3050000
151
-#define SQLITE_SOURCE_ID "2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185"
151
+#define SQLITE_SOURCE_ID "2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-03-16 00:13:29 18bda13e197e4b4ec7464b3e70012f71edc05f73d8b14bb48bad452f81c7e185"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-03-27 23:29:25 121f4d97f9a855131859d342bc2ade5f8c34ba7732029ae156d02cec7cb6dd85"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

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