On Thu, Mar 02, 2006 at 04:51:05PM -0800, David Wheeler wrote:
> Fellow DBIers,
> 
> I've been having a need in my tests to be able to disconnect all  
> current connections to a database?before I drop the database, for  
> example. Now my code uses connect_cached(), so this used to be quite  
> a PITA, because the DBI was keeping connections open!
> 
> But then I stumbled on the new installed_drivers() method and figured  
> out how to do it:
> 
>     my %drhs = DBI->installed_drivers;
>     $_->disconnect for grep { defined }
>         values %{ $drhs{Pg}->{CachedKids} };
> 
> This works great! But I hadn't realized that installed_drivers() was  
> added to the DBI only recently, so my fellow hackers suddenly started  
> to get strange failures. Once we figured out the problem, everyone  
> upgraded, but I'm left with this question:
> 
> Was there any way to get hold of all cached database handles from the  
> DBI before the introduction of installed_drivers() in 1.49?

installed_drivers is simply:

        sub installed_drivers { %DBI::installed_drh }

so you could just refer to %DBI::installed_drh, or better still:

    *DBI::installed_drivers = sub { %DBI::installed_drh }
        unless defined &DBI::installed_drivers;

> Oh, and on a side note: How come installed_drivers() isn't mentioned  
> in DBI::Changes?

Oversight. Sorry. I've fixed it for the next release.

Tim.

Reply via email to