var scope of query in cfc
I made a silly code error. I admit it. In my CFC I had queries without var scoping them. The result was some rather crazy errors for one client. To my credit I had properly scoped and locked my loading of the cfc and its init vars, etc. Why didn't I? Not sure why but it just didn't occur to me that I needed to. Makes sense now of course. A handy guide to scoping in CFC was made by Ray Camden for those that need more general info.
The code as it was works very well as is on my server and all our clients servers. All but one. At first it was maddening to determine just what the issue was. Then I found out the client web server was a P2 400mhz 512mb Ram. Yes you read that right. So basically each request was quite slow. Very easy to have heavy load on the server and thus for the vars to swap data, etc. Something I couldn't reproduce on any other server was easily reproducible on theirs.
So to recap I did:
<cfquery name="GetData" datasource="blah">
Select MyField
From MyTable
</cfquery>
<cfreturn getData />
</cffunction>
Because GetData wasn't specifically scoped it was by default in the variables scope and GetData then lived throughout the entire CFC and swapped data and all kinds of bad things.
I should have done:
<cfset var GetData = "">
<cfquery name="GetData" datasource="blah">
Select MyField
From MyTable
</cfquery>
<cfreturn getData />
</cffunction>
This blog post is to help me remember to not do that again. Bad josh. bad. :-)
Like this entry? Subscribe to my blog.


Comments (moderation on)
Also check out varscper - very useful
http://www.schierberl.com/cfblog/index.cfm/2006/7/...
Looks like a great tool. Good to have those in your arsenal just in case. :-)