What happened to the variables I set?
Here's a question for everyone out there.
I created a query:
<cfquery dbtype="query" name="companyInfo">
SELECT *
FROM companyList
WHERE companyId = #url.companyId#
</cfquery>
SELECT *
FROM companyList
WHERE companyId = #url.companyId#
</cfquery>
Then without really thinking tried to set some new variables so my page wouldn't error out:
<cfset companyInfo.newVariableOne = "">
<cfset companyInfo.newVariableTwo = "">
<cfset companyInfo.newVariableTwo = "">
I did a CFDUMP of companyInfo, and it dumps the query result without the additional variables. What exactly happened to the new variables? If I try to declare the structure with a StructNew() it overwrites the query.
Now before anyone gets anxious, I realize you can't set a static variable like this into a complex object type, especially a query. I'd have to create the new column in the query, and specify what row this value is for, and blah blah blah.
I'm just curious if anyone knows how Coldfusion handles this situation, and how I would retrieve a static value set like this. Thanks.


<cfset var returnStruct = StructNew() />
<cfquery dbtype="query" name="returnStruct .queryObj">
SELECT c1,c2,c3
FROM companyList
WHERE c1 = <cfqueryparam value="#url.companyId#" cfsqltype="cf_sql_bigint">
</cfquery>
<cfset returnStruct.newVariable = "foo">
<cfset returnStruct.otherVariable = "bar">
<cfscript>
request.foo=structnew();
request.foo.var1="";
request.foo.var2="";
</cfscript>
then run your query, giving it the name request.foo.myQuery;
Then you could retyrn the struct with the query, plus the key value pairs.
It just comes down to careful coding, as not to reuse variable names. A good naming convention would help... "qryName" or "qry_Name", for example, would let you know that it's a query and you can't assign new variables as if it were a structure.