aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-04-13 18:44:59 +0000
committerdrh <>2023-04-13 18:44:59 +0000
commit731a1aaeb2de2d7b69b2b4f0d08d1f5f33ae9a26 (patch)
tree023d157c9dd6c8d8b46e8e01dac746caa3994f72 /src
parent8efa288f99675acd237f02bfdaca63a9542eb426 (diff)
downloadsqlite-731a1aaeb2de2d7b69b2b4f0d08d1f5f33ae9a26.tar.gz
sqlite-731a1aaeb2de2d7b69b2b4f0d08d1f5f33ae9a26.zip
Fix an obscure issue with ALTER TABLE RENAME that comes up with triggers
that have UPDATE statements that contain errors. [forum:/forumpost/ff3840145a|Forum post ff3840145a]. FossilOrigin-Name: c4845a7c5f7f219848d3ee32eef0f9c69ad6dc6e8509da84d612f41e1e05f007
Diffstat (limited to 'src')
-rw-r--r--src/alter.c23
-rw-r--r--src/select.c2
2 files changed, 24 insertions, 1 deletions
diff --git a/src/alter.c b/src/alter.c
index cebeec385..121b61711 100644
--- a/src/alter.c
+++ b/src/alter.c
@@ -1280,6 +1280,19 @@ static int renameEditSql(
}
/*
+** Set all pEList->a[].fg.eEName fields in the expression-list to val.
+*/
+static void renameSetENames(ExprList *pEList, int val){
+ if( pEList ){
+ int i;
+ for(i=0; i<pEList->nExpr; i++){
+ assert( val==ENAME_NAME || pEList->a[i].fg.eEName==ENAME_NAME );
+ pEList->a[i].fg.eEName = val;
+ }
+ }
+}
+
+/*
** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
** it was read from the schema of database zDb. Return SQLITE_OK if
** successful. Otherwise, return an SQLite error code and leave an error
@@ -1326,7 +1339,17 @@ static int renameResolveTrigger(Parse *pParse){
pSrc = 0;
rc = SQLITE_NOMEM;
}else{
+ /* pStep->pExprList contains an expression-list used for an UPDATE
+ ** statement. So the a[].zEName values are the RHS of the
+ ** "<col> = <expr>" clauses of the UPDATE statement. So, before
+ ** running SelectPrep(), change all the eEName values in
+ ** pStep->pExprList to ENAME_SPAN (from their current value of
+ ** ENAME_NAME). This is to prevent any ids in ON() clauses that are
+ ** part of pSrc from being incorrectly resolved against the
+ ** a[].zEName values as if they were column aliases. */
+ renameSetENames(pStep->pExprList, ENAME_SPAN);
sqlite3SelectPrep(pParse, pSel, 0);
+ renameSetENames(pStep->pExprList, ENAME_NAME);
rc = pParse->nErr ? SQLITE_ERROR : SQLITE_OK;
assert( pStep->pExprList==0 || pStep->pExprList==pSel->pEList );
assert( pSrc==pSel->pSrc );
diff --git a/src/select.c b/src/select.c
index fcf8ae78d..9edc04f46 100644
--- a/src/select.c
+++ b/src/select.c
@@ -2318,7 +2318,7 @@ void sqlite3SubqueryColumnTypes(
assert( (pSelect->selFlags & SF_Resolved)!=0 );
assert( pTab->nCol==pSelect->pEList->nExpr || pParse->nErr>0 );
assert( aff==SQLITE_AFF_NONE || aff==SQLITE_AFF_BLOB );
- if( db->mallocFailed ) return;
+ if( db->mallocFailed || IN_RENAME_OBJECT ) return;
while( pSelect->pPrior ) pSelect = pSelect->pPrior;
a = pSelect->pEList->a;
memset(&sNC, 0, sizeof(sNC));