A Little Known Attribute of CFQUERY
While building some database abstraction methods and components for a CF/Flex application I am working on, I had a need for determining how many rows were affected when I ran a specified SQL UPDATE statement. I figured there was some way of displaying this since SQL Server returns such a response when you run this type of query.
In my sandbox I did a quick test, and to my brief disappointment, when I dumped the query object it did not exist. Notice I said brief. I figured this may be the case. This is where the result attribute comes in handy. When you specify the result attribute in cfquery, a struct of a few pieces of valuable data gets returned after the execution of the query. One of these pieces is recordcount. Bingo! When an UPDATE query is run, resultName.recordCount will tell me how many rows were affected by the UPDATE statement.
The other attributes returned in this struct are:
- cached (true/false)
- executiontime (in milliseconds)
- recordcount
- sql (the sql statement used in the query)
Example:
UPDATE artists
SET firstname = 'Foo'
WHERE artistid = 22
</cfquery>
<cfdump var="#qReadResult#" />


