Perl DBI usage at report building Joe Jiang [email_address]
Perl Language Practical Extraction and ... Reporting Language
Perl Programmer Laziness Impatience Hubris (Boldness)
DBMS Database Management (descide) System
DBI.pm The gate to Management level programming
Back to reporting The man in breau The game they played The suggestion I once made on OLAP
Chemical Perl (Gas-ware) PHP for website Python for architecture Ruby for rails Perl for what?
Reports again DMBS is the container SQL is for query Perl is the formater
Give me Excel Copy HTML table into Excel Or, name HTML as .xls Use some IDE tool?
Toolset basic $ echo 'select SESSION_ID, HIT_ID from hit where USERNAME=? and ACCESS_TIME between to_date(?,?) and to_date(?,?)' > session.sql ↵
It worked $ bofc < session.sql user-123 201106122345 YYYYMMDDHH24MI 201106122357 YYYYMMDDHH24MI | wc -l ↵ SESSION_ID HIT_ID 12
And ... $ bofc < session.sql user-123 201106122345 YYYYMMDDHH24MI 201106122357 YYYYMMDDHH24MI | sort ↵ SESSION_ID HIT_ID 20110612234046 1772475805 20110612234046 1772475807 20110612234046 1772475809 20110612234046 1772475811 20110612234046 1772475813 ...
Highlights works with wc -l & sort (Laziness)
works with parameter binding (Boldness)
purify the SQL with limited punctuaction (Impatience)
Camel coding PERL5LIB=/proj/Web/EMIS/Modules perl -MEMIS::Database -le '($s= do{$d=EMIS::Database::gethandle(q(CDB)); $d->do(q(begin; nls_format_setting; end;)); $d}->prepare_cached(join q(),<STDIN>))->execute(@ARGV); $,=qq(\t); print STDERR @{$s->{NAME}}; print @r while @r=$s->fetchrow_array; $d->disconnect' $*
Hints PERL5LIB=/proj/Web/EMIS/Modules -MEMIS::Database
-le ' ... '
$s = do { $d=...; ...; $d } -> prepare_cached( join q(),<STDIN>)
( $s = ... ) -> excute ( @ARGV );
$, = qq( \t );
print STDERR @{$s->{NAME}};
print @r while @r=$s->fetchrow_array;
emp #!/usr/bin/perl -l use DBI; $s = do { DBI-> connect ( q(DBI:mysql:database=employees) , q() , q() ); }->prepare_cached( join ( q() ,<>) ); $s->execute ( @ARGV ); $, = qq( \t ) ; print STDERR @{$s->{ NAME }} ; print @r while @r = $s->fetchrow_array ;
Work Horse But I want query more than one DB ... Can you send me another column? Make a comma seperated list in one column ...
Report Driven Report binding variables no longer in @ARGV
SQL no longer in STDIN
Here comes loop
Running faster by prepare $s=$d->prepare_cached(do { open(SQL, q(<), shift); join(q(),<SQL>) });
$s->execute(@F);
@r=$s->fetchrow_array;
@x = map {q()} @r unless @x;
IO::Handle::autoflush STDOUT 1;

perl usage at database applications