[thelist] stupid CSS question

Rory.Plaire at wahchang.com Rory.Plaire at wahchang.com
Tue Nov 27 20:47:03 CST 2001


+| > <p class="big, strong">
+| 
+|     Except you shouldn't use a comma. It should be 
+| a space-separated list.
+| 
+| James Aylard

So you are right.

I don't like to give bad information, so, a tip.

<tip type="ColdFusion Transactions" author="rory" alt="8)">

Need to update a table in a database which relies on data from that table
you just updated? In most Parent/Child relationship tables, this is indeed
the case. However, what happens to the data you so tenderly handled to keep
clean and consistent when that second change is hiccupped by your DMBS? Not
pretty, for sure (unless you like to clean data from tables late at night
while blasting techno on the b-box).

So, what to do?

Look at it, you have several queries dependent on preceding success, right?
This is why the concept of a "transaction" was developed. It aggregates
queries so that if one fails, they all fail, and data integrity and
consistency remains in its original, before transaction, state. Good news
for those who like to sleep at night.

How does this look in CF?

Try this:

<cftransaction action="begin">
<!-- begins a transaction block -->

	<cfset bCommitted = "Yes">
	<cfset sErr = "">
	<cftry>
		<cftry>
			<cfquery datasource="myData" name="qry1">
				INSERT INTO	tblStuff
					(aStuff)
				VALUES
					(#Form.Name#)
			</cfquery>
			<cfcatch type="database">
			<!-- catch qry1 errors -->
				<cfset bCommitted = "No">
				<cfset sErr = cfcatch.message & 
					"(" & cfcatch.detail & ")">
			</cfcatch>
		</cftry>

		<cftry>
			<cfquery datasource="myData" name="qry2">
				INSERT INTO	tblStuffStuff
				(	Stuff_Id
				,	moStuff
				)
				VALUES
				(
GetLastInsertedId(depends_on_your_dbms)
				,	#Form.Interest#
				)
			</cfquery>
			<cfcatch type="database">
			<!-- catch qry2 errors -->
				<cfset bCommitted = "No">
				<cfset sErr = cfcatch.message & 
					"(" & cfcatch.detail & ")">
			</cfcatch>
		</cftry>

		<cfif bCommitted>
		<!-- commits the queries executed -->
		<!-- / no further rollback possible by normal means-->

			<cftransaction action="Commit"/>

		<cfelse>
		<!-- rejects the executed queries -->
		<!-- and rolls the state of the data -->
		<!-- back to when the transaction began -->

			<cftransaction action="RollBack"/>
			<cfthrow message = sErr>

		</cfif>

		<cfcatch type="any">
			<cfthrow 
				message="Can you believe it? " & 
					"The application is having trouble "
&
					"accessing resources. Please try
again " &
					"later, and kindly submit a bug
report." 
				detail=#cfcatch.detail#>
		</cfcatch>
	</cftry>
</cftransaction>

This works on DBMSs which support transactions: Oracle, Jet (MSAccess),
MySQL (>= 3.24), PostgreSQL, and MS SQL, to name a few...
</tip>




More information about the thelist mailing list