The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

CFQuery bug found

posted under category: ColdFusion on August 23, 2004 at 1:00 am by Nathan

My co-worker Raff just discovered a bug with the CFQuery tag. When you set the variable for a query, and then run the cfquery tag, if the query doesn't return a recordset, your previously set variable will be undefined. Example:

<cfset qry = "">
<cfquery name="qry" datasource="dsn">
UPDATE table
SET field = 0
WHERE id = 1
</cfquery>
<cfdump var="#qry#">

The cfdump will throw an error, stating that "qry" doesn't exist.


Workarounds are fairly simple. Either check to see if your query is defined, or if you must have a query, even with a recordcount of zero, do <cfparam name="qry" default="#queryNew('')#"> after your cfquery call.