Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

sekimura (3756)

sekimura
  (email not shown publicly)
http://sekimura.vox.com/

Journal of sekimura (3756)

Thursday April 19, 2007
01:18 AM

DBD::Util::Bundle

[ #33029 ]
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;
}
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.