DBD::Util::Bundle

sekimura on 2007-04-19T06:18:05

package DBD::Util::Bundle;

=pod

my $dbh0 = DBI->connect( 'dbi:mysql:database=myfoo', 'doh' ); my $dbh1 = DBI->connect( 'dbi:Pg:dbname=pgfoo', 'ugh' );

my $bbh = DBD::Util::Bundle->new(dbh_stack => [$dbh0, $dbh1]);

$bbh->prepare('SELECT * FROM bookshelf WHERE book_id >= 10'); $bbh->execute();

use Data::Dumper; use YAML; while ( my ($aref0, $aref1) = $bbh->fetchrow_arrayref ) { my ($dump0, $dmup1) = map { YAML::Dump $_ } ($aref0, $aref1); print "SRC $dump0 DST $dump1" if $dump0 ne $dump1; }



=cut

sub new { my $class = shift; my %args = @_; my $self = bless {}, $class; $self->{dbh_stack} = $args{dbh_stack}; return $self; }

sub prepare { my $self = shift; my ( @args ) = @_; my @ret; for my $dbh (@{$self->{dbh_stack}}) { push @ret, $dbh->prepare(@args); } $self->{sth_stack} = \@ret; return @ret; }

sub execute { my $self = shift; my ( @args ) = @_; my @ret; for my $sth (@{$self->{sth_stack}}) { push @ret, $sth->execute(@args); } return @ret; }

sub fetchrow_arrayref { my $self = shift; my @ret; for my $sth (@{$self->{sth_stack}}) { my $aref = $sth->fetchrow_arrayref or return; push @ret, $aref; } return @ret; }