diff options
author | dan <Dan Kennedy> | 2021-06-01 15:37:14 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2021-06-01 15:37:14 +0000 |
commit | b56a09079e8b5305d3c99ae19aedcbbd343b28d9 (patch) | |
tree | 1577fb0f5d5b7e187020968b74dcdb2df2a4669e /src/resolve.c | |
parent | d65b7e36ecf05a3464c7071f92cfd304197ac66a (diff) | |
download | sqlite-b56a09079e8b5305d3c99ae19aedcbbd343b28d9.tar.gz sqlite-b56a09079e8b5305d3c99ae19aedcbbd343b28d9.zip |
Fix a problem with running ALTER TABLE against schemas that contain compound SELECT statements with ORDER BY clauses containing one or more references to the second or subsequent component SELECT statements.
FossilOrigin-Name: 587a3044468a40707c714d013cb766d8a4d9eb13bb20871846a0e8c34bea8cf4
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/resolve.c b/src/resolve.c index d5cec3550..93e10b6e4 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1262,7 +1262,7 @@ static int resolveOrderByTermToExprList( nc.nNcErr = 0; db = pParse->db; savedSuppErr = db->suppressErr; - if( IN_RENAME_OBJECT==0 ) db->suppressErr = 1; + db->suppressErr = 1; rc = sqlite3ResolveExprNames(&nc, pE); db->suppressErr = savedSuppErr; if( rc ) return 0; @@ -1361,29 +1361,24 @@ static int resolveCompoundOrderBy( ** 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 this is running as part of an ALTER TABLE operation and + ** the symbols resolve successfully, also resolve the symbols in the + ** actual expression. This allows the code in alter.c to modify + ** column references within the ORDER BY expression as required. */ + pDup = sqlite3ExprDup(db, pE, 0); if( !db->mallocFailed ){ assert(pDup); iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup); + if( IN_RENAME_OBJECT && iCol>0 ){ + resolveOrderByTermToExprList(pParse, pSelect, pE); + } } - if( !IN_RENAME_OBJECT ){ - sqlite3ExprDelete(db, pDup); - } + sqlite3ExprDelete(db, pDup); } } if( iCol>0 ){ /* Convert the ORDER BY term into an integer column number iCol, - ** taking care to preserve the COLLATE clause if it exists */ + ** taking care to preserve the COLLATE clause if it exists. */ if( !IN_RENAME_OBJECT ){ Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0); if( pNew==0 ) return 1; |