[Dbix-class] db handle disconnect?

Brandon Black blblack at gmail.com
Wed Aug 9 18:29:13 CEST 2006


On 8/9/06, Tim Keefer <tkeefer at gmail.com> wrote:
>
> unfortunately I didn't make note of the versions before I upgraded.
>

What exactly is broken?  What error messages/behavior happen that you
expected to be different?

We're trying to accomplish two things,
> 1) pull database connection info out of our conf so the models can be
> shared between the web apps, scripts, etc.
> 2) avoid extraneous connects to the database.
>
> Here's the exact code reference:
>
> [.......]
>

Well, you could handle the configuration side of your issue easily without a
coderef in connect_info, so I can only assume you're doing all of this
because you're trying to share a single $dbh with non-DBIC code in the same
running interpreter?  Have you considered just connecting a $schema object
using your info the normal way, and "sharing" the $dbh via mechanisms like:

sub my_code_that_does_not_use_dbic_but_gets_dbh_from_a_dbic_schema {
    my ($self, $schema, @other_stuff) = @_;
    my $dbh = $schema->storage->dbh;
    $dbh->do(...);
    return;
}

This would allow DBIC to manage the $dbh for you and still give access to
other code.  DBIC has hundreds of lines of code devoted specifically to
managed $dbh's better than your subroutine can - you should let it do the
work for you if possible.

The only known issue at the moment for 0.07000 sharing $dbh with other code
is that when your connected schema object goes out of scope, its going to
forcefully disconnect the active $dbh connection that other code might be
using.  There's a fix for that in -current, I'll make sure it makes it into
trunk for 0.07001 too.

-- Brandon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060809/20d734e7/attachment.htm 


More information about the Dbix-class mailing list