11/******************************************************************************
22** This file is an amalgamation of many separate C source files from SQLite
3- ** version 3.38.2 . By combining all the individual C code files into this
3+ ** version 3.38.3 . 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
@@ -452,9 +452,9 @@ extern "C" {
452452** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453** [sqlite_version()] and [sqlite_source_id()].
454454*/
455- #define SQLITE_VERSION "3.38.2 "
456- #define SQLITE_VERSION_NUMBER 3038002
457- #define SQLITE_SOURCE_ID "2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f "
455+ #define SQLITE_VERSION "3.38.3 "
456+ #define SQLITE_VERSION_NUMBER 3038003
457+ #define SQLITE_SOURCE_ID "2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4 "
458458
459459/*
460460** CAPI3REF: Run-Time Library Version Numbers
@@ -19929,6 +19929,7 @@ SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1992919929SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
1993019930SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
1993119931SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
19932+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*);
1993219933#ifdef SQLITE_ENABLE_CURSOR_HINTS
1993319934SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
1993419935#endif
@@ -29337,8 +29338,9 @@ SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const cha
2933729338** Free any prior content in *pz and replace it with a copy of zNew.
2933829339*/
2933929340SQLITE_PRIVATE void sqlite3SetString(char **pz, sqlite3 *db, const char *zNew){
29341+ char *z = sqlite3DbStrDup(db, zNew);
2934029342 sqlite3DbFree(db, *pz);
29341- *pz = sqlite3DbStrDup(db, zNew) ;
29343+ *pz = z ;
2934229344}
2934329345
2934429346/*
@@ -67764,6 +67766,8 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
6776467766 ** fragmented bytes within the page. */
6776567767 memcpy(&aData[iAddr], &aData[pc], 2);
6776667768 aData[hdr+7] += (u8)x;
67769+ testcase( pc+x>maxPC );
67770+ return &aData[pc];
6776767771 }else if( x+pc > maxPC ){
6776867772 /* This slot extends off the end of the usable part of the page */
6776967773 *pRc = SQLITE_CORRUPT_PAGE(pPg);
@@ -71963,7 +71967,7 @@ SQLITE_PRIVATE int sqlite3BtreeIndexMoveto(
7196371967 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
7196471968 assert( pPage->isInit );
7196571969 if( pPage->leaf ){
71966- assert( pCur->ix<pCur->pPage->nCell );
71970+ assert( pCur->ix<pCur->pPage->nCell || CORRUPT_DB );
7196771971 pCur->ix = (u16)idx;
7196871972 *pRes = c;
7196971973 rc = SQLITE_OK;
@@ -74487,7 +74491,7 @@ static int balance_nonroot(
7448774491 iOvflSpace += sz;
7448874492 assert( sz<=pBt->maxLocal+23 );
7448974493 assert( iOvflSpace <= (int)pBt->pageSize );
74490- for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
74494+ for(k=0; b.ixNx[k]<=j && ALWAYS(k<NB*2); k++){}
7449174495 pSrcEnd = b.apEnd[k];
7449274496 if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
7449374497 rc = SQLITE_CORRUPT_BKPT;
@@ -78052,7 +78056,11 @@ SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
7805278056 assert( !sqlite3VdbeMemIsRowSet(pMem) );
7805378057 assert( desiredEnc==SQLITE_UTF8 || desiredEnc==SQLITE_UTF16LE
7805478058 || desiredEnc==SQLITE_UTF16BE );
78055- if( !(pMem->flags&MEM_Str) || pMem->enc==desiredEnc ){
78059+ if( !(pMem->flags&MEM_Str) ){
78060+ pMem->enc = desiredEnc;
78061+ return SQLITE_OK;
78062+ }
78063+ if( pMem->enc==desiredEnc ){
7805678064 return SQLITE_OK;
7805778065 }
7805878066 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
@@ -104759,6 +104767,38 @@ SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
104759104767 return exprIsConst(p, 3, iCur);
104760104768}
104761104769
104770+ /*
104771+ ** Check pExpr to see if it is an invariant constraint on data source pSrc.
104772+ ** This is an optimization. False negatives will perhaps cause slower
104773+ ** queries, but false positives will yield incorrect answers. So when in
104774+ ** double, return 0.
104775+ **
104776+ ** To be an invariant constraint, the following must be true:
104777+ **
104778+ ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
104779+ **
104780+ ** (2) pExpr cannot use subqueries or non-deterministic functions.
104781+ **
104782+ ** (*) ** Not applicable to this branch **
104783+ **
104784+ ** (4) If pSrc is the right operand of a LEFT JOIN, then...
104785+ ** (4a) pExpr must come from an ON clause..
104786+ ** (4b) and specifically the ON clause associated with the LEFT JOIN.
104787+ **
104788+ ** (5) If pSrc is not the right operand of a LEFT JOIN or the left
104789+ ** operand of a RIGHT JOIN, then pExpr must be from the WHERE
104790+ ** clause, not an ON clause.
104791+ */
104792+ SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){
104793+ if( pSrc->fg.jointype & JT_LEFT ){
104794+ if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */
104795+ if( pExpr->w.iRightJoinTable!=pSrc->iCursor ) return 0; /* rule (4b) */
104796+ }else{
104797+ if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */
104798+ }
104799+ return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */
104800+ }
104801+
104762104802
104763104803/*
104764104804** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
@@ -139042,8 +139082,7 @@ static int pushDownWhereTerms(
139042139082 Parse *pParse, /* Parse context (for malloc() and error reporting) */
139043139083 Select *pSubq, /* The subquery whose WHERE clause is to be augmented */
139044139084 Expr *pWhere, /* The WHERE clause of the outer query */
139045- int iCursor, /* Cursor number of the subquery */
139046- int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
139085+ SrcItem *pSrc /* The subquery term of the outer FROM clause */
139047139086){
139048139087 Expr *pNew;
139049139088 int nChng = 0;
@@ -139078,10 +139117,11 @@ static int pushDownWhereTerms(
139078139117 return 0; /* restriction (3) */
139079139118 }
139080139119 while( pWhere->op==TK_AND ){
139081- nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight,
139082- iCursor, isLeftJoin);
139120+ nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc);
139083139121 pWhere = pWhere->pLeft;
139084139122 }
139123+
139124+ #if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */
139085139125 if( isLeftJoin
139086139126 && (ExprHasProperty(pWhere,EP_FromJoin)==0
139087139127 || pWhere->w.iRightJoinTable!=iCursor)
@@ -139093,16 +139133,18 @@ static int pushDownWhereTerms(
139093139133 ){
139094139134 return 0; /* restriction (5) */
139095139135 }
139096- if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
139136+ #endif
139137+
139138+ if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){
139097139139 nChng++;
139098139140 pSubq->selFlags |= SF_PushDown;
139099139141 while( pSubq ){
139100139142 SubstContext x;
139101139143 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
139102139144 unsetJoinExpr(pNew, -1);
139103139145 x.pParse = pParse;
139104- x.iTable = iCursor;
139105- x.iNewTable = iCursor;
139146+ x.iTable = pSrc-> iCursor;
139147+ x.iNewTable = pSrc-> iCursor;
139106139148 x.isLeftJoin = 0;
139107139149 x.pEList = pSubq->pEList;
139108139150 pNew = substExpr(&x, pNew);
@@ -140884,8 +140926,7 @@ SQLITE_PRIVATE int sqlite3Select(
140884140926 if( OptimizationEnabled(db, SQLITE_PushDown)
140885140927 && (pItem->fg.isCte==0
140886140928 || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2))
140887- && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor,
140888- (pItem->fg.jointype & JT_OUTER)!=0)
140929+ && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem)
140889140930 ){
140890140931#if SELECTTRACE_ENABLED
140891140932 if( sqlite3SelectTrace & 0x100 ){
@@ -152810,8 +152851,7 @@ static SQLITE_NOINLINE void constructAutomaticIndex(
152810152851 ** WHERE clause (or the ON clause of a LEFT join) that constrain which
152811152852 ** rows of the target table (pSrc) that can be used. */
152812152853 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
152813- && ((pSrc->fg.jointype&JT_LEFT)==0 || ExprHasProperty(pExpr,EP_FromJoin))
152814- && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor)
152854+ && sqlite3ExprIsTableConstraint(pExpr, pSrc)
152815152855 ){
152816152856 pPartial = sqlite3ExprAnd(pParse, pPartial,
152817152857 sqlite3ExprDup(pParse->db, pExpr, 0));
@@ -153050,7 +153090,7 @@ static SQLITE_NOINLINE void sqlite3ConstructBloomFilter(
153050153090 for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){
153051153091 Expr *pExpr = pTerm->pExpr;
153052153092 if( (pTerm->wtFlags & TERM_VIRTUAL)==0
153053- && sqlite3ExprIsTableConstant (pExpr, iCur )
153093+ && sqlite3ExprIsTableConstraint (pExpr, pItem )
153054153094 ){
153055153095 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
153056153096 }
@@ -159970,7 +160010,7 @@ static void windowAggStep(
159970160010
159971160011 for(iEnd=sqlite3VdbeCurrentAddr(v); iOp<iEnd; iOp++){
159972160012 VdbeOp *pOp = sqlite3VdbeGetOp(v, iOp);
159973- if( pOp->opcode==OP_Column && pOp->p1==pWin ->iEphCsr ){
160013+ if( pOp->opcode==OP_Column && pOp->p1==pMWin ->iEphCsr ){
159974160014 pOp->p1 = csr;
159975160015 }
159976160016 }
@@ -194288,14 +194328,15 @@ static JsonNode *jsonLookupStep(
194288194328 *pzErr = zPath;
194289194329 return 0;
194290194330 }
194331+ testcase( nKey==0 );
194291194332 }else{
194292194333 zKey = zPath;
194293194334 for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
194294194335 nKey = i;
194295- }
194296- if( nKey==0 ){
194297- *pzErr = zPath ;
194298- return 0;
194336+ if( nKey==0 ){
194337+ *pzErr = zPath;
194338+ return 0 ;
194339+ }
194299194340 }
194300194341 j = 1;
194301194342 for(;;){
@@ -195443,6 +195484,33 @@ static int jsonEachNext(sqlite3_vtab_cursor *cur){
195443195484 return SQLITE_OK;
195444195485}
195445195486
195487+ /* Append an object label to the JSON Path being constructed
195488+ ** in pStr.
195489+ */
195490+ static void jsonAppendObjectPathElement(
195491+ JsonString *pStr,
195492+ JsonNode *pNode
195493+ ){
195494+ int jj, nn;
195495+ const char *z;
195496+ assert( pNode->eType==JSON_STRING );
195497+ assert( pNode->jnFlags & JNODE_LABEL );
195498+ assert( pNode->eU==1 );
195499+ z = pNode->u.zJContent;
195500+ nn = pNode->n;
195501+ assert( nn>=2 );
195502+ assert( z[0]=='"' );
195503+ assert( z[nn-1]=='"' );
195504+ if( nn>2 && sqlite3Isalpha(z[1]) ){
195505+ for(jj=2; jj<nn-1 && sqlite3Isalnum(z[jj]); jj++){}
195506+ if( jj==nn-1 ){
195507+ z++;
195508+ nn -= 2;
195509+ }
195510+ }
195511+ jsonPrintf(nn+2, pStr, ".%.*s", nn, z);
195512+ }
195513+
195446195514/* Append the name of the path for element i to pStr
195447195515*/
195448195516static void jsonEachComputePath(
@@ -195467,10 +195535,7 @@ static void jsonEachComputePath(
195467195535 }else{
195468195536 assert( pUp->eType==JSON_OBJECT );
195469195537 if( (pNode->jnFlags & JNODE_LABEL)==0 ) pNode--;
195470- assert( pNode->eType==JSON_STRING );
195471- assert( pNode->jnFlags & JNODE_LABEL );
195472- assert( pNode->eU==1 );
195473- jsonPrintf(pNode->n+1, pStr, ".%.*s", pNode->n-2, pNode->u.zJContent+1);
195538+ jsonAppendObjectPathElement(pStr, pNode);
195474195539 }
195475195540}
195476195541
@@ -195541,8 +195606,7 @@ static int jsonEachColumn(
195541195606 if( p->eType==JSON_ARRAY ){
195542195607 jsonPrintf(30, &x, "[%d]", p->iRowid);
195543195608 }else if( p->eType==JSON_OBJECT ){
195544- assert( pThis->eU==1 );
195545- jsonPrintf(pThis->n, &x, ".%.*s", pThis->n-2, pThis->u.zJContent+1);
195609+ jsonAppendObjectPathElement(&x, pThis);
195546195610 }
195547195611 }
195548195612 jsonResult(&x);
@@ -234433,7 +234497,7 @@ static void fts5SourceIdFunc(
234433234497){
234434234498 assert( nArg==0 );
234435234499 UNUSED_PARAM2(nArg, apUnused);
234436- sqlite3_result_text(pCtx, "fts5: 2022-03-26 13:51:10 d33c709cc0af66bc5b6dc6216eba9f1f0b40960b9ae83694c986fbf4c1d6f08f ", -1, SQLITE_TRANSIENT);
234500+ sqlite3_result_text(pCtx, "fts5: 2022-04-27 12:03:15 9547e2c38a1c6f751a77d4d796894dec4dc5d8f5d79b1cd39e1ffc50df7b3be4 ", -1, SQLITE_TRANSIENT);
234437234501}
234438234502
234439234503/*
0 commit comments