diff options
author | drh <> | 2022-07-20 16:42:40 +0000 |
---|---|---|
committer | drh <> | 2022-07-20 16:42:40 +0000 |
commit | 3245f3be67907a31431a4506908d981ab1354523 (patch) | |
tree | ac2241d94ea310318b704c524d5612ee73ed216e /src/resolve.c | |
parent | a5cc692422afa7fad710a4459139d7ba00346b21 (diff) | |
download | sqlite-3245f3be67907a31431a4506908d981ab1354523.tar.gz sqlite-3245f3be67907a31431a4506908d981ab1354523.zip |
Simplify the logic that converts the "1" expression in "ORDER BY 1" into a
copy of the expression that defines the first output column.
FossilOrigin-Name: e1f1cfe7f4387b60443bd31742e2f49db1a2d0443200318a898ba0da216619be
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/resolve.c b/src/resolve.c index 99e30d4c8..9512e3a42 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -85,33 +85,23 @@ static void resolveAlias( sqlite3ExprDelete(db, pDup); pDup = 0; }else{ + Expr temp; incrAggFunctionDepth(pDup, nSubquery); if( pExpr->op==TK_COLLATE ){ assert( !ExprHasProperty(pExpr, EP_IntValue) ); pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken); } - - /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This - ** prevents ExprDelete() from deleting the Expr structure itself, - ** allowing it to be repopulated by the memcpy() on the following line. - ** The pExpr->u.zToken might point into memory that will be freed by the - ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to - ** make a copy of the token before doing the sqlite3DbFree(). - */ - ExprSetProperty(pExpr, EP_Static); - sqlite3ExprDelete(db, pExpr); - memcpy(pExpr, pDup, sizeof(*pExpr)); - if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){ - assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 ); - pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken); - pExpr->flags |= EP_MemToken; - } + memcpy(&temp, pDup, sizeof(Expr)); + memcpy(pDup, pExpr, sizeof(Expr)); + memcpy(pExpr, &temp, sizeof(Expr)); if( ExprHasProperty(pExpr, EP_WinFunc) ){ if( ALWAYS(pExpr->y.pWin!=0) ){ pExpr->y.pWin->pOwner = pExpr; } } - sqlite3DbFree(db, pDup); + sqlite3ParserAddCleanup(pParse, + (void(*)(sqlite3*,void*))sqlite3ExprDelete, + pDup); } } |