查询多个订单的CF查询按语句添加最后排序的列进行选择

时间:2017-12-14 09:49:04

标签: coldfusion adobe sql-order-by qoq

我发现了ColdFusion query组件的一些非常奇怪的行为。 当您使用此组件构建另一个ColdFusion查询的查询(QoQ)查询并在多个列上使用order by时,order by列表中的最后一列将添加到所选输出中。 这似乎发生在CF9,10,11和2016,但不是在Lucee。

/* Create an unsorted CF-query */
unsorted = QueryNew("col1,col2,col3,col4","VarChar,VarChar,Integer,VarChar");
for (a=10;a gte 1;a--){
    QueryAddRow(unsorted);
    QuerySetCell(unsorted,"col1","col1 #a#");
    QuerySetCell(unsorted,"col2","col2 #a#");
    QuerySetCell(unsorted,"col3","#a#");
    QuerySetCell(unsorted,"col4","col4 #a#");
}

writeDump(var="#unsorted#");

/* Create a new CF query of query with the unsorted table */ 
sorted = new query(
    dbtype = "query"
    ,unsorted = unsorted
    ,sql = "select [col1],[col2] from unsorted order by [col3], [col4] asc"
    ).execute().getresult();

/* The last column in the order by list will be displayed in the result */  
writeDump(var="#sorted#", label="sorted");  

Try this on trycf.com 这是上次查询的结果:

    col1        col2        col4
1   col1 1      col2 1      1
2   col1 2      col2 2      2
3   col1 3      col2 3      3
4   col1 4      col2 4      4
5   col1 5      col2 5      5
6   col1 6      col2 6      6
7   col1 7      col2 7      7
8   col1 8      col2 8      8
9   col1 9      col2 9      9
10  col1 10     col2 10     10

这是Adobe CF的已知错误吗?

有没有人知道在ColdFusion QoQ中按多列排序的更好,更好的方式?

1 个答案:

答案 0 :(得分:0)

Alright, I reported the bug with Adobe: https://tracker.adobe.com/#/view/CF-4200408 and decided to work around the bug by using two QoQ's, seperating the ordering of the data and selecting of the columns, like so:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0){
        return arr.count; 
    }else if (section == 1{
        return arr1.count;
    }

    return arr2.count;
}

-(void)insertNewACell:(UIButton *)addButton atIndexPath:(NSIndexPath *)addBtnIndexPath
{

    newArray = [[NSMutableArray alloc]init];
   [newArray addObject:@"XXXX"];
   [newArray addObject:@"YYYY"];
   [newArray addObject:@"YYYY"];

   if(addBtnIndexPath.section)
    [arr addObject:newArray]
   }else if(addBtnIndexPath.section){
    [arr1 addObject:newArray]
   }else{
    [arr addObject:newArray]
   }

Of course, you'll take a big performance hit with this. There might be other solutions until Adobe fixes the bug themselves. For example, I found this ancient comment from Ben Nadel demonstrating where to find the code for the cfquery custom tag and figured that this code could be edited, if one were so inclined.