From: drh Date: Fri, 7 Dec 2012 21:02:47 +0000 (+0000) Subject: Fix the processing of ORDER BY clauses with COLLATE terms on compound X-Git-Tag: version-3.7.15~7^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd13d34b08ddc66a079f671bcbe96127b41da957;p=thirdparty%2Fsqlite.git Fix the processing of ORDER BY clauses with COLLATE terms on compound queries. 52 veryquick test failures remain. FossilOrigin-Name: 49654453ad157693414c1f86fa3afa0918acffd4 --- diff --git a/manifest b/manifest index 34721bdbc1..dae7f8ea53 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Many\smore\stests\sare\spassing.\s\sOnly\sabout\s100\sfailures\sremain\sin\sveryquick. -D 2012-12-07T20:31:11.446 +C Fix\sthe\sprocessing\sof\sORDER\sBY\sclauses\swith\sCOLLATE\sterms\son\scompound\nqueries.\s\s52\sveryquick\stest\sfailures\sremain. +D 2012-12-07T21:02:47.824 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 690d441a758cbffd13e814dc2724a721a6ebd400 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -172,7 +172,7 @@ F src/pragma.c 015723c48072781d2740e310ab04dc92956b76d1 F src/prepare.c 931ad0d852a0df48f79adcba6ce79ca5f475625c F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c fd2206ae5c324d9539b97d402b7a957afac78307 +F src/resolve.c 34168dc9c5e7b388d0ce209dac16069263ae7ed7 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c eb3ded8d6ffcbab20dc3e65ba6a6dc13a01e7fbf F src/shell.c e392dd1ccbb77cc1d75a8367a89b473c24bea019 @@ -1025,7 +1025,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 972443b4eb282d45507da06c75e2cd46dd72326b -R addb1e849abbd533b321eb7c1f86638b +P f9fa7581c0371fe0feb4e97487741ade18595810 +R ffd541783cdf83fbb00a5f595a07c0f7 U drh -Z f47e0ce4e032364f0db26315f2eb73bb +Z c3f0cf345664d8221c8b35557e376692 diff --git a/manifest.uuid b/manifest.uuid index f24da198dd..88849058bd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9fa7581c0371fe0feb4e97487741ade18595810 \ No newline at end of file +49654453ad157693414c1f86fa3afa0918acffd4 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 6e5e2e7a9a..4b9d8fa145 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -129,6 +129,9 @@ static void resolveAlias( /* 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); @@ -824,7 +827,7 @@ static int resolveCompoundOrderBy( int iCol = -1; Expr *pE, *pDup; if( pItem->done ) continue; - pE = pItem->pExpr; + pE = sqlite3ExprSkipCollate(pItem->pExpr); if( sqlite3ExprIsInteger(pE, &iCol) ){ if( iCol<=0 || iCol>pEList->nExpr ){ resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr); @@ -842,11 +845,20 @@ 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{ + assert( pItem->pExpr->op==TK_COLLATE ); + assert( pItem->pExpr->pLeft==pE ); + pItem->pExpr->pLeft = pNew; + } sqlite3ExprDelete(db, pE); - pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0); - if( pE==0 ) return 1; - pE->flags |= EP_IntValue; - pE->u.iValue = iCol; pItem->iOrderByCol = (u16)iCol; pItem->done = 1; }else{