Fossil SCM

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

drh 2025-04-16 12:02 trunk
Commit d14a7803d77e8d0ba27c9e96f43d4a1e1789e2c3b2a5c28b230b77c5880f22e7
2 files changed +60 -20 +4 -3
+60 -20
--- 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
-** 20acd630b91609725794ce84f9eda01d5f3c with changes in files:
21
+** d22475b81c4e26ccc50f3b5626d43b32f7a2 with changes in files:
2222
**
2323
**
2424
*/
2525
#ifndef SQLITE_AMALGAMATION
2626
#define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465465
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466466
** [sqlite_version()] and [sqlite_source_id()].
467467
*/
468468
#define SQLITE_VERSION "3.50.0"
469469
#define SQLITE_VERSION_NUMBER 3050000
470
-#define SQLITE_SOURCE_ID "2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6"
470
+#define SQLITE_SOURCE_ID "2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5"
471471
472472
/*
473473
** CAPI3REF: Run-Time Library Version Numbers
474474
** KEYWORDS: sqlite3_version sqlite3_sourceid
475475
**
@@ -11946,12 +11946,13 @@
1194611946
** To clarify, if this function is called and then a changeset constructed
1194711947
** using [sqlite3session_changeset()], then after applying that changeset to
1194811948
** database zFrom the contents of the two compatible tables would be
1194911949
** identical.
1195011950
**
11951
-** It an error if database zFrom does not exist or does not contain the
11952
-** required compatible table.
11951
+** Unless the call to this function is a no-op as described above, it is an
11952
+** error if database zFrom does not exist or does not contain the required
11953
+** compatible table.
1195311954
**
1195411955
** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
1195511956
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
1195611957
** may be set to point to a buffer containing an English language error
1195711958
** message. It is the responsibility of the caller to free this buffer using
@@ -19162,10 +19163,11 @@
1916219163
unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
1916319164
unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
1916419165
unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */
1916519166
unsigned bNoQuery:1; /* Do not use this index to optimize queries */
1916619167
unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
19168
+ unsigned bIdxRowid:1; /* One or more of the index keys is the ROWID */
1916719169
unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
1916819170
unsigned bHasExpr:1; /* Index contains an expression, either a literal
1916919171
** expression, or a reference to a VIRTUAL column */
1917019172
#ifdef SQLITE_ENABLE_STAT4
1917119173
int nSample; /* Number of elements in aSample[] */
@@ -127237,10 +127239,11 @@
127237127239
}else{
127238127240
j = pCExpr->iColumn;
127239127241
assert( j<=0x7fff );
127240127242
if( j<0 ){
127241127243
j = pTab->iPKey;
127244
+ pIndex->bIdxRowid = 1;
127242127245
}else{
127243127246
if( pTab->aCol[j].notNull==0 ){
127244127247
pIndex->uniqNotNull = 0;
127245127248
}
127246127249
if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -149706,11 +149709,12 @@
149706149709
&& pE2->iColumn==pColumn->iColumn
149707149710
){
149708149711
return; /* Already present. Return without doing anything. */
149709149712
}
149710149713
}
149711
- if( sqlite3ExprAffinity(pColumn)==SQLITE_AFF_BLOB ){
149714
+ assert( SQLITE_AFF_NONE<SQLITE_AFF_BLOB );
149715
+ if( sqlite3ExprAffinity(pColumn)<=SQLITE_AFF_BLOB ){
149712149716
pConst->bHasAffBlob = 1;
149713149717
}
149714149718
149715149719
pConst->nConst++;
149716149720
pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
@@ -149781,11 +149785,12 @@
149781149785
for(i=0; i<pConst->nConst; i++){
149782149786
Expr *pColumn = pConst->apExpr[i*2];
149783149787
if( pColumn==pExpr ) continue;
149784149788
if( pColumn->iTable!=pExpr->iTable ) continue;
149785149789
if( pColumn->iColumn!=pExpr->iColumn ) continue;
149786
- if( bIgnoreAffBlob && sqlite3ExprAffinity(pColumn)==SQLITE_AFF_BLOB ){
149790
+ assert( SQLITE_AFF_NONE<SQLITE_AFF_BLOB );
149791
+ if( bIgnoreAffBlob && sqlite3ExprAffinity(pColumn)<=SQLITE_AFF_BLOB ){
149787149792
break;
149788149793
}
149789149794
/* A match is found. Add the EP_FixedCol property */
149790149795
pConst->nChng++;
149791149796
ExprClearProperty(pExpr, EP_Leaf);
@@ -152965,10 +152970,16 @@
152965152970
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
152966152971
p->pEList, p, wctrlFlags, p->nSelectRow);
152967152972
if( pWInfo==0 ) goto select_end;
152968152973
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
152969152974
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
152975
+ if( pDest->eDest<=SRT_DistQueue && pDest->eDest>=SRT_DistFifo ){
152976
+ /* TUNING: For a UNION CTE, because UNION is implies DISTINCT,
152977
+ ** reduce the estimated output row count by 8 (LogEst 30).
152978
+ ** Search for tag-20250414a to see other cases */
152979
+ p->nSelectRow -= 30;
152980
+ }
152970152981
}
152971152982
if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
152972152983
sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
152973152984
}
152974152985
if( sSort.pOrderBy ){
@@ -160131,11 +160142,11 @@
160131160142
160132160143
160133160144
/*
160134160145
** pX is an expression of the form: (vector) IN (SELECT ...)
160135160146
** In other words, it is a vector IN operator with a SELECT clause on the
160136
-** LHS. But not all terms in the vector are indexable and the terms might
160147
+** RHS. But not all terms in the vector are indexable and the terms might
160137160148
** not be in the correct order for indexing.
160138160149
**
160139160150
** This routine makes a copy of the input pX expression and then adjusts
160140160151
** the vector on the LHS with corresponding changes to the SELECT so that
160141160152
** the vector contains only index terms and those terms are in the correct
@@ -167926,11 +167937,11 @@
167926167937
}
167927167938
167928167939
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167929167940
&& pNew->u.btree.nEq<pProbe->nColumn
167930167941
&& (pNew->u.btree.nEq<pProbe->nKeyCol ||
167931
- pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
167942
+ (pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY && !pProbe->bIdxRowid))
167932167943
){
167933167944
if( pNew->u.btree.nEq>3 ){
167934167945
sqlite3ProgressCheck(pParse);
167935167946
}
167936167947
whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -171384,11 +171395,12 @@
171384171395
wherePathSolver(pWInfo, pWInfo->nRowOut<0 ? 1 : pWInfo->nRowOut+1);
171385171396
if( db->mallocFailed ) goto whereBeginError;
171386171397
}
171387171398
171388171399
/* TUNING: Assume that a DISTINCT clause on a subquery reduces
171389
- ** the output size by a factor of 8 (LogEst -30).
171400
+ ** the output size by a factor of 8 (LogEst -30). Search for
171401
+ ** tag-20250414a to see other cases.
171390171402
*/
171391171403
if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
171392171404
WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
171393171405
pWInfo->nRowOut, pWInfo->nRowOut-30));
171394171406
pWInfo->nRowOut -= 30;
@@ -206261,20 +206273,20 @@
206261206273
case FTS3_MATCHINFO_LCS:
206262206274
nVal = pInfo->nCol;
206263206275
break;
206264206276
206265206277
case FTS3_MATCHINFO_LHITS:
206266
- nVal = pInfo->nCol * pInfo->nPhrase;
206278
+ nVal = (size_t)pInfo->nCol * pInfo->nPhrase;
206267206279
break;
206268206280
206269206281
case FTS3_MATCHINFO_LHITS_BM:
206270
- nVal = pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
206282
+ nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
206271206283
break;
206272206284
206273206285
default:
206274206286
assert( cArg==FTS3_MATCHINFO_HITS );
206275
- nVal = pInfo->nCol * pInfo->nPhrase * 3;
206287
+ nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3;
206276206288
break;
206277206289
}
206278206290
206279206291
return nVal;
206280206292
}
@@ -229245,10 +229257,12 @@
229245229257
int rc = SQLITE_OK;
229246229258
229247229259
if( pTab->nCol==0 ){
229248229260
u8 *abPK;
229249229261
assert( pTab->azCol==0 || pTab->abPK==0 );
229262
+ sqlite3_free(pTab->azCol);
229263
+ pTab->abPK = 0;
229250229264
rc = sessionTableInfo(pSession, db, zDb,
229251229265
pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
229252229266
&pTab->azDflt, &pTab->aiIdx, &abPK,
229253229267
((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
229254229268
);
@@ -230265,21 +230279,47 @@
230265230279
230266230280
/* Check the table schemas match */
230267230281
if( rc==SQLITE_OK ){
230268230282
int bHasPk = 0;
230269230283
int bMismatch = 0;
230270
- int nCol; /* Columns in zFrom.zTbl */
230284
+ int nCol = 0; /* Columns in zFrom.zTbl */
230271230285
int bRowid = 0;
230272
- u8 *abPK;
230286
+ u8 *abPK = 0;
230273230287
const char **azCol = 0;
230274
- rc = sessionTableInfo(0, db, zFrom, zTbl,
230275
- &nCol, 0, 0, &azCol, 0, 0, &abPK,
230276
- pSession->bImplicitPK ? &bRowid : 0
230277
- );
230288
+ char *zDbExists = 0;
230289
+
230290
+ /* Check that database zFrom is attached. */
230291
+ zDbExists = sqlite3_mprintf("SELECT * FROM %Q.sqlite_schema", zFrom);
230292
+ if( zDbExists==0 ){
230293
+ rc = SQLITE_NOMEM;
230294
+ }else{
230295
+ sqlite3_stmt *pDbExists = 0;
230296
+ rc = sqlite3_prepare_v2(db, zDbExists, -1, &pDbExists, 0);
230297
+ if( rc==SQLITE_ERROR ){
230298
+ rc = SQLITE_OK;
230299
+ nCol = -1;
230300
+ }
230301
+ sqlite3_finalize(pDbExists);
230302
+ sqlite3_free(zDbExists);
230303
+ }
230304
+
230305
+ if( rc==SQLITE_OK && nCol==0 ){
230306
+ rc = sessionTableInfo(0, db, zFrom, zTbl,
230307
+ &nCol, 0, 0, &azCol, 0, 0, &abPK,
230308
+ pSession->bImplicitPK ? &bRowid : 0
230309
+ );
230310
+ }
230278230311
if( rc==SQLITE_OK ){
230279230312
if( pTo->nCol!=nCol ){
230280
- bMismatch = 1;
230313
+ if( nCol<=0 ){
230314
+ rc = SQLITE_SCHEMA;
230315
+ if( pzErrMsg ){
230316
+ *pzErrMsg = sqlite3_mprintf("no such table: %s.%s", zFrom, zTbl);
230317
+ }
230318
+ }else{
230319
+ bMismatch = 1;
230320
+ }
230281230321
}else{
230282230322
int i;
230283230323
for(i=0; i<nCol; i++){
230284230324
if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
230285230325
if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
@@ -257173,11 +257213,11 @@
257173257213
int nArg, /* Number of args */
257174257214
sqlite3_value **apUnused /* Function arguments */
257175257215
){
257176257216
assert( nArg==0 );
257177257217
UNUSED_PARAM2(nArg, apUnused);
257178
- sqlite3_result_text(pCtx, "fts5: 2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6", -1, SQLITE_TRANSIENT);
257218
+ sqlite3_result_text(pCtx, "fts5: 2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5", -1, SQLITE_TRANSIENT);
257179257219
}
257180257220
257181257221
/*
257182257222
** Implementation of fts5_locale(LOCALE, TEXT) function.
257183257223
**
257184257224
--- 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 ** 20acd630b91609725794ce84f9eda01d5f3c with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.50.0"
469 #define SQLITE_VERSION_NUMBER 3050000
470 #define SQLITE_SOURCE_ID "2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -11946,12 +11946,13 @@
11946 ** To clarify, if this function is called and then a changeset constructed
11947 ** using [sqlite3session_changeset()], then after applying that changeset to
11948 ** database zFrom the contents of the two compatible tables would be
11949 ** identical.
11950 **
11951 ** It an error if database zFrom does not exist or does not contain the
11952 ** required compatible table.
 
11953 **
11954 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11955 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11956 ** may be set to point to a buffer containing an English language error
11957 ** message. It is the responsibility of the caller to free this buffer using
@@ -19162,10 +19163,11 @@
19162 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
19163 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
19164 unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */
19165 unsigned bNoQuery:1; /* Do not use this index to optimize queries */
19166 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
 
19167 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
19168 unsigned bHasExpr:1; /* Index contains an expression, either a literal
19169 ** expression, or a reference to a VIRTUAL column */
19170 #ifdef SQLITE_ENABLE_STAT4
19171 int nSample; /* Number of elements in aSample[] */
@@ -127237,10 +127239,11 @@
127237 }else{
127238 j = pCExpr->iColumn;
127239 assert( j<=0x7fff );
127240 if( j<0 ){
127241 j = pTab->iPKey;
 
127242 }else{
127243 if( pTab->aCol[j].notNull==0 ){
127244 pIndex->uniqNotNull = 0;
127245 }
127246 if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -149706,11 +149709,12 @@
149706 && pE2->iColumn==pColumn->iColumn
149707 ){
149708 return; /* Already present. Return without doing anything. */
149709 }
149710 }
149711 if( sqlite3ExprAffinity(pColumn)==SQLITE_AFF_BLOB ){
 
149712 pConst->bHasAffBlob = 1;
149713 }
149714
149715 pConst->nConst++;
149716 pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
@@ -149781,11 +149785,12 @@
149781 for(i=0; i<pConst->nConst; i++){
149782 Expr *pColumn = pConst->apExpr[i*2];
149783 if( pColumn==pExpr ) continue;
149784 if( pColumn->iTable!=pExpr->iTable ) continue;
149785 if( pColumn->iColumn!=pExpr->iColumn ) continue;
149786 if( bIgnoreAffBlob && sqlite3ExprAffinity(pColumn)==SQLITE_AFF_BLOB ){
 
149787 break;
149788 }
149789 /* A match is found. Add the EP_FixedCol property */
149790 pConst->nChng++;
149791 ExprClearProperty(pExpr, EP_Leaf);
@@ -152965,10 +152970,16 @@
152965 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
152966 p->pEList, p, wctrlFlags, p->nSelectRow);
152967 if( pWInfo==0 ) goto select_end;
152968 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
152969 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
 
 
 
 
 
 
152970 }
152971 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
152972 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
152973 }
152974 if( sSort.pOrderBy ){
@@ -160131,11 +160142,11 @@
160131
160132
160133 /*
160134 ** pX is an expression of the form: (vector) IN (SELECT ...)
160135 ** In other words, it is a vector IN operator with a SELECT clause on the
160136 ** LHS. But not all terms in the vector are indexable and the terms might
160137 ** not be in the correct order for indexing.
160138 **
160139 ** This routine makes a copy of the input pX expression and then adjusts
160140 ** the vector on the LHS with corresponding changes to the SELECT so that
160141 ** the vector contains only index terms and those terms are in the correct
@@ -167926,11 +167937,11 @@
167926 }
167927
167928 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167929 && pNew->u.btree.nEq<pProbe->nColumn
167930 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
167931 pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY)
167932 ){
167933 if( pNew->u.btree.nEq>3 ){
167934 sqlite3ProgressCheck(pParse);
167935 }
167936 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -171384,11 +171395,12 @@
171384 wherePathSolver(pWInfo, pWInfo->nRowOut<0 ? 1 : pWInfo->nRowOut+1);
171385 if( db->mallocFailed ) goto whereBeginError;
171386 }
171387
171388 /* TUNING: Assume that a DISTINCT clause on a subquery reduces
171389 ** the output size by a factor of 8 (LogEst -30).
 
171390 */
171391 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
171392 WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
171393 pWInfo->nRowOut, pWInfo->nRowOut-30));
171394 pWInfo->nRowOut -= 30;
@@ -206261,20 +206273,20 @@
206261 case FTS3_MATCHINFO_LCS:
206262 nVal = pInfo->nCol;
206263 break;
206264
206265 case FTS3_MATCHINFO_LHITS:
206266 nVal = pInfo->nCol * pInfo->nPhrase;
206267 break;
206268
206269 case FTS3_MATCHINFO_LHITS_BM:
206270 nVal = pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
206271 break;
206272
206273 default:
206274 assert( cArg==FTS3_MATCHINFO_HITS );
206275 nVal = pInfo->nCol * pInfo->nPhrase * 3;
206276 break;
206277 }
206278
206279 return nVal;
206280 }
@@ -229245,10 +229257,12 @@
229245 int rc = SQLITE_OK;
229246
229247 if( pTab->nCol==0 ){
229248 u8 *abPK;
229249 assert( pTab->azCol==0 || pTab->abPK==0 );
 
 
229250 rc = sessionTableInfo(pSession, db, zDb,
229251 pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
229252 &pTab->azDflt, &pTab->aiIdx, &abPK,
229253 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
229254 );
@@ -230265,21 +230279,47 @@
230265
230266 /* Check the table schemas match */
230267 if( rc==SQLITE_OK ){
230268 int bHasPk = 0;
230269 int bMismatch = 0;
230270 int nCol; /* Columns in zFrom.zTbl */
230271 int bRowid = 0;
230272 u8 *abPK;
230273 const char **azCol = 0;
230274 rc = sessionTableInfo(0, db, zFrom, zTbl,
230275 &nCol, 0, 0, &azCol, 0, 0, &abPK,
230276 pSession->bImplicitPK ? &bRowid : 0
230277 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230278 if( rc==SQLITE_OK ){
230279 if( pTo->nCol!=nCol ){
230280 bMismatch = 1;
 
 
 
 
 
 
 
230281 }else{
230282 int i;
230283 for(i=0; i<nCol; i++){
230284 if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
230285 if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
@@ -257173,11 +257213,11 @@
257173 int nArg, /* Number of args */
257174 sqlite3_value **apUnused /* Function arguments */
257175 ){
257176 assert( nArg==0 );
257177 UNUSED_PARAM2(nArg, apUnused);
257178 sqlite3_result_text(pCtx, "fts5: 2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6", -1, SQLITE_TRANSIENT);
257179 }
257180
257181 /*
257182 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257183 **
257184
--- 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 ** d22475b81c4e26ccc50f3b5626d43b32f7a2 with changes in files:
22 **
23 **
24 */
25 #ifndef SQLITE_AMALGAMATION
26 #define SQLITE_CORE 1
@@ -465,11 +465,11 @@
465 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
466 ** [sqlite_version()] and [sqlite_source_id()].
467 */
468 #define SQLITE_VERSION "3.50.0"
469 #define SQLITE_VERSION_NUMBER 3050000
470 #define SQLITE_SOURCE_ID "2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5"
471
472 /*
473 ** CAPI3REF: Run-Time Library Version Numbers
474 ** KEYWORDS: sqlite3_version sqlite3_sourceid
475 **
@@ -11946,12 +11946,13 @@
11946 ** To clarify, if this function is called and then a changeset constructed
11947 ** using [sqlite3session_changeset()], then after applying that changeset to
11948 ** database zFrom the contents of the two compatible tables would be
11949 ** identical.
11950 **
11951 ** Unless the call to this function is a no-op as described above, it is an
11952 ** error if database zFrom does not exist or does not contain the required
11953 ** compatible table.
11954 **
11955 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11956 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11957 ** may be set to point to a buffer containing an English language error
11958 ** message. It is the responsibility of the caller to free this buffer using
@@ -19162,10 +19163,11 @@
19163 unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
19164 unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
19165 unsigned bLowQual:1; /* sqlite_stat1 says this is a low-quality index */
19166 unsigned bNoQuery:1; /* Do not use this index to optimize queries */
19167 unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
19168 unsigned bIdxRowid:1; /* One or more of the index keys is the ROWID */
19169 unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
19170 unsigned bHasExpr:1; /* Index contains an expression, either a literal
19171 ** expression, or a reference to a VIRTUAL column */
19172 #ifdef SQLITE_ENABLE_STAT4
19173 int nSample; /* Number of elements in aSample[] */
@@ -127237,10 +127239,11 @@
127239 }else{
127240 j = pCExpr->iColumn;
127241 assert( j<=0x7fff );
127242 if( j<0 ){
127243 j = pTab->iPKey;
127244 pIndex->bIdxRowid = 1;
127245 }else{
127246 if( pTab->aCol[j].notNull==0 ){
127247 pIndex->uniqNotNull = 0;
127248 }
127249 if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
@@ -149706,11 +149709,12 @@
149709 && pE2->iColumn==pColumn->iColumn
149710 ){
149711 return; /* Already present. Return without doing anything. */
149712 }
149713 }
149714 assert( SQLITE_AFF_NONE<SQLITE_AFF_BLOB );
149715 if( sqlite3ExprAffinity(pColumn)<=SQLITE_AFF_BLOB ){
149716 pConst->bHasAffBlob = 1;
149717 }
149718
149719 pConst->nConst++;
149720 pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
@@ -149781,11 +149785,12 @@
149785 for(i=0; i<pConst->nConst; i++){
149786 Expr *pColumn = pConst->apExpr[i*2];
149787 if( pColumn==pExpr ) continue;
149788 if( pColumn->iTable!=pExpr->iTable ) continue;
149789 if( pColumn->iColumn!=pExpr->iColumn ) continue;
149790 assert( SQLITE_AFF_NONE<SQLITE_AFF_BLOB );
149791 if( bIgnoreAffBlob && sqlite3ExprAffinity(pColumn)<=SQLITE_AFF_BLOB ){
149792 break;
149793 }
149794 /* A match is found. Add the EP_FixedCol property */
149795 pConst->nChng++;
149796 ExprClearProperty(pExpr, EP_Leaf);
@@ -152965,10 +152970,16 @@
152970 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
152971 p->pEList, p, wctrlFlags, p->nSelectRow);
152972 if( pWInfo==0 ) goto select_end;
152973 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
152974 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
152975 if( pDest->eDest<=SRT_DistQueue && pDest->eDest>=SRT_DistFifo ){
152976 /* TUNING: For a UNION CTE, because UNION is implies DISTINCT,
152977 ** reduce the estimated output row count by 8 (LogEst 30).
152978 ** Search for tag-20250414a to see other cases */
152979 p->nSelectRow -= 30;
152980 }
152981 }
152982 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
152983 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
152984 }
152985 if( sSort.pOrderBy ){
@@ -160131,11 +160142,11 @@
160142
160143
160144 /*
160145 ** pX is an expression of the form: (vector) IN (SELECT ...)
160146 ** In other words, it is a vector IN operator with a SELECT clause on the
160147 ** RHS. But not all terms in the vector are indexable and the terms might
160148 ** not be in the correct order for indexing.
160149 **
160150 ** This routine makes a copy of the input pX expression and then adjusts
160151 ** the vector on the LHS with corresponding changes to the SELECT so that
160152 ** the vector contains only index terms and those terms are in the correct
@@ -167926,11 +167937,11 @@
167937 }
167938
167939 if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
167940 && pNew->u.btree.nEq<pProbe->nColumn
167941 && (pNew->u.btree.nEq<pProbe->nKeyCol ||
167942 (pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY && !pProbe->bIdxRowid))
167943 ){
167944 if( pNew->u.btree.nEq>3 ){
167945 sqlite3ProgressCheck(pParse);
167946 }
167947 whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn);
@@ -171384,11 +171395,12 @@
171395 wherePathSolver(pWInfo, pWInfo->nRowOut<0 ? 1 : pWInfo->nRowOut+1);
171396 if( db->mallocFailed ) goto whereBeginError;
171397 }
171398
171399 /* TUNING: Assume that a DISTINCT clause on a subquery reduces
171400 ** the output size by a factor of 8 (LogEst -30). Search for
171401 ** tag-20250414a to see other cases.
171402 */
171403 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
171404 WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",
171405 pWInfo->nRowOut, pWInfo->nRowOut-30));
171406 pWInfo->nRowOut -= 30;
@@ -206261,20 +206273,20 @@
206273 case FTS3_MATCHINFO_LCS:
206274 nVal = pInfo->nCol;
206275 break;
206276
206277 case FTS3_MATCHINFO_LHITS:
206278 nVal = (size_t)pInfo->nCol * pInfo->nPhrase;
206279 break;
206280
206281 case FTS3_MATCHINFO_LHITS_BM:
206282 nVal = (size_t)pInfo->nPhrase * ((pInfo->nCol + 31) / 32);
206283 break;
206284
206285 default:
206286 assert( cArg==FTS3_MATCHINFO_HITS );
206287 nVal = (size_t)pInfo->nCol * pInfo->nPhrase * 3;
206288 break;
206289 }
206290
206291 return nVal;
206292 }
@@ -229245,10 +229257,12 @@
229257 int rc = SQLITE_OK;
229258
229259 if( pTab->nCol==0 ){
229260 u8 *abPK;
229261 assert( pTab->azCol==0 || pTab->abPK==0 );
229262 sqlite3_free(pTab->azCol);
229263 pTab->abPK = 0;
229264 rc = sessionTableInfo(pSession, db, zDb,
229265 pTab->zName, &pTab->nCol, &pTab->nTotalCol, 0, &pTab->azCol,
229266 &pTab->azDflt, &pTab->aiIdx, &abPK,
229267 ((pSession==0 || pSession->bImplicitPK) ? &pTab->bRowid : 0)
229268 );
@@ -230265,21 +230279,47 @@
230279
230280 /* Check the table schemas match */
230281 if( rc==SQLITE_OK ){
230282 int bHasPk = 0;
230283 int bMismatch = 0;
230284 int nCol = 0; /* Columns in zFrom.zTbl */
230285 int bRowid = 0;
230286 u8 *abPK = 0;
230287 const char **azCol = 0;
230288 char *zDbExists = 0;
230289
230290 /* Check that database zFrom is attached. */
230291 zDbExists = sqlite3_mprintf("SELECT * FROM %Q.sqlite_schema", zFrom);
230292 if( zDbExists==0 ){
230293 rc = SQLITE_NOMEM;
230294 }else{
230295 sqlite3_stmt *pDbExists = 0;
230296 rc = sqlite3_prepare_v2(db, zDbExists, -1, &pDbExists, 0);
230297 if( rc==SQLITE_ERROR ){
230298 rc = SQLITE_OK;
230299 nCol = -1;
230300 }
230301 sqlite3_finalize(pDbExists);
230302 sqlite3_free(zDbExists);
230303 }
230304
230305 if( rc==SQLITE_OK && nCol==0 ){
230306 rc = sessionTableInfo(0, db, zFrom, zTbl,
230307 &nCol, 0, 0, &azCol, 0, 0, &abPK,
230308 pSession->bImplicitPK ? &bRowid : 0
230309 );
230310 }
230311 if( rc==SQLITE_OK ){
230312 if( pTo->nCol!=nCol ){
230313 if( nCol<=0 ){
230314 rc = SQLITE_SCHEMA;
230315 if( pzErrMsg ){
230316 *pzErrMsg = sqlite3_mprintf("no such table: %s.%s", zFrom, zTbl);
230317 }
230318 }else{
230319 bMismatch = 1;
230320 }
230321 }else{
230322 int i;
230323 for(i=0; i<nCol; i++){
230324 if( pTo->abPK[i]!=abPK[i] ) bMismatch = 1;
230325 if( sqlite3_stricmp(azCol[i], pTo->azCol[i]) ) bMismatch = 1;
@@ -257173,11 +257213,11 @@
257213 int nArg, /* Number of args */
257214 sqlite3_value **apUnused /* Function arguments */
257215 ){
257216 assert( nArg==0 );
257217 UNUSED_PARAM2(nArg, apUnused);
257218 sqlite3_result_text(pCtx, "fts5: 2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5", -1, SQLITE_TRANSIENT);
257219 }
257220
257221 /*
257222 ** Implementation of fts5_locale(LOCALE, TEXT) function.
257223 **
257224
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.50.0"
150150
#define SQLITE_VERSION_NUMBER 3050000
151
-#define SQLITE_SOURCE_ID "2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6"
151
+#define SQLITE_SOURCE_ID "2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -11627,12 +11627,13 @@
1162711627
** To clarify, if this function is called and then a changeset constructed
1162811628
** using [sqlite3session_changeset()], then after applying that changeset to
1162911629
** database zFrom the contents of the two compatible tables would be
1163011630
** identical.
1163111631
**
11632
-** It an error if database zFrom does not exist or does not contain the
11633
-** required compatible table.
11632
+** Unless the call to this function is a no-op as described above, it is an
11633
+** error if database zFrom does not exist or does not contain the required
11634
+** compatible table.
1163411635
**
1163511636
** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
1163611637
** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
1163711638
** may be set to point to a buffer containing an English language error
1163811639
** message. It is the responsibility of the caller to free this buffer using
1163911640
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-04-10 10:18:07 20acd630b91609725794ce84f9eda01d5f3c898407f0948264830851d25ccaa6"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -11627,12 +11627,13 @@
11627 ** To clarify, if this function is called and then a changeset constructed
11628 ** using [sqlite3session_changeset()], then after applying that changeset to
11629 ** database zFrom the contents of the two compatible tables would be
11630 ** identical.
11631 **
11632 ** It an error if database zFrom does not exist or does not contain the
11633 ** required compatible table.
 
11634 **
11635 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11636 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11637 ** may be set to point to a buffer containing an English language error
11638 ** message. It is the responsibility of the caller to free this buffer using
11639
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.50.0"
150 #define SQLITE_VERSION_NUMBER 3050000
151 #define SQLITE_SOURCE_ID "2025-04-15 21:59:38 d22475b81c4e26ccc50f3b5626d43b32f7a2de34e5a764539554665bdda735d5"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -11627,12 +11627,13 @@
11627 ** To clarify, if this function is called and then a changeset constructed
11628 ** using [sqlite3session_changeset()], then after applying that changeset to
11629 ** database zFrom the contents of the two compatible tables would be
11630 ** identical.
11631 **
11632 ** Unless the call to this function is a no-op as described above, it is an
11633 ** error if database zFrom does not exist or does not contain the required
11634 ** compatible table.
11635 **
11636 ** If the operation is successful, SQLITE_OK is returned. Otherwise, an SQLite
11637 ** error code. In this case, if argument pzErrMsg is not NULL, *pzErrMsg
11638 ** may be set to point to a buffer containing an English language error
11639 ** message. It is the responsibility of the caller to free this buffer using
11640

Keyboard Shortcuts

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