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:
\n"
. $q->textarea( "sqlquery", $execstr, 8, 60 )
. "
\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
| ] . qq[$_ | \n]; } $html .= "
| $v | \n"; } $html .= "