Forum OpenACS Q&A: for those of you stuck in the bad old days of ns_db gethandle

I put this in ad-utilities.tcl.preload to help track down where some of aD's code was misallocating its handles:
proc_doc ad_calling_proc { } {
    returns the name of the function calling the invoker
} {
    if [catch {
        set p [uplevel {info level [expr "[info level] - 1"]}]
    }] {
        set p ""
    }
    return $p
}

rename ns_db ns_db_old
proc ns_db args {
    set arg1 [lindex $args 0]
    if ![string compare $arg1 gethandle] {
        catch {
            set pool [lindex $args 1]
            if ![string compare $pool subquery] {
                ns_log notice "[ad_calling_proc] in [info script] 
calling ns_db gethandle $pool]"
            }
        }
    }
    uplevel "ns_db_old $args"
}