我发现了 ColdFusion 的一些非常奇怪的行为 query成分。
当您使用此组件构建另一个 ColdFusion Query 的查询 (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 中按多列排序的不同的更好的方法吗?
最佳答案
好的,我向 Adobe 报告了错误:https://tracker.adobe.com/#/view/CF-4200408并决定通过使用两个 QoQ 来解决该错误,将数据的排序和列的选择分开,如下所示:
/* 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");
selected = new query(
dbtype = "query"
,sorted = sorted
,sql = "select [col1],[col2] from sorted"
).execute().getresult();
当然,您会因此而受到很大的性能打击。在 Adobe 自行修复错误之前,可能还有其他解决方案。例如,我发现了这个 ancient comment来自 Ben Nadel 演示了在哪里可以找到 cfquery 自定义标记的代码,并认为可以编辑此代码,如果有人愿意的话。
关于coldfusion - CF Query of Query multiple order by 语句添加最后一个有序列来选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47810316/