ColdFusion Query Argument Reference Can Be Confusing

Posted July 5, 2006 at 9:41 AM

Tags: ColdFusion

I was experimenting with a QueryAppend() function when I came across an interesting caveat to query variables. In ColdFusion, queries are passed around by reference. That is, if you pass a query to a method, such as QueryAddRow(), no query is returned because the original query object is updated by reference; however, this does not always seem to be the case. In my experimentation, I found that QueryAddRow() did in fact update the original query:

 Launch code in new window » Download code as text file »

  • <cfset QueryAddRow( ARGUMENTS.QueryOne ) />

... but, changing the pointer of the query did NOT change the original reference:

 Launch code in new window » Download code as text file »

  • <cfset ARGUMENTS.QueryOne = 3 />

This one leaves the original query alone and only affects the local variable, ARGUMENTS.QueryOne. I am sure this has to due with when the variable value is dereferenced or evaluated, but it seems to be a bit confusing.

Download Code Snippet ZIP File

Comments (0)  |  Post Comment  |  Ask Ben  |  Permalink  |  Other Searches  |  Print Page



I'm Too Young For This!

Reader Comments

There are no comments posted for this web log entry.


Post Comment  |  Ask Ben


Home   |   Web Log   |   ColdFusion   |   Projects   |   Resume   |   Job Form   |   Search   |   Contact
Epicenter Consulting - Custom Software Solutions for Business Evolution HostMySite.com - The Leader In ColdFusion Hosting