Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cftransaction and cftry efficiency

Status
Not open for further replies.

toyt78

Technical User
Apr 5, 2005
125
US
I am inserting into 3 Access 2000 database tables from my Cold Fusion page and everything works. But I need to know if I am using cftransaction,cftry,cfcatch correctly.
Please review the below script and advise.
Also is it okay to insert into three tables where I assume I have to use three different inserts?

Code:
<cftransaction action="BEGIN">
<cfset myDatabaseNameCommit = "yes">
<cfset myMsg = 
"Database is not available.">
<cftry>                                             
    	<CFQUERY DATASOURCE="myDatabaseName">
			INSERT INTO tableOne
			(FName,LName)
			VALUES(
		   	'#FORM.FName#',
		   	'#FORM.LName#'
		  	)
    	</CFQUERY>
	<cfcatch type="database">
		<cfset myDatabaseNameCommit = "No">
	</cfcatch>
</cftry>
  
<cftry>
   <CFQUERY DATASOURCE="myDatabaseName">
		INSERT INTO tableTwo
		(aaa,bbb)
		VALUES(
		   '#FORM.aaa#',
		   '#FORM.bbb#'	
		  )
    </CFQUERY>
	<cfcatch type="database">
		<cfset myDatabaseNameCommit = "No">
	</cfcatch>
</cftry>

    <CFQUERY NAME="find_last_record" DATASOURCE="myDatabaseName" DBTYPE="ODBC">
			SELECT *
			FROM tableOne
			WHERE tableOneID = (SELECT MAX(tableOneID) FROM tableOne)
	</CFQUERY>
	
<cftry>
    <CFQUERY DATASOURCE="myDatabaseName">
		INSERT INTO tableThree
		(tableOneID,zzz)
		VALUES(
		   #find_last_record.tableOneID#,
		   '#FORM.zzz#'
		  )
       </CFQUERY>
	<cfcatch type="database">
		<cfset myDatabaseNameCommit = "No">
	</cfcatch>
</cftry>
</cftransaction>
 
wouldn't you want only one set of cftry tags around all three queries, so that if there is an error with any of them, the catch can run the transaction=rollback?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top