db_with_handle

one of the documented procedures in this installation of the ACS
Usage:
db_with_handle   db   code_block
What it does:
Places a usable database handle in $db and executes $code_block.
Defined in: /web/philip/packages/acs-core/10-database-procs.tcl

Source code:


    upvar $db dbh

    global ad_conn

    # Initialize bookkeeping variables.
    if { ![info exists ad_conn(db,handles)] } {
	set ad_conn(db,handles) [list]
    }
    if { ![info exists ad_conn(db,n_handles_used)] } {
	set ad_conn(db,n_handles_used) 0
    }
    if { $ad_conn(db,n_handles_used) >= [llength $ad_conn(db,handles)] } {
	lappend ad_conn(db,handles) [ns_db gethandle [db_nth_pool_name $ad_conn(db,n_handles_used)]]
    }
    set dbh [lindex $ad_conn(db,handles) $ad_conn(db,n_handles_used)]
    set ad_conn(db,last_used) $dbh

    incr ad_conn(db,n_handles_used)
    set errno [catch [list uplevel $code_block] error]
    incr ad_conn(db,n_handles_used) -1

    # This may have changed while the code_block was being evaluated.
    set ad_conn(db,last_used) $dbh

    # Unset dbh, so any subsequence use of this variable will bomb.
    unset dbh

    # This may seem a little weird, but it just says "do whatever $code_block did" -
    # propagates a TCL_RETURN, TCL_BREAK, TCL_CONTINUE, TCL_OK, or TCL_ERROR to
    # the caller.
    if { $errno == 0 || $errno == 2 } {
	# TCL_OK or TCL_RETURN
	return $error
    } elseif { $errno == 3 } {
	# TCL_BREAK
	break
    } elseif { $errno == 4 } {
	# TCL_CONTINUE
	continue
    } else {
	# TCL_ERROR or something funky
	global errorInfo
	error $error $errorInfo $errno
    }


philg@mit.edu