tracker issue : CF-4201825

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

[ANeff] Bug for: coldfusion.sql.QueryColumn coersion broken for function argument

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/AsDesigned

Reporter/Name(from Bugbase): Aaron Neff / ()

Created: 04/04/2018

Components: Language, Functions

Versions: 2016

Failure Type: Others

Found In Build/Fixed In Build: 2016.0.05.303689 /

Priority/Frequency: Normal /

Locale/System: / Platforms All

Vote Count: 0

Issue: When a coldfusion.sql.QueryColumn is passed into a function argument of type array, coersion is broken.

Repro:
{code:java}
<cfscript>
  q = queryNew("id", "integer", [[1],[2]]);
  function f(array myArg) {return [ARGUMENTS.myArg.getClass().getName(), ARGUMENTS.myArg];}
  if(isArray(q["id"])) {
    writeDump(f(q["id"]));//shorter and should work
    //writeDump(f(q.valueArray("id")));//unnecessary workaround
    //writeDump(f(arrayNew(1).append(q["id"], true)));//unnecessary workaround
  }
</cfscript>
{code}


Actual result: [coldfusion.sql.QueryColumn, 1]

Expected result: [coldfusion.sql.QueryColumn, [1,2]]

See? Argument type is array. But myArg only received the 1st cell value. It should've received all the cell values.

Since the current behavior is broken (an array is expected, but not received), backward-compat shouldn't be respected.

Attachments:

Comments:

<!--- These examples are likely related. These examples should return "1,2" instead of coldfusion.runtime.NonArrayException ---> <cfscript> q = queryNew("id", "integer", [[1],[2]]); //writeDump(arrayToList(q["id"]));//returns 1,2 (good) r = q["id"]; writeDump(r.getClass().getName());//returns coldfusion.sql.QueryColumn (good) writeDump(arrayToList(r));//throws "coldfusion.runtime.NonArrayException: Object of type class java.lang.Integer cannot be used as an array" (bad) </cfscript> <cfscript> array function f() { var q = queryNew("id", "integer", [[1],[2]]); return q["id"]; } //writeDump(arrayToList(f()));//returns "1,2" (good) r = f(); writeDump(f().getClass().getName());//returns coldfusion.sql.QueryColumn (good) writeDump(arrayToList(r));//throws "coldfusion.runtime.NonArrayException: Object of type class java.lang.Integer cannot be used as an array" (bad) </cfscript> See? Type remained coldfusion.sql.QueryColumn (good). So why do both exceptions say "Object of type class java.lang.Integer"?? coldfusion.sql.QueryColumn should cast to array, just like it does in myArray.append(query["column"], true). Thanks!, -Aaron
Comment by Aaron N.
27278 | April 04, 2018 05:58:14 AM GMT
q["id"] returns the currentRow's "id" column value, which in this case is the first row. This has been the existing behavior in CF 2016 as well. Changing this behavior will break backward compatibility.
Comment by Vijay M.
27511 | April 18, 2018 12:20:40 PM GMT
Hi Vijay, Regarding: q["id"] returns the currentRow's "id" column value Yes and no. It depends: q["id"] is the ValueArray(q, "id") shorthand since CF10 and earlier: <cfscript> q = queryNew("foobar", "", [["foo"],["bar"]]); a = []; arrayAppend(a, q["foobar"], true); writeDump(a);//returns ["foo","bar"] </cfscript> q["id"] allowed as array since CF10 or earlier: <cfscript> function f(array myArg) {//does not throw exception when myArg is q["id"] return ARGUMENTS.myArg; } q = queryNew("id", "integer", [[1],[2]]); writeDump(f(q["id"])); </cfscript> Thanks!, -Aaron
Comment by Aaron N.
27666 | May 04, 2018 09:08:48 PM GMT
Hi Vijay, I also see the backward-compat issue, so, yes, please disregard. Thanks!, -Aaron
Comment by Aaron N.
27667 | May 04, 2018 09:44:59 PM GMT