jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

I am looking for a script or application that will produce a nicely organised table structure report. The last day or so I have been running a describe tablename; query and copying the data from the result pane because I do not appear to be able to print form that.

Something that runs on Linux or Windows would be fine, even a CGI type script would be quite okay as long as it is Perl not PHP!

jdtoronto

Replies are listed 'Best First'.
Re: OT - MySQL report generation (PM code)
by tye (Sage) on Nov 20, 2003 at 23:35 UTC

    Here is some code we use at PerlMonks. I think vroom wrote the first version (but I doubt he'd mind me releasing it). I patched it some after that and I've removed some of the PM-specific bits (such as the template that it is embedded in, which dictated some of the structure of it).

    You'll have to paste in your own DB connect method and this code doesn't deal with DB errors (the templating system already does that, if rather verbosely, so we haven't bothered to put such in here).

    use CGI; my $q = CGI->new(); print $q->header(); my $db = Your::Module::GetYourDataBaseHandle(); my $html = ''; my $execstr = $q->param("sqlquery"); $html .= $q->start_multipart_form( "POST", $ENV{script_name}) . "\n" . $q->hidden("displaytype") . "\n" . $q->hidden("node_id", getId($NODE)) . "\n" . "SQL Query:<br />\n" . $q->textarea( "sqlquery", $execstr, 8, 60 ) . "<br />\n" . $q->submit('execsql', 'Execute') . "\n" . $q->end_form(); print $html; $html = ''; if( $execstr ) { my $cursor = $db->prepare($execstr); my $count = eval { $cursor->execute() }; if( ! $count ) { $html= "Execute failed: $DBI::errstr\n"; } elsif( ! $cursor->{NUM_OF_FIELDS} ) { # not a select statement $html= "$count rows affected.\n"; } else { my $ROW; while( $ROW = $cursor->fetchrow_hashref() ) { if( $html eq "" ) { $html = "$count rows:\n<table border=1>\n"; $html .= " <tr>\n"; foreach ( @{$cursor->{NAME}} ) { if( ! defined $_ ) { $_= ""; } elsif( "" eq $_ ) { $_= "&nbsp;"; } else { $_= $q->escapeHTML($_); } $html .= qq[ <td align="center" bgcolor="#CC99CC">] . qq[<font color="#000000">$_</font></td>\n]; } $html .= " </tr>\n"; } $html .= " <tr>\n"; my( $k, $v ); foreach ( @{$cursor->{NAME}} ) { #(keys %$ROW) $k = $_; $v = $$ROW{$_}; if( ! defined $v ) { $v= ""; } elsif( "" eq $v ) { $v= "&nbsp;"; } else { $v= $q->escapeHTML($v); $v =~ s# # &nbsp;#g; $v =~ s#\n#<br />\n#g; } $html .= " <td>$v</td>\n"; } $html .= " </tr>\n"; } $cursor->finish(); if( $html eq "" ) { $html .= "Zero rows returned.\n"; } else { $html .= "</table>\n" } } } print $html;

    I've tested the original code quite a bit but I've not even tried to compile this reinterpretation of it.

                    - tye
Re: OT - MySQL report generation
by LTjake (Prior) on Nov 21, 2003 at 02:57 UTC

    Like I've said before (1, 2, 3), if you're looking for something like phpMyAdmin, checkout MySQLMan. It's free and perl-based.

    --
    "To err is human, but to really foul things up you need a computer." --Paul Ehrlich

Re: OT - MySQL report generation
by DaWolf (Curate) on Nov 21, 2003 at 01:06 UTC
    I'm not sure if that's what you want (the definition of "nice" changes from person to person :)), but there is a software that you can find on mySQL's website that is called mySQL Control Center.

    Hope it helps.

    my ($author_nickname, $author_email) = ("DaWolf","erabbott\@terra.com.br") if ($author_name eq "Er Galvão Abbott");
Re: OT - MySQL report generation
by Cody Pendant (Prior) on Nov 21, 2003 at 00:14 UTC
    Isn't there a Perl version of the myAdmin thing? Or is it only PHPmyAdmin now?


    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print