query.map mishandles the "template" query

Description

See http://blog.adamcameron.me/2017/04/cfml-lucee-13-v-4-14-v-6-coldfusion-we.html

Query.map and queryMap take a parameter of type query which specifies the definition of the query that should be returned. This is not uses properly in two ways, as demonstrated by this test case:

describe("map tests", function(){ var numbers = duplicate(baseNumbers); var remapTemplate = queryNew("value,english,maori"); var reMapped = numbers.map(function(row){ return {value=row.id, english=row.en, maori=row.mi}; }, remapTemplate); it("does a basic remapping", function(){ var queryWithDifferentColumns = queryNew("value,english,maori", "integer,varchar,varchar", [ [1,"one","tahi"], [2,"two","rua"], [3,"three","toru"], [4,"four","wha"] ]); expect(reMapped).toBe(queryWithDifferentColumns); }); it("does not mess with the remapTemplate", function(){ expect(remapTemplate).toBe(queryNew("value,english,maori")); }); });

Both of these fail:

  • the columns from queryWithDifferentColumns should be the only columns in the resultant query. however these columns are just added to the original query

  • the queryWithDifferentColumns should not change: it's just a template. However it seems this is replaced by the remapped query.

Contrast this with CF on which both tests pass.

Environment

None

Activity

Show:

Adam Cameron 5 May 2017 at 12:41
Edited

And to be clear - I was part of the discussions for the spec for queryMap - the CF behaviour with the "remapping query template" is very deliberate. It is only there to provide the schema for the returned query. Nothing else.

(thanks for looking into this, btw)

Pothys - MitrahSoft 5 May 2017 at 10:49

I've added test case for this ticket & confirmed the issue. If we map the original query to remapping query template, resultant queryMap added the column of original query, but it shouldn't in ACF. Also remapping query template value replaced with resultant mapped query. In ACF there is no changes on remapping query template.

Pull request: https://github.com/lucee/Lucee/pull/226

Fixed

Details

Assignee

Reporter

Priority

Fix versions

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

Affects versions

Created 2 May 2017 at 08:32
Updated 7 May 2018 at 15:00
Resolved 7 May 2018 at 15:00