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







What is the best way to define the term sandbox? I think I understand the problems with flash and sandbox violations, but I don’t think that I completely get what "sandbox" means in the context of the coldfusion/ria/computer world.
In this case, I use the term very casually. I just have a folder in my webroot called sandbox where I create various files to test things in. This does not refer to the ColdFusion Security Sandbox.
When a select query is called from a cfc and the query object is returned to is there any way to return the result=’myResult’ variable as well. Do I have to change my return type to return a structure that contains two keys one for the query object and one for the result struct? Any way this result can be simultaneously returned with all returned query objects.
Thanks a lot.
Tim
That is correct, you would need to create a struct to pass both items back.
Thanks…that works great I was just hoping to be able to use it on pre-written code that is expecting a query back from the cfc rather than the structure. I think i’ll always return a structure from my cfc instead of the query object from now on to have that information available. Thanks for your clarification.