tracker issue : CF-4204019

select a category, or use search below
(searches all categories and all time range)
Title:

Unable to assign result of a QueryExecute to a bracket style variable reference

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/MustFix

Reporter/Name(from Bugbase): Isaiah F. / ()

Created: 02/12/2019

Components: Core Runtime, Parser/Compiler

Versions: 2016,11.0,2018

Failure Type: Others

Found In Build/Fixed In Build: 11,0,16,313933 / 313973

Priority/Frequency: Normal /

Locale/System: / Linux Ubuntu 14.04

Vote Count: 6

Problem Description: Assigning the result of a QueryExecute directly to a bracket style variable reference results in an exception in the compiler.

Steps to Reproduce:
{code:java}
<cfset rs = QueryNew('col', 'integer', [[1]])>
<cfset vrs = {}>
<cfset vrs['foo'] = QueryExecute("select * from rs", {}, {dbtype = 'query'})>
<cfdump var="#vrs#">
{code}

Actual Result:
The CFML compiler encountered an unexpected java.lang.ClassCastException exception. 
The reason for this was: coldfusion.compiler.ASTarrayReference cannot be cast to coldfusion.compiler.ASTsimpleVariableReference Occurred at:

java.lang.ClassCastException: coldfusion.compiler.ASTarrayReference cannot be cast to coldfusion.compiler.ASTsimpleVariableReference
	at coldfusion.compiler.Treewalker.postorder(Treewalker.java:90)
	at coldfusion.compiler.Treewalker.postorder(Treewalker.java:27)
	at coldfusion.compiler.Treewalker.postorder(Treewalker.java:27)
	at coldfusion.compiler.NeoTranslator.parseAndTransform(NeoTranslator.java:459)
	at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:391)
	at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:160)
	at coldfusion.runtime.TemplateClassLoader$TemplateCache$1.fetch(TemplateClassLoader.java:461)
	at coldfusion.util.LruCache.get(LruCache.java:180)
	at coldfusion.runtime.TemplateClassLoader$TemplateCache.fetchSerial(TemplateClassLoader.java:387)
	at coldfusion.util.AbstractCache.fetch(AbstractCache.java:58)
	at coldfusion.util.SoftCache.get_statsOff(SoftCache.java:133)
	at coldfusion.util.SoftCache.get(SoftCache.java:81)
at coldfusion.runtime.TemplateClassLoader.findClass(TemplateClassLoader.java:642)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:138)
	at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:78)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
	at coldfusion.CfmServlet.service(CfmServlet.java:219)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:458)
	at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:196)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

Expected Result:
A dump showing the struct with a key `foo` that has a query with one row, with one column `col` with a value of `1`

Any Workarounds:
Assign the value of the `QueryExecute` to a normal variable, then assign that variable to the bracket style variable reference. E.g.

{code:java}
<cfset rs = QueryNew('col', 'integer', [[1]])>
<cfset vrs = {}>
<cfset tmp = QueryExecute("select * from rs", {}, {dbtype = 'query'})>
<cfset vrs['foo'] = tmp>
<cfdump var="#vrs#">
{code}

Attachments:

Comments:

This is also an issue on CF2018
Vote by Peter F.
30237 | February 12, 2019 08:31:55 PM GMT
I suspect this is due to the "fix" for CF-4200137 which was just included in the latest updates.
Comment by Kama S.
30239 | February 13, 2019 12:51:49 AM GMT
Hello Everyone, We were able to repro this issue at our end. This issue is fixed now for all versions of ColdFusion server. Please contact [cfsup@adobe.com|mailto:cfsup@adobe.com] to get the patch for this issue and the steps on how to apply the patch. -Nimit Sharma ColdFusion Team
Comment by Nimit S.
30241 | February 13, 2019 04:59:41 PM GMT
The fix does not work. I've added a stack trace and sample code that fails every time it's tried, but it used to work.
Comment by Wil G.
30245 | February 13, 2019 09:56:12 PM GMT
Wil about your comment (on the 13th), are you saying that you got the patch which Nimit offered that day (to be put on top of the CF update released on the 12th), and that even with that patch applied (and CF restarted), your code attempt still failed? (BTW, the code offered in your attachment doesn't run as-is, did you? It does not, but because of other reasons. Maybe it was just meant as a fragment, though.)
Comment by Charlie A.
30323 | February 18, 2019 10:31:37 PM GMT
For folks who may have been pointed to this bug report, about "the issue with queryexecute as per the Feb CF update", I will note that the problem is really quite specific, as Isaiah has reported here. It's not that the update "broke queryexecute" (meaning ALL uses of the function, which is indeed how some resources on the web are are characterizing this, either explicitly or implicitly). Instead, note how it's identified here as being specifically when the queryexecute result is assigned to a bracket-notated variable. That's pretty darn particular. :-) And as Isaiah proposes, one workaround would be to use an intermediate variable to hold the result which is THEN assigned to the bracketed one. Now, some may well wonder, why not just use this instead (for his example): <cfset vrs.foo = QueryExecute("select * from rs", {}, {dbtype = 'query'})> And that would indeed not "error" with the current update, but it may not "work" for folks as a workaround: the point of bracketed notation is really for when you do NOT know the name of the variable and may be determining it dynamically, such that what's in the brackets may be a variable whose value (the name of the key within the named struct or scope to be created) may be coming from a db lookup or form field, etc. FWIW, I have noticed that the cffiddle site seems to have gotten that patch, because now even Isaiah's original code does work there: https://cffiddle.org/app/file?filepath=cce2a84b-7ce9-413a-bade-038227b7d7f8/a11916c9-39d7-4aa8-ac36-75bea6119309/a406de52-49b7-4126-a4e7-ad19e78951b0.cfm That's encouraging, as it seems to confirm that they have the fix in place, and one can get it from Nimi (via that cfsup address above), or hopefully there will be a new or corrected update at some point.
Comment by Charlie A.
30324 | February 18, 2019 10:46:22 PM GMT
The patch they gave us on the 13th failed to work. The patch they gave us on the 14th does work. I've yet to see an official patch as part of an official update. The reason the code snippet I sent isn't working is it's expecting a default datasource defined in the Application. This code still does not work unless the manual hot fix is applied. Not that this is not using a bracket-notated variable. Both have been tested on ColdFusion 2016 update 8 without the manual hot fix applied and then with the manual hot fix applied. component output="false" { public query function getRoles() { var myvars = {}; var userRoles =''; var myvars.sql = "SELECT roleId, roleName FROM userRole ORDER BY roleID"; userRoles = queryExecute(myvars.sql,{},{datasource="mydatasource"}); return userRoles; } } Same for this way with using a simple variable. component output="false" { public query function getRoles() { var userRoles =''; var sql = "SELECT roleId, roleName FROM userRole ORDER BY roleID"; userRoles = queryExecute(sql,{},{datasource="mydatasource"}); return userRoles; } }
Comment by Wil G.
30325 | February 18, 2019 11:12:42 PM GMT
My first code example above is incorrect. It should be this. Testing was done on CF2016u8 without and with the manual hot fix jar file. Without the hot fix this does not work. Between testing I stopped CF16, deleting the files in the cfclasses folder and started cf16 again and then deleting the files in the cfclasses folder again. (strangely enough the files return when you start CF16.) component output="false" { public query function getRoles() { var myvars = {}; var userRoles =''; var sql = "SELECT roleId, roleName FROM userRole ORDER BY roleID"; myvars.userRoles = queryExecute(sql); return myvars.userRoles; } }
Comment by Wil G.
30326 | February 19, 2019 12:17:21 AM GMT
Unfortunately, the INSERT opeeration also fails. This example from CFDocs used to work: queryExecute( "INSERT INTO employee ( firstname ) VALUES ( :firstname )", { firstname = { value="Han", cfsqltype="varchar" } }, { result="employee" } ); Now its coming up with error: "Complex object types cannot be converted to simple values." But if you take out the 3rd parameter {result="employee"} it works! Please fix! -Alberto
Vote by Labe N.
30382 | February 23, 2019 12:51:52 PM GMT
Sorry to repeat myself but need to correct my previous text and script. Unfortunately, the INSERT operation also fails. This example from CFDocs used to work: queryExecute( "INSERT INTO employee ( firstname ) VALUES ( :firstname )", { firstname = { value="Han", cfsqltype="varchar" } }, {datasource="myDataSourceName"}, { result="employee" } ); Now its coming up with error: "Complex object types cannot be converted to simple values." But if you take out the 3rd argument {result="employee"} it works! -Alberto Comment by Labe N.
Comment by Labe N.
30383 | February 24, 2019 07:37:35 AM GMT
Apologies.. my bad - sorry, nothing wrong with the INSERT. My script is incorrect as it has 4 arguments instead of 3. All good now.
Comment by Labe N.
30392 | February 26, 2019 05:47:39 AM GMT
This issue is fixed now. The fix for this issue will be available as part of ColdFusion 2018 Update 3, ColdFusion 2016 Update 9 and ColdFusion 11 Update 17. -Nimit
Comment by Nimit S.
30500 | March 13, 2019 06:05:17 PM GMT