Wow, not a good morning for one of my favorite new features of ColdFusion 11. This morning I reported on a bug found with queryExecute by a user on StackOverflow. I did some more digging and found that if you use queryExecute inside a thread, it returns an undefined value. Here is a simple test case:
<cfscript>
data = querynew("id", "varchar", [{id:"a"}, {id:"b"}]);
cfthread(name="d1") {
thread.result = queryExecute("select * from data", {}, {dbtype:"query"});
}
cfthread(name="d2") {
var result = queryExecute("select sleep(2), title from tblblogentries limit 0,1", {}, {datasource:"myblog"});
thread.foo = 1;
thread.result = result;
}
cfthread(action="join",name="d1,d2");
writedump(cfthread);
</cfscript>
<cfdump var="#variables#" showudfs="false" >
In the code above I'm running two threads that use queryExecute. In the first thread the value of result is undefined. In the second thread it throws an error because result is not defined.
So, you can't use queryExecute inside a thread call. I've reported this here: https://bugbase.adobe.com/index.cfm?event=bug&id=3836820.
Archived Comments
have you tried without the var keyword? ie: instead of "var result = queryExecute" try "result = queryexecute"? Can you use the var keyword outside of functions now?
Oh, wait in the first example you assign it directly to the thread scoped variable and it still doesn't work. Never mind.
The thread block can use var scope.
Have you tried whether it'll work if you pass the base query to the thread explicitly or through a tunnel (e.g., http://www.bennadel.com/blo... )?
Maybe it's the way the QoQ tries to find and reference the base query that runs into problems after the code was changed to accommodate the new function.
To your second part, it isn't a QofQ issue. I tried w/a QofQ and a 'real' query- same issue.
Could this go back to the internal query name (_queryname_var0) being the same for every call to queryExecute()?
Well, that's what I was initially trying to see. I had looked up how to do a 'pause' in a query (MySQL makes this easy). I was trying to see if I had 2 queries running at once if it was possible for the result set to overwrite another one. I never got that far because of this bug.