You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joe Thomas <jo...@tellme.com> on 2004/09/01 00:24:14 UTC

[PATCH] Fix Apache::DBI cleanup when multiple database handles are used

This patch should make the cleanup handlers roll back all database handles
that have been used in a script, rather than just the last one connected.
Currently, $Idx is a file-scoped variable, and gets overwritten with each
call to Apache::DBI::connect.

I've made $Idx a lexical variable scoped to connect(), and pass it as a
parameter to cleanup().  This necessitated pushing a closure ("sub {
cleanup($Idx) }") onto the cleanup handlers.

The real reason I wrote this was that I have a DBD driver that aggregates
several database handles into one virtual handle.  It was calling
DBI->connect from inside its own connect method, and strange bugs started
popping up when it was run under Apache::DBI.  It turns out that the inner
connect() calls were causing $Idx to be overwritten, so the handle got
stored in the wrong slot in %Connected.

This patch makes Apache::DBI::connect reentrant, and my problem goes away.

Joe