aboutsummaryrefslogtreecommitdiff
path: root/src/resolve.c
diff options
context:
space:
mode:
authordrh <>2021-02-08 13:41:17 +0000
committerdrh <>2021-02-08 13:41:17 +0000
commitd5101972763c64fce051b477ef046b2476f18392 (patch)
tree737b0b4f0ae92f7a55f2379d9aea5f1133a618ae /src/resolve.c
parente1c9a4ebf9c234942ccf6f2f23731b9c89a71895 (diff)
downloadsqlite-d5101972763c64fce051b477ef046b2476f18392.tar.gz
sqlite-d5101972763c64fce051b477ef046b2476f18392.zip
Improved name resolution for references to a table begin modified from
within a subquery in the RETURNING clause. FossilOrigin-Name: 799d205bfa7945ee4a92dfec5fbf90a00b9a535e3171aab2ec46404f7efb0f78
Diffstat (limited to 'src/resolve.c')
-rw-r--r--src/resolve.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/resolve.c b/src/resolve.c
index 24ec7bb46..8642dffac 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -368,9 +368,10 @@ static int lookupName(
#if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT)
/* If we have not already resolved the name, then maybe
** it is a new.* or old.* trigger argument reference. Or
- ** maybe it is an excluded.* from an upsert.
+ ** maybe it is an excluded.* from an upsert. Or maybe it is
+ ** a reference in the RETURNING clause to a table being modified.
*/
- if( cntTab==0 && zDb==0 ){
+ if( cnt==0 && zDb==0 ){
pTab = 0;
#ifndef SQLITE_OMIT_TRIGGER
if( pParse->pTriggerTab!=0 ){
@@ -389,7 +390,7 @@ static int lookupName(
}
#endif /* SQLITE_OMIT_TRIGGER */
#ifndef SQLITE_OMIT_UPSERT
- if( (pNC->ncFlags & NC_UUpsert)!=0 && ALWAYS(zTab) ){
+ if( (pNC->ncFlags & NC_UUpsert)!=0 && zTab!=0 ){
Upsert *pUpsert = pNC->uNC.pUpsert;
if( pUpsert && sqlite3StrICmp("excluded",zTab)==0 ){
pTab = pUpsert->pUpsertSrc->a[0].pTab;
@@ -434,8 +435,13 @@ static int lookupName(
{
pExpr->y.pTab = pTab;
if( pParse->bReturning ){
+ NameContext *pUp = pNC;
+ while( (pUp->ncFlags & NC_UBaseReg)==0 && ALWAYS(pUp->pNext) ){
+ pUp = pUp->pNext;
+ }
+ assert( pUp->ncFlags & NC_UBaseReg );
eNewExprOp = TK_REGISTER;
- pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable
+ pExpr->iTable = pUp->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable
+ iCol + 1;
}else{
pExpr->iColumn = (i16)iCol;
@@ -1648,7 +1654,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
** Minor point: If this is the case, then the expression will be
** re-evaluated for each reference to it.
*/
- assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert))==0 );
+ assert( (sNC.ncFlags & (NC_UAggInfo|NC_UUpsert|NC_UBaseReg))==0 );
sNC.uNC.pEList = p->pEList;
sNC.ncFlags |= NC_UEList;
if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;