The Duplicate ColdFusion 9 function should return a clone, also known as a deep copy of the variable, with no reference to the original variable. This should be true for complex objects such as structures and queries.
I am working on code that uses a request object that is in the scope of APPLICATION. This request needs to be changed locally for use on a specific page, and I need to know what the original request line is (which is in the metadata of the request object). Thus, in this case, creating a deep copy of the original request is the most reasonable solution.
But, unfortunately, it seems that ColdFusion does not clone the entire object, but only its result set, thereby losing all metadata.
This is not the behavior that I expected from Duplicate , and I do not consider it compatible with what happens when duplicating other kinds of complex objects.
One solution to my problem would be to pass the AND result set of the sql string as separate arguments to the function.
I would like to know, however, if you have a more elegant solution and / or throw a little light on the request. Duplicate the problem.
Here is some code that proves the problems for a duplicate request:
<cfquery name="qry" datasource="mydatasource"> SELECT "blue" AS colour, "pear" as fruit </cfquery> <cfset qry_copy = qry> <cfset qry_deepcopy = duplicate(qry)> <cfdump var="#qry#" label="Original query" /> <cfdump var="#qry_copy#" label="Copy of the query (by reference)" /> <cfdump var="#qry_deepcopy#" label="Deep copy of the query (by value)" /> <cfdump var="#qry.getMetaData().getExtendedMetaData()#" label="Metadata of the original query" /> <cfdump var="#qry_copy.getMetaData().getExtendedMetaData()#" label="Metadata of the copy of the query" /> <cfdump var="#qry_deepcopy.getMetaData().getExtendedMetaData()#" label="Metadata of the deep copy of the query" />

Edit:
In short, these are my findings so far:
- Metadata is not duplicated because
qry.getMetaData() is a JAVA class and, as stated in the documentation, if the field of an element of an array or structure is a COM, CORBA or JAVA object, you cannot duplicate an array or structure. - The registered ColdFusion function for retrieving query metadata is
getMetaData(qry) . - I fixed my problem by saving both
qry and getMetaData(qry) in the APPLICATION area.
source share