Jan 20
Problem with query of queries and flex
Posted by James Netherton | Saturday 20 January 2007 6:18 PM | In ColdFusion
It may be a quirk or just me misunderstanding the way in which query of queries works.
Here's an example:
variables.boyNameList = "James,David,John";
variables.boyNames = queryNew("id, name");
variables.girlNameList = "Jane,Sarah,Betty";
variables.girlNames = queryNew("id, name");
for(i = 1; i lt listLen(variables.boyNameList); i = i + 1)
{
queryAddRow(variables.boyNames);
queryAddRow(variables.girlNames);
querySetCell(variables.boyNames, "id", i);
querySetCell(variables.boyNames, "name", listGetAt(variables.boyNameList,i));
querySetCell(variables.girlNames, "id", i);
querySetCell(variables.girlNames, "name", listGetAt(variables.girlNameList,i));
}
</cfscript>
Which produces the following query recordsets:

Now create a cartesian product:
SELECT
boyNames.name AS boysNames,
girlNames.name AS girlsNames
FROM
boyNames,
girlNames
</cfquery>

Even though the column names were aliased, the query metadata hasn't changed.

Why would this ever be any problem? It turns out that if you were to return this query object back to Flex and bind it to the DataGrid component, only one column titled 'name' would be displayed.
It appears that Flex uses the query metadata to determine the query column names, so no matter what aliases exist, they are ignored.
So if one wanted to change the query metadata, how could this be achieved? ColdFusion reperesents query metadata through objects of type coldfusion.sql.QueryTableMetaData. This object exposes a method that allows column names to be set:
{
column_label = colLabel;
}
Change the metadata:
<cfset joinNames.getmetaData().setColumnLabel(newColumnNames.Split(","))>
And the query metadata has changed:

0 Comments
[Post comment]