Skip to main content
elisabethf82215657
Inspiring
September 28, 2021
質問

query(querycolumn).toArray() broken

  • September 28, 2021
  • 返信数 3.
  • 1532 ビュー

We updated our Coldfusion 2018 installations to the recent version 12.

After this update code of the form <queryname>("<querycolumn>").toArray(), which worked the way ValueArray(x,x) worked before, is broken.
Is there any way to get compatibility here or do we have to change the application?

    このトピックへの返信は締め切られました。

    返信数 3

    BKBK
    Community Expert
    Community Expert
    September 28, 2021
    quote

    After this update code of the form <queryname>("<querycolumn>").toArray(), which worked the way ValueArray(x,x) worked before, is broken.


    By @elisabethf82215657

     

    Uhrm, do you mean something like the following?

     

    <cfset myQueryColumnArray=myQuery("myColumn").toArray()>

     

    If so, then I can see why ColdFusion doesn't tolerate this any longer. When you write it like that, you immediately see that it is incorrect CFML code. It is ambiguous to start with. It suggests that myQuery is a function that accepts as argument the string"myColumn". Which doesn't make sense.

     

    It is what is usually called an undocumented method. The fact that it worked in the past doesn't necessarily make it OK. In general, ColdFusion changes for the better. So it would have dropped whatever it was that made that query code to work in the past. For the sake of improving the language.

     

    My guess is that that line of code is one of the vestiges of Flex or Actionscript integration in ColdFusion. For example, take a look at Actionscript's mx.utils package. You can see there that toArray() is a method in the ArrayUtil class.

     

    Which gives us a clue. Flex Remoting has officially been retired from ColdFusion as of ColdFusion 2018, and Flex Integration has been removed from ColdFusion 2021.

     

    To cut a long story short, just use the documented method, valueArray().

     

     

     

     

     

    elisabethf82215657
    Inspiring
    September 29, 2021

    And so we did (as written above).

    Thanks for your elaboration. Unfortunately I made a mistake when creating the post in the first hand.

    The broken old syntax has no ambiguity to functions, it was query[columname].toArray().

    Where this came from in the first hand I do not know, our application had a number of developers in the past.

    We changed all occurences of this syntax to ValueList and now everything seems to work.

    BKBK
    Community Expert
    Community Expert
    September 29, 2021

    Ah, thanks for the addition. The code,

     

     

    <cfset myQueryColumnArray=myQuery["myColumn"].toArray()>

     

     

    fares better. The part myQuery["myColumn"] is correct CFML code. It will give you the data in myColumn in the first row of the myQuery result-set.

     

    However, toArray is still out of place. For the reason I gave before: possibly because your predecessors used legacy Flex/Actionscript.

     

    Even if we ignore the legacy argument, we will still have trouble using toArray. For, suppose the data-type of myColumn is int. Then myQuery["myColumn"] will belong to the class java.lang.Integer. ( You can verify this by dumping myQuery["myColumn"].getClass().getName() ). If myColumn is varchar type, representing email, for example, then myQuery["myColumn"] will belong to the class java.lang.String. If it's a date, the corresponding class will be java.util.Date.

     

    If you examine the API of the classes java.lang.Integer and java.util.Date, you will find no method that returns an array. In the java.lang.String API, the only methods that return an array are getBytes(), split() and toCharArray(). None of them does what we expect toArray() to do. We therefore have to conclude that toArray() is probably not CFML, which would explain why it fails in ColdFusion 2018.

     

    elisabethf82215657
    Inspiring
    September 28, 2021

    We now have fixed all uses of the toArray function on a query-column  by using ValueArray and so the problem is fixed for us. Nevertheless I would like to know why this worked earlier and now is broken.

    BKBK
    Community Expert
    Community Expert
    September 29, 2021
    quote

    ... I would like to know why this worked earlier and now is broken.


    By @elisabethf82215657

     

    I hope you are satisfied with my answer.

     

     

    We now have fixed all uses of the toArray function on a query-column  by using ValueArray and so the problem is fixed for us.

     

    Good move. All's well that ends well. 🙂

    Charlie Arehart
    Community Expert
    Community Expert
    September 28, 2021

    It may not be the toarray but rather what's in the query that's broken. If that query is fed by a query of queries, yes there's a bug with that in the Sept updates, and yes Adobe has a fix. Email them at cfsup@adobe.com to ask for it, which will includes simple steps to apply the fix. 

    /Charlie (troubleshooter, carehart. org)
    elisabethf82215657
    Inspiring
    September 28, 2021

    Thanks Charlie, but the query of query bug is already installed on our servers! I think it really is the toArray function. The Error message is: the toArray() method was not found
    MethodSelectionException

    elisabethf82215657
    Inspiring
    September 28, 2021

    of course the fix is installed, not the bug 🙂