11/******************************************************************************
22** This file is an amalgamation of many separate C source files from SQLite
3- ** version 3.43.0 . By combining all the individual C code files into this
3+ ** version 3.43.1 . By combining all the individual C code files into this
44** single large file, the entire code can be compiled as a single translation
55** unit. This allows many compilers to do optimizations that would not be
66** possible if the files were compiled separately. Performance improvements
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- ** f80b798b3f4b81a7bb4233c58294edd0f11 .
21+ ** d3a40c05c49e1a49264912b1a05bc2143ac .
2222*/
2323#define SQLITE_CORE 1
2424#define SQLITE_AMALGAMATION 1
@@ -459,9 +459,9 @@ extern "C" {
459459** [sqlite3_libversion_number()], [sqlite3_sourceid()],
460460** [sqlite_version()] and [sqlite_source_id()].
461461*/
462- #define SQLITE_VERSION "3.43.0 "
463- #define SQLITE_VERSION_NUMBER 3043000
464- #define SQLITE_SOURCE_ID "2023-08-24 12:36:59 0f80b798b3f4b81a7bb4233c58294edd0f1156f36b6ecf5ab8e83631d468778c "
462+ #define SQLITE_VERSION "3.43.1 "
463+ #define SQLITE_VERSION_NUMBER 3043001
464+ #define SQLITE_SOURCE_ID "2023-09-11 12:01:27 2d3a40c05c49e1a49264912b1a05bc2143ac0e7c3df588276ce80a4cbc9bd1b0 "
465465
466466/*
467467** CAPI3REF: Run-Time Library Version Numbers
@@ -128461,8 +128461,10 @@ static void sumFinalize(sqlite3_context *context){
128461128461 if( p->approx ){
128462128462 if( p->ovrfl ){
128463128463 sqlite3_result_error(context,"integer overflow",-1);
128464- }else{
128464+ }else if( !sqlite3IsNaN(p->rErr) ) {
128465128465 sqlite3_result_double(context, p->rSum+p->rErr);
128466+ }else{
128467+ sqlite3_result_double(context, p->rSum);
128466128468 }
128467128469 }else{
128468128470 sqlite3_result_int64(context, p->iSum);
@@ -128475,7 +128477,8 @@ static void avgFinalize(sqlite3_context *context){
128475128477 if( p && p->cnt>0 ){
128476128478 double r;
128477128479 if( p->approx ){
128478- r = p->rSum+p->rErr;
128480+ r = p->rSum;
128481+ if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
128479128482 }else{
128480128483 r = (double)(p->iSum);
128481128484 }
@@ -128488,7 +128491,8 @@ static void totalFinalize(sqlite3_context *context){
128488128491 p = sqlite3_aggregate_context(context, 0);
128489128492 if( p ){
128490128493 if( p->approx ){
128491- r = p->rSum+p->rErr;
128494+ r = p->rSum;
128495+ if( !sqlite3IsNaN(p->rErr) ) r += p->rErr;
128492128496 }else{
128493128497 r = (double)(p->iSum);
128494128498 }
@@ -145691,12 +145695,12 @@ static int disableUnusedSubqueryResultColumns(SrcItem *pItem){
145691145695 assert( pItem->pSelect!=0 );
145692145696 pSub = pItem->pSelect;
145693145697 assert( pSub->pEList->nExpr==pTab->nCol );
145694- if( (pSub->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){
145695- testcase( pSub->selFlags & SF_Distinct );
145696- testcase( pSub->selFlags & SF_Aggregate );
145697- return 0;
145698- }
145699145698 for(pX=pSub; pX; pX=pX->pPrior){
145699+ if( (pX->selFlags & (SF_Distinct|SF_Aggregate))!=0 ){
145700+ testcase( pX->selFlags & SF_Distinct );
145701+ testcase( pX->selFlags & SF_Aggregate );
145702+ return 0;
145703+ }
145700145704 if( pX->pPrior && pX->op!=TK_ALL ){
145701145705 /* This optimization does not work for compound subqueries that
145702145706 ** use UNION, INTERSECT, or EXCEPT. Only UNION ALL is allowed. */
@@ -198084,7 +198088,7 @@ static u64 fts3ChecksumIndex(
198084198088 int rc;
198085198089 u64 cksum = 0;
198086198090
198087- assert ( *pRc==SQLITE_OK ) ;
198091+ if ( *pRc ) return 0 ;
198088198092
198089198093 memset(&filter, 0, sizeof(filter));
198090198094 memset(&csr, 0, sizeof(csr));
@@ -203714,7 +203718,9 @@ static void jsonArrayLengthFunc(
203714203718 }
203715203719 if( pNode->eType==JSON_ARRAY ){
203716203720 while( 1 /*exit-by-break*/ ){
203717- for(i=1; i<=pNode->n; n++){
203721+ i = 1;
203722+ while( i<=pNode->n ){
203723+ if( (pNode[i].jnFlags & JNODE_REMOVE)==0 ) n++;
203718203724 i += jsonNodeSize(&pNode[i]);
203719203725 }
203720203726 if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
@@ -222986,15 +222992,19 @@ static int sessionReadRecord(
222986222992 }
222987222993 }
222988222994 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
222989- sqlite3_int64 v = sessionGetI64(aVal);
222990- if( eType==SQLITE_INTEGER ){
222991- sqlite3VdbeMemSetInt64(apOut[i], v);
222995+ if( (pIn->nData-pIn->iNext)<8 ){
222996+ rc = SQLITE_CORRUPT_BKPT;
222992222997 }else{
222993- double d;
222994- memcpy(&d, &v, 8);
222995- sqlite3VdbeMemSetDouble(apOut[i], d);
222998+ sqlite3_int64 v = sessionGetI64(aVal);
222999+ if( eType==SQLITE_INTEGER ){
223000+ sqlite3VdbeMemSetInt64(apOut[i], v);
223001+ }else{
223002+ double d;
223003+ memcpy(&d, &v, 8);
223004+ sqlite3VdbeMemSetDouble(apOut[i], d);
223005+ }
223006+ pIn->iNext += 8;
222996223007 }
222997- pIn->iNext += 8;
222998223008 }
222999223009 }
223000223010 }
@@ -239820,80 +239830,79 @@ static void fts5DoSecureDelete(
239820239830 }
239821239831 }
239822239832 }else if( iStart==4 ){
239823- int iPgno;
239824-
239825- assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
239826- /* The entry being removed may be the only position list in
239827- ** its doclist. */
239828- for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
239829- Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
239830- int bEmpty = (pPg && pPg->nn==4);
239831- fts5DataRelease(pPg);
239832- if( bEmpty==0 ) break;
239833- }
239834-
239835- if( iPgno==pSeg->iTermLeafPgno ){
239836- i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
239837- Fts5Data *pTerm = fts5DataRead(p, iId);
239838- if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
239839- u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
239840- int nTermIdx = pTerm->nn - pTerm->szLeaf;
239841- int iTermIdx = 0;
239842- int iTermOff = 0;
239843-
239844- while( 1 ){
239845- u32 iVal = 0;
239846- int nByte = fts5GetVarint32(&aTermIdx[iTermIdx], iVal);
239847- iTermOff += iVal;
239848- if( (iTermIdx+nByte)>=nTermIdx ) break;
239849- iTermIdx += nByte;
239850- }
239851- nTermIdx = iTermIdx;
239833+ int iPgno;
239834+
239835+ assert_nc( pSeg->iLeafPgno>pSeg->iTermLeafPgno );
239836+ /* The entry being removed may be the only position list in
239837+ ** its doclist. */
239838+ for(iPgno=pSeg->iLeafPgno-1; iPgno>pSeg->iTermLeafPgno; iPgno-- ){
239839+ Fts5Data *pPg = fts5DataRead(p, FTS5_SEGMENT_ROWID(iSegid, iPgno));
239840+ int bEmpty = (pPg && pPg->nn==4);
239841+ fts5DataRelease(pPg);
239842+ if( bEmpty==0 ) break;
239843+ }
239852239844
239853- memmove(&pTerm->p[iTermOff], &pTerm->p[pTerm->szLeaf], nTermIdx);
239854- fts5PutU16(&pTerm->p[2], iTermOff);
239845+ if( iPgno==pSeg->iTermLeafPgno ){
239846+ i64 iId = FTS5_SEGMENT_ROWID(iSegid, pSeg->iTermLeafPgno);
239847+ Fts5Data *pTerm = fts5DataRead(p, iId);
239848+ if( pTerm && pTerm->szLeaf==pSeg->iTermLeafOffset ){
239849+ u8 *aTermIdx = &pTerm->p[pTerm->szLeaf];
239850+ int nTermIdx = pTerm->nn - pTerm->szLeaf;
239851+ int iTermIdx = 0;
239852+ int iTermOff = 0;
239855239853
239856- fts5DataWrite(p, iId, pTerm->p, iTermOff+nTermIdx);
239857- if( nTermIdx==0 ){
239858- fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iTermLeafPgno);
239859- }
239854+ while( 1 ){
239855+ u32 iVal = 0;
239856+ int nByte = fts5GetVarint32(&aTermIdx[iTermIdx], iVal);
239857+ iTermOff += iVal;
239858+ if( (iTermIdx+nByte)>=nTermIdx ) break;
239859+ iTermIdx += nByte;
239860239860 }
239861- fts5DataRelease(pTerm);
239862- }
239863- }
239861+ nTermIdx = iTermIdx;
239864239862
239865- if( p->rc==SQLITE_OK ){
239866- const int nMove = nPg - iNextOff;
239867- int nShift = 0;
239868-
239869- memmove(&aPg[iOff], &aPg[iNextOff], nMove);
239870- iPgIdx -= (iNextOff - iOff);
239871- nPg = iPgIdx;
239872- fts5PutU16(&aPg[2], iPgIdx);
239873-
239874- nShift = iNextOff - iOff;
239875- for(iIdx=0, iKeyOff=0, iPrevKeyOff=0; iIdx<nIdx; /* no-op */){
239876- u32 iVal = 0;
239877- iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
239878- iKeyOff += iVal;
239879- if( iKeyOff!=iDelKeyOff ){
239880- if( iKeyOff>iOff ){
239881- iKeyOff -= nShift;
239882- nShift = 0;
239883- }
239884- nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOff - iPrevKeyOff);
239885- iPrevKeyOff = iKeyOff;
239863+ memmove(&pTerm->p[iTermOff], &pTerm->p[pTerm->szLeaf], nTermIdx);
239864+ fts5PutU16(&pTerm->p[2], iTermOff);
239865+
239866+ fts5DataWrite(p, iId, pTerm->p, iTermOff+nTermIdx);
239867+ if( nTermIdx==0 ){
239868+ fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iTermLeafPgno);
239886239869 }
239887239870 }
239871+ fts5DataRelease(pTerm);
239872+ }
239873+ }
239874+
239875+ if( p->rc==SQLITE_OK ){
239876+ const int nMove = nPg - iNextOff; /* Number of bytes to move */
239877+ int nShift = iNextOff - iOff; /* Distance to move them */
239888239878
239889- if( iPgIdx==nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
239890- fts5SecureDeleteIdxEntry(p, iSegid, pSeg->iLeafPgno);
239879+ int iPrevKeyOut = 0;
239880+ int iKeyIn = 0;
239881+
239882+ memmove(&aPg[iOff], &aPg[iNextOff], nMove);
239883+ iPgIdx -= nShift;
239884+ nPg = iPgIdx;
239885+ fts5PutU16(&aPg[2], iPgIdx);
239886+
239887+ for(iIdx=0; iIdx<nIdx; /* no-op */){
239888+ u32 iVal = 0;
239889+ iIdx += fts5GetVarint32(&aIdx[iIdx], iVal);
239890+ iKeyIn += iVal;
239891+ if( iKeyIn!=iDelKeyOff ){
239892+ int iKeyOut = (iKeyIn - (iKeyIn>iOff ? nShift : 0));
239893+ nPg += sqlite3Fts5PutVarint(&aPg[nPg], iKeyOut - iPrevKeyOut);
239894+ iPrevKeyOut = iKeyOut;
239891239895 }
239896+ }
239892239897
239893- assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
239894- fts5DataWrite (p, FTS5_SEGMENT_ROWID( iSegid,pSeg->iLeafPgno), aPg,nPg );
239898+ if( iPgIdx== nPg && nIdx>0 && pSeg->iLeafPgno!=1 ){
239899+ fts5SecureDeleteIdxEntry (p, iSegid, pSeg->iLeafPgno);
239895239900 }
239896- sqlite3_free(aIdx);
239901+
239902+ assert_nc( nPg>4 || fts5GetU16(aPg)==0 );
239903+ fts5DataWrite(p, FTS5_SEGMENT_ROWID(iSegid,pSeg->iLeafPgno), aPg, nPg);
239904+ }
239905+ sqlite3_free(aIdx);
239897239906}
239898239907
239899239908/*
@@ -245745,7 +245754,7 @@ static void fts5SourceIdFunc(
245745245754){
245746245755 assert( nArg==0 );
245747245756 UNUSED_PARAM2(nArg, apUnused);
245748- sqlite3_result_text(pCtx, "fts5: 2023-08-24 12:36:59 0f80b798b3f4b81a7bb4233c58294edd0f1156f36b6ecf5ab8e83631d468778c ", -1, SQLITE_TRANSIENT);
245757+ sqlite3_result_text(pCtx, "fts5: 2023-09-11 12:01:27 2d3a40c05c49e1a49264912b1a05bc2143ac0e7c3df588276ce80a4cbc9bd1b0 ", -1, SQLITE_TRANSIENT);
245749245758}
245750245759
245751245760/*
0 commit comments