Microsoft Access has a database property called .recordsaffected.
The help files says
"...the RecordsAffected property will contain the number of records deleted, updated, or inserted."
Is there such a property in <cfquery> when doing an UPDATE?
I see RecordCount, which returns the number of rows in the SELECT stmt, but not the number of rows in an UPDATE.
And I can't do a SELECT right after doing the update to see how many records I updated, because that's assuming another process hasn't come along right behind me and updated what I just updated. Sheesh!
I need to KNOW how many records were updated in the UPDATE stmt.
A SELECT after the update would IMPLY that so many records were updated.
I thought about using <cftransaction>, but I'm not sure <cftransaction> would lock a SELECT stmt.
This example adds $1,000 to Amount_Due for customer #7.
<cftransaction>
<cfquery datasource="dsn" name="TEST">
SELECT * FROM Cust WHERE CustID = 7
</cfquery>
<cfoutput query="TEST">
<cfset FORM.Amount_Due = Amount_Due>
<cfset FORM.Log_Time_Stmp = Log_Time_Stmp>
</cfquery>
<!--- An infinitesimally small amount of time passes here, but still... --->
<cfquery datasource="dsn">
UPDATE Cust
SET Amount_Due = #FORM.Amount_Due# + 1000,
Log_TimeStmp = (#FORM.Log_TimeStmp# + 1)
WHERE CustID = 7
AND Log_TimeStmp = #FORM.Log_TimeStmp# <!--- This is the important part --->
</cfquery>
</cftransaction>
<!--- Were 0 records affected?
If so, someone else must have udpated the record while I had my back turned --->
The idea is:
Any other UPDATE stmts need to include Log_TimeStmp when they execute.
If I get back "0 records affected", it means another process UPDATED the Customer record between the time I did the SELECT stmt and the time I did the UPDATE.
This is not a SQL Server database, so I can't use the RowVersion field type.
Hey! What if I did a
<cftransaction>
<UPDATE>
<SELECT>
<UPDATE>
</cftransaction>
?
It's Friday at 4:50pm. Stick a fork in me, 'cause I'm done.
Start Free Trial