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>

Then without really thinking tried to set some new variables so my page wouldn't error out:

<cfset companyInfo.newVariableOne = "">
<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.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Don Q's Gravatar I've done this inside a method before..
<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">
# Posted By Don Q | 2/27/08 11:48 AM
Jeff's Gravatar Have you tried QueryAddColumn()?
# Posted By Jeff | 2/27/08 12:18 PM
David Garthe's Gravatar I'm not actually trying to do add a value to the query result with this code, I'm just wondering what happens to the value set, and how would you access it?
# Posted By David Garthe | 2/27/08 12:42 PM
Tom K's Gravatar Could you do:
<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.
# Posted By Tom K | 2/28/08 3:08 AM
Rob O's Gravatar From some quick testing, it seems as if CF just quietly discards your attempt to set those variables. No error. No indication at all that the CFSET failed.

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.
# Posted By Rob O | 6/23/08 12:38 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.