The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

CFQuery bug found

posted under category: ColdFusion on August 23, 2004 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
<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.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.