Whatever message this page gives is out now! Go check it out!
queryMap(query, function(row [, currentRow] [, query] ){} [, parallel] [, maxThreadCount])Parameter | Description |
query | (Required) The query to be iterated over. |
closure | (Required) Map function to be called with each row of the query. |
parallel | (Optional) True if you want to enable parallel programming. |
maxThreadCount | (Optional) The number of threads the function can execute. The number of threads must be between 1-50. If the value exceeds 50, there is an exception. |
template | (Optional) Define the schema of the returned query. |
<cfscript>
myQuery = queryNew("id,name,amount","Integer,Varchar,Integer",
[
{id=1,name="One",amount=15},
{id=2,name="Two",amount=18},
{id=3,name="Three",amount=32}
]);
qmap=QueryMap(myQuery,function(obj){
if (obj.id>1){
obj.name="Hello " & obj.name
return obj
}
else{
obj.name="Hi " & obj.name
return obj
}
})
writeOutput("The new query is:")
writeDump(qmap)
</cfscript><cfscript>
qoptions = {result="myresult", datasource="cfbookclub", fetchclientinfo="yes"};
sampleQuery = QueryExecute("select * from books order by bookid", [] ,qoptions);
function mapQuery(any Obj){
if(Obj.ISSPOTLIGHT == "Y")
Obj.TITLE = "NEW: " & Obj.TITLE;
return Obj;
}
newQuery = QueryMap(sampleQuery, mapQuery);
writedump(newQuery);
</cfscript><cfscript>
myResult=QueryExecute("SELECT * FROM EMPLOYEES",[],{datasource="cfdocexamples"});
myArray=ArrayNew(1);
// Populate myArrray with values "NO"
for (i=1;i<=myResult.recordcount;i++){
myArray[i]="NO";
}
// Add column InSanFrancisco and populate with values of myArray
QueryAddColumn(myResult,"InSanFrancisco","varchar",myArray);
// Iterate through the array and replace values of InSanFrancisco where location is San Francisco
status=myResult.map(function (col){
if (col.LOCATION=="San Francisco")
col.InSanFrancisco = "YES";
return col;
});
WriteDump(status);
</cfscript><cfscript>
myQuery = queryNew("id,name,amount","Integer,Varchar,Integer",
[
{id=1,name="One",amount=15},
{id=2,name="Two",amount=18},
{id=3,name="Three",amount=32}
]);
qmap=QueryMap(myQuery,function(obj){
if (obj.id>1){
obj.name="Hello " & obj.name
return obj
}
else{
obj.name="Hi " & obj.name
return obj
}
})
writeOutput("The new query is:")
writeDump(qmap)
</cfscript>