11/******************************************************************************
22** This file is an amalgamation of many separate C source files from SQLite
3- ** version 3.32.0 . By combining all the individual C code files into this
3+ ** version 3.32.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
@@ -1162,9 +1162,9 @@ extern "C" {
11621162** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163** [sqlite_version()] and [sqlite_source_id()].
11641164*/
1165- #define SQLITE_VERSION "3.32.0 "
1166- #define SQLITE_VERSION_NUMBER 3032000
1167- #define SQLITE_SOURCE_ID "2020-05-22 17:46:16 5998789c9c744bce92e4cff7636bba800a75574243d6977e1fc8281e360f8d5a "
1165+ #define SQLITE_VERSION "3.32.1 "
1166+ #define SQLITE_VERSION_NUMBER 3032001
1167+ #define SQLITE_SOURCE_ID "2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba83350 "
11681168
11691169/*
11701170** CAPI3REF: Run-Time Library Version Numbers
@@ -17843,7 +17843,7 @@ struct Token {
1784317843** code for a SELECT that contains aggregate functions.
1784417844**
1784517845** If Expr.op==TK_AGG_COLUMN or TK_AGG_FUNCTION then Expr.pAggInfo is a
17846- ** pointer to this structure. The Expr.iColumn field is the index in
17846+ ** pointer to this structure. The Expr.iAgg field is the index in
1784717847** AggInfo.aCol[] or AggInfo.aFunc[] of information needed to generate
1784817848** code for that node.
1784917849**
@@ -19082,6 +19082,9 @@ SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
1908219082SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
1908319083SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
1908419084SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
19085+ SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*);
19086+ SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*);
19087+
1908519088#ifdef SQLITE_DEBUG
1908619089SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
1908719090#endif
@@ -28276,6 +28279,13 @@ static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
2827628279#endif
2827728280#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
2827828281
28282+ /*
28283+ ** Hard limit on the precision of floating-point conversions.
28284+ */
28285+ #ifndef SQLITE_PRINTF_PRECISION_LIMIT
28286+ # define SQLITE_FP_PRECISION_LIMIT 100000000
28287+ #endif
28288+
2827928289/*
2828028290** Render a string given by "fmt" into the StrAccum object.
2828128291*/
@@ -28476,6 +28486,8 @@ SQLITE_API void sqlite3_str_vappendf(
2847628486 ** xtype The class of the conversion.
2847728487 ** infop Pointer to the appropriate info struct.
2847828488 */
28489+ assert( width>=0 );
28490+ assert( precision>=(-1) );
2847928491 switch( xtype ){
2848028492 case etPOINTER:
2848128493 flag_long = sizeof(char*)==sizeof(i64) ? 2 :
@@ -28597,6 +28609,11 @@ SQLITE_API void sqlite3_str_vappendf(
2859728609 length = 0;
2859828610#else
2859928611 if( precision<0 ) precision = 6; /* Set default precision */
28612+ #ifdef SQLITE_FP_PRECISION_LIMIT
28613+ if( precision>SQLITE_FP_PRECISION_LIMIT ){
28614+ precision = SQLITE_FP_PRECISION_LIMIT;
28615+ }
28616+ #endif
2860028617 if( realvalue<0.0 ){
2860128618 realvalue = -realvalue;
2860228619 prefix = '-';
@@ -28879,7 +28896,7 @@ SQLITE_API void sqlite3_str_vappendf(
2887928896 }
2888028897 isnull = escarg==0;
2888128898 if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
28882- /* For %q, %Q, and %w, the precision is the number of byte (or
28899+ /* For %q, %Q, and %w, the precision is the number of bytes (or
2888328900 ** characters if the ! flags is present) to use from the input.
2888428901 ** Because of the extra quoting characters inserted, the number
2888528902 ** of output characters may be larger than the precision.
@@ -29964,8 +29981,9 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
2996429981#endif
2996529982 }
2996629983 if( pExpr->op==TK_AGG_FUNCTION ){
29967- sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s",
29968- pExpr->op2, pExpr->u.zToken, zFlgs);
29984+ sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p",
29985+ pExpr->op2, pExpr->u.zToken, zFlgs,
29986+ pExpr->iAgg, pExpr->pAggInfo);
2996929987 }else if( pExpr->op2!=0 ){
2997029988 const char *zOp2;
2997129989 char zBuf[8];
@@ -62135,12 +62153,14 @@ SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal){
6213562153SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){
6213662154 int rc; /* Return code */
6213762155 int cnt = 0; /* Number of TryBeginRead attempts */
62156+ #ifdef SQLITE_ENABLE_SNAPSHOT
62157+ int bChanged = 0;
62158+ WalIndexHdr *pSnapshot = pWal->pSnapshot;
62159+ #endif
6213862160
6213962161 assert( pWal->ckptLock==0 );
6214062162
6214162163#ifdef SQLITE_ENABLE_SNAPSHOT
62142- int bChanged = 0;
62143- WalIndexHdr *pSnapshot = pWal->pSnapshot;
6214462164 if( pSnapshot ){
6214562165 if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){
6214662166 bChanged = 1;
@@ -97465,6 +97485,43 @@ SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){
9746597485 return WRC_Continue;
9746697486}
9746797487
97488+ /* Increase the walkerDepth when entering a subquery, and
97489+ ** descrease when leaving the subquery.
97490+ */
97491+ SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){
97492+ UNUSED_PARAMETER(pSelect);
97493+ pWalker->walkerDepth++;
97494+ return WRC_Continue;
97495+ }
97496+ SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker *pWalker, Select *pSelect){
97497+ UNUSED_PARAMETER(pSelect);
97498+ pWalker->walkerDepth--;
97499+ }
97500+
97501+
97502+ /*
97503+ ** No-op routine for the parse-tree walker.
97504+ **
97505+ ** When this routine is the Walker.xExprCallback then expression trees
97506+ ** are walked without any actions being taken at each node. Presumably,
97507+ ** when this routine is used for Walker.xExprCallback then
97508+ ** Walker.xSelectCallback is set to do something useful for every
97509+ ** subquery in the parser tree.
97510+ */
97511+ SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker *NotUsed, Expr *NotUsed2){
97512+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
97513+ return WRC_Continue;
97514+ }
97515+
97516+ /*
97517+ ** No-op routine for the parse-tree walker for SELECT statements.
97518+ ** subquery in the parser tree.
97519+ */
97520+ SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker *NotUsed, Select *NotUsed2){
97521+ UNUSED_PARAMETER2(NotUsed, NotUsed2);
97522+ return WRC_Continue;
97523+ }
97524+
9746897525/************** End of walker.c **********************************************/
9746997526/************** Begin file resolve.c *****************************************/
9747097527/*
@@ -97493,6 +97550,8 @@ SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){
9749397550**
9749497551** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..)
9749597552** is a helper function - a callback for the tree walker.
97553+ **
97554+ ** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c
9749697555*/
9749797556static int incrAggDepth(Walker *pWalker, Expr *pExpr){
9749897557 if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n;
@@ -103234,7 +103293,10 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
103234103293 switch( op ){
103235103294 case TK_AGG_COLUMN: {
103236103295 AggInfo *pAggInfo = pExpr->pAggInfo;
103237- struct AggInfo_col *pCol = &pAggInfo->aCol[pExpr->iAgg];
103296+ struct AggInfo_col *pCol;
103297+ assert( pAggInfo!=0 );
103298+ assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
103299+ pCol = &pAggInfo->aCol[pExpr->iAgg];
103238103300 if( !pAggInfo->directMode ){
103239103301 assert( pCol->iMem>0 );
103240103302 return pCol->iMem;
@@ -103534,7 +103596,10 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
103534103596 }
103535103597 case TK_AGG_FUNCTION: {
103536103598 AggInfo *pInfo = pExpr->pAggInfo;
103537- if( pInfo==0 ){
103599+ if( pInfo==0
103600+ || NEVER(pExpr->iAgg<0)
103601+ || NEVER(pExpr->iAgg>=pInfo->nFunc)
103602+ ){
103538103603 assert( !ExprHasProperty(pExpr, EP_IntValue) );
103539103604 sqlite3ErrorMsg(pParse, "misuse of aggregate: %s()", pExpr->u.zToken);
103540103605 }else{
@@ -105290,15 +105355,6 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
105290105355 }
105291105356 return WRC_Continue;
105292105357}
105293- static int analyzeAggregatesInSelect(Walker *pWalker, Select *pSelect){
105294- UNUSED_PARAMETER(pSelect);
105295- pWalker->walkerDepth++;
105296- return WRC_Continue;
105297- }
105298- static void analyzeAggregatesInSelectEnd(Walker *pWalker, Select *pSelect){
105299- UNUSED_PARAMETER(pSelect);
105300- pWalker->walkerDepth--;
105301- }
105302105358
105303105359/*
105304105360** Analyze the pExpr expression looking for aggregate functions and
@@ -105312,8 +105368,8 @@ static void analyzeAggregatesInSelectEnd(Walker *pWalker, Select *pSelect){
105312105368SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
105313105369 Walker w;
105314105370 w.xExprCallback = analyzeAggregate;
105315- w.xSelectCallback = analyzeAggregatesInSelect ;
105316- w.xSelectCallback2 = analyzeAggregatesInSelectEnd ;
105371+ w.xSelectCallback = sqlite3WalkerDepthIncrease ;
105372+ w.xSelectCallback2 = sqlite3WalkerDepthDecrease ;
105317105373 w.walkerDepth = 0;
105318105374 w.u.pNC = pNC;
105319105375 w.pParse = 0;
@@ -122035,7 +122091,7 @@ SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(
122035122091 sqlite3TableAffinity(v, pTab, regNewData+1);
122036122092 bAffinityDone = 1;
122037122093 }
122038- VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
122094+ VdbeNoopComment((v, "prep index %s", pIdx->zName));
122039122095 iThisCur = iIdxCur+ix;
122040122096
122041122097
@@ -134007,29 +134063,6 @@ static int selectExpander(Walker *pWalker, Select *p){
134007134063 return WRC_Continue;
134008134064}
134009134065
134010- /*
134011- ** No-op routine for the parse-tree walker.
134012- **
134013- ** When this routine is the Walker.xExprCallback then expression trees
134014- ** are walked without any actions being taken at each node. Presumably,
134015- ** when this routine is used for Walker.xExprCallback then
134016- ** Walker.xSelectCallback is set to do something useful for every
134017- ** subquery in the parser tree.
134018- */
134019- SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker *NotUsed, Expr *NotUsed2){
134020- UNUSED_PARAMETER2(NotUsed, NotUsed2);
134021- return WRC_Continue;
134022- }
134023-
134024- /*
134025- ** No-op routine for the parse-tree walker for SELECT statements.
134026- ** subquery in the parser tree.
134027- */
134028- SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker *NotUsed, Select *NotUsed2){
134029- UNUSED_PARAMETER2(NotUsed, NotUsed2);
134030- return WRC_Continue;
134031- }
134032-
134033134066#if SQLITE_DEBUG
134034134067/*
134035134068** Always assert. This xSelectCallback2 implementation proves that the
@@ -135200,7 +135233,7 @@ SQLITE_PRIVATE int sqlite3Select(
135200135233#if SELECTTRACE_ENABLED
135201135234 if( sqlite3SelectTrace & 0x400 ){
135202135235 int ii;
135203- SELECTTRACE(0x400,pParse,p,("After aggregate analysis:\n"));
135236+ SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p :\n", &sAggInfo ));
135204135237 sqlite3TreeViewSelect(0, p, 0);
135205135238 for(ii=0; ii<sAggInfo.nColumn; ii++){
135206135239 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
@@ -151244,6 +151277,23 @@ static ExprList *exprListAppendList(
151244151277 return pList;
151245151278}
151246151279
151280+ /*
151281+ ** When rewriting a query, if the new subquery in the FROM clause
151282+ ** contains TK_AGG_FUNCTION nodes that refer to an outer query,
151283+ ** then we have to increase the Expr->op2 values of those nodes
151284+ ** due to the extra subquery layer that was added.
151285+ **
151286+ ** See also the incrAggDepth() routine in resolve.c
151287+ */
151288+ static int sqlite3WindowExtraAggFuncDepth(Walker *pWalker, Expr *pExpr){
151289+ if( pExpr->op==TK_AGG_FUNCTION
151290+ && pExpr->op2>=pWalker->walkerDepth
151291+ ){
151292+ pExpr->op2++;
151293+ }
151294+ return WRC_Continue;
151295+ }
151296+
151247151297/*
151248151298** If the SELECT statement passed as the second argument does not invoke
151249151299** any SQL window functions, this function is a no-op. Otherwise, it
@@ -151353,6 +151403,7 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
151353151403 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151354151404 if( p->pSrc ){
151355151405 Table *pTab2;
151406+ Walker w;
151356151407 p->pSrc->a[0].pSelect = pSub;
151357151408 sqlite3SrcListAssignCursors(pParse, p->pSrc);
151358151409 pSub->selFlags |= SF_Expanded;
@@ -151368,6 +151419,11 @@ SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){
151368151419 pTab->tabFlags |= TF_Ephemeral;
151369151420 p->pSrc->a[0].pTab = pTab;
151370151421 pTab = pTab2;
151422+ memset(&w, 0, sizeof(w));
151423+ w.xExprCallback = sqlite3WindowExtraAggFuncDepth;
151424+ w.xSelectCallback = sqlite3WalkerDepthIncrease;
151425+ w.xSelectCallback2 = sqlite3WalkerDepthDecrease;
151426+ sqlite3WalkSelect(&w, pSub);
151371151427 }
151372151428 }else{
151373151429 sqlite3SelectDelete(db, pSub);
@@ -224766,7 +224822,7 @@ static void fts5SourceIdFunc(
224766224822){
224767224823 assert( nArg==0 );
224768224824 UNUSED_PARAM2(nArg, apUnused);
224769- sqlite3_result_text(pCtx, "fts5: 2020-05-22 17:46:16 5998789c9c744bce92e4cff7636bba800a75574243d6977e1fc8281e360f8d5a ", -1, SQLITE_TRANSIENT);
224825+ sqlite3_result_text(pCtx, "fts5: 2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba83350 ", -1, SQLITE_TRANSIENT);
224770224826}
224771224827
224772224828/*
@@ -229549,9 +229605,9 @@ SQLITE_API int sqlite3_stmt_init(
229549229605#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229550229606
229551229607/************** End of stmt.c ************************************************/
229552- #if __LINE__!=229552
229608+ #if __LINE__!=229608
229553229609#undef SQLITE_SOURCE_ID
229554- #define SQLITE_SOURCE_ID "2020-05-22 17:46:16 5998789c9c744bce92e4cff7636bba800a75574243d6977e1fc8281e360falt2 "
229610+ #define SQLITE_SOURCE_ID "2020-05-25 16:19:56 0c1fcf4711a2e66c813aed38cf41cd3e2123ee8eb6db98118086764c4ba8alt2 "
229555229611#endif
229556229612/* Return the source-id for this library */
229557229613SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
0 commit comments