Handle hostnames with upper-case letters
[webmin.git] / custom / sql.cgi
1 #!/usr/local/bin/perl
2 # Execute some SQL and display the result
3
4 require './custom-lib.pl';
5 if ($ENV{'CONTENT_TYPE'} =~ /multipart\/form-data/i) {
6         &ReadParseMime();
7         }
8 else {
9         &ReadParse();
10         }
11 &error_setup($text{'srun_err'});
12 $cmd = &get_command($in{'id'}, $in{'idx'});
13 &can_run_command($cmd) || &error($text{'run_ecannot'});
14
15 # Connect to the DB
16 use DBI;
17 $drh = DBI->install_driver($cmd->{'type'});
18 $drh || &error($text{'srun_edriver'});
19 ($driver) = grep { $_->{'driver'} eq $cmd->{'type'} } &list_dbi_drivers();
20 $dbh = $drh->connect($driver->{'dbparam'}."=".$cmd->{'db'}.
21                      ($cmd->{'host'} ? ";host=$cmd->{'host'}" : ""),
22                      $cmd->{'user'}, $cmd->{'pass'}, { });
23 $dbh || &error(&text('srun_econnect', $drh->errstr));
24
25 # Show header
26 &ui_print_unbuffered_header(undef, $text{'srun_title'}, "");
27 print &text('srun_cmd', "<tt>$cmd->{'sql'}</tt>"),"<p>\n";
28
29 # Work out params
30 ($env, $export, $str, $displaystr, $args) = &set_parameter_envs($cmd, $cmd->{'sql'}, undef);
31
32 # Run it
33 $cmd = $dbh->prepare($cmd->{'sql'});
34 if (!$cmd) {
35         print &text('srun_eprepare', $dbh->errstr),"<p>\n";
36         }
37 elsif (!$cmd->execute(@$args)) {
38         print &text('srun_eexecute', $dbh->errstr),"<p>\n";
39         }
40 else {
41         # Show results
42         if (@titles = @{$cmd->{'NAME'}}) {
43                 print &ui_columns_start(\@titles);
44
45                 # Show results
46                 while(my @r = $cmd->fetchrow()) {
47                         print &ui_columns_row(\@r);
48                         }
49
50                 print &ui_columns_end();
51                 $cmd->finish();
52                 }
53         else {
54                 $r = $cmd->finish();
55                 print &text('srun_none', $r),"<p>\n";
56                 }
57         }
58
59 &ui_print_footer("", $text{'index_return'});
60