Here's a revised version of my test script from before, using the same basic
mechanism, but setting the transactions manually using CFQUERY and SQL
statements, rather than the CFTRANSACTION tag.  This one behaves correctly.

To switch to this from what I previously suggested, all you need to do is
modify your beginTransaction, rollbackTransaction and commitTransaction
methods to use CFQUERY and SQL rather than the CFTRANSACTION tag (as shown
in the first three functions below).  Once again, encapsulation comes to the
rescue!

Cheers,
Barneyb

<cfset request.dsn = "test" />

<cffunction name="begin">
        <cfquery datasource="#request.dsn#" name="">begin</cfquery>
</cffunction>
<cffunction name="rollback">
        <cfquery datasource="#request.dsn#" name="">rollback</cfquery>
</cffunction>
<cffunction name="commit">
        <cfquery datasource="#request.dsn#" name="">commit</cfquery>
</cffunction>

<cffunction name="getstatus" output="true">
        <cfquery datasource="#request.dsn#" name="get">
                SELECT *
                FROM test
        </cfquery>
        <p>Current Table Status:</p>
        <cfdump var="#get#" />
</cffunction>


<!--- get the initial status of the table --->
<cfset getstatus() />

<!--- begin a transaction, running a 'good' query and a 'bad' query,
manually doing the rollback --->
<cfset begin() />
<cftry>
        <cftry>
                
                <cfquery datasource="#request.dsn#" name="">
                        INSERT INTO test
                                (name)
                        VALUES
                                ('emery')
                </cfquery>
                
                <cfquery datasource="#request.dsn#" name="">
                        INSERT INTO test
                                (name)
                        VALUES
                </cfquery>
                
                <cfcatch type="database">
                        <cfset rollback() />
                </cfcatch>
        </cftry>
        <cfcatch type="any">
                <cfoutput><p>error occurred:
#cfcatch.message#</p></cfoutput>
        </cfcatch>
</cftry>
<cfset commit() />

<!--- begin a transaction, running a 'good' query and a 'bad' query,
manually doing the rollback --->
<cfset begin() />
<cftry>
        <cftry>
                
                <cfquery datasource="#request.dsn#" name="">
                        INSERT INTO test
                                (name)
                        VALUES
                                ('emery')
                </cfquery>
                
                <cfcatch type="database">
                        <cfset rollback() />
                </cfcatch>
        </cftry>
        <cfcatch type="any">
                <cfoutput><p>error occurred:
#cfcatch.message#</p></cfoutput>
        </cfcatch>
</cftry>
<cfset commit() />

<cfset getstatus() />

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' 
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to