I don't do alot of Query of Queries and when I do I often forget that you can escape special reserved words. One of those words is local.
With ColdFusion 9's local scope this is likely to come up if you name the first query local.someQuery and try to QoQ that it wont work unless you escape local as so:
[local].someQuery
We had to do this anyway as we always used to do:
< cfset var local = {} /> prior to CF9.
While making an example I wanted to write this in tags and in pure script. QoQ in script proved a challenge I thought it would just work but it actually needs an additional line:
local.qoq.setAttributes(resultSet = local.qryRes.getResult());
where local.qoq is the new query object and local.qryRes is the original query.
I tried for a while and knew I had seen this in action once but I could not work it out. I had a quick chat with Dave Ferguson who pointed me in the right direction.
Here is an example:
Click here to run the code.
Tag based cfc:
Script based cfc:
Hi Paul,
ReplyDeleteI thought I was the only one bumped into this strange behaviour with the local scope in QoQ's. The most strange thing I find is that the variables scope works perfectly, but the local not, without escaping :s
Rainer
@rainerschreiber
this post saved me a good deal of headaches.
ReplyDeleteI didn't even know you could escape scopes in QoQ.
Thanks.