Query Reference Data and CFCs
I would to run a query once that returns a record set and pass that as reference data to functions in a ColdFusion component. Inside those functions, I'd take the query and run a query of queries for aggregate results among other things. Can this be done? I am getting an error basically saying the passed-in query is not a simple value where I use it in the FROM clause of the query.
It works fine when both queries are within the same function, but it's needless overhead to continually get the same ref data.
Example:
template.cfm
-------------------
...
<cfobject name="lib" component="mycfc">
<cfinvoke component="#lib#" method="getQueryRefData" returnvariable="refData" />
<cfinvoke component="#lib#" method="getSum" returnvariable="sum" refdata="#refData#" />
...
mycfc.cfc
--------------
...
<cffunction name="getQueryRefData" access="public" returntype="query">
<cfquery name="allData" datasource="myDatasource">
SELECT * FROM answer
</cfquery>
<cfreturn allData>
</cffunction>
<cffunction name="getSum" access="public" returntype="numeric">
<cfargument name="refData" type="query" required="yes">
<cfquery name="deptSum" dbtype="query">
SELECT COUNT(*) AS total, department
FROM ARGUMENTS.refData <--- ERROR occurs here --->
GROUP BY department
</cfquery>
<cfreturn Val(deptSum.total)>
</cffunction>
...
