diff options
author | dan <dan@noemail.net> | 2020-07-13 18:04:27 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2020-07-13 18:04:27 +0000 |
commit | a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0 (patch) | |
tree | e2000d1d8b1b14297c1a8790c65dd90c4a20e2b9 /src/resolve.c | |
parent | 7465787b97a0a09841e343630a07ba80f1399e4a (diff) | |
parent | 5b107654e965973e68c88f90a09a3cc53bac9d8b (diff) | |
download | sqlite-a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0.tar.gz sqlite-a7f82d9f47ca75a2f47dc14f8a8deb6730d718d0.zip |
Merge latest trunk changes with this branch.
FossilOrigin-Name: 5ee3c27e20d12a126fb773b428bb864102b949a5b26a8d5c523753dcedf4be10
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/resolve.c b/src/resolve.c index 76cdc8ccd..2b2a3fa12 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -17,6 +17,11 @@ #include "sqliteInt.h" /* +** Magic table number to mean the EXCLUDED table in an UPSERT statement. +*/ +#define EXCLUDED_TABLE_NUMBER 2 + +/* ** Walk the expression tree pExpr and increase the aggregate function ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. ** This needs to occur when copying a TK_AGG_FUNCTION node from an @@ -24,6 +29,8 @@ ** ** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) ** is a helper function - a callback for the tree walker. +** +** See also the sqlite3WindowExtraAggFuncDepth() routine in window.c */ static int incrAggDepth(Walker *pWalker, Expr *pExpr){ if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.n; @@ -384,7 +391,7 @@ static int lookupName( Upsert *pUpsert = pNC->uNC.pUpsert; if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){ pTab = pUpsert->pUpsertSrc->a[0].pTab; - pExpr->iTable = 2; + pExpr->iTable = EXCLUDED_TABLE_NUMBER; } } #endif /* SQLITE_OMIT_UPSERT */ @@ -409,14 +416,15 @@ static int lookupName( if( iCol<pTab->nCol ){ cnt++; #ifndef SQLITE_OMIT_UPSERT - if( pExpr->iTable==2 ){ + if( pExpr->iTable==EXCLUDED_TABLE_NUMBER ){ testcase( iCol==(-1) ); if( IN_RENAME_OBJECT ){ pExpr->iColumn = iCol; pExpr->y.pTab = pTab; eNewExprOp = TK_COLUMN; }else{ - pExpr->iTable = pNC->uNC.pUpsert->regData + iCol; + pExpr->iTable = pNC->uNC.pUpsert->regData + + sqlite3TableColumnToStorage(pTab, iCol); eNewExprOp = TK_REGISTER; ExprSetProperty(pExpr, EP_Alias); } |