3 # Execute some SQL command and display output
5 require './postgresql-lib.pl';
7 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8 &error_setup($text{'exec_err'});
11 # Delete the history file
12 &unlink_file($commands_file.".".$in{'db'});
13 &redirect("exec_form.cgi?db=$in{'db'}");
17 $in{'cmd'} = join(" ", split(/[\r\n]+/, $in{'cmd'}));
18 $cmd = $in{'cmd'} ? $in{'cmd'} : $in{'old'};
19 $d = &execute_sql_logged($in{'db'}, $cmd);
21 &ui_print_header(undef, $text{'exec_title'}, "");
22 print &text('exec_out', "<tt>".&html_escape($cmd)."</tt>"),"<p>\n";
23 @data = @{$d->{'data'}};
25 print &ui_columns_start($d->{'titles'});
27 @prow = map { ref($_) eq 'ARRAY' ? join(", ", @$_)
29 print &ui_columns_row(\@prow);
31 print &ui_columns_end();
34 print "<b>$text{'exec_none'}</b> <p>\n";
37 # Add to the old commands file
38 open(OLD, "$commands_file.$in{'db'}");
41 $already++ if ($_ eq $in{'cmd'});
44 if (!$already && $in{'cmd'} =~ /\S/) {
45 &open_lock_tempfile(OLD, ">>$commands_file.$in{'db'}");
46 &print_tempfile(OLD, "$in{'cmd'}\n");
48 chmod(0700, "$commands_file.$in{'db'}");
51 &webmin_log("exec", undef, $in{'db'}, \%in);
54 &ui_print_footer("exec_form.cgi?db=$in{'db'}", $text{'exec_return'},
55 "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
56 "", $text{'index_return'});