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?
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>