Trying to work with a database on remote machines can be a pain sometimes...
This script will dump SP_HELP to the web browser, and allow the user to select one or more tables. Selected tables will then have their structure shown.
use strict; use DBI; use CGI qw(:all); use CGI::Carp qw(fatalsToBrowser); $|++; print header (); print start_html; my $db_username="user"; my $db_password="password"; my $db_serverstring="DBI:Driver:here"; my $dbh = DBI->connect ($db_serverstring, $db_username, $db_password) +|| die ("Cannot connect to database -- DBI reports ", $DBI::errstr); print "\n"; if (param("view")) { h3"<CENTER>Viewing tables</CENTER>"; my @tables = param("view"); foreach (@tables) { my $sql = $dbh->prepare ("sp_columns $_") || die;; my $sth = $sql->execute or die "no ".$DBI::errstr; print h3("<CENTER>Viewing table $_</CENTER>"),"<TABLE Border = + 1>\n"; my $THdone; while (my $result_ref = $sql->fetchrow_hashref()){ unless ($THdone) { foreach (sort keys %$result_ref) { print "<TH>$_ </TH>"; } $THdone = "yes, indeedy!"; } print "<TR>"; foreach (sort keys %$result_ref) { if (! defined $$result_ref{$_}) {print "<TD><I>undef</ +i></TD>";next} print "<TD>$$result_ref{$_}</TD>"; } print "</TR>\n"; } print "</TABLE><BR><BR>"; } } else { print h2"<CENTER>Viewing sp_help</CENTER>"; print start_form; my $sql = $dbh->prepare ("sp_help") || die;; my $sth = $sql->execute or die "no ".$DBI::errstr; print "<TABLE Border = 1>\n<TH>Select me!</TH>"; my $THdone; while (my $result_ref = $sql->fetchrow_hashref()){ unless ($THdone) { foreach (sort keys %$result_ref) { print "<TH>$_ </TH>"; } $THdone = "yes, indeedy!"; } print "<TR><TD>",checkbox(-name=>"view",-checked=>"", -value=> +"$$result_ref{Name}"),"</TD>"; foreach (sort keys %$result_ref) { if (! defined $$result_ref{$_}) {print "<TD>--undef--</TD> +";next} print "<TD>$$result_ref{$_}</TD>"; } print "</TR>\n"; } print "</TABLE>"; print submit; print end_form; } print end_html;

In reply to SP_HELP_DUMP by boo_radley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.