db_transaction

one of the documented procedures in this installation of the ACS
Usage:
db_transaction   code
What it does:
Executes the contained code in a single database transaction.
Defined in: /web/philip/packages/acs-core/10-database-procs.tcl

Source code:


    global ad_conn

    db_with_handle db {
	# Preserve the handle, since db_with_handle kills it after executing
	# this block.
	set dbh $db

	# Remember that there's a transaction happening on this handle.
	if { ![info exists ad_conn(db,transaction_level,$db)] } {
	    set ad_conn(db,transaction_level,$db) 0
	}
	set level [incr ad_conn(db,transaction_level,$db)]
	if { $level == 1 } {
	    ns_db dml $db "begin transaction"
	}
    }

    set errno [catch [list uplevel $code] error]
    incr ad_conn(db,transaction_level,$dbh) -1

    if { $errno == 1 && ![string compare $error "<<AD_ABORT_TRANSACTION>>"] } {
	# Abort the transaction. If this the outermost transaction, actually perform
	# the "abort transaction" DML; if not, propagate the error.
	if { $level == 1 } {
	    ns_db dml $dbh "abort transaction"
	}
	
	if { $level != 1 } {
	    error "<<AD_ABORT_TRANSACTION>>"
	}
    } elseif { $errno } {
	# Propagate the error
	global errorInfo
	error $error $errorInfo $errno
    } else {
	# Success!
	if { $level == 1 } {
	    ns_db dml $dbh "end transaction"
	}
    }


philg@mit.edu