Forum OpenACS Q&A: closing all db handles...

Request notifications

Collapse
Posted by David Kuczek on
In a proc I want to close all database handles no matter how many are
opened and what their variable names are... How can I do this?
Collapse
Posted by Dan Wickstrom on
Try calling db_release_unused_handles.
Collapse
Posted by David Kuczek on
Thanks Dan,

but any idea for 3.2.5? It can't be ported too straightforwardly...

Collapse
Posted by Dan Wickstrom on
Oh 3.2.5...

If it's not too much of a problem to rewrite queries, you can backfit the openacs 4 db api to 3.2.5.  I know there are several versions of the openacs 4 db api ported to 3.2.5 floating around (search the bboards).  If not, there's no easy way to do it from tcl, unless you somehow keep track of all the handles that have been allocated, which is what the oacs 4 db api does.

If you want to write a tcl extension in 'c', then you could also create a proc for closing all of the handles in the current connection thread.  Db handles are stored in thread-specific data, so it's easy to get access to them from a 'c'-function.

Collapse
Posted by Michael A. Cleverly on
If you really want to close all database handles (that your thread has access to), and you don't care how they were opened, then I'd do this.
set total_num_handles [expr {5 + 5 + 5}]
for {set i $total_num_handles} {$i >= 0} {incr i -1} {
    catch { ns_db releasehandle nsdb$i }
}
Totally hackish, but it should meet the "no matter how many were opened and what their variable names were" criteria. :^) I'd suggest backporting the database API though.