diff options
author | dan <dan@noemail.net> | 2019-01-16 14:58:37 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2019-01-16 14:58:37 +0000 |
commit | 5e970a8f40b1923558fc86cfe21b1bcc9a0064c2 (patch) | |
tree | e6af6f9a2f9e6a097d5b1eb0e3e156fe376c579f /src/resolve.c | |
parent | fb8ac325d769248e45eaa056adf4da9960bdd9c3 (diff) | |
download | sqlite-5e970a8f40b1923558fc86cfe21b1bcc9a0064c2.tar.gz sqlite-5e970a8f40b1923558fc86cfe21b1bcc9a0064c2.zip |
Fix a problem with renaming a column that is used as part of an ORDER BY on a
compound SELECT within a database view or trigger.
FossilOrigin-Name: b4b5741366578b25ec6e4c415ab8239215e53b1c900be613575f40a826cfccc9
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/resolve.c b/src/resolve.c index 23d30f29f..3a5b467ad 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1138,12 +1138,36 @@ static int resolveCompoundOrderBy( }else{ iCol = resolveAsName(pParse, pEList, pE); if( iCol==0 ){ - pDup = sqlite3ExprDup(db, pE, 0); + /* Now test if expression pE matches one of the values returned + ** by pSelect. In the usual case this is done by duplicating the + ** expression, resolving any symbols in it, and then comparing + ** it against each expression returned by the SELECT statement. + ** Once the comparisons are finished, the duplicate expression + ** is deleted. + ** + ** Or, if this is running as part of an ALTER TABLE operation, + ** resolve the symbols in the actual expression, not a duplicate. + ** And, if one of the comparisons is successful, leave the expression + ** as is instead of transforming it to an integer as in the usual + ** case. This allows the code in alter.c to modify column + ** refererences within the ORDER BY expression as required. */ + if( IN_RENAME_OBJECT ){ + pDup = pE; + }else{ + pDup = sqlite3ExprDup(db, pE, 0); + } if( !db->mallocFailed ){ assert(pDup); iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup); } - sqlite3ExprDelete(db, pDup); + if( IN_RENAME_OBJECT ){ + if( iCol>0 ){ + pItem->done = 1; + break; + } + }else{ + sqlite3ExprDelete(db, pDup); + } } } if( iCol>0 ){ |