I've written a couple of subclasses of DBI (after much hair-pulling
frustration) -- so far, most everything works like I want it, with the
exception of automatic disconnect handling...  I'd like to put the
disconnect method in a DESTROY, but none of my attempts are working.  Here's
what I've got so far -- any advice on my approach would be most appreciated,
especially if you can help get the automatic disconnect handling working.

package mydbi;
@ISA = qw( DBI );
use DBI;

sub connect {
        my( $proto, $dns, $username, $password ) = @_;
        my $class = ref( $proto ) || $proto;
        $class->init_rootclass;
        my $dbh = $class->SUPER::connect( $dns, $username, $password );
        $dbh;
}

package mydbi::db;
@ISA = qw( DBI::db );

sub select_value {
        my( $self, $st, $attr, @bind_values ) = @_;
        my $sth;
        if( ref $st ) { $sth = $st }
        else { $sth = $self->prepare( $st, $attr ) or return undef }
        $sth->execute( @bind_values ) or return undef;
        my $value = $sth->fetchrow_array;
}

package mydbi::st;
@ISA = qw( DBI::st );

1;


package specificdb;
use mydbi;
@ISA = qw( mydbi DBI );
use DBI;

sub new {
        my( $proto ) = shift;
        my $class = ref( $proto ) || $proto;
        my $dns = "DBI:mysql:database=XXX";
        my $username = "XXX";
        my $password = "XXX";
        my $self = $class->connect( $dns, $username, $password );
        $self;
}

package newbdb::db;
@ISA = qw( mydbi::db );

package newbdb::st;
@ISA = qw( mydbi::st );

1;

Reply via email to