queryAddRow() treats struct of arrays different than Adobe

Description

QueryAddRow(), and the third param to queryNew() will accept the following

  • An array of values (placed positionally in the new single row)

  • A struct of values (placed via key name matching column name in a single row)

  • An array of structs (One new query row per array item, each struct added like bullet #2

  • A struct of arrays (placed via key name matching column name, one row per array value)

The last bullet is a source of issue (and doesn’t seem to be documented anywhere) as it has a different behavior than Adobe CF and cannot be used to set an actual array into a single column cell, which is valid and supported by functions such as querySetCell().

The following code shows the difference of behaviors between Adobe and Lucee

https://trycf.com/gist/86d6f4c1fe54baa964055d0ac61042ec/lucee5?theme=monokai

qry = queryNew( "name,items","varchar,object" ) qry.addRow( 1 ) qry.setCell( 'name', 'Brad' ) qry.setCell( 'items', [ 1, 2, 3 ] ) qry.addRow( { 'name' : 'Luis', 'items' : [ 4, 5, 6 ] } ); writedump( qry )

Adobe only has two rows in the query when it’s done, but Lucee has 4 rows in the query as it breaks out Luis' “items” into separate rows.

Since Lucee’s docs don’t actually document this last behavior, I’m tempted to say perhaps it should be removed, or AT LEAST not attempted if not all the struct values contain arrays of the same length. But if there are for sure people using the behavior, then at least this ticket can serve as documentation of the difference.

Attachments

1
  • 29 Mar 2022, 06:17 am

Activity

Show:

Adam Cameron 29 March 2022 at 14:52

I would say don’t even worry if “Is anyone actually using this” because - as you say - it’s not documented, so it’s on them if they used it. It’s also just not valid, is it? A struct in this usage should reflect the values for one row, irrespective of the values for the columns within the struct.

Brad Wood 29 March 2022 at 14:02

Wow, funny that I didn’t find the other ticket and I’m the person who put it in! 5 years ago… confused face

Thanks for the pull, but I’m inclined to think that querynew() and queryAddRow() should behave the same. The better question is whether the struct of arrays for multiple rows is really a valid and supported option since it's not actually documented anywhere I can find. Is anyone actually using this or can it just go away everywhere?

Pothys - MitrahSoft 29 March 2022 at 10:31

I’ve created a patch with the changes done in https://luceeserver.atlassian.net/browse/LDEV-1206
PR for Lucee-5.3: https://github.com/lucee/Lucee/pull/1609

Pothys - MitrahSoft 29 March 2022 at 06:17
Edited

Already we have a ticket for this issue https://luceeserver.atlassian.net/browse/LDEV-1206 and it was fixed in lucee 6.0.

Duplicate

Details

Assignee

Reporter

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Sprint

Priority

Created 29 March 2022 at 02:00
Updated 9 June 2023 at 16:44
Resolved 9 June 2023 at 16:44

Flag notifications