QueryMap()

I am doing through all the query functions and creating example to help me
learn and also to add as example to http://docs.lucee.org/

But am having issues with QueryMap()

As I read it http://docs.lucee.org/reference/functions/querymap.html, the
returned struct is used to populate the new query, but I am just getting
the original query

​It would seem that you can only change the value of existing query fields
not:

  • create a new query
  • add a new column

Is this the case?


try {
qryPeople = queryNew(“name,dob”,“varchar,date”,[[“Susi”,
CreateDate(1970,1,1)],[“Urs”,CreateDate(1995,1,1)],[“Fred”,
CreateDate(1960,1,1)],[“Jim”, CreateDate(1988,1,1)]]);

// map dob to age
qryPeopleAge = qryPeople.map(function(row, rowNumber, qryData){
row[‘age’] = DateDiff(‘yyyy’, row.dob, Now());
dump(var=row, abort=false);
return row;
});
dump(var=qryPeopleAge, label=‘map() - map dob to age’);

} catch (any error) {
dump(var=error, abort=true);

}
​–

AJ Mercer
<webonix:net strength=“Industrial” /> http://webonix.net | <webonix:org
community=“Open” /> http://webonix.org
http://twitter.com/webonix

If I change your code to set the dob field to the age, it works:

row[‘dob’] = DateDiff(‘yyyy’, row.dob, Now());

Apparently there is no mechanism in the underlying implementation to add a
query column on the fly. (Might be convenient if there would be …)

According to the above, your example should work if you add an empty age
column to the original query.

Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamediaOn Wed, Sep 23, 2015 at 4:53 AM, AJ Mercer <@AJ_Mercer> wrote:

I am doing through all the query functions and creating example to help me
learn and also to add as example to http://docs.lucee.org/

But am having issues with QueryMap()

As I read it http://docs.lucee.org/reference/functions/querymap.html,
the returned struct is used to populate the new query, but I am just
getting the original query

​It would seem that you can only change the value of existing query fields
not:

  • create a new query
  • add a new column

Is this the case?


try {
qryPeople = queryNew(“name,dob”,“varchar,date”,[[“Susi”,
CreateDate(1970,1,1)],[“Urs”,CreateDate(1995,1,1)],[“Fred”,
CreateDate(1960,1,1)],[“Jim”, CreateDate(1988,1,1)]]);

// map dob to age
qryPeopleAge = qryPeople.map(function(row, rowNumber, qryData){
row[‘age’] = DateDiff(‘yyyy’, row.dob, Now());
dump(var=row, abort=false);
return row;
});
dump(var=qryPeopleAge, label=‘map() - map dob to age’);

} catch (any error) {
dump(var=error, abort=true);

}

AJ Mercer
<webonix:net strength=“Industrial” /> http://webonix.net | <webonix:org
community=“Open” /> http://webonix.org
http://twitter.com/webonix


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your
ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/CAPURtC3uhhK8cdbfdCXnFgeBH4s%3DD7%3DCQH-xp1o-M%3DCw-xKygQ%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAPURtC3uhhK8cdbfdCXnFgeBH4s%3DD7%3DCQH-xp1o-M%3DCw-xKygQ%40mail.gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

yeah - would seem my understanding of map() was incorrect.

Thanks for repliesOn 23 September 2015 at 20:30, Nando Breiter <@Nando_Breiter> wrote:

On second thought, adding a query column on the fly via a struct might be
problematic, because a query is a grid, whereas a struct can have an
arbitrary number of keys. There is nothing to prevent code within the map
function to have conditionally adds a key so that only some rows would have
the added column, which doesn’t make sense in query-land. So although it
might be convenient to add a query column on the fly, it would probably
necessitate an underlying implementation that is not efficient - “opps, we
don’t have that column, let be go back and add it and then start again”

Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

On Wed, Sep 23, 2015 at 2:21 PM, Nando Breiter <@Nando_Breiter> wrote:

If I change your code to set the dob field to the age, it works:

row[‘dob’] = DateDiff(‘yyyy’, row.dob, Now());

Apparently there is no mechanism in the underlying implementation to add
a query column on the fly. (Might be convenient if there would be …)

According to the above, your example should work if you add an empty age
column to the original query.

Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

On Wed, Sep 23, 2015 at 4:53 AM, AJ Mercer <@AJ_Mercer> wrote:

I am doing through all the query functions and creating example to help
me learn and also to add as example to http://docs.lucee.org/

But am having issues with QueryMap()

As I read it http://docs.lucee.org/reference/functions/querymap.html,
the returned struct is used to populate the new query, but I am just
getting the original query

​It would seem that you can only change the value of existing query
fields
not:

  • create a new query
  • add a new column

Is this the case?


try {
qryPeople = queryNew(“name,dob”,“varchar,date”,[[“Susi”,
CreateDate(1970,1,1)],[“Urs”,CreateDate(1995,1,1)],[“Fred”,
CreateDate(1960,1,1)],[“Jim”, CreateDate(1988,1,1)]]);

// map dob to age
qryPeopleAge = qryPeople.map(function(row, rowNumber, qryData){
row[‘age’] = DateDiff(‘yyyy’, row.dob, Now());
dump(var=row, abort=false);
return row;
});
dump(var=qryPeopleAge, label=‘map() - map dob to age’);

} catch (any error) {
dump(var=error, abort=true);

}

AJ Mercer
<webonix:net strength=“Industrial” /> http://webonix.net | <webonix:org
community=“Open” /> http://webonix.org
http://twitter.com/webonix


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get
your ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google
Groups “Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/CAPURtC3uhhK8cdbfdCXnFgeBH4s%3DD7%3DCQH-xp1o-M%3DCw-xKygQ%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAPURtC3uhhK8cdbfdCXnFgeBH4s%3DD7%3DCQH-xp1o-M%3DCw-xKygQ%40mail.gmail.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.


See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your
ticket NOW - http://www.cfcamp.org/

You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/CAGHrs%3D93C5dcA6DT3TE338YxuqXOhttohRKmfF%2BuA6s277%2BwEA%40mail.gmail.com
https://groups.google.com/d/msgid/lucee/CAGHrs%3D93C5dcA6DT3TE338YxuqXOhttohRKmfF%2BuA6s277%2BwEA%40mail.gmail.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.

AJ Mercer
<webonix:net strength=“Industrial” /> http://webonix.net | <webonix:org
community=“Open” /> http://webonix.org
http://twitter.com/webonix