3 # Execute some SQL commands from a file and display the output
5 require './mysql-lib.pl';
7 &can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
8 $access{'edonly'} && &error($text{'dbase_ecannot'});
9 &error_setup($text{'exec_err'});
13 $in{'upload'} || &error($text{'exec_eupload'});
16 print TEMP $in{'upload'};
18 &ui_print_header(undef, $text{'exec_title'}, "");
19 print "$text{'exec_uploadout'}<p>\n";
24 -r $in{'file'} || &error($text{'exec_efile'});
26 &ui_print_header(undef, $text{'exec_title'}, "");
27 print &text('exec_fileout', "<tt>$in{'file'}</tt>"),"<p>\n";
31 # Un-compress file if needed
32 $cf = &compression_format($file);
33 $cmd = $cf == 1 ? "gunzip -c" :
34 $cf == 2 ? "uncompress -C" :
35 $cf == 3 ? "bunzip2 -c" : undef;
37 ($prog, @args) = split(/\s+/, $cmd);
38 &has_command($prog) ||
39 &error(&text('exec_ecompress', "<tt>$prog</tt>"));
40 $tempfile = &transname();
41 $out = &backquote_command("$cmd <$file 2>&1 >$tempfile");
43 &error(&text('exec_ecompress2', "<pre>$out</pre>"));
45 unlink($file) if ($need_unlink);
50 # Check the file for tables created and rows inserted
55 if (/^\s*insert\s+into\s+`(\S+)`/i ||
56 /^\s*insert\s+into\s+(\S+)/i) {
59 if (/^\s*create\s+table\s+`(\S+)`/i ||
60 /^\s*create\s+table\s+(\S+)/i) {
67 ($ex, $out) = &execute_sql_file($in{'db'}, $file,
68 undef, undef, $access{'buser'});
69 print &html_escape($out);
70 $got++ if ($out =~ /\S/);
71 print "<i>$text{'exec_noout'}</i>\n" if (!$got);
75 print &text('exec_created', $create_count),"\n";
78 print &text('exec_inserted', $insert_count),"\n";
80 if ($create_count || $insert_count) {
84 &webmin_log("execfile", undef, $in{'db'}, { 'mode' => $in{'mode'},
85 'file' => $in{'file'} });
86 unlink($file) if ($need_unlink);
88 &ui_print_footer("exec_form.cgi?db=$in{'db'}&mode=file", $text{'exec_return'},
89 "edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'},
90 "", $text{'index_return'});