sekimura's Journal http://use.perl.org/~sekimura/journal/ sekimura's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:43:33+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 sekimura's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~sekimura/journal/ DBD::Util::Bundle http://use.perl.org/~sekimura/journal/33029?from=rss <tt>package DBD::Util::Bundle;<br><br>=pod<br><br>&nbsp; &nbsp; my $dbh0 = DBI-&gt;connect( 'dbi:mysql:database=myfoo', 'doh' );<br>&nbsp; &nbsp; my $dbh1 = DBI-&gt;connect( 'dbi:Pg:dbname=pgfoo', 'ugh' );<br><br>&nbsp; &nbsp; my $bbh = DBD::Util::Bundle-&gt;new(dbh_stack =&gt; [$dbh0, $dbh1]);<br><br>&nbsp; &nbsp; $bbh-&gt;prepare('SELECT * FROM bookshelf WHERE book_id &gt;= 10');<br>&nbsp; &nbsp; $bbh-&gt;execute();<br><br>&nbsp; &nbsp; use Data::Dumper;<br>&nbsp; &nbsp; use YAML;<br>&nbsp; &nbsp; while ( my ($aref0, $aref1) = $bbh-&gt;fetchrow_arrayref ) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my ($dump0, $dmup1) = map { YAML::Dump $_ } ($aref0, $aref1);<br>&nbsp; &nbsp; &nbsp; &nbsp; print "SRC $dump0 DST $dump1" if $dump0 ne $dump1;<br>&nbsp; &nbsp; }<br><br>=cut<br><br>sub new {<br>&nbsp; &nbsp; my $class = shift;<br>&nbsp; &nbsp; my %args = @_;<br>&nbsp; &nbsp; my $self = bless {}, $class;<br>&nbsp; &nbsp; $self-&gt;{dbh_stack} = $args{dbh_stack};<br>&nbsp; &nbsp; return $self;<br>}<br><br>sub prepare {<br>&nbsp; &nbsp; my $self = shift;<br>&nbsp; &nbsp; my ( @args ) = @_;<br>&nbsp; &nbsp; my @ret;<br>&nbsp; &nbsp; for my $dbh (@{$self-&gt;{dbh_stack}}) {<br>&nbsp; &nbsp; &nbsp; &nbsp; push @ret, $dbh-&gt;prepare(@args);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; $self-&gt;{sth_stack} = \@ret;<br>&nbsp; &nbsp; return @ret;<br>}<br><br>sub execute {<br>&nbsp; &nbsp; my $self = shift;<br>&nbsp; &nbsp; my ( @args ) = @_;<br>&nbsp; &nbsp; my @ret;<br>&nbsp; &nbsp; for my $sth (@{$self-&gt;{sth_stack}}) {<br>&nbsp; &nbsp; &nbsp; &nbsp; push @ret, $sth-&gt;execute(@args);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return @ret;<br>}<br><br>sub fetchrow_arrayref {<br>&nbsp; &nbsp; my $self = shift;<br>&nbsp; &nbsp; my @ret;<br>&nbsp; &nbsp; for my $sth (@{$self-&gt;{sth_stack}}) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $aref = $sth-&gt;fetchrow_arrayref or return;<br>&nbsp; &nbsp; &nbsp; &nbsp; push @ret, $aref;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; return @ret;<br>}<br></tt> sekimura 2007-04-19T06:18:05+00:00 journal a simple SQL client http://use.perl.org/~sekimura/journal/32985?from=rss <p>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. </p><p>using "screen" and "mysql + psql" works but sometimes I wanna share a term history on each SQL clients. </p><p>so, I'm doing it. Term::Shell and Text::ASCIITable rock.</p><p>TODO: handle '*', '%' and more SQL special chars.</p><p> <strong>UPDATE</strong> found DBI::Shell but it can't handle multiple DBI connections.</p> sekimura 2007-04-13T17:07:30+00:00 journal