aboutsummaryrefslogtreecommitdiff
path: root/src/resolve.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2015-04-04 16:43:16 +0000
committerdan <dan@noemail.net>2015-04-04 16:43:16 +0000
commitb33c50f215b45acd1b6f47008562e64d895d3fba (patch)
treedc7c0350a48cc6ef85460ddf4a148bf6fc304863 /src/resolve.c
parent62ca61ee61c379af19b2dd64cab29081216d2140 (diff)
downloadsqlite-b33c50f215b45acd1b6f47008562e64d895d3fba.tar.gz
sqlite-b33c50f215b45acd1b6f47008562e64d895d3fba.zip
Fix a problem with resolving ORDER BY clauses that feature COLLATE clauses attached to compound SELECT statements.
FossilOrigin-Name: 427b50fba7362e5b447e79d39050f25ed2ef10af
Diffstat (limited to 'src/resolve.c')
-rw-r--r--src/resolve.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/resolve.c b/src/resolve.c
index 47df7243f..a7b14cd00 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -1186,6 +1186,20 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
sqlite3ResolveExprNames(&sNC, p->pOffset) ){
return WRC_Abort;
}
+
+ /* If the SF_Converted flags is set, then this Select object was
+ ** was created by the convertCompoundSelectToSubquery() function.
+ ** In this case the ORDER BY clause (p->pOrderBy) should be resolved
+ ** as if it were part of the sub-query, not the parent. This block
+ ** moves the pOrderBy down to the sub-query. It will be moved back
+ ** after the names have been resolved. */
+ if( p->selFlags & SF_Converted ){
+ Select *pSub = p->pSrc->a[0].pSelect;
+ assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy );
+ assert( pSub->pPrior && pSub->pOrderBy==0 );
+ pSub->pOrderBy = p->pOrderBy;
+ p->pOrderBy = 0;
+ }
/* Recursively resolve names in all subqueries
*/
@@ -1268,6 +1282,17 @@ static int resolveSelectStep(Walker *pWalker, Select *p){
sNC.pNext = 0;
sNC.ncFlags |= NC_AllowAgg;
+ /* If this is a converted compound query, move the ORDER BY clause from
+ ** the sub-query back to the parent query. At this point each term
+ ** within the ORDER BY clause has been transformed to an integer value.
+ ** These integers will be replaced by copies of the corresponding result
+ ** set expressions by the call to resolveOrderGroupBy() below. */
+ if( p->selFlags & SF_Converted ){
+ Select *pSub = p->pSrc->a[0].pSelect;
+ p->pOrderBy = pSub->pOrderBy;
+ pSub->pOrderBy = 0;
+ }
+
/* Process the ORDER BY clause for singleton SELECT statements.
** The ORDER BY clause for compounds SELECT statements is handled
** below, after all of the result-sets for all of the elements of