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 MrNate

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.

Too old to comment!
On Jan 11, 2006 at 1:00 AM Jackson (jackson who really likes jacksongmoore.com) said:
I know its been a while, but do you have an update on this? On MX6.1, the error happens even if you don't have the first line with the cfset. For example:

update table
set id=1
where id=99999999

returns the Variable myQuery is undefined

On Jan 11, 2006 at 1:00 AM Jackson (jackson who spends every waking moment visiting jacksongmoore.com) said:
I know its been a while, but do you have an update on this? On MX6.1, the error happens even if you don't have the first line with the cfset. For example:

[cfquery name="myQuery" datasource="#mydsn#"]
update table
set id=1
where id=99999999
[/cfquery]
[cfdump var="#myQuery#"]

returns the Variable myQuery is undefined
Too old to comment!