/ Check-in [49654453]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the processing of ORDER BY clauses with COLLATE terms on compound queries. 52 veryquick test failures remain.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ticket-71e333e7
Files: files | file ages | folders
SHA1: 49654453ad157693414c1f86fa3afa0918acffd4
User & Date: drh 2012-12-07 21:02:47
Context
2012-12-07
22:18
Fix a long-standing issue with the distinct-as-aggregate optimization that only expressed when the new collating-sequence logic is turned on. check-in: 0aaf52a3 user: drh tags: ticket-71e333e7
21:02
Fix the processing of ORDER BY clauses with COLLATE terms on compound queries. 52 veryquick test failures remain. check-in: 49654453 user: drh tags: ticket-71e333e7
20:31
Many more tests are passing. Only about 100 failures remain in veryquick. check-in: f9fa7581 user: drh tags: ticket-71e333e7
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

   125    125       pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
   126    126     }
   127    127   #endif
   128    128   
   129    129     /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 
   130    130     ** prevents ExprDelete() from deleting the Expr structure itself,
   131    131     ** allowing it to be repopulated by the memcpy() on the following line.
          132  +  ** The pExpr->u.zToken might point into memory that will be freed by the
          133  +  ** sqlite3DbFree(db, pDup) on the last line of this block, so be sure to
          134  +  ** make a copy of the token before doing the sqlite3DbFree().
   132    135     */
   133    136     ExprSetProperty(pExpr, EP_Static);
   134    137     sqlite3ExprDelete(db, pExpr);
   135    138     memcpy(pExpr, pDup, sizeof(*pExpr));
   136    139     if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
   137    140       assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
   138    141       pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
................................................................................
   820    823       moreToDo = 0;
   821    824       pEList = pSelect->pEList;
   822    825       assert( pEList!=0 );
   823    826       for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
   824    827         int iCol = -1;
   825    828         Expr *pE, *pDup;
   826    829         if( pItem->done ) continue;
   827         -      pE = pItem->pExpr;
          830  +      pE = sqlite3ExprSkipCollate(pItem->pExpr);
   828    831         if( sqlite3ExprIsInteger(pE, &iCol) ){
   829    832           if( iCol<=0 || iCol>pEList->nExpr ){
   830    833             resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
   831    834             return 1;
   832    835           }
   833    836         }else{
   834    837           iCol = resolveAsName(pParse, pEList, pE);
................................................................................
   838    841               assert(pDup);
   839    842               iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
   840    843             }
   841    844             sqlite3ExprDelete(db, pDup);
   842    845           }
   843    846         }
   844    847         if( iCol>0 ){
          848  +        /* Convert the ORDER BY term into an integer column number iCol,
          849  +        ** taking care to preserve the COLLATE clause if it exists */
          850  +        Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
          851  +        if( pNew==0 ) return 1;
          852  +        pNew->flags |= EP_IntValue;
          853  +        pNew->u.iValue = iCol;
          854  +        if( pItem->pExpr==pE ){
          855  +          pItem->pExpr = pNew;
          856  +        }else{
          857  +          assert( pItem->pExpr->op==TK_COLLATE );
          858  +          assert( pItem->pExpr->pLeft==pE );
          859  +          pItem->pExpr->pLeft = pNew;
          860  +        }
   845    861           sqlite3ExprDelete(db, pE);
   846         -        pItem->pExpr = pE = sqlite3Expr(db, TK_INTEGER, 0);
   847         -        if( pE==0 ) return 1;
   848         -        pE->flags |= EP_IntValue;
   849         -        pE->u.iValue = iCol;
   850    862           pItem->iOrderByCol = (u16)iCol;
   851    863           pItem->done = 1;
   852    864         }else{
   853    865           moreToDo = 1;
   854    866         }
   855    867       }
   856    868       pSelect = pSelect->pNext;