Not yet rated

Problem

You need to determine the execution time of a query being returned from a CFC, function or tag.

Solution

Use the getMetaData() on a query object to get access to its "result" structure.

Detailed explanation

ColdFusion supports a result attribute in the <cfquery /> tag for returning a structure containing execution time, the SQL statement, record count, etc. However, when your query object is being returned from a CFC, function or tag you may not have the ability to utilize the result attribute.

However, you can get access to this same information by using the getMetaData() method on the query object:

<cfdump var="#queryName.getMetaData().getExtendedMetaData()#"
/>

This will output the basic information that's normally available via the <cfquery /> tag's result attribute.

This means you can output the execution time of any query object that originated from a SQL statement using the following:


<cfoutput>    

#numberFormat(max(queryName.getMetaData().getExtendedMetaData().executionTime, 1)/1000, "0.000")# seconds

</cfoutput>

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes