1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-09-09 21:09:38 +03:00

Fix a problem with renaming a table within a schema that contains a composite query that uses a column alias as an ORDER BY term.

FossilOrigin-Name: 2ca6b8f84ec07e313aa4e1c0894827401b418dcc4221e9c54c384f1c3893952a
This commit is contained in:
dan
2019-01-23 19:50:46 +00:00
parent e3dadac591
commit a5f9f42a0e
4 changed files with 47 additions and 29 deletions

View File

@@ -1160,12 +1160,7 @@ static int resolveCompoundOrderBy(
assert(pDup);
iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
}
if( IN_RENAME_OBJECT ){
if( iCol>0 ){
pItem->done = 1;
continue;
}
}else{
if( !IN_RENAME_OBJECT ){
sqlite3ExprDelete(db, pDup);
}
}
@@ -1173,21 +1168,23 @@ static int resolveCompoundOrderBy(
if( iCol>0 ){
/* Convert the ORDER BY term into an integer column number iCol,
** taking care to preserve the COLLATE clause if it exists */
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
if( pNew==0 ) return 1;
pNew->flags |= EP_IntValue;
pNew->u.iValue = iCol;
if( pItem->pExpr==pE ){
pItem->pExpr = pNew;
}else{
Expr *pParent = pItem->pExpr;
assert( pParent->op==TK_COLLATE );
while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
assert( pParent->pLeft==pE );
pParent->pLeft = pNew;
if( !IN_RENAME_OBJECT ){
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
if( pNew==0 ) return 1;
pNew->flags |= EP_IntValue;
pNew->u.iValue = iCol;
if( pItem->pExpr==pE ){
pItem->pExpr = pNew;
}else{
Expr *pParent = pItem->pExpr;
assert( pParent->op==TK_COLLATE );
while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
assert( pParent->pLeft==pE );
pParent->pLeft = pNew;
}
sqlite3ExprDelete(db, pE);
pItem->u.x.iOrderByCol = (u16)iCol;
}
sqlite3ExprDelete(db, pE);
pItem->u.x.iOrderByCol = (u16)iCol;
pItem->done = 1;
}else{
moreToDo = 1;