Fossil SCM

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

drh 2026-06-27 10:28 UTC trunk
Commit 859458555b9ba82cf034908d21e025a352f26002db387f45c4e4c046c4ff8d93
3 files changed +25 -16 +777 -416 +63 -10
+25 -16
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5839,10 +5839,13 @@
58395839
}
58405840
58415841
/*
58425842
** Allocate a new Decimal object initialized to the text in zIn[].
58435843
** Return NULL if any kind of error occurs.
5844
+**
5845
+** Note that zIn[] is not necessarily zero-terminated. Always
5846
+** respect the boundary imposed by the n argument.
58445847
*/
58455848
static Decimal *decimalNewFromText(const char *zIn, int n){
58465849
Decimal *p = 0;
58475850
int i;
58485851
int iExp = 0;
@@ -5856,15 +5859,15 @@
58565859
p->isNull = 0;
58575860
p->nDigit = 0;
58585861
p->nFrac = 0;
58595862
p->a = sqlite3_malloc64( n+1 );
58605863
if( p->a==0 ) goto new_from_text_failed;
5861
- for(i=0; IsSpace(zIn[i]); i++){}
5862
- if( zIn[i]=='-' ){
5864
+ for(i=0; i<n && IsSpace(zIn[i]); i++){}
5865
+ if( i<n && zIn[i]=='-' ){
58635866
p->sign = 1;
58645867
i++;
5865
- }else if( zIn[i]=='+' ){
5868
+ }else if( i<n && zIn[i]=='+' ){
58665869
i++;
58675870
}
58685871
while( i<n && zIn[i]=='0' ) i++;
58695872
while( i<n ){
58705873
char c = zIn[i];
@@ -6091,11 +6094,11 @@
60916094
if( p->a[N]>=5 ){
60926095
/* If all leading digits are 9, increase the number of digits
60936096
** by adding a new 0 to the front */
60946097
for(i=0; i<N && p->a[i]==9; i++){}
60956098
if( i==N ){
6096
- decimal_expand(p, p->nDigit+1, 0);
6099
+ decimal_expand(p, p->nDigit+1, p->nFrac);
60976100
if( p->oom ) return;
60986101
}
60996102
61006103
/* Do the rounding */
61016104
p->a[N-1]++;
@@ -6249,10 +6252,11 @@
62496252
int nAddSig;
62506253
int nAddFrac;
62516254
signed char *a;
62526255
if( p==0 ) return;
62536256
nAddFrac = nFrac - p->nFrac;
6257
+ assert( nAddFrac>=0 );
62546258
nAddSig = (nDigit - p->nDigit) - nAddFrac;
62556259
if( nAddFrac==0 && nAddSig==0 ) return;
62566260
if( nDigit+1>SQLITE_DECIMAL_MAX_DIGIT ){ p->oom = 1; return; }
62576261
a = sqlite3_realloc64(p->a, nDigit+1);
62586262
if( a==0 ){
@@ -8256,10 +8260,20 @@
82568260
if( r==(double)x ) return r;
82578261
if( r<(double)x ) x--;
82588262
return (double)x;
82598263
}
82608264
#endif
8265
+
8266
+/* Convert a floating point value to its closest integer. Do so in
8267
+** a way that avoids 'outside the range of representable values' warnings
8268
+** from UBSAN.
8269
+*/
8270
+sqlite3_int64 seriesRealToI64(double r){
8271
+ if( r<-9223372036854774784.0 ) return SMALLEST_INT64;
8272
+ if( r>+9223372036854774784.0 ) return LARGEST_INT64;
8273
+ return (sqlite3_int64)r;
8274
+}
82618275
82628276
/*
82638277
** This method is called to "rewind" the series_cursor object back
82648278
** to the first row of output. This method is always called at least
82658279
** once prior to any call to seriesColumn() or seriesRowid() or
@@ -8379,11 +8393,11 @@
83798393
double r = sqlite3_value_double(argv[iArg++]);
83808394
if( r==seriesCeil(r)
83818395
&& r>=(double)SMALLEST_INT64
83828396
&& r<=(double)LARGEST_INT64
83838397
){
8384
- iMin = iMax = (sqlite3_int64)r;
8398
+ iMin = iMax = seriesRealToI64(r);
83858399
}else{
83868400
goto series_no_rows;
83878401
}
83888402
}else{
83898403
iMin = iMax = sqlite3_value_int64(argv[iArg++]);
@@ -8395,14 +8409,11 @@
83958409
if( r<=(double)SMALLEST_INT64 ){
83968410
iMin = SMALLEST_INT64;
83978411
}else if( r>(double)LARGEST_INT64 ){
83988412
goto series_no_rows;
83998413
}else{
8400
- iMin = (sqlite3_int64)seriesCeil(r);
8401
- if( iMin<0 && r>0.0 ){
8402
- iMin = LARGEST_INT64;
8403
- }
8414
+ iMin = seriesRealToI64(seriesCeil(r));
84048415
if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
84058416
if( iMin==LARGEST_INT64 ) goto series_no_rows;
84068417
iMin++;
84078418
}
84088419
}
@@ -8423,14 +8434,12 @@
84238434
if( r>=(double)LARGEST_INT64 ){
84248435
iMax = LARGEST_INT64;
84258436
}else if( r<=(double)SMALLEST_INT64 ){
84268437
goto series_no_rows;
84278438
}else{
8428
- iMax = (sqlite3_int64)seriesFloor(r);
8429
- if( iMax<0 && r>0.0 ){
8430
- iMax = LARGEST_INT64;
8431
- }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8439
+ iMax = seriesRealToI64(seriesFloor(r));
8440
+ if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
84328441
if( iMax==SMALLEST_INT64 ) goto series_no_rows;
84338442
iMax--;
84348443
}
84358444
}
84368445
}else{
@@ -14457,11 +14466,11 @@
1445714466
eocd.nEntry = (u16)p->nEntry;
1445814467
eocd.nEntryTotal = (u16)p->nEntry;
1445914468
eocd.nSize = p->cds.n;
1446014469
eocd.iOffset = p->body.n;
1446114470
14462
- nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
14471
+ nZip = (i64)p->body.n + (i64)p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
1446314472
aZip = (u8*)sqlite3_malloc64(nZip);
1446414473
if( aZip==0 ){
1446514474
sqlite3_result_error_nomem(pCtx);
1446614475
}else{
1446714476
memcpy(aZip, p->body.a, p->body.n);
@@ -17584,11 +17593,11 @@
1758417593
}
1758517594
iRet++;
1758617595
}
1758717596
}
1758817597
else if( c=='[' ){
17589
- while( z[iRet++]!=']' && z[iRet] );
17598
+ while( z[iRet] && z[iRet++]!=']' ){}
1759017599
}
1759117600
else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
1759217601
while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){
1759317602
iRet++;
1759417603
}
@@ -20355,11 +20364,11 @@
2035520364
){
2035620365
int rc = SQLITE_OK;
2035720366
SQLITE_EXTENSION_INIT2(pApi);
2035820367
(void)pzErrMsg; /* Unused parameter */
2035920368
rc = sqlite3_create_function(db, "diskused", 1,
20360
- SQLITE_UTF8|SQLITE_INNOCUOUS,
20369
+ SQLITE_UTF8|SQLITE_DIRECTONLY,
2036120370
0, diskusedFunc, 0, 0);
2036220371
return rc;
2036320372
}
2036420373
2036520374
/************************* End ext/misc/diskused.c ********************/
2036620375
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5839,10 +5839,13 @@
5839 }
5840
5841 /*
5842 ** Allocate a new Decimal object initialized to the text in zIn[].
5843 ** Return NULL if any kind of error occurs.
 
 
 
5844 */
5845 static Decimal *decimalNewFromText(const char *zIn, int n){
5846 Decimal *p = 0;
5847 int i;
5848 int iExp = 0;
@@ -5856,15 +5859,15 @@
5856 p->isNull = 0;
5857 p->nDigit = 0;
5858 p->nFrac = 0;
5859 p->a = sqlite3_malloc64( n+1 );
5860 if( p->a==0 ) goto new_from_text_failed;
5861 for(i=0; IsSpace(zIn[i]); i++){}
5862 if( zIn[i]=='-' ){
5863 p->sign = 1;
5864 i++;
5865 }else if( zIn[i]=='+' ){
5866 i++;
5867 }
5868 while( i<n && zIn[i]=='0' ) i++;
5869 while( i<n ){
5870 char c = zIn[i];
@@ -6091,11 +6094,11 @@
6091 if( p->a[N]>=5 ){
6092 /* If all leading digits are 9, increase the number of digits
6093 ** by adding a new 0 to the front */
6094 for(i=0; i<N && p->a[i]==9; i++){}
6095 if( i==N ){
6096 decimal_expand(p, p->nDigit+1, 0);
6097 if( p->oom ) return;
6098 }
6099
6100 /* Do the rounding */
6101 p->a[N-1]++;
@@ -6249,10 +6252,11 @@
6249 int nAddSig;
6250 int nAddFrac;
6251 signed char *a;
6252 if( p==0 ) return;
6253 nAddFrac = nFrac - p->nFrac;
 
6254 nAddSig = (nDigit - p->nDigit) - nAddFrac;
6255 if( nAddFrac==0 && nAddSig==0 ) return;
6256 if( nDigit+1>SQLITE_DECIMAL_MAX_DIGIT ){ p->oom = 1; return; }
6257 a = sqlite3_realloc64(p->a, nDigit+1);
6258 if( a==0 ){
@@ -8256,10 +8260,20 @@
8256 if( r==(double)x ) return r;
8257 if( r<(double)x ) x--;
8258 return (double)x;
8259 }
8260 #endif
 
 
 
 
 
 
 
 
 
 
8261
8262 /*
8263 ** This method is called to "rewind" the series_cursor object back
8264 ** to the first row of output. This method is always called at least
8265 ** once prior to any call to seriesColumn() or seriesRowid() or
@@ -8379,11 +8393,11 @@
8379 double r = sqlite3_value_double(argv[iArg++]);
8380 if( r==seriesCeil(r)
8381 && r>=(double)SMALLEST_INT64
8382 && r<=(double)LARGEST_INT64
8383 ){
8384 iMin = iMax = (sqlite3_int64)r;
8385 }else{
8386 goto series_no_rows;
8387 }
8388 }else{
8389 iMin = iMax = sqlite3_value_int64(argv[iArg++]);
@@ -8395,14 +8409,11 @@
8395 if( r<=(double)SMALLEST_INT64 ){
8396 iMin = SMALLEST_INT64;
8397 }else if( r>(double)LARGEST_INT64 ){
8398 goto series_no_rows;
8399 }else{
8400 iMin = (sqlite3_int64)seriesCeil(r);
8401 if( iMin<0 && r>0.0 ){
8402 iMin = LARGEST_INT64;
8403 }
8404 if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8405 if( iMin==LARGEST_INT64 ) goto series_no_rows;
8406 iMin++;
8407 }
8408 }
@@ -8423,14 +8434,12 @@
8423 if( r>=(double)LARGEST_INT64 ){
8424 iMax = LARGEST_INT64;
8425 }else if( r<=(double)SMALLEST_INT64 ){
8426 goto series_no_rows;
8427 }else{
8428 iMax = (sqlite3_int64)seriesFloor(r);
8429 if( iMax<0 && r>0.0 ){
8430 iMax = LARGEST_INT64;
8431 }else if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
8432 if( iMax==SMALLEST_INT64 ) goto series_no_rows;
8433 iMax--;
8434 }
8435 }
8436 }else{
@@ -14457,11 +14466,11 @@
14457 eocd.nEntry = (u16)p->nEntry;
14458 eocd.nEntryTotal = (u16)p->nEntry;
14459 eocd.nSize = p->cds.n;
14460 eocd.iOffset = p->body.n;
14461
14462 nZip = p->body.n + p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
14463 aZip = (u8*)sqlite3_malloc64(nZip);
14464 if( aZip==0 ){
14465 sqlite3_result_error_nomem(pCtx);
14466 }else{
14467 memcpy(aZip, p->body.a, p->body.n);
@@ -17584,11 +17593,11 @@
17584 }
17585 iRet++;
17586 }
17587 }
17588 else if( c=='[' ){
17589 while( z[iRet++]!=']' && z[iRet] );
17590 }
17591 else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
17592 while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){
17593 iRet++;
17594 }
@@ -20355,11 +20364,11 @@
20355 ){
20356 int rc = SQLITE_OK;
20357 SQLITE_EXTENSION_INIT2(pApi);
20358 (void)pzErrMsg; /* Unused parameter */
20359 rc = sqlite3_create_function(db, "diskused", 1,
20360 SQLITE_UTF8|SQLITE_INNOCUOUS,
20361 0, diskusedFunc, 0, 0);
20362 return rc;
20363 }
20364
20365 /************************* End ext/misc/diskused.c ********************/
20366
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -5839,10 +5839,13 @@
5839 }
5840
5841 /*
5842 ** Allocate a new Decimal object initialized to the text in zIn[].
5843 ** Return NULL if any kind of error occurs.
5844 **
5845 ** Note that zIn[] is not necessarily zero-terminated. Always
5846 ** respect the boundary imposed by the n argument.
5847 */
5848 static Decimal *decimalNewFromText(const char *zIn, int n){
5849 Decimal *p = 0;
5850 int i;
5851 int iExp = 0;
@@ -5856,15 +5859,15 @@
5859 p->isNull = 0;
5860 p->nDigit = 0;
5861 p->nFrac = 0;
5862 p->a = sqlite3_malloc64( n+1 );
5863 if( p->a==0 ) goto new_from_text_failed;
5864 for(i=0; i<n && IsSpace(zIn[i]); i++){}
5865 if( i<n && zIn[i]=='-' ){
5866 p->sign = 1;
5867 i++;
5868 }else if( i<n && zIn[i]=='+' ){
5869 i++;
5870 }
5871 while( i<n && zIn[i]=='0' ) i++;
5872 while( i<n ){
5873 char c = zIn[i];
@@ -6091,11 +6094,11 @@
6094 if( p->a[N]>=5 ){
6095 /* If all leading digits are 9, increase the number of digits
6096 ** by adding a new 0 to the front */
6097 for(i=0; i<N && p->a[i]==9; i++){}
6098 if( i==N ){
6099 decimal_expand(p, p->nDigit+1, p->nFrac);
6100 if( p->oom ) return;
6101 }
6102
6103 /* Do the rounding */
6104 p->a[N-1]++;
@@ -6249,10 +6252,11 @@
6252 int nAddSig;
6253 int nAddFrac;
6254 signed char *a;
6255 if( p==0 ) return;
6256 nAddFrac = nFrac - p->nFrac;
6257 assert( nAddFrac>=0 );
6258 nAddSig = (nDigit - p->nDigit) - nAddFrac;
6259 if( nAddFrac==0 && nAddSig==0 ) return;
6260 if( nDigit+1>SQLITE_DECIMAL_MAX_DIGIT ){ p->oom = 1; return; }
6261 a = sqlite3_realloc64(p->a, nDigit+1);
6262 if( a==0 ){
@@ -8256,10 +8260,20 @@
8260 if( r==(double)x ) return r;
8261 if( r<(double)x ) x--;
8262 return (double)x;
8263 }
8264 #endif
8265
8266 /* Convert a floating point value to its closest integer. Do so in
8267 ** a way that avoids 'outside the range of representable values' warnings
8268 ** from UBSAN.
8269 */
8270 sqlite3_int64 seriesRealToI64(double r){
8271 if( r<-9223372036854774784.0 ) return SMALLEST_INT64;
8272 if( r>+9223372036854774784.0 ) return LARGEST_INT64;
8273 return (sqlite3_int64)r;
8274 }
8275
8276 /*
8277 ** This method is called to "rewind" the series_cursor object back
8278 ** to the first row of output. This method is always called at least
8279 ** once prior to any call to seriesColumn() or seriesRowid() or
@@ -8379,11 +8393,11 @@
8393 double r = sqlite3_value_double(argv[iArg++]);
8394 if( r==seriesCeil(r)
8395 && r>=(double)SMALLEST_INT64
8396 && r<=(double)LARGEST_INT64
8397 ){
8398 iMin = iMax = seriesRealToI64(r);
8399 }else{
8400 goto series_no_rows;
8401 }
8402 }else{
8403 iMin = iMax = sqlite3_value_int64(argv[iArg++]);
@@ -8395,14 +8409,11 @@
8409 if( r<=(double)SMALLEST_INT64 ){
8410 iMin = SMALLEST_INT64;
8411 }else if( r>(double)LARGEST_INT64 ){
8412 goto series_no_rows;
8413 }else{
8414 iMin = seriesRealToI64(seriesCeil(r));
 
 
 
8415 if( (idxNum & 0x0200)!=0 && r==seriesCeil(r) ){
8416 if( iMin==LARGEST_INT64 ) goto series_no_rows;
8417 iMin++;
8418 }
8419 }
@@ -8423,14 +8434,12 @@
8434 if( r>=(double)LARGEST_INT64 ){
8435 iMax = LARGEST_INT64;
8436 }else if( r<=(double)SMALLEST_INT64 ){
8437 goto series_no_rows;
8438 }else{
8439 iMax = seriesRealToI64(seriesFloor(r));
8440 if( (idxNum & 0x2000)!=0 && r==seriesFloor(r) ){
 
 
8441 if( iMax==SMALLEST_INT64 ) goto series_no_rows;
8442 iMax--;
8443 }
8444 }
8445 }else{
@@ -14457,11 +14466,11 @@
14466 eocd.nEntry = (u16)p->nEntry;
14467 eocd.nEntryTotal = (u16)p->nEntry;
14468 eocd.nSize = p->cds.n;
14469 eocd.iOffset = p->body.n;
14470
14471 nZip = (i64)p->body.n + (i64)p->cds.n + ZIPFILE_EOCD_FIXED_SZ;
14472 aZip = (u8*)sqlite3_malloc64(nZip);
14473 if( aZip==0 ){
14474 sqlite3_result_error_nomem(pCtx);
14475 }else{
14476 memcpy(aZip, p->body.a, p->body.n);
@@ -17584,11 +17593,11 @@
17593 }
17594 iRet++;
17595 }
17596 }
17597 else if( c=='[' ){
17598 while( z[iRet] && z[iRet++]!=']' ){}
17599 }
17600 else if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
17601 while( (z[iRet]>='A' && z[iRet]<='Z') || (z[iRet]>='a' && z[iRet]<='z') ){
17602 iRet++;
17603 }
@@ -20355,11 +20364,11 @@
20364 ){
20365 int rc = SQLITE_OK;
20366 SQLITE_EXTENSION_INIT2(pApi);
20367 (void)pzErrMsg; /* Unused parameter */
20368 rc = sqlite3_create_function(db, "diskused", 1,
20369 SQLITE_UTF8|SQLITE_DIRECTONLY,
20370 0, diskusedFunc, 0, 0);
20371 return rc;
20372 }
20373
20374 /************************* End ext/misc/diskused.c ********************/
20375
+777 -416
--- 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
-** 3f3fb9b638f59ad982beafb7c117f24ddd3d with changes in files:
21
+** 716782abe939083b7732289d862ddfd84105 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467467
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468468
** [sqlite_version()] and [sqlite_source_id()].
469469
*/
470470
#define SQLITE_VERSION "3.54.0"
471471
#define SQLITE_VERSION_NUMBER 3054000
472
-#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
472
+#define SQLITE_SOURCE_ID "2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c"
473473
#define SQLITE_SCM_BRANCH "trunk"
474474
#define SQLITE_SCM_TAGS ""
475
-#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
475
+#define SQLITE_SCM_DATETIME "2026-06-26T19:31:46.902Z"
476476
477477
/*
478478
** CAPI3REF: Run-Time Library Version Numbers
479479
** KEYWORDS: sqlite3_version sqlite3_sourceid
480480
**
@@ -3732,11 +3732,11 @@
37323732
** authorizer will fail with an error message explaining that
37333733
** access is denied.
37343734
**
37353735
** ^The first parameter to the authorizer callback is a copy of the third
37363736
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3737
-** to the callback is an integer [SQLITE_COPY | action code] that specifies
3737
+** to the callback is an integer [SQLITE_READ | action code] that specifies
37383738
** the particular action to be authorized. ^The third through sixth parameters
37393739
** to the callback are either NULL pointers or zero-terminated strings
37403740
** that contain additional details about the action to be authorized.
37413741
** Applications must always be prepared to encounter a NULL pointer in any
37423742
** of the third through the sixth parameters of the authorization callback.
@@ -3775,25 +3775,37 @@
37753775
** ^(Only a single authorizer can be in place on a database connection
37763776
** at a time. Each call to sqlite3_set_authorizer overrides the
37773777
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
37783778
** The authorizer is disabled by default.
37793779
**
3780
-** The authorizer callback must not do anything that will modify
3780
+** <h3>Limitations And Caveats</h3><ul>
3781
+**
3782
+** <li>The authorizer callback must not do anything that will modify
37813783
** the database connection that invoked the authorizer callback.
37823784
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
37833785
** database connections for the meaning of "modify" in this paragraph.
37843786
**
3785
-** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3787
+** <li>^When [sqlite3_prepare_v2()] is used to prepare a statement, the
37863788
** statement might be re-prepared during [sqlite3_step()] due to a
37873789
** schema change. Hence, the application should ensure that the
37883790
** correct authorizer callback remains in place during the [sqlite3_step()].
37893791
**
3790
-** ^Note that the authorizer callback is invoked only during
3792
+** <li>^The authorizer callback is invoked only during
37913793
** [sqlite3_prepare()] or its variants. Authorization is not
37923794
** performed during statement evaluation in [sqlite3_step()], unless
37933795
** as stated in the previous paragraph, sqlite3_step() invokes
37943796
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3797
+**
3798
+** <li>Authorizer callbacks for the expressions of a
3799
+** [generated column] are invoked when the schema is parsed (and specifically
3800
+** when the [CREATE TABLE] statement that contains the generated column is
3801
+** parsed) not when the generated column is used in a DML statement.
3802
+** This is deliberate, as one of the purposes of generated columns
3803
+** is to give schema designers the ability to provide gated access
3804
+** to privileged columns and/or functions.
3805
+**
3806
+** </ul>
37953807
*/
37963808
SQLITE_API int sqlite3_set_authorizer(
37973809
sqlite3*,
37983810
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
37993811
void *pUserData
@@ -3864,12 +3876,17 @@
38643876
#define SQLITE_ANALYZE 28 /* Table Name NULL */
38653877
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
38663878
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
38673879
#define SQLITE_FUNCTION 31 /* NULL Function Name */
38683880
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3869
-#define SQLITE_COPY 0 /* No longer used */
38703881
#define SQLITE_RECURSIVE 33 /* NULL NULL */
3882
+
3883
+/*
3884
+** Note: The SQLITE_COPY macro (with value 0) used to be one of the
3885
+** action codes above. That macro has now been repurposed as a possible
3886
+** value to the 3rd argument to sqlite3_result_str().
3887
+*/
38713888
38723889
/*
38733890
** CAPI3REF: Deprecated Tracing And Profiling Functions
38743891
** DEPRECATED
38753892
**
@@ -4860,10 +4877,12 @@
48604877
** there is a small performance advantage to passing an nByte parameter that
48614878
** is the number of bytes in the input string <i>including</i>
48624879
** the nul-terminator.
48634880
** Note that nByte measures the length of the input in bytes, not
48644881
** characters, even for the UTF-16 interfaces.
4882
+** For the sqlite3_prepare16() and sqlite3_prepare16_v2() interfaces,
4883
+** the nByte value must be even or undefined behavior can result.
48654884
**
48664885
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
48674886
** past the end of the first SQL statement in zSql. These routines only
48684887
** compile the first statement in zSql, so *pzTail is left pointing to
48694888
** what remains uncompiled.
@@ -5606,11 +5625,11 @@
56065625
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
56075626
** can be obtained by calling [sqlite3_reset()] on the
56085627
** [prepared statement]. ^In the "v2" interface,
56095628
** the more specific error code is returned directly by sqlite3_step().
56105629
**
5611
-** [SQLITE_MISUSE] means that the this routine was called inappropriately.
5630
+** [SQLITE_MISUSE] means that this routine was called inappropriately.
56125631
** Perhaps it was called on a [prepared statement] that has
56135632
** already been [sqlite3_finalize | finalized] or on one that had
56145633
** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
56155634
** be the case that the same database connection is being used by two or
56165635
** more threads at the same moment in time.
@@ -9117,12 +9136,12 @@
91179136
** The lifecycle of an sqlite3_str object is as follows:
91189137
** <ol>
91199138
** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
91209139
** <li> ^Text is appended to the sqlite3_str object using various
91219140
** methods, such as [sqlite3_str_appendf()].
9122
-** <li> ^The sqlite3_str object is destroyed and the string it created
9123
-** is returned using the [sqlite3_str_finish()] interface.
9141
+** <li> The sqlite3_str object is destroyed and the string it created
9142
+** is returned using [sqlite3_str_finish()] or [sqlite3_result_str()].
91249143
** </ol>
91259144
*/
91269145
typedef struct sqlite3_str sqlite3_str;
91279146
91289147
/*
@@ -9170,10 +9189,44 @@
91709189
** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
91719190
*/
91729191
SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
91739192
SQLITE_API void sqlite3_str_free(sqlite3_str*);
91749193
9194
+/*
9195
+** CAPI3REF: Return A Dynamic String From an SQL Function
9196
+**
9197
+** The [sqlite3_result_str(C,S,F)] interface causes the
9198
+** [sqlite3_str|dynamic string] S to become the return value for the
9199
+** application-defined function or virtual table that uses
9200
+** [sqlite3_context] C. The F flag can be one of [SQLITE_COPY]
9201
+** or [SQLITE_XFER] or [SQLITE_FINISH].
9202
+**
9203
+** If the dynamic string is invalid or incomplete due to an out-of-memory
9204
+** or string-too-large error, then this routine transfers that error
9205
+** over to the SQL function.
9206
+**
9207
+** If the F argument is SQLITE_COPY, then a copy of the dynamic string
9208
+** content is made and the dynamic string object is unchanged.
9209
+** If the F argument is SQLITE_XFER, then ownership of the content
9210
+** in the dynamic is transferred to the SQL function (via a pointer copy
9211
+** rather than a string copy) and the dynamic string is reset to an
9212
+** empty string. The SQLITE_FINISH value for F works like SQLITE_RESET
9213
+** except that it also invokes the [sqlite3_str_free(S)] destructor
9214
+** on the dynamic string object.
9215
+*/
9216
+SQLITE_API void sqlite3_result_str(sqlite3_context*, sqlite3_str*, int);
9217
+
9218
+/*
9219
+** CAPI3REF: Control Flags For sqlite3_result_str()
9220
+**
9221
+** The following integers can be used as the third "F" argument
9222
+** to [sqlite3_result_str(C,S,F)].
9223
+*/
9224
+#define SQLITE_COPY 0 /* Results copied. Dynamic string unchanged */
9225
+#define SQLITE_XFER 1 /* Results transfered. Dynamic string reset */
9226
+#define SQLITE_FINISH 2 /* Like SQLITE_XFER, plus dynamic string freed */
9227
+
91759228
/*
91769229
** CAPI3REF: Add Content To A Dynamic String
91779230
** METHOD: sqlite3_str
91789231
**
91799232
** These interfaces add or remove content to an sqlite3_str object
@@ -17190,11 +17243,11 @@
1719017243
SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
1719117244
#endif
1719217245
1719317246
SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
1719417247
SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
17195
-SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
17248
+SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree*, Btree*);
1719617249
1719717250
SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
1719817251
1719917252
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
1720017253
** of the flags shown below.
@@ -17267,16 +17320,23 @@
1726717320
** The design of the _RANGE hint is aid b-tree implementations that try
1726817321
** to prefetch content from remote machines - to provide those
1726917322
** implementations with limits on what needs to be prefetched and thereby
1727017323
** reduce network bandwidth.
1727117324
**
17325
+** BTREE_HINT_TABLECURSOR (arguments: BtCursor*)
17326
+**
17327
+** This hint is invoked on a non-covering index cursor soon after it
17328
+** is opened. The only argument is a pointer to the table cursor used to
17329
+** obtain non-covered fields from the database.
17330
+**
1727217331
** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
1727317332
** standard SQLite. The other hints are provided for extensions that use
1727417333
** the SQLite parser and code generator but substitute their own storage
1727517334
** engine.
1727617335
*/
1727717336
#define BTREE_HINT_RANGE 0 /* Range constraints on queries */
17337
+#define BTREE_HINT_TABLECURSOR 1 /* Table csr associated with this index csr */
1727817338
1727917339
/*
1728017340
** Values that may be OR'd together to form the argument to the
1728117341
** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
1728217342
**
@@ -17332,10 +17392,13 @@
1733217392
#endif
1733317393
SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
1733417394
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
1733517395
#ifdef SQLITE_ENABLE_CURSOR_HINTS
1733617396
SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
17397
+ #ifdef SQLITE_DEBUG
17398
+SQLITE_PRIVATE BtCursor *sqlite3BtreeCursorHintTblCsr(BtCursor*);
17399
+ #endif
1733717400
#endif
1733817401
1733917402
SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
1734017403
SQLITE_PRIVATE int sqlite3BtreeTableMoveto(
1734117404
BtCursor*,
@@ -20940,16 +21003,16 @@
2094021003
bft bHasExists :1; /* Has a correlated "EXISTS (SELECT ....)" expression */
2094121004
bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
2094221005
bft bHasWith :1; /* True if statement contains WITH */
2094321006
bft okConstFactor:1; /* OK to factor out constants */
2094421007
bft checkSchema :1; /* Causes schema cookie check after an error */
21008
+ bft usesAinc :1; /* True if pAinc is valid */
2094521009
int nRangeReg; /* Size of the temporary register block */
2094621010
int iRangeReg; /* First register in temporary register block */
2094721011
int nErr; /* Number of errors seen */
2094821012
int nTab; /* Number of previously allocated VDBE cursors */
2094921013
int nMem; /* Number of memory cells used so far */
20950
- int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
2095121014
int iSelfTab; /* Table associated with an index on expr, or negative
2095221015
** of the base register during check-constraint eval */
2095321016
int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
2095421017
int nLabel; /* The *negative* of the number of labels used */
2095521018
int nLabelAlloc; /* Number of slots in aLabel */
@@ -20964,13 +21027,11 @@
2096421027
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
2096521028
u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
2096621029
#endif
2096721030
#ifndef SQLITE_OMIT_SHARED_CACHE
2096821031
int nTableLock; /* Number of locks in aTableLock */
20969
- TableLock *aTableLock; /* Required table locks for shared-cache mode */
2097021032
#endif
20971
- AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
2097221033
Parse *pToplevel; /* Parse structure for main program (or NULL) */
2097321034
Table *pTriggerTab; /* Table triggers are being coded for */
2097421035
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
2097521036
ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
2097621037
@@ -20995,10 +21056,17 @@
2099521056
} cr;
2099621057
struct { /* These fields available to all other statements */
2099721058
Returning *pReturning; /* The RETURNING clause */
2099821059
} d;
2099921060
} u1;
21061
+ AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters. Only
21062
+ ** valid if Parse.usesAinc is true */
21063
+#ifndef SQLITE_OMIT_SHARED_CACHE
21064
+ TableLock *aTableLock; /* Required table locks for shared-cache mode. Only
21065
+ ** valid if Parse.nTableLock>0 */
21066
+#endif
21067
+
2100021068
2100121069
/************************************************************************
2100221070
** Above is constant between recursions. Below is reset before and after
2100321071
** each recursion. The boundary between these two regions is determined
2100421072
** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -22528,10 +22596,11 @@
2252822596
SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
2252922597
SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
2253022598
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
2253122599
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
2253222600
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
22601
+SQLITE_PRIVATE const sqlite3_str sqlite3OomStr;
2253322602
#ifndef SQLITE_OMIT_WSD
2253422603
SQLITE_PRIVATE int sqlite3PendingByte;
2253522604
#endif
2253622605
#endif /* SQLITE_AMALGAMATION */
2253722606
#ifdef VDBE_PROFILE
@@ -22630,11 +22699,10 @@
2263022699
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
2263122700
SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
2263222701
SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum*, i64);
2263322702
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
2263422703
SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
22635
-SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
2263622704
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
2263722705
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
2263822706
SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
2263922707
SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
2264022708
@@ -24228,10 +24296,20 @@
2422824296
** Hash table for global functions - functions common to all
2422924297
** database connections. After initialization, this table is
2423024298
** read-only.
2423124299
*/
2423224300
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
24301
+
24302
+/*
24303
+** This singleton is an sqlite3_str object that is returned if
24304
+** sqlite3_malloc() fails to provide space for a real one. This
24305
+** sqlite3_str object accepts no new text and always returns
24306
+** an SQLITE_NOMEM error.
24307
+*/
24308
+SQLITE_PRIVATE const sqlite3_str sqlite3OomStr = {
24309
+ 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
24310
+};
2423324311
2423424312
#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
2423524313
/*
2423624314
** Counter used for coverage testing. Does not come into play for
2423724315
** release builds.
@@ -26947,42 +27025,42 @@
2694727025
){
2694827026
DateTime x;
2694927027
size_t i,j;
2695027028
sqlite3 *db;
2695127029
const char *zFmt;
26952
- sqlite3_str sRes;
27030
+ sqlite3_str *pRes;
2695327031
2695427032
2695527033
if( argc==0 ) return;
2695627034
zFmt = (const char*)sqlite3_value_text(argv[0]);
2695727035
if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
2695827036
db = sqlite3_context_db_handle(context);
26959
- sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
27037
+ pRes = sqlite3_str_new(db);
2696027038
2696127039
computeJD(&x);
2696227040
computeYMD_HMS(&x);
2696327041
for(i=j=0; zFmt[i]; i++){
2696427042
char cf;
2696527043
if( zFmt[i]!='%' ) continue;
26966
- if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
27044
+ if( j<i ) sqlite3_str_append(pRes, zFmt+j, (int)(i-j));
2696727045
i++;
2696827046
j = i + 1;
2696927047
cf = zFmt[i];
2697027048
switch( cf ){
2697127049
case 'd': /* Fall thru */
2697227050
case 'e': {
26973
- sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
27051
+ sqlite3_str_appendf(pRes, cf=='d' ? "%02d" : "%2d", x.D);
2697427052
break;
2697527053
}
2697627054
case 'f': { /* Fractional seconds. (Non-standard) */
2697727055
double s = x.s;
2697827056
if( NEVER(s>59.999) ) s = 59.999;
26979
- sqlite3_str_appendf(&sRes, "%06.3f", s);
27057
+ sqlite3_str_appendf(pRes, "%06.3f", s);
2698027058
break;
2698127059
}
2698227060
case 'F': {
26983
- sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
27061
+ sqlite3_str_appendf(pRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
2698427062
break;
2698527063
}
2698627064
case 'G': /* Fall thru */
2698727065
case 'g': {
2698827066
DateTime y = x;
@@ -26990,85 +27068,85 @@
2699027068
/* Move y so that it is the Thursday in the same week as x */
2699127069
y.iJD += (3 - daysAfterMonday(&x))*86400000;
2699227070
y.validYMD = 0;
2699327071
computeYMD(&y);
2699427072
if( cf=='g' ){
26995
- sqlite3_str_appendf(&sRes, "%02d", y.Y%100);
27073
+ sqlite3_str_appendf(pRes, "%02d", y.Y%100);
2699627074
}else{
26997
- sqlite3_str_appendf(&sRes, "%04d", y.Y);
27075
+ sqlite3_str_appendf(pRes, "%04d", y.Y);
2699827076
}
2699927077
break;
2700027078
}
2700127079
case 'H':
2700227080
case 'k': {
27003
- sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h);
27081
+ sqlite3_str_appendf(pRes, cf=='H' ? "%02d" : "%2d", x.h);
2700427082
break;
2700527083
}
2700627084
case 'I': /* Fall thru */
2700727085
case 'l': {
2700827086
int h = x.h;
2700927087
if( h>12 ) h -= 12;
2701027088
if( h==0 ) h = 12;
27011
- sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h);
27089
+ sqlite3_str_appendf(pRes, cf=='I' ? "%02d" : "%2d", h);
2701227090
break;
2701327091
}
2701427092
case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */
27015
- sqlite3_str_appendf(&sRes,"%03d",daysAfterJan01(&x)+1);
27093
+ sqlite3_str_appendf(pRes,"%03d",daysAfterJan01(&x)+1);
2701627094
break;
2701727095
}
2701827096
case 'J': { /* Julian day number. (Non-standard) */
27019
- sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
27097
+ sqlite3_str_appendf(pRes,"%.16g",x.iJD/86400000.0);
2702027098
break;
2702127099
}
2702227100
case 'm': {
27023
- sqlite3_str_appendf(&sRes,"%02d",x.M);
27101
+ sqlite3_str_appendf(pRes,"%02d",x.M);
2702427102
break;
2702527103
}
2702627104
case 'M': {
27027
- sqlite3_str_appendf(&sRes,"%02d",x.m);
27105
+ sqlite3_str_appendf(pRes,"%02d",x.m);
2702827106
break;
2702927107
}
2703027108
case 'p': /* Fall thru */
2703127109
case 'P': {
2703227110
if( x.h>=12 ){
27033
- sqlite3_str_append(&sRes, cf=='p' ? "PM" : "pm", 2);
27111
+ sqlite3_str_append(pRes, cf=='p' ? "PM" : "pm", 2);
2703427112
}else{
27035
- sqlite3_str_append(&sRes, cf=='p' ? "AM" : "am", 2);
27113
+ sqlite3_str_append(pRes, cf=='p' ? "AM" : "am", 2);
2703627114
}
2703727115
break;
2703827116
}
2703927117
case 'R': {
27040
- sqlite3_str_appendf(&sRes, "%02d:%02d", x.h, x.m);
27118
+ sqlite3_str_appendf(pRes, "%02d:%02d", x.h, x.m);
2704127119
break;
2704227120
}
2704327121
case 's': {
2704427122
if( x.useSubsec ){
27045
- sqlite3_str_appendf(&sRes,"%.3f",
27123
+ sqlite3_str_appendf(pRes,"%.3f",
2704627124
(x.iJD - 21086676*(i64)10000000)/1000.0);
2704727125
}else{
2704827126
i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
27049
- sqlite3_str_appendf(&sRes,"%lld",iS);
27127
+ sqlite3_str_appendf(pRes,"%lld",iS);
2705027128
}
2705127129
break;
2705227130
}
2705327131
case 'S': {
27054
- sqlite3_str_appendf(&sRes,"%02d",(int)x.s);
27132
+ sqlite3_str_appendf(pRes,"%02d",(int)x.s);
2705527133
break;
2705627134
}
2705727135
case 'T': {
27058
- sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
27136
+ sqlite3_str_appendf(pRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
2705927137
break;
2706027138
}
2706127139
case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */
2706227140
case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */
2706327141
char c = (char)daysAfterSunday(&x) + '0';
2706427142
if( c=='0' && cf=='u' ) c = '7';
27065
- sqlite3_str_appendchar(&sRes, 1, c);
27143
+ sqlite3_str_appendchar(pRes, 1, c);
2706627144
break;
2706727145
}
2706827146
case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */
27069
- sqlite3_str_appendf(&sRes,"%02d",
27147
+ sqlite3_str_appendf(pRes,"%02d",
2707027148
(daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7);
2707127149
break;
2707227150
}
2707327151
case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */
2707427152
DateTime y = x;
@@ -27075,34 +27153,34 @@
2707527153
/* Adjust y so that is the Thursday in the same week as x */
2707627154
assert( y.validJD );
2707727155
y.iJD += (3 - daysAfterMonday(&x))*86400000;
2707827156
y.validYMD = 0;
2707927157
computeYMD(&y);
27080
- sqlite3_str_appendf(&sRes,"%02d", daysAfterJan01(&y)/7+1);
27158
+ sqlite3_str_appendf(pRes,"%02d", daysAfterJan01(&y)/7+1);
2708127159
break;
2708227160
}
2708327161
case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */
27084
- sqlite3_str_appendf(&sRes,"%02d",
27162
+ sqlite3_str_appendf(pRes,"%02d",
2708527163
(daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7);
2708627164
break;
2708727165
}
2708827166
case 'Y': {
27089
- sqlite3_str_appendf(&sRes,"%04d",x.Y);
27167
+ sqlite3_str_appendf(pRes,"%04d",x.Y);
2709027168
break;
2709127169
}
2709227170
case '%': {
27093
- sqlite3_str_appendchar(&sRes, 1, '%');
27171
+ sqlite3_str_appendchar(pRes, 1, '%');
2709427172
break;
2709527173
}
2709627174
default: {
27097
- sqlite3_str_reset(&sRes);
27175
+ sqlite3_str_free(pRes);
2709827176
return;
2709927177
}
2710027178
}
2710127179
}
27102
- if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
27103
- sqlite3ResultStrAccum(context, &sRes);
27180
+ if( j<i ) sqlite3_str_append(pRes, zFmt+j, (int)(i-j));
27181
+ sqlite3_result_str(context, pRes, SQLITE_FINISH);
2710427182
}
2710527183
2710627184
/*
2710727185
** current_time()
2710827186
**
@@ -27234,11 +27312,11 @@
2723427312
clearYMD_HMS_TZ(&d1);
2723527313
computeYMD_HMS(&d1);
2723627314
sqlite3StrAccumInit(&sRes, 0, 0, 0, 100);
2723727315
sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f",
2723827316
sign, Y, M, d1.D-1, d1.h, d1.m, d1.s);
27239
- sqlite3ResultStrAccum(context, &sRes);
27317
+ sqlite3_result_str(context, &sRes, SQLITE_XFER);
2724027318
}
2724127319
2724227320
2724327321
/*
2724427322
** current_timestamp()
@@ -27662,11 +27740,11 @@
2766227740
if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
2766327741
rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
2766427742
}else{
2766527743
double r;
2766627744
rc = pVfs->xCurrentTime(pVfs, &r);
27667
- *pTimeOut = (sqlite3_int64)(r*86400000.0);
27745
+ *pTimeOut = sqlite3RealToI64(r*86400000.0);
2766827746
}
2766927747
return rc;
2767027748
}
2767127749
2767227750
SQLITE_PRIVATE int sqlite3OsOpenMalloc(
@@ -32612,10 +32690,14 @@
3261232690
*/
3261332691
#ifndef SQLITE_PRINTF_PRECISION_LIMIT
3261432692
# define SQLITE_FP_PRECISION_LIMIT 100000000
3261532693
#endif
3261632694
32695
+/* Forward reference */
32696
+static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N);
32697
+static void sqlite3StrAppendchar64(sqlite3_str *p, i64 N, char c);
32698
+
3261732699
/*
3261832700
** Render a string given by "fmt" into the StrAccum object.
3261932701
*/
3262032702
SQLITE_API void sqlite3_str_vappendf(
3262132703
sqlite3_str *pAccum, /* Accumulate results here */
@@ -32622,14 +32704,14 @@
3262232704
const char *fmt, /* Format string */
3262332705
va_list ap /* arguments */
3262432706
){
3262532707
int c; /* Next character in the format string */
3262632708
char *bufpt; /* Pointer to the conversion buffer */
32627
- int precision; /* Precision of the current field */
32628
- int length; /* Length of the field */
32709
+ i64 precision; /* Precision of the current field */
32710
+ i64 length; /* Length of the field */
3262932711
int idx; /* A general purpose loop counter */
32630
- int width; /* Width of the current field */
32712
+ i64 width; /* Width of the current field */
3263132713
etByte flag_leftjustify; /* True if "-" flag is present */
3263232714
etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
3263332715
etByte flag_alternateform; /* True if "#" flag is present */
3263432716
etByte flag_altform2; /* True if "!" flag is present */
3263532717
etByte flag_zeropad; /* True if field width constant starts with zero */
@@ -32673,11 +32755,11 @@
3267332755
fmt = strchr(fmt, '%');
3267432756
if( fmt==0 ){
3267532757
fmt = bufpt + strlen(bufpt);
3267632758
}
3267732759
#endif
32678
- sqlite3_str_append(pAccum, bufpt, (int)(fmt - bufpt));
32760
+ sqlite3StrAppend64(pAccum, bufpt, fmt - bufpt);
3267932761
if( *fmt==0 ) break;
3268032762
}
3268132763
if( (c=(*++fmt))==0 ){
3268232764
sqlite3_str_append(pAccum, "%", 1);
3268332765
break;
@@ -32919,26 +33001,27 @@
3291933001
do{ /* Convert to ascii */
3292033002
*(--bufpt) = cset[longvalue%base];
3292133003
longvalue = longvalue/base;
3292233004
}while( longvalue>0 );
3292333005
}
32924
- length = (int)(&zOut[nOut-1]-bufpt);
33006
+ length = &zOut[nOut-1] - bufpt;
3292533007
if( precision>length ){ /* zero pad */
32926
- int nn = precision-length;
33008
+ i64 nn = precision-length;
3292733009
bufpt -= nn;
3292833010
memset(bufpt,'0',nn);
3292933011
length = precision;
3293033012
}
3293133013
if( cThousand ){
32932
- int nn = (length - 1)/3; /* Number of "," to insert */
32933
- int ix = (length - 1)%3 + 1;
33014
+ i64 nn = (length - 1)/3; /* Number of "," to insert */
33015
+ i64 ix = (length - 1)%3 + 1;
33016
+ int ii;
3293433017
bufpt -= nn;
32935
- for(idx=0; nn>0; idx++){
32936
- bufpt[idx] = bufpt[idx+nn];
33018
+ for(ii=0; nn>0; ii++){
33019
+ bufpt[ii] = bufpt[ii+nn];
3293733020
ix--;
3293833021
if( ix==0 ){
32939
- bufpt[++idx] = cThousand;
33022
+ bufpt[++ii] = cThousand;
3294033023
nn--;
3294133024
ix = 3;
3294233025
}
3294333026
}
3294433027
}
@@ -32947,11 +33030,11 @@
3294733030
const char *pre;
3294833031
char x;
3294933032
pre = &aPrefix[infop->prefix];
3295033033
for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
3295133034
}
32952
- length = (int)(&zOut[nOut-1]-bufpt);
33035
+ length = &zOut[nOut-1] - bufpt;
3295333036
break;
3295433037
case etFLOAT:
3295533038
case etEXP:
3295633039
case etGENERIC: {
3295733040
FpDecode s;
@@ -32979,12 +33062,17 @@
3297933062
iRound = precision+1;
3298033063
}
3298133064
sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 20 : 16);
3298233065
if( s.isSpecial ){
3298333066
if( s.isSpecial==2 ){
32984
- bufpt = flag_zeropad ? "null" : "NaN";
32985
- length = sqlite3Strlen30(bufpt);
33067
+ if( flag_zeropad ){
33068
+ bufpt = "null";
33069
+ length = 4;
33070
+ }else{
33071
+ bufpt = "NaN";
33072
+ length = 3;
33073
+ }
3298633074
break;
3298733075
}else if( flag_zeropad ){
3298833076
s.z[0] = '9';
3298933077
s.iDP = 1000;
3299033078
s.n = 1;
@@ -32996,11 +33084,11 @@
3299633084
}else if( flag_prefix ){
3299733085
buf[0] = flag_prefix;
3299833086
}else{
3299933087
bufpt++;
3300033088
}
33001
- length = sqlite3Strlen30(bufpt);
33089
+ length = strlen(bufpt);
3300233090
break;
3300333091
}
3300433092
}
3300533093
if( s.sign=='-' ){
3300633094
if( flag_alternateform
@@ -33152,11 +33240,11 @@
3315233240
}
3315333241
*(bufpt++) = (char)(exp/10+'0'); /* 10's digit */
3315433242
*(bufpt++) = (char)(exp%10+'0'); /* 1's digit */
3315533243
}
3315633244
33157
- length = (int)(bufpt-zOut);
33245
+ length = bufpt - zOut;
3315833246
assert( length <= szBufNeeded );
3315933247
if( length<width ){
3316033248
i64 nPad = width - length;
3316133249
if( flag_leftjustify ){
3316233250
memset(bufpt, ' ', nPad);
@@ -33172,10 +33260,11 @@
3317233260
}
3317333261
3317433262
if( zExtra==0 ){
3317533263
/* The result is being rendered directory into pAccum. This
3317633264
** is the common and fast case */
33265
+ assert( pAccum->nChar + length < SMXV(pAccum->nChar) );
3317733266
pAccum->nChar += length;
3317833267
zOut[length] = 0;
3317933268
continue;
3318033269
}else{
3318133270
/* We were unable to render directly into pAccum because we
@@ -33218,14 +33307,14 @@
3321833307
}
3321933308
if( precision>1 ){
3322033309
i64 nPrior = 1;
3322133310
width -= precision-1;
3322233311
if( width>1 && !flag_leftjustify ){
33223
- sqlite3_str_appendchar(pAccum, width-1, ' ');
33312
+ sqlite3StrAppendchar64(pAccum, width-1, ' ');
3322433313
width = 0;
3322533314
}
33226
- sqlite3_str_append(pAccum, buf, length);
33315
+ sqlite3StrAppend64(pAccum, buf, length);
3322733316
precision--;
3322833317
while( precision > 1 ){
3322933318
i64 nCopyBytes;
3323033319
if( nPrior > precision-1 ) nPrior = precision - 1;
3323133320
nCopyBytes = length*nPrior;
@@ -33277,21 +33366,21 @@
3327733366
** precision characters */
3327833367
unsigned char *z = (unsigned char*)bufpt;
3327933368
while( precision-- > 0 && z[0] ){
3328033369
SQLITE_SKIP_UTF8(z);
3328133370
}
33282
- length = (int)(z - (unsigned char*)bufpt);
33371
+ length = z - (unsigned char*)bufpt;
3328333372
}else{
3328433373
for(length=0; length<precision && bufpt[length]; length++){}
3328533374
}
3328633375
}else{
33287
- length = 0x7fffffff & (int)strlen(bufpt);
33376
+ length = strlen(bufpt);
3328833377
}
3328933378
adjust_width_for_utf8:
3329033379
if( flag_altform2 && width>0 ){
3329133380
/* Adjust width to account for extra bytes in UTF-8 characters */
33292
- int ii = length - 1;
33381
+ i64 ii = length - 1;
3329333382
while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
3329433383
}
3329533384
break;
3329633385
case etESCAPE_j: /* %j: JSON string literal w/o "..." */
3329733386
case etESCAPE_J: { /* %J: Generate a JSON string literal */
@@ -33322,11 +33411,11 @@
3332233411
while( (escarg[px]&0xc0)==0x80 ) px++;
3332333412
}
3332433413
}
3332533414
for(i=j=0; i<px; i++){
3332633415
if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){
33327
- if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33416
+ if( j<i ) sqlite3StrAppend64(pAccum, &escarg[j], i-j);
3332833417
j = i+1;
3332933418
if( ch==0 ) break;
3333033419
sqlite3_str_appendchar(pAccum, 1, '\\');
3333133420
if( ch>0x1f ){
3333233421
sqlite3_str_appendchar(pAccum, 1, ch);
@@ -33338,11 +33427,11 @@
3333833427
sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]);
3333933428
sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]);
3334033429
}
3334133430
}
3334233431
}
33343
- if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33432
+ if( j<i ) sqlite3StrAppend64(pAccum, &escarg[j], i-j);
3334433433
if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
3334533434
}
3334633435
if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){
3334733436
sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart;
3334833437
sqlite3_int64 len = n;
@@ -33354,11 +33443,11 @@
3335433443
}
3335533444
}
3335633445
if( width>len ){
3335733446
sqlite3_int64 sp = width-len;
3335833447
assert( sp>0 && sp<0x7fffffff );
33359
- sqlite3_str_appendchar(pAccum, (int)sp, ' ');
33448
+ sqlite3StrAppendchar64(pAccum, (int)sp, ' ');
3336033449
if( !flag_leftjustify
3336133450
&& n>0
3336233451
&& sqlite3_str_errcode(pAccum)==0
3336333452
){
3336433453
zz = sqlite3_str_value(pAccum);
@@ -33546,15 +33635,15 @@
3354633635
** indicating that width and precision should be expressed in characters,
3354733636
** then the values have been translated prior to reaching this point.
3354833637
*/
3354933638
width -= length;
3355033639
if( width>0 ){
33551
- if( !flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
33552
- sqlite3_str_append(pAccum, bufpt, length);
33553
- if( flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
33640
+ if( !flag_leftjustify ) sqlite3StrAppendchar64(pAccum, width, ' ');
33641
+ sqlite3StrAppend64(pAccum, bufpt, length);
33642
+ if( flag_leftjustify ) sqlite3StrAppendchar64(pAccum, width, ' ');
3355433643
}else{
33555
- sqlite3_str_append(pAccum, bufpt, length);
33644
+ sqlite3StrAppend64(pAccum, bufpt, length);
3355633645
}
3355733646
3355833647
if( zExtra ){
3355933648
sqlite3DbFree(pAccum->db, zExtra);
3356033649
zExtra = 0;
@@ -33670,10 +33759,17 @@
3367033759
if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
3367133760
return;
3367233761
}
3367333762
while( (N--)>0 ) p->zText[p->nChar++] = c;
3367433763
}
33764
+static void sqlite3StrAppendchar64(sqlite3_str *p, i64 N, char c){
33765
+ testcase( p->nChar + N > 0x7fffffff );
33766
+ if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
33767
+ return;
33768
+ }
33769
+ while( (N--)>0 ) p->zText[p->nChar++] = c;
33770
+}
3367533771
3367633772
/*
3367733773
** The StrAccum "p" is not large enough to accept N new bytes of z[].
3367833774
** So enlarge if first, then do the append.
3367933775
**
@@ -33704,10 +33800,24 @@
3370433800
assert( p->zText );
3370533801
p->nChar += N;
3370633802
memcpy(&p->zText[p->nChar-N], z, N);
3370733803
}
3370833804
}
33805
+static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N){
33806
+ assert( z!=0 || N==0 );
33807
+ assert( p->zText!=0 || p->nChar==0 || p->accError );
33808
+ assert( N>=0 );
33809
+ assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
33810
+ if( p->nChar+N >= (i64)p->nAlloc ){
33811
+ enlargeAndAppend(p,z,N);
33812
+ }else if( N ){
33813
+ assert( p->zText );
33814
+ p->nChar += N;
33815
+ memcpy(&p->zText[p->nChar-N], z, N);
33816
+ }
33817
+}
33818
+
3370933819
3371033820
/*
3371133821
** Append the complete text of zero-terminated string z[] to the p string.
3371233822
*/
3371333823
SQLITE_API void sqlite3_str_appendall(sqlite3_str *p, const char *z){
@@ -33741,41 +33851,15 @@
3374133851
}
3374233852
}
3374333853
return p->zText;
3374433854
}
3374533855
33746
-/*
33747
-** Use the content of the StrAccum passed as the second argument
33748
-** as the result of an SQL function.
33749
-*/
33750
-SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context *pCtx, StrAccum *p){
33751
- if( p->accError ){
33752
- sqlite3_result_error_code(pCtx, p->accError);
33753
- sqlite3_str_reset(p);
33754
- }else if( isMalloced(p) ){
33755
- sqlite3_result_text(pCtx, p->zText, p->nChar, SQLITE_DYNAMIC);
33756
- }else{
33757
- sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
33758
- sqlite3_str_reset(p);
33759
- }
33760
-}
33761
-
33762
-/*
33763
-** This singleton is an sqlite3_str object that is returned if
33764
-** sqlite3_malloc() fails to provide space for a real one. This
33765
-** sqlite3_str object accepts no new text and always returns
33766
-** an SQLITE_NOMEM error.
33767
-*/
33768
-static sqlite3_str sqlite3OomStr = {
33769
- 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
33770
-};
33771
-
3377233856
/* Finalize a string created using sqlite3_str_new().
3377333857
*/
3377433858
SQLITE_API char *sqlite3_str_finish(sqlite3_str *p){
3377533859
char *z;
33776
- if( p!=0 && p!=&sqlite3OomStr ){
33860
+ if( p!=0 && p!=(sqlite3_str*)&sqlite3OomStr ){
3377733861
z = sqlite3StrAccumFinish(p);
3377833862
sqlite3_free(p);
3377933863
}else{
3378033864
z = 0;
3378133865
}
@@ -33812,10 +33896,12 @@
3381233896
*/
3381333897
SQLITE_API void sqlite3_str_reset(StrAccum *p){
3381433898
if( isMalloced(p) ){
3381533899
sqlite3DbFree(p->db, p->zText);
3381633900
p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
33901
+ }else if( p==(sqlite3_str*)&sqlite3OomStr ){
33902
+ return;
3381733903
}
3381833904
p->nAlloc = 0;
3381933905
p->nChar = 0;
3382033906
p->zText = 0;
3382133907
}
@@ -33823,11 +33909,11 @@
3382333909
/*
3382433910
** Destroy a dynamically allocate sqlite3_str object and all
3382533911
** of its content, all in one call.
3382633912
*/
3382733913
SQLITE_API void sqlite3_str_free(sqlite3_str *p){
33828
- if( p!=0 && p!=&sqlite3OomStr ){
33914
+ if( p!=0 && p!=(sqlite3_str*)&sqlite3OomStr ){
3382933915
sqlite3_str_reset(p);
3383033916
sqlite3_free(p);
3383133917
}
3383233918
}
3383333919
@@ -33860,11 +33946,11 @@
3386033946
sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
3386133947
if( p ){
3386233948
sqlite3StrAccumInit(p, 0, 0, 0,
3386333949
db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
3386433950
}else{
33865
- p = &sqlite3OomStr;
33951
+ p = (sqlite3_str*)&sqlite3OomStr;
3386633952
}
3386733953
return p;
3386833954
}
3386933955
3387033956
/*
@@ -37500,11 +37586,11 @@
3750037586
return mState;
3750137587
}
3750237588
}
3750337589
return 0xfffffff0 | mState;
3750437590
#else
37505
- return sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8)==0;
37591
+ return sqlite3Atoi64(zIn, pResult, strlen(zIn), SQLITE_UTF8)==0;
3750637592
#endif /* SQLITE_OMIT_FLOATING_POINT */
3750737593
}
3750837594
3750937595
/*
3751037596
** Digit pairs used to convert a U64 or I64 into text, two digits
@@ -39731,20 +39817,21 @@
3973139817
i = 0;
3973239818
j = 0;
3973339819
while( 1 ){
3973439820
c = kvvfsHexValue[aIn[i]];
3973539821
if( c<0 ){
39736
- int n = 0;
39737
- int mult = 1;
39822
+ sqlite3_int64 n = 0;
39823
+ sqlite3_int64 mult = 1;
3973839824
c = aIn[i];
3973939825
if( c==0 ) break;
3974039826
while( c>='a' && c<='z' ){
3974139827
n += (c - 'a')*mult;
39828
+ if( n>nOut ) return -1 /* oversized/malformed input */;
3974239829
mult *= 26;
3974339830
c = aIn[++i];
3974439831
}
39745
- if( j+n>nOut ) return -1;
39832
+ if( j+n>nOut ) return -1 /* oversized/malformed input */;
3974639833
memset(&aOut[j], 0, n);
3974739834
j += n;
3974839835
if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
3974939836
}else if( j<nOut ){
3975039837
aOut[j] = c<<4;
@@ -39773,22 +39860,28 @@
3977339860
static void kvvfsDecodeJournal(
3977439861
KVVfsFile *pFile, /* Store decoding in pFile->aJrnl */
3977539862
const char *zTxt, /* Text encoding. Zero-terminated */
3977639863
int nTxt /* Bytes in zTxt, excluding zero terminator */
3977739864
){
39778
- unsigned int n = 0;
39779
- int c, i, mult;
39865
+ unsigned int n = 0, mult;
39866
+ int c, i;
3978039867
i = 0;
3978139868
mult = 1;
39782
- while( (c = zTxt[i++])>='a' && c<='z' ){
39783
- n += (zTxt[i] - 'a')*mult;
39869
+ sqlite3_free(pFile->aJrnl);
39870
+ pFile->aJrnl = 0;
39871
+ pFile->nJrnl = 0;
39872
+ while( (c = zTxt[i])>='a' && c<='z' ){
39873
+ n += (c - 'a')*mult;
3978439874
mult *= 26;
39875
+ ++i;
3978539876
}
39786
- sqlite3_free(pFile->aJrnl);
39877
+ if( ' '!=zTxt[i++] ){
39878
+ /* Malformed input */
39879
+ return;
39880
+ }
3978739881
pFile->aJrnl = sqlite3_malloc64( n );
3978839882
if( pFile->aJrnl==0 ){
39789
- pFile->nJrnl = 0;
3979039883
return;
3979139884
}
3979239885
pFile->nJrnl = n;
3979339886
n = kvvfsDecode(zTxt+i, pFile->aJrnl, pFile->nJrnl);
3979439887
if( n<pFile->nJrnl ){
@@ -39824,13 +39917,11 @@
3982439917
3982539918
SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass,
3982639919
pFile->isJournal ? "journal" : "db"));
3982739920
sqlite3_free(pFile->aJrnl);
3982839921
sqlite3_free(pFile->aData);
39829
-#ifdef SQLITE_WASM
3983039922
memset(pFile, 0, sizeof(*pFile));
39831
-#endif
3983239923
return SQLITE_OK;
3983339924
}
3983439925
3983539926
/*
3983639927
** Read from the -journal file.
@@ -39856,10 +39947,11 @@
3985639947
if( aTxt==0 ) return SQLITE_NOMEM;
3985739948
rc = sqlite3KvvfsMethods.xRcrdRead(pFile->zClass, "jrnl",
3985839949
aTxt, szTxt+1);
3985939950
if( rc>=0 ){
3986039951
kvvfsDecodeJournal(pFile, aTxt, szTxt);
39952
+ rc = 0;
3986139953
}
3986239954
sqlite3_free(aTxt);
3986339955
if( rc ) return rc;
3986439956
if( pFile->aJrnl==0 ) return SQLITE_IOERR;
3986539957
}
@@ -40180,11 +40272,11 @@
4018040272
}
4018140273
if( !pFile->zClass ){
4018240274
#ifdef SQLITE_WASM
4018340275
if( strlen(zName) >= (KVRECORD_KEY_SZ
4018440276
- 6 /* "kvvfs-" */
40185
- - 11 /* "-##########" */) ){
40277
+ - 11 /* "-NNNNNNNNNNN" */) ){
4018640278
return SQLITE_CANTOPEN;
4018740279
}
4018840280
#else
4018940281
if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){
4019040282
/* Historical naming restriction which journaling depends on. */
@@ -52221,11 +52313,11 @@
5222152313
# define sqlite3_win_test_unc_locking 0
5222252314
#endif
5222352315
5222452316
/*
5222552317
** Return true if the string passed as the only argument is likely
52226
-** to be a UNC path. Return false if note.
52318
+** to be a UNC path. Return false if not.
5222752319
**
5222852320
** Return true if:
5222952321
**
5223052322
** (1) The name begins with "\\"
5223152323
** (2) But does not begin with "\\?\C:\" where C can be any alphabetic
@@ -55070,26 +55162,27 @@
5507055162
int iDb;
5507155163
Btree *pBt;
5507255164
sqlite3_int64 sz;
5507355165
int szPage = 0;
5507455166
sqlite3_stmt *pStmt = 0;
55075
- unsigned char *pOut;
55167
+ unsigned char *pOut = 0;
5507655168
char *zSql;
5507755169
int rc;
5507855170
5507955171
#ifdef SQLITE_ENABLE_API_ARMOR
5508055172
if( !sqlite3SafetyCheckOk(db) ){
5508155173
(void)SQLITE_MISUSE_BKPT;
5508255174
return 0;
5508355175
}
5508455176
#endif
55177
+ sqlite3_mutex_enter(db->mutex);
5508555178
5508655179
if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
5508755180
p = memdbFromDbSchema(db, zSchema);
5508855181
iDb = sqlite3FindDbName(db, zSchema);
5508955182
if( piSize ) *piSize = -1;
55090
- if( iDb<0 ) return 0;
55183
+ if( iDb<0 ) goto serialize_out;
5509155184
if( p ){
5509255185
MemStore *pStore = p->pStore;
5509355186
assert( pStore->pMutex==0 );
5509455187
if( piSize ) *piSize = pStore->sz;
5509555188
if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
@@ -55096,23 +55189,21 @@
5509655189
pOut = pStore->aData;
5509755190
}else{
5509855191
pOut = sqlite3_malloc64( pStore->sz );
5509955192
if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
5510055193
}
55101
- return pOut;
55194
+ goto serialize_out;
5510255195
}
5510355196
pBt = db->aDb[iDb].pBt;
55104
- if( pBt==0 ) return 0;
55197
+ if( pBt==0 ) goto serialize_out;
5510555198
szPage = sqlite3BtreeGetPageSize(pBt);
5510655199
zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema);
5510755200
rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
5510855201
sqlite3_free(zSql);
55109
- if( rc ) return 0;
55202
+ if( rc ) goto serialize_out;
5511055203
rc = sqlite3_step(pStmt);
55111
- if( rc!=SQLITE_ROW ){
55112
- pOut = 0;
55113
- }else{
55204
+ if( rc==SQLITE_ROW ){
5511455205
sz = sqlite3_column_int64(pStmt, 0)*szPage;
5511555206
if( sz==0 ){
5511655207
sqlite3_reset(pStmt);
5511755208
sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
5511855209
rc = sqlite3_step(pStmt);
@@ -55142,10 +55233,13 @@
5514255233
}
5514355234
}
5514455235
}
5514555236
}
5514655237
sqlite3_finalize(pStmt);
55238
+
55239
+ serialize_out:
55240
+ sqlite3_mutex_leave(db->mutex);
5514755241
return pOut;
5514855242
}
5514955243
5515055244
/* Convert zSchema to a MemDB and initialize its content.
5515155245
*/
@@ -59917,10 +60011,45 @@
5991760011
static void freeSuperJournal(char *zSuper){
5991860012
if( zSuper ){
5991960013
sqlite3_free(&zSuper[-4]);
5992060014
}
5992160015
}
60016
+
60017
+/*
60018
+** Check if zSuper is a valid super-journal name. There are two valid
60019
+** formats:
60020
+**
60021
+** + The 3rd and 4th last bytes of the filename are ".9", and the
60022
+** following 2 bytes are hex digits. This is a file created in 8.3
60023
+** filenames mode.
60024
+**
60025
+** + The 3rd last byte of the filename is "9" and the filename
60026
+** contains the string "-mj" starting at the 12th last byte.
60027
+** All bytes following the "-mj" are hex digits.
60028
+**
60029
+** If the filename matches either of these patterns, return non-zero.
60030
+** Otherwise, return zero.
60031
+*/
60032
+static int pagerIsSuperJrnlName(const char *zSuper){
60033
+ const int nSuper = sqlite3Strlen30(zSuper);
60034
+ int ii;
60035
+
60036
+#ifdef SQLITE_ENABLE_8_3_NAMES
60037
+ if( nSuper<4 ) return 0;
60038
+ if( zSuper[nSuper-3]!='9' ) return 0;
60039
+ if( sqlite3Isxdigit(zSuper[nSuper-2])==0 ) return 0;
60040
+ if( sqlite3Isxdigit(zSuper[nSuper-1])==0 ) return 0;
60041
+ if( zSuper[nSuper-4]=='.' ) return 1;
60042
+#endif
60043
+ if( nSuper<12 ) return 0;
60044
+ if( memcmp(&zSuper[nSuper-12], "-mj", 3) ) return 0;
60045
+ if( zSuper[nSuper-3]!='9' ) return 0;
60046
+ for(ii=nSuper-9; ii<nSuper; ii++){
60047
+ if( sqlite3Isxdigit(zSuper[ii])==0 ) return 0;
60048
+ }
60049
+ return 1;
60050
+}
5992260051
5992360052
/*
5992460053
** Parameter pJrnl is a file-handle open on a journal file. This function
5992560054
** attempts to read a super-journal file name from the end of the journal
5992660055
** file. If successful, it sets output parameter (*pzSuper) to point to a
@@ -59955,32 +60084,34 @@
5995560084
|| len>=nSuper
5995660085
|| len>szJ-16
5995760086
|| len==0
5995860087
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
5995960088
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
59960
- || memcmp(aMagic, aJournalMagic, 8)
5996160089
){
5996260090
return rc;
5996360091
}
5996460092
5996560093
zOut = (char*)sqlite3MallocZero(4 + len + 2);
5996660094
if( !zOut ){
59967
- rc = SQLITE_NOMEM_BKPT;
60095
+ rc = memcmp(aMagic,aJournalMagic,8) ? SQLITE_OK : SQLITE_NOMEM_BKPT;
5996860096
}else{
5996960097
zOut = &zOut[4];
5997060098
if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){
5997160099
u32 u; /* Unsigned loop counter */
5997260100
/* See if the checksum matches the super-journal name */
5997360101
for(u=0; u<len; u++){
5997460102
cksum -= zOut[u];
5997560103
}
5997660104
}
59977
- if( rc!=SQLITE_OK || cksum ){
59978
- /* If the checksum doesn't add up, then one or more of the disk sectors
59979
- ** containing the super-journal filename is corrupted. This means
59980
- ** definitely roll back, so just return SQLITE_OK and report a (nul)
59981
- ** super-journal filename. */
60105
+ if( rc!=SQLITE_OK /* Couldn't read the name */
60106
+ || !pagerIsSuperJrnlName(zOut) /* Name is not valid */
60107
+ || cksum /* checksum is incorrect */
60108
+ || memcmp(aMagic, aJournalMagic, 8)!=0 /* Bad magic number */
60109
+ ){
60110
+ /* If any validity checks fail, that means the super-journal filename
60111
+ ** is corrupted, so rollback. Return SQLITE_K and a NULL super-journal
60112
+ ** name */
5998260113
freeSuperJournal(zOut);
5998360114
zOut = 0;
5998460115
}
5998560116
}
5998660117
@@ -60359,10 +60490,11 @@
6035960490
i64 jrnlSize; /* Size of journal file on disk */
6036060491
u32 cksum = 0; /* Checksum of string zSuper */
6036160492
6036260493
assert( pPager->setSuper==0 );
6036360494
assert( !pagerUseWal(pPager) );
60495
+ assert( zSuper==0 || pagerIsSuperJrnlName(zSuper) );
6036460496
6036560497
if( !zSuper
6036660498
|| pPager->journalMode==PAGER_JOURNALMODE_MEMORY
6036760499
|| !isOpen(pPager->jfd)
6036860500
){
@@ -61189,10 +61321,23 @@
6118961321
sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
6119061322
char *zSuperJournal = 0; /* Contents of super-journal file */
6119161323
i64 nSuperJournal; /* Size of super-journal file */
6119261324
char *zJournal; /* Pointer to one journal within MJ file */
6119361325
char *zFree = 0; /* Free this buffer */
61326
+ int bSeen = 0; /* If super-journal contains pPager->zJournal */
61327
+
61328
+ /* Check if this looks like a real super-journal name. If it does not,
61329
+ ** return SQLITE_OK without attempting to delete it. This is to limit
61330
+ ** the degree to which a crafted journal file can be used to cause
61331
+ ** SQLite to delete arbitrary files.
61332
+ **
61333
+ ** This test never fails, becaue the super journal name is checked
61334
+ ** by readSuperJournal().
61335
+ */
61336
+ if( NEVER(pagerIsSuperJrnlName(zSuper)==0) ){
61337
+ return SQLITE_OK;
61338
+ }
6119461339
6119561340
/* Allocate space for both the pJournal and pSuper file descriptors.
6119661341
** If successful, open the super-journal file for reading.
6119761342
*/
6119861343
pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61228,51 +61373,60 @@
6122861373
zSuperJournal[nSuperJournal] = 0;
6122961374
zSuperJournal[nSuperJournal+1] = 0;
6123061375
6123161376
zJournal = zSuperJournal;
6123261377
while( (zJournal-zSuperJournal)<nSuperJournal ){
61233
- int exists;
61234
- rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61235
- if( rc!=SQLITE_OK ){
61236
- goto delsuper_out;
61237
- }
61238
- if( exists ){
61239
- char *zSuperPtr = 0;
61240
-
61241
- /* One of the journals pointed to by the super-journal exists.
61242
- ** Open it and check if it points at the super-journal. If
61243
- ** so, return without deleting the super-journal file.
61244
- ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61245
- ** SUPER_JOURNAL here so that the VFS will not send the zJournal
61246
- ** name into sqlite3_database_file_object().
61247
- */
61248
- int c;
61249
- int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
61250
- rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61251
- if( rc!=SQLITE_OK ){
61252
- goto delsuper_out;
61253
- }
61254
-
61255
- rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
61256
- sqlite3OsClose(pJournal);
61257
- if( rc!=SQLITE_OK ){
61258
- assert( zSuperPtr==0 );
61259
- goto delsuper_out;
61260
- }
61261
-
61262
- c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61263
- freeSuperJournal(zSuperPtr);
61264
- if( c ){
61265
- /* We have a match. Do not delete the super-journal file. */
61266
- goto delsuper_out;
61378
+ if( strcmp(zJournal, pPager->zJournal)==0 ){
61379
+ bSeen = 1;
61380
+ }else{
61381
+ int exists;
61382
+ rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61383
+ if( rc!=SQLITE_OK ){
61384
+ goto delsuper_out;
61385
+ }
61386
+ if( exists ){
61387
+ char *zSuperPtr = 0;
61388
+
61389
+ /* One of the journals pointed to by the super-journal exists.
61390
+ ** Open it and check if it points at the super-journal. If
61391
+ ** so, return without deleting the super-journal file.
61392
+ ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61393
+ ** SUPER_JOURNAL here so that the VFS will not send the zJournal
61394
+ ** name into sqlite3_database_file_object().
61395
+ */
61396
+ int c;
61397
+ int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
61398
+ rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61399
+ if( rc!=SQLITE_OK ){
61400
+ goto delsuper_out;
61401
+ }
61402
+
61403
+ rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
61404
+ sqlite3OsClose(pJournal);
61405
+ if( rc!=SQLITE_OK ){
61406
+ assert( zSuperPtr==0 );
61407
+ goto delsuper_out;
61408
+ }
61409
+
61410
+ c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61411
+ freeSuperJournal(zSuperPtr);
61412
+ if( c ){
61413
+ /* We have a match. Do not delete the super-journal file. */
61414
+ goto delsuper_out;
61415
+ }
6126761416
}
6126861417
}
6126961418
zJournal += (sqlite3Strlen30(zJournal)+1);
6127061419
}
6127161420
6127261421
sqlite3OsClose(pSuper);
61273
- rc = sqlite3OsDelete(pVfs, zSuper, 0);
61422
+ if( bSeen ){
61423
+ /* Only delete the super-journal if bSeen is true - indicating that
61424
+ ** the super-journal contained a pointer to this database's journal
61425
+ ** file. */
61426
+ rc = sqlite3OsDelete(pVfs, zSuper, 0);
61427
+ }
6127461428
6127561429
delsuper_out:
6127661430
sqlite3_free(zFree);
6127761431
if( pSuper ){
6127861432
sqlite3OsClose(pSuper);
@@ -71674,10 +71828,13 @@
7167471828
int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
7167571829
** Error code if eState==CURSOR_FAULT */
7167671830
Btree *pBtree; /* The Btree to which this cursor belongs */
7167771831
Pgno *aOverflow; /* Cache of overflow page locations */
7167871832
void *pKey; /* Saved key that was cursor last known position */
71833
+#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
71834
+ BtCursor *pCursorHintTableCursor;
71835
+#endif
7167971836
/* All fields above are zeroed when the cursor is allocated. See
7168071837
** sqlite3BtreeCursorZero(). Fields that follow must be manually
7168171838
** initialized. */
7168271839
#define BTCURSOR_FIRST_UNINIT pBt /* Name of first uninitialized field */
7168371840
BtShared *pBt; /* The BtShared this cursor points to */
@@ -71850,10 +72007,13 @@
7185072007
int v2; /* Value for third %d substitution in zPfx */
7185172008
StrAccum errMsg; /* Accumulate the error message text here */
7185272009
u32 *heap; /* Min-heap used for analyzing cell coverage */
7185372010
sqlite3 *db; /* Database connection running the check */
7185472011
i64 nRow; /* Number of rows visited in current tree */
72012
+#ifdef SQLITE_DEBUG
72013
+ u32 mxHeap; /* Maximum number of entries in the Min-heap */
72014
+#endif
7185572015
};
7185672016
7185772017
/*
7185872018
** Routines to read or write a two- and four-byte big-endian integer values.
7185972019
*/
@@ -73178,28 +73338,45 @@
7317873338
** parameter. See the definitions of the BTREE_HINT_* macros for details.
7317973339
*/
7318073340
SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){
7318173341
/* Used only by system that substitute their own storage engine */
7318273342
#ifdef SQLITE_DEBUG
73183
- if( ALWAYS(eHintType==BTREE_HINT_RANGE) ){
73184
- va_list ap;
73343
+ va_list ap;
73344
+ va_start(ap, eHintType);
73345
+ if( eHintType==BTREE_HINT_RANGE ){
7318573346
Expr *pExpr;
7318673347
Walker w;
7318773348
memset(&w, 0, sizeof(w));
7318873349
w.xExprCallback = sqlite3CursorRangeHintExprCheck;
73189
- va_start(ap, eHintType);
7319073350
pExpr = va_arg(ap, Expr*);
7319173351
w.u.aMem = va_arg(ap, Mem*);
73192
- va_end(ap);
7319373352
assert( pExpr!=0 );
7319473353
assert( w.u.aMem!=0 );
7319573354
sqlite3WalkExpr(&w, pExpr);
73355
+ }else if( ALWAYS(eHintType==BTREE_HINT_TABLECURSOR) ){
73356
+ BtCursor *pCsr = va_arg(ap, BtCursor*);
73357
+ assert( pCur->pCursorHintTableCursor==0
73358
+ || pCur->pCursorHintTableCursor==pCsr
73359
+ );
73360
+ assert( pCsr->pKeyInfo==0 || CORRUPT_DB );
73361
+ pCur->pCursorHintTableCursor = pCsr;
7319673362
}
73363
+ va_end(ap);
7319773364
#endif /* SQLITE_DEBUG */
7319873365
}
7319973366
#endif /* SQLITE_ENABLE_CURSOR_HINTS */
7320073367
73368
+#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
73369
+/*
73370
+** Return the pointer configured via the BTREE_HINT_TABLECURSOR hint on
73371
+** cursor pCsr. This is used from OP_DeferredSeek to assert() that the
73372
+** index cursor has been correctly configured with the table cursor.
73373
+*/
73374
+SQLITE_PRIVATE BtCursor *sqlite3BtreeCursorHintTblCsr(BtCursor *pCsr){
73375
+ return pCsr->pCursorHintTableCursor;
73376
+}
73377
+#endif
7320173378
7320273379
/*
7320373380
** Provide flag hints to the cursor.
7320473381
*/
7320573382
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){
@@ -74321,12 +74498,16 @@
7432174498
/* Freeblock off the end of the page */
7432274499
return SQLITE_CORRUPT_PAGE(pPage);
7432374500
}
7432474501
next = get2byte(&data[pc]);
7432574502
size = get2byte(&data[pc+2]);
74503
+ if( size<4 ){
74504
+ /* Minimum freeblock size is 4 */
74505
+ return SQLITE_CORRUPT_PAGE(pPage);
74506
+ }
7432674507
nFree = nFree + size;
74327
- if( next<=pc+size+3 ) break;
74508
+ if( next<pc+size+4 ) break;
7432874509
pc = next;
7432974510
}
7433074511
if( next>0 ){
7433174512
/* Freeblock not in ascending order */
7433274513
return SQLITE_CORRUPT_PAGE(pPage);
@@ -78157,18 +78338,18 @@
7815778338
nCell = pCell[0];
7815878339
if( nCell<=pPage->max1bytePayload ){
7815978340
/* This branch runs if the record-size field of the cell is a
7816078341
** single byte varint and the record fits entirely on the main
7816178342
** b-tree page. */
78162
- testcase( pCell+nCell+1==pPage->aDataEnd );
78343
+ if( pCell + nCell >= pPage->aDataEnd ) return 99;
7816378344
c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
7816478345
}else if( !(pCell[1] & 0x80)
7816578346
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
7816678347
){
7816778348
/* The record-size field is a 2 byte varint and the record
7816878349
** fits entirely on the main b-tree page. */
78169
- testcase( pCell+nCell+2==pPage->aDataEnd );
78350
+ if( pCell + nCell >= pPage->aDataEnd ) return 99;
7817078351
c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
7817178352
}else{
7817278353
/* If the record extends into overflow pages, do not attempt
7817378354
** the optimization. */
7817478355
c = 99;
@@ -78326,18 +78507,21 @@
7832678507
nCell = pCell[0];
7832778508
if( nCell<=pPage->max1bytePayload ){
7832878509
/* This branch runs if the record-size field of the cell is a
7832978510
** single byte varint and the record fits entirely on the main
7833078511
** b-tree page. */
78331
- testcase( pCell+nCell+1==pPage->aDataEnd );
78512
+ if( pCell + nCell >= pPage->aDataEnd ){
78513
+ rc = SQLITE_CORRUPT_PAGE(pPage);
78514
+ goto moveto_index_finish;
78515
+ }
7833278516
c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
7833378517
}else if( !(pCell[1] & 0x80)
7833478518
&& (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
78519
+ && pCell + nCell < pPage->aDataEnd
7833578520
){
7833678521
/* The record-size field is a 2 byte varint and the record
7833778522
** fits entirely on the main b-tree page. */
78338
- testcase( pCell+nCell+2==pPage->aDataEnd );
7833978523
c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
7834078524
}else{
7834178525
/* The record flows over onto one or more overflow pages. In
7834278526
** this case the whole cell needs to be parsed, a buffer allocated
7834378527
** and accessPayload() used to retrieve the record into the
@@ -83203,10 +83387,11 @@
8320383387
checkAppendMsg(pCheck, "Child page depth differs");
8320483388
depth = d2;
8320583389
}
8320683390
}else{
8320783391
/* Populate the coverage-checking heap for leaf pages */
83392
+ assert( heap[0] < pCheck->mxHeap );
8320883393
btreeHeapInsert(heap, (pc<<16)|(pc+info.nSize-1));
8320983394
}
8321083395
}
8321183396
*piMinKey = maxKey;
8321283397
@@ -83222,10 +83407,11 @@
8322283407
heap[0] = 0;
8322383408
for(i=nCell-1; i>=0; i--){
8322483409
u32 size;
8322583410
pc = get2byteAligned(&data[cellStart+i*2]);
8322683411
size = pPage->xCellSize(pPage, &data[pc]);
83412
+ assert( heap[0] < pCheck->mxHeap );
8322783413
btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
8322883414
}
8322983415
}
8323083416
assert( heap!=0 );
8323183417
/* Add the freeblocks to the min-heap
@@ -83238,10 +83424,11 @@
8323883424
while( i>0 ){
8323983425
int size, j;
8324083426
assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
8324183427
size = get2byte(&data[i+2]);
8324283428
assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
83429
+ assert( heap[0] < pCheck->mxHeap );
8324383430
btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
8324483431
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
8324583432
** big-endian integer which is the offset in the b-tree page of the next
8324683433
** freeblock in the chain, or zero if the freeblock is the last on the
8324783434
** chain. */
@@ -83372,10 +83559,13 @@
8337283559
if( !sCheck.aPgRef ){
8337383560
checkOom(&sCheck);
8337483561
goto integrity_ck_cleanup;
8337583562
}
8337683563
sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
83564
+#ifdef SQLITE_DEBUG
83565
+ sCheck.mxHeap = pBt->pageSize/4 - 1;
83566
+#endif
8337783567
if( sCheck.heap==0 ){
8337883568
checkOom(&sCheck);
8337983569
goto integrity_ck_cleanup;
8338083570
}
8338183571
@@ -83796,17 +83986,18 @@
8379683986
/*
8379783987
** Structure allocated for each backup operation.
8379883988
*/
8379983989
struct sqlite3_backup {
8380083990
sqlite3* pDestDb; /* Destination database handle */
83801
- Db *pDest; /* Destination db file */
83991
+ char *zDestDb;
83992
+ Btree *pDest; /* Destination b-tree file */
8380283993
u32 iDestSchema; /* Original schema cookie in destination */
8380383994
int bDestLocked; /* True once a write-transaction is open on pDest */
8380483995
8380583996
Pgno iNext; /* Page number of the next source page to copy */
8380683997
sqlite3* pSrcDb; /* Source database handle */
83807
- Db *pSrc; /* Source db file */
83998
+ Btree *pSrc; /* Source b-tree file */
8380883999
8380984000
int rc; /* Backup process error code */
8381084001
8381184002
/* These two variables are set by every call to backup_step(). They are
8381284003
** read by calls to backup_remaining() and backup_pagecount().
@@ -83855,11 +84046,11 @@
8385584046
**
8385684047
** If the "temp" database is requested, it may need to be opened by this
8385784048
** function. If an error occurs while doing so, return 0 and write an
8385884049
** error message to pErrorDb.
8385984050
*/
83860
-static Db *findDatabase(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
84051
+static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
8386184052
int i = sqlite3FindDbName(pDb, zDb);
8386284053
8386384054
if( i==1 ){
8386484055
Parse sParse;
8386584056
int rc = 0;
@@ -83878,21 +84069,19 @@
8387884069
if( i<0 ){
8387984070
sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
8388084071
return 0;
8388184072
}
8388284073
83883
- return &pDb->aDb[i];
84074
+ return pDb->aDb[i].pBt;
8388484075
}
8388584076
8388684077
/*
8388784078
** Attempt to set the page size of the destination to match the page size
8388884079
** of the source.
8388984080
*/
83890
-static int setDestPgsz(sqlite3_backup *p){
83891
- return sqlite3BtreeSetPageSize(p->pDest->pBt,
83892
- sqlite3BtreeGetPageSize(p->pSrc->pBt), 0, 0
83893
- );
84081
+static int setDestPgsz(Btree *pDest, Btree *pSrc){
84082
+ return sqlite3BtreeSetPageSize(pDest, sqlite3BtreeGetPageSize(pSrc), 0, 0);
8389484083
}
8389584084
8389684085
/*
8389784086
** Check that there is no open read-transaction on the b-tree passed as the
8389884087
** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -83945,31 +84134,41 @@
8394584134
sqlite3ErrorWithMsg(
8394684135
pDestDb, SQLITE_ERROR, "source and destination must be distinct"
8394784136
);
8394884137
p = 0;
8394984138
}else {
84139
+ int nDest = sqlite3Strlen30(zDestDb);
84140
+
8395084141
/* Allocate space for a new sqlite3_backup object...
8395184142
** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
8395284143
** call to sqlite3_backup_init() and is destroyed by a call to
8395384144
** sqlite3_backup_finish(). */
83954
- p = (sqlite3_backup *)sqlite3MallocZero(sizeof(sqlite3_backup));
84145
+ p = (sqlite3_backup*)sqlite3MallocZero(sizeof(sqlite3_backup)+nDest+1);
8395584146
if( !p ){
8395684147
sqlite3Error(pDestDb, SQLITE_NOMEM_BKPT);
84148
+ }else{
84149
+ p->zDestDb = (char*)&p[1];
84150
+ memcpy(p->zDestDb, zDestDb, nDest);
8395784151
}
8395884152
}
8395984153
8396084154
/* If the allocation succeeded, populate the new object. */
8396184155
if( p ){
83962
- p->pSrc = findDatabase(pDestDb, pSrcDb, zSrcDb);
83963
- p->pDest = findDatabase(pDestDb, pDestDb, zDestDb);
84156
+ /* Do not store the pointer to the destination b-tree at this point.
84157
+ ** This is because there is nothing preventing it from being detached
84158
+ ** or otherwise freed before the first call to sqlite3_backup_step()
84159
+ ** on this object. The source b-tree does not have this problem, as
84160
+ ** incrementing Btree.nBackup (see below) effectively locks the object. */
84161
+ Btree *pDest = findBtree(pDestDb, pDestDb, zDestDb);
84162
+ p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
8396484163
p->pDestDb = pDestDb;
8396584164
p->pSrcDb = pSrcDb;
8396684165
p->iNext = 1;
8396784166
p->isAttached = 0;
8396884167
83969
- if( 0==p->pSrc || 0==p->pDest
83970
- || checkReadTransaction(pDestDb, p->pDest->pBt)!=SQLITE_OK
84168
+ if( 0==p->pSrc || 0==pDest
84169
+ || checkReadTransaction(pDestDb, pDest)!=SQLITE_OK
8397184170
){
8397284171
/* One (or both) of the named databases did not exist or an OOM
8397384172
** error was hit. Or there is a transaction open on the destination
8397484173
** database. The error has already been written into the pDestDb
8397584174
** handle. All that is left to do here is free the sqlite3_backup
@@ -83977,11 +84176,11 @@
8397784176
sqlite3_free(p);
8397884177
p = 0;
8397984178
}
8398084179
}
8398184180
if( p ){
83982
- p->pSrc->pBt->nBackup++;
84181
+ p->pSrc->nBackup++;
8398384182
}
8398484183
8398584184
sqlite3_mutex_leave(pDestDb->mutex);
8398684185
sqlite3_mutex_leave(pSrcDb->mutex);
8398784186
return p;
@@ -84005,22 +84204,22 @@
8400584204
sqlite3_backup *p, /* Backup handle */
8400684205
Pgno iSrcPg, /* Source database page to backup */
8400784206
const u8 *zSrcData, /* Source database page data */
8400884207
int bUpdate /* True for an update, false otherwise */
8400984208
){
84010
- Pager * const pDestPager = sqlite3BtreePager(p->pDest->pBt);
84011
- const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc->pBt);
84012
- int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest->pBt);
84209
+ Pager * const pDestPager = sqlite3BtreePager(p->pDest);
84210
+ const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
84211
+ int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
8401384212
const int nCopy = MIN(nSrcPgsz, nDestPgsz);
8401484213
const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
8401584214
int rc = SQLITE_OK;
8401684215
i64 iOff;
8401784216
84018
- assert( sqlite3BtreeGetReserveNoMutex(p->pSrc->pBt)>=0 );
84217
+ assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
8401984218
assert( p->bDestLocked );
8402084219
assert( !isFatalError(p->rc) );
84021
- assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt->pBt) );
84220
+ assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
8402284221
assert( zSrcData );
8402384222
assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
8402484223
8402584224
/* This loop runs once for each destination page spanned by the source
8402684225
** page. For each iteration, variable iOff is set to the byte offset
@@ -84027,11 +84226,11 @@
8402784226
** of the destination page.
8402884227
*/
8402984228
for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
8403084229
DbPage *pDestPg = 0;
8403184230
Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
84032
- if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt->pBt) ) continue;
84231
+ if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
8403384232
if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
8403484233
&& SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
8403584234
){
8403684235
const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
8403784236
u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -84045,11 +84244,11 @@
8404584244
** "MUST BE FIRST" for this purpose.
8404684245
*/
8404784246
memcpy(zOut, zIn, nCopy);
8404884247
((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
8404984248
if( iOff==0 && bUpdate==0 ){
84050
- sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc->pBt));
84249
+ sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc));
8405184250
}
8405284251
}
8405384252
sqlite3PagerUnref(pDestPg);
8405484253
}
8405584254
@@ -84077,12 +84276,12 @@
8407784276
** Register this backup object with the associated source pager for
8407884277
** callbacks when pages are changed or the cache invalidated.
8407984278
*/
8408084279
static void attachBackupObject(sqlite3_backup *p){
8408184280
sqlite3_backup **pp;
84082
- assert( sqlite3BtreeHoldsMutex(p->pSrc->pBt) );
84083
- pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
84281
+ assert( sqlite3BtreeHoldsMutex(p->pSrc) );
84282
+ pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
8408484283
p->pNext = *pp;
8408584284
*pp = p;
8408684285
p->isAttached = 1;
8408784286
}
8408884287
@@ -84089,93 +84288,103 @@
8408984288
/*
8409084289
** Copy nPage pages from the source b-tree to the destination.
8409184290
*/
8409284291
SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
8409384292
int rc;
84094
- int destMode; /* Destination journal mode */
84293
+ int destMode = 0; /* Destination journal mode */
8409584294
int pgszSrc = 0; /* Source page size */
8409684295
int pgszDest = 0; /* Destination page size */
84097
- Btree *pDest;
84098
- Btree *pSrc;
8409984296
8410084297
#ifdef SQLITE_ENABLE_API_ARMOR
8410184298
if( p==0 ) return SQLITE_MISUSE_BKPT;
8410284299
#endif
84103
- assert( p->pDest );
84104
- assert( p->pSrc );
84105
- pDest = p->pDest->pBt;
84106
- pSrc = p->pSrc->pBt;
8410784300
sqlite3_mutex_enter(p->pSrcDb->mutex);
84108
- sqlite3BtreeEnter(pSrc);
84301
+ sqlite3BtreeEnter(p->pSrc);
8410984302
if( p->pDestDb ){
8411084303
sqlite3_mutex_enter(p->pDestDb->mutex);
8411184304
}
8411284305
8411384306
rc = p->rc;
8411484307
if( !isFatalError(rc) ){
84115
- Pager * const pSrcPager = sqlite3BtreePager(pSrc); /* Source pager */
84116
- Pager * const pDestPager = sqlite3BtreePager(pDest); /* Dest pager */
84308
+ Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */
84309
+ Btree * pDest = 0; /* Dest btree */
84310
+ Pager * pDestPager = 0; /* Dest pager */
8411784311
int ii; /* Iterator variable */
8411884312
int nSrcPage = -1; /* Size of source db in pages */
8411984313
int bCloseTrans = 0; /* True if src db requires unlocking */
8412084314
8412184315
/* If the source pager is currently in a write-transaction, return
8412284316
** SQLITE_BUSY immediately.
8412384317
*/
84124
- if( p->pDestDb && pSrc->pBt->inTransaction==TRANS_WRITE ){
84318
+ if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
8412584319
rc = SQLITE_BUSY;
8412684320
}else{
8412784321
rc = SQLITE_OK;
8412884322
}
84323
+
8412984324
8413084325
/* If there is no open read-transaction on the source database, open
8413184326
** one now. If a transaction is opened here, then it will be closed
8413284327
** before this function exits.
8413384328
*/
84134
- if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(pSrc) ){
84135
- rc = sqlite3BtreeBeginTrans(pSrc, 0, 0);
84329
+ if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
84330
+ rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
8413684331
bCloseTrans = 1;
8413784332
}
84333
+
84334
+ /* Locate the destination btree and pager. */
84335
+ if( (pDest = p->pDest)==0 ){
84336
+ pDest = findBtree(p->pDestDb, p->pDestDb, p->zDestDb);
84337
+ }
84338
+ if( pDest==0 ){
84339
+ rc = SQLITE_ERROR;
84340
+ }else{
84341
+ pDestPager = sqlite3BtreePager(pDest);
84342
+ }
8413884343
8413984344
/* If the destination database has not yet been locked (i.e. if this
8414084345
** is the first call to backup_step() for the current backup operation),
8414184346
** try to set its page size to the same as the source database. This
8414284347
** is especially important on ZipVFS systems, as in that case it is
8414384348
** not possible to create a database file that uses one page size by
8414484349
** writing to it with another. */
84145
- if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
84350
+ if( p->bDestLocked==0 && rc==SQLITE_OK
84351
+ && setDestPgsz(pDest, p->pSrc)==SQLITE_NOMEM
84352
+ ){
8414684353
rc = SQLITE_NOMEM;
8414784354
}
8414884355
8414984356
/* Lock the destination database, if it is not locked already. */
8415084357
if( SQLITE_OK==rc && p->bDestLocked==0
8415184358
&& SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2,
8415284359
(int*)&p->iDestSchema))
8415384360
){
8415484361
p->bDestLocked = 1;
84362
+ p->pDest = pDest;
8415584363
}
8415684364
8415784365
/* Do not allow backup if the destination database is in WAL mode
8415884366
** and the page sizes are different between source and destination */
84159
- pgszSrc = sqlite3BtreeGetPageSize(pSrc);
84160
- pgszDest = sqlite3BtreeGetPageSize(pDest);
84161
- destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(pDest));
84162
- if( SQLITE_OK==rc
84163
- && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
84164
- && pgszSrc!=pgszDest
84165
- ){
84166
- rc = SQLITE_READONLY;
84367
+ if( rc==SQLITE_OK ){
84368
+ pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
84369
+ pgszDest = sqlite3BtreeGetPageSize(p->pDest);
84370
+ destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
84371
+ if( (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
84372
+ && pgszSrc!=pgszDest
84373
+ ){
84374
+ rc = SQLITE_READONLY;
84375
+ }
8416784376
}
8416884377
8416984378
/* Now that there is a read-lock on the source database, query the
8417084379
** source pager for the number of pages in the database.
8417184380
*/
84172
- nSrcPage = (int)sqlite3BtreeLastPage(pSrc);
84381
+ nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
8417384382
assert( nSrcPage>=0 );
8417484383
for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
8417584384
const Pgno iSrcPg = p->iNext; /* Source page number */
84176
- if( iSrcPg!=PENDING_BYTE_PAGE(pSrc->pBt) ){
84385
+ if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
8417784386
DbPage *pSrcPg; /* Source page object */
8417884387
rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
8417984388
if( rc==SQLITE_OK ){
8418084389
rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
8418184390
sqlite3PagerUnref(pSrcPg);
@@ -84198,22 +84407,22 @@
8419884407
** the case where the source and destination databases have the
8419984408
** same schema version.
8420084409
*/
8420184410
if( rc==SQLITE_DONE ){
8420284411
if( nSrcPage==0 ){
84203
- rc = sqlite3BtreeNewDb(pDest);
84412
+ rc = sqlite3BtreeNewDb(p->pDest);
8420484413
nSrcPage = 1;
8420584414
}
8420684415
if( rc==SQLITE_OK || rc==SQLITE_DONE ){
84207
- rc = sqlite3BtreeUpdateMeta(pDest,1,p->iDestSchema+1);
84416
+ rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
8420884417
}
8420984418
if( rc==SQLITE_OK ){
8421084419
if( p->pDestDb ){
8421184420
sqlite3ResetAllSchemasOfConnection(p->pDestDb);
8421284421
}
8421384422
if( destMode==PAGER_JOURNALMODE_WAL ){
84214
- rc = sqlite3BtreeSetVersion(pDest, 2);
84423
+ rc = sqlite3BtreeSetVersion(p->pDest, 2);
8421584424
}
8421684425
}
8421784426
if( rc==SQLITE_OK ){
8421884427
int nDestTruncate;
8421984428
/* Set nDestTruncate to the final number of pages in the destination
@@ -84226,16 +84435,16 @@
8422684435
** sqlite3PagerTruncateImage() here so that any pages in the
8422784436
** destination file that lie beyond the nDestTruncate page mark are
8422884437
** journalled by PagerCommitPhaseOne() before they are destroyed
8422984438
** by the file truncation.
8423084439
*/
84231
- assert( pgszSrc==sqlite3BtreeGetPageSize(pSrc) );
84232
- assert( pgszDest==sqlite3BtreeGetPageSize(pDest) );
84440
+ assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
84441
+ assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
8423384442
if( pgszSrc<pgszDest ){
8423484443
int ratio = pgszDest/pgszSrc;
8423584444
nDestTruncate = (nSrcPage+ratio-1)/ratio;
84236
- if( nDestTruncate==(int)PENDING_BYTE_PAGE(pDest->pBt) ){
84445
+ if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
8423784446
nDestTruncate--;
8423884447
}
8423984448
}else{
8424084449
nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
8424184450
}
@@ -84259,11 +84468,11 @@
8425984468
i64 iEnd;
8426084469
8426184470
assert( pFile );
8426284471
assert( nDestTruncate==0
8426384472
|| (i64)nDestTruncate*(i64)pgszDest >= iSize || (
84264
- nDestTruncate==(int)(PENDING_BYTE_PAGE(pDest->pBt)-1)
84473
+ nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
8426584474
&& iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
8426684475
));
8426784476
8426884477
/* This block ensures that all data required to recreate the original
8426984478
** database has been stored in the journal for pDestPager and the
@@ -84271,11 +84480,11 @@
8427184480
** the database file in any way, knowing that if a power failure
8427284481
** occurs, the original database will be reconstructed from the
8427384482
** journal file. */
8427484483
sqlite3PagerPagecount(pDestPager, &nDstPage);
8427584484
for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
84276
- if( iPg!=PENDING_BYTE_PAGE(pDest->pBt) ){
84485
+ if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
8427784486
DbPage *pPg;
8427884487
rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
8427984488
if( rc==SQLITE_OK ){
8428084489
rc = sqlite3PagerWrite(pPg);
8428184490
sqlite3PagerUnref(pPg);
@@ -84315,11 +84524,11 @@
8431584524
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
8431684525
}
8431784526
8431884527
/* Finish committing the transaction to the destination database. */
8431984528
if( SQLITE_OK==rc
84320
- && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(pDest, 0))
84529
+ && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
8432184530
){
8432284531
rc = SQLITE_DONE;
8432384532
}
8432484533
}
8432584534
}
@@ -84329,12 +84538,12 @@
8432984538
** no need to check the return values of the btree methods here, as
8433084539
** "committing" a read-only transaction cannot fail.
8433184540
*/
8433284541
if( bCloseTrans ){
8433384542
TESTONLY( int rc2 );
84334
- TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(pSrc, 0);
84335
- TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(pSrc, 0);
84543
+ TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
84544
+ TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
8433684545
assert( rc2==SQLITE_OK );
8433784546
}
8433884547
8433984548
if( rc==SQLITE_IOERR_NOMEM ){
8434084549
rc = SQLITE_NOMEM_BKPT;
@@ -84342,11 +84551,11 @@
8434284551
p->rc = rc;
8434384552
}
8434484553
if( p->pDestDb ){
8434584554
sqlite3_mutex_leave(p->pDestDb->mutex);
8434684555
}
84347
- sqlite3BtreeLeave(pSrc);
84556
+ sqlite3BtreeLeave(p->pSrc);
8434884557
sqlite3_mutex_leave(p->pSrcDb->mutex);
8434984558
return rc;
8435084559
}
8435184560
8435284561
/*
@@ -84359,41 +84568,43 @@
8435984568
8436084569
/* Enter the mutexes */
8436184570
if( p==0 ) return SQLITE_OK;
8436284571
pSrcDb = p->pSrcDb;
8436384572
sqlite3_mutex_enter(pSrcDb->mutex);
84364
- sqlite3BtreeEnter(p->pSrc->pBt);
84573
+ sqlite3BtreeEnter(p->pSrc);
8436584574
if( p->pDestDb ){
8436684575
sqlite3_mutex_enter(p->pDestDb->mutex);
8436784576
}
8436884577
8436984578
/* Detach this backup from the source pager. */
8437084579
if( p->pDestDb ){
84371
- p->pSrc->pBt->nBackup--;
84580
+ p->pSrc->nBackup--;
8437284581
}
8437384582
if( p->isAttached ){
84374
- pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
84583
+ pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
8437584584
assert( pp!=0 );
8437684585
while( *pp!=p ){
8437784586
pp = &(*pp)->pNext;
8437884587
assert( pp!=0 );
8437984588
}
8438084589
*pp = p->pNext;
8438184590
}
8438284591
8438384592
/* If a transaction is still open on the Btree, roll it back. */
84384
- sqlite3BtreeRollback(p->pDest->pBt, SQLITE_OK, 0);
84593
+ if( p->pDest ){
84594
+ sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
84595
+ }
8438584596
8438684597
/* Set the error code of the destination database handle. */
8438784598
rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
8438884599
if( p->pDestDb ){
8438984600
sqlite3Error(p->pDestDb, rc);
8439084601
8439184602
/* Exit the mutexes and free the backup context structure. */
8439284603
sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
8439384604
}
84394
- sqlite3BtreeLeave(p->pSrc->pBt);
84605
+ sqlite3BtreeLeave(p->pSrc);
8439584606
if( p->pDestDb ){
8439684607
/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
8439784608
** call to sqlite3_backup_init() and is destroyed by a call to
8439884609
** sqlite3_backup_finish(). */
8439984610
sqlite3_free(p);
@@ -84447,11 +84658,11 @@
8444784658
Pgno iPage,
8444884659
const u8 *aData
8444984660
){
8445084661
assert( p!=0 );
8445184662
do{
84452
- assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84663
+ assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
8445384664
if( !isFatalError(p->rc) && iPage<p->iNext ){
8445484665
/* The backup process p has already copied page iPage. But now it
8445584666
** has been modified by a transaction on the source pager. Copy
8445684667
** the new data into the backup.
8445784668
*/
@@ -84483,11 +84694,11 @@
8448384694
** called.
8448484695
*/
8448584696
SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
8448684697
sqlite3_backup *p; /* Iterator variable */
8448784698
for(p=pBackup; p; p=p->pNext){
84488
- assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84699
+ assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
8448984700
p->iNext = 1;
8449084701
}
8449184702
}
8449284703
8449384704
#ifndef SQLITE_OMIT_VACUUM
@@ -84501,12 +84712,10 @@
8450184712
*/
8450284713
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
8450384714
int rc;
8450484715
sqlite3_file *pFd; /* File descriptor for database pTo */
8450584716
sqlite3_backup b;
84506
- Db dbDest;
84507
- Db dbSrc;
8450884717
sqlite3BtreeEnter(pTo);
8450984718
sqlite3BtreeEnter(pFrom);
8451084719
8451184720
assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
8451284721
pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -84521,17 +84730,13 @@
8452184730
** to 0. This is used by the implementations of sqlite3_backup_step()
8452284731
** and sqlite3_backup_finish() to detect that they are being called
8452384732
** from this function, not directly by the user.
8452484733
*/
8452584734
memset(&b, 0, sizeof(b));
84526
- memset(&dbDest, 0, sizeof(dbDest));
84527
- memset(&dbSrc, 0, sizeof(dbSrc));
84528
- dbDest.pBt = pTo;
84529
- dbSrc.pBt = pFrom;
8453084735
b.pSrcDb = pFrom->db;
84531
- b.pSrc = &dbSrc;
84532
- b.pDest = &dbDest;
84736
+ b.pSrc = pFrom;
84737
+ b.pDest = pTo;
8453384738
b.iNext = 1;
8453484739
8453584740
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
8453684741
** file. By passing this as the number of pages to copy to
8453784742
** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -84543,11 +84748,11 @@
8454384748
8454484749
rc = sqlite3_backup_finish(&b);
8454584750
if( rc==SQLITE_OK ){
8454684751
pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
8454784752
}else{
84548
- sqlite3PagerClearCache(sqlite3BtreePager(pTo));
84753
+ sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
8454984754
}
8455084755
8455184756
assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
8455284757
copy_finished:
8455384758
sqlite3BtreeLeave(pFrom);
@@ -86859,11 +87064,10 @@
8685987064
p->pParse = pParse;
8686087065
pParse->pVdbe = p;
8686187066
assert( pParse->aLabel==0 );
8686287067
assert( pParse->nLabel==0 );
8686387068
assert( p->nOpAlloc==0 );
86864
- assert( pParse->szOpAlloc==0 );
8686587069
sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
8686687070
return p;
8686787071
}
8686887072
8686987073
/*
@@ -87009,12 +87213,11 @@
8700987213
8701087214
assert( nOp<=(int)(1024/sizeof(Op)) );
8701187215
assert( nNew>=(v->nOpAlloc+nOp) );
8701287216
pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
8701387217
if( pNew ){
87014
- p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
87015
- v->nOpAlloc = p->szOpAlloc/sizeof(Op);
87218
+ v->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
8701687219
v->aOp = pNew;
8701787220
}
8701887221
return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
8701987222
}
8702087223
@@ -87445,11 +87648,11 @@
8744587648
** Resolve label "x" to be the address of the next instruction to
8744687649
** be inserted. The parameter "x" must have been obtained from
8744787650
** a prior call to sqlite3VdbeMakeLabel().
8744887651
*/
8744987652
static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
87450
- int nNewSize = 10 - p->nLabel;
87653
+ int nNewSize = 25 - p->nLabel;
8745187654
p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
8745287655
nNewSize*sizeof(p->aLabel[0]));
8745387656
if( p->aLabel==0 ){
8745487657
p->nLabelAlloc = 0;
8745587658
}else{
@@ -89513,11 +89716,11 @@
8951389716
** of the prepared statement.
8951489717
*/
8951589718
n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
8951689719
x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
8951789720
assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
89518
- x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */
89721
+ x.nFree = ROUNDDOWN8((p->nOpAlloc-p->nOp)*sizeof(Op)); /* Bytes unused mem */
8951989722
assert( x.nFree>=0 );
8952089723
assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
8952189724
8952289725
resolveP2Values(p, &nArg);
8952389726
p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92662,12 +92865,18 @@
9266292865
** that sqlite3_prepare() generates. For example, if new functions or
9266392866
** collating sequences are registered or if an authorizer function is
9266492867
** added or changed.
9266592868
*/
9266692869
SQLITE_API int sqlite3_expired(sqlite3_stmt *pStmt){
92667
- Vdbe *p = (Vdbe*)pStmt;
92668
- return p==0 || p->expired;
92870
+ int iRet = 1;
92871
+ if( pStmt ){
92872
+ Vdbe *p = (Vdbe*)pStmt;
92873
+ sqlite3_mutex_enter(p->db->mutex);
92874
+ iRet = p->expired;
92875
+ sqlite3_mutex_leave(p->db->mutex);
92876
+ }
92877
+ return iRet;
9266992878
}
9267092879
#endif
9267192880
9267292881
/*
9267392882
** Check on a Vdbe to make sure it has not been finalized. Log
@@ -93009,19 +93218,22 @@
9300993218
sqlite3ValueFree(pOld);
9301093219
}
9301193220
9301293221
9301393222
/**************************** sqlite3_result_ *******************************
93014
-** The following routines are used by user-defined functions to specify
93015
-** the function result.
93016
-**
93017
-** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
93018
-** result as a string or blob. Appropriate errors are set if the string/blob
93019
-** is too big or if an OOM occurs.
93020
-**
93021
-** The invokeValueDestructor(P,X) routine invokes destructor function X()
93022
-** on value P if P is not going to be used and need to be destroyed.
93223
+** The following routines are used by application-defined SQL functions to
93224
+** specify the function return value. There are many variations on
93225
+** sqlite3_result_xxxx() for different types of return values.
93226
+**
93227
+** The setStrOrError() function is a helper function that invokes
93228
+** sqlite3VdbeMemSetStr() to store the result as a string or blob.
93229
+** Appropriate errors are set if the string/blob is too big or if
93230
+** an OOM occurs.
93231
+**
93232
+** The invokeValueDestructor(P,X) helper function invokes the destructor
93233
+** function X() on value P if P is not going to be used and need to
93234
+** be destroyed.
9302393235
*/
9302493236
static void setResultStrOrError(
9302593237
sqlite3_context *pCtx, /* Function context */
9302693238
const char *z, /* String pointer */
9302793239
int n, /* Bytes in string, or negative */
@@ -93330,11 +93542,11 @@
9333093542
setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
9333193543
SQLITE_STATIC);
9333293544
}
9333393545
}
9333493546
93335
-/* Force an SQLITE_TOOBIG error. */
93547
+/* Cause the SQL function to raise an SQLITE_TOOBIG error. */
9333693548
SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
9333793549
#ifdef SQLITE_ENABLE_API_ARMOR
9333893550
if( pCtx==0 ) return;
9333993551
#endif
9334093552
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -93341,20 +93553,82 @@
9334193553
pCtx->isError = SQLITE_TOOBIG;
9334293554
sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1,
9334393555
SQLITE_UTF8, SQLITE_STATIC);
9334493556
}
9334593557
93346
-/* An SQLITE_NOMEM error. */
93558
+/* Cause the SQL function to raise an SQLITE_NOMEM error. */
9334793559
SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){
9334893560
#ifdef SQLITE_ENABLE_API_ARMOR
9334993561
if( pCtx==0 ) return;
9335093562
#endif
9335193563
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
9335293564
sqlite3VdbeMemSetNull(pCtx->pOut);
9335393565
pCtx->isError = SQLITE_NOMEM_BKPT;
9335493566
sqlite3OomFault(pCtx->pOut->db);
9335593567
}
93568
+
93569
+/* Make the return value of the SQL function or virtual table pCtx
93570
+** be the content of the sqlite3_str object pStr. The eOwn flag
93571
+** determines ownership of the sqlite3_str object and its content.
93572
+**
93573
+** eOwn Ownership transfer
93574
+** ------------- ------------------------------------------------
93575
+**
93576
+** SQLITE_COPY The SQL function returns a copy the sqlite3_str
93577
+** content and leaves the sqlite3_str object itself
93578
+** unchanged.
93579
+**
93580
+** SQLITE_XFER The content of the sqlite3_str is transferred to
93581
+** the SQL function and the SQL function takes
93582
+** responsibility for freeing that content when it is
93583
+** no longer needed. The sqlite3_str object is reset
93584
+** to an empty string.
93585
+**
93586
+** SQLITE_FINISH Like SQLITE_XFER except that the pStr is also
93587
+** freed using sqlite3_str_free().
93588
+*/
93589
+SQLITE_API void sqlite3_result_str(sqlite3_context *pCtx, sqlite3_str *pStr, int eOwn){
93590
+#ifdef SQLITE_ENABLE_API_ARMOR
93591
+ if( pCtx==0 ) return;
93592
+ if( pStr==0 ) return;
93593
+#endif
93594
+ if( pStr->accError==0 ){
93595
+ if( pStr->nChar==0 ){
93596
+ setResultStrOrError(pCtx, "", 0, SQLITE_UTF8_ZT, SQLITE_STATIC);
93597
+ if( eOwn ) sqlite3_str_reset(pStr);
93598
+ }else{
93599
+ const char *zText = sqlite3_str_value(pStr);
93600
+ /* Only internal code has the ability to capture a pointer to
93601
+ ** an sqlite3_str object that uses static buffer. And none of
93602
+ ** those internal use cases every invoke the sqlite3_result_str()
93603
+ ** interface on a static-buffer sqlite3_str. Should this change
93604
+ ** in the future, the following assert() will let us know. */
93605
+ assert( isMalloced(pStr) );
93606
+ if( eOwn==SQLITE_COPY ){
93607
+ setResultStrOrError(pCtx, zText, pStr->nChar,
93608
+ SQLITE_UTF8, SQLITE_TRANSIENT);
93609
+ }else{
93610
+ setResultStrOrError(pCtx, zText, pStr->nChar,
93611
+ SQLITE_UTF8_ZT, SQLITE_DYNAMIC);
93612
+ }
93613
+ }
93614
+ }else if( pStr->accError==SQLITE_NOMEM ){
93615
+ sqlite3_result_error_nomem(pCtx);
93616
+ }else{
93617
+ assert( pStr->accError==SQLITE_TOOBIG );
93618
+ sqlite3_result_error_toobig(pCtx);
93619
+ }
93620
+ if( eOwn ){
93621
+ testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
93622
+ if( pStr->accError==0 ){
93623
+ sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
93624
+ }
93625
+ if( eOwn==SQLITE_FINISH ){
93626
+ sqlite3_str_free(pStr);
93627
+ }
93628
+ }
93629
+}
9335693630
9335793631
#ifndef SQLITE_UNTESTABLE
9335893632
/* Force the INT64 value currently stored as the result to be
9335993633
** a MEM_IntReal value. See the SQLITE_TESTCTRL_RESULT_INTREAL
9336093634
** test-control.
@@ -102342,10 +102616,15 @@
102342102616
pTabCur = p->apCsr[pOp->p3];
102343102617
assert( pTabCur!=0 );
102344102618
assert( pTabCur->eCurType==CURTYPE_BTREE );
102345102619
assert( pTabCur->uc.pCursor!=0 );
102346102620
assert( pTabCur->isTable );
102621
+#if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
102622
+ assert(
102623
+ sqlite3BtreeCursorHintTblCsr(pC->uc.pCursor)==pTabCur->uc.pCursor
102624
+ );
102625
+#endif
102347102626
pTabCur->nullRow = 0;
102348102627
pTabCur->movetoTarget = rowid;
102349102628
pTabCur->deferredMoveto = 1;
102350102629
pTabCur->cacheStatus = CACHE_STALE;
102351102630
assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
@@ -104724,27 +105003,41 @@
104724105003
p->aCounter[SQLITE_STMTSTATUS_RUN]++;
104725105004
goto jump_to_p2;
104726105005
}
104727105006
104728105007
#ifdef SQLITE_ENABLE_CURSOR_HINTS
104729
-/* Opcode: CursorHint P1 * * P4 *
105008
+/* Opcode: CursorHint P1 * P3 P4 *
104730105009
**
104731
-** Provide a hint to cursor P1 that it only needs to return rows that
104732
-** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
104733
-** to values currently held in registers. TK_COLUMN terms in the P4
105010
+** Provide a hint to cursor P1.
105011
+**
105012
+** If P4 is of type P4_EXPR, then the hint is that the cursor need only return
105013
+** rows that satisfy the Expr in P4. TK_REGISTER terms in the P4 expression
105014
+** refer to values currently held in registers. TK_COLUMN terms in the P4
104734105015
** expression refer to columns in the b-tree to which cursor P1 is pointing.
105016
+** P3 is ignore in this case.
105017
+**
105018
+** Or, if P4 is P4_NOTUSED, then the hint is that cursor P1 is an index cursor
105019
+** used to drive table cursor P3. In other words, that this VM may execute
105020
+** OP_DeferredSeek instructions to lazily position P3 based on current
105021
+** position of P1.
104735105022
*/
104736105023
case OP_CursorHint: {
104737105024
VdbeCursor *pC;
105025
+ pC = p->apCsr[pOp->p1];
104738105026
104739105027
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
104740
- assert( pOp->p4type==P4_EXPR );
104741
- pC = p->apCsr[pOp->p1];
105028
+
104742105029
if( pC ){
104743105030
assert( pC->eCurType==CURTYPE_BTREE );
104744
- sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE,
104745
- pOp->p4.pExpr, aMem);
105031
+ if( pOp->p4type==P4_EXPR ){
105032
+ sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE,
105033
+ pOp->p4.pExpr, aMem);
105034
+ }else if( p->apCsr[pOp->p3] ){
105035
+ sqlite3BtreeCursorHint(
105036
+ pC->uc.pCursor, BTREE_HINT_TABLECURSOR, p->apCsr[pOp->p3]->uc.pCursor
105037
+ );
105038
+ }
104746105039
}
104747105040
break;
104748105041
}
104749105042
#endif /* SQLITE_ENABLE_CURSOR_HINTS */
104750105043
@@ -117229,11 +117522,16 @@
117229117522
#ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117230117523
if( pDef==0 && pParse->explain ){
117231117524
pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
117232117525
}
117233117526
#endif
117234
- if( pDef==0 || pDef->xFinalize!=0 ){
117527
+ if( pDef==0
117528
+ || pDef->xFinalize!=0
117529
+ || ((pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0 &&
117530
+ !pParse->nested &&
117531
+ (db->mDbFlags & DBFLAG_InternalFunc)==0)
117532
+ ){
117235117533
sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
117236117534
break;
117237117535
}
117238117536
if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
117239117537
assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
@@ -122236,13 +122534,12 @@
122236122534
const u8 *zSql = sqlite3_value_text(argv[0]);
122237122535
const char *zCons = (const char*)sqlite3_value_text(argv[1]);
122238122536
int iCol = sqlite3_value_int(argv[2]);
122239122537
int iOff = 0;
122240122538
int ii;
122241
- char *zNew = 0;
122539
+ sqlite3_str *pNew;
122242122540
int t = 0;
122243
- sqlite3 *db;
122244122541
UNUSED_PARAMETER(NotUsed);
122245122542
122246122543
if( skipCreateTable(ctx, zSql, &iOff) ) return;
122247122544
122248122545
for(ii=0; ii<=iCol || (iCol<0 && t!=TK_RP); ii++){
@@ -122258,17 +122555,15 @@
122258122555
}
122259122556
}
122260122557
122261122558
iOff += getWhitespace(&zSql[iOff]);
122262122559
122263
- db = sqlite3_context_db_handle(ctx);
122264
- if( iCol<0 ){
122265
- zNew = sqlite3MPrintf(db, "%.*s, %s%s", iOff, zSql, zCons, &zSql[iOff]);
122266
- }else{
122267
- zNew = sqlite3MPrintf(db, "%.*s %s%s", iOff, zSql, zCons, &zSql[iOff]);
122268
- }
122269
- sqlite3_result_text(ctx, zNew, -1, SQLITE_DYNAMIC);
122560
+ pNew = sqlite3_str_new(sqlite3_context_db_handle(ctx));
122561
+ sqlite3_str_append(pNew, (const char*)zSql, iOff);
122562
+ if( iCol<0 ) sqlite3_str_append(pNew, ",", 1);
122563
+ sqlite3_str_appendf(pNew, " %s%s", zCons, &zSql[iOff]);
122564
+ sqlite3_result_str(ctx, pNew, SQLITE_FINISH);
122270122565
}
122271122566
122272122567
/*
122273122568
** Find a column named pCol in table pTab. If successful, set output
122274122569
** parameter *piCol to the index of the column in the table and return
@@ -123524,11 +123819,11 @@
123524123819
sqlite3_str_appendf(&sStat, " %llu", iVal);
123525123820
#ifdef SQLITE_ENABLE_STAT4
123526123821
assert( p->current.anEq[i] || p->nRow==0 );
123527123822
#endif
123528123823
}
123529
- sqlite3ResultStrAccum(context, &sStat);
123824
+ sqlite3_result_str(context, &sStat, SQLITE_XFER);
123530123825
}
123531123826
#ifdef SQLITE_ENABLE_STAT4
123532123827
else if( eCall==STAT_GET_ROWID ){
123533123828
if( p->iGet<0 ){
123534123829
samplePushPrevious(p, 0);
@@ -123561,11 +123856,11 @@
123561123856
sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
123562123857
for(i=0; i<p->nCol; i++){
123563123858
sqlite3_str_appendf(&sStat, "%llu ", (u64)aCnt[i]);
123564123859
}
123565123860
if( sStat.nChar ) sStat.nChar--;
123566
- sqlite3ResultStrAccum(context, &sStat);
123861
+ sqlite3_result_str(context, &sStat, SQLITE_XFER);
123567123862
}
123568123863
#endif /* SQLITE_ENABLE_STAT4 */
123569123864
#ifndef SQLITE_DEBUG
123570123865
UNUSED_PARAMETER( argc );
123571123866
#endif
@@ -125649,10 +125944,11 @@
125649125944
}
125650125945
}
125651125946
125652125947
assert( pToplevel->nTableLock < 0x7fff0000 );
125653125948
nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
125949
+ if( pToplevel->nTableLock==0 ) pToplevel->aTableLock = 0;
125654125950
pToplevel->aTableLock =
125655125951
sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
125656125952
if( pToplevel->aTableLock ){
125657125953
p = &pToplevel->aTableLock[pToplevel->nTableLock++];
125658125954
p->iDb = iDb;
@@ -125815,11 +126111,11 @@
125815126111
if( pParse->nTableLock ) codeTableLocks(pParse);
125816126112
#endif
125817126113
125818126114
/* Initialize any AUTOINCREMENT data structures required.
125819126115
*/
125820
- if( pParse->pAinc ) sqlite3AutoincrementBegin(pParse);
126116
+ if( pParse->usesAinc ) sqlite3AutoincrementBegin(pParse);
125821126117
125822126118
/* Code constant expressions that were factored out of inner loops.
125823126119
*/
125824126120
if( pParse->pConstExpr ){
125825126121
ExprList *pEL = pParse->pConstExpr;
@@ -125848,11 +126144,11 @@
125848126144
assert( v!=0 || pParse->nErr );
125849126145
assert( db->mallocFailed==0 || pParse->nErr );
125850126146
if( pParse->nErr==0 ){
125851126147
/* A minimum of one cursor is required if autoincrement is used
125852126148
* See ticket [a696379c1f08866] */
125853
- assert( pParse->pAinc==0 || pParse->nTab>0 );
126149
+ assert( pParse->usesAinc==0 || pParse->nTab>0 );
125854126150
sqlite3VdbeMakeReady(v, pParse);
125855126151
pParse->rc = SQLITE_DONE;
125856126152
}else{
125857126153
pParse->rc = SQLITE_ERROR;
125858126154
}
@@ -133318,32 +133614,20 @@
133318133614
sqlite3_value **argv
133319133615
){
133320133616
PrintfArguments x;
133321133617
StrAccum str;
133322133618
const char *zFormat;
133323
- int n;
133324133619
sqlite3 *db = sqlite3_context_db_handle(context);
133325133620
133326133621
if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
133327133622
x.nArg = argc-1;
133328133623
x.nUsed = 0;
133329133624
x.apArg = argv+1;
133330133625
sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
133331133626
str.printfFlags = SQLITE_PRINTF_SQLFUNC;
133332133627
sqlite3_str_appendf(&str, zFormat, &x);
133333
- if( str.accError==SQLITE_OK ){
133334
- n = str.nChar;
133335
- sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
133336
- SQLITE_DYNAMIC);
133337
- }else{
133338
- if( str.accError==SQLITE_NOMEM ){
133339
- sqlite3_result_error_nomem(context);
133340
- }else{
133341
- sqlite3_result_error_toobig(context);
133342
- }
133343
- sqlite3_str_reset(&str);
133344
- }
133628
+ sqlite3_result_str(context, &str, SQLITE_XFER);
133345133629
}
133346133630
}
133347133631
133348133632
/*
133349133633
** Implementation of the substr() function.
@@ -134286,16 +134570,11 @@
134286134570
sqlite3 *db = sqlite3_context_db_handle(context);
134287134571
assert( argc==1 );
134288134572
UNUSED_PARAMETER(argc);
134289134573
sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
134290134574
sqlite3QuoteValue(&str,argv[0],SQLITE_PTR_TO_INT(sqlite3_user_data(context)));
134291
- sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
134292
- SQLITE_DYNAMIC);
134293
- if( str.accError!=SQLITE_OK ){
134294
- sqlite3_result_null(context);
134295
- sqlite3_result_error_code(context, str.accError);
134296
- }
134575
+ sqlite3_result_str(context, &str, SQLITE_XFER);
134297134576
}
134298134577
134299134578
/*
134300134579
** The unicode() function. Return the integer unicode code-point value
134301134580
** for the first character of the input string.
@@ -135324,32 +135603,22 @@
135324135603
#endif /* SQLITE_OMIT_WINDOWFUNC */
135325135604
static void groupConcatFinalize(sqlite3_context *context){
135326135605
GroupConcatCtx *pGCC
135327135606
= (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135328135607
if( pGCC ){
135329
- sqlite3ResultStrAccum(context, &pGCC->str);
135608
+ sqlite3_result_str(context, &pGCC->str, SQLITE_XFER);
135330135609
#ifndef SQLITE_OMIT_WINDOWFUNC
135331135610
sqlite3_free(pGCC->pnSepLengths);
135332135611
#endif
135333135612
}
135334135613
}
135335135614
#ifndef SQLITE_OMIT_WINDOWFUNC
135336135615
static void groupConcatValue(sqlite3_context *context){
135337135616
GroupConcatCtx *pGCC
135338135617
= (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135339
- if( pGCC ){
135340
- StrAccum *pAccum = &pGCC->str;
135341
- if( pAccum->accError==SQLITE_TOOBIG ){
135342
- sqlite3_result_error_toobig(context);
135343
- }else if( pAccum->accError==SQLITE_NOMEM ){
135344
- sqlite3_result_error_nomem(context);
135345
- }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){
135346
- sqlite3_result_text(context, "", 1, SQLITE_STATIC);
135347
- }else{
135348
- const char *zText = sqlite3_str_value(pAccum);
135349
- sqlite3_result_text(context, zText, pAccum->nChar, SQLITE_TRANSIENT);
135350
- }
135618
+ if( pGCC && pGCC->nAccum>0 ){
135619
+ sqlite3_result_str(context, &pGCC->str, SQLITE_COPY);
135351135620
}
135352135621
}
135353135622
#else
135354135623
# define groupConcatValue 0
135355135624
#endif /* SQLITE_OMIT_WINDOWFUNC */
@@ -136190,12 +136459,11 @@
136190136459
sqlite3_str_appendall(pStr, ",\"journal\":");
136191136460
rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_FILESTAT, pStr);
136192136461
if( rc ) sqlite3_str_append(pStr, "null", 4);
136193136462
}
136194136463
sqlite3_str_append(pStr, "}", 1);
136195
- sqlite3_result_text(context, sqlite3_str_finish(pStr), -1,
136196
- sqlite3_free);
136464
+ sqlite3_result_str(context, pStr, SQLITE_FINISH);
136197136465
}
136198136466
sqlite3BtreeLeave(pBtree);
136199136467
}else{
136200136468
sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
136201136469
}
@@ -136307,12 +136575,12 @@
136307136575
}else{
136308136576
sqlite3_str_appendf(pResult, ", NULL");
136309136577
}
136310136578
}
136311136579
}
136312
- sqlite3_result_text(ctx, sqlite3_str_finish(pResult), -1, sqlite3_free);
136313136580
}
136581
+ sqlite3_result_str(ctx, pResult, SQLITE_FINISH);
136314136582
sqlite3_free_filename(zFile);
136315136583
sqlite3_free(zErr);
136316136584
}
136317136585
#endif /* SQLITE_DEBUG */
136318136586
@@ -136405,11 +136673,11 @@
136405136673
VFUNCTION(random, 0, 0, 0, randomFunc ),
136406136674
VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
136407136675
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
136408136676
DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
136409136677
DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
136410
- FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
136678
+ SFUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
136411136679
FUNCTION(unistr, 1, 0, 0, unistrFunc ),
136412136680
FUNCTION(quote, 1, 0, 0, quoteFunc ),
136413136681
FUNCTION(unistr_quote, 1, 1, 0, quoteFunc ),
136414136682
VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
136415136683
VFUNCTION(changes, 0, 0, 0, changes ),
@@ -138454,19 +138722,23 @@
138454138722
pParse->nErr++;
138455138723
pParse->rc = SQLITE_CORRUPT_SEQUENCE;
138456138724
return 0;
138457138725
}
138458138726
138727
+ if( pToplevel->usesAinc==0 ){
138728
+ pToplevel->pAinc = 0;
138729
+ }
138459138730
pInfo = pToplevel->pAinc;
138460138731
while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
138461138732
if( pInfo==0 ){
138462138733
pInfo = sqlite3DbMallocRawNN(pParse->db, sizeof(*pInfo));
138463138734
sqlite3ParserAddCleanup(pToplevel, sqlite3DbFree, pInfo);
138464138735
testcase( pParse->earlyCleanup );
138465138736
if( pParse->db->mallocFailed ) return 0;
138466138737
pInfo->pNext = pToplevel->pAinc;
138467138738
pToplevel->pAinc = pInfo;
138739
+ pToplevel->usesAinc = 1;
138468138740
pInfo->pTab = pTab;
138469138741
pInfo->iDb = iDb;
138470138742
pToplevel->nMem++; /* Register to hold name of table */
138471138743
pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
138472138744
pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */
@@ -138491,10 +138763,11 @@
138491138763
** only called from the top-level */
138492138764
assert( pParse->pTriggerTab==0 );
138493138765
assert( sqlite3IsToplevel(pParse) );
138494138766
138495138767
assert( v ); /* We failed long ago if this is not so */
138768
+ assert( pParse->usesAinc );
138496138769
for(p = pParse->pAinc; p; p = p->pNext){
138497138770
static const int iLn = VDBE_OFFSET_LINENO(2);
138498138771
static const VdbeOpList autoInc[] = {
138499138772
/* 0 */ {OP_Null, 0, 0, 0},
138500138773
/* 1 */ {OP_Rewind, 0, 10, 0},
@@ -138558,10 +138831,11 @@
138558138831
AutoincInfo *p;
138559138832
Vdbe *v = pParse->pVdbe;
138560138833
sqlite3 *db = pParse->db;
138561138834
138562138835
assert( v );
138836
+ assert( pParse->usesAinc );
138563138837
for(p = pParse->pAinc; p; p = p->pNext){
138564138838
static const int iLn = VDBE_OFFSET_LINENO(2);
138565138839
static const VdbeOpList autoIncEnd[] = {
138566138840
/* 0 */ {OP_NotNull, 0, 2, 0},
138567138841
/* 1 */ {OP_NewRowid, 0, 0, 0},
@@ -138590,11 +138864,11 @@
138590138864
aOp[3].p5 = OPFLAG_APPEND;
138591138865
sqlite3ReleaseTempReg(pParse, iRec);
138592138866
}
138593138867
}
138594138868
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse){
138595
- if( pParse->pAinc ) autoIncrementEnd(pParse);
138869
+ if( pParse->usesAinc ) autoIncrementEnd(pParse);
138596138870
}
138597138871
#else
138598138872
/*
138599138873
** If SQLITE_OMIT_AUTOINCREMENT is defined, then the three routines
138600138874
** above are all no-ops
@@ -142023,10 +142297,11 @@
142023142297
void (*str_free)(sqlite3_str*);
142024142298
int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142025142299
int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
142026142300
/* Version 3.54.0 and later */
142027142301
sqlite3_int64 (*incomplete)(const char*);
142302
+ void (*result_str)(sqlite3_context*,sqlite3_str*,int);
142028142303
};
142029142304
142030142305
/*
142031142306
** This is the function signature used for all extension entry points. It
142032142307
** is also defined in the file "loadext.c".
@@ -142368,10 +142643,11 @@
142368142643
#define sqlite3_str_free sqlite3_api->str_free
142369142644
#define sqlite3_carray_bind sqlite3_api->carray_bind
142370142645
#define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142371142646
/* Version 3.54.0 and later */
142372142647
#define sqlite3_incomplete sqlite3_api->incomplete
142648
+#define sqlite3_result_str sqlite3_api->result_str
142373142649
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142374142650
142375142651
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142376142652
/* This case when the file really is being compiled as a loadable
142377142653
** extension */
@@ -142905,11 +143181,13 @@
142905143181
sqlite3_carray_bind_v2,
142906143182
#else
142907143183
0,
142908143184
0,
142909143185
#endif
142910
- sqlite3_incomplete
143186
+ /* Version 3.54.0 and later */
143187
+ sqlite3_incomplete,
143188
+ sqlite3_result_str
142911143189
};
142912143190
142913143191
/* True if x is the directory separator character
142914143192
*/
142915143193
#if SQLITE_OS_WIN
@@ -147674,11 +147952,11 @@
147674147952
sqlite3 *db = pParse->db;
147675147953
assert( db!=0 );
147676147954
assert( db->pParse==pParse );
147677147955
assert( pParse->nested==0 );
147678147956
#ifndef SQLITE_OMIT_SHARED_CACHE
147679
- if( pParse->aTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
147957
+ if( pParse->nTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
147680147958
#endif
147681147959
while( pParse->pCleanup ){
147682147960
ParseCleanup *pCleanup = pParse->pCleanup;
147683147961
pParse->pCleanup = pCleanup->pNext;
147684147962
pCleanup->xCleanup(db, pCleanup->pPtr);
@@ -148157,11 +148435,11 @@
148157148435
int nBytes, /* Length of zSql in bytes. */
148158148436
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148159148437
const void **pzTail /* OUT: End of parsed string */
148160148438
){
148161148439
int rc;
148162
- rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
148440
+ rc = sqlite3Prepare16(db,zSql,nBytes&~1,0,ppStmt,pzTail);
148163148441
assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148164148442
return rc;
148165148443
}
148166148444
SQLITE_API int sqlite3_prepare16_v2(
148167148445
sqlite3 *db, /* Database handle. */
@@ -148169,11 +148447,11 @@
148169148447
int nBytes, /* Length of zSql in bytes. */
148170148448
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148171148449
const void **pzTail /* OUT: End of parsed string */
148172148450
){
148173148451
int rc;
148174
- rc = sqlite3Prepare16(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,ppStmt,pzTail);
148452
+ rc = sqlite3Prepare16(db,zSql,nBytes&~1,SQLITE_PREPARE_SAVESQL,ppStmt,pzTail);
148175148453
assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148176148454
return rc;
148177148455
}
148178148456
SQLITE_API int sqlite3_prepare16_v3(
148179148457
sqlite3 *db, /* Database handle. */
@@ -148182,11 +148460,11 @@
148182148460
unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
148183148461
sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148184148462
const void **pzTail /* OUT: End of parsed string */
148185148463
){
148186148464
int rc;
148187
- rc = sqlite3Prepare16(db,zSql,nBytes,
148465
+ rc = sqlite3Prepare16(db,zSql,nBytes&~1,
148188148466
SQLITE_PREPARE_SAVESQL|(prepFlags&SQLITE_PREPARE_MASK),
148189148467
ppStmt,pzTail);
148190148468
assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148191148469
return rc;
148192148470
}
@@ -148855,11 +149133,12 @@
148855149133
pRight->u3.pOn = 0;
148856149134
pRight->fg.isOn = 1;
148857149135
p->selFlags |= SF_OnToWhere;
148858149136
}
148859149137
148860
- if( IsVirtual(pRightTab) && joinType==EP_OuterON && pRight->u1.pFuncArg ){
149138
+ if( pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg ){
149139
+ assert( IsVirtual(pRightTab) );
148861149140
p->selFlags |= SF_OnToWhere;
148862149141
}
148863149142
}
148864149143
return 0;
148865149144
}
@@ -161225,10 +161504,11 @@
161225161504
SQLITE_API int sqlite3_drop_modules(sqlite3 *db, const char** azNames){
161226161505
HashElem *pThis, *pNext;
161227161506
#ifdef SQLITE_ENABLE_API_ARMOR
161228161507
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
161229161508
#endif
161509
+ sqlite3_mutex_enter(db->mutex);
161230161510
for(pThis=sqliteHashFirst(&db->aModule); pThis; pThis=pNext){
161231161511
Module *pMod = (Module*)sqliteHashData(pThis);
161232161512
pNext = sqliteHashNext(pThis);
161233161513
if( azNames ){
161234161514
int ii;
@@ -161235,10 +161515,11 @@
161235161515
for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
161236161516
if( azNames[ii]!=0 ) continue;
161237161517
}
161238161518
createModule(db, pMod->zName, 0, 0, 0);
161239161519
}
161520
+ sqlite3_mutex_leave(db->mutex);
161240161521
return SQLITE_OK;
161241161522
}
161242161523
161243161524
/*
161244161525
** Decrement the reference count on a Module object. Destroy the
@@ -167001,33 +167282,62 @@
167001167282
}
167002167283
}
167003167284
}
167004167285
}
167005167286
167006
- /* At this point, okToChngToIN is true if original pTerm satisfies
167007
- ** case 1. In that case, construct a new virtual term that is
167008
- ** pTerm converted into an IN operator.
167287
+ /* At this point, okToChngToIN is true if original pTerm is a
167288
+ ** candidate to satisfy case 1, though we are not yet certain that
167289
+ ** the collating sequences are all compatible. Try to construct a
167290
+ ** new virtual term that is pTerm converted from an OR operator
167291
+ ** into an IN operator.
167292
+ **
167293
+ ** During construction, verify that the collating sequences on all
167294
+ ** subterms of the OR are compatible. Omit the construction of the
167295
+ ** new IN operator if there are any collating sequence mismatches.
167009167296
*/
167010167297
if( okToChngToIN ){
167011167298
Expr *pDup; /* A transient duplicate expression */
167012167299
ExprList *pList = 0; /* The RHS of the IN operator */
167013167300
Expr *pLeft = 0; /* The LHS of the IN operator */
167301
+ CollSeq *pCollSeq = 0; /* Collating sequence to use */
167014167302
Expr *pNew; /* The complete IN operator */
167015167303
167016167304
for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
167305
+ Expr *pThis;
167017167306
if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
167018167307
assert( pOrTerm->eOperator & WO_EQ );
167019167308
assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
167020167309
assert( pOrTerm->leftCursor==iCursor );
167021167310
assert( pOrTerm->u.x.leftColumn==iColumn );
167022
- pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
167311
+ pThis = pOrTerm->pExpr;
167312
+ pDup = sqlite3ExprDup(db, pThis->pRight, 0);
167023167313
pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
167024
- pLeft = pOrTerm->pExpr->pLeft;
167314
+ if( pLeft==0 ){
167315
+ pLeft = pThis->pLeft;
167316
+ pCollSeq = sqlite3ExprCompareCollSeq(pParse, pThis);
167317
+ }else{
167318
+ assert( 0==sqlite3ExprCompare(pParse,
167319
+ sqlite3ExprSkipCollate(pThis->pLeft),
167320
+ sqlite3ExprSkipCollate(pLeft), -1) );
167321
+ if( pCollSeq!=sqlite3ExprCompareCollSeq(pParse, pThis) ){
167322
+ pLeft = 0; /* Collating sequence mismatch */
167323
+ break;
167324
+ }
167325
+ }
167025167326
}
167026
- assert( pLeft!=0 );
167027
- pDup = sqlite3ExprDup(db, pLeft, 0);
167028
- pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
167327
+ if( pLeft==0 ){
167328
+ pNew = 0; /* Collating sequence mismatch */
167329
+ }else{
167330
+ pDup = sqlite3ExprDup(db, pLeft, 0);
167331
+ if( sqlite3ExprCollSeq(pParse, pDup)!=pCollSeq
167332
+ && ALWAYS(pCollSeq!=0)
167333
+ ){
167334
+ assert( pCollSeq->zName!=0 );
167335
+ pDup = sqlite3ExprAddCollateString(pParse, pDup, pCollSeq->zName);
167336
+ }
167337
+ pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
167338
+ }
167029167339
if( pNew ){
167030167340
int idxNew;
167031167341
transferJoinMarkings(pNew, pExpr);
167032167342
assert( ExprUseXList(pNew) );
167033167343
pNew->x.pList = pList;
@@ -175432,10 +175742,15 @@
175432175742
}
175433175743
sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
175434175744
(u8*)&colUsed, P4_INT64);
175435175745
}
175436175746
#endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
175747
+#ifdef SQLITE_ENABLE_CURSOR_HINTS
175748
+ if( HasRowid(pTab) ){
175749
+ sqlite3VdbeAddOp3(v, OP_CursorHint, iIndexCur, 0, pTabItem->iCursor);
175750
+ }
175751
+#endif
175437175752
}
175438175753
}
175439175754
if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
175440175755
if( (pTabItem->fg.jointype & JT_RIGHT)!=0
175441175756
&& (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
@@ -176155,11 +176470,11 @@
176155176470
case SQLITE_INTEGER:
176156176471
iVal = sqlite3_value_int64(apArg[1]);
176157176472
break;
176158176473
case SQLITE_FLOAT: {
176159176474
double fVal = sqlite3_value_double(apArg[1]);
176160
- if( ((i64)fVal)!=fVal ) goto error_out;
176475
+ if( sqlite3RealToI64(fVal)!=fVal ) goto error_out;
176161176476
iVal = (i64)fVal;
176162176477
break;
176163176478
}
176164176479
default:
176165176480
goto error_out;
@@ -187755,17 +188070,21 @@
187755188070
187756188071
/*
187757188072
** Return the ROWID of the most recent insert
187758188073
*/
187759188074
SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
188075
+ i64 iRet;
187760188076
#ifdef SQLITE_ENABLE_API_ARMOR
187761188077
if( !sqlite3SafetyCheckOk(db) ){
187762188078
(void)SQLITE_MISUSE_BKPT;
187763188079
return 0;
187764188080
}
187765188081
#endif
187766
- return db->lastRowid;
188082
+ sqlite3_mutex_enter(db->mutex);
188083
+ iRet = db->lastRowid;
188084
+ sqlite3_mutex_leave(db->mutex);
188085
+ return iRet;
187767188086
}
187768188087
187769188088
/*
187770188089
** Set the value returned by the sqlite3_last_insert_rowid() API function.
187771188090
*/
@@ -187784,33 +188103,41 @@
187784188103
/*
187785188104
** Return the number of changes in the most recently executed DML
187786188105
** statement.
187787188106
*/
187788188107
SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3 *db){
188108
+ i64 iRet;
187789188109
#ifdef SQLITE_ENABLE_API_ARMOR
187790188110
if( !sqlite3SafetyCheckOk(db) ){
187791188111
(void)SQLITE_MISUSE_BKPT;
187792188112
return 0;
187793188113
}
187794188114
#endif
187795
- return db->nChange;
188115
+ sqlite3_mutex_enter(db->mutex);
188116
+ iRet = db->nChange;
188117
+ sqlite3_mutex_leave(db->mutex);
188118
+ return iRet;
187796188119
}
187797188120
SQLITE_API int sqlite3_changes(sqlite3 *db){
187798188121
return (int)sqlite3_changes64(db);
187799188122
}
187800188123
187801188124
/*
187802188125
** Return the number of changes since the database handle was opened.
187803188126
*/
187804188127
SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){
188128
+ i64 iRet;
187805188129
#ifdef SQLITE_ENABLE_API_ARMOR
187806188130
if( !sqlite3SafetyCheckOk(db) ){
187807188131
(void)SQLITE_MISUSE_BKPT;
187808188132
return 0;
187809188133
}
187810188134
#endif
187811
- return db->nTotalChange;
188135
+ sqlite3_mutex_enter(db->mutex);
188136
+ iRet = db->nTotalChange;
188137
+ sqlite3_mutex_leave(db->mutex);
188138
+ return iRet;
187812188139
}
187813188140
SQLITE_API int sqlite3_total_changes(sqlite3 *db){
187814188141
return (int)sqlite3_total_changes64(db);
187815188142
}
187816188143
@@ -188489,10 +188816,11 @@
188489188816
*/
188490188817
SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
188491188818
#ifdef SQLITE_ENABLE_API_ARMOR
188492188819
if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
188493188820
#endif
188821
+ sqlite3_mutex_enter(db->mutex);
188494188822
if( ms>0 ){
188495188823
sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
188496188824
(void*)db);
188497188825
db->busyTimeout = ms;
188498188826
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
@@ -188499,10 +188827,11 @@
188499188827
db->setlkTimeout = ms;
188500188828
#endif
188501188829
}else{
188502188830
sqlite3_busy_handler(db, 0, 0);
188503188831
}
188832
+ sqlite3_mutex_leave(db->mutex);
188504188833
return SQLITE_OK;
188505188834
}
188506188835
188507188836
/*
188508188837
** Set the setlk timeout value.
@@ -189404,13 +189733,15 @@
189404189733
/*
189405189734
** Return the byte offset of the most recent error
189406189735
*/
189407189736
SQLITE_API int sqlite3_error_offset(sqlite3 *db){
189408189737
int iOffset = -1;
189409
- if( db && sqlite3SafetyCheckSickOrOk(db) && db->errCode ){
189738
+ if( db && sqlite3SafetyCheckSickOrOk(db) ){
189410189739
sqlite3_mutex_enter(db->mutex);
189411
- iOffset = db->errByteOffset;
189740
+ if( db->errCode ){
189741
+ iOffset = db->errByteOffset;
189742
+ }
189412189743
sqlite3_mutex_leave(db->mutex);
189413189744
}
189414189745
return iOffset;
189415189746
}
189416189747
@@ -189460,29 +189791,47 @@
189460189791
/*
189461189792
** Return the most recent error code generated by an SQLite routine. If NULL is
189462189793
** passed to this function, we assume a malloc() failed during sqlite3_open().
189463189794
*/
189464189795
SQLITE_API int sqlite3_errcode(sqlite3 *db){
189465
- if( db && !sqlite3SafetyCheckSickOrOk(db) ){
189796
+ int iRet;
189797
+ if( !db ) return SQLITE_NOMEM_BKPT;
189798
+ if( !sqlite3SafetyCheckSickOrOk(db) ){
189466189799
return SQLITE_MISUSE_BKPT;
189467189800
}
189468
- if( !db || db->mallocFailed ){
189469
- return SQLITE_NOMEM_BKPT;
189801
+ sqlite3_mutex_enter(db->mutex);
189802
+ if( db->mallocFailed ){
189803
+ iRet = SQLITE_NOMEM_BKPT;
189804
+ }else{
189805
+ iRet = db->errCode & db->errMask;
189470189806
}
189471
- return db->errCode & db->errMask;
189807
+ sqlite3_mutex_leave(db->mutex);
189808
+ return iRet;
189472189809
}
189473189810
SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
189474
- if( db && !sqlite3SafetyCheckSickOrOk(db) ){
189811
+ int iRet;
189812
+ if( !db ) return SQLITE_NOMEM_BKPT;
189813
+ if( !sqlite3SafetyCheckSickOrOk(db) ){
189475189814
return SQLITE_MISUSE_BKPT;
189476189815
}
189477
- if( !db || db->mallocFailed ){
189478
- return SQLITE_NOMEM_BKPT;
189816
+ sqlite3_mutex_enter(db->mutex);
189817
+ if( db->mallocFailed ){
189818
+ iRet = SQLITE_NOMEM_BKPT;
189819
+ }else{
189820
+ iRet = db->errCode;
189479189821
}
189480
- return db->errCode;
189822
+ sqlite3_mutex_leave(db->mutex);
189823
+ return iRet;
189481189824
}
189482189825
SQLITE_API int sqlite3_system_errno(sqlite3 *db){
189483
- return db ? db->iSysErrno : 0;
189826
+ int iRet = 0;
189827
+ if( db ){
189828
+ sqlite3_mutex_enter(db->mutex);
189829
+ iRet = db->iSysErrno;
189830
+ sqlite3_mutex_leave(db->mutex);
189831
+ }
189832
+ return iRet;
189484189833
}
189485189834
189486189835
/*
189487189836
** Return a string that describes the kind of error specified in the
189488189837
** argument. For now, this simply calls the internal sqlite3ErrStr()
@@ -189673,19 +190022,21 @@
189673190022
189674190023
189675190024
if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
189676190025
return -1;
189677190026
}
190027
+ sqlite3_mutex_enter(db->mutex);
189678190028
oldLimit = db->aLimit[limitId];
189679190029
if( newLimit>=0 ){ /* IMP: R-52476-28732 */
189680190030
if( newLimit>aHardLimit[limitId] ){
189681190031
newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
189682190032
}else if( newLimit<SQLITE_MIN_LENGTH && limitId==SQLITE_LIMIT_LENGTH ){
189683190033
newLimit = SQLITE_MIN_LENGTH;
189684190034
}
189685190035
db->aLimit[limitId] = newLimit;
189686190036
}
190037
+ sqlite3_mutex_leave(db->mutex);
189687190038
return oldLimit; /* IMP: R-53341-35419 */
189688190039
}
189689190040
189690190041
/*
189691190042
** This function is used to parse both URIs and non-URI filenames passed by the
@@ -189724,22 +190075,22 @@
189724190075
int rc = SQLITE_OK;
189725190076
unsigned int flags = *pFlags;
189726190077
const char *zVfs = zDefaultVfs;
189727190078
char *zFile;
189728190079
char c;
189729
- int nUri = sqlite3Strlen30(zUri);
190080
+ i64 nUri = strlen(zUri);
189730190081
189731190082
assert( *pzErrMsg==0 );
189732190083
189733190084
if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
189734190085
|| AtomicLoad(&sqlite3GlobalConfig.bOpenUri)) /* IMP: R-51689-46548 */
189735190086
&& nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
189736190087
){
189737190088
char *zOpt;
189738190089
int eState; /* Parser state when parsing URI */
189739
- int iIn; /* Input character index */
189740
- int iOut = 0; /* Output character index */
190090
+ i64 iIn; /* Input character index */
190091
+ i64 iOut = 0; /* Output character index */
189741190092
u64 nByte = nUri+8; /* Bytes of space to allocate */
189742190093
189743190094
/* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
189744190095
** method that there may be extra parameters following the file-name. */
189745190096
flags |= SQLITE_OPEN_URI;
@@ -189769,11 +190120,11 @@
189769190120
if( zUri[5]=='/' && zUri[6]=='/' ){
189770190121
iIn = 7;
189771190122
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
189772190123
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
189773190124
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
189774
- iIn-7, &zUri[7]);
190125
+ (int)(iIn-7), &zUri[7]);
189775190126
rc = SQLITE_ERROR;
189776190127
goto parse_uri_out;
189777190128
}
189778190129
}
189779190130
#endif
@@ -189844,15 +190195,15 @@
189844190195
189845190196
/* Check if there were any options specified that should be interpreted
189846190197
** here. Options that are interpreted here include "vfs" and those that
189847190198
** correspond to flags that may be passed to the sqlite3_open_v2()
189848190199
** method. */
189849
- zOpt = &zFile[sqlite3Strlen30(zFile)+1];
190200
+ zOpt = &zFile[strlen(zFile)+1];
189850190201
while( zOpt[0] ){
189851
- int nOpt = sqlite3Strlen30(zOpt);
190202
+ i64 nOpt = strlen(zOpt);
189852190203
char *zVal = &zOpt[nOpt+1];
189853
- int nVal = sqlite3Strlen30(zVal);
190204
+ i64 nVal = strlen(zVal);
189854190205
189855190206
if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
189856190207
zVfs = zVal;
189857190208
}else{
189858190209
struct OpenMode {
@@ -189894,11 +190245,11 @@
189894190245
if( aMode ){
189895190246
int i;
189896190247
int mode = 0;
189897190248
for(i=0; aMode[i].z; i++){
189898190249
const char *z = aMode[i].z;
189899
- if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
190250
+ if( nVal==(i64)strlen(z) && 0==memcmp(zVal, z, nVal) ){
189900190251
mode = aMode[i].mode;
189901190252
break;
189902190253
}
189903190254
}
189904190255
if( mode==0 ){
@@ -190579,17 +190930,21 @@
190579190930
** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
190580190931
** by default. Autocommit is disabled by a BEGIN statement and reenabled
190581190932
** by the next COMMIT or ROLLBACK.
190582190933
*/
190583190934
SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
190935
+ int iRet;
190584190936
#ifdef SQLITE_ENABLE_API_ARMOR
190585190937
if( !sqlite3SafetyCheckOk(db) ){
190586190938
(void)SQLITE_MISUSE_BKPT;
190587190939
return 0;
190588190940
}
190589190941
#endif
190590
- return db->autoCommit;
190942
+ sqlite3_mutex_enter(db->mutex);
190943
+ iRet = db->autoCommit;
190944
+ sqlite3_mutex_leave(db->mutex);
190945
+ return iRet;
190591190946
}
190592190947
190593190948
/*
190594190949
** The following routines are substitutes for constants SQLITE_CORRUPT,
190595190950
** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
@@ -191610,21 +191965,23 @@
191610191965
/*
191611191966
** Return the name of the N-th database schema. Return NULL if N is out
191612191967
** of range.
191613191968
*/
191614191969
SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
191970
+ const char *zRet = 0;
191615191971
#ifdef SQLITE_ENABLE_API_ARMOR
191616191972
if( !sqlite3SafetyCheckOk(db) ){
191617191973
(void)SQLITE_MISUSE_BKPT;
191618191974
return 0;
191619191975
}
191620191976
#endif
191621
- if( N<0 || N>=db->nDb ){
191622
- return 0;
191623
- }else{
191624
- return db->aDb[N].zDbSName;
191977
+ sqlite3_mutex_enter(db->mutex);
191978
+ if( N>=0 && N<db->nDb ){
191979
+ zRet = db->aDb[N].zDbSName;
191625191980
}
191981
+ sqlite3_mutex_leave(db->mutex);
191982
+ return zRet;
191626191983
}
191627191984
191628191985
/*
191629191986
** Return the filename of the database associated with a database
191630191987
** connection.
@@ -197602,10 +197959,11 @@
197602197959
}else{
197603197960
int nDistance;
197604197961
char *p1;
197605197962
char *p2;
197606197963
char *aOut;
197964
+ i64 nAlloc = (i64)nPoslist*2 + FTS3_BUFFER_PADDING;
197607197965
197608197966
if( nMaxUndeferred>iPrev ){
197609197967
p1 = aPoslist;
197610197968
p2 = pPhrase->doclist.pList;
197611197969
nDistance = nMaxUndeferred - iPrev;
@@ -197613,11 +197971,11 @@
197613197971
p1 = pPhrase->doclist.pList;
197614197972
p2 = aPoslist;
197615197973
nDistance = iPrev - nMaxUndeferred;
197616197974
}
197617197975
197618
- aOut = (char *)sqlite3Fts3MallocZero(((i64)nPoslist)+FTS3_BUFFER_PADDING);
197976
+ aOut = (char *)sqlite3Fts3MallocZero(nAlloc);
197619197977
if( !aOut ){
197620197978
sqlite3_free(aPoslist);
197621197979
return SQLITE_NOMEM;
197622197980
}
197623197981
@@ -207898,11 +208256,11 @@
207898208256
if( nHeight<1 || nHeight>=FTS_MAX_APPENDABLE_HEIGHT ){
207899208257
sqlite3_reset(pSelect);
207900208258
return FTS_CORRUPT_VTAB;
207901208259
}
207902208260
207903
- pWriter->nLeafEst = (int)((iEnd - iStart) + 1)/FTS_MAX_APPENDABLE_HEIGHT;
208261
+ pWriter->nLeafEst = (int)(((iEnd - iStart)+1)/FTS_MAX_APPENDABLE_HEIGHT);
207904208262
pWriter->iStart = iStart;
207905208263
pWriter->iEnd = iEnd;
207906208264
pWriter->iAbsLevel = iAbsLevel;
207907208265
pWriter->iIdx = iIdx;
207908208266
@@ -215418,12 +215776,11 @@
215418215776
jsonBlobAppendNode(pParse, JSONB_TEXTRAW, nJson, zJson);
215419215777
}
215420215778
break;
215421215779
}
215422215780
case SQLITE_FLOAT: {
215423
- double r = sqlite3_value_double(pArg);
215424
- if( NEVER(sqlite3IsNaN(r)) ){
215781
+ if( NEVER(sqlite3IsNaN(sqlite3_value_double(pArg))) ){
215425215782
jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
215426215783
}else{
215427215784
int n = sqlite3_value_bytes(pArg);
215428215785
const char *z = (const char*)sqlite3_value_text(pArg);
215429215786
if( z==0 ) return 1;
@@ -218016,11 +218373,11 @@
218016218373
int mxLevel; /* iLevel value for root of the tree */
218017218374
RtreeSearchPoint *aPoint; /* Priority queue for search points */
218018218375
sqlite3_stmt *pReadAux; /* Statement to read aux-data */
218019218376
RtreeSearchPoint sPoint; /* Cached next search point */
218020218377
RtreeNode *aNode[RTREE_CACHE_SZ]; /* Rtree node cache */
218021
- u32 anQueue[RTREE_MAX_DEPTH+1]; /* Number of queued entries by iLevel */
218378
+ u32 anQueue[RTREE_MAX_DEPTH+2]; /* Number of queued entries by iLevel */
218022218379
};
218023218380
218024218381
/* Return the Rtree of a RtreeCursor */
218025218382
#define RTREE_OF_CURSOR(X) ((Rtree*)((X)->base.pVtab))
218026218383
@@ -218499,11 +218856,11 @@
218499218856
** are the leaves, and so on. If the depth as specified on the root node
218500218857
** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
218501218858
*/
218502218859
if( rc==SQLITE_OK && pNode && iNode==1 ){
218503218860
pRtree->iDepth = readInt16(pNode->zData);
218504
- if( pRtree->iDepth>RTREE_MAX_DEPTH ){
218861
+ if( pRtree->iDepth>=RTREE_MAX_DEPTH ){
218505218862
rc = SQLITE_CORRUPT_VTAB;
218506218863
RTREE_IS_CORRUPT(pRtree);
218507218864
}
218508218865
}
218509218866
@@ -234473,11 +234830,11 @@
234473234830
SessionBuffer *p,
234474234831
const char *zStr,
234475234832
int *pRc
234476234833
){
234477234834
int nStr = sqlite3Strlen30(zStr);
234478
- if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
234835
+ if( 0==sessionBufferGrow(p, (i64)nStr+1, pRc) ){
234479234836
memcpy(&p->aBuf[p->nBuf], zStr, nStr);
234480234837
p->nBuf += nStr;
234481234838
p->aBuf[p->nBuf] = 0x00;
234482234839
}
234483234840
}
@@ -239875,18 +240232,21 @@
239875240232
int nCol, /* Number of columns in each record */
239876240233
u8 *a1, int n1, /* Record 1 */
239877240234
u8 *a2, int n2, /* Record 2 */
239878240235
int *pRc /* IN/OUT: error code */
239879240236
){
239880
- sessionBufferGrow(pBuf, n1+n2, pRc);
240237
+ u8 *a1Eof = &a1[n1];
240238
+ u8 *a2Eof = &a2[n2];
240239
+
240240
+ sessionBufferGrow(pBuf, (i64)n1+n2, pRc);
239881240241
if( *pRc==SQLITE_OK ){
239882240242
int i;
239883240243
u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
239884240244
for(i=0; i<nCol; i++){
239885
- int nn1 = sessionSerialLen(a1);
239886
- int nn2 = sessionSerialLen(a2);
239887
- if( *a1==0 || *a1==0xFF ){
240245
+ int nn1 = (a1<a1Eof ? sessionSerialLen(a1) : 0);
240246
+ int nn2 = (a2<a2Eof ? sessionSerialLen(a2) : 0);
240247
+ if( nn1==0 || (nn2>0 && (*a1==0 || *a1==0xFF)) ){
239888240248
memcpy(pOut, a2, nn2);
239889240249
pOut += nn2;
239890240250
}else{
239891240251
memcpy(pOut, a1, nn1);
239892240252
pOut += nn1;
@@ -239924,11 +240284,11 @@
239924240284
sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */
239925240285
u8 *aRec, int nRec, /* Local change */
239926240286
u8 *aChange, int nChange, /* Record to rebase against */
239927240287
int *pRc /* IN/OUT: Return Code */
239928240288
){
239929
- sessionBufferGrow(pBuf, 2+nRec+nChange, pRc);
240289
+ sessionBufferGrow(pBuf, (i64)2+nRec+nChange, pRc);
239930240290
if( *pRc==SQLITE_OK ){
239931240291
int bData = 0;
239932240292
u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
239933240293
int i;
239934240294
u8 *a1 = aRec;
@@ -258623,13 +258983,17 @@
258623258983
iRowidOff = fts5LeafFirstRowidOff(pLeaf);
258624258984
if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
258625258985
FTS5_CORRUPT_ROWID(p, iRow);
258626258986
}else{
258627258987
iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
258628
- res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
258629
- if( res==0 ) res = nTerm - nIdxTerm;
258630
- if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
258988
+ if( iOff+nTerm>pLeaf->szLeaf ){
258989
+ FTS5_CORRUPT_ROWID(p, iRow);
258990
+ }else{
258991
+ res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
258992
+ if( res==0 ) res = nTerm - nIdxTerm;
258993
+ if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
258994
+ }
258631258995
}
258632258996
258633258997
fts5IntegrityCheckPgidx(p, iRow, pLeaf);
258634258998
}
258635258999
fts5DataRelease(pLeaf);
@@ -263267,11 +263631,11 @@
263267263631
int nArg, /* Number of args */
263268263632
sqlite3_value **apUnused /* Function arguments */
263269263633
){
263270263634
assert( nArg==0 );
263271263635
UNUSED_PARAM2(nArg, apUnused);
263272
- sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT);
263636
+ sqlite3_result_text(pCtx, "fts5: 2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c", -1, SQLITE_TRANSIENT);
263273263637
}
263274263638
263275263639
/*
263276263640
** Implementation of fts5_locale(LOCALE, TEXT) function.
263277263641
**
@@ -263909,38 +264273,35 @@
263909264273
263910264274
if( bCreate ){
263911264275
if( pConfig->eContent==FTS5_CONTENT_NORMAL
263912264276
|| pConfig->eContent==FTS5_CONTENT_UNINDEXED
263913264277
){
263914
- int nDefn = 32 + pConfig->nCol*10;
263915
- char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 20);
263916
- if( zDefn==0 ){
263917
- rc = SQLITE_NOMEM;
263918
- }else{
263919
- int i;
263920
- int iOff;
263921
- sqlite3_snprintf(nDefn, zDefn, "id INTEGER PRIMARY KEY");
263922
- iOff = (int)strlen(zDefn);
263923
- for(i=0; i<pConfig->nCol; i++){
263924
- if( pConfig->eContent==FTS5_CONTENT_NORMAL
263925
- || pConfig->abUnindexed[i]
263926
- ){
263927
- sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", c%d", i);
263928
- iOff += (int)strlen(&zDefn[iOff]);
263929
- }
263930
- }
263931
- if( pConfig->bLocale ){
263932
- for(i=0; i<pConfig->nCol; i++){
263933
- if( pConfig->abUnindexed[i]==0 ){
263934
- sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", l%d", i);
263935
- iOff += (int)strlen(&zDefn[iOff]);
263936
- }
263937
- }
263938
- }
263939
- rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
263940
- }
263941
- sqlite3_free(zDefn);
264278
+ int i = 0;
264279
+ char *zDefn = 0;
264280
+ sqlite3_str *pDefn = sqlite3_str_new(pConfig->db);
264281
+
264282
+ sqlite3_str_appendf(pDefn, "id INTEGER PRIMARY KEY");
264283
+ for(i=0; i<pConfig->nCol; i++){
264284
+ if( pConfig->eContent==FTS5_CONTENT_NORMAL || pConfig->abUnindexed[i] ){
264285
+ sqlite3_str_appendf(pDefn, ", c%d", i);
264286
+ }
264287
+ }
264288
+ if( pConfig->bLocale ){
264289
+ for(i=0; i<pConfig->nCol; i++){
264290
+ if( pConfig->abUnindexed[i]==0 ){
264291
+ sqlite3_str_appendf(pDefn, ", l%d", i);
264292
+ }
264293
+ }
264294
+ }
264295
+ zDefn = sqlite3_str_finish(pDefn);
264296
+
264297
+ if( zDefn ){
264298
+ rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
264299
+ sqlite3_free(zDefn);
264300
+ }else{
264301
+ rc = SQLITE_NOMEM;
264302
+ }
263942264303
}
263943264304
263944264305
if( rc==SQLITE_OK && pConfig->bColumnsize ){
263945264306
const char *zCols = "id INTEGER PRIMARY KEY, sz BLOB";
263946264307
if( pConfig->bContentlessDelete ){
263947264308
--- 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 ** 3f3fb9b638f59ad982beafb7c117f24ddd3d with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3732,11 +3732,11 @@
3732 ** authorizer will fail with an error message explaining that
3733 ** access is denied.
3734 **
3735 ** ^The first parameter to the authorizer callback is a copy of the third
3736 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3737 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
3738 ** the particular action to be authorized. ^The third through sixth parameters
3739 ** to the callback are either NULL pointers or zero-terminated strings
3740 ** that contain additional details about the action to be authorized.
3741 ** Applications must always be prepared to encounter a NULL pointer in any
3742 ** of the third through the sixth parameters of the authorization callback.
@@ -3775,25 +3775,37 @@
3775 ** ^(Only a single authorizer can be in place on a database connection
3776 ** at a time. Each call to sqlite3_set_authorizer overrides the
3777 ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
3778 ** The authorizer is disabled by default.
3779 **
3780 ** The authorizer callback must not do anything that will modify
 
 
3781 ** the database connection that invoked the authorizer callback.
3782 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3783 ** database connections for the meaning of "modify" in this paragraph.
3784 **
3785 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3786 ** statement might be re-prepared during [sqlite3_step()] due to a
3787 ** schema change. Hence, the application should ensure that the
3788 ** correct authorizer callback remains in place during the [sqlite3_step()].
3789 **
3790 ** ^Note that the authorizer callback is invoked only during
3791 ** [sqlite3_prepare()] or its variants. Authorization is not
3792 ** performed during statement evaluation in [sqlite3_step()], unless
3793 ** as stated in the previous paragraph, sqlite3_step() invokes
3794 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
 
 
 
 
 
 
 
 
 
 
3795 */
3796 SQLITE_API int sqlite3_set_authorizer(
3797 sqlite3*,
3798 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3799 void *pUserData
@@ -3864,12 +3876,17 @@
3864 #define SQLITE_ANALYZE 28 /* Table Name NULL */
3865 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
3866 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3867 #define SQLITE_FUNCTION 31 /* NULL Function Name */
3868 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3869 #define SQLITE_COPY 0 /* No longer used */
3870 #define SQLITE_RECURSIVE 33 /* NULL NULL */
 
 
 
 
 
 
3871
3872 /*
3873 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3874 ** DEPRECATED
3875 **
@@ -4860,10 +4877,12 @@
4860 ** there is a small performance advantage to passing an nByte parameter that
4861 ** is the number of bytes in the input string <i>including</i>
4862 ** the nul-terminator.
4863 ** Note that nByte measures the length of the input in bytes, not
4864 ** characters, even for the UTF-16 interfaces.
 
 
4865 **
4866 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4867 ** past the end of the first SQL statement in zSql. These routines only
4868 ** compile the first statement in zSql, so *pzTail is left pointing to
4869 ** what remains uncompiled.
@@ -5606,11 +5625,11 @@
5606 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5607 ** can be obtained by calling [sqlite3_reset()] on the
5608 ** [prepared statement]. ^In the "v2" interface,
5609 ** the more specific error code is returned directly by sqlite3_step().
5610 **
5611 ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
5612 ** Perhaps it was called on a [prepared statement] that has
5613 ** already been [sqlite3_finalize | finalized] or on one that had
5614 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
5615 ** be the case that the same database connection is being used by two or
5616 ** more threads at the same moment in time.
@@ -9117,12 +9136,12 @@
9117 ** The lifecycle of an sqlite3_str object is as follows:
9118 ** <ol>
9119 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
9120 ** <li> ^Text is appended to the sqlite3_str object using various
9121 ** methods, such as [sqlite3_str_appendf()].
9122 ** <li> ^The sqlite3_str object is destroyed and the string it created
9123 ** is returned using the [sqlite3_str_finish()] interface.
9124 ** </ol>
9125 */
9126 typedef struct sqlite3_str sqlite3_str;
9127
9128 /*
@@ -9170,10 +9189,44 @@
9170 ** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
9171 */
9172 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
9173 SQLITE_API void sqlite3_str_free(sqlite3_str*);
9174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9175 /*
9176 ** CAPI3REF: Add Content To A Dynamic String
9177 ** METHOD: sqlite3_str
9178 **
9179 ** These interfaces add or remove content to an sqlite3_str object
@@ -17190,11 +17243,11 @@
17190 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
17191 #endif
17192
17193 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
17194 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
17195 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
17196
17197 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
17198
17199 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
17200 ** of the flags shown below.
@@ -17267,16 +17320,23 @@
17267 ** The design of the _RANGE hint is aid b-tree implementations that try
17268 ** to prefetch content from remote machines - to provide those
17269 ** implementations with limits on what needs to be prefetched and thereby
17270 ** reduce network bandwidth.
17271 **
 
 
 
 
 
 
17272 ** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
17273 ** standard SQLite. The other hints are provided for extensions that use
17274 ** the SQLite parser and code generator but substitute their own storage
17275 ** engine.
17276 */
17277 #define BTREE_HINT_RANGE 0 /* Range constraints on queries */
 
17278
17279 /*
17280 ** Values that may be OR'd together to form the argument to the
17281 ** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
17282 **
@@ -17332,10 +17392,13 @@
17332 #endif
17333 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
17334 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
17335 #ifdef SQLITE_ENABLE_CURSOR_HINTS
17336 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
 
 
 
17337 #endif
17338
17339 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
17340 SQLITE_PRIVATE int sqlite3BtreeTableMoveto(
17341 BtCursor*,
@@ -20940,16 +21003,16 @@
20940 bft bHasExists :1; /* Has a correlated "EXISTS (SELECT ....)" expression */
20941 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
20942 bft bHasWith :1; /* True if statement contains WITH */
20943 bft okConstFactor:1; /* OK to factor out constants */
20944 bft checkSchema :1; /* Causes schema cookie check after an error */
 
20945 int nRangeReg; /* Size of the temporary register block */
20946 int iRangeReg; /* First register in temporary register block */
20947 int nErr; /* Number of errors seen */
20948 int nTab; /* Number of previously allocated VDBE cursors */
20949 int nMem; /* Number of memory cells used so far */
20950 int szOpAlloc; /* Bytes of memory space allocated for Vdbe.aOp[] */
20951 int iSelfTab; /* Table associated with an index on expr, or negative
20952 ** of the base register during check-constraint eval */
20953 int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
20954 int nLabel; /* The *negative* of the number of labels used */
20955 int nLabelAlloc; /* Number of slots in aLabel */
@@ -20964,13 +21027,11 @@
20964 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
20965 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
20966 #endif
20967 #ifndef SQLITE_OMIT_SHARED_CACHE
20968 int nTableLock; /* Number of locks in aTableLock */
20969 TableLock *aTableLock; /* Required table locks for shared-cache mode */
20970 #endif
20971 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
20972 Parse *pToplevel; /* Parse structure for main program (or NULL) */
20973 Table *pTriggerTab; /* Table triggers are being coded for */
20974 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
20975 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
20976
@@ -20995,10 +21056,17 @@
20995 } cr;
20996 struct { /* These fields available to all other statements */
20997 Returning *pReturning; /* The RETURNING clause */
20998 } d;
20999 } u1;
 
 
 
 
 
 
 
21000
21001 /************************************************************************
21002 ** Above is constant between recursions. Below is reset before and after
21003 ** each recursion. The boundary between these two regions is determined
21004 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -22528,10 +22596,11 @@
22528 SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
22529 SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
22530 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
22531 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
22532 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
 
22533 #ifndef SQLITE_OMIT_WSD
22534 SQLITE_PRIVATE int sqlite3PendingByte;
22535 #endif
22536 #endif /* SQLITE_AMALGAMATION */
22537 #ifdef VDBE_PROFILE
@@ -22630,11 +22699,10 @@
22630 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
22631 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
22632 SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum*, i64);
22633 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
22634 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
22635 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
22636 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
22637 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
22638 SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
22639 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
22640
@@ -24228,10 +24296,20 @@
24228 ** Hash table for global functions - functions common to all
24229 ** database connections. After initialization, this table is
24230 ** read-only.
24231 */
24232 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
 
 
 
 
 
 
 
 
 
 
24233
24234 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
24235 /*
24236 ** Counter used for coverage testing. Does not come into play for
24237 ** release builds.
@@ -26947,42 +27025,42 @@
26947 ){
26948 DateTime x;
26949 size_t i,j;
26950 sqlite3 *db;
26951 const char *zFmt;
26952 sqlite3_str sRes;
26953
26954
26955 if( argc==0 ) return;
26956 zFmt = (const char*)sqlite3_value_text(argv[0]);
26957 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
26958 db = sqlite3_context_db_handle(context);
26959 sqlite3StrAccumInit(&sRes, 0, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
26960
26961 computeJD(&x);
26962 computeYMD_HMS(&x);
26963 for(i=j=0; zFmt[i]; i++){
26964 char cf;
26965 if( zFmt[i]!='%' ) continue;
26966 if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
26967 i++;
26968 j = i + 1;
26969 cf = zFmt[i];
26970 switch( cf ){
26971 case 'd': /* Fall thru */
26972 case 'e': {
26973 sqlite3_str_appendf(&sRes, cf=='d' ? "%02d" : "%2d", x.D);
26974 break;
26975 }
26976 case 'f': { /* Fractional seconds. (Non-standard) */
26977 double s = x.s;
26978 if( NEVER(s>59.999) ) s = 59.999;
26979 sqlite3_str_appendf(&sRes, "%06.3f", s);
26980 break;
26981 }
26982 case 'F': {
26983 sqlite3_str_appendf(&sRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
26984 break;
26985 }
26986 case 'G': /* Fall thru */
26987 case 'g': {
26988 DateTime y = x;
@@ -26990,85 +27068,85 @@
26990 /* Move y so that it is the Thursday in the same week as x */
26991 y.iJD += (3 - daysAfterMonday(&x))*86400000;
26992 y.validYMD = 0;
26993 computeYMD(&y);
26994 if( cf=='g' ){
26995 sqlite3_str_appendf(&sRes, "%02d", y.Y%100);
26996 }else{
26997 sqlite3_str_appendf(&sRes, "%04d", y.Y);
26998 }
26999 break;
27000 }
27001 case 'H':
27002 case 'k': {
27003 sqlite3_str_appendf(&sRes, cf=='H' ? "%02d" : "%2d", x.h);
27004 break;
27005 }
27006 case 'I': /* Fall thru */
27007 case 'l': {
27008 int h = x.h;
27009 if( h>12 ) h -= 12;
27010 if( h==0 ) h = 12;
27011 sqlite3_str_appendf(&sRes, cf=='I' ? "%02d" : "%2d", h);
27012 break;
27013 }
27014 case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */
27015 sqlite3_str_appendf(&sRes,"%03d",daysAfterJan01(&x)+1);
27016 break;
27017 }
27018 case 'J': { /* Julian day number. (Non-standard) */
27019 sqlite3_str_appendf(&sRes,"%.16g",x.iJD/86400000.0);
27020 break;
27021 }
27022 case 'm': {
27023 sqlite3_str_appendf(&sRes,"%02d",x.M);
27024 break;
27025 }
27026 case 'M': {
27027 sqlite3_str_appendf(&sRes,"%02d",x.m);
27028 break;
27029 }
27030 case 'p': /* Fall thru */
27031 case 'P': {
27032 if( x.h>=12 ){
27033 sqlite3_str_append(&sRes, cf=='p' ? "PM" : "pm", 2);
27034 }else{
27035 sqlite3_str_append(&sRes, cf=='p' ? "AM" : "am", 2);
27036 }
27037 break;
27038 }
27039 case 'R': {
27040 sqlite3_str_appendf(&sRes, "%02d:%02d", x.h, x.m);
27041 break;
27042 }
27043 case 's': {
27044 if( x.useSubsec ){
27045 sqlite3_str_appendf(&sRes,"%.3f",
27046 (x.iJD - 21086676*(i64)10000000)/1000.0);
27047 }else{
27048 i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
27049 sqlite3_str_appendf(&sRes,"%lld",iS);
27050 }
27051 break;
27052 }
27053 case 'S': {
27054 sqlite3_str_appendf(&sRes,"%02d",(int)x.s);
27055 break;
27056 }
27057 case 'T': {
27058 sqlite3_str_appendf(&sRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
27059 break;
27060 }
27061 case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */
27062 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */
27063 char c = (char)daysAfterSunday(&x) + '0';
27064 if( c=='0' && cf=='u' ) c = '7';
27065 sqlite3_str_appendchar(&sRes, 1, c);
27066 break;
27067 }
27068 case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */
27069 sqlite3_str_appendf(&sRes,"%02d",
27070 (daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7);
27071 break;
27072 }
27073 case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */
27074 DateTime y = x;
@@ -27075,34 +27153,34 @@
27075 /* Adjust y so that is the Thursday in the same week as x */
27076 assert( y.validJD );
27077 y.iJD += (3 - daysAfterMonday(&x))*86400000;
27078 y.validYMD = 0;
27079 computeYMD(&y);
27080 sqlite3_str_appendf(&sRes,"%02d", daysAfterJan01(&y)/7+1);
27081 break;
27082 }
27083 case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */
27084 sqlite3_str_appendf(&sRes,"%02d",
27085 (daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7);
27086 break;
27087 }
27088 case 'Y': {
27089 sqlite3_str_appendf(&sRes,"%04d",x.Y);
27090 break;
27091 }
27092 case '%': {
27093 sqlite3_str_appendchar(&sRes, 1, '%');
27094 break;
27095 }
27096 default: {
27097 sqlite3_str_reset(&sRes);
27098 return;
27099 }
27100 }
27101 }
27102 if( j<i ) sqlite3_str_append(&sRes, zFmt+j, (int)(i-j));
27103 sqlite3ResultStrAccum(context, &sRes);
27104 }
27105
27106 /*
27107 ** current_time()
27108 **
@@ -27234,11 +27312,11 @@
27234 clearYMD_HMS_TZ(&d1);
27235 computeYMD_HMS(&d1);
27236 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100);
27237 sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f",
27238 sign, Y, M, d1.D-1, d1.h, d1.m, d1.s);
27239 sqlite3ResultStrAccum(context, &sRes);
27240 }
27241
27242
27243 /*
27244 ** current_timestamp()
@@ -27662,11 +27740,11 @@
27662 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
27663 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
27664 }else{
27665 double r;
27666 rc = pVfs->xCurrentTime(pVfs, &r);
27667 *pTimeOut = (sqlite3_int64)(r*86400000.0);
27668 }
27669 return rc;
27670 }
27671
27672 SQLITE_PRIVATE int sqlite3OsOpenMalloc(
@@ -32612,10 +32690,14 @@
32612 */
32613 #ifndef SQLITE_PRINTF_PRECISION_LIMIT
32614 # define SQLITE_FP_PRECISION_LIMIT 100000000
32615 #endif
32616
 
 
 
 
32617 /*
32618 ** Render a string given by "fmt" into the StrAccum object.
32619 */
32620 SQLITE_API void sqlite3_str_vappendf(
32621 sqlite3_str *pAccum, /* Accumulate results here */
@@ -32622,14 +32704,14 @@
32622 const char *fmt, /* Format string */
32623 va_list ap /* arguments */
32624 ){
32625 int c; /* Next character in the format string */
32626 char *bufpt; /* Pointer to the conversion buffer */
32627 int precision; /* Precision of the current field */
32628 int length; /* Length of the field */
32629 int idx; /* A general purpose loop counter */
32630 int width; /* Width of the current field */
32631 etByte flag_leftjustify; /* True if "-" flag is present */
32632 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
32633 etByte flag_alternateform; /* True if "#" flag is present */
32634 etByte flag_altform2; /* True if "!" flag is present */
32635 etByte flag_zeropad; /* True if field width constant starts with zero */
@@ -32673,11 +32755,11 @@
32673 fmt = strchr(fmt, '%');
32674 if( fmt==0 ){
32675 fmt = bufpt + strlen(bufpt);
32676 }
32677 #endif
32678 sqlite3_str_append(pAccum, bufpt, (int)(fmt - bufpt));
32679 if( *fmt==0 ) break;
32680 }
32681 if( (c=(*++fmt))==0 ){
32682 sqlite3_str_append(pAccum, "%", 1);
32683 break;
@@ -32919,26 +33001,27 @@
32919 do{ /* Convert to ascii */
32920 *(--bufpt) = cset[longvalue%base];
32921 longvalue = longvalue/base;
32922 }while( longvalue>0 );
32923 }
32924 length = (int)(&zOut[nOut-1]-bufpt);
32925 if( precision>length ){ /* zero pad */
32926 int nn = precision-length;
32927 bufpt -= nn;
32928 memset(bufpt,'0',nn);
32929 length = precision;
32930 }
32931 if( cThousand ){
32932 int nn = (length - 1)/3; /* Number of "," to insert */
32933 int ix = (length - 1)%3 + 1;
 
32934 bufpt -= nn;
32935 for(idx=0; nn>0; idx++){
32936 bufpt[idx] = bufpt[idx+nn];
32937 ix--;
32938 if( ix==0 ){
32939 bufpt[++idx] = cThousand;
32940 nn--;
32941 ix = 3;
32942 }
32943 }
32944 }
@@ -32947,11 +33030,11 @@
32947 const char *pre;
32948 char x;
32949 pre = &aPrefix[infop->prefix];
32950 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
32951 }
32952 length = (int)(&zOut[nOut-1]-bufpt);
32953 break;
32954 case etFLOAT:
32955 case etEXP:
32956 case etGENERIC: {
32957 FpDecode s;
@@ -32979,12 +33062,17 @@
32979 iRound = precision+1;
32980 }
32981 sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 20 : 16);
32982 if( s.isSpecial ){
32983 if( s.isSpecial==2 ){
32984 bufpt = flag_zeropad ? "null" : "NaN";
32985 length = sqlite3Strlen30(bufpt);
 
 
 
 
 
32986 break;
32987 }else if( flag_zeropad ){
32988 s.z[0] = '9';
32989 s.iDP = 1000;
32990 s.n = 1;
@@ -32996,11 +33084,11 @@
32996 }else if( flag_prefix ){
32997 buf[0] = flag_prefix;
32998 }else{
32999 bufpt++;
33000 }
33001 length = sqlite3Strlen30(bufpt);
33002 break;
33003 }
33004 }
33005 if( s.sign=='-' ){
33006 if( flag_alternateform
@@ -33152,11 +33240,11 @@
33152 }
33153 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */
33154 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */
33155 }
33156
33157 length = (int)(bufpt-zOut);
33158 assert( length <= szBufNeeded );
33159 if( length<width ){
33160 i64 nPad = width - length;
33161 if( flag_leftjustify ){
33162 memset(bufpt, ' ', nPad);
@@ -33172,10 +33260,11 @@
33172 }
33173
33174 if( zExtra==0 ){
33175 /* The result is being rendered directory into pAccum. This
33176 ** is the common and fast case */
 
33177 pAccum->nChar += length;
33178 zOut[length] = 0;
33179 continue;
33180 }else{
33181 /* We were unable to render directly into pAccum because we
@@ -33218,14 +33307,14 @@
33218 }
33219 if( precision>1 ){
33220 i64 nPrior = 1;
33221 width -= precision-1;
33222 if( width>1 && !flag_leftjustify ){
33223 sqlite3_str_appendchar(pAccum, width-1, ' ');
33224 width = 0;
33225 }
33226 sqlite3_str_append(pAccum, buf, length);
33227 precision--;
33228 while( precision > 1 ){
33229 i64 nCopyBytes;
33230 if( nPrior > precision-1 ) nPrior = precision - 1;
33231 nCopyBytes = length*nPrior;
@@ -33277,21 +33366,21 @@
33277 ** precision characters */
33278 unsigned char *z = (unsigned char*)bufpt;
33279 while( precision-- > 0 && z[0] ){
33280 SQLITE_SKIP_UTF8(z);
33281 }
33282 length = (int)(z - (unsigned char*)bufpt);
33283 }else{
33284 for(length=0; length<precision && bufpt[length]; length++){}
33285 }
33286 }else{
33287 length = 0x7fffffff & (int)strlen(bufpt);
33288 }
33289 adjust_width_for_utf8:
33290 if( flag_altform2 && width>0 ){
33291 /* Adjust width to account for extra bytes in UTF-8 characters */
33292 int ii = length - 1;
33293 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
33294 }
33295 break;
33296 case etESCAPE_j: /* %j: JSON string literal w/o "..." */
33297 case etESCAPE_J: { /* %J: Generate a JSON string literal */
@@ -33322,11 +33411,11 @@
33322 while( (escarg[px]&0xc0)==0x80 ) px++;
33323 }
33324 }
33325 for(i=j=0; i<px; i++){
33326 if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){
33327 if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33328 j = i+1;
33329 if( ch==0 ) break;
33330 sqlite3_str_appendchar(pAccum, 1, '\\');
33331 if( ch>0x1f ){
33332 sqlite3_str_appendchar(pAccum, 1, ch);
@@ -33338,11 +33427,11 @@
33338 sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]);
33339 sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]);
33340 }
33341 }
33342 }
33343 if( j<i ) sqlite3_str_append(pAccum, &escarg[j], i-j);
33344 if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33345 }
33346 if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){
33347 sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart;
33348 sqlite3_int64 len = n;
@@ -33354,11 +33443,11 @@
33354 }
33355 }
33356 if( width>len ){
33357 sqlite3_int64 sp = width-len;
33358 assert( sp>0 && sp<0x7fffffff );
33359 sqlite3_str_appendchar(pAccum, (int)sp, ' ');
33360 if( !flag_leftjustify
33361 && n>0
33362 && sqlite3_str_errcode(pAccum)==0
33363 ){
33364 zz = sqlite3_str_value(pAccum);
@@ -33546,15 +33635,15 @@
33546 ** indicating that width and precision should be expressed in characters,
33547 ** then the values have been translated prior to reaching this point.
33548 */
33549 width -= length;
33550 if( width>0 ){
33551 if( !flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
33552 sqlite3_str_append(pAccum, bufpt, length);
33553 if( flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
33554 }else{
33555 sqlite3_str_append(pAccum, bufpt, length);
33556 }
33557
33558 if( zExtra ){
33559 sqlite3DbFree(pAccum->db, zExtra);
33560 zExtra = 0;
@@ -33670,10 +33759,17 @@
33670 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
33671 return;
33672 }
33673 while( (N--)>0 ) p->zText[p->nChar++] = c;
33674 }
 
 
 
 
 
 
 
33675
33676 /*
33677 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
33678 ** So enlarge if first, then do the append.
33679 **
@@ -33704,10 +33800,24 @@
33704 assert( p->zText );
33705 p->nChar += N;
33706 memcpy(&p->zText[p->nChar-N], z, N);
33707 }
33708 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33709
33710 /*
33711 ** Append the complete text of zero-terminated string z[] to the p string.
33712 */
33713 SQLITE_API void sqlite3_str_appendall(sqlite3_str *p, const char *z){
@@ -33741,41 +33851,15 @@
33741 }
33742 }
33743 return p->zText;
33744 }
33745
33746 /*
33747 ** Use the content of the StrAccum passed as the second argument
33748 ** as the result of an SQL function.
33749 */
33750 SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context *pCtx, StrAccum *p){
33751 if( p->accError ){
33752 sqlite3_result_error_code(pCtx, p->accError);
33753 sqlite3_str_reset(p);
33754 }else if( isMalloced(p) ){
33755 sqlite3_result_text(pCtx, p->zText, p->nChar, SQLITE_DYNAMIC);
33756 }else{
33757 sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
33758 sqlite3_str_reset(p);
33759 }
33760 }
33761
33762 /*
33763 ** This singleton is an sqlite3_str object that is returned if
33764 ** sqlite3_malloc() fails to provide space for a real one. This
33765 ** sqlite3_str object accepts no new text and always returns
33766 ** an SQLITE_NOMEM error.
33767 */
33768 static sqlite3_str sqlite3OomStr = {
33769 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
33770 };
33771
33772 /* Finalize a string created using sqlite3_str_new().
33773 */
33774 SQLITE_API char *sqlite3_str_finish(sqlite3_str *p){
33775 char *z;
33776 if( p!=0 && p!=&sqlite3OomStr ){
33777 z = sqlite3StrAccumFinish(p);
33778 sqlite3_free(p);
33779 }else{
33780 z = 0;
33781 }
@@ -33812,10 +33896,12 @@
33812 */
33813 SQLITE_API void sqlite3_str_reset(StrAccum *p){
33814 if( isMalloced(p) ){
33815 sqlite3DbFree(p->db, p->zText);
33816 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
 
 
33817 }
33818 p->nAlloc = 0;
33819 p->nChar = 0;
33820 p->zText = 0;
33821 }
@@ -33823,11 +33909,11 @@
33823 /*
33824 ** Destroy a dynamically allocate sqlite3_str object and all
33825 ** of its content, all in one call.
33826 */
33827 SQLITE_API void sqlite3_str_free(sqlite3_str *p){
33828 if( p!=0 && p!=&sqlite3OomStr ){
33829 sqlite3_str_reset(p);
33830 sqlite3_free(p);
33831 }
33832 }
33833
@@ -33860,11 +33946,11 @@
33860 sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
33861 if( p ){
33862 sqlite3StrAccumInit(p, 0, 0, 0,
33863 db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
33864 }else{
33865 p = &sqlite3OomStr;
33866 }
33867 return p;
33868 }
33869
33870 /*
@@ -37500,11 +37586,11 @@
37500 return mState;
37501 }
37502 }
37503 return 0xfffffff0 | mState;
37504 #else
37505 return sqlite3Atoi64(z, pResult, strlen(z), SQLITE_UTF8)==0;
37506 #endif /* SQLITE_OMIT_FLOATING_POINT */
37507 }
37508
37509 /*
37510 ** Digit pairs used to convert a U64 or I64 into text, two digits
@@ -39731,20 +39817,21 @@
39731 i = 0;
39732 j = 0;
39733 while( 1 ){
39734 c = kvvfsHexValue[aIn[i]];
39735 if( c<0 ){
39736 int n = 0;
39737 int mult = 1;
39738 c = aIn[i];
39739 if( c==0 ) break;
39740 while( c>='a' && c<='z' ){
39741 n += (c - 'a')*mult;
 
39742 mult *= 26;
39743 c = aIn[++i];
39744 }
39745 if( j+n>nOut ) return -1;
39746 memset(&aOut[j], 0, n);
39747 j += n;
39748 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
39749 }else if( j<nOut ){
39750 aOut[j] = c<<4;
@@ -39773,22 +39860,28 @@
39773 static void kvvfsDecodeJournal(
39774 KVVfsFile *pFile, /* Store decoding in pFile->aJrnl */
39775 const char *zTxt, /* Text encoding. Zero-terminated */
39776 int nTxt /* Bytes in zTxt, excluding zero terminator */
39777 ){
39778 unsigned int n = 0;
39779 int c, i, mult;
39780 i = 0;
39781 mult = 1;
39782 while( (c = zTxt[i++])>='a' && c<='z' ){
39783 n += (zTxt[i] - 'a')*mult;
 
 
 
39784 mult *= 26;
 
39785 }
39786 sqlite3_free(pFile->aJrnl);
 
 
 
39787 pFile->aJrnl = sqlite3_malloc64( n );
39788 if( pFile->aJrnl==0 ){
39789 pFile->nJrnl = 0;
39790 return;
39791 }
39792 pFile->nJrnl = n;
39793 n = kvvfsDecode(zTxt+i, pFile->aJrnl, pFile->nJrnl);
39794 if( n<pFile->nJrnl ){
@@ -39824,13 +39917,11 @@
39824
39825 SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass,
39826 pFile->isJournal ? "journal" : "db"));
39827 sqlite3_free(pFile->aJrnl);
39828 sqlite3_free(pFile->aData);
39829 #ifdef SQLITE_WASM
39830 memset(pFile, 0, sizeof(*pFile));
39831 #endif
39832 return SQLITE_OK;
39833 }
39834
39835 /*
39836 ** Read from the -journal file.
@@ -39856,10 +39947,11 @@
39856 if( aTxt==0 ) return SQLITE_NOMEM;
39857 rc = sqlite3KvvfsMethods.xRcrdRead(pFile->zClass, "jrnl",
39858 aTxt, szTxt+1);
39859 if( rc>=0 ){
39860 kvvfsDecodeJournal(pFile, aTxt, szTxt);
 
39861 }
39862 sqlite3_free(aTxt);
39863 if( rc ) return rc;
39864 if( pFile->aJrnl==0 ) return SQLITE_IOERR;
39865 }
@@ -40180,11 +40272,11 @@
40180 }
40181 if( !pFile->zClass ){
40182 #ifdef SQLITE_WASM
40183 if( strlen(zName) >= (KVRECORD_KEY_SZ
40184 - 6 /* "kvvfs-" */
40185 - 11 /* "-##########" */) ){
40186 return SQLITE_CANTOPEN;
40187 }
40188 #else
40189 if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){
40190 /* Historical naming restriction which journaling depends on. */
@@ -52221,11 +52313,11 @@
52221 # define sqlite3_win_test_unc_locking 0
52222 #endif
52223
52224 /*
52225 ** Return true if the string passed as the only argument is likely
52226 ** to be a UNC path. Return false if note.
52227 **
52228 ** Return true if:
52229 **
52230 ** (1) The name begins with "\\"
52231 ** (2) But does not begin with "\\?\C:\" where C can be any alphabetic
@@ -55070,26 +55162,27 @@
55070 int iDb;
55071 Btree *pBt;
55072 sqlite3_int64 sz;
55073 int szPage = 0;
55074 sqlite3_stmt *pStmt = 0;
55075 unsigned char *pOut;
55076 char *zSql;
55077 int rc;
55078
55079 #ifdef SQLITE_ENABLE_API_ARMOR
55080 if( !sqlite3SafetyCheckOk(db) ){
55081 (void)SQLITE_MISUSE_BKPT;
55082 return 0;
55083 }
55084 #endif
 
55085
55086 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
55087 p = memdbFromDbSchema(db, zSchema);
55088 iDb = sqlite3FindDbName(db, zSchema);
55089 if( piSize ) *piSize = -1;
55090 if( iDb<0 ) return 0;
55091 if( p ){
55092 MemStore *pStore = p->pStore;
55093 assert( pStore->pMutex==0 );
55094 if( piSize ) *piSize = pStore->sz;
55095 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
@@ -55096,23 +55189,21 @@
55096 pOut = pStore->aData;
55097 }else{
55098 pOut = sqlite3_malloc64( pStore->sz );
55099 if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
55100 }
55101 return pOut;
55102 }
55103 pBt = db->aDb[iDb].pBt;
55104 if( pBt==0 ) return 0;
55105 szPage = sqlite3BtreeGetPageSize(pBt);
55106 zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema);
55107 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
55108 sqlite3_free(zSql);
55109 if( rc ) return 0;
55110 rc = sqlite3_step(pStmt);
55111 if( rc!=SQLITE_ROW ){
55112 pOut = 0;
55113 }else{
55114 sz = sqlite3_column_int64(pStmt, 0)*szPage;
55115 if( sz==0 ){
55116 sqlite3_reset(pStmt);
55117 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
55118 rc = sqlite3_step(pStmt);
@@ -55142,10 +55233,13 @@
55142 }
55143 }
55144 }
55145 }
55146 sqlite3_finalize(pStmt);
 
 
 
55147 return pOut;
55148 }
55149
55150 /* Convert zSchema to a MemDB and initialize its content.
55151 */
@@ -59917,10 +60011,45 @@
59917 static void freeSuperJournal(char *zSuper){
59918 if( zSuper ){
59919 sqlite3_free(&zSuper[-4]);
59920 }
59921 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59922
59923 /*
59924 ** Parameter pJrnl is a file-handle open on a journal file. This function
59925 ** attempts to read a super-journal file name from the end of the journal
59926 ** file. If successful, it sets output parameter (*pzSuper) to point to a
@@ -59955,32 +60084,34 @@
59955 || len>=nSuper
59956 || len>szJ-16
59957 || len==0
59958 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
59959 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
59960 || memcmp(aMagic, aJournalMagic, 8)
59961 ){
59962 return rc;
59963 }
59964
59965 zOut = (char*)sqlite3MallocZero(4 + len + 2);
59966 if( !zOut ){
59967 rc = SQLITE_NOMEM_BKPT;
59968 }else{
59969 zOut = &zOut[4];
59970 if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){
59971 u32 u; /* Unsigned loop counter */
59972 /* See if the checksum matches the super-journal name */
59973 for(u=0; u<len; u++){
59974 cksum -= zOut[u];
59975 }
59976 }
59977 if( rc!=SQLITE_OK || cksum ){
59978 /* If the checksum doesn't add up, then one or more of the disk sectors
59979 ** containing the super-journal filename is corrupted. This means
59980 ** definitely roll back, so just return SQLITE_OK and report a (nul)
59981 ** super-journal filename. */
 
 
 
59982 freeSuperJournal(zOut);
59983 zOut = 0;
59984 }
59985 }
59986
@@ -60359,10 +60490,11 @@
60359 i64 jrnlSize; /* Size of journal file on disk */
60360 u32 cksum = 0; /* Checksum of string zSuper */
60361
60362 assert( pPager->setSuper==0 );
60363 assert( !pagerUseWal(pPager) );
 
60364
60365 if( !zSuper
60366 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
60367 || !isOpen(pPager->jfd)
60368 ){
@@ -61189,10 +61321,23 @@
61189 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
61190 char *zSuperJournal = 0; /* Contents of super-journal file */
61191 i64 nSuperJournal; /* Size of super-journal file */
61192 char *zJournal; /* Pointer to one journal within MJ file */
61193 char *zFree = 0; /* Free this buffer */
 
 
 
 
 
 
 
 
 
 
 
 
 
61194
61195 /* Allocate space for both the pJournal and pSuper file descriptors.
61196 ** If successful, open the super-journal file for reading.
61197 */
61198 pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61228,51 +61373,60 @@
61228 zSuperJournal[nSuperJournal] = 0;
61229 zSuperJournal[nSuperJournal+1] = 0;
61230
61231 zJournal = zSuperJournal;
61232 while( (zJournal-zSuperJournal)<nSuperJournal ){
61233 int exists;
61234 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61235 if( rc!=SQLITE_OK ){
61236 goto delsuper_out;
61237 }
61238 if( exists ){
61239 char *zSuperPtr = 0;
61240
61241 /* One of the journals pointed to by the super-journal exists.
61242 ** Open it and check if it points at the super-journal. If
61243 ** so, return without deleting the super-journal file.
61244 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61245 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
61246 ** name into sqlite3_database_file_object().
61247 */
61248 int c;
61249 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
61250 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61251 if( rc!=SQLITE_OK ){
61252 goto delsuper_out;
61253 }
61254
61255 rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
61256 sqlite3OsClose(pJournal);
61257 if( rc!=SQLITE_OK ){
61258 assert( zSuperPtr==0 );
61259 goto delsuper_out;
61260 }
61261
61262 c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61263 freeSuperJournal(zSuperPtr);
61264 if( c ){
61265 /* We have a match. Do not delete the super-journal file. */
61266 goto delsuper_out;
 
 
 
 
61267 }
61268 }
61269 zJournal += (sqlite3Strlen30(zJournal)+1);
61270 }
61271
61272 sqlite3OsClose(pSuper);
61273 rc = sqlite3OsDelete(pVfs, zSuper, 0);
 
 
 
 
 
61274
61275 delsuper_out:
61276 sqlite3_free(zFree);
61277 if( pSuper ){
61278 sqlite3OsClose(pSuper);
@@ -71674,10 +71828,13 @@
71674 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
71675 ** Error code if eState==CURSOR_FAULT */
71676 Btree *pBtree; /* The Btree to which this cursor belongs */
71677 Pgno *aOverflow; /* Cache of overflow page locations */
71678 void *pKey; /* Saved key that was cursor last known position */
 
 
 
71679 /* All fields above are zeroed when the cursor is allocated. See
71680 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
71681 ** initialized. */
71682 #define BTCURSOR_FIRST_UNINIT pBt /* Name of first uninitialized field */
71683 BtShared *pBt; /* The BtShared this cursor points to */
@@ -71850,10 +72007,13 @@
71850 int v2; /* Value for third %d substitution in zPfx */
71851 StrAccum errMsg; /* Accumulate the error message text here */
71852 u32 *heap; /* Min-heap used for analyzing cell coverage */
71853 sqlite3 *db; /* Database connection running the check */
71854 i64 nRow; /* Number of rows visited in current tree */
 
 
 
71855 };
71856
71857 /*
71858 ** Routines to read or write a two- and four-byte big-endian integer values.
71859 */
@@ -73178,28 +73338,45 @@
73178 ** parameter. See the definitions of the BTREE_HINT_* macros for details.
73179 */
73180 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){
73181 /* Used only by system that substitute their own storage engine */
73182 #ifdef SQLITE_DEBUG
73183 if( ALWAYS(eHintType==BTREE_HINT_RANGE) ){
73184 va_list ap;
 
73185 Expr *pExpr;
73186 Walker w;
73187 memset(&w, 0, sizeof(w));
73188 w.xExprCallback = sqlite3CursorRangeHintExprCheck;
73189 va_start(ap, eHintType);
73190 pExpr = va_arg(ap, Expr*);
73191 w.u.aMem = va_arg(ap, Mem*);
73192 va_end(ap);
73193 assert( pExpr!=0 );
73194 assert( w.u.aMem!=0 );
73195 sqlite3WalkExpr(&w, pExpr);
 
 
 
 
 
 
 
73196 }
 
73197 #endif /* SQLITE_DEBUG */
73198 }
73199 #endif /* SQLITE_ENABLE_CURSOR_HINTS */
73200
 
 
 
 
 
 
 
 
 
 
73201
73202 /*
73203 ** Provide flag hints to the cursor.
73204 */
73205 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){
@@ -74321,12 +74498,16 @@
74321 /* Freeblock off the end of the page */
74322 return SQLITE_CORRUPT_PAGE(pPage);
74323 }
74324 next = get2byte(&data[pc]);
74325 size = get2byte(&data[pc+2]);
 
 
 
 
74326 nFree = nFree + size;
74327 if( next<=pc+size+3 ) break;
74328 pc = next;
74329 }
74330 if( next>0 ){
74331 /* Freeblock not in ascending order */
74332 return SQLITE_CORRUPT_PAGE(pPage);
@@ -78157,18 +78338,18 @@
78157 nCell = pCell[0];
78158 if( nCell<=pPage->max1bytePayload ){
78159 /* This branch runs if the record-size field of the cell is a
78160 ** single byte varint and the record fits entirely on the main
78161 ** b-tree page. */
78162 testcase( pCell+nCell+1==pPage->aDataEnd );
78163 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
78164 }else if( !(pCell[1] & 0x80)
78165 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
78166 ){
78167 /* The record-size field is a 2 byte varint and the record
78168 ** fits entirely on the main b-tree page. */
78169 testcase( pCell+nCell+2==pPage->aDataEnd );
78170 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
78171 }else{
78172 /* If the record extends into overflow pages, do not attempt
78173 ** the optimization. */
78174 c = 99;
@@ -78326,18 +78507,21 @@
78326 nCell = pCell[0];
78327 if( nCell<=pPage->max1bytePayload ){
78328 /* This branch runs if the record-size field of the cell is a
78329 ** single byte varint and the record fits entirely on the main
78330 ** b-tree page. */
78331 testcase( pCell+nCell+1==pPage->aDataEnd );
 
 
 
78332 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
78333 }else if( !(pCell[1] & 0x80)
78334 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
 
78335 ){
78336 /* The record-size field is a 2 byte varint and the record
78337 ** fits entirely on the main b-tree page. */
78338 testcase( pCell+nCell+2==pPage->aDataEnd );
78339 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
78340 }else{
78341 /* The record flows over onto one or more overflow pages. In
78342 ** this case the whole cell needs to be parsed, a buffer allocated
78343 ** and accessPayload() used to retrieve the record into the
@@ -83203,10 +83387,11 @@
83203 checkAppendMsg(pCheck, "Child page depth differs");
83204 depth = d2;
83205 }
83206 }else{
83207 /* Populate the coverage-checking heap for leaf pages */
 
83208 btreeHeapInsert(heap, (pc<<16)|(pc+info.nSize-1));
83209 }
83210 }
83211 *piMinKey = maxKey;
83212
@@ -83222,10 +83407,11 @@
83222 heap[0] = 0;
83223 for(i=nCell-1; i>=0; i--){
83224 u32 size;
83225 pc = get2byteAligned(&data[cellStart+i*2]);
83226 size = pPage->xCellSize(pPage, &data[pc]);
 
83227 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
83228 }
83229 }
83230 assert( heap!=0 );
83231 /* Add the freeblocks to the min-heap
@@ -83238,10 +83424,11 @@
83238 while( i>0 ){
83239 int size, j;
83240 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
83241 size = get2byte(&data[i+2]);
83242 assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
 
83243 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
83244 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
83245 ** big-endian integer which is the offset in the b-tree page of the next
83246 ** freeblock in the chain, or zero if the freeblock is the last on the
83247 ** chain. */
@@ -83372,10 +83559,13 @@
83372 if( !sCheck.aPgRef ){
83373 checkOom(&sCheck);
83374 goto integrity_ck_cleanup;
83375 }
83376 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
 
 
 
83377 if( sCheck.heap==0 ){
83378 checkOom(&sCheck);
83379 goto integrity_ck_cleanup;
83380 }
83381
@@ -83796,17 +83986,18 @@
83796 /*
83797 ** Structure allocated for each backup operation.
83798 */
83799 struct sqlite3_backup {
83800 sqlite3* pDestDb; /* Destination database handle */
83801 Db *pDest; /* Destination db file */
 
83802 u32 iDestSchema; /* Original schema cookie in destination */
83803 int bDestLocked; /* True once a write-transaction is open on pDest */
83804
83805 Pgno iNext; /* Page number of the next source page to copy */
83806 sqlite3* pSrcDb; /* Source database handle */
83807 Db *pSrc; /* Source db file */
83808
83809 int rc; /* Backup process error code */
83810
83811 /* These two variables are set by every call to backup_step(). They are
83812 ** read by calls to backup_remaining() and backup_pagecount().
@@ -83855,11 +84046,11 @@
83855 **
83856 ** If the "temp" database is requested, it may need to be opened by this
83857 ** function. If an error occurs while doing so, return 0 and write an
83858 ** error message to pErrorDb.
83859 */
83860 static Db *findDatabase(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
83861 int i = sqlite3FindDbName(pDb, zDb);
83862
83863 if( i==1 ){
83864 Parse sParse;
83865 int rc = 0;
@@ -83878,21 +84069,19 @@
83878 if( i<0 ){
83879 sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
83880 return 0;
83881 }
83882
83883 return &pDb->aDb[i];
83884 }
83885
83886 /*
83887 ** Attempt to set the page size of the destination to match the page size
83888 ** of the source.
83889 */
83890 static int setDestPgsz(sqlite3_backup *p){
83891 return sqlite3BtreeSetPageSize(p->pDest->pBt,
83892 sqlite3BtreeGetPageSize(p->pSrc->pBt), 0, 0
83893 );
83894 }
83895
83896 /*
83897 ** Check that there is no open read-transaction on the b-tree passed as the
83898 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -83945,31 +84134,41 @@
83945 sqlite3ErrorWithMsg(
83946 pDestDb, SQLITE_ERROR, "source and destination must be distinct"
83947 );
83948 p = 0;
83949 }else {
 
 
83950 /* Allocate space for a new sqlite3_backup object...
83951 ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
83952 ** call to sqlite3_backup_init() and is destroyed by a call to
83953 ** sqlite3_backup_finish(). */
83954 p = (sqlite3_backup *)sqlite3MallocZero(sizeof(sqlite3_backup));
83955 if( !p ){
83956 sqlite3Error(pDestDb, SQLITE_NOMEM_BKPT);
 
 
 
83957 }
83958 }
83959
83960 /* If the allocation succeeded, populate the new object. */
83961 if( p ){
83962 p->pSrc = findDatabase(pDestDb, pSrcDb, zSrcDb);
83963 p->pDest = findDatabase(pDestDb, pDestDb, zDestDb);
 
 
 
 
 
83964 p->pDestDb = pDestDb;
83965 p->pSrcDb = pSrcDb;
83966 p->iNext = 1;
83967 p->isAttached = 0;
83968
83969 if( 0==p->pSrc || 0==p->pDest
83970 || checkReadTransaction(pDestDb, p->pDest->pBt)!=SQLITE_OK
83971 ){
83972 /* One (or both) of the named databases did not exist or an OOM
83973 ** error was hit. Or there is a transaction open on the destination
83974 ** database. The error has already been written into the pDestDb
83975 ** handle. All that is left to do here is free the sqlite3_backup
@@ -83977,11 +84176,11 @@
83977 sqlite3_free(p);
83978 p = 0;
83979 }
83980 }
83981 if( p ){
83982 p->pSrc->pBt->nBackup++;
83983 }
83984
83985 sqlite3_mutex_leave(pDestDb->mutex);
83986 sqlite3_mutex_leave(pSrcDb->mutex);
83987 return p;
@@ -84005,22 +84204,22 @@
84005 sqlite3_backup *p, /* Backup handle */
84006 Pgno iSrcPg, /* Source database page to backup */
84007 const u8 *zSrcData, /* Source database page data */
84008 int bUpdate /* True for an update, false otherwise */
84009 ){
84010 Pager * const pDestPager = sqlite3BtreePager(p->pDest->pBt);
84011 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc->pBt);
84012 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest->pBt);
84013 const int nCopy = MIN(nSrcPgsz, nDestPgsz);
84014 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
84015 int rc = SQLITE_OK;
84016 i64 iOff;
84017
84018 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc->pBt)>=0 );
84019 assert( p->bDestLocked );
84020 assert( !isFatalError(p->rc) );
84021 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt->pBt) );
84022 assert( zSrcData );
84023 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
84024
84025 /* This loop runs once for each destination page spanned by the source
84026 ** page. For each iteration, variable iOff is set to the byte offset
@@ -84027,11 +84226,11 @@
84027 ** of the destination page.
84028 */
84029 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
84030 DbPage *pDestPg = 0;
84031 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
84032 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt->pBt) ) continue;
84033 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
84034 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
84035 ){
84036 const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
84037 u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -84045,11 +84244,11 @@
84045 ** "MUST BE FIRST" for this purpose.
84046 */
84047 memcpy(zOut, zIn, nCopy);
84048 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
84049 if( iOff==0 && bUpdate==0 ){
84050 sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc->pBt));
84051 }
84052 }
84053 sqlite3PagerUnref(pDestPg);
84054 }
84055
@@ -84077,12 +84276,12 @@
84077 ** Register this backup object with the associated source pager for
84078 ** callbacks when pages are changed or the cache invalidated.
84079 */
84080 static void attachBackupObject(sqlite3_backup *p){
84081 sqlite3_backup **pp;
84082 assert( sqlite3BtreeHoldsMutex(p->pSrc->pBt) );
84083 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
84084 p->pNext = *pp;
84085 *pp = p;
84086 p->isAttached = 1;
84087 }
84088
@@ -84089,93 +84288,103 @@
84089 /*
84090 ** Copy nPage pages from the source b-tree to the destination.
84091 */
84092 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
84093 int rc;
84094 int destMode; /* Destination journal mode */
84095 int pgszSrc = 0; /* Source page size */
84096 int pgszDest = 0; /* Destination page size */
84097 Btree *pDest;
84098 Btree *pSrc;
84099
84100 #ifdef SQLITE_ENABLE_API_ARMOR
84101 if( p==0 ) return SQLITE_MISUSE_BKPT;
84102 #endif
84103 assert( p->pDest );
84104 assert( p->pSrc );
84105 pDest = p->pDest->pBt;
84106 pSrc = p->pSrc->pBt;
84107 sqlite3_mutex_enter(p->pSrcDb->mutex);
84108 sqlite3BtreeEnter(pSrc);
84109 if( p->pDestDb ){
84110 sqlite3_mutex_enter(p->pDestDb->mutex);
84111 }
84112
84113 rc = p->rc;
84114 if( !isFatalError(rc) ){
84115 Pager * const pSrcPager = sqlite3BtreePager(pSrc); /* Source pager */
84116 Pager * const pDestPager = sqlite3BtreePager(pDest); /* Dest pager */
 
84117 int ii; /* Iterator variable */
84118 int nSrcPage = -1; /* Size of source db in pages */
84119 int bCloseTrans = 0; /* True if src db requires unlocking */
84120
84121 /* If the source pager is currently in a write-transaction, return
84122 ** SQLITE_BUSY immediately.
84123 */
84124 if( p->pDestDb && pSrc->pBt->inTransaction==TRANS_WRITE ){
84125 rc = SQLITE_BUSY;
84126 }else{
84127 rc = SQLITE_OK;
84128 }
 
84129
84130 /* If there is no open read-transaction on the source database, open
84131 ** one now. If a transaction is opened here, then it will be closed
84132 ** before this function exits.
84133 */
84134 if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(pSrc) ){
84135 rc = sqlite3BtreeBeginTrans(pSrc, 0, 0);
84136 bCloseTrans = 1;
84137 }
 
 
 
 
 
 
 
 
 
 
84138
84139 /* If the destination database has not yet been locked (i.e. if this
84140 ** is the first call to backup_step() for the current backup operation),
84141 ** try to set its page size to the same as the source database. This
84142 ** is especially important on ZipVFS systems, as in that case it is
84143 ** not possible to create a database file that uses one page size by
84144 ** writing to it with another. */
84145 if( p->bDestLocked==0 && rc==SQLITE_OK && setDestPgsz(p)==SQLITE_NOMEM ){
 
 
84146 rc = SQLITE_NOMEM;
84147 }
84148
84149 /* Lock the destination database, if it is not locked already. */
84150 if( SQLITE_OK==rc && p->bDestLocked==0
84151 && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2,
84152 (int*)&p->iDestSchema))
84153 ){
84154 p->bDestLocked = 1;
 
84155 }
84156
84157 /* Do not allow backup if the destination database is in WAL mode
84158 ** and the page sizes are different between source and destination */
84159 pgszSrc = sqlite3BtreeGetPageSize(pSrc);
84160 pgszDest = sqlite3BtreeGetPageSize(pDest);
84161 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(pDest));
84162 if( SQLITE_OK==rc
84163 && (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
84164 && pgszSrc!=pgszDest
84165 ){
84166 rc = SQLITE_READONLY;
 
84167 }
84168
84169 /* Now that there is a read-lock on the source database, query the
84170 ** source pager for the number of pages in the database.
84171 */
84172 nSrcPage = (int)sqlite3BtreeLastPage(pSrc);
84173 assert( nSrcPage>=0 );
84174 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
84175 const Pgno iSrcPg = p->iNext; /* Source page number */
84176 if( iSrcPg!=PENDING_BYTE_PAGE(pSrc->pBt) ){
84177 DbPage *pSrcPg; /* Source page object */
84178 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
84179 if( rc==SQLITE_OK ){
84180 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
84181 sqlite3PagerUnref(pSrcPg);
@@ -84198,22 +84407,22 @@
84198 ** the case where the source and destination databases have the
84199 ** same schema version.
84200 */
84201 if( rc==SQLITE_DONE ){
84202 if( nSrcPage==0 ){
84203 rc = sqlite3BtreeNewDb(pDest);
84204 nSrcPage = 1;
84205 }
84206 if( rc==SQLITE_OK || rc==SQLITE_DONE ){
84207 rc = sqlite3BtreeUpdateMeta(pDest,1,p->iDestSchema+1);
84208 }
84209 if( rc==SQLITE_OK ){
84210 if( p->pDestDb ){
84211 sqlite3ResetAllSchemasOfConnection(p->pDestDb);
84212 }
84213 if( destMode==PAGER_JOURNALMODE_WAL ){
84214 rc = sqlite3BtreeSetVersion(pDest, 2);
84215 }
84216 }
84217 if( rc==SQLITE_OK ){
84218 int nDestTruncate;
84219 /* Set nDestTruncate to the final number of pages in the destination
@@ -84226,16 +84435,16 @@
84226 ** sqlite3PagerTruncateImage() here so that any pages in the
84227 ** destination file that lie beyond the nDestTruncate page mark are
84228 ** journalled by PagerCommitPhaseOne() before they are destroyed
84229 ** by the file truncation.
84230 */
84231 assert( pgszSrc==sqlite3BtreeGetPageSize(pSrc) );
84232 assert( pgszDest==sqlite3BtreeGetPageSize(pDest) );
84233 if( pgszSrc<pgszDest ){
84234 int ratio = pgszDest/pgszSrc;
84235 nDestTruncate = (nSrcPage+ratio-1)/ratio;
84236 if( nDestTruncate==(int)PENDING_BYTE_PAGE(pDest->pBt) ){
84237 nDestTruncate--;
84238 }
84239 }else{
84240 nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
84241 }
@@ -84259,11 +84468,11 @@
84259 i64 iEnd;
84260
84261 assert( pFile );
84262 assert( nDestTruncate==0
84263 || (i64)nDestTruncate*(i64)pgszDest >= iSize || (
84264 nDestTruncate==(int)(PENDING_BYTE_PAGE(pDest->pBt)-1)
84265 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
84266 ));
84267
84268 /* This block ensures that all data required to recreate the original
84269 ** database has been stored in the journal for pDestPager and the
@@ -84271,11 +84480,11 @@
84271 ** the database file in any way, knowing that if a power failure
84272 ** occurs, the original database will be reconstructed from the
84273 ** journal file. */
84274 sqlite3PagerPagecount(pDestPager, &nDstPage);
84275 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
84276 if( iPg!=PENDING_BYTE_PAGE(pDest->pBt) ){
84277 DbPage *pPg;
84278 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
84279 if( rc==SQLITE_OK ){
84280 rc = sqlite3PagerWrite(pPg);
84281 sqlite3PagerUnref(pPg);
@@ -84315,11 +84524,11 @@
84315 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
84316 }
84317
84318 /* Finish committing the transaction to the destination database. */
84319 if( SQLITE_OK==rc
84320 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(pDest, 0))
84321 ){
84322 rc = SQLITE_DONE;
84323 }
84324 }
84325 }
@@ -84329,12 +84538,12 @@
84329 ** no need to check the return values of the btree methods here, as
84330 ** "committing" a read-only transaction cannot fail.
84331 */
84332 if( bCloseTrans ){
84333 TESTONLY( int rc2 );
84334 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(pSrc, 0);
84335 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(pSrc, 0);
84336 assert( rc2==SQLITE_OK );
84337 }
84338
84339 if( rc==SQLITE_IOERR_NOMEM ){
84340 rc = SQLITE_NOMEM_BKPT;
@@ -84342,11 +84551,11 @@
84342 p->rc = rc;
84343 }
84344 if( p->pDestDb ){
84345 sqlite3_mutex_leave(p->pDestDb->mutex);
84346 }
84347 sqlite3BtreeLeave(pSrc);
84348 sqlite3_mutex_leave(p->pSrcDb->mutex);
84349 return rc;
84350 }
84351
84352 /*
@@ -84359,41 +84568,43 @@
84359
84360 /* Enter the mutexes */
84361 if( p==0 ) return SQLITE_OK;
84362 pSrcDb = p->pSrcDb;
84363 sqlite3_mutex_enter(pSrcDb->mutex);
84364 sqlite3BtreeEnter(p->pSrc->pBt);
84365 if( p->pDestDb ){
84366 sqlite3_mutex_enter(p->pDestDb->mutex);
84367 }
84368
84369 /* Detach this backup from the source pager. */
84370 if( p->pDestDb ){
84371 p->pSrc->pBt->nBackup--;
84372 }
84373 if( p->isAttached ){
84374 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc->pBt));
84375 assert( pp!=0 );
84376 while( *pp!=p ){
84377 pp = &(*pp)->pNext;
84378 assert( pp!=0 );
84379 }
84380 *pp = p->pNext;
84381 }
84382
84383 /* If a transaction is still open on the Btree, roll it back. */
84384 sqlite3BtreeRollback(p->pDest->pBt, SQLITE_OK, 0);
 
 
84385
84386 /* Set the error code of the destination database handle. */
84387 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
84388 if( p->pDestDb ){
84389 sqlite3Error(p->pDestDb, rc);
84390
84391 /* Exit the mutexes and free the backup context structure. */
84392 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
84393 }
84394 sqlite3BtreeLeave(p->pSrc->pBt);
84395 if( p->pDestDb ){
84396 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
84397 ** call to sqlite3_backup_init() and is destroyed by a call to
84398 ** sqlite3_backup_finish(). */
84399 sqlite3_free(p);
@@ -84447,11 +84658,11 @@
84447 Pgno iPage,
84448 const u8 *aData
84449 ){
84450 assert( p!=0 );
84451 do{
84452 assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84453 if( !isFatalError(p->rc) && iPage<p->iNext ){
84454 /* The backup process p has already copied page iPage. But now it
84455 ** has been modified by a transaction on the source pager. Copy
84456 ** the new data into the backup.
84457 */
@@ -84483,11 +84694,11 @@
84483 ** called.
84484 */
84485 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
84486 sqlite3_backup *p; /* Iterator variable */
84487 for(p=pBackup; p; p=p->pNext){
84488 assert( sqlite3_mutex_held(p->pSrc->pBt->pBt->mutex) );
84489 p->iNext = 1;
84490 }
84491 }
84492
84493 #ifndef SQLITE_OMIT_VACUUM
@@ -84501,12 +84712,10 @@
84501 */
84502 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
84503 int rc;
84504 sqlite3_file *pFd; /* File descriptor for database pTo */
84505 sqlite3_backup b;
84506 Db dbDest;
84507 Db dbSrc;
84508 sqlite3BtreeEnter(pTo);
84509 sqlite3BtreeEnter(pFrom);
84510
84511 assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
84512 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -84521,17 +84730,13 @@
84521 ** to 0. This is used by the implementations of sqlite3_backup_step()
84522 ** and sqlite3_backup_finish() to detect that they are being called
84523 ** from this function, not directly by the user.
84524 */
84525 memset(&b, 0, sizeof(b));
84526 memset(&dbDest, 0, sizeof(dbDest));
84527 memset(&dbSrc, 0, sizeof(dbSrc));
84528 dbDest.pBt = pTo;
84529 dbSrc.pBt = pFrom;
84530 b.pSrcDb = pFrom->db;
84531 b.pSrc = &dbSrc;
84532 b.pDest = &dbDest;
84533 b.iNext = 1;
84534
84535 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
84536 ** file. By passing this as the number of pages to copy to
84537 ** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -84543,11 +84748,11 @@
84543
84544 rc = sqlite3_backup_finish(&b);
84545 if( rc==SQLITE_OK ){
84546 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
84547 }else{
84548 sqlite3PagerClearCache(sqlite3BtreePager(pTo));
84549 }
84550
84551 assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
84552 copy_finished:
84553 sqlite3BtreeLeave(pFrom);
@@ -86859,11 +87064,10 @@
86859 p->pParse = pParse;
86860 pParse->pVdbe = p;
86861 assert( pParse->aLabel==0 );
86862 assert( pParse->nLabel==0 );
86863 assert( p->nOpAlloc==0 );
86864 assert( pParse->szOpAlloc==0 );
86865 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
86866 return p;
86867 }
86868
86869 /*
@@ -87009,12 +87213,11 @@
87009
87010 assert( nOp<=(int)(1024/sizeof(Op)) );
87011 assert( nNew>=(v->nOpAlloc+nOp) );
87012 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
87013 if( pNew ){
87014 p->szOpAlloc = sqlite3DbMallocSize(p->db, pNew);
87015 v->nOpAlloc = p->szOpAlloc/sizeof(Op);
87016 v->aOp = pNew;
87017 }
87018 return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
87019 }
87020
@@ -87445,11 +87648,11 @@
87445 ** Resolve label "x" to be the address of the next instruction to
87446 ** be inserted. The parameter "x" must have been obtained from
87447 ** a prior call to sqlite3VdbeMakeLabel().
87448 */
87449 static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
87450 int nNewSize = 10 - p->nLabel;
87451 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
87452 nNewSize*sizeof(p->aLabel[0]));
87453 if( p->aLabel==0 ){
87454 p->nLabelAlloc = 0;
87455 }else{
@@ -89513,11 +89716,11 @@
89513 ** of the prepared statement.
89514 */
89515 n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
89516 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
89517 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
89518 x.nFree = ROUNDDOWN8(pParse->szOpAlloc - n); /* Bytes of unused memory */
89519 assert( x.nFree>=0 );
89520 assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
89521
89522 resolveP2Values(p, &nArg);
89523 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92662,12 +92865,18 @@
92662 ** that sqlite3_prepare() generates. For example, if new functions or
92663 ** collating sequences are registered or if an authorizer function is
92664 ** added or changed.
92665 */
92666 SQLITE_API int sqlite3_expired(sqlite3_stmt *pStmt){
92667 Vdbe *p = (Vdbe*)pStmt;
92668 return p==0 || p->expired;
 
 
 
 
 
 
92669 }
92670 #endif
92671
92672 /*
92673 ** Check on a Vdbe to make sure it has not been finalized. Log
@@ -93009,19 +93218,22 @@
93009 sqlite3ValueFree(pOld);
93010 }
93011
93012
93013 /**************************** sqlite3_result_ *******************************
93014 ** The following routines are used by user-defined functions to specify
93015 ** the function result.
93016 **
93017 ** The setStrOrError() function calls sqlite3VdbeMemSetStr() to store the
93018 ** result as a string or blob. Appropriate errors are set if the string/blob
93019 ** is too big or if an OOM occurs.
93020 **
93021 ** The invokeValueDestructor(P,X) routine invokes destructor function X()
93022 ** on value P if P is not going to be used and need to be destroyed.
 
 
 
93023 */
93024 static void setResultStrOrError(
93025 sqlite3_context *pCtx, /* Function context */
93026 const char *z, /* String pointer */
93027 int n, /* Bytes in string, or negative */
@@ -93330,11 +93542,11 @@
93330 setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
93331 SQLITE_STATIC);
93332 }
93333 }
93334
93335 /* Force an SQLITE_TOOBIG error. */
93336 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
93337 #ifdef SQLITE_ENABLE_API_ARMOR
93338 if( pCtx==0 ) return;
93339 #endif
93340 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -93341,20 +93553,82 @@
93341 pCtx->isError = SQLITE_TOOBIG;
93342 sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1,
93343 SQLITE_UTF8, SQLITE_STATIC);
93344 }
93345
93346 /* An SQLITE_NOMEM error. */
93347 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){
93348 #ifdef SQLITE_ENABLE_API_ARMOR
93349 if( pCtx==0 ) return;
93350 #endif
93351 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
93352 sqlite3VdbeMemSetNull(pCtx->pOut);
93353 pCtx->isError = SQLITE_NOMEM_BKPT;
93354 sqlite3OomFault(pCtx->pOut->db);
93355 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93356
93357 #ifndef SQLITE_UNTESTABLE
93358 /* Force the INT64 value currently stored as the result to be
93359 ** a MEM_IntReal value. See the SQLITE_TESTCTRL_RESULT_INTREAL
93360 ** test-control.
@@ -102342,10 +102616,15 @@
102342 pTabCur = p->apCsr[pOp->p3];
102343 assert( pTabCur!=0 );
102344 assert( pTabCur->eCurType==CURTYPE_BTREE );
102345 assert( pTabCur->uc.pCursor!=0 );
102346 assert( pTabCur->isTable );
 
 
 
 
 
102347 pTabCur->nullRow = 0;
102348 pTabCur->movetoTarget = rowid;
102349 pTabCur->deferredMoveto = 1;
102350 pTabCur->cacheStatus = CACHE_STALE;
102351 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
@@ -104724,27 +105003,41 @@
104724 p->aCounter[SQLITE_STMTSTATUS_RUN]++;
104725 goto jump_to_p2;
104726 }
104727
104728 #ifdef SQLITE_ENABLE_CURSOR_HINTS
104729 /* Opcode: CursorHint P1 * * P4 *
104730 **
104731 ** Provide a hint to cursor P1 that it only needs to return rows that
104732 ** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
104733 ** to values currently held in registers. TK_COLUMN terms in the P4
 
 
104734 ** expression refer to columns in the b-tree to which cursor P1 is pointing.
 
 
 
 
 
 
104735 */
104736 case OP_CursorHint: {
104737 VdbeCursor *pC;
 
104738
104739 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
104740 assert( pOp->p4type==P4_EXPR );
104741 pC = p->apCsr[pOp->p1];
104742 if( pC ){
104743 assert( pC->eCurType==CURTYPE_BTREE );
104744 sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE,
104745 pOp->p4.pExpr, aMem);
 
 
 
 
 
 
104746 }
104747 break;
104748 }
104749 #endif /* SQLITE_ENABLE_CURSOR_HINTS */
104750
@@ -117229,11 +117522,16 @@
117229 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117230 if( pDef==0 && pParse->explain ){
117231 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
117232 }
117233 #endif
117234 if( pDef==0 || pDef->xFinalize!=0 ){
 
 
 
 
 
117235 sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
117236 break;
117237 }
117238 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
117239 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
@@ -122236,13 +122534,12 @@
122236 const u8 *zSql = sqlite3_value_text(argv[0]);
122237 const char *zCons = (const char*)sqlite3_value_text(argv[1]);
122238 int iCol = sqlite3_value_int(argv[2]);
122239 int iOff = 0;
122240 int ii;
122241 char *zNew = 0;
122242 int t = 0;
122243 sqlite3 *db;
122244 UNUSED_PARAMETER(NotUsed);
122245
122246 if( skipCreateTable(ctx, zSql, &iOff) ) return;
122247
122248 for(ii=0; ii<=iCol || (iCol<0 && t!=TK_RP); ii++){
@@ -122258,17 +122555,15 @@
122258 }
122259 }
122260
122261 iOff += getWhitespace(&zSql[iOff]);
122262
122263 db = sqlite3_context_db_handle(ctx);
122264 if( iCol<0 ){
122265 zNew = sqlite3MPrintf(db, "%.*s, %s%s", iOff, zSql, zCons, &zSql[iOff]);
122266 }else{
122267 zNew = sqlite3MPrintf(db, "%.*s %s%s", iOff, zSql, zCons, &zSql[iOff]);
122268 }
122269 sqlite3_result_text(ctx, zNew, -1, SQLITE_DYNAMIC);
122270 }
122271
122272 /*
122273 ** Find a column named pCol in table pTab. If successful, set output
122274 ** parameter *piCol to the index of the column in the table and return
@@ -123524,11 +123819,11 @@
123524 sqlite3_str_appendf(&sStat, " %llu", iVal);
123525 #ifdef SQLITE_ENABLE_STAT4
123526 assert( p->current.anEq[i] || p->nRow==0 );
123527 #endif
123528 }
123529 sqlite3ResultStrAccum(context, &sStat);
123530 }
123531 #ifdef SQLITE_ENABLE_STAT4
123532 else if( eCall==STAT_GET_ROWID ){
123533 if( p->iGet<0 ){
123534 samplePushPrevious(p, 0);
@@ -123561,11 +123856,11 @@
123561 sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
123562 for(i=0; i<p->nCol; i++){
123563 sqlite3_str_appendf(&sStat, "%llu ", (u64)aCnt[i]);
123564 }
123565 if( sStat.nChar ) sStat.nChar--;
123566 sqlite3ResultStrAccum(context, &sStat);
123567 }
123568 #endif /* SQLITE_ENABLE_STAT4 */
123569 #ifndef SQLITE_DEBUG
123570 UNUSED_PARAMETER( argc );
123571 #endif
@@ -125649,10 +125944,11 @@
125649 }
125650 }
125651
125652 assert( pToplevel->nTableLock < 0x7fff0000 );
125653 nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
 
125654 pToplevel->aTableLock =
125655 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
125656 if( pToplevel->aTableLock ){
125657 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
125658 p->iDb = iDb;
@@ -125815,11 +126111,11 @@
125815 if( pParse->nTableLock ) codeTableLocks(pParse);
125816 #endif
125817
125818 /* Initialize any AUTOINCREMENT data structures required.
125819 */
125820 if( pParse->pAinc ) sqlite3AutoincrementBegin(pParse);
125821
125822 /* Code constant expressions that were factored out of inner loops.
125823 */
125824 if( pParse->pConstExpr ){
125825 ExprList *pEL = pParse->pConstExpr;
@@ -125848,11 +126144,11 @@
125848 assert( v!=0 || pParse->nErr );
125849 assert( db->mallocFailed==0 || pParse->nErr );
125850 if( pParse->nErr==0 ){
125851 /* A minimum of one cursor is required if autoincrement is used
125852 * See ticket [a696379c1f08866] */
125853 assert( pParse->pAinc==0 || pParse->nTab>0 );
125854 sqlite3VdbeMakeReady(v, pParse);
125855 pParse->rc = SQLITE_DONE;
125856 }else{
125857 pParse->rc = SQLITE_ERROR;
125858 }
@@ -133318,32 +133614,20 @@
133318 sqlite3_value **argv
133319 ){
133320 PrintfArguments x;
133321 StrAccum str;
133322 const char *zFormat;
133323 int n;
133324 sqlite3 *db = sqlite3_context_db_handle(context);
133325
133326 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
133327 x.nArg = argc-1;
133328 x.nUsed = 0;
133329 x.apArg = argv+1;
133330 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
133331 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
133332 sqlite3_str_appendf(&str, zFormat, &x);
133333 if( str.accError==SQLITE_OK ){
133334 n = str.nChar;
133335 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
133336 SQLITE_DYNAMIC);
133337 }else{
133338 if( str.accError==SQLITE_NOMEM ){
133339 sqlite3_result_error_nomem(context);
133340 }else{
133341 sqlite3_result_error_toobig(context);
133342 }
133343 sqlite3_str_reset(&str);
133344 }
133345 }
133346 }
133347
133348 /*
133349 ** Implementation of the substr() function.
@@ -134286,16 +134570,11 @@
134286 sqlite3 *db = sqlite3_context_db_handle(context);
134287 assert( argc==1 );
134288 UNUSED_PARAMETER(argc);
134289 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
134290 sqlite3QuoteValue(&str,argv[0],SQLITE_PTR_TO_INT(sqlite3_user_data(context)));
134291 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), str.nChar,
134292 SQLITE_DYNAMIC);
134293 if( str.accError!=SQLITE_OK ){
134294 sqlite3_result_null(context);
134295 sqlite3_result_error_code(context, str.accError);
134296 }
134297 }
134298
134299 /*
134300 ** The unicode() function. Return the integer unicode code-point value
134301 ** for the first character of the input string.
@@ -135324,32 +135603,22 @@
135324 #endif /* SQLITE_OMIT_WINDOWFUNC */
135325 static void groupConcatFinalize(sqlite3_context *context){
135326 GroupConcatCtx *pGCC
135327 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135328 if( pGCC ){
135329 sqlite3ResultStrAccum(context, &pGCC->str);
135330 #ifndef SQLITE_OMIT_WINDOWFUNC
135331 sqlite3_free(pGCC->pnSepLengths);
135332 #endif
135333 }
135334 }
135335 #ifndef SQLITE_OMIT_WINDOWFUNC
135336 static void groupConcatValue(sqlite3_context *context){
135337 GroupConcatCtx *pGCC
135338 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135339 if( pGCC ){
135340 StrAccum *pAccum = &pGCC->str;
135341 if( pAccum->accError==SQLITE_TOOBIG ){
135342 sqlite3_result_error_toobig(context);
135343 }else if( pAccum->accError==SQLITE_NOMEM ){
135344 sqlite3_result_error_nomem(context);
135345 }else if( pGCC->nAccum>0 && pAccum->nChar==0 ){
135346 sqlite3_result_text(context, "", 1, SQLITE_STATIC);
135347 }else{
135348 const char *zText = sqlite3_str_value(pAccum);
135349 sqlite3_result_text(context, zText, pAccum->nChar, SQLITE_TRANSIENT);
135350 }
135351 }
135352 }
135353 #else
135354 # define groupConcatValue 0
135355 #endif /* SQLITE_OMIT_WINDOWFUNC */
@@ -136190,12 +136459,11 @@
136190 sqlite3_str_appendall(pStr, ",\"journal\":");
136191 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_FILESTAT, pStr);
136192 if( rc ) sqlite3_str_append(pStr, "null", 4);
136193 }
136194 sqlite3_str_append(pStr, "}", 1);
136195 sqlite3_result_text(context, sqlite3_str_finish(pStr), -1,
136196 sqlite3_free);
136197 }
136198 sqlite3BtreeLeave(pBtree);
136199 }else{
136200 sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
136201 }
@@ -136307,12 +136575,12 @@
136307 }else{
136308 sqlite3_str_appendf(pResult, ", NULL");
136309 }
136310 }
136311 }
136312 sqlite3_result_text(ctx, sqlite3_str_finish(pResult), -1, sqlite3_free);
136313 }
 
136314 sqlite3_free_filename(zFile);
136315 sqlite3_free(zErr);
136316 }
136317 #endif /* SQLITE_DEBUG */
136318
@@ -136405,11 +136673,11 @@
136405 VFUNCTION(random, 0, 0, 0, randomFunc ),
136406 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
136407 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
136408 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
136409 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
136410 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
136411 FUNCTION(unistr, 1, 0, 0, unistrFunc ),
136412 FUNCTION(quote, 1, 0, 0, quoteFunc ),
136413 FUNCTION(unistr_quote, 1, 1, 0, quoteFunc ),
136414 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
136415 VFUNCTION(changes, 0, 0, 0, changes ),
@@ -138454,19 +138722,23 @@
138454 pParse->nErr++;
138455 pParse->rc = SQLITE_CORRUPT_SEQUENCE;
138456 return 0;
138457 }
138458
 
 
 
138459 pInfo = pToplevel->pAinc;
138460 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
138461 if( pInfo==0 ){
138462 pInfo = sqlite3DbMallocRawNN(pParse->db, sizeof(*pInfo));
138463 sqlite3ParserAddCleanup(pToplevel, sqlite3DbFree, pInfo);
138464 testcase( pParse->earlyCleanup );
138465 if( pParse->db->mallocFailed ) return 0;
138466 pInfo->pNext = pToplevel->pAinc;
138467 pToplevel->pAinc = pInfo;
 
138468 pInfo->pTab = pTab;
138469 pInfo->iDb = iDb;
138470 pToplevel->nMem++; /* Register to hold name of table */
138471 pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
138472 pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */
@@ -138491,10 +138763,11 @@
138491 ** only called from the top-level */
138492 assert( pParse->pTriggerTab==0 );
138493 assert( sqlite3IsToplevel(pParse) );
138494
138495 assert( v ); /* We failed long ago if this is not so */
 
138496 for(p = pParse->pAinc; p; p = p->pNext){
138497 static const int iLn = VDBE_OFFSET_LINENO(2);
138498 static const VdbeOpList autoInc[] = {
138499 /* 0 */ {OP_Null, 0, 0, 0},
138500 /* 1 */ {OP_Rewind, 0, 10, 0},
@@ -138558,10 +138831,11 @@
138558 AutoincInfo *p;
138559 Vdbe *v = pParse->pVdbe;
138560 sqlite3 *db = pParse->db;
138561
138562 assert( v );
 
138563 for(p = pParse->pAinc; p; p = p->pNext){
138564 static const int iLn = VDBE_OFFSET_LINENO(2);
138565 static const VdbeOpList autoIncEnd[] = {
138566 /* 0 */ {OP_NotNull, 0, 2, 0},
138567 /* 1 */ {OP_NewRowid, 0, 0, 0},
@@ -138590,11 +138864,11 @@
138590 aOp[3].p5 = OPFLAG_APPEND;
138591 sqlite3ReleaseTempReg(pParse, iRec);
138592 }
138593 }
138594 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse){
138595 if( pParse->pAinc ) autoIncrementEnd(pParse);
138596 }
138597 #else
138598 /*
138599 ** If SQLITE_OMIT_AUTOINCREMENT is defined, then the three routines
138600 ** above are all no-ops
@@ -142023,10 +142297,11 @@
142023 void (*str_free)(sqlite3_str*);
142024 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142025 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
142026 /* Version 3.54.0 and later */
142027 sqlite3_int64 (*incomplete)(const char*);
 
142028 };
142029
142030 /*
142031 ** This is the function signature used for all extension entry points. It
142032 ** is also defined in the file "loadext.c".
@@ -142368,10 +142643,11 @@
142368 #define sqlite3_str_free sqlite3_api->str_free
142369 #define sqlite3_carray_bind sqlite3_api->carray_bind
142370 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142371 /* Version 3.54.0 and later */
142372 #define sqlite3_incomplete sqlite3_api->incomplete
 
142373 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142374
142375 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142376 /* This case when the file really is being compiled as a loadable
142377 ** extension */
@@ -142905,11 +143181,13 @@
142905 sqlite3_carray_bind_v2,
142906 #else
142907 0,
142908 0,
142909 #endif
142910 sqlite3_incomplete
 
 
142911 };
142912
142913 /* True if x is the directory separator character
142914 */
142915 #if SQLITE_OS_WIN
@@ -147674,11 +147952,11 @@
147674 sqlite3 *db = pParse->db;
147675 assert( db!=0 );
147676 assert( db->pParse==pParse );
147677 assert( pParse->nested==0 );
147678 #ifndef SQLITE_OMIT_SHARED_CACHE
147679 if( pParse->aTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
147680 #endif
147681 while( pParse->pCleanup ){
147682 ParseCleanup *pCleanup = pParse->pCleanup;
147683 pParse->pCleanup = pCleanup->pNext;
147684 pCleanup->xCleanup(db, pCleanup->pPtr);
@@ -148157,11 +148435,11 @@
148157 int nBytes, /* Length of zSql in bytes. */
148158 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148159 const void **pzTail /* OUT: End of parsed string */
148160 ){
148161 int rc;
148162 rc = sqlite3Prepare16(db,zSql,nBytes,0,ppStmt,pzTail);
148163 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148164 return rc;
148165 }
148166 SQLITE_API int sqlite3_prepare16_v2(
148167 sqlite3 *db, /* Database handle. */
@@ -148169,11 +148447,11 @@
148169 int nBytes, /* Length of zSql in bytes. */
148170 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148171 const void **pzTail /* OUT: End of parsed string */
148172 ){
148173 int rc;
148174 rc = sqlite3Prepare16(db,zSql,nBytes,SQLITE_PREPARE_SAVESQL,ppStmt,pzTail);
148175 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148176 return rc;
148177 }
148178 SQLITE_API int sqlite3_prepare16_v3(
148179 sqlite3 *db, /* Database handle. */
@@ -148182,11 +148460,11 @@
148182 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
148183 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148184 const void **pzTail /* OUT: End of parsed string */
148185 ){
148186 int rc;
148187 rc = sqlite3Prepare16(db,zSql,nBytes,
148188 SQLITE_PREPARE_SAVESQL|(prepFlags&SQLITE_PREPARE_MASK),
148189 ppStmt,pzTail);
148190 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148191 return rc;
148192 }
@@ -148855,11 +149133,12 @@
148855 pRight->u3.pOn = 0;
148856 pRight->fg.isOn = 1;
148857 p->selFlags |= SF_OnToWhere;
148858 }
148859
148860 if( IsVirtual(pRightTab) && joinType==EP_OuterON && pRight->u1.pFuncArg ){
 
148861 p->selFlags |= SF_OnToWhere;
148862 }
148863 }
148864 return 0;
148865 }
@@ -161225,10 +161504,11 @@
161225 SQLITE_API int sqlite3_drop_modules(sqlite3 *db, const char** azNames){
161226 HashElem *pThis, *pNext;
161227 #ifdef SQLITE_ENABLE_API_ARMOR
161228 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
161229 #endif
 
161230 for(pThis=sqliteHashFirst(&db->aModule); pThis; pThis=pNext){
161231 Module *pMod = (Module*)sqliteHashData(pThis);
161232 pNext = sqliteHashNext(pThis);
161233 if( azNames ){
161234 int ii;
@@ -161235,10 +161515,11 @@
161235 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
161236 if( azNames[ii]!=0 ) continue;
161237 }
161238 createModule(db, pMod->zName, 0, 0, 0);
161239 }
 
161240 return SQLITE_OK;
161241 }
161242
161243 /*
161244 ** Decrement the reference count on a Module object. Destroy the
@@ -167001,33 +167282,62 @@
167001 }
167002 }
167003 }
167004 }
167005
167006 /* At this point, okToChngToIN is true if original pTerm satisfies
167007 ** case 1. In that case, construct a new virtual term that is
167008 ** pTerm converted into an IN operator.
 
 
 
 
 
 
167009 */
167010 if( okToChngToIN ){
167011 Expr *pDup; /* A transient duplicate expression */
167012 ExprList *pList = 0; /* The RHS of the IN operator */
167013 Expr *pLeft = 0; /* The LHS of the IN operator */
 
167014 Expr *pNew; /* The complete IN operator */
167015
167016 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
 
167017 if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
167018 assert( pOrTerm->eOperator & WO_EQ );
167019 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
167020 assert( pOrTerm->leftCursor==iCursor );
167021 assert( pOrTerm->u.x.leftColumn==iColumn );
167022 pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
 
167023 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
167024 pLeft = pOrTerm->pExpr->pLeft;
 
 
 
 
 
 
 
 
 
 
 
167025 }
167026 assert( pLeft!=0 );
167027 pDup = sqlite3ExprDup(db, pLeft, 0);
167028 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
 
 
 
 
 
 
 
 
 
167029 if( pNew ){
167030 int idxNew;
167031 transferJoinMarkings(pNew, pExpr);
167032 assert( ExprUseXList(pNew) );
167033 pNew->x.pList = pList;
@@ -175432,10 +175742,15 @@
175432 }
175433 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
175434 (u8*)&colUsed, P4_INT64);
175435 }
175436 #endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
 
 
 
 
 
175437 }
175438 }
175439 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
175440 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
175441 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
@@ -176155,11 +176470,11 @@
176155 case SQLITE_INTEGER:
176156 iVal = sqlite3_value_int64(apArg[1]);
176157 break;
176158 case SQLITE_FLOAT: {
176159 double fVal = sqlite3_value_double(apArg[1]);
176160 if( ((i64)fVal)!=fVal ) goto error_out;
176161 iVal = (i64)fVal;
176162 break;
176163 }
176164 default:
176165 goto error_out;
@@ -187755,17 +188070,21 @@
187755
187756 /*
187757 ** Return the ROWID of the most recent insert
187758 */
187759 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
 
187760 #ifdef SQLITE_ENABLE_API_ARMOR
187761 if( !sqlite3SafetyCheckOk(db) ){
187762 (void)SQLITE_MISUSE_BKPT;
187763 return 0;
187764 }
187765 #endif
187766 return db->lastRowid;
 
 
 
187767 }
187768
187769 /*
187770 ** Set the value returned by the sqlite3_last_insert_rowid() API function.
187771 */
@@ -187784,33 +188103,41 @@
187784 /*
187785 ** Return the number of changes in the most recently executed DML
187786 ** statement.
187787 */
187788 SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3 *db){
 
187789 #ifdef SQLITE_ENABLE_API_ARMOR
187790 if( !sqlite3SafetyCheckOk(db) ){
187791 (void)SQLITE_MISUSE_BKPT;
187792 return 0;
187793 }
187794 #endif
187795 return db->nChange;
 
 
 
187796 }
187797 SQLITE_API int sqlite3_changes(sqlite3 *db){
187798 return (int)sqlite3_changes64(db);
187799 }
187800
187801 /*
187802 ** Return the number of changes since the database handle was opened.
187803 */
187804 SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){
 
187805 #ifdef SQLITE_ENABLE_API_ARMOR
187806 if( !sqlite3SafetyCheckOk(db) ){
187807 (void)SQLITE_MISUSE_BKPT;
187808 return 0;
187809 }
187810 #endif
187811 return db->nTotalChange;
 
 
 
187812 }
187813 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
187814 return (int)sqlite3_total_changes64(db);
187815 }
187816
@@ -188489,10 +188816,11 @@
188489 */
188490 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
188491 #ifdef SQLITE_ENABLE_API_ARMOR
188492 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
188493 #endif
 
188494 if( ms>0 ){
188495 sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
188496 (void*)db);
188497 db->busyTimeout = ms;
188498 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
@@ -188499,10 +188827,11 @@
188499 db->setlkTimeout = ms;
188500 #endif
188501 }else{
188502 sqlite3_busy_handler(db, 0, 0);
188503 }
 
188504 return SQLITE_OK;
188505 }
188506
188507 /*
188508 ** Set the setlk timeout value.
@@ -189404,13 +189733,15 @@
189404 /*
189405 ** Return the byte offset of the most recent error
189406 */
189407 SQLITE_API int sqlite3_error_offset(sqlite3 *db){
189408 int iOffset = -1;
189409 if( db && sqlite3SafetyCheckSickOrOk(db) && db->errCode ){
189410 sqlite3_mutex_enter(db->mutex);
189411 iOffset = db->errByteOffset;
 
 
189412 sqlite3_mutex_leave(db->mutex);
189413 }
189414 return iOffset;
189415 }
189416
@@ -189460,29 +189791,47 @@
189460 /*
189461 ** Return the most recent error code generated by an SQLite routine. If NULL is
189462 ** passed to this function, we assume a malloc() failed during sqlite3_open().
189463 */
189464 SQLITE_API int sqlite3_errcode(sqlite3 *db){
189465 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
 
 
189466 return SQLITE_MISUSE_BKPT;
189467 }
189468 if( !db || db->mallocFailed ){
189469 return SQLITE_NOMEM_BKPT;
 
 
 
189470 }
189471 return db->errCode & db->errMask;
 
189472 }
189473 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
189474 if( db && !sqlite3SafetyCheckSickOrOk(db) ){
 
 
189475 return SQLITE_MISUSE_BKPT;
189476 }
189477 if( !db || db->mallocFailed ){
189478 return SQLITE_NOMEM_BKPT;
 
 
 
189479 }
189480 return db->errCode;
 
189481 }
189482 SQLITE_API int sqlite3_system_errno(sqlite3 *db){
189483 return db ? db->iSysErrno : 0;
 
 
 
 
 
 
189484 }
189485
189486 /*
189487 ** Return a string that describes the kind of error specified in the
189488 ** argument. For now, this simply calls the internal sqlite3ErrStr()
@@ -189673,19 +190022,21 @@
189673
189674
189675 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
189676 return -1;
189677 }
 
189678 oldLimit = db->aLimit[limitId];
189679 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
189680 if( newLimit>aHardLimit[limitId] ){
189681 newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
189682 }else if( newLimit<SQLITE_MIN_LENGTH && limitId==SQLITE_LIMIT_LENGTH ){
189683 newLimit = SQLITE_MIN_LENGTH;
189684 }
189685 db->aLimit[limitId] = newLimit;
189686 }
 
189687 return oldLimit; /* IMP: R-53341-35419 */
189688 }
189689
189690 /*
189691 ** This function is used to parse both URIs and non-URI filenames passed by the
@@ -189724,22 +190075,22 @@
189724 int rc = SQLITE_OK;
189725 unsigned int flags = *pFlags;
189726 const char *zVfs = zDefaultVfs;
189727 char *zFile;
189728 char c;
189729 int nUri = sqlite3Strlen30(zUri);
189730
189731 assert( *pzErrMsg==0 );
189732
189733 if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
189734 || AtomicLoad(&sqlite3GlobalConfig.bOpenUri)) /* IMP: R-51689-46548 */
189735 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
189736 ){
189737 char *zOpt;
189738 int eState; /* Parser state when parsing URI */
189739 int iIn; /* Input character index */
189740 int iOut = 0; /* Output character index */
189741 u64 nByte = nUri+8; /* Bytes of space to allocate */
189742
189743 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
189744 ** method that there may be extra parameters following the file-name. */
189745 flags |= SQLITE_OPEN_URI;
@@ -189769,11 +190120,11 @@
189769 if( zUri[5]=='/' && zUri[6]=='/' ){
189770 iIn = 7;
189771 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
189772 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
189773 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
189774 iIn-7, &zUri[7]);
189775 rc = SQLITE_ERROR;
189776 goto parse_uri_out;
189777 }
189778 }
189779 #endif
@@ -189844,15 +190195,15 @@
189844
189845 /* Check if there were any options specified that should be interpreted
189846 ** here. Options that are interpreted here include "vfs" and those that
189847 ** correspond to flags that may be passed to the sqlite3_open_v2()
189848 ** method. */
189849 zOpt = &zFile[sqlite3Strlen30(zFile)+1];
189850 while( zOpt[0] ){
189851 int nOpt = sqlite3Strlen30(zOpt);
189852 char *zVal = &zOpt[nOpt+1];
189853 int nVal = sqlite3Strlen30(zVal);
189854
189855 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
189856 zVfs = zVal;
189857 }else{
189858 struct OpenMode {
@@ -189894,11 +190245,11 @@
189894 if( aMode ){
189895 int i;
189896 int mode = 0;
189897 for(i=0; aMode[i].z; i++){
189898 const char *z = aMode[i].z;
189899 if( nVal==sqlite3Strlen30(z) && 0==memcmp(zVal, z, nVal) ){
189900 mode = aMode[i].mode;
189901 break;
189902 }
189903 }
189904 if( mode==0 ){
@@ -190579,17 +190930,21 @@
190579 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
190580 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
190581 ** by the next COMMIT or ROLLBACK.
190582 */
190583 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
 
190584 #ifdef SQLITE_ENABLE_API_ARMOR
190585 if( !sqlite3SafetyCheckOk(db) ){
190586 (void)SQLITE_MISUSE_BKPT;
190587 return 0;
190588 }
190589 #endif
190590 return db->autoCommit;
 
 
 
190591 }
190592
190593 /*
190594 ** The following routines are substitutes for constants SQLITE_CORRUPT,
190595 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
@@ -191610,21 +191965,23 @@
191610 /*
191611 ** Return the name of the N-th database schema. Return NULL if N is out
191612 ** of range.
191613 */
191614 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
 
191615 #ifdef SQLITE_ENABLE_API_ARMOR
191616 if( !sqlite3SafetyCheckOk(db) ){
191617 (void)SQLITE_MISUSE_BKPT;
191618 return 0;
191619 }
191620 #endif
191621 if( N<0 || N>=db->nDb ){
191622 return 0;
191623 }else{
191624 return db->aDb[N].zDbSName;
191625 }
 
 
191626 }
191627
191628 /*
191629 ** Return the filename of the database associated with a database
191630 ** connection.
@@ -197602,10 +197959,11 @@
197602 }else{
197603 int nDistance;
197604 char *p1;
197605 char *p2;
197606 char *aOut;
 
197607
197608 if( nMaxUndeferred>iPrev ){
197609 p1 = aPoslist;
197610 p2 = pPhrase->doclist.pList;
197611 nDistance = nMaxUndeferred - iPrev;
@@ -197613,11 +197971,11 @@
197613 p1 = pPhrase->doclist.pList;
197614 p2 = aPoslist;
197615 nDistance = iPrev - nMaxUndeferred;
197616 }
197617
197618 aOut = (char *)sqlite3Fts3MallocZero(((i64)nPoslist)+FTS3_BUFFER_PADDING);
197619 if( !aOut ){
197620 sqlite3_free(aPoslist);
197621 return SQLITE_NOMEM;
197622 }
197623
@@ -207898,11 +208256,11 @@
207898 if( nHeight<1 || nHeight>=FTS_MAX_APPENDABLE_HEIGHT ){
207899 sqlite3_reset(pSelect);
207900 return FTS_CORRUPT_VTAB;
207901 }
207902
207903 pWriter->nLeafEst = (int)((iEnd - iStart) + 1)/FTS_MAX_APPENDABLE_HEIGHT;
207904 pWriter->iStart = iStart;
207905 pWriter->iEnd = iEnd;
207906 pWriter->iAbsLevel = iAbsLevel;
207907 pWriter->iIdx = iIdx;
207908
@@ -215418,12 +215776,11 @@
215418 jsonBlobAppendNode(pParse, JSONB_TEXTRAW, nJson, zJson);
215419 }
215420 break;
215421 }
215422 case SQLITE_FLOAT: {
215423 double r = sqlite3_value_double(pArg);
215424 if( NEVER(sqlite3IsNaN(r)) ){
215425 jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
215426 }else{
215427 int n = sqlite3_value_bytes(pArg);
215428 const char *z = (const char*)sqlite3_value_text(pArg);
215429 if( z==0 ) return 1;
@@ -218016,11 +218373,11 @@
218016 int mxLevel; /* iLevel value for root of the tree */
218017 RtreeSearchPoint *aPoint; /* Priority queue for search points */
218018 sqlite3_stmt *pReadAux; /* Statement to read aux-data */
218019 RtreeSearchPoint sPoint; /* Cached next search point */
218020 RtreeNode *aNode[RTREE_CACHE_SZ]; /* Rtree node cache */
218021 u32 anQueue[RTREE_MAX_DEPTH+1]; /* Number of queued entries by iLevel */
218022 };
218023
218024 /* Return the Rtree of a RtreeCursor */
218025 #define RTREE_OF_CURSOR(X) ((Rtree*)((X)->base.pVtab))
218026
@@ -218499,11 +218856,11 @@
218499 ** are the leaves, and so on. If the depth as specified on the root node
218500 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
218501 */
218502 if( rc==SQLITE_OK && pNode && iNode==1 ){
218503 pRtree->iDepth = readInt16(pNode->zData);
218504 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
218505 rc = SQLITE_CORRUPT_VTAB;
218506 RTREE_IS_CORRUPT(pRtree);
218507 }
218508 }
218509
@@ -234473,11 +234830,11 @@
234473 SessionBuffer *p,
234474 const char *zStr,
234475 int *pRc
234476 ){
234477 int nStr = sqlite3Strlen30(zStr);
234478 if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
234479 memcpy(&p->aBuf[p->nBuf], zStr, nStr);
234480 p->nBuf += nStr;
234481 p->aBuf[p->nBuf] = 0x00;
234482 }
234483 }
@@ -239875,18 +240232,21 @@
239875 int nCol, /* Number of columns in each record */
239876 u8 *a1, int n1, /* Record 1 */
239877 u8 *a2, int n2, /* Record 2 */
239878 int *pRc /* IN/OUT: error code */
239879 ){
239880 sessionBufferGrow(pBuf, n1+n2, pRc);
 
 
 
239881 if( *pRc==SQLITE_OK ){
239882 int i;
239883 u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
239884 for(i=0; i<nCol; i++){
239885 int nn1 = sessionSerialLen(a1);
239886 int nn2 = sessionSerialLen(a2);
239887 if( *a1==0 || *a1==0xFF ){
239888 memcpy(pOut, a2, nn2);
239889 pOut += nn2;
239890 }else{
239891 memcpy(pOut, a1, nn1);
239892 pOut += nn1;
@@ -239924,11 +240284,11 @@
239924 sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */
239925 u8 *aRec, int nRec, /* Local change */
239926 u8 *aChange, int nChange, /* Record to rebase against */
239927 int *pRc /* IN/OUT: Return Code */
239928 ){
239929 sessionBufferGrow(pBuf, 2+nRec+nChange, pRc);
239930 if( *pRc==SQLITE_OK ){
239931 int bData = 0;
239932 u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
239933 int i;
239934 u8 *a1 = aRec;
@@ -258623,13 +258983,17 @@
258623 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
258624 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
258625 FTS5_CORRUPT_ROWID(p, iRow);
258626 }else{
258627 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
258628 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
258629 if( res==0 ) res = nTerm - nIdxTerm;
258630 if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
 
 
 
 
258631 }
258632
258633 fts5IntegrityCheckPgidx(p, iRow, pLeaf);
258634 }
258635 fts5DataRelease(pLeaf);
@@ -263267,11 +263631,11 @@
263267 int nArg, /* Number of args */
263268 sqlite3_value **apUnused /* Function arguments */
263269 ){
263270 assert( nArg==0 );
263271 UNUSED_PARAM2(nArg, apUnused);
263272 sqlite3_result_text(pCtx, "fts5: 2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06", -1, SQLITE_TRANSIENT);
263273 }
263274
263275 /*
263276 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263277 **
@@ -263909,38 +264273,35 @@
263909
263910 if( bCreate ){
263911 if( pConfig->eContent==FTS5_CONTENT_NORMAL
263912 || pConfig->eContent==FTS5_CONTENT_UNINDEXED
263913 ){
263914 int nDefn = 32 + pConfig->nCol*10;
263915 char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 20);
263916 if( zDefn==0 ){
263917 rc = SQLITE_NOMEM;
263918 }else{
263919 int i;
263920 int iOff;
263921 sqlite3_snprintf(nDefn, zDefn, "id INTEGER PRIMARY KEY");
263922 iOff = (int)strlen(zDefn);
263923 for(i=0; i<pConfig->nCol; i++){
263924 if( pConfig->eContent==FTS5_CONTENT_NORMAL
263925 || pConfig->abUnindexed[i]
263926 ){
263927 sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", c%d", i);
263928 iOff += (int)strlen(&zDefn[iOff]);
263929 }
263930 }
263931 if( pConfig->bLocale ){
263932 for(i=0; i<pConfig->nCol; i++){
263933 if( pConfig->abUnindexed[i]==0 ){
263934 sqlite3_snprintf(nDefn-iOff, &zDefn[iOff], ", l%d", i);
263935 iOff += (int)strlen(&zDefn[iOff]);
263936 }
263937 }
263938 }
263939 rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
263940 }
263941 sqlite3_free(zDefn);
263942 }
263943
263944 if( rc==SQLITE_OK && pConfig->bColumnsize ){
263945 const char *zCols = "id INTEGER PRIMARY KEY, sz BLOB";
263946 if( pConfig->bContentlessDelete ){
263947
--- 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 ** 716782abe939083b7732289d862ddfd84105 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -467,14 +467,14 @@
467 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
468 ** [sqlite_version()] and [sqlite_source_id()].
469 */
470 #define SQLITE_VERSION "3.54.0"
471 #define SQLITE_VERSION_NUMBER 3054000
472 #define SQLITE_SOURCE_ID "2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c"
473 #define SQLITE_SCM_BRANCH "trunk"
474 #define SQLITE_SCM_TAGS ""
475 #define SQLITE_SCM_DATETIME "2026-06-26T19:31:46.902Z"
476
477 /*
478 ** CAPI3REF: Run-Time Library Version Numbers
479 ** KEYWORDS: sqlite3_version sqlite3_sourceid
480 **
@@ -3732,11 +3732,11 @@
3732 ** authorizer will fail with an error message explaining that
3733 ** access is denied.
3734 **
3735 ** ^The first parameter to the authorizer callback is a copy of the third
3736 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3737 ** to the callback is an integer [SQLITE_READ | action code] that specifies
3738 ** the particular action to be authorized. ^The third through sixth parameters
3739 ** to the callback are either NULL pointers or zero-terminated strings
3740 ** that contain additional details about the action to be authorized.
3741 ** Applications must always be prepared to encounter a NULL pointer in any
3742 ** of the third through the sixth parameters of the authorization callback.
@@ -3775,25 +3775,37 @@
3775 ** ^(Only a single authorizer can be in place on a database connection
3776 ** at a time. Each call to sqlite3_set_authorizer overrides the
3777 ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
3778 ** The authorizer is disabled by default.
3779 **
3780 ** <h3>Limitations And Caveats</h3><ul>
3781 **
3782 ** <li>The authorizer callback must not do anything that will modify
3783 ** the database connection that invoked the authorizer callback.
3784 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3785 ** database connections for the meaning of "modify" in this paragraph.
3786 **
3787 ** <li>^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3788 ** statement might be re-prepared during [sqlite3_step()] due to a
3789 ** schema change. Hence, the application should ensure that the
3790 ** correct authorizer callback remains in place during the [sqlite3_step()].
3791 **
3792 ** <li>^The authorizer callback is invoked only during
3793 ** [sqlite3_prepare()] or its variants. Authorization is not
3794 ** performed during statement evaluation in [sqlite3_step()], unless
3795 ** as stated in the previous paragraph, sqlite3_step() invokes
3796 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3797 **
3798 ** <li>Authorizer callbacks for the expressions of a
3799 ** [generated column] are invoked when the schema is parsed (and specifically
3800 ** when the [CREATE TABLE] statement that contains the generated column is
3801 ** parsed) not when the generated column is used in a DML statement.
3802 ** This is deliberate, as one of the purposes of generated columns
3803 ** is to give schema designers the ability to provide gated access
3804 ** to privileged columns and/or functions.
3805 **
3806 ** </ul>
3807 */
3808 SQLITE_API int sqlite3_set_authorizer(
3809 sqlite3*,
3810 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3811 void *pUserData
@@ -3864,12 +3876,17 @@
3876 #define SQLITE_ANALYZE 28 /* Table Name NULL */
3877 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
3878 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3879 #define SQLITE_FUNCTION 31 /* NULL Function Name */
3880 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
 
3881 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3882
3883 /*
3884 ** Note: The SQLITE_COPY macro (with value 0) used to be one of the
3885 ** action codes above. That macro has now been repurposed as a possible
3886 ** value to the 3rd argument to sqlite3_result_str().
3887 */
3888
3889 /*
3890 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3891 ** DEPRECATED
3892 **
@@ -4860,10 +4877,12 @@
4877 ** there is a small performance advantage to passing an nByte parameter that
4878 ** is the number of bytes in the input string <i>including</i>
4879 ** the nul-terminator.
4880 ** Note that nByte measures the length of the input in bytes, not
4881 ** characters, even for the UTF-16 interfaces.
4882 ** For the sqlite3_prepare16() and sqlite3_prepare16_v2() interfaces,
4883 ** the nByte value must be even or undefined behavior can result.
4884 **
4885 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4886 ** past the end of the first SQL statement in zSql. These routines only
4887 ** compile the first statement in zSql, so *pzTail is left pointing to
4888 ** what remains uncompiled.
@@ -5606,11 +5625,11 @@
5625 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5626 ** can be obtained by calling [sqlite3_reset()] on the
5627 ** [prepared statement]. ^In the "v2" interface,
5628 ** the more specific error code is returned directly by sqlite3_step().
5629 **
5630 ** [SQLITE_MISUSE] means that this routine was called inappropriately.
5631 ** Perhaps it was called on a [prepared statement] that has
5632 ** already been [sqlite3_finalize | finalized] or on one that had
5633 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
5634 ** be the case that the same database connection is being used by two or
5635 ** more threads at the same moment in time.
@@ -9117,12 +9136,12 @@
9136 ** The lifecycle of an sqlite3_str object is as follows:
9137 ** <ol>
9138 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
9139 ** <li> ^Text is appended to the sqlite3_str object using various
9140 ** methods, such as [sqlite3_str_appendf()].
9141 ** <li> The sqlite3_str object is destroyed and the string it created
9142 ** is returned using [sqlite3_str_finish()] or [sqlite3_result_str()].
9143 ** </ol>
9144 */
9145 typedef struct sqlite3_str sqlite3_str;
9146
9147 /*
@@ -9170,10 +9189,44 @@
9189 ** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
9190 */
9191 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
9192 SQLITE_API void sqlite3_str_free(sqlite3_str*);
9193
9194 /*
9195 ** CAPI3REF: Return A Dynamic String From an SQL Function
9196 **
9197 ** The [sqlite3_result_str(C,S,F)] interface causes the
9198 ** [sqlite3_str|dynamic string] S to become the return value for the
9199 ** application-defined function or virtual table that uses
9200 ** [sqlite3_context] C. The F flag can be one of [SQLITE_COPY]
9201 ** or [SQLITE_XFER] or [SQLITE_FINISH].
9202 **
9203 ** If the dynamic string is invalid or incomplete due to an out-of-memory
9204 ** or string-too-large error, then this routine transfers that error
9205 ** over to the SQL function.
9206 **
9207 ** If the F argument is SQLITE_COPY, then a copy of the dynamic string
9208 ** content is made and the dynamic string object is unchanged.
9209 ** If the F argument is SQLITE_XFER, then ownership of the content
9210 ** in the dynamic is transferred to the SQL function (via a pointer copy
9211 ** rather than a string copy) and the dynamic string is reset to an
9212 ** empty string. The SQLITE_FINISH value for F works like SQLITE_RESET
9213 ** except that it also invokes the [sqlite3_str_free(S)] destructor
9214 ** on the dynamic string object.
9215 */
9216 SQLITE_API void sqlite3_result_str(sqlite3_context*, sqlite3_str*, int);
9217
9218 /*
9219 ** CAPI3REF: Control Flags For sqlite3_result_str()
9220 **
9221 ** The following integers can be used as the third "F" argument
9222 ** to [sqlite3_result_str(C,S,F)].
9223 */
9224 #define SQLITE_COPY 0 /* Results copied. Dynamic string unchanged */
9225 #define SQLITE_XFER 1 /* Results transfered. Dynamic string reset */
9226 #define SQLITE_FINISH 2 /* Like SQLITE_XFER, plus dynamic string freed */
9227
9228 /*
9229 ** CAPI3REF: Add Content To A Dynamic String
9230 ** METHOD: sqlite3_str
9231 **
9232 ** These interfaces add or remove content to an sqlite3_str object
@@ -17190,11 +17243,11 @@
17243 SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
17244 #endif
17245
17246 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
17247 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
17248 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree*, Btree*);
17249
17250 SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *);
17251
17252 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
17253 ** of the flags shown below.
@@ -17267,16 +17320,23 @@
17320 ** The design of the _RANGE hint is aid b-tree implementations that try
17321 ** to prefetch content from remote machines - to provide those
17322 ** implementations with limits on what needs to be prefetched and thereby
17323 ** reduce network bandwidth.
17324 **
17325 ** BTREE_HINT_TABLECURSOR (arguments: BtCursor*)
17326 **
17327 ** This hint is invoked on a non-covering index cursor soon after it
17328 ** is opened. The only argument is a pointer to the table cursor used to
17329 ** obtain non-covered fields from the database.
17330 **
17331 ** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
17332 ** standard SQLite. The other hints are provided for extensions that use
17333 ** the SQLite parser and code generator but substitute their own storage
17334 ** engine.
17335 */
17336 #define BTREE_HINT_RANGE 0 /* Range constraints on queries */
17337 #define BTREE_HINT_TABLECURSOR 1 /* Table csr associated with this index csr */
17338
17339 /*
17340 ** Values that may be OR'd together to form the argument to the
17341 ** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint():
17342 **
@@ -17332,10 +17392,13 @@
17392 #endif
17393 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
17394 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
17395 #ifdef SQLITE_ENABLE_CURSOR_HINTS
17396 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
17397 #ifdef SQLITE_DEBUG
17398 SQLITE_PRIVATE BtCursor *sqlite3BtreeCursorHintTblCsr(BtCursor*);
17399 #endif
17400 #endif
17401
17402 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor*);
17403 SQLITE_PRIVATE int sqlite3BtreeTableMoveto(
17404 BtCursor*,
@@ -20940,16 +21003,16 @@
21003 bft bHasExists :1; /* Has a correlated "EXISTS (SELECT ....)" expression */
21004 bft colNamesSet :1; /* TRUE after OP_ColumnName has been issued to pVdbe */
21005 bft bHasWith :1; /* True if statement contains WITH */
21006 bft okConstFactor:1; /* OK to factor out constants */
21007 bft checkSchema :1; /* Causes schema cookie check after an error */
21008 bft usesAinc :1; /* True if pAinc is valid */
21009 int nRangeReg; /* Size of the temporary register block */
21010 int iRangeReg; /* First register in temporary register block */
21011 int nErr; /* Number of errors seen */
21012 int nTab; /* Number of previously allocated VDBE cursors */
21013 int nMem; /* Number of memory cells used so far */
 
21014 int iSelfTab; /* Table associated with an index on expr, or negative
21015 ** of the base register during check-constraint eval */
21016 int nNestSel; /* Number of nested SELECT statements and/or VIEWs */
21017 int nLabel; /* The *negative* of the number of labels used */
21018 int nLabelAlloc; /* Number of slots in aLabel */
@@ -20964,13 +21027,11 @@
21027 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
21028 u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
21029 #endif
21030 #ifndef SQLITE_OMIT_SHARED_CACHE
21031 int nTableLock; /* Number of locks in aTableLock */
 
21032 #endif
 
21033 Parse *pToplevel; /* Parse structure for main program (or NULL) */
21034 Table *pTriggerTab; /* Table triggers are being coded for */
21035 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
21036 ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
21037
@@ -20995,10 +21056,17 @@
21056 } cr;
21057 struct { /* These fields available to all other statements */
21058 Returning *pReturning; /* The RETURNING clause */
21059 } d;
21060 } u1;
21061 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters. Only
21062 ** valid if Parse.usesAinc is true */
21063 #ifndef SQLITE_OMIT_SHARED_CACHE
21064 TableLock *aTableLock; /* Required table locks for shared-cache mode. Only
21065 ** valid if Parse.nTableLock>0 */
21066 #endif
21067
21068
21069 /************************************************************************
21070 ** Above is constant between recursions. Below is reset before and after
21071 ** each recursion. The boundary between these two regions is determined
21072 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
@@ -22528,10 +22596,11 @@
22596 SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
22597 SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
22598 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
22599 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
22600 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
22601 SQLITE_PRIVATE const sqlite3_str sqlite3OomStr;
22602 #ifndef SQLITE_OMIT_WSD
22603 SQLITE_PRIVATE int sqlite3PendingByte;
22604 #endif
22605 #endif /* SQLITE_AMALGAMATION */
22606 #ifdef VDBE_PROFILE
@@ -22630,11 +22699,10 @@
22699 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
22700 SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
22701 SQLITE_PRIVATE int sqlite3StrAccumEnlargeIfNeeded(StrAccum*, i64);
22702 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
22703 SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
 
22704 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
22705 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
22706 SQLITE_PRIVATE void sqlite3RecordErrorByteOffset(sqlite3*,const char*);
22707 SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3*,const Expr*);
22708
@@ -24228,10 +24296,20 @@
24296 ** Hash table for global functions - functions common to all
24297 ** database connections. After initialization, this table is
24298 ** read-only.
24299 */
24300 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
24301
24302 /*
24303 ** This singleton is an sqlite3_str object that is returned if
24304 ** sqlite3_malloc() fails to provide space for a real one. This
24305 ** sqlite3_str object accepts no new text and always returns
24306 ** an SQLITE_NOMEM error.
24307 */
24308 SQLITE_PRIVATE const sqlite3_str sqlite3OomStr = {
24309 0, 0, 0, 0, 0, SQLITE_NOMEM, 0
24310 };
24311
24312 #if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)
24313 /*
24314 ** Counter used for coverage testing. Does not come into play for
24315 ** release builds.
@@ -26947,42 +27025,42 @@
27025 ){
27026 DateTime x;
27027 size_t i,j;
27028 sqlite3 *db;
27029 const char *zFmt;
27030 sqlite3_str *pRes;
27031
27032
27033 if( argc==0 ) return;
27034 zFmt = (const char*)sqlite3_value_text(argv[0]);
27035 if( zFmt==0 || isDate(context, argc-1, argv+1, &x) ) return;
27036 db = sqlite3_context_db_handle(context);
27037 pRes = sqlite3_str_new(db);
27038
27039 computeJD(&x);
27040 computeYMD_HMS(&x);
27041 for(i=j=0; zFmt[i]; i++){
27042 char cf;
27043 if( zFmt[i]!='%' ) continue;
27044 if( j<i ) sqlite3_str_append(pRes, zFmt+j, (int)(i-j));
27045 i++;
27046 j = i + 1;
27047 cf = zFmt[i];
27048 switch( cf ){
27049 case 'd': /* Fall thru */
27050 case 'e': {
27051 sqlite3_str_appendf(pRes, cf=='d' ? "%02d" : "%2d", x.D);
27052 break;
27053 }
27054 case 'f': { /* Fractional seconds. (Non-standard) */
27055 double s = x.s;
27056 if( NEVER(s>59.999) ) s = 59.999;
27057 sqlite3_str_appendf(pRes, "%06.3f", s);
27058 break;
27059 }
27060 case 'F': {
27061 sqlite3_str_appendf(pRes, "%04d-%02d-%02d", x.Y, x.M, x.D);
27062 break;
27063 }
27064 case 'G': /* Fall thru */
27065 case 'g': {
27066 DateTime y = x;
@@ -26990,85 +27068,85 @@
27068 /* Move y so that it is the Thursday in the same week as x */
27069 y.iJD += (3 - daysAfterMonday(&x))*86400000;
27070 y.validYMD = 0;
27071 computeYMD(&y);
27072 if( cf=='g' ){
27073 sqlite3_str_appendf(pRes, "%02d", y.Y%100);
27074 }else{
27075 sqlite3_str_appendf(pRes, "%04d", y.Y);
27076 }
27077 break;
27078 }
27079 case 'H':
27080 case 'k': {
27081 sqlite3_str_appendf(pRes, cf=='H' ? "%02d" : "%2d", x.h);
27082 break;
27083 }
27084 case 'I': /* Fall thru */
27085 case 'l': {
27086 int h = x.h;
27087 if( h>12 ) h -= 12;
27088 if( h==0 ) h = 12;
27089 sqlite3_str_appendf(pRes, cf=='I' ? "%02d" : "%2d", h);
27090 break;
27091 }
27092 case 'j': { /* Day of year. Jan01==1, Jan02==2, and so forth */
27093 sqlite3_str_appendf(pRes,"%03d",daysAfterJan01(&x)+1);
27094 break;
27095 }
27096 case 'J': { /* Julian day number. (Non-standard) */
27097 sqlite3_str_appendf(pRes,"%.16g",x.iJD/86400000.0);
27098 break;
27099 }
27100 case 'm': {
27101 sqlite3_str_appendf(pRes,"%02d",x.M);
27102 break;
27103 }
27104 case 'M': {
27105 sqlite3_str_appendf(pRes,"%02d",x.m);
27106 break;
27107 }
27108 case 'p': /* Fall thru */
27109 case 'P': {
27110 if( x.h>=12 ){
27111 sqlite3_str_append(pRes, cf=='p' ? "PM" : "pm", 2);
27112 }else{
27113 sqlite3_str_append(pRes, cf=='p' ? "AM" : "am", 2);
27114 }
27115 break;
27116 }
27117 case 'R': {
27118 sqlite3_str_appendf(pRes, "%02d:%02d", x.h, x.m);
27119 break;
27120 }
27121 case 's': {
27122 if( x.useSubsec ){
27123 sqlite3_str_appendf(pRes,"%.3f",
27124 (x.iJD - 21086676*(i64)10000000)/1000.0);
27125 }else{
27126 i64 iS = (i64)(x.iJD/1000 - 21086676*(i64)10000);
27127 sqlite3_str_appendf(pRes,"%lld",iS);
27128 }
27129 break;
27130 }
27131 case 'S': {
27132 sqlite3_str_appendf(pRes,"%02d",(int)x.s);
27133 break;
27134 }
27135 case 'T': {
27136 sqlite3_str_appendf(pRes,"%02d:%02d:%02d", x.h, x.m, (int)x.s);
27137 break;
27138 }
27139 case 'u': /* Day of week. 1 to 7. Monday==1, Sunday==7 */
27140 case 'w': { /* Day of week. 0 to 6. Sunday==0, Monday==1 */
27141 char c = (char)daysAfterSunday(&x) + '0';
27142 if( c=='0' && cf=='u' ) c = '7';
27143 sqlite3_str_appendchar(pRes, 1, c);
27144 break;
27145 }
27146 case 'U': { /* Week num. 00-53. First Sun of the year is week 01 */
27147 sqlite3_str_appendf(pRes,"%02d",
27148 (daysAfterJan01(&x)-daysAfterSunday(&x)+7)/7);
27149 break;
27150 }
27151 case 'V': { /* Week num. 01-53. First week with a Thur is week 01 */
27152 DateTime y = x;
@@ -27075,34 +27153,34 @@
27153 /* Adjust y so that is the Thursday in the same week as x */
27154 assert( y.validJD );
27155 y.iJD += (3 - daysAfterMonday(&x))*86400000;
27156 y.validYMD = 0;
27157 computeYMD(&y);
27158 sqlite3_str_appendf(pRes,"%02d", daysAfterJan01(&y)/7+1);
27159 break;
27160 }
27161 case 'W': { /* Week num. 00-53. First Mon of the year is week 01 */
27162 sqlite3_str_appendf(pRes,"%02d",
27163 (daysAfterJan01(&x)-daysAfterMonday(&x)+7)/7);
27164 break;
27165 }
27166 case 'Y': {
27167 sqlite3_str_appendf(pRes,"%04d",x.Y);
27168 break;
27169 }
27170 case '%': {
27171 sqlite3_str_appendchar(pRes, 1, '%');
27172 break;
27173 }
27174 default: {
27175 sqlite3_str_free(pRes);
27176 return;
27177 }
27178 }
27179 }
27180 if( j<i ) sqlite3_str_append(pRes, zFmt+j, (int)(i-j));
27181 sqlite3_result_str(context, pRes, SQLITE_FINISH);
27182 }
27183
27184 /*
27185 ** current_time()
27186 **
@@ -27234,11 +27312,11 @@
27312 clearYMD_HMS_TZ(&d1);
27313 computeYMD_HMS(&d1);
27314 sqlite3StrAccumInit(&sRes, 0, 0, 0, 100);
27315 sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f",
27316 sign, Y, M, d1.D-1, d1.h, d1.m, d1.s);
27317 sqlite3_result_str(context, &sRes, SQLITE_XFER);
27318 }
27319
27320
27321 /*
27322 ** current_timestamp()
@@ -27662,11 +27740,11 @@
27740 if( pVfs->iVersion>=2 && pVfs->xCurrentTimeInt64 ){
27741 rc = pVfs->xCurrentTimeInt64(pVfs, pTimeOut);
27742 }else{
27743 double r;
27744 rc = pVfs->xCurrentTime(pVfs, &r);
27745 *pTimeOut = sqlite3RealToI64(r*86400000.0);
27746 }
27747 return rc;
27748 }
27749
27750 SQLITE_PRIVATE int sqlite3OsOpenMalloc(
@@ -32612,10 +32690,14 @@
32690 */
32691 #ifndef SQLITE_PRINTF_PRECISION_LIMIT
32692 # define SQLITE_FP_PRECISION_LIMIT 100000000
32693 #endif
32694
32695 /* Forward reference */
32696 static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N);
32697 static void sqlite3StrAppendchar64(sqlite3_str *p, i64 N, char c);
32698
32699 /*
32700 ** Render a string given by "fmt" into the StrAccum object.
32701 */
32702 SQLITE_API void sqlite3_str_vappendf(
32703 sqlite3_str *pAccum, /* Accumulate results here */
@@ -32622,14 +32704,14 @@
32704 const char *fmt, /* Format string */
32705 va_list ap /* arguments */
32706 ){
32707 int c; /* Next character in the format string */
32708 char *bufpt; /* Pointer to the conversion buffer */
32709 i64 precision; /* Precision of the current field */
32710 i64 length; /* Length of the field */
32711 int idx; /* A general purpose loop counter */
32712 i64 width; /* Width of the current field */
32713 etByte flag_leftjustify; /* True if "-" flag is present */
32714 etByte flag_prefix; /* '+' or ' ' or 0 for prefix */
32715 etByte flag_alternateform; /* True if "#" flag is present */
32716 etByte flag_altform2; /* True if "!" flag is present */
32717 etByte flag_zeropad; /* True if field width constant starts with zero */
@@ -32673,11 +32755,11 @@
32755 fmt = strchr(fmt, '%');
32756 if( fmt==0 ){
32757 fmt = bufpt + strlen(bufpt);
32758 }
32759 #endif
32760 sqlite3StrAppend64(pAccum, bufpt, fmt - bufpt);
32761 if( *fmt==0 ) break;
32762 }
32763 if( (c=(*++fmt))==0 ){
32764 sqlite3_str_append(pAccum, "%", 1);
32765 break;
@@ -32919,26 +33001,27 @@
33001 do{ /* Convert to ascii */
33002 *(--bufpt) = cset[longvalue%base];
33003 longvalue = longvalue/base;
33004 }while( longvalue>0 );
33005 }
33006 length = &zOut[nOut-1] - bufpt;
33007 if( precision>length ){ /* zero pad */
33008 i64 nn = precision-length;
33009 bufpt -= nn;
33010 memset(bufpt,'0',nn);
33011 length = precision;
33012 }
33013 if( cThousand ){
33014 i64 nn = (length - 1)/3; /* Number of "," to insert */
33015 i64 ix = (length - 1)%3 + 1;
33016 int ii;
33017 bufpt -= nn;
33018 for(ii=0; nn>0; ii++){
33019 bufpt[ii] = bufpt[ii+nn];
33020 ix--;
33021 if( ix==0 ){
33022 bufpt[++ii] = cThousand;
33023 nn--;
33024 ix = 3;
33025 }
33026 }
33027 }
@@ -32947,11 +33030,11 @@
33030 const char *pre;
33031 char x;
33032 pre = &aPrefix[infop->prefix];
33033 for(; (x=(*pre))!=0; pre++) *(--bufpt) = x;
33034 }
33035 length = &zOut[nOut-1] - bufpt;
33036 break;
33037 case etFLOAT:
33038 case etEXP:
33039 case etGENERIC: {
33040 FpDecode s;
@@ -32979,12 +33062,17 @@
33062 iRound = precision+1;
33063 }
33064 sqlite3FpDecode(&s, realvalue, iRound, flag_altform2 ? 20 : 16);
33065 if( s.isSpecial ){
33066 if( s.isSpecial==2 ){
33067 if( flag_zeropad ){
33068 bufpt = "null";
33069 length = 4;
33070 }else{
33071 bufpt = "NaN";
33072 length = 3;
33073 }
33074 break;
33075 }else if( flag_zeropad ){
33076 s.z[0] = '9';
33077 s.iDP = 1000;
33078 s.n = 1;
@@ -32996,11 +33084,11 @@
33084 }else if( flag_prefix ){
33085 buf[0] = flag_prefix;
33086 }else{
33087 bufpt++;
33088 }
33089 length = strlen(bufpt);
33090 break;
33091 }
33092 }
33093 if( s.sign=='-' ){
33094 if( flag_alternateform
@@ -33152,11 +33240,11 @@
33240 }
33241 *(bufpt++) = (char)(exp/10+'0'); /* 10's digit */
33242 *(bufpt++) = (char)(exp%10+'0'); /* 1's digit */
33243 }
33244
33245 length = bufpt - zOut;
33246 assert( length <= szBufNeeded );
33247 if( length<width ){
33248 i64 nPad = width - length;
33249 if( flag_leftjustify ){
33250 memset(bufpt, ' ', nPad);
@@ -33172,10 +33260,11 @@
33260 }
33261
33262 if( zExtra==0 ){
33263 /* The result is being rendered directory into pAccum. This
33264 ** is the common and fast case */
33265 assert( pAccum->nChar + length < SMXV(pAccum->nChar) );
33266 pAccum->nChar += length;
33267 zOut[length] = 0;
33268 continue;
33269 }else{
33270 /* We were unable to render directly into pAccum because we
@@ -33218,14 +33307,14 @@
33307 }
33308 if( precision>1 ){
33309 i64 nPrior = 1;
33310 width -= precision-1;
33311 if( width>1 && !flag_leftjustify ){
33312 sqlite3StrAppendchar64(pAccum, width-1, ' ');
33313 width = 0;
33314 }
33315 sqlite3StrAppend64(pAccum, buf, length);
33316 precision--;
33317 while( precision > 1 ){
33318 i64 nCopyBytes;
33319 if( nPrior > precision-1 ) nPrior = precision - 1;
33320 nCopyBytes = length*nPrior;
@@ -33277,21 +33366,21 @@
33366 ** precision characters */
33367 unsigned char *z = (unsigned char*)bufpt;
33368 while( precision-- > 0 && z[0] ){
33369 SQLITE_SKIP_UTF8(z);
33370 }
33371 length = z - (unsigned char*)bufpt;
33372 }else{
33373 for(length=0; length<precision && bufpt[length]; length++){}
33374 }
33375 }else{
33376 length = strlen(bufpt);
33377 }
33378 adjust_width_for_utf8:
33379 if( flag_altform2 && width>0 ){
33380 /* Adjust width to account for extra bytes in UTF-8 characters */
33381 i64 ii = length - 1;
33382 while( ii>=0 ) if( (bufpt[ii--] & 0xc0)==0x80 ) width++;
33383 }
33384 break;
33385 case etESCAPE_j: /* %j: JSON string literal w/o "..." */
33386 case etESCAPE_J: { /* %J: Generate a JSON string literal */
@@ -33322,11 +33411,11 @@
33411 while( (escarg[px]&0xc0)==0x80 ) px++;
33412 }
33413 }
33414 for(i=j=0; i<px; i++){
33415 if( (ch = ((u8*)escarg)[i])<=0x1f || ch=='"' || ch=='\\' ){
33416 if( j<i ) sqlite3StrAppend64(pAccum, &escarg[j], i-j);
33417 j = i+1;
33418 if( ch==0 ) break;
33419 sqlite3_str_appendchar(pAccum, 1, '\\');
33420 if( ch>0x1f ){
33421 sqlite3_str_appendchar(pAccum, 1, ch);
@@ -33338,11 +33427,11 @@
33427 sqlite3_str_appendchar(pAccum, 1, aHex[ch>>4]);
33428 sqlite3_str_appendchar(pAccum, 1, aHex[ch&0xf]);
33429 }
33430 }
33431 }
33432 if( j<i ) sqlite3StrAppend64(pAccum, &escarg[j], i-j);
33433 if( xtype==etESCAPE_J ) sqlite3_str_append(pAccum, "\"", 1);
33434 }
33435 if( width>0 && sqlite3_str_errcode(pAccum)==SQLITE_OK ){
33436 sqlite3_int64 n = sqlite3_str_length(pAccum) - iStart;
33437 sqlite3_int64 len = n;
@@ -33354,11 +33443,11 @@
33443 }
33444 }
33445 if( width>len ){
33446 sqlite3_int64 sp = width-len;
33447 assert( sp>0 && sp<0x7fffffff );
33448 sqlite3StrAppendchar64(pAccum, (int)sp, ' ');
33449 if( !flag_leftjustify
33450 && n>0
33451 && sqlite3_str_errcode(pAccum)==0
33452 ){
33453 zz = sqlite3_str_value(pAccum);
@@ -33546,15 +33635,15 @@
33635 ** indicating that width and precision should be expressed in characters,
33636 ** then the values have been translated prior to reaching this point.
33637 */
33638 width -= length;
33639 if( width>0 ){
33640 if( !flag_leftjustify ) sqlite3StrAppendchar64(pAccum, width, ' ');
33641 sqlite3StrAppend64(pAccum, bufpt, length);
33642 if( flag_leftjustify ) sqlite3StrAppendchar64(pAccum, width, ' ');
33643 }else{
33644 sqlite3StrAppend64(pAccum, bufpt, length);
33645 }
33646
33647 if( zExtra ){
33648 sqlite3DbFree(pAccum->db, zExtra);
33649 zExtra = 0;
@@ -33670,10 +33759,17 @@
33759 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
33760 return;
33761 }
33762 while( (N--)>0 ) p->zText[p->nChar++] = c;
33763 }
33764 static void sqlite3StrAppendchar64(sqlite3_str *p, i64 N, char c){
33765 testcase( p->nChar + N > 0x7fffffff );
33766 if( p->nChar+N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
33767 return;
33768 }
33769 while( (N--)>0 ) p->zText[p->nChar++] = c;
33770 }
33771
33772 /*
33773 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
33774 ** So enlarge if first, then do the append.
33775 **
@@ -33704,10 +33800,24 @@
33800 assert( p->zText );
33801 p->nChar += N;
33802 memcpy(&p->zText[p->nChar-N], z, N);
33803 }
33804 }
33805 static void sqlite3StrAppend64(sqlite3_str *p, const char *z, i64 N){
33806 assert( z!=0 || N==0 );
33807 assert( p->zText!=0 || p->nChar==0 || p->accError );
33808 assert( N>=0 );
33809 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
33810 if( p->nChar+N >= (i64)p->nAlloc ){
33811 enlargeAndAppend(p,z,N);
33812 }else if( N ){
33813 assert( p->zText );
33814 p->nChar += N;
33815 memcpy(&p->zText[p->nChar-N], z, N);
33816 }
33817 }
33818
33819
33820 /*
33821 ** Append the complete text of zero-terminated string z[] to the p string.
33822 */
33823 SQLITE_API void sqlite3_str_appendall(sqlite3_str *p, const char *z){
@@ -33741,41 +33851,15 @@
33851 }
33852 }
33853 return p->zText;
33854 }
33855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33856 /* Finalize a string created using sqlite3_str_new().
33857 */
33858 SQLITE_API char *sqlite3_str_finish(sqlite3_str *p){
33859 char *z;
33860 if( p!=0 && p!=(sqlite3_str*)&sqlite3OomStr ){
33861 z = sqlite3StrAccumFinish(p);
33862 sqlite3_free(p);
33863 }else{
33864 z = 0;
33865 }
@@ -33812,10 +33896,12 @@
33896 */
33897 SQLITE_API void sqlite3_str_reset(StrAccum *p){
33898 if( isMalloced(p) ){
33899 sqlite3DbFree(p->db, p->zText);
33900 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
33901 }else if( p==(sqlite3_str*)&sqlite3OomStr ){
33902 return;
33903 }
33904 p->nAlloc = 0;
33905 p->nChar = 0;
33906 p->zText = 0;
33907 }
@@ -33823,11 +33909,11 @@
33909 /*
33910 ** Destroy a dynamically allocate sqlite3_str object and all
33911 ** of its content, all in one call.
33912 */
33913 SQLITE_API void sqlite3_str_free(sqlite3_str *p){
33914 if( p!=0 && p!=(sqlite3_str*)&sqlite3OomStr ){
33915 sqlite3_str_reset(p);
33916 sqlite3_free(p);
33917 }
33918 }
33919
@@ -33860,11 +33946,11 @@
33946 sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
33947 if( p ){
33948 sqlite3StrAccumInit(p, 0, 0, 0,
33949 db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
33950 }else{
33951 p = (sqlite3_str*)&sqlite3OomStr;
33952 }
33953 return p;
33954 }
33955
33956 /*
@@ -37500,11 +37586,11 @@
37586 return mState;
37587 }
37588 }
37589 return 0xfffffff0 | mState;
37590 #else
37591 return sqlite3Atoi64(zIn, pResult, strlen(zIn), SQLITE_UTF8)==0;
37592 #endif /* SQLITE_OMIT_FLOATING_POINT */
37593 }
37594
37595 /*
37596 ** Digit pairs used to convert a U64 or I64 into text, two digits
@@ -39731,20 +39817,21 @@
39817 i = 0;
39818 j = 0;
39819 while( 1 ){
39820 c = kvvfsHexValue[aIn[i]];
39821 if( c<0 ){
39822 sqlite3_int64 n = 0;
39823 sqlite3_int64 mult = 1;
39824 c = aIn[i];
39825 if( c==0 ) break;
39826 while( c>='a' && c<='z' ){
39827 n += (c - 'a')*mult;
39828 if( n>nOut ) return -1 /* oversized/malformed input */;
39829 mult *= 26;
39830 c = aIn[++i];
39831 }
39832 if( j+n>nOut ) return -1 /* oversized/malformed input */;
39833 memset(&aOut[j], 0, n);
39834 j += n;
39835 if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
39836 }else if( j<nOut ){
39837 aOut[j] = c<<4;
@@ -39773,22 +39860,28 @@
39860 static void kvvfsDecodeJournal(
39861 KVVfsFile *pFile, /* Store decoding in pFile->aJrnl */
39862 const char *zTxt, /* Text encoding. Zero-terminated */
39863 int nTxt /* Bytes in zTxt, excluding zero terminator */
39864 ){
39865 unsigned int n = 0, mult;
39866 int c, i;
39867 i = 0;
39868 mult = 1;
39869 sqlite3_free(pFile->aJrnl);
39870 pFile->aJrnl = 0;
39871 pFile->nJrnl = 0;
39872 while( (c = zTxt[i])>='a' && c<='z' ){
39873 n += (c - 'a')*mult;
39874 mult *= 26;
39875 ++i;
39876 }
39877 if( ' '!=zTxt[i++] ){
39878 /* Malformed input */
39879 return;
39880 }
39881 pFile->aJrnl = sqlite3_malloc64( n );
39882 if( pFile->aJrnl==0 ){
 
39883 return;
39884 }
39885 pFile->nJrnl = n;
39886 n = kvvfsDecode(zTxt+i, pFile->aJrnl, pFile->nJrnl);
39887 if( n<pFile->nJrnl ){
@@ -39824,13 +39917,11 @@
39917
39918 SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass,
39919 pFile->isJournal ? "journal" : "db"));
39920 sqlite3_free(pFile->aJrnl);
39921 sqlite3_free(pFile->aData);
 
39922 memset(pFile, 0, sizeof(*pFile));
 
39923 return SQLITE_OK;
39924 }
39925
39926 /*
39927 ** Read from the -journal file.
@@ -39856,10 +39947,11 @@
39947 if( aTxt==0 ) return SQLITE_NOMEM;
39948 rc = sqlite3KvvfsMethods.xRcrdRead(pFile->zClass, "jrnl",
39949 aTxt, szTxt+1);
39950 if( rc>=0 ){
39951 kvvfsDecodeJournal(pFile, aTxt, szTxt);
39952 rc = 0;
39953 }
39954 sqlite3_free(aTxt);
39955 if( rc ) return rc;
39956 if( pFile->aJrnl==0 ) return SQLITE_IOERR;
39957 }
@@ -40180,11 +40272,11 @@
40272 }
40273 if( !pFile->zClass ){
40274 #ifdef SQLITE_WASM
40275 if( strlen(zName) >= (KVRECORD_KEY_SZ
40276 - 6 /* "kvvfs-" */
40277 - 11 /* "-NNNNNNNNNNN" */) ){
40278 return SQLITE_CANTOPEN;
40279 }
40280 #else
40281 if( 0!=strcmp(zName, "local") && 0!=strcmp(zName, "session") ){
40282 /* Historical naming restriction which journaling depends on. */
@@ -52221,11 +52313,11 @@
52313 # define sqlite3_win_test_unc_locking 0
52314 #endif
52315
52316 /*
52317 ** Return true if the string passed as the only argument is likely
52318 ** to be a UNC path. Return false if not.
52319 **
52320 ** Return true if:
52321 **
52322 ** (1) The name begins with "\\"
52323 ** (2) But does not begin with "\\?\C:\" where C can be any alphabetic
@@ -55070,26 +55162,27 @@
55162 int iDb;
55163 Btree *pBt;
55164 sqlite3_int64 sz;
55165 int szPage = 0;
55166 sqlite3_stmt *pStmt = 0;
55167 unsigned char *pOut = 0;
55168 char *zSql;
55169 int rc;
55170
55171 #ifdef SQLITE_ENABLE_API_ARMOR
55172 if( !sqlite3SafetyCheckOk(db) ){
55173 (void)SQLITE_MISUSE_BKPT;
55174 return 0;
55175 }
55176 #endif
55177 sqlite3_mutex_enter(db->mutex);
55178
55179 if( zSchema==0 ) zSchema = db->aDb[0].zDbSName;
55180 p = memdbFromDbSchema(db, zSchema);
55181 iDb = sqlite3FindDbName(db, zSchema);
55182 if( piSize ) *piSize = -1;
55183 if( iDb<0 ) goto serialize_out;
55184 if( p ){
55185 MemStore *pStore = p->pStore;
55186 assert( pStore->pMutex==0 );
55187 if( piSize ) *piSize = pStore->sz;
55188 if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
@@ -55096,23 +55189,21 @@
55189 pOut = pStore->aData;
55190 }else{
55191 pOut = sqlite3_malloc64( pStore->sz );
55192 if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
55193 }
55194 goto serialize_out;
55195 }
55196 pBt = db->aDb[iDb].pBt;
55197 if( pBt==0 ) goto serialize_out;
55198 szPage = sqlite3BtreeGetPageSize(pBt);
55199 zSql = sqlite3_mprintf("PRAGMA \"%w\".page_count", zSchema);
55200 rc = zSql ? sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0) : SQLITE_NOMEM;
55201 sqlite3_free(zSql);
55202 if( rc ) goto serialize_out;
55203 rc = sqlite3_step(pStmt);
55204 if( rc==SQLITE_ROW ){
 
 
55205 sz = sqlite3_column_int64(pStmt, 0)*szPage;
55206 if( sz==0 ){
55207 sqlite3_reset(pStmt);
55208 sqlite3_exec(db, "BEGIN IMMEDIATE; COMMIT;", 0, 0, 0);
55209 rc = sqlite3_step(pStmt);
@@ -55142,10 +55233,13 @@
55233 }
55234 }
55235 }
55236 }
55237 sqlite3_finalize(pStmt);
55238
55239 serialize_out:
55240 sqlite3_mutex_leave(db->mutex);
55241 return pOut;
55242 }
55243
55244 /* Convert zSchema to a MemDB and initialize its content.
55245 */
@@ -59917,10 +60011,45 @@
60011 static void freeSuperJournal(char *zSuper){
60012 if( zSuper ){
60013 sqlite3_free(&zSuper[-4]);
60014 }
60015 }
60016
60017 /*
60018 ** Check if zSuper is a valid super-journal name. There are two valid
60019 ** formats:
60020 **
60021 ** + The 3rd and 4th last bytes of the filename are ".9", and the
60022 ** following 2 bytes are hex digits. This is a file created in 8.3
60023 ** filenames mode.
60024 **
60025 ** + The 3rd last byte of the filename is "9" and the filename
60026 ** contains the string "-mj" starting at the 12th last byte.
60027 ** All bytes following the "-mj" are hex digits.
60028 **
60029 ** If the filename matches either of these patterns, return non-zero.
60030 ** Otherwise, return zero.
60031 */
60032 static int pagerIsSuperJrnlName(const char *zSuper){
60033 const int nSuper = sqlite3Strlen30(zSuper);
60034 int ii;
60035
60036 #ifdef SQLITE_ENABLE_8_3_NAMES
60037 if( nSuper<4 ) return 0;
60038 if( zSuper[nSuper-3]!='9' ) return 0;
60039 if( sqlite3Isxdigit(zSuper[nSuper-2])==0 ) return 0;
60040 if( sqlite3Isxdigit(zSuper[nSuper-1])==0 ) return 0;
60041 if( zSuper[nSuper-4]=='.' ) return 1;
60042 #endif
60043 if( nSuper<12 ) return 0;
60044 if( memcmp(&zSuper[nSuper-12], "-mj", 3) ) return 0;
60045 if( zSuper[nSuper-3]!='9' ) return 0;
60046 for(ii=nSuper-9; ii<nSuper; ii++){
60047 if( sqlite3Isxdigit(zSuper[ii])==0 ) return 0;
60048 }
60049 return 1;
60050 }
60051
60052 /*
60053 ** Parameter pJrnl is a file-handle open on a journal file. This function
60054 ** attempts to read a super-journal file name from the end of the journal
60055 ** file. If successful, it sets output parameter (*pzSuper) to point to a
@@ -59955,32 +60084,34 @@
60084 || len>=nSuper
60085 || len>szJ-16
60086 || len==0
60087 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
60088 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
 
60089 ){
60090 return rc;
60091 }
60092
60093 zOut = (char*)sqlite3MallocZero(4 + len + 2);
60094 if( !zOut ){
60095 rc = memcmp(aMagic,aJournalMagic,8) ? SQLITE_OK : SQLITE_NOMEM_BKPT;
60096 }else{
60097 zOut = &zOut[4];
60098 if( SQLITE_OK==(rc = sqlite3OsRead(pJrnl, zOut, len, szJ-16-len)) ){
60099 u32 u; /* Unsigned loop counter */
60100 /* See if the checksum matches the super-journal name */
60101 for(u=0; u<len; u++){
60102 cksum -= zOut[u];
60103 }
60104 }
60105 if( rc!=SQLITE_OK /* Couldn't read the name */
60106 || !pagerIsSuperJrnlName(zOut) /* Name is not valid */
60107 || cksum /* checksum is incorrect */
60108 || memcmp(aMagic, aJournalMagic, 8)!=0 /* Bad magic number */
60109 ){
60110 /* If any validity checks fail, that means the super-journal filename
60111 ** is corrupted, so rollback. Return SQLITE_K and a NULL super-journal
60112 ** name */
60113 freeSuperJournal(zOut);
60114 zOut = 0;
60115 }
60116 }
60117
@@ -60359,10 +60490,11 @@
60490 i64 jrnlSize; /* Size of journal file on disk */
60491 u32 cksum = 0; /* Checksum of string zSuper */
60492
60493 assert( pPager->setSuper==0 );
60494 assert( !pagerUseWal(pPager) );
60495 assert( zSuper==0 || pagerIsSuperJrnlName(zSuper) );
60496
60497 if( !zSuper
60498 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
60499 || !isOpen(pPager->jfd)
60500 ){
@@ -61189,10 +61321,23 @@
61321 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
61322 char *zSuperJournal = 0; /* Contents of super-journal file */
61323 i64 nSuperJournal; /* Size of super-journal file */
61324 char *zJournal; /* Pointer to one journal within MJ file */
61325 char *zFree = 0; /* Free this buffer */
61326 int bSeen = 0; /* If super-journal contains pPager->zJournal */
61327
61328 /* Check if this looks like a real super-journal name. If it does not,
61329 ** return SQLITE_OK without attempting to delete it. This is to limit
61330 ** the degree to which a crafted journal file can be used to cause
61331 ** SQLite to delete arbitrary files.
61332 **
61333 ** This test never fails, becaue the super journal name is checked
61334 ** by readSuperJournal().
61335 */
61336 if( NEVER(pagerIsSuperJrnlName(zSuper)==0) ){
61337 return SQLITE_OK;
61338 }
61339
61340 /* Allocate space for both the pJournal and pSuper file descriptors.
61341 ** If successful, open the super-journal file for reading.
61342 */
61343 pSuper = (sqlite3_file *)sqlite3MallocZero(2 * (i64)pVfs->szOsFile);
@@ -61228,51 +61373,60 @@
61373 zSuperJournal[nSuperJournal] = 0;
61374 zSuperJournal[nSuperJournal+1] = 0;
61375
61376 zJournal = zSuperJournal;
61377 while( (zJournal-zSuperJournal)<nSuperJournal ){
61378 if( strcmp(zJournal, pPager->zJournal)==0 ){
61379 bSeen = 1;
61380 }else{
61381 int exists;
61382 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
61383 if( rc!=SQLITE_OK ){
61384 goto delsuper_out;
61385 }
61386 if( exists ){
61387 char *zSuperPtr = 0;
61388
61389 /* One of the journals pointed to by the super-journal exists.
61390 ** Open it and check if it points at the super-journal. If
61391 ** so, return without deleting the super-journal file.
61392 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
61393 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
61394 ** name into sqlite3_database_file_object().
61395 */
61396 int c;
61397 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
61398 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
61399 if( rc!=SQLITE_OK ){
61400 goto delsuper_out;
61401 }
61402
61403 rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr);
61404 sqlite3OsClose(pJournal);
61405 if( rc!=SQLITE_OK ){
61406 assert( zSuperPtr==0 );
61407 goto delsuper_out;
61408 }
61409
61410 c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0;
61411 freeSuperJournal(zSuperPtr);
61412 if( c ){
61413 /* We have a match. Do not delete the super-journal file. */
61414 goto delsuper_out;
61415 }
61416 }
61417 }
61418 zJournal += (sqlite3Strlen30(zJournal)+1);
61419 }
61420
61421 sqlite3OsClose(pSuper);
61422 if( bSeen ){
61423 /* Only delete the super-journal if bSeen is true - indicating that
61424 ** the super-journal contained a pointer to this database's journal
61425 ** file. */
61426 rc = sqlite3OsDelete(pVfs, zSuper, 0);
61427 }
61428
61429 delsuper_out:
61430 sqlite3_free(zFree);
61431 if( pSuper ){
61432 sqlite3OsClose(pSuper);
@@ -71674,10 +71828,13 @@
71828 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
71829 ** Error code if eState==CURSOR_FAULT */
71830 Btree *pBtree; /* The Btree to which this cursor belongs */
71831 Pgno *aOverflow; /* Cache of overflow page locations */
71832 void *pKey; /* Saved key that was cursor last known position */
71833 #if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
71834 BtCursor *pCursorHintTableCursor;
71835 #endif
71836 /* All fields above are zeroed when the cursor is allocated. See
71837 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
71838 ** initialized. */
71839 #define BTCURSOR_FIRST_UNINIT pBt /* Name of first uninitialized field */
71840 BtShared *pBt; /* The BtShared this cursor points to */
@@ -71850,10 +72007,13 @@
72007 int v2; /* Value for third %d substitution in zPfx */
72008 StrAccum errMsg; /* Accumulate the error message text here */
72009 u32 *heap; /* Min-heap used for analyzing cell coverage */
72010 sqlite3 *db; /* Database connection running the check */
72011 i64 nRow; /* Number of rows visited in current tree */
72012 #ifdef SQLITE_DEBUG
72013 u32 mxHeap; /* Maximum number of entries in the Min-heap */
72014 #endif
72015 };
72016
72017 /*
72018 ** Routines to read or write a two- and four-byte big-endian integer values.
72019 */
@@ -73178,28 +73338,45 @@
73338 ** parameter. See the definitions of the BTREE_HINT_* macros for details.
73339 */
73340 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor *pCur, int eHintType, ...){
73341 /* Used only by system that substitute their own storage engine */
73342 #ifdef SQLITE_DEBUG
73343 va_list ap;
73344 va_start(ap, eHintType);
73345 if( eHintType==BTREE_HINT_RANGE ){
73346 Expr *pExpr;
73347 Walker w;
73348 memset(&w, 0, sizeof(w));
73349 w.xExprCallback = sqlite3CursorRangeHintExprCheck;
 
73350 pExpr = va_arg(ap, Expr*);
73351 w.u.aMem = va_arg(ap, Mem*);
 
73352 assert( pExpr!=0 );
73353 assert( w.u.aMem!=0 );
73354 sqlite3WalkExpr(&w, pExpr);
73355 }else if( ALWAYS(eHintType==BTREE_HINT_TABLECURSOR) ){
73356 BtCursor *pCsr = va_arg(ap, BtCursor*);
73357 assert( pCur->pCursorHintTableCursor==0
73358 || pCur->pCursorHintTableCursor==pCsr
73359 );
73360 assert( pCsr->pKeyInfo==0 || CORRUPT_DB );
73361 pCur->pCursorHintTableCursor = pCsr;
73362 }
73363 va_end(ap);
73364 #endif /* SQLITE_DEBUG */
73365 }
73366 #endif /* SQLITE_ENABLE_CURSOR_HINTS */
73367
73368 #if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
73369 /*
73370 ** Return the pointer configured via the BTREE_HINT_TABLECURSOR hint on
73371 ** cursor pCsr. This is used from OP_DeferredSeek to assert() that the
73372 ** index cursor has been correctly configured with the table cursor.
73373 */
73374 SQLITE_PRIVATE BtCursor *sqlite3BtreeCursorHintTblCsr(BtCursor *pCsr){
73375 return pCsr->pCursorHintTableCursor;
73376 }
73377 #endif
73378
73379 /*
73380 ** Provide flag hints to the cursor.
73381 */
73382 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor *pCur, unsigned x){
@@ -74321,12 +74498,16 @@
74498 /* Freeblock off the end of the page */
74499 return SQLITE_CORRUPT_PAGE(pPage);
74500 }
74501 next = get2byte(&data[pc]);
74502 size = get2byte(&data[pc+2]);
74503 if( size<4 ){
74504 /* Minimum freeblock size is 4 */
74505 return SQLITE_CORRUPT_PAGE(pPage);
74506 }
74507 nFree = nFree + size;
74508 if( next<pc+size+4 ) break;
74509 pc = next;
74510 }
74511 if( next>0 ){
74512 /* Freeblock not in ascending order */
74513 return SQLITE_CORRUPT_PAGE(pPage);
@@ -78157,18 +78338,18 @@
78338 nCell = pCell[0];
78339 if( nCell<=pPage->max1bytePayload ){
78340 /* This branch runs if the record-size field of the cell is a
78341 ** single byte varint and the record fits entirely on the main
78342 ** b-tree page. */
78343 if( pCell + nCell >= pPage->aDataEnd ) return 99;
78344 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
78345 }else if( !(pCell[1] & 0x80)
78346 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
78347 ){
78348 /* The record-size field is a 2 byte varint and the record
78349 ** fits entirely on the main b-tree page. */
78350 if( pCell + nCell >= pPage->aDataEnd ) return 99;
78351 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
78352 }else{
78353 /* If the record extends into overflow pages, do not attempt
78354 ** the optimization. */
78355 c = 99;
@@ -78326,18 +78507,21 @@
78507 nCell = pCell[0];
78508 if( nCell<=pPage->max1bytePayload ){
78509 /* This branch runs if the record-size field of the cell is a
78510 ** single byte varint and the record fits entirely on the main
78511 ** b-tree page. */
78512 if( pCell + nCell >= pPage->aDataEnd ){
78513 rc = SQLITE_CORRUPT_PAGE(pPage);
78514 goto moveto_index_finish;
78515 }
78516 c = xRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
78517 }else if( !(pCell[1] & 0x80)
78518 && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
78519 && pCell + nCell < pPage->aDataEnd
78520 ){
78521 /* The record-size field is a 2 byte varint and the record
78522 ** fits entirely on the main b-tree page. */
 
78523 c = xRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
78524 }else{
78525 /* The record flows over onto one or more overflow pages. In
78526 ** this case the whole cell needs to be parsed, a buffer allocated
78527 ** and accessPayload() used to retrieve the record into the
@@ -83203,10 +83387,11 @@
83387 checkAppendMsg(pCheck, "Child page depth differs");
83388 depth = d2;
83389 }
83390 }else{
83391 /* Populate the coverage-checking heap for leaf pages */
83392 assert( heap[0] < pCheck->mxHeap );
83393 btreeHeapInsert(heap, (pc<<16)|(pc+info.nSize-1));
83394 }
83395 }
83396 *piMinKey = maxKey;
83397
@@ -83222,10 +83407,11 @@
83407 heap[0] = 0;
83408 for(i=nCell-1; i>=0; i--){
83409 u32 size;
83410 pc = get2byteAligned(&data[cellStart+i*2]);
83411 size = pPage->xCellSize(pPage, &data[pc]);
83412 assert( heap[0] < pCheck->mxHeap );
83413 btreeHeapInsert(heap, (pc<<16)|(pc+size-1));
83414 }
83415 }
83416 assert( heap!=0 );
83417 /* Add the freeblocks to the min-heap
@@ -83238,10 +83424,11 @@
83424 while( i>0 ){
83425 int size, j;
83426 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
83427 size = get2byte(&data[i+2]);
83428 assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
83429 assert( heap[0] < pCheck->mxHeap );
83430 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
83431 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
83432 ** big-endian integer which is the offset in the b-tree page of the next
83433 ** freeblock in the chain, or zero if the freeblock is the last on the
83434 ** chain. */
@@ -83372,10 +83559,13 @@
83559 if( !sCheck.aPgRef ){
83560 checkOom(&sCheck);
83561 goto integrity_ck_cleanup;
83562 }
83563 sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
83564 #ifdef SQLITE_DEBUG
83565 sCheck.mxHeap = pBt->pageSize/4 - 1;
83566 #endif
83567 if( sCheck.heap==0 ){
83568 checkOom(&sCheck);
83569 goto integrity_ck_cleanup;
83570 }
83571
@@ -83796,17 +83986,18 @@
83986 /*
83987 ** Structure allocated for each backup operation.
83988 */
83989 struct sqlite3_backup {
83990 sqlite3* pDestDb; /* Destination database handle */
83991 char *zDestDb;
83992 Btree *pDest; /* Destination b-tree file */
83993 u32 iDestSchema; /* Original schema cookie in destination */
83994 int bDestLocked; /* True once a write-transaction is open on pDest */
83995
83996 Pgno iNext; /* Page number of the next source page to copy */
83997 sqlite3* pSrcDb; /* Source database handle */
83998 Btree *pSrc; /* Source b-tree file */
83999
84000 int rc; /* Backup process error code */
84001
84002 /* These two variables are set by every call to backup_step(). They are
84003 ** read by calls to backup_remaining() and backup_pagecount().
@@ -83855,11 +84046,11 @@
84046 **
84047 ** If the "temp" database is requested, it may need to be opened by this
84048 ** function. If an error occurs while doing so, return 0 and write an
84049 ** error message to pErrorDb.
84050 */
84051 static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
84052 int i = sqlite3FindDbName(pDb, zDb);
84053
84054 if( i==1 ){
84055 Parse sParse;
84056 int rc = 0;
@@ -83878,21 +84069,19 @@
84069 if( i<0 ){
84070 sqlite3ErrorWithMsg(pErrorDb, SQLITE_ERROR, "unknown database %s", zDb);
84071 return 0;
84072 }
84073
84074 return pDb->aDb[i].pBt;
84075 }
84076
84077 /*
84078 ** Attempt to set the page size of the destination to match the page size
84079 ** of the source.
84080 */
84081 static int setDestPgsz(Btree *pDest, Btree *pSrc){
84082 return sqlite3BtreeSetPageSize(pDest, sqlite3BtreeGetPageSize(pSrc), 0, 0);
 
 
84083 }
84084
84085 /*
84086 ** Check that there is no open read-transaction on the b-tree passed as the
84087 ** second argument. If there is not, return SQLITE_OK. Otherwise, if there
@@ -83945,31 +84134,41 @@
84134 sqlite3ErrorWithMsg(
84135 pDestDb, SQLITE_ERROR, "source and destination must be distinct"
84136 );
84137 p = 0;
84138 }else {
84139 int nDest = sqlite3Strlen30(zDestDb);
84140
84141 /* Allocate space for a new sqlite3_backup object...
84142 ** EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
84143 ** call to sqlite3_backup_init() and is destroyed by a call to
84144 ** sqlite3_backup_finish(). */
84145 p = (sqlite3_backup*)sqlite3MallocZero(sizeof(sqlite3_backup)+nDest+1);
84146 if( !p ){
84147 sqlite3Error(pDestDb, SQLITE_NOMEM_BKPT);
84148 }else{
84149 p->zDestDb = (char*)&p[1];
84150 memcpy(p->zDestDb, zDestDb, nDest);
84151 }
84152 }
84153
84154 /* If the allocation succeeded, populate the new object. */
84155 if( p ){
84156 /* Do not store the pointer to the destination b-tree at this point.
84157 ** This is because there is nothing preventing it from being detached
84158 ** or otherwise freed before the first call to sqlite3_backup_step()
84159 ** on this object. The source b-tree does not have this problem, as
84160 ** incrementing Btree.nBackup (see below) effectively locks the object. */
84161 Btree *pDest = findBtree(pDestDb, pDestDb, zDestDb);
84162 p->pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
84163 p->pDestDb = pDestDb;
84164 p->pSrcDb = pSrcDb;
84165 p->iNext = 1;
84166 p->isAttached = 0;
84167
84168 if( 0==p->pSrc || 0==pDest
84169 || checkReadTransaction(pDestDb, pDest)!=SQLITE_OK
84170 ){
84171 /* One (or both) of the named databases did not exist or an OOM
84172 ** error was hit. Or there is a transaction open on the destination
84173 ** database. The error has already been written into the pDestDb
84174 ** handle. All that is left to do here is free the sqlite3_backup
@@ -83977,11 +84176,11 @@
84176 sqlite3_free(p);
84177 p = 0;
84178 }
84179 }
84180 if( p ){
84181 p->pSrc->nBackup++;
84182 }
84183
84184 sqlite3_mutex_leave(pDestDb->mutex);
84185 sqlite3_mutex_leave(pSrcDb->mutex);
84186 return p;
@@ -84005,22 +84204,22 @@
84204 sqlite3_backup *p, /* Backup handle */
84205 Pgno iSrcPg, /* Source database page to backup */
84206 const u8 *zSrcData, /* Source database page data */
84207 int bUpdate /* True for an update, false otherwise */
84208 ){
84209 Pager * const pDestPager = sqlite3BtreePager(p->pDest);
84210 const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
84211 int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
84212 const int nCopy = MIN(nSrcPgsz, nDestPgsz);
84213 const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
84214 int rc = SQLITE_OK;
84215 i64 iOff;
84216
84217 assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
84218 assert( p->bDestLocked );
84219 assert( !isFatalError(p->rc) );
84220 assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
84221 assert( zSrcData );
84222 assert( nSrcPgsz==nDestPgsz || sqlite3PagerIsMemdb(pDestPager)==0 );
84223
84224 /* This loop runs once for each destination page spanned by the source
84225 ** page. For each iteration, variable iOff is set to the byte offset
@@ -84027,11 +84226,11 @@
84226 ** of the destination page.
84227 */
84228 for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
84229 DbPage *pDestPg = 0;
84230 Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
84231 if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
84232 if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg, 0))
84233 && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
84234 ){
84235 const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
84236 u8 *zDestData = sqlite3PagerGetData(pDestPg);
@@ -84045,11 +84244,11 @@
84244 ** "MUST BE FIRST" for this purpose.
84245 */
84246 memcpy(zOut, zIn, nCopy);
84247 ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
84248 if( iOff==0 && bUpdate==0 ){
84249 sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc));
84250 }
84251 }
84252 sqlite3PagerUnref(pDestPg);
84253 }
84254
@@ -84077,12 +84276,12 @@
84276 ** Register this backup object with the associated source pager for
84277 ** callbacks when pages are changed or the cache invalidated.
84278 */
84279 static void attachBackupObject(sqlite3_backup *p){
84280 sqlite3_backup **pp;
84281 assert( sqlite3BtreeHoldsMutex(p->pSrc) );
84282 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
84283 p->pNext = *pp;
84284 *pp = p;
84285 p->isAttached = 1;
84286 }
84287
@@ -84089,93 +84288,103 @@
84288 /*
84289 ** Copy nPage pages from the source b-tree to the destination.
84290 */
84291 SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
84292 int rc;
84293 int destMode = 0; /* Destination journal mode */
84294 int pgszSrc = 0; /* Source page size */
84295 int pgszDest = 0; /* Destination page size */
 
 
84296
84297 #ifdef SQLITE_ENABLE_API_ARMOR
84298 if( p==0 ) return SQLITE_MISUSE_BKPT;
84299 #endif
 
 
 
 
84300 sqlite3_mutex_enter(p->pSrcDb->mutex);
84301 sqlite3BtreeEnter(p->pSrc);
84302 if( p->pDestDb ){
84303 sqlite3_mutex_enter(p->pDestDb->mutex);
84304 }
84305
84306 rc = p->rc;
84307 if( !isFatalError(rc) ){
84308 Pager * const pSrcPager = sqlite3BtreePager(p->pSrc); /* Source pager */
84309 Btree * pDest = 0; /* Dest btree */
84310 Pager * pDestPager = 0; /* Dest pager */
84311 int ii; /* Iterator variable */
84312 int nSrcPage = -1; /* Size of source db in pages */
84313 int bCloseTrans = 0; /* True if src db requires unlocking */
84314
84315 /* If the source pager is currently in a write-transaction, return
84316 ** SQLITE_BUSY immediately.
84317 */
84318 if( p->pDestDb && p->pSrc->pBt->inTransaction==TRANS_WRITE ){
84319 rc = SQLITE_BUSY;
84320 }else{
84321 rc = SQLITE_OK;
84322 }
84323
84324
84325 /* If there is no open read-transaction on the source database, open
84326 ** one now. If a transaction is opened here, then it will be closed
84327 ** before this function exits.
84328 */
84329 if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
84330 rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
84331 bCloseTrans = 1;
84332 }
84333
84334 /* Locate the destination btree and pager. */
84335 if( (pDest = p->pDest)==0 ){
84336 pDest = findBtree(p->pDestDb, p->pDestDb, p->zDestDb);
84337 }
84338 if( pDest==0 ){
84339 rc = SQLITE_ERROR;
84340 }else{
84341 pDestPager = sqlite3BtreePager(pDest);
84342 }
84343
84344 /* If the destination database has not yet been locked (i.e. if this
84345 ** is the first call to backup_step() for the current backup operation),
84346 ** try to set its page size to the same as the source database. This
84347 ** is especially important on ZipVFS systems, as in that case it is
84348 ** not possible to create a database file that uses one page size by
84349 ** writing to it with another. */
84350 if( p->bDestLocked==0 && rc==SQLITE_OK
84351 && setDestPgsz(pDest, p->pSrc)==SQLITE_NOMEM
84352 ){
84353 rc = SQLITE_NOMEM;
84354 }
84355
84356 /* Lock the destination database, if it is not locked already. */
84357 if( SQLITE_OK==rc && p->bDestLocked==0
84358 && SQLITE_OK==(rc = sqlite3BtreeBeginTrans(pDest, 2,
84359 (int*)&p->iDestSchema))
84360 ){
84361 p->bDestLocked = 1;
84362 p->pDest = pDest;
84363 }
84364
84365 /* Do not allow backup if the destination database is in WAL mode
84366 ** and the page sizes are different between source and destination */
84367 if( rc==SQLITE_OK ){
84368 pgszSrc = sqlite3BtreeGetPageSize(p->pSrc);
84369 pgszDest = sqlite3BtreeGetPageSize(p->pDest);
84370 destMode = sqlite3PagerGetJournalMode(sqlite3BtreePager(p->pDest));
84371 if( (destMode==PAGER_JOURNALMODE_WAL || sqlite3PagerIsMemdb(pDestPager))
84372 && pgszSrc!=pgszDest
84373 ){
84374 rc = SQLITE_READONLY;
84375 }
84376 }
84377
84378 /* Now that there is a read-lock on the source database, query the
84379 ** source pager for the number of pages in the database.
84380 */
84381 nSrcPage = (int)sqlite3BtreeLastPage(p->pSrc);
84382 assert( nSrcPage>=0 );
84383 for(ii=0; (nPage<0 || ii<nPage) && p->iNext<=(Pgno)nSrcPage && !rc; ii++){
84384 const Pgno iSrcPg = p->iNext; /* Source page number */
84385 if( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) ){
84386 DbPage *pSrcPg; /* Source page object */
84387 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg,PAGER_GET_READONLY);
84388 if( rc==SQLITE_OK ){
84389 rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg), 0);
84390 sqlite3PagerUnref(pSrcPg);
@@ -84198,22 +84407,22 @@
84407 ** the case where the source and destination databases have the
84408 ** same schema version.
84409 */
84410 if( rc==SQLITE_DONE ){
84411 if( nSrcPage==0 ){
84412 rc = sqlite3BtreeNewDb(p->pDest);
84413 nSrcPage = 1;
84414 }
84415 if( rc==SQLITE_OK || rc==SQLITE_DONE ){
84416 rc = sqlite3BtreeUpdateMeta(p->pDest,1,p->iDestSchema+1);
84417 }
84418 if( rc==SQLITE_OK ){
84419 if( p->pDestDb ){
84420 sqlite3ResetAllSchemasOfConnection(p->pDestDb);
84421 }
84422 if( destMode==PAGER_JOURNALMODE_WAL ){
84423 rc = sqlite3BtreeSetVersion(p->pDest, 2);
84424 }
84425 }
84426 if( rc==SQLITE_OK ){
84427 int nDestTruncate;
84428 /* Set nDestTruncate to the final number of pages in the destination
@@ -84226,16 +84435,16 @@
84435 ** sqlite3PagerTruncateImage() here so that any pages in the
84436 ** destination file that lie beyond the nDestTruncate page mark are
84437 ** journalled by PagerCommitPhaseOne() before they are destroyed
84438 ** by the file truncation.
84439 */
84440 assert( pgszSrc==sqlite3BtreeGetPageSize(p->pSrc) );
84441 assert( pgszDest==sqlite3BtreeGetPageSize(p->pDest) );
84442 if( pgszSrc<pgszDest ){
84443 int ratio = pgszDest/pgszSrc;
84444 nDestTruncate = (nSrcPage+ratio-1)/ratio;
84445 if( nDestTruncate==(int)PENDING_BYTE_PAGE(p->pDest->pBt) ){
84446 nDestTruncate--;
84447 }
84448 }else{
84449 nDestTruncate = nSrcPage * (pgszSrc/pgszDest);
84450 }
@@ -84259,11 +84468,11 @@
84468 i64 iEnd;
84469
84470 assert( pFile );
84471 assert( nDestTruncate==0
84472 || (i64)nDestTruncate*(i64)pgszDest >= iSize || (
84473 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
84474 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
84475 ));
84476
84477 /* This block ensures that all data required to recreate the original
84478 ** database has been stored in the journal for pDestPager and the
@@ -84271,11 +84480,11 @@
84480 ** the database file in any way, knowing that if a power failure
84481 ** occurs, the original database will be reconstructed from the
84482 ** journal file. */
84483 sqlite3PagerPagecount(pDestPager, &nDstPage);
84484 for(iPg=nDestTruncate; rc==SQLITE_OK && iPg<=(Pgno)nDstPage; iPg++){
84485 if( iPg!=PENDING_BYTE_PAGE(p->pDest->pBt) ){
84486 DbPage *pPg;
84487 rc = sqlite3PagerGet(pDestPager, iPg, &pPg, 0);
84488 if( rc==SQLITE_OK ){
84489 rc = sqlite3PagerWrite(pPg);
84490 sqlite3PagerUnref(pPg);
@@ -84315,11 +84524,11 @@
84524 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
84525 }
84526
84527 /* Finish committing the transaction to the destination database. */
84528 if( SQLITE_OK==rc
84529 && SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p->pDest, 0))
84530 ){
84531 rc = SQLITE_DONE;
84532 }
84533 }
84534 }
@@ -84329,12 +84538,12 @@
84538 ** no need to check the return values of the btree methods here, as
84539 ** "committing" a read-only transaction cannot fail.
84540 */
84541 if( bCloseTrans ){
84542 TESTONLY( int rc2 );
84543 TESTONLY( rc2 = ) sqlite3BtreeCommitPhaseOne(p->pSrc, 0);
84544 TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p->pSrc, 0);
84545 assert( rc2==SQLITE_OK );
84546 }
84547
84548 if( rc==SQLITE_IOERR_NOMEM ){
84549 rc = SQLITE_NOMEM_BKPT;
@@ -84342,11 +84551,11 @@
84551 p->rc = rc;
84552 }
84553 if( p->pDestDb ){
84554 sqlite3_mutex_leave(p->pDestDb->mutex);
84555 }
84556 sqlite3BtreeLeave(p->pSrc);
84557 sqlite3_mutex_leave(p->pSrcDb->mutex);
84558 return rc;
84559 }
84560
84561 /*
@@ -84359,41 +84568,43 @@
84568
84569 /* Enter the mutexes */
84570 if( p==0 ) return SQLITE_OK;
84571 pSrcDb = p->pSrcDb;
84572 sqlite3_mutex_enter(pSrcDb->mutex);
84573 sqlite3BtreeEnter(p->pSrc);
84574 if( p->pDestDb ){
84575 sqlite3_mutex_enter(p->pDestDb->mutex);
84576 }
84577
84578 /* Detach this backup from the source pager. */
84579 if( p->pDestDb ){
84580 p->pSrc->nBackup--;
84581 }
84582 if( p->isAttached ){
84583 pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
84584 assert( pp!=0 );
84585 while( *pp!=p ){
84586 pp = &(*pp)->pNext;
84587 assert( pp!=0 );
84588 }
84589 *pp = p->pNext;
84590 }
84591
84592 /* If a transaction is still open on the Btree, roll it back. */
84593 if( p->pDest ){
84594 sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0);
84595 }
84596
84597 /* Set the error code of the destination database handle. */
84598 rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
84599 if( p->pDestDb ){
84600 sqlite3Error(p->pDestDb, rc);
84601
84602 /* Exit the mutexes and free the backup context structure. */
84603 sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
84604 }
84605 sqlite3BtreeLeave(p->pSrc);
84606 if( p->pDestDb ){
84607 /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
84608 ** call to sqlite3_backup_init() and is destroyed by a call to
84609 ** sqlite3_backup_finish(). */
84610 sqlite3_free(p);
@@ -84447,11 +84658,11 @@
84658 Pgno iPage,
84659 const u8 *aData
84660 ){
84661 assert( p!=0 );
84662 do{
84663 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
84664 if( !isFatalError(p->rc) && iPage<p->iNext ){
84665 /* The backup process p has already copied page iPage. But now it
84666 ** has been modified by a transaction on the source pager. Copy
84667 ** the new data into the backup.
84668 */
@@ -84483,11 +84694,11 @@
84694 ** called.
84695 */
84696 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
84697 sqlite3_backup *p; /* Iterator variable */
84698 for(p=pBackup; p; p=p->pNext){
84699 assert( sqlite3_mutex_held(p->pSrc->pBt->mutex) );
84700 p->iNext = 1;
84701 }
84702 }
84703
84704 #ifndef SQLITE_OMIT_VACUUM
@@ -84501,12 +84712,10 @@
84712 */
84713 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
84714 int rc;
84715 sqlite3_file *pFd; /* File descriptor for database pTo */
84716 sqlite3_backup b;
 
 
84717 sqlite3BtreeEnter(pTo);
84718 sqlite3BtreeEnter(pFrom);
84719
84720 assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
84721 pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
@@ -84521,17 +84730,13 @@
84730 ** to 0. This is used by the implementations of sqlite3_backup_step()
84731 ** and sqlite3_backup_finish() to detect that they are being called
84732 ** from this function, not directly by the user.
84733 */
84734 memset(&b, 0, sizeof(b));
 
 
 
 
84735 b.pSrcDb = pFrom->db;
84736 b.pSrc = pFrom;
84737 b.pDest = pTo;
84738 b.iNext = 1;
84739
84740 /* 0x7FFFFFFF is the hard limit for the number of pages in a database
84741 ** file. By passing this as the number of pages to copy to
84742 ** sqlite3_backup_step(), we can guarantee that the copy finishes
@@ -84543,11 +84748,11 @@
84748
84749 rc = sqlite3_backup_finish(&b);
84750 if( rc==SQLITE_OK ){
84751 pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
84752 }else{
84753 sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
84754 }
84755
84756 assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
84757 copy_finished:
84758 sqlite3BtreeLeave(pFrom);
@@ -86859,11 +87064,10 @@
87064 p->pParse = pParse;
87065 pParse->pVdbe = p;
87066 assert( pParse->aLabel==0 );
87067 assert( pParse->nLabel==0 );
87068 assert( p->nOpAlloc==0 );
 
87069 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
87070 return p;
87071 }
87072
87073 /*
@@ -87009,12 +87213,11 @@
87213
87214 assert( nOp<=(int)(1024/sizeof(Op)) );
87215 assert( nNew>=(v->nOpAlloc+nOp) );
87216 pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op));
87217 if( pNew ){
87218 v->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op);
 
87219 v->aOp = pNew;
87220 }
87221 return (pNew ? SQLITE_OK : SQLITE_NOMEM_BKPT);
87222 }
87223
@@ -87445,11 +87648,11 @@
87648 ** Resolve label "x" to be the address of the next instruction to
87649 ** be inserted. The parameter "x" must have been obtained from
87650 ** a prior call to sqlite3VdbeMakeLabel().
87651 */
87652 static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
87653 int nNewSize = 25 - p->nLabel;
87654 p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel,
87655 nNewSize*sizeof(p->aLabel[0]));
87656 if( p->aLabel==0 ){
87657 p->nLabelAlloc = 0;
87658 }else{
@@ -89513,11 +89716,11 @@
89716 ** of the prepared statement.
89717 */
89718 n = ROUND8P(sizeof(Op)*p->nOp); /* Bytes of opcode memory used */
89719 x.pSpace = &((u8*)p->aOp)[n]; /* Unused opcode memory */
89720 assert( EIGHT_BYTE_ALIGNMENT(x.pSpace) );
89721 x.nFree = ROUNDDOWN8((p->nOpAlloc-p->nOp)*sizeof(Op)); /* Bytes unused mem */
89722 assert( x.nFree>=0 );
89723 assert( EIGHT_BYTE_ALIGNMENT(&x.pSpace[x.nFree]) );
89724
89725 resolveP2Values(p, &nArg);
89726 p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort);
@@ -92662,12 +92865,18 @@
92865 ** that sqlite3_prepare() generates. For example, if new functions or
92866 ** collating sequences are registered or if an authorizer function is
92867 ** added or changed.
92868 */
92869 SQLITE_API int sqlite3_expired(sqlite3_stmt *pStmt){
92870 int iRet = 1;
92871 if( pStmt ){
92872 Vdbe *p = (Vdbe*)pStmt;
92873 sqlite3_mutex_enter(p->db->mutex);
92874 iRet = p->expired;
92875 sqlite3_mutex_leave(p->db->mutex);
92876 }
92877 return iRet;
92878 }
92879 #endif
92880
92881 /*
92882 ** Check on a Vdbe to make sure it has not been finalized. Log
@@ -93009,19 +93218,22 @@
93218 sqlite3ValueFree(pOld);
93219 }
93220
93221
93222 /**************************** sqlite3_result_ *******************************
93223 ** The following routines are used by application-defined SQL functions to
93224 ** specify the function return value. There are many variations on
93225 ** sqlite3_result_xxxx() for different types of return values.
93226 **
93227 ** The setStrOrError() function is a helper function that invokes
93228 ** sqlite3VdbeMemSetStr() to store the result as a string or blob.
93229 ** Appropriate errors are set if the string/blob is too big or if
93230 ** an OOM occurs.
93231 **
93232 ** The invokeValueDestructor(P,X) helper function invokes the destructor
93233 ** function X() on value P if P is not going to be used and need to
93234 ** be destroyed.
93235 */
93236 static void setResultStrOrError(
93237 sqlite3_context *pCtx, /* Function context */
93238 const char *z, /* String pointer */
93239 int n, /* Bytes in string, or negative */
@@ -93330,11 +93542,11 @@
93542 setResultStrOrError(pCtx, sqlite3ErrStr(errCode), -1, SQLITE_UTF8,
93543 SQLITE_STATIC);
93544 }
93545 }
93546
93547 /* Cause the SQL function to raise an SQLITE_TOOBIG error. */
93548 SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){
93549 #ifdef SQLITE_ENABLE_API_ARMOR
93550 if( pCtx==0 ) return;
93551 #endif
93552 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -93341,20 +93553,82 @@
93553 pCtx->isError = SQLITE_TOOBIG;
93554 sqlite3VdbeMemSetStr(pCtx->pOut, "string or blob too big", -1,
93555 SQLITE_UTF8, SQLITE_STATIC);
93556 }
93557
93558 /* Cause the SQL function to raise an SQLITE_NOMEM error. */
93559 SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){
93560 #ifdef SQLITE_ENABLE_API_ARMOR
93561 if( pCtx==0 ) return;
93562 #endif
93563 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
93564 sqlite3VdbeMemSetNull(pCtx->pOut);
93565 pCtx->isError = SQLITE_NOMEM_BKPT;
93566 sqlite3OomFault(pCtx->pOut->db);
93567 }
93568
93569 /* Make the return value of the SQL function or virtual table pCtx
93570 ** be the content of the sqlite3_str object pStr. The eOwn flag
93571 ** determines ownership of the sqlite3_str object and its content.
93572 **
93573 ** eOwn Ownership transfer
93574 ** ------------- ------------------------------------------------
93575 **
93576 ** SQLITE_COPY The SQL function returns a copy the sqlite3_str
93577 ** content and leaves the sqlite3_str object itself
93578 ** unchanged.
93579 **
93580 ** SQLITE_XFER The content of the sqlite3_str is transferred to
93581 ** the SQL function and the SQL function takes
93582 ** responsibility for freeing that content when it is
93583 ** no longer needed. The sqlite3_str object is reset
93584 ** to an empty string.
93585 **
93586 ** SQLITE_FINISH Like SQLITE_XFER except that the pStr is also
93587 ** freed using sqlite3_str_free().
93588 */
93589 SQLITE_API void sqlite3_result_str(sqlite3_context *pCtx, sqlite3_str *pStr, int eOwn){
93590 #ifdef SQLITE_ENABLE_API_ARMOR
93591 if( pCtx==0 ) return;
93592 if( pStr==0 ) return;
93593 #endif
93594 if( pStr->accError==0 ){
93595 if( pStr->nChar==0 ){
93596 setResultStrOrError(pCtx, "", 0, SQLITE_UTF8_ZT, SQLITE_STATIC);
93597 if( eOwn ) sqlite3_str_reset(pStr);
93598 }else{
93599 const char *zText = sqlite3_str_value(pStr);
93600 /* Only internal code has the ability to capture a pointer to
93601 ** an sqlite3_str object that uses static buffer. And none of
93602 ** those internal use cases every invoke the sqlite3_result_str()
93603 ** interface on a static-buffer sqlite3_str. Should this change
93604 ** in the future, the following assert() will let us know. */
93605 assert( isMalloced(pStr) );
93606 if( eOwn==SQLITE_COPY ){
93607 setResultStrOrError(pCtx, zText, pStr->nChar,
93608 SQLITE_UTF8, SQLITE_TRANSIENT);
93609 }else{
93610 setResultStrOrError(pCtx, zText, pStr->nChar,
93611 SQLITE_UTF8_ZT, SQLITE_DYNAMIC);
93612 }
93613 }
93614 }else if( pStr->accError==SQLITE_NOMEM ){
93615 sqlite3_result_error_nomem(pCtx);
93616 }else{
93617 assert( pStr->accError==SQLITE_TOOBIG );
93618 sqlite3_result_error_toobig(pCtx);
93619 }
93620 if( eOwn ){
93621 testcase( pStr==(sqlite3_str*)&sqlite3OomStr );
93622 if( pStr->accError==0 ){
93623 sqlite3StrAccumInit(pStr, pStr->db, 0, 0, pStr->mxAlloc);
93624 }
93625 if( eOwn==SQLITE_FINISH ){
93626 sqlite3_str_free(pStr);
93627 }
93628 }
93629 }
93630
93631 #ifndef SQLITE_UNTESTABLE
93632 /* Force the INT64 value currently stored as the result to be
93633 ** a MEM_IntReal value. See the SQLITE_TESTCTRL_RESULT_INTREAL
93634 ** test-control.
@@ -102342,10 +102616,15 @@
102616 pTabCur = p->apCsr[pOp->p3];
102617 assert( pTabCur!=0 );
102618 assert( pTabCur->eCurType==CURTYPE_BTREE );
102619 assert( pTabCur->uc.pCursor!=0 );
102620 assert( pTabCur->isTable );
102621 #if defined(SQLITE_ENABLE_CURSOR_HINTS) && defined(SQLITE_DEBUG)
102622 assert(
102623 sqlite3BtreeCursorHintTblCsr(pC->uc.pCursor)==pTabCur->uc.pCursor
102624 );
102625 #endif
102626 pTabCur->nullRow = 0;
102627 pTabCur->movetoTarget = rowid;
102628 pTabCur->deferredMoveto = 1;
102629 pTabCur->cacheStatus = CACHE_STALE;
102630 assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 );
@@ -104724,27 +105003,41 @@
105003 p->aCounter[SQLITE_STMTSTATUS_RUN]++;
105004 goto jump_to_p2;
105005 }
105006
105007 #ifdef SQLITE_ENABLE_CURSOR_HINTS
105008 /* Opcode: CursorHint P1 * P3 P4 *
105009 **
105010 ** Provide a hint to cursor P1.
105011 **
105012 ** If P4 is of type P4_EXPR, then the hint is that the cursor need only return
105013 ** rows that satisfy the Expr in P4. TK_REGISTER terms in the P4 expression
105014 ** refer to values currently held in registers. TK_COLUMN terms in the P4
105015 ** expression refer to columns in the b-tree to which cursor P1 is pointing.
105016 ** P3 is ignore in this case.
105017 **
105018 ** Or, if P4 is P4_NOTUSED, then the hint is that cursor P1 is an index cursor
105019 ** used to drive table cursor P3. In other words, that this VM may execute
105020 ** OP_DeferredSeek instructions to lazily position P3 based on current
105021 ** position of P1.
105022 */
105023 case OP_CursorHint: {
105024 VdbeCursor *pC;
105025 pC = p->apCsr[pOp->p1];
105026
105027 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
105028
 
105029 if( pC ){
105030 assert( pC->eCurType==CURTYPE_BTREE );
105031 if( pOp->p4type==P4_EXPR ){
105032 sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE,
105033 pOp->p4.pExpr, aMem);
105034 }else if( p->apCsr[pOp->p3] ){
105035 sqlite3BtreeCursorHint(
105036 pC->uc.pCursor, BTREE_HINT_TABLECURSOR, p->apCsr[pOp->p3]->uc.pCursor
105037 );
105038 }
105039 }
105040 break;
105041 }
105042 #endif /* SQLITE_ENABLE_CURSOR_HINTS */
105043
@@ -117229,11 +117522,16 @@
117522 #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
117523 if( pDef==0 && pParse->explain ){
117524 pDef = sqlite3FindFunction(db, "unknown", nFarg, enc, 0);
117525 }
117526 #endif
117527 if( pDef==0
117528 || pDef->xFinalize!=0
117529 || ((pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0 &&
117530 !pParse->nested &&
117531 (db->mDbFlags & DBFLAG_InternalFunc)==0)
117532 ){
117533 sqlite3ErrorMsg(pParse, "unknown function: %#T()", pExpr);
117534 break;
117535 }
117536 if( (pDef->funcFlags & SQLITE_FUNC_INLINE)!=0 && ALWAYS(pFarg!=0) ){
117537 assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 );
@@ -122236,13 +122534,12 @@
122534 const u8 *zSql = sqlite3_value_text(argv[0]);
122535 const char *zCons = (const char*)sqlite3_value_text(argv[1]);
122536 int iCol = sqlite3_value_int(argv[2]);
122537 int iOff = 0;
122538 int ii;
122539 sqlite3_str *pNew;
122540 int t = 0;
 
122541 UNUSED_PARAMETER(NotUsed);
122542
122543 if( skipCreateTable(ctx, zSql, &iOff) ) return;
122544
122545 for(ii=0; ii<=iCol || (iCol<0 && t!=TK_RP); ii++){
@@ -122258,17 +122555,15 @@
122555 }
122556 }
122557
122558 iOff += getWhitespace(&zSql[iOff]);
122559
122560 pNew = sqlite3_str_new(sqlite3_context_db_handle(ctx));
122561 sqlite3_str_append(pNew, (const char*)zSql, iOff);
122562 if( iCol<0 ) sqlite3_str_append(pNew, ",", 1);
122563 sqlite3_str_appendf(pNew, " %s%s", zCons, &zSql[iOff]);
122564 sqlite3_result_str(ctx, pNew, SQLITE_FINISH);
 
 
122565 }
122566
122567 /*
122568 ** Find a column named pCol in table pTab. If successful, set output
122569 ** parameter *piCol to the index of the column in the table and return
@@ -123524,11 +123819,11 @@
123819 sqlite3_str_appendf(&sStat, " %llu", iVal);
123820 #ifdef SQLITE_ENABLE_STAT4
123821 assert( p->current.anEq[i] || p->nRow==0 );
123822 #endif
123823 }
123824 sqlite3_result_str(context, &sStat, SQLITE_XFER);
123825 }
123826 #ifdef SQLITE_ENABLE_STAT4
123827 else if( eCall==STAT_GET_ROWID ){
123828 if( p->iGet<0 ){
123829 samplePushPrevious(p, 0);
@@ -123561,11 +123856,11 @@
123856 sqlite3StrAccumInit(&sStat, 0, 0, 0, p->nCol*100);
123857 for(i=0; i<p->nCol; i++){
123858 sqlite3_str_appendf(&sStat, "%llu ", (u64)aCnt[i]);
123859 }
123860 if( sStat.nChar ) sStat.nChar--;
123861 sqlite3_result_str(context, &sStat, SQLITE_XFER);
123862 }
123863 #endif /* SQLITE_ENABLE_STAT4 */
123864 #ifndef SQLITE_DEBUG
123865 UNUSED_PARAMETER( argc );
123866 #endif
@@ -125649,10 +125944,11 @@
125944 }
125945 }
125946
125947 assert( pToplevel->nTableLock < 0x7fff0000 );
125948 nBytes = sizeof(TableLock) * (pToplevel->nTableLock+1);
125949 if( pToplevel->nTableLock==0 ) pToplevel->aTableLock = 0;
125950 pToplevel->aTableLock =
125951 sqlite3DbReallocOrFree(pToplevel->db, pToplevel->aTableLock, nBytes);
125952 if( pToplevel->aTableLock ){
125953 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
125954 p->iDb = iDb;
@@ -125815,11 +126111,11 @@
126111 if( pParse->nTableLock ) codeTableLocks(pParse);
126112 #endif
126113
126114 /* Initialize any AUTOINCREMENT data structures required.
126115 */
126116 if( pParse->usesAinc ) sqlite3AutoincrementBegin(pParse);
126117
126118 /* Code constant expressions that were factored out of inner loops.
126119 */
126120 if( pParse->pConstExpr ){
126121 ExprList *pEL = pParse->pConstExpr;
@@ -125848,11 +126144,11 @@
126144 assert( v!=0 || pParse->nErr );
126145 assert( db->mallocFailed==0 || pParse->nErr );
126146 if( pParse->nErr==0 ){
126147 /* A minimum of one cursor is required if autoincrement is used
126148 * See ticket [a696379c1f08866] */
126149 assert( pParse->usesAinc==0 || pParse->nTab>0 );
126150 sqlite3VdbeMakeReady(v, pParse);
126151 pParse->rc = SQLITE_DONE;
126152 }else{
126153 pParse->rc = SQLITE_ERROR;
126154 }
@@ -133318,32 +133614,20 @@
133614 sqlite3_value **argv
133615 ){
133616 PrintfArguments x;
133617 StrAccum str;
133618 const char *zFormat;
 
133619 sqlite3 *db = sqlite3_context_db_handle(context);
133620
133621 if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){
133622 x.nArg = argc-1;
133623 x.nUsed = 0;
133624 x.apArg = argv+1;
133625 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
133626 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
133627 sqlite3_str_appendf(&str, zFormat, &x);
133628 sqlite3_result_str(context, &str, SQLITE_XFER);
 
 
 
 
 
 
 
 
 
 
 
133629 }
133630 }
133631
133632 /*
133633 ** Implementation of the substr() function.
@@ -134286,16 +134570,11 @@
134570 sqlite3 *db = sqlite3_context_db_handle(context);
134571 assert( argc==1 );
134572 UNUSED_PARAMETER(argc);
134573 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
134574 sqlite3QuoteValue(&str,argv[0],SQLITE_PTR_TO_INT(sqlite3_user_data(context)));
134575 sqlite3_result_str(context, &str, SQLITE_XFER);
 
 
 
 
 
134576 }
134577
134578 /*
134579 ** The unicode() function. Return the integer unicode code-point value
134580 ** for the first character of the input string.
@@ -135324,32 +135603,22 @@
135603 #endif /* SQLITE_OMIT_WINDOWFUNC */
135604 static void groupConcatFinalize(sqlite3_context *context){
135605 GroupConcatCtx *pGCC
135606 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135607 if( pGCC ){
135608 sqlite3_result_str(context, &pGCC->str, SQLITE_XFER);
135609 #ifndef SQLITE_OMIT_WINDOWFUNC
135610 sqlite3_free(pGCC->pnSepLengths);
135611 #endif
135612 }
135613 }
135614 #ifndef SQLITE_OMIT_WINDOWFUNC
135615 static void groupConcatValue(sqlite3_context *context){
135616 GroupConcatCtx *pGCC
135617 = (GroupConcatCtx*)sqlite3_aggregate_context(context, 0);
135618 if( pGCC && pGCC->nAccum>0 ){
135619 sqlite3_result_str(context, &pGCC->str, SQLITE_COPY);
 
 
 
 
 
 
 
 
 
 
135620 }
135621 }
135622 #else
135623 # define groupConcatValue 0
135624 #endif /* SQLITE_OMIT_WINDOWFUNC */
@@ -136190,12 +136459,11 @@
136459 sqlite3_str_appendall(pStr, ",\"journal\":");
136460 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_FILESTAT, pStr);
136461 if( rc ) sqlite3_str_append(pStr, "null", 4);
136462 }
136463 sqlite3_str_append(pStr, "}", 1);
136464 sqlite3_result_str(context, pStr, SQLITE_FINISH);
 
136465 }
136466 sqlite3BtreeLeave(pBtree);
136467 }else{
136468 sqlite3_result_text(context, "{}", 2, SQLITE_STATIC);
136469 }
@@ -136307,12 +136575,12 @@
136575 }else{
136576 sqlite3_str_appendf(pResult, ", NULL");
136577 }
136578 }
136579 }
 
136580 }
136581 sqlite3_result_str(ctx, pResult, SQLITE_FINISH);
136582 sqlite3_free_filename(zFile);
136583 sqlite3_free(zErr);
136584 }
136585 #endif /* SQLITE_DEBUG */
136586
@@ -136405,11 +136673,11 @@
136673 VFUNCTION(random, 0, 0, 0, randomFunc ),
136674 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
136675 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
136676 DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
136677 DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
136678 SFUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
136679 FUNCTION(unistr, 1, 0, 0, unistrFunc ),
136680 FUNCTION(quote, 1, 0, 0, quoteFunc ),
136681 FUNCTION(unistr_quote, 1, 1, 0, quoteFunc ),
136682 VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid),
136683 VFUNCTION(changes, 0, 0, 0, changes ),
@@ -138454,19 +138722,23 @@
138722 pParse->nErr++;
138723 pParse->rc = SQLITE_CORRUPT_SEQUENCE;
138724 return 0;
138725 }
138726
138727 if( pToplevel->usesAinc==0 ){
138728 pToplevel->pAinc = 0;
138729 }
138730 pInfo = pToplevel->pAinc;
138731 while( pInfo && pInfo->pTab!=pTab ){ pInfo = pInfo->pNext; }
138732 if( pInfo==0 ){
138733 pInfo = sqlite3DbMallocRawNN(pParse->db, sizeof(*pInfo));
138734 sqlite3ParserAddCleanup(pToplevel, sqlite3DbFree, pInfo);
138735 testcase( pParse->earlyCleanup );
138736 if( pParse->db->mallocFailed ) return 0;
138737 pInfo->pNext = pToplevel->pAinc;
138738 pToplevel->pAinc = pInfo;
138739 pToplevel->usesAinc = 1;
138740 pInfo->pTab = pTab;
138741 pInfo->iDb = iDb;
138742 pToplevel->nMem++; /* Register to hold name of table */
138743 pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
138744 pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */
@@ -138491,10 +138763,11 @@
138763 ** only called from the top-level */
138764 assert( pParse->pTriggerTab==0 );
138765 assert( sqlite3IsToplevel(pParse) );
138766
138767 assert( v ); /* We failed long ago if this is not so */
138768 assert( pParse->usesAinc );
138769 for(p = pParse->pAinc; p; p = p->pNext){
138770 static const int iLn = VDBE_OFFSET_LINENO(2);
138771 static const VdbeOpList autoInc[] = {
138772 /* 0 */ {OP_Null, 0, 0, 0},
138773 /* 1 */ {OP_Rewind, 0, 10, 0},
@@ -138558,10 +138831,11 @@
138831 AutoincInfo *p;
138832 Vdbe *v = pParse->pVdbe;
138833 sqlite3 *db = pParse->db;
138834
138835 assert( v );
138836 assert( pParse->usesAinc );
138837 for(p = pParse->pAinc; p; p = p->pNext){
138838 static const int iLn = VDBE_OFFSET_LINENO(2);
138839 static const VdbeOpList autoIncEnd[] = {
138840 /* 0 */ {OP_NotNull, 0, 2, 0},
138841 /* 1 */ {OP_NewRowid, 0, 0, 0},
@@ -138590,11 +138864,11 @@
138864 aOp[3].p5 = OPFLAG_APPEND;
138865 sqlite3ReleaseTempReg(pParse, iRec);
138866 }
138867 }
138868 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse){
138869 if( pParse->usesAinc ) autoIncrementEnd(pParse);
138870 }
138871 #else
138872 /*
138873 ** If SQLITE_OMIT_AUTOINCREMENT is defined, then the three routines
138874 ** above are all no-ops
@@ -142023,10 +142297,11 @@
142297 void (*str_free)(sqlite3_str*);
142298 int (*carray_bind)(sqlite3_stmt*,int,void*,int,int,void(*)(void*));
142299 int (*carray_bind_v2)(sqlite3_stmt*,int,void*,int,int,void(*)(void*),void*);
142300 /* Version 3.54.0 and later */
142301 sqlite3_int64 (*incomplete)(const char*);
142302 void (*result_str)(sqlite3_context*,sqlite3_str*,int);
142303 };
142304
142305 /*
142306 ** This is the function signature used for all extension entry points. It
142307 ** is also defined in the file "loadext.c".
@@ -142368,10 +142643,11 @@
142643 #define sqlite3_str_free sqlite3_api->str_free
142644 #define sqlite3_carray_bind sqlite3_api->carray_bind
142645 #define sqlite3_carray_bind_v2 sqlite3_api->carray_bind_v2
142646 /* Version 3.54.0 and later */
142647 #define sqlite3_incomplete sqlite3_api->incomplete
142648 #define sqlite3_result_str sqlite3_api->result_str
142649 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
142650
142651 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
142652 /* This case when the file really is being compiled as a loadable
142653 ** extension */
@@ -142905,11 +143181,13 @@
143181 sqlite3_carray_bind_v2,
143182 #else
143183 0,
143184 0,
143185 #endif
143186 /* Version 3.54.0 and later */
143187 sqlite3_incomplete,
143188 sqlite3_result_str
143189 };
143190
143191 /* True if x is the directory separator character
143192 */
143193 #if SQLITE_OS_WIN
@@ -147674,11 +147952,11 @@
147952 sqlite3 *db = pParse->db;
147953 assert( db!=0 );
147954 assert( db->pParse==pParse );
147955 assert( pParse->nested==0 );
147956 #ifndef SQLITE_OMIT_SHARED_CACHE
147957 if( pParse->nTableLock ) sqlite3DbNNFreeNN(db, pParse->aTableLock);
147958 #endif
147959 while( pParse->pCleanup ){
147960 ParseCleanup *pCleanup = pParse->pCleanup;
147961 pParse->pCleanup = pCleanup->pNext;
147962 pCleanup->xCleanup(db, pCleanup->pPtr);
@@ -148157,11 +148435,11 @@
148435 int nBytes, /* Length of zSql in bytes. */
148436 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148437 const void **pzTail /* OUT: End of parsed string */
148438 ){
148439 int rc;
148440 rc = sqlite3Prepare16(db,zSql,nBytes&~1,0,ppStmt,pzTail);
148441 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148442 return rc;
148443 }
148444 SQLITE_API int sqlite3_prepare16_v2(
148445 sqlite3 *db, /* Database handle. */
@@ -148169,11 +148447,11 @@
148447 int nBytes, /* Length of zSql in bytes. */
148448 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148449 const void **pzTail /* OUT: End of parsed string */
148450 ){
148451 int rc;
148452 rc = sqlite3Prepare16(db,zSql,nBytes&~1,SQLITE_PREPARE_SAVESQL,ppStmt,pzTail);
148453 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148454 return rc;
148455 }
148456 SQLITE_API int sqlite3_prepare16_v3(
148457 sqlite3 *db, /* Database handle. */
@@ -148182,11 +148460,11 @@
148460 unsigned int prepFlags, /* Zero or more SQLITE_PREPARE_* flags */
148461 sqlite3_stmt **ppStmt, /* OUT: A pointer to the prepared statement */
148462 const void **pzTail /* OUT: End of parsed string */
148463 ){
148464 int rc;
148465 rc = sqlite3Prepare16(db,zSql,nBytes&~1,
148466 SQLITE_PREPARE_SAVESQL|(prepFlags&SQLITE_PREPARE_MASK),
148467 ppStmt,pzTail);
148468 assert( rc==SQLITE_OK || ppStmt==0 || *ppStmt==0 ); /* VERIFY: F13021 */
148469 return rc;
148470 }
@@ -148855,11 +149133,12 @@
149133 pRight->u3.pOn = 0;
149134 pRight->fg.isOn = 1;
149135 p->selFlags |= SF_OnToWhere;
149136 }
149137
149138 if( pRight->fg.isTabFunc && joinType==EP_OuterON && pRight->u1.pFuncArg ){
149139 assert( IsVirtual(pRightTab) );
149140 p->selFlags |= SF_OnToWhere;
149141 }
149142 }
149143 return 0;
149144 }
@@ -161225,10 +161504,11 @@
161504 SQLITE_API int sqlite3_drop_modules(sqlite3 *db, const char** azNames){
161505 HashElem *pThis, *pNext;
161506 #ifdef SQLITE_ENABLE_API_ARMOR
161507 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
161508 #endif
161509 sqlite3_mutex_enter(db->mutex);
161510 for(pThis=sqliteHashFirst(&db->aModule); pThis; pThis=pNext){
161511 Module *pMod = (Module*)sqliteHashData(pThis);
161512 pNext = sqliteHashNext(pThis);
161513 if( azNames ){
161514 int ii;
@@ -161235,10 +161515,11 @@
161515 for(ii=0; azNames[ii]!=0 && strcmp(azNames[ii],pMod->zName)!=0; ii++){}
161516 if( azNames[ii]!=0 ) continue;
161517 }
161518 createModule(db, pMod->zName, 0, 0, 0);
161519 }
161520 sqlite3_mutex_leave(db->mutex);
161521 return SQLITE_OK;
161522 }
161523
161524 /*
161525 ** Decrement the reference count on a Module object. Destroy the
@@ -167001,33 +167282,62 @@
167282 }
167283 }
167284 }
167285 }
167286
167287 /* At this point, okToChngToIN is true if original pTerm is a
167288 ** candidate to satisfy case 1, though we are not yet certain that
167289 ** the collating sequences are all compatible. Try to construct a
167290 ** new virtual term that is pTerm converted from an OR operator
167291 ** into an IN operator.
167292 **
167293 ** During construction, verify that the collating sequences on all
167294 ** subterms of the OR are compatible. Omit the construction of the
167295 ** new IN operator if there are any collating sequence mismatches.
167296 */
167297 if( okToChngToIN ){
167298 Expr *pDup; /* A transient duplicate expression */
167299 ExprList *pList = 0; /* The RHS of the IN operator */
167300 Expr *pLeft = 0; /* The LHS of the IN operator */
167301 CollSeq *pCollSeq = 0; /* Collating sequence to use */
167302 Expr *pNew; /* The complete IN operator */
167303
167304 for(i=pOrWc->nTerm-1, pOrTerm=pOrWc->a; i>=0; i--, pOrTerm++){
167305 Expr *pThis;
167306 if( (pOrTerm->wtFlags & TERM_OK)==0 ) continue;
167307 assert( pOrTerm->eOperator & WO_EQ );
167308 assert( (pOrTerm->eOperator & (WO_OR|WO_AND))==0 );
167309 assert( pOrTerm->leftCursor==iCursor );
167310 assert( pOrTerm->u.x.leftColumn==iColumn );
167311 pThis = pOrTerm->pExpr;
167312 pDup = sqlite3ExprDup(db, pThis->pRight, 0);
167313 pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
167314 if( pLeft==0 ){
167315 pLeft = pThis->pLeft;
167316 pCollSeq = sqlite3ExprCompareCollSeq(pParse, pThis);
167317 }else{
167318 assert( 0==sqlite3ExprCompare(pParse,
167319 sqlite3ExprSkipCollate(pThis->pLeft),
167320 sqlite3ExprSkipCollate(pLeft), -1) );
167321 if( pCollSeq!=sqlite3ExprCompareCollSeq(pParse, pThis) ){
167322 pLeft = 0; /* Collating sequence mismatch */
167323 break;
167324 }
167325 }
167326 }
167327 if( pLeft==0 ){
167328 pNew = 0; /* Collating sequence mismatch */
167329 }else{
167330 pDup = sqlite3ExprDup(db, pLeft, 0);
167331 if( sqlite3ExprCollSeq(pParse, pDup)!=pCollSeq
167332 && ALWAYS(pCollSeq!=0)
167333 ){
167334 assert( pCollSeq->zName!=0 );
167335 pDup = sqlite3ExprAddCollateString(pParse, pDup, pCollSeq->zName);
167336 }
167337 pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
167338 }
167339 if( pNew ){
167340 int idxNew;
167341 transferJoinMarkings(pNew, pExpr);
167342 assert( ExprUseXList(pNew) );
167343 pNew->x.pList = pList;
@@ -175432,10 +175742,15 @@
175742 }
175743 sqlite3VdbeAddOp4Dup8(v, OP_ColumnsUsed, iIndexCur, 0, 0,
175744 (u8*)&colUsed, P4_INT64);
175745 }
175746 #endif /* SQLITE_ENABLE_COLUMN_USED_MASK */
175747 #ifdef SQLITE_ENABLE_CURSOR_HINTS
175748 if( HasRowid(pTab) ){
175749 sqlite3VdbeAddOp3(v, OP_CursorHint, iIndexCur, 0, pTabItem->iCursor);
175750 }
175751 #endif
175752 }
175753 }
175754 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
175755 if( (pTabItem->fg.jointype & JT_RIGHT)!=0
175756 && (pLevel->pRJ = sqlite3WhereMalloc(pWInfo, sizeof(WhereRightJoin)))!=0
@@ -176155,11 +176470,11 @@
176470 case SQLITE_INTEGER:
176471 iVal = sqlite3_value_int64(apArg[1]);
176472 break;
176473 case SQLITE_FLOAT: {
176474 double fVal = sqlite3_value_double(apArg[1]);
176475 if( sqlite3RealToI64(fVal)!=fVal ) goto error_out;
176476 iVal = (i64)fVal;
176477 break;
176478 }
176479 default:
176480 goto error_out;
@@ -187755,17 +188070,21 @@
188070
188071 /*
188072 ** Return the ROWID of the most recent insert
188073 */
188074 SQLITE_API sqlite_int64 sqlite3_last_insert_rowid(sqlite3 *db){
188075 i64 iRet;
188076 #ifdef SQLITE_ENABLE_API_ARMOR
188077 if( !sqlite3SafetyCheckOk(db) ){
188078 (void)SQLITE_MISUSE_BKPT;
188079 return 0;
188080 }
188081 #endif
188082 sqlite3_mutex_enter(db->mutex);
188083 iRet = db->lastRowid;
188084 sqlite3_mutex_leave(db->mutex);
188085 return iRet;
188086 }
188087
188088 /*
188089 ** Set the value returned by the sqlite3_last_insert_rowid() API function.
188090 */
@@ -187784,33 +188103,41 @@
188103 /*
188104 ** Return the number of changes in the most recently executed DML
188105 ** statement.
188106 */
188107 SQLITE_API sqlite3_int64 sqlite3_changes64(sqlite3 *db){
188108 i64 iRet;
188109 #ifdef SQLITE_ENABLE_API_ARMOR
188110 if( !sqlite3SafetyCheckOk(db) ){
188111 (void)SQLITE_MISUSE_BKPT;
188112 return 0;
188113 }
188114 #endif
188115 sqlite3_mutex_enter(db->mutex);
188116 iRet = db->nChange;
188117 sqlite3_mutex_leave(db->mutex);
188118 return iRet;
188119 }
188120 SQLITE_API int sqlite3_changes(sqlite3 *db){
188121 return (int)sqlite3_changes64(db);
188122 }
188123
188124 /*
188125 ** Return the number of changes since the database handle was opened.
188126 */
188127 SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3 *db){
188128 i64 iRet;
188129 #ifdef SQLITE_ENABLE_API_ARMOR
188130 if( !sqlite3SafetyCheckOk(db) ){
188131 (void)SQLITE_MISUSE_BKPT;
188132 return 0;
188133 }
188134 #endif
188135 sqlite3_mutex_enter(db->mutex);
188136 iRet = db->nTotalChange;
188137 sqlite3_mutex_leave(db->mutex);
188138 return iRet;
188139 }
188140 SQLITE_API int sqlite3_total_changes(sqlite3 *db){
188141 return (int)sqlite3_total_changes64(db);
188142 }
188143
@@ -188489,10 +188816,11 @@
188816 */
188817 SQLITE_API int sqlite3_busy_timeout(sqlite3 *db, int ms){
188818 #ifdef SQLITE_ENABLE_API_ARMOR
188819 if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT;
188820 #endif
188821 sqlite3_mutex_enter(db->mutex);
188822 if( ms>0 ){
188823 sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback,
188824 (void*)db);
188825 db->busyTimeout = ms;
188826 #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
@@ -188499,10 +188827,11 @@
188827 db->setlkTimeout = ms;
188828 #endif
188829 }else{
188830 sqlite3_busy_handler(db, 0, 0);
188831 }
188832 sqlite3_mutex_leave(db->mutex);
188833 return SQLITE_OK;
188834 }
188835
188836 /*
188837 ** Set the setlk timeout value.
@@ -189404,13 +189733,15 @@
189733 /*
189734 ** Return the byte offset of the most recent error
189735 */
189736 SQLITE_API int sqlite3_error_offset(sqlite3 *db){
189737 int iOffset = -1;
189738 if( db && sqlite3SafetyCheckSickOrOk(db) ){
189739 sqlite3_mutex_enter(db->mutex);
189740 if( db->errCode ){
189741 iOffset = db->errByteOffset;
189742 }
189743 sqlite3_mutex_leave(db->mutex);
189744 }
189745 return iOffset;
189746 }
189747
@@ -189460,29 +189791,47 @@
189791 /*
189792 ** Return the most recent error code generated by an SQLite routine. If NULL is
189793 ** passed to this function, we assume a malloc() failed during sqlite3_open().
189794 */
189795 SQLITE_API int sqlite3_errcode(sqlite3 *db){
189796 int iRet;
189797 if( !db ) return SQLITE_NOMEM_BKPT;
189798 if( !sqlite3SafetyCheckSickOrOk(db) ){
189799 return SQLITE_MISUSE_BKPT;
189800 }
189801 sqlite3_mutex_enter(db->mutex);
189802 if( db->mallocFailed ){
189803 iRet = SQLITE_NOMEM_BKPT;
189804 }else{
189805 iRet = db->errCode & db->errMask;
189806 }
189807 sqlite3_mutex_leave(db->mutex);
189808 return iRet;
189809 }
189810 SQLITE_API int sqlite3_extended_errcode(sqlite3 *db){
189811 int iRet;
189812 if( !db ) return SQLITE_NOMEM_BKPT;
189813 if( !sqlite3SafetyCheckSickOrOk(db) ){
189814 return SQLITE_MISUSE_BKPT;
189815 }
189816 sqlite3_mutex_enter(db->mutex);
189817 if( db->mallocFailed ){
189818 iRet = SQLITE_NOMEM_BKPT;
189819 }else{
189820 iRet = db->errCode;
189821 }
189822 sqlite3_mutex_leave(db->mutex);
189823 return iRet;
189824 }
189825 SQLITE_API int sqlite3_system_errno(sqlite3 *db){
189826 int iRet = 0;
189827 if( db ){
189828 sqlite3_mutex_enter(db->mutex);
189829 iRet = db->iSysErrno;
189830 sqlite3_mutex_leave(db->mutex);
189831 }
189832 return iRet;
189833 }
189834
189835 /*
189836 ** Return a string that describes the kind of error specified in the
189837 ** argument. For now, this simply calls the internal sqlite3ErrStr()
@@ -189673,19 +190022,21 @@
190022
190023
190024 if( limitId<0 || limitId>=SQLITE_N_LIMIT ){
190025 return -1;
190026 }
190027 sqlite3_mutex_enter(db->mutex);
190028 oldLimit = db->aLimit[limitId];
190029 if( newLimit>=0 ){ /* IMP: R-52476-28732 */
190030 if( newLimit>aHardLimit[limitId] ){
190031 newLimit = aHardLimit[limitId]; /* IMP: R-51463-25634 */
190032 }else if( newLimit<SQLITE_MIN_LENGTH && limitId==SQLITE_LIMIT_LENGTH ){
190033 newLimit = SQLITE_MIN_LENGTH;
190034 }
190035 db->aLimit[limitId] = newLimit;
190036 }
190037 sqlite3_mutex_leave(db->mutex);
190038 return oldLimit; /* IMP: R-53341-35419 */
190039 }
190040
190041 /*
190042 ** This function is used to parse both URIs and non-URI filenames passed by the
@@ -189724,22 +190075,22 @@
190075 int rc = SQLITE_OK;
190076 unsigned int flags = *pFlags;
190077 const char *zVfs = zDefaultVfs;
190078 char *zFile;
190079 char c;
190080 i64 nUri = strlen(zUri);
190081
190082 assert( *pzErrMsg==0 );
190083
190084 if( ((flags & SQLITE_OPEN_URI) /* IMP: R-48725-32206 */
190085 || AtomicLoad(&sqlite3GlobalConfig.bOpenUri)) /* IMP: R-51689-46548 */
190086 && nUri>=5 && memcmp(zUri, "file:", 5)==0 /* IMP: R-57884-37496 */
190087 ){
190088 char *zOpt;
190089 int eState; /* Parser state when parsing URI */
190090 i64 iIn; /* Input character index */
190091 i64 iOut = 0; /* Output character index */
190092 u64 nByte = nUri+8; /* Bytes of space to allocate */
190093
190094 /* Make sure the SQLITE_OPEN_URI flag is set to indicate to the VFS xOpen
190095 ** method that there may be extra parameters following the file-name. */
190096 flags |= SQLITE_OPEN_URI;
@@ -189769,11 +190120,11 @@
190120 if( zUri[5]=='/' && zUri[6]=='/' ){
190121 iIn = 7;
190122 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
190123 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
190124 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
190125 (int)(iIn-7), &zUri[7]);
190126 rc = SQLITE_ERROR;
190127 goto parse_uri_out;
190128 }
190129 }
190130 #endif
@@ -189844,15 +190195,15 @@
190195
190196 /* Check if there were any options specified that should be interpreted
190197 ** here. Options that are interpreted here include "vfs" and those that
190198 ** correspond to flags that may be passed to the sqlite3_open_v2()
190199 ** method. */
190200 zOpt = &zFile[strlen(zFile)+1];
190201 while( zOpt[0] ){
190202 i64 nOpt = strlen(zOpt);
190203 char *zVal = &zOpt[nOpt+1];
190204 i64 nVal = strlen(zVal);
190205
190206 if( nOpt==3 && memcmp("vfs", zOpt, 3)==0 ){
190207 zVfs = zVal;
190208 }else{
190209 struct OpenMode {
@@ -189894,11 +190245,11 @@
190245 if( aMode ){
190246 int i;
190247 int mode = 0;
190248 for(i=0; aMode[i].z; i++){
190249 const char *z = aMode[i].z;
190250 if( nVal==(i64)strlen(z) && 0==memcmp(zVal, z, nVal) ){
190251 mode = aMode[i].mode;
190252 break;
190253 }
190254 }
190255 if( mode==0 ){
@@ -190579,17 +190930,21 @@
190930 ** mode. Return TRUE if it is and FALSE if not. Autocommit mode is on
190931 ** by default. Autocommit is disabled by a BEGIN statement and reenabled
190932 ** by the next COMMIT or ROLLBACK.
190933 */
190934 SQLITE_API int sqlite3_get_autocommit(sqlite3 *db){
190935 int iRet;
190936 #ifdef SQLITE_ENABLE_API_ARMOR
190937 if( !sqlite3SafetyCheckOk(db) ){
190938 (void)SQLITE_MISUSE_BKPT;
190939 return 0;
190940 }
190941 #endif
190942 sqlite3_mutex_enter(db->mutex);
190943 iRet = db->autoCommit;
190944 sqlite3_mutex_leave(db->mutex);
190945 return iRet;
190946 }
190947
190948 /*
190949 ** The following routines are substitutes for constants SQLITE_CORRUPT,
190950 ** SQLITE_MISUSE, SQLITE_CANTOPEN, SQLITE_NOMEM and possibly other error
@@ -191610,21 +191965,23 @@
191965 /*
191966 ** Return the name of the N-th database schema. Return NULL if N is out
191967 ** of range.
191968 */
191969 SQLITE_API const char *sqlite3_db_name(sqlite3 *db, int N){
191970 const char *zRet = 0;
191971 #ifdef SQLITE_ENABLE_API_ARMOR
191972 if( !sqlite3SafetyCheckOk(db) ){
191973 (void)SQLITE_MISUSE_BKPT;
191974 return 0;
191975 }
191976 #endif
191977 sqlite3_mutex_enter(db->mutex);
191978 if( N>=0 && N<db->nDb ){
191979 zRet = db->aDb[N].zDbSName;
 
191980 }
191981 sqlite3_mutex_leave(db->mutex);
191982 return zRet;
191983 }
191984
191985 /*
191986 ** Return the filename of the database associated with a database
191987 ** connection.
@@ -197602,10 +197959,11 @@
197959 }else{
197960 int nDistance;
197961 char *p1;
197962 char *p2;
197963 char *aOut;
197964 i64 nAlloc = (i64)nPoslist*2 + FTS3_BUFFER_PADDING;
197965
197966 if( nMaxUndeferred>iPrev ){
197967 p1 = aPoslist;
197968 p2 = pPhrase->doclist.pList;
197969 nDistance = nMaxUndeferred - iPrev;
@@ -197613,11 +197971,11 @@
197971 p1 = pPhrase->doclist.pList;
197972 p2 = aPoslist;
197973 nDistance = iPrev - nMaxUndeferred;
197974 }
197975
197976 aOut = (char *)sqlite3Fts3MallocZero(nAlloc);
197977 if( !aOut ){
197978 sqlite3_free(aPoslist);
197979 return SQLITE_NOMEM;
197980 }
197981
@@ -207898,11 +208256,11 @@
208256 if( nHeight<1 || nHeight>=FTS_MAX_APPENDABLE_HEIGHT ){
208257 sqlite3_reset(pSelect);
208258 return FTS_CORRUPT_VTAB;
208259 }
208260
208261 pWriter->nLeafEst = (int)(((iEnd - iStart)+1)/FTS_MAX_APPENDABLE_HEIGHT);
208262 pWriter->iStart = iStart;
208263 pWriter->iEnd = iEnd;
208264 pWriter->iAbsLevel = iAbsLevel;
208265 pWriter->iIdx = iIdx;
208266
@@ -215418,12 +215776,11 @@
215776 jsonBlobAppendNode(pParse, JSONB_TEXTRAW, nJson, zJson);
215777 }
215778 break;
215779 }
215780 case SQLITE_FLOAT: {
215781 if( NEVER(sqlite3IsNaN(sqlite3_value_double(pArg))) ){
 
215782 jsonBlobAppendNode(pParse, JSONB_NULL, 0, 0);
215783 }else{
215784 int n = sqlite3_value_bytes(pArg);
215785 const char *z = (const char*)sqlite3_value_text(pArg);
215786 if( z==0 ) return 1;
@@ -218016,11 +218373,11 @@
218373 int mxLevel; /* iLevel value for root of the tree */
218374 RtreeSearchPoint *aPoint; /* Priority queue for search points */
218375 sqlite3_stmt *pReadAux; /* Statement to read aux-data */
218376 RtreeSearchPoint sPoint; /* Cached next search point */
218377 RtreeNode *aNode[RTREE_CACHE_SZ]; /* Rtree node cache */
218378 u32 anQueue[RTREE_MAX_DEPTH+2]; /* Number of queued entries by iLevel */
218379 };
218380
218381 /* Return the Rtree of a RtreeCursor */
218382 #define RTREE_OF_CURSOR(X) ((Rtree*)((X)->base.pVtab))
218383
@@ -218499,11 +218856,11 @@
218856 ** are the leaves, and so on. If the depth as specified on the root node
218857 ** is greater than RTREE_MAX_DEPTH, the r-tree structure must be corrupt.
218858 */
218859 if( rc==SQLITE_OK && pNode && iNode==1 ){
218860 pRtree->iDepth = readInt16(pNode->zData);
218861 if( pRtree->iDepth>=RTREE_MAX_DEPTH ){
218862 rc = SQLITE_CORRUPT_VTAB;
218863 RTREE_IS_CORRUPT(pRtree);
218864 }
218865 }
218866
@@ -234473,11 +234830,11 @@
234830 SessionBuffer *p,
234831 const char *zStr,
234832 int *pRc
234833 ){
234834 int nStr = sqlite3Strlen30(zStr);
234835 if( 0==sessionBufferGrow(p, (i64)nStr+1, pRc) ){
234836 memcpy(&p->aBuf[p->nBuf], zStr, nStr);
234837 p->nBuf += nStr;
234838 p->aBuf[p->nBuf] = 0x00;
234839 }
234840 }
@@ -239875,18 +240232,21 @@
240232 int nCol, /* Number of columns in each record */
240233 u8 *a1, int n1, /* Record 1 */
240234 u8 *a2, int n2, /* Record 2 */
240235 int *pRc /* IN/OUT: error code */
240236 ){
240237 u8 *a1Eof = &a1[n1];
240238 u8 *a2Eof = &a2[n2];
240239
240240 sessionBufferGrow(pBuf, (i64)n1+n2, pRc);
240241 if( *pRc==SQLITE_OK ){
240242 int i;
240243 u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
240244 for(i=0; i<nCol; i++){
240245 int nn1 = (a1<a1Eof ? sessionSerialLen(a1) : 0);
240246 int nn2 = (a2<a2Eof ? sessionSerialLen(a2) : 0);
240247 if( nn1==0 || (nn2>0 && (*a1==0 || *a1==0xFF)) ){
240248 memcpy(pOut, a2, nn2);
240249 pOut += nn2;
240250 }else{
240251 memcpy(pOut, a1, nn1);
240252 pOut += nn1;
@@ -239924,11 +240284,11 @@
240284 sqlite3_changeset_iter *pIter, /* Iterator pointed at local change */
240285 u8 *aRec, int nRec, /* Local change */
240286 u8 *aChange, int nChange, /* Record to rebase against */
240287 int *pRc /* IN/OUT: Return Code */
240288 ){
240289 sessionBufferGrow(pBuf, (i64)2+nRec+nChange, pRc);
240290 if( *pRc==SQLITE_OK ){
240291 int bData = 0;
240292 u8 *pOut = &pBuf->aBuf[pBuf->nBuf];
240293 int i;
240294 u8 *a1 = aRec;
@@ -258623,13 +258983,17 @@
258983 iRowidOff = fts5LeafFirstRowidOff(pLeaf);
258984 if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
258985 FTS5_CORRUPT_ROWID(p, iRow);
258986 }else{
258987 iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
258988 if( iOff+nTerm>pLeaf->szLeaf ){
258989 FTS5_CORRUPT_ROWID(p, iRow);
258990 }else{
258991 res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
258992 if( res==0 ) res = nTerm - nIdxTerm;
258993 if( res<0 ) FTS5_CORRUPT_ROWID(p, iRow);
258994 }
258995 }
258996
258997 fts5IntegrityCheckPgidx(p, iRow, pLeaf);
258998 }
258999 fts5DataRelease(pLeaf);
@@ -263267,11 +263631,11 @@
263631 int nArg, /* Number of args */
263632 sqlite3_value **apUnused /* Function arguments */
263633 ){
263634 assert( nArg==0 );
263635 UNUSED_PARAM2(nArg, apUnused);
263636 sqlite3_result_text(pCtx, "fts5: 2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c", -1, SQLITE_TRANSIENT);
263637 }
263638
263639 /*
263640 ** Implementation of fts5_locale(LOCALE, TEXT) function.
263641 **
@@ -263909,38 +264273,35 @@
264273
264274 if( bCreate ){
264275 if( pConfig->eContent==FTS5_CONTENT_NORMAL
264276 || pConfig->eContent==FTS5_CONTENT_UNINDEXED
264277 ){
264278 int i = 0;
264279 char *zDefn = 0;
264280 sqlite3_str *pDefn = sqlite3_str_new(pConfig->db);
264281
264282 sqlite3_str_appendf(pDefn, "id INTEGER PRIMARY KEY");
264283 for(i=0; i<pConfig->nCol; i++){
264284 if( pConfig->eContent==FTS5_CONTENT_NORMAL || pConfig->abUnindexed[i] ){
264285 sqlite3_str_appendf(pDefn, ", c%d", i);
264286 }
264287 }
264288 if( pConfig->bLocale ){
264289 for(i=0; i<pConfig->nCol; i++){
264290 if( pConfig->abUnindexed[i]==0 ){
264291 sqlite3_str_appendf(pDefn, ", l%d", i);
264292 }
264293 }
264294 }
264295 zDefn = sqlite3_str_finish(pDefn);
264296
264297 if( zDefn ){
264298 rc = sqlite3Fts5CreateTable(pConfig, "content", zDefn, 0, pzErr);
264299 sqlite3_free(zDefn);
264300 }else{
264301 rc = SQLITE_NOMEM;
264302 }
 
 
 
264303 }
264304
264305 if( rc==SQLITE_OK && pConfig->bColumnsize ){
264306 const char *zCols = "id INTEGER PRIMARY KEY, sz BLOB";
264307 if( pConfig->bContentlessDelete ){
264308
+63 -10
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.54.0"
150150
#define SQLITE_VERSION_NUMBER 3054000
151
-#define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
151
+#define SQLITE_SOURCE_ID "2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c"
152152
#define SQLITE_SCM_BRANCH "trunk"
153153
#define SQLITE_SCM_TAGS ""
154
-#define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
154
+#define SQLITE_SCM_DATETIME "2026-06-26T19:31:46.902Z"
155155
156156
/*
157157
** CAPI3REF: Run-Time Library Version Numbers
158158
** KEYWORDS: sqlite3_version sqlite3_sourceid
159159
**
@@ -3411,11 +3411,11 @@
34113411
** authorizer will fail with an error message explaining that
34123412
** access is denied.
34133413
**
34143414
** ^The first parameter to the authorizer callback is a copy of the third
34153415
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3416
-** to the callback is an integer [SQLITE_COPY | action code] that specifies
3416
+** to the callback is an integer [SQLITE_READ | action code] that specifies
34173417
** the particular action to be authorized. ^The third through sixth parameters
34183418
** to the callback are either NULL pointers or zero-terminated strings
34193419
** that contain additional details about the action to be authorized.
34203420
** Applications must always be prepared to encounter a NULL pointer in any
34213421
** of the third through the sixth parameters of the authorization callback.
@@ -3454,25 +3454,37 @@
34543454
** ^(Only a single authorizer can be in place on a database connection
34553455
** at a time. Each call to sqlite3_set_authorizer overrides the
34563456
** previous call.)^ ^Disable the authorizer by installing a NULL callback.
34573457
** The authorizer is disabled by default.
34583458
**
3459
-** The authorizer callback must not do anything that will modify
3459
+** <h3>Limitations And Caveats</h3><ul>
3460
+**
3461
+** <li>The authorizer callback must not do anything that will modify
34603462
** the database connection that invoked the authorizer callback.
34613463
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
34623464
** database connections for the meaning of "modify" in this paragraph.
34633465
**
3464
-** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3466
+** <li>^When [sqlite3_prepare_v2()] is used to prepare a statement, the
34653467
** statement might be re-prepared during [sqlite3_step()] due to a
34663468
** schema change. Hence, the application should ensure that the
34673469
** correct authorizer callback remains in place during the [sqlite3_step()].
34683470
**
3469
-** ^Note that the authorizer callback is invoked only during
3471
+** <li>^The authorizer callback is invoked only during
34703472
** [sqlite3_prepare()] or its variants. Authorization is not
34713473
** performed during statement evaluation in [sqlite3_step()], unless
34723474
** as stated in the previous paragraph, sqlite3_step() invokes
34733475
** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3476
+**
3477
+** <li>Authorizer callbacks for the expressions of a
3478
+** [generated column] are invoked when the schema is parsed (and specifically
3479
+** when the [CREATE TABLE] statement that contains the generated column is
3480
+** parsed) not when the generated column is used in a DML statement.
3481
+** This is deliberate, as one of the purposes of generated columns
3482
+** is to give schema designers the ability to provide gated access
3483
+** to privileged columns and/or functions.
3484
+**
3485
+** </ul>
34743486
*/
34753487
SQLITE_API int sqlite3_set_authorizer(
34763488
sqlite3*,
34773489
int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
34783490
void *pUserData
@@ -3543,12 +3555,17 @@
35433555
#define SQLITE_ANALYZE 28 /* Table Name NULL */
35443556
#define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
35453557
#define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
35463558
#define SQLITE_FUNCTION 31 /* NULL Function Name */
35473559
#define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3548
-#define SQLITE_COPY 0 /* No longer used */
35493560
#define SQLITE_RECURSIVE 33 /* NULL NULL */
3561
+
3562
+/*
3563
+** Note: The SQLITE_COPY macro (with value 0) used to be one of the
3564
+** action codes above. That macro has now been repurposed as a possible
3565
+** value to the 3rd argument to sqlite3_result_str().
3566
+*/
35503567
35513568
/*
35523569
** CAPI3REF: Deprecated Tracing And Profiling Functions
35533570
** DEPRECATED
35543571
**
@@ -4539,10 +4556,12 @@
45394556
** there is a small performance advantage to passing an nByte parameter that
45404557
** is the number of bytes in the input string <i>including</i>
45414558
** the nul-terminator.
45424559
** Note that nByte measures the length of the input in bytes, not
45434560
** characters, even for the UTF-16 interfaces.
4561
+** For the sqlite3_prepare16() and sqlite3_prepare16_v2() interfaces,
4562
+** the nByte value must be even or undefined behavior can result.
45444563
**
45454564
** ^If pzTail is not NULL then *pzTail is made to point to the first byte
45464565
** past the end of the first SQL statement in zSql. These routines only
45474566
** compile the first statement in zSql, so *pzTail is left pointing to
45484567
** what remains uncompiled.
@@ -5285,11 +5304,11 @@
52855304
** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
52865305
** can be obtained by calling [sqlite3_reset()] on the
52875306
** [prepared statement]. ^In the "v2" interface,
52885307
** the more specific error code is returned directly by sqlite3_step().
52895308
**
5290
-** [SQLITE_MISUSE] means that the this routine was called inappropriately.
5309
+** [SQLITE_MISUSE] means that this routine was called inappropriately.
52915310
** Perhaps it was called on a [prepared statement] that has
52925311
** already been [sqlite3_finalize | finalized] or on one that had
52935312
** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
52945313
** be the case that the same database connection is being used by two or
52955314
** more threads at the same moment in time.
@@ -8796,12 +8815,12 @@
87968815
** The lifecycle of an sqlite3_str object is as follows:
87978816
** <ol>
87988817
** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
87998818
** <li> ^Text is appended to the sqlite3_str object using various
88008819
** methods, such as [sqlite3_str_appendf()].
8801
-** <li> ^The sqlite3_str object is destroyed and the string it created
8802
-** is returned using the [sqlite3_str_finish()] interface.
8820
+** <li> The sqlite3_str object is destroyed and the string it created
8821
+** is returned using [sqlite3_str_finish()] or [sqlite3_result_str()].
88038822
** </ol>
88048823
*/
88058824
typedef struct sqlite3_str sqlite3_str;
88068825
88078826
/*
@@ -8849,10 +8868,44 @@
88498868
** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
88508869
*/
88518870
SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
88528871
SQLITE_API void sqlite3_str_free(sqlite3_str*);
88538872
8873
+/*
8874
+** CAPI3REF: Return A Dynamic String From an SQL Function
8875
+**
8876
+** The [sqlite3_result_str(C,S,F)] interface causes the
8877
+** [sqlite3_str|dynamic string] S to become the return value for the
8878
+** application-defined function or virtual table that uses
8879
+** [sqlite3_context] C. The F flag can be one of [SQLITE_COPY]
8880
+** or [SQLITE_XFER] or [SQLITE_FINISH].
8881
+**
8882
+** If the dynamic string is invalid or incomplete due to an out-of-memory
8883
+** or string-too-large error, then this routine transfers that error
8884
+** over to the SQL function.
8885
+**
8886
+** If the F argument is SQLITE_COPY, then a copy of the dynamic string
8887
+** content is made and the dynamic string object is unchanged.
8888
+** If the F argument is SQLITE_XFER, then ownership of the content
8889
+** in the dynamic is transferred to the SQL function (via a pointer copy
8890
+** rather than a string copy) and the dynamic string is reset to an
8891
+** empty string. The SQLITE_FINISH value for F works like SQLITE_RESET
8892
+** except that it also invokes the [sqlite3_str_free(S)] destructor
8893
+** on the dynamic string object.
8894
+*/
8895
+SQLITE_API void sqlite3_result_str(sqlite3_context*, sqlite3_str*, int);
8896
+
8897
+/*
8898
+** CAPI3REF: Control Flags For sqlite3_result_str()
8899
+**
8900
+** The following integers can be used as the third "F" argument
8901
+** to [sqlite3_result_str(C,S,F)].
8902
+*/
8903
+#define SQLITE_COPY 0 /* Results copied. Dynamic string unchanged */
8904
+#define SQLITE_XFER 1 /* Results transfered. Dynamic string reset */
8905
+#define SQLITE_FINISH 2 /* Like SQLITE_XFER, plus dynamic string freed */
8906
+
88548907
/*
88558908
** CAPI3REF: Add Content To A Dynamic String
88568909
** METHOD: sqlite3_str
88578910
**
88588911
** These interfaces add or remove content to an sqlite3_str object
88598912
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-06-16 13:43:08 3f3fb9b638f59ad982beafb7c117f24ddd3da612e62c862510805fa672ffae06"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-06-16T13:43:08.110Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3411,11 +3411,11 @@
3411 ** authorizer will fail with an error message explaining that
3412 ** access is denied.
3413 **
3414 ** ^The first parameter to the authorizer callback is a copy of the third
3415 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3416 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
3417 ** the particular action to be authorized. ^The third through sixth parameters
3418 ** to the callback are either NULL pointers or zero-terminated strings
3419 ** that contain additional details about the action to be authorized.
3420 ** Applications must always be prepared to encounter a NULL pointer in any
3421 ** of the third through the sixth parameters of the authorization callback.
@@ -3454,25 +3454,37 @@
3454 ** ^(Only a single authorizer can be in place on a database connection
3455 ** at a time. Each call to sqlite3_set_authorizer overrides the
3456 ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
3457 ** The authorizer is disabled by default.
3458 **
3459 ** The authorizer callback must not do anything that will modify
 
 
3460 ** the database connection that invoked the authorizer callback.
3461 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3462 ** database connections for the meaning of "modify" in this paragraph.
3463 **
3464 ** ^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3465 ** statement might be re-prepared during [sqlite3_step()] due to a
3466 ** schema change. Hence, the application should ensure that the
3467 ** correct authorizer callback remains in place during the [sqlite3_step()].
3468 **
3469 ** ^Note that the authorizer callback is invoked only during
3470 ** [sqlite3_prepare()] or its variants. Authorization is not
3471 ** performed during statement evaluation in [sqlite3_step()], unless
3472 ** as stated in the previous paragraph, sqlite3_step() invokes
3473 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
 
 
 
 
 
 
 
 
 
 
3474 */
3475 SQLITE_API int sqlite3_set_authorizer(
3476 sqlite3*,
3477 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3478 void *pUserData
@@ -3543,12 +3555,17 @@
3543 #define SQLITE_ANALYZE 28 /* Table Name NULL */
3544 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
3545 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3546 #define SQLITE_FUNCTION 31 /* NULL Function Name */
3547 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
3548 #define SQLITE_COPY 0 /* No longer used */
3549 #define SQLITE_RECURSIVE 33 /* NULL NULL */
 
 
 
 
 
 
3550
3551 /*
3552 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3553 ** DEPRECATED
3554 **
@@ -4539,10 +4556,12 @@
4539 ** there is a small performance advantage to passing an nByte parameter that
4540 ** is the number of bytes in the input string <i>including</i>
4541 ** the nul-terminator.
4542 ** Note that nByte measures the length of the input in bytes, not
4543 ** characters, even for the UTF-16 interfaces.
 
 
4544 **
4545 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4546 ** past the end of the first SQL statement in zSql. These routines only
4547 ** compile the first statement in zSql, so *pzTail is left pointing to
4548 ** what remains uncompiled.
@@ -5285,11 +5304,11 @@
5285 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5286 ** can be obtained by calling [sqlite3_reset()] on the
5287 ** [prepared statement]. ^In the "v2" interface,
5288 ** the more specific error code is returned directly by sqlite3_step().
5289 **
5290 ** [SQLITE_MISUSE] means that the this routine was called inappropriately.
5291 ** Perhaps it was called on a [prepared statement] that has
5292 ** already been [sqlite3_finalize | finalized] or on one that had
5293 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
5294 ** be the case that the same database connection is being used by two or
5295 ** more threads at the same moment in time.
@@ -8796,12 +8815,12 @@
8796 ** The lifecycle of an sqlite3_str object is as follows:
8797 ** <ol>
8798 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
8799 ** <li> ^Text is appended to the sqlite3_str object using various
8800 ** methods, such as [sqlite3_str_appendf()].
8801 ** <li> ^The sqlite3_str object is destroyed and the string it created
8802 ** is returned using the [sqlite3_str_finish()] interface.
8803 ** </ol>
8804 */
8805 typedef struct sqlite3_str sqlite3_str;
8806
8807 /*
@@ -8849,10 +8868,44 @@
8849 ** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
8850 */
8851 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
8852 SQLITE_API void sqlite3_str_free(sqlite3_str*);
8853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8854 /*
8855 ** CAPI3REF: Add Content To A Dynamic String
8856 ** METHOD: sqlite3_str
8857 **
8858 ** These interfaces add or remove content to an sqlite3_str object
8859
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,14 +146,14 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.54.0"
150 #define SQLITE_VERSION_NUMBER 3054000
151 #define SQLITE_SOURCE_ID "2026-06-26 19:31:46 716782abe939083b7732289d862ddfd841057d3458814f96e5e6d7826ec7fa5c"
152 #define SQLITE_SCM_BRANCH "trunk"
153 #define SQLITE_SCM_TAGS ""
154 #define SQLITE_SCM_DATETIME "2026-06-26T19:31:46.902Z"
155
156 /*
157 ** CAPI3REF: Run-Time Library Version Numbers
158 ** KEYWORDS: sqlite3_version sqlite3_sourceid
159 **
@@ -3411,11 +3411,11 @@
3411 ** authorizer will fail with an error message explaining that
3412 ** access is denied.
3413 **
3414 ** ^The first parameter to the authorizer callback is a copy of the third
3415 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
3416 ** to the callback is an integer [SQLITE_READ | action code] that specifies
3417 ** the particular action to be authorized. ^The third through sixth parameters
3418 ** to the callback are either NULL pointers or zero-terminated strings
3419 ** that contain additional details about the action to be authorized.
3420 ** Applications must always be prepared to encounter a NULL pointer in any
3421 ** of the third through the sixth parameters of the authorization callback.
@@ -3454,25 +3454,37 @@
3454 ** ^(Only a single authorizer can be in place on a database connection
3455 ** at a time. Each call to sqlite3_set_authorizer overrides the
3456 ** previous call.)^ ^Disable the authorizer by installing a NULL callback.
3457 ** The authorizer is disabled by default.
3458 **
3459 ** <h3>Limitations And Caveats</h3><ul>
3460 **
3461 ** <li>The authorizer callback must not do anything that will modify
3462 ** the database connection that invoked the authorizer callback.
3463 ** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3464 ** database connections for the meaning of "modify" in this paragraph.
3465 **
3466 ** <li>^When [sqlite3_prepare_v2()] is used to prepare a statement, the
3467 ** statement might be re-prepared during [sqlite3_step()] due to a
3468 ** schema change. Hence, the application should ensure that the
3469 ** correct authorizer callback remains in place during the [sqlite3_step()].
3470 **
3471 ** <li>^The authorizer callback is invoked only during
3472 ** [sqlite3_prepare()] or its variants. Authorization is not
3473 ** performed during statement evaluation in [sqlite3_step()], unless
3474 ** as stated in the previous paragraph, sqlite3_step() invokes
3475 ** sqlite3_prepare_v2() to reprepare a statement after a schema change.
3476 **
3477 ** <li>Authorizer callbacks for the expressions of a
3478 ** [generated column] are invoked when the schema is parsed (and specifically
3479 ** when the [CREATE TABLE] statement that contains the generated column is
3480 ** parsed) not when the generated column is used in a DML statement.
3481 ** This is deliberate, as one of the purposes of generated columns
3482 ** is to give schema designers the ability to provide gated access
3483 ** to privileged columns and/or functions.
3484 **
3485 ** </ul>
3486 */
3487 SQLITE_API int sqlite3_set_authorizer(
3488 sqlite3*,
3489 int (*xAuth)(void*,int,const char*,const char*,const char*,const char*),
3490 void *pUserData
@@ -3543,12 +3555,17 @@
3555 #define SQLITE_ANALYZE 28 /* Table Name NULL */
3556 #define SQLITE_CREATE_VTABLE 29 /* Table Name Module Name */
3557 #define SQLITE_DROP_VTABLE 30 /* Table Name Module Name */
3558 #define SQLITE_FUNCTION 31 /* NULL Function Name */
3559 #define SQLITE_SAVEPOINT 32 /* Operation Savepoint Name */
 
3560 #define SQLITE_RECURSIVE 33 /* NULL NULL */
3561
3562 /*
3563 ** Note: The SQLITE_COPY macro (with value 0) used to be one of the
3564 ** action codes above. That macro has now been repurposed as a possible
3565 ** value to the 3rd argument to sqlite3_result_str().
3566 */
3567
3568 /*
3569 ** CAPI3REF: Deprecated Tracing And Profiling Functions
3570 ** DEPRECATED
3571 **
@@ -4539,10 +4556,12 @@
4556 ** there is a small performance advantage to passing an nByte parameter that
4557 ** is the number of bytes in the input string <i>including</i>
4558 ** the nul-terminator.
4559 ** Note that nByte measures the length of the input in bytes, not
4560 ** characters, even for the UTF-16 interfaces.
4561 ** For the sqlite3_prepare16() and sqlite3_prepare16_v2() interfaces,
4562 ** the nByte value must be even or undefined behavior can result.
4563 **
4564 ** ^If pzTail is not NULL then *pzTail is made to point to the first byte
4565 ** past the end of the first SQL statement in zSql. These routines only
4566 ** compile the first statement in zSql, so *pzTail is left pointing to
4567 ** what remains uncompiled.
@@ -5285,11 +5304,11 @@
5304 ** [SQLITE_INTERRUPT], [SQLITE_SCHEMA], [SQLITE_CORRUPT], and so forth)
5305 ** can be obtained by calling [sqlite3_reset()] on the
5306 ** [prepared statement]. ^In the "v2" interface,
5307 ** the more specific error code is returned directly by sqlite3_step().
5308 **
5309 ** [SQLITE_MISUSE] means that this routine was called inappropriately.
5310 ** Perhaps it was called on a [prepared statement] that has
5311 ** already been [sqlite3_finalize | finalized] or on one that had
5312 ** previously returned [SQLITE_ERROR] or [SQLITE_DONE]. Or it could
5313 ** be the case that the same database connection is being used by two or
5314 ** more threads at the same moment in time.
@@ -8796,12 +8815,12 @@
8815 ** The lifecycle of an sqlite3_str object is as follows:
8816 ** <ol>
8817 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
8818 ** <li> ^Text is appended to the sqlite3_str object using various
8819 ** methods, such as [sqlite3_str_appendf()].
8820 ** <li> The sqlite3_str object is destroyed and the string it created
8821 ** is returned using [sqlite3_str_finish()] or [sqlite3_result_str()].
8822 ** </ol>
8823 */
8824 typedef struct sqlite3_str sqlite3_str;
8825
8826 /*
@@ -8849,10 +8868,44 @@
8868 ** the equivalent of calling [sqlite3_free](sqlite3_str_finish(X)).
8869 */
8870 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
8871 SQLITE_API void sqlite3_str_free(sqlite3_str*);
8872
8873 /*
8874 ** CAPI3REF: Return A Dynamic String From an SQL Function
8875 **
8876 ** The [sqlite3_result_str(C,S,F)] interface causes the
8877 ** [sqlite3_str|dynamic string] S to become the return value for the
8878 ** application-defined function or virtual table that uses
8879 ** [sqlite3_context] C. The F flag can be one of [SQLITE_COPY]
8880 ** or [SQLITE_XFER] or [SQLITE_FINISH].
8881 **
8882 ** If the dynamic string is invalid or incomplete due to an out-of-memory
8883 ** or string-too-large error, then this routine transfers that error
8884 ** over to the SQL function.
8885 **
8886 ** If the F argument is SQLITE_COPY, then a copy of the dynamic string
8887 ** content is made and the dynamic string object is unchanged.
8888 ** If the F argument is SQLITE_XFER, then ownership of the content
8889 ** in the dynamic is transferred to the SQL function (via a pointer copy
8890 ** rather than a string copy) and the dynamic string is reset to an
8891 ** empty string. The SQLITE_FINISH value for F works like SQLITE_RESET
8892 ** except that it also invokes the [sqlite3_str_free(S)] destructor
8893 ** on the dynamic string object.
8894 */
8895 SQLITE_API void sqlite3_result_str(sqlite3_context*, sqlite3_str*, int);
8896
8897 /*
8898 ** CAPI3REF: Control Flags For sqlite3_result_str()
8899 **
8900 ** The following integers can be used as the third "F" argument
8901 ** to [sqlite3_result_str(C,S,F)].
8902 */
8903 #define SQLITE_COPY 0 /* Results copied. Dynamic string unchanged */
8904 #define SQLITE_XFER 1 /* Results transfered. Dynamic string reset */
8905 #define SQLITE_FINISH 2 /* Like SQLITE_XFER, plus dynamic string freed */
8906
8907 /*
8908 ** CAPI3REF: Add Content To A Dynamic String
8909 ** METHOD: sqlite3_str
8910 **
8911 ** These interfaces add or remove content to an sqlite3_str object
8912

Keyboard Shortcuts

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