tomill / DBIx-Simple-Inject

https://metacpan.org/pod/DBIx::Simple::Inject
4 stars 0 forks source link

prevents auto-reconnect with DBIx::Connector from working. #1

Open markstos opened 11 years ago

markstos commented 11 years ago

Thanks for this module. I like the idea of it. I wanted to use it to combine the DBIx::Simple API with the auto-reconnection feature of DBIx::Connector. However, as my testing shows below, it doesn't work in all cases.

Adjust the $DSN to suit you, and then you'll see that when using DBIx::Simple::Inject, the connection doesn't recover from a disconnect:

use Test::More;
use Test::Exception;
use DBIx::Simple::Inject;
use DBIx::Connector;

# The base case, no DBIx::Simple::Inject
{
    my $dbixc = DBIx::Connector->new('dbi:Pg:...','yourname');
    my $dbh = $dbixc->dbh;

    # Reality check connection
    note $dbh->selectrow_array("SELECT version()");

    lives_ok( sub {
        $dbh->disconnect;
        note $dbixc->dbh->selectrow_array("SELECT version()")
    }, "Without DBIx::Simple::Inject: auto-reconnect after dbh->disconnect");

    lives_ok( sub {
        $dbixc->disconnect;
        note $dbixc->dbh->selectrow_array("SELECT version()")
    }, "Without DBIx::Simple::Inject: auto-reconnect after dbixc->disconnect");
}

# With DBIx::Simple::Inject
{
    my $dbixc = DBIx::Connector->new('dbi:Pg:...','yourname', undef, {
        RootClass => 'DBIx::Simple::Inject',
    });
    my $dbh = $dbixc->dbh;

    # Reality check connection
    note $dbh->selectrow_array("SELECT version()");

    lives_ok( sub {
        $dbh->disconnect;
        note $dbixc->dbh->selectrow_array("SELECT version()")
    }, "WITH DBIx::Simple::Inject: auto-reconnect after dbh->disconnect");

    # Currently fails here.
    lives_ok( sub {
        $dbixc->disconnect;
        note $dbixc->dbh->selectrow_array("SELECT version()")
    }, "WITH DBIx::Simple::Inject: auto-reconnect after dbixc->disconnect");
}

done_testing; ~

tomill commented 11 years ago

thanks the report. I'm another DBIx::Simple and DBIx::Connector fan ;)

I’ve never seen this error, because I dont call $dbh->disconnect() to keep connection managing as DBIx::Connector's job. but in some cases, need it though.

I noticed $dbh->disconntct() should call DBI::db::disconnect() directly when using DBIx::Simple as a subclass.

Tests(added your above test) passed. How about this?

ComLock commented 10 years ago

Any reason why there is not a 0.05 version with this? Trying to use DBIx::Connector and DBIx::Simple::Inject in an Mojolicious hypnotoad app :)

Database object no longer usable (because of DBIx::Simple=HASH(0x5e612e0)->disconnect at ...local/lib/perl5/DBIx/Simple/Inject.pm line 63)
markstos commented 10 years ago

DBIx::Simple::Connector is a cleaner design approach to integrating DBIx::Simple and DBIx::Connector. The author of DBIx::Simple has approved the general approach when creating DBIx::Simple::Connector, but has not get formally reviewed and released it, along with the minor updates to DBIx::Simple that it requires:

https://rt.cpan.org/Public/Bug/Display.html?id=89258

ComLock commented 10 years ago

I don't have write access to https://rt.cpan.org/Public/Bug/Display.html?id=89258

But I think this is needed aswell:

diff -rN -u DBIx-Simple-1.35/MANIFEST DBIx-Simple-1.40/MANIFEST
--- DBIx-Simple-1.35/MANIFEST   2007-11-11 01:10:33.000000000 +0100
+++ DBIx-Simple-1.40/MANIFEST   2013-11-25 15:26:19.968743073 +0100
@@ -7,6 +7,7 @@
 t/sqlite.t
 t/swap.t
 lib/DBIx/Simple.pm
+lib/DBIx/Simple/Connector.pm
 lib/DBIx/Simple/Examples.pod
 lib/DBIx/Simple/Comparison.pod
 lib/DBIx/Simple/Result/RowObject.pm
diff -rN -u DBIx-Simple-1.35/META.yml DBIx-Simple-1.40/META.yml
--- DBIx-Simple-1.35/META.yml   2011-01-04 23:58:25.000000000 +0100
+++ DBIx-Simple-1.40/META.yml   2013-11-25 15:26:38.329329293 +0100
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               DBIx-Simple
-version:            1.35
+version:            1.40
 abstract:           Very complete easy-to-use OO interface to DBI
 author:
     - Juerd Waalboer 
ComLock commented 10 years ago

What about this?

RootClass      => 'DBIx::Simple::Inject',