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

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;
}
Friday April 13, 2007
12:07 PM

a simple SQL client

now I'm writing a simple SQL client that can connect multiple database servers. for some reasons I need to connect to MySQL and PostgreSQL.

using "screen" and "mysql + psql" works but sometimes I wanna share a term history on each SQL clients.

so, I'm doing it. Term::Shell and Text::ASCIITable rock.

TODO: handle '*', '%' and more SQL special chars.

UPDATE found DBI::Shell but it can't handle multiple DBI connections.