Another bug with queryExecute - Threads

This post is more than 2 years old.

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:

data = querynew(&quot;id&quot;, &quot;varchar&quot;, [{id:&quot;a&quot;}, {id:&quot;b&quot;}]);

cfthread(name=&quot;d1&quot;) {
	thread.result = queryExecute(&quot;select * from data&quot;, {}, {dbtype:&quot;query&quot;});
cfthread(name=&quot;d2&quot;) {
	var result = queryExecute(&quot;select sleep(2), title from tblblogentries limit 0,1&quot;, {}, {datasource:&quot;myblog&quot;}); = 1;
	thread.result = result;


<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:

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Sean Coyne posted on 10/9/2014 at 7:54 PM

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?

Comment 2 by Sean Coyne posted on 10/9/2014 at 7:56 PM

Oh, wait in the first example you assign it directly to the thread scoped variable and it still doesn't work. Never mind.

Comment 3 by Raymond Camden posted on 10/9/2014 at 8:04 PM

The thread block can use var scope.

Comment 4 by Michael Zock posted on 10/9/2014 at 9:08 PM

Have you tried whether it'll work if you pass the base query to the thread explicitly or through a tunnel (e.g., )?
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.

Comment 5 by Raymond Camden posted on 10/9/2014 at 9:16 PM

To your second part, it isn't a QofQ issue. I tried w/a QofQ and a 'real' query- same issue.

Comment 6 by Scott Jibben posted on 10/10/2014 at 2:04 PM

Could this go back to the internal query name (_queryname_var0) being the same for every call to queryExecute()?

Comment 7 by Raymond Camden posted on 10/10/2014 at 2:49 PM

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.