1
1
/******************************************************************************
2
2
** This file is an amalgamation of many separate C source files from SQLite
3
- ** version 3.50.0 . By combining all the individual C code files into this
3
+ ** version 3.50.1 . By combining all the individual C code files into this
4
4
** single large file, the entire code can be compiled as a single translation
5
5
** unit. This allows many compilers to do optimizations that would not be
6
6
** possible if the files were compiled separately. Performance improvements
18
18
** separate file. This file contains only code for the core SQLite library.
19
19
**
20
20
** The content in this amalgamation comes from Fossil check-in
21
- ** dfc790f998f450d9c35e3ba1c8c89c17466c with changes in files:
21
+ ** b77dc5e0f596d2140d9ac682b2893ff65d3a with changes in files:
22
22
**
23
23
**
24
24
*/
@@ -465,9 +465,9 @@ extern "C" {
465
465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466
466
** [sqlite_version()] and [sqlite_source_id()].
467
467
*/
468
- #define SQLITE_VERSION "3.50.0 "
469
- #define SQLITE_VERSION_NUMBER 3050000
470
- #define SQLITE_SOURCE_ID "2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742 "
468
+ #define SQLITE_VERSION "3.50.1 "
469
+ #define SQLITE_VERSION_NUMBER 3050001
470
+ #define SQLITE_SOURCE_ID "2025-06-06 14:52:32 b77dc5e0f596d2140d9ac682b2893ff65d3a4140aa86067a3efebe29dc914c95 "
471
471
472
472
/*
473
473
** CAPI3REF: Run-Time Library Version Numbers
@@ -18703,6 +18703,7 @@ struct CollSeq {
18703
18703
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
18704
18704
#define SQLITE_AFF_REAL 0x45 /* 'E' */
18705
18705
#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
18706
+ #define SQLITE_AFF_DEFER 0x58 /* 'X' - defer computation until later */
18706
18707
18707
18708
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
18708
18709
@@ -43874,21 +43875,20 @@ static int unixShmLock(
43874
43875
/* Check that, if this to be a blocking lock, no locks that occur later
43875
43876
** in the following list than the lock being obtained are already held:
43876
43877
**
43877
- ** 1. Checkpointer lock (ofst==1).
43878
- ** 2. Write lock (ofst==0).
43879
- ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
43878
+ ** 1. Recovery lock (ofst==2).
43879
+ ** 2. Checkpointer lock (ofst==1).
43880
+ ** 3. Write lock (ofst==0).
43881
+ ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
43880
43882
**
43881
43883
** In other words, if this is a blocking lock, none of the locks that
43882
43884
** occur later in the above list than the lock being obtained may be
43883
43885
** held.
43884
- **
43885
- ** It is not permitted to block on the RECOVER lock.
43886
43886
*/
43887
43887
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
43888
43888
{
43889
43889
u16 lockMask = (p->exclMask|p->sharedMask);
43890
43890
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
43891
- (ofst!=2) /* not RECOVER */
43891
+ (ofst!=2 || lockMask==0)
43892
43892
&& (ofst!=1 || lockMask==0 || lockMask==2)
43893
43893
&& (ofst!=0 || lockMask<3)
43894
43894
&& (ofst<3 || lockMask<(1<<ofst))
@@ -49849,7 +49849,11 @@ static int winHandleLockTimeout(
49849
49849
if( res==WAIT_OBJECT_0 ){
49850
49850
ret = TRUE;
49851
49851
}else if( res==WAIT_TIMEOUT ){
49852
+ #if SQLITE_ENABLE_SETLK_TIMEOUT==1
49852
49853
rc = SQLITE_BUSY_TIMEOUT;
49854
+ #else
49855
+ rc = SQLITE_BUSY;
49856
+ #endif
49853
49857
}else{
49854
49858
/* Some other error has occurred */
49855
49859
rc = SQLITE_IOERR_LOCK;
@@ -51660,21 +51664,20 @@ static int winShmLock(
51660
51664
/* Check that, if this to be a blocking lock, no locks that occur later
51661
51665
** in the following list than the lock being obtained are already held:
51662
51666
**
51663
- ** 1. Checkpointer lock (ofst==1).
51664
- ** 2. Write lock (ofst==0).
51665
- ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
51667
+ ** 1. Recovery lock (ofst==2).
51668
+ ** 2. Checkpointer lock (ofst==1).
51669
+ ** 3. Write lock (ofst==0).
51670
+ ** 4. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK).
51666
51671
**
51667
51672
** In other words, if this is a blocking lock, none of the locks that
51668
51673
** occur later in the above list than the lock being obtained may be
51669
51674
** held.
51670
- **
51671
- ** It is not permitted to block on the RECOVER lock.
51672
51675
*/
51673
51676
#if defined(SQLITE_ENABLE_SETLK_TIMEOUT) && defined(SQLITE_DEBUG)
51674
51677
{
51675
51678
u16 lockMask = (p->exclMask|p->sharedMask);
51676
51679
assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || (
51677
- (ofst!=2) /* not RECOVER */
51680
+ (ofst!=2 || lockMask==0)
51678
51681
&& (ofst!=1 || lockMask==0 || lockMask==2)
51679
51682
&& (ofst!=0 || lockMask<3)
51680
51683
&& (ofst<3 || lockMask<(1<<ofst))
@@ -58750,6 +58753,9 @@ struct Pager {
58750
58753
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
58751
58754
char *zWal; /* File name for write-ahead log */
58752
58755
#endif
58756
+ #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
58757
+ sqlite3 *dbWal;
58758
+ #endif
58753
58759
};
58754
58760
58755
58761
/*
@@ -65631,6 +65637,11 @@ static int pagerOpenWal(Pager *pPager){
65631
65637
pPager->fd, pPager->zWal, pPager->exclusiveMode,
65632
65638
pPager->journalSizeLimit, &pPager->pWal
65633
65639
);
65640
+ #ifdef SQLITE_ENABLE_SETLK_TIMEOUT
65641
+ if( rc==SQLITE_OK ){
65642
+ sqlite3WalDb(pPager->pWal, pPager->dbWal);
65643
+ }
65644
+ #endif
65634
65645
}
65635
65646
pagerFixMaplimit(pPager);
65636
65647
@@ -65750,6 +65761,7 @@ SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager *pPager, int bLock){
65750
65761
** blocking locks are required.
65751
65762
*/
65752
65763
SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){
65764
+ pPager->dbWal = db;
65753
65765
if( pagerUseWal(pPager) ){
65754
65766
sqlite3WalDb(pPager->pWal, db);
65755
65767
}
@@ -68923,7 +68935,6 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
68923
68935
rc = walIndexReadHdr(pWal, pChanged);
68924
68936
}
68925
68937
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
68926
- walDisableBlocking(pWal);
68927
68938
if( rc==SQLITE_BUSY_TIMEOUT ){
68928
68939
rc = SQLITE_BUSY;
68929
68940
*pCnt |= WAL_RETRY_BLOCKED_MASK;
@@ -68938,6 +68949,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
68938
68949
** WAL_RETRY this routine will be called again and will probably be
68939
68950
** right on the second iteration.
68940
68951
*/
68952
+ (void)walEnableBlocking(pWal);
68941
68953
if( pWal->apWiData[0]==0 ){
68942
68954
/* This branch is taken when the xShmMap() method returns SQLITE_BUSY.
68943
68955
** We assume this is a transient condition, so return WAL_RETRY. The
@@ -68954,6 +68966,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int *pCnt){
68954
68966
rc = SQLITE_BUSY_RECOVERY;
68955
68967
}
68956
68968
}
68969
+ walDisableBlocking(pWal);
68957
68970
if( rc!=SQLITE_OK ){
68958
68971
return rc;
68959
68972
}
@@ -75228,6 +75241,13 @@ static SQLITE_NOINLINE int btreeBeginTrans(
75228
75241
(void)sqlite3PagerWalWriteLock(pPager, 0);
75229
75242
unlockBtreeIfUnused(pBt);
75230
75243
}
75244
+ #if defined(SQLITE_ENABLE_SETLK_TIMEOUT)
75245
+ if( rc==SQLITE_BUSY_TIMEOUT ){
75246
+ /* If a blocking lock timed out, break out of the loop here so that
75247
+ ** the busy-handler is not invoked. */
75248
+ break;
75249
+ }
75250
+ #endif
75231
75251
}while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE &&
75232
75252
btreeInvokeBusyHandler(pBt) );
75233
75253
sqlite3PagerWalDb(pPager, 0);
@@ -105039,7 +105059,7 @@ SQLITE_PRIVATE int sqlite3VdbeSorterInit(
105039
105059
assert( pCsr->eCurType==CURTYPE_SORTER );
105040
105060
assert( sizeof(KeyInfo) + UMXV(pCsr->pKeyInfo->nKeyField)*sizeof(CollSeq*)
105041
105061
< 0x7fffffff );
105042
- szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField+1 );
105062
+ szKeyInfo = SZ_KEYINFO(pCsr->pKeyInfo->nKeyField);
105043
105063
sz = SZ_VDBESORTER(nWorker+1);
105044
105064
105045
105065
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -110389,7 +110409,9 @@ SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
110389
110409
pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
110390
110410
);
110391
110411
}
110392
- if( op==TK_VECTOR ){
110412
+ if( op==TK_VECTOR
110413
+ || (op==TK_FUNCTION && pExpr->affExpr==SQLITE_AFF_DEFER)
110414
+ ){
110393
110415
assert( ExprUseXList(pExpr) );
110394
110416
return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
110395
110417
}
@@ -110582,7 +110604,9 @@ SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
110582
110604
p = p->pLeft;
110583
110605
continue;
110584
110606
}
110585
- if( op==TK_VECTOR ){
110607
+ if( op==TK_VECTOR
110608
+ || (op==TK_FUNCTION && p->affExpr==SQLITE_AFF_DEFER)
110609
+ ){
110586
110610
assert( ExprUseXList(p) );
110587
110611
p = p->x.pList->a[0].pExpr;
110588
110612
continue;
@@ -145364,7 +145388,7 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
145364
145388
}
145365
145389
pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iLeftCol);
145366
145390
sqlite3SrcItemColumnUsed(&pSrc->a[iLeft], iLeftCol);
145367
- if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
145391
+ if( (pSrc->a[0].fg.jointype & JT_LTORJ)!=0 && pParse->nErr==0 ){
145368
145392
/* This branch runs if the query contains one or more RIGHT or FULL
145369
145393
** JOINs. If only a single table on the left side of this join
145370
145394
** contains the zName column, then this branch is a no-op.
@@ -145380,6 +145404,8 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
145380
145404
*/
145381
145405
ExprList *pFuncArgs = 0; /* Arguments to the coalesce() */
145382
145406
static const Token tkCoalesce = { "coalesce", 8 };
145407
+ assert( pE1!=0 );
145408
+ ExprSetProperty(pE1, EP_CanBeNull);
145383
145409
while( tableAndColumnIndex(pSrc, iLeft+1, i, zName, &iLeft, &iLeftCol,
145384
145410
pRight->fg.isSynthUsing)!=0 ){
145385
145411
if( pSrc->a[iLeft].fg.isUsing==0
@@ -145396,7 +145422,13 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
145396
145422
if( pFuncArgs ){
145397
145423
pFuncArgs = sqlite3ExprListAppend(pParse, pFuncArgs, pE1);
145398
145424
pE1 = sqlite3ExprFunction(pParse, pFuncArgs, &tkCoalesce, 0);
145425
+ if( pE1 ){
145426
+ pE1->affExpr = SQLITE_AFF_DEFER;
145427
+ }
145399
145428
}
145429
+ }else if( (pSrc->a[i+1].fg.jointype & JT_LEFT)!=0 && pParse->nErr==0 ){
145430
+ assert( pE1!=0 );
145431
+ ExprSetProperty(pE1, EP_CanBeNull);
145400
145432
}
145401
145433
pE2 = sqlite3CreateColumnExpr(db, pSrc, i+1, iRightCol);
145402
145434
sqlite3SrcItemColumnUsed(pRight, iRightCol);
@@ -149004,9 +149036,9 @@ static int compoundHasDifferentAffinities(Select *p){
149004
149036
** from 2015-02-09.)
149005
149037
**
149006
149038
** (3) If the subquery is the right operand of a LEFT JOIN then
149007
- ** (3a) the subquery may not be a join and
149008
- ** (3b) the FROM clause of the subquery may not contain a virtual
149009
- ** table and
149039
+ ** (3a) the subquery may not be a join
149040
+ ** (**) Was ( 3b): " the FROM clause of the subquery may not contain
149041
+ ** a virtual table"
149010
149042
** (**) Was: "The outer query may not have a GROUP BY." This case
149011
149043
** is now managed correctly
149012
149044
** (3d) the outer query may not be DISTINCT.
@@ -149222,7 +149254,7 @@ static int flattenSubquery(
149222
149254
*/
149223
149255
if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
149224
149256
if( pSubSrc->nSrc>1 /* (3a) */
149225
- || IsVirtual(pSubSrc->a[0].pSTab) /* (3b) */
149257
+ /**** || IsVirtual(pSubSrc->a[0].pSTab) (3b)-omitted */
149226
149258
|| (p->selFlags & SF_Distinct)!=0 /* (3d) */
149227
149259
|| (pSubitem->fg.jointype & JT_RIGHT)!=0 /* (26) */
149228
149260
){
@@ -161722,12 +161754,13 @@ SQLITE_PRIVATE Bitmask sqlite3WhereCodeOneLoopStart(
161722
161754
if( pLevel->iLeftJoin==0 ){
161723
161755
/* If a partial index is driving the loop, try to eliminate WHERE clause
161724
161756
** terms from the query that must be true due to the WHERE clause of
161725
- ** the partial index.
161757
+ ** the partial index. This optimization does not work on an outer join,
161758
+ ** as shown by:
161726
161759
**
161727
- ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work
161728
- ** for a LEFT JOIN.
161760
+ ** 2019-11-02 ticket 623eff57e76d45f6 (LEFT JOIN)
161761
+ ** 2025-05-29 forum post 7dee41d32506c4ae (RIGHT JOIN)
161729
161762
*/
161730
- if( pIdx->pPartIdxWhere ){
161763
+ if( pIdx->pPartIdxWhere && pLevel->pRJ==0 ){
161731
161764
whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
161732
161765
}
161733
161766
}else{
@@ -209021,8 +209054,10 @@ static int jsonBlobChangePayloadSize(
209021
209054
nExtra = 1;
209022
209055
}else if( szType==13 ){
209023
209056
nExtra = 2;
209024
- }else{
209057
+ }else if( szType==14 ) {
209025
209058
nExtra = 4;
209059
+ }else{
209060
+ nExtra = 8;
209026
209061
}
209027
209062
if( szPayload<=11 ){
209028
209063
nNeeded = 0;
@@ -213407,6 +213442,8 @@ SQLITE_PRIVATE int sqlite3JsonTableFunctions(sqlite3 *db){
213407
213442
#endif
213408
213443
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char*,int*); /* In the SQLite core */
213409
213444
213445
+ /* #include <stddef.h> */
213446
+
213410
213447
/*
213411
213448
** If building separately, we will need some setup that is normally
213412
213449
** found in sqliteInt.h
@@ -235449,6 +235486,7 @@ SQLITE_EXTENSION_INIT1
235449
235486
235450
235487
/* #include <string.h> */
235451
235488
/* #include <assert.h> */
235489
+ /* #include <stddef.h> */
235452
235490
235453
235491
#ifndef SQLITE_AMALGAMATION
235454
235492
@@ -257192,7 +257230,7 @@ static void fts5SourceIdFunc(
257192
257230
){
257193
257231
assert( nArg==0 );
257194
257232
UNUSED_PARAM2(nArg, apUnused);
257195
- sqlite3_result_text(pCtx, "fts5: 2025-05-29 14:26:00 dfc790f998f450d9c35e3ba1c8c89c17466cb559f87b0239e4aab9d34e28f742 ", -1, SQLITE_TRANSIENT);
257233
+ sqlite3_result_text(pCtx, "fts5: 2025-06-06 14:52:32 b77dc5e0f596d2140d9ac682b2893ff65d3a4140aa86067a3efebe29dc914c95 ", -1, SQLITE_TRANSIENT);
257196
257234
}
257197
257235
257198
257236
/*
0 commit comments