在ColdFusion中可以动态生成查询名称吗? [英] Is it possible to have dynamically generated query names in ColdFusion?
问题描述
我想做的是
<cfloop array="#LOCAL.someArray" index="LOCAL.aString">
<cfset LOCAL.queryName = "uniqueQueryName_" & LOCAL.aString />
<cfquery name="#LOCAL.queryName#" datasource="db" cachedwithin="#CreateTimeSpan(1,0,0,0)#">
SELECT count(*) AS c FROM someTable
</cfquery>
<cfdump var="#LOCAL.queryName#" />
</cfloop>
这是否可能,或者有更好的方法吗?
is this possible, or is there a better way to do it?
编辑
这与< cfloop query = LOCAL.queryName >
,但是当我尝试执行< cfset ArrayAppend(LOCAL.returnArray,LOCAL.queryName.c)/>
This works with <cfloop query="LOCAL.queryName">
but not when I try to do <cfset ArrayAppend(LOCAL.returnArray, LOCAL.queryName.c) />
推荐答案
不需要使用 evaluate()
来完成,
您需要做的就是使用关联数组符号:
All you need to do is use associative array notation:
<cfdump var="#local[qname]#">
如果要访问该查询的列,则为:
If one wants to access a column of that query, it's:
#local[qname][columnName]#
对于一个特定的单元格:
And for a specific cell:
#local[qname][columnName][rowNumber]#
在极少数情况下, evaluate()
是任何事情的正确答案。一个人不能依赖Adobe文档,因为-不幸的是-绝大部分不是由经验丰富的ColdFusion开发人员编写的。
There are very very very few situations in which evaluate()
is the correct answer to anything. One cannot rely on the Adobe docs because - unfortunately - an awful lot of it was not written by very experienced ColdFusion developers.
这篇关于在ColdFusion中可以动态生成查询名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!