Friday, February 03, 2012    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Dec 2006 >>
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Search

Categories
 • Acrobat (5) [RSS]
 • Adobe (110) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (34) [RSS]
 • AdobeMAX11 (27) [RSS]
 • AIR (297) [RSS]
 • Appearances (217) [RSS]
 • Books (86) [RSS]
 • CFEclipse (15) [RSS]
 • Cloud (1) [RSS]
 • ColdFusion (1477) [RSS]
 • ColdFusion Builder (22) [RSS]
 • Data Services (42) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (356) [RSS]
 • Flex (561) [RSS]
 • Home Automation (5) [RSS]
 • HTML5 (21) [RSS]
 • JavaScript (2) [RSS]
 • Jobs (130) [RSS]
 • jQuery (14) [RSS]
 • JRun (14) [RSS]
 • Labs (62) [RSS]
 • LiveCycle (37) [RSS]
 • MAX (284) [RSS]
 • Mobile (238) [RSS]
 • Regular Expressions (19) [RSS]
 • RIA (21) [RSS]
 • SQL (45) [RSS]
 • Stuff (554) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (167) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
December 8, 2006

Getting RECORDCOUNT For INSERT, UPDATE, DELETE Operations

<cfquery> returns the number of rows retrieved by a SELECT operation in the recordcount variable, available in the CFQUERY structure or the specified RESULT structure.

But what if you are performing INSERT, UPDATE, or DELETE operations, how could you determine the number of rows affected?

Well, apparently this one snuck in under the radar, I don't see it in the docs (which say that result_name.recordcount contains "Number of records (rows) returned from the query.") or in the release notes. But, as of CFMX 7.0.2, result_name.recordcount also returns the number of rows affected by INSERT, UPDATE, and DELETE operations.

Comments
If you try to reference this pr 7.0.2 will it crash or just return zero? I can't test as I have an up-to-date dev box.
# Posted By Ben Nadel | 12/8/06 3:52 PM
I still tried it on Crystaltech hosting, but system replied me that recordCount is undefined in query result. Also I tried to CFDUMP query, but system replied me that query variable is undefined.

PRODUCTVERSION     7,0,2,142559
# Posted By Merlinox | 12/9/06 8:33 AM
I'm also running 7,0,2,142559 and only ever get -1 returned as the record count. Using MSSQL 2005 express.
# Posted By James Netherton | 12/9/06 8:59 AM
Merlinox, it's in the RESULT structure, not the query structure.

Ben, the RESULT structure is returned pre 7.0.2, but RECORDCOUNT will be empty or not present.

James, I'll report that. The number should be whatever the DBMS reports.

--- Ben
# Posted By Ben Forta | 12/9/06 10:23 PM
Thanks Ben, I didn't know RESULT field of query, and I found it on <a href="http://livedocs.macromedia.com/coldfusion/7/htmldo...; (... is slow only for me that site?).

result.recordCount returns -1 me too.
Have a nice new week :)
# Posted By Merlinox | 12/11/06 3:30 AM
This would be a great feature to have, but it doesn't seem to work for me using SQL 2000, CF Version:7,0,2,142559. I get -1 all the time in the result struct.
# Posted By Kevin | 12/11/06 11:27 AM
I tried it in Access and it works, but SQL Server ... I am going to test a few more databases. And I am also checking with the engineers and QA to see if they have any details as to what works and what does not.

--- Ben
# Posted By Ben Forta | 12/11/06 4:32 PM
Have you ever found a solution to this issue? I am running against MYSQL 5 and am seeing -1 as well.
# Posted By Chris | 5/7/07 3:20 PM
Ditto others against Oracle 9i. Only returns -1. Sadly, I'm not sure which version of CF 7 we're on.

Bob
# Posted By Bob Jacoby | 6/11/07 11:56 AM
I'm using CF 7.0.2.... and MySQL 5.0.27 and am having the same problem as many others. My result is -1.
# Posted By Jason | 7/12/07 11:22 AM
Hi Ben,

Just wondering, if this issue has been fixed in ColdFusion 8 beta.

Thanks
# Posted By William from Lagos | 7/21/07 7:57 PM
For anyone using CF 7 and looking for solution to this issue, check it out here http://www.techfeed.net/blog/index.cfm/2006/4/20/O...
# Posted By William from Lagos | 7/21/07 8:04 PM
Another thing you could do with SQL Server is to include SELECT changedRows = @@ ROWCOUNT right after you Insert/Update/Delete inside your cfquery and then reference it by queryname.changedRows.
# Posted By Kevin Kazmierczak | 7/23/07 8:40 AM
Just thought I would put one testimonial in here for this working. I set the result attribute for my query tag to queryResult and was able to get the recordCount through queryResult.recordCount for a DELETE query. Thanks Ben!
# Posted By Nils Thingvall | 5/14/09 3:01 PM
CF MX 7 + SQL 2000

Found I had to wrap the query with
SET NOCOUNT ON;
<cfquery....
SELECT changedRows = @@ROWCOUNT
SET NOCOUNT OFF;

*Note no space between @@ and Row as perkevin comment...
# Posted By Peter Smith | 10/1/09 1:31 PM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved