Catch query failure
authorJamie Cameron <jcameron@webmin.com>
Thu, 2 Jul 2009 23:24:56 +0000 (23:24 +0000)
committerJamie Cameron <jcameron@webmin.com>
Thu, 2 Jul 2009 23:24:56 +0000 (23:24 +0000)
postgresql/edit_dbase.cgi
postgresql/postgresql-lib.pl

index 825be14..9db6327 100755 (executable)
@@ -103,8 +103,13 @@ elsif (@titles || @indexes || @views || @seqs) {
        if ($displayconfig{'style'} == 1) {
                # Show as table
                foreach $t (@titles) {
-                       local $c = &execute_sql($in{'db'},
-                               "select count(*) from ".quote_table($t));
+                       local $c;
+                       eval {
+                               local $main::error_must_die = 1;
+                               $c = &execute_sql($in{'db'},
+                                   "select count(*) from ".quote_table($t));
+                               };
+                       $c ||= { 'data' => [ [ "-" ] ] };
                        push(@rows, $c->{'data'}->[0]->[0]);
                        local @str = &table_structure($in{'db'}, $t);
                        push(@fields, scalar(@str));
index 1ede9df..a6b2f22 100644 (file)
@@ -760,14 +760,14 @@ sub quotestr
 return "\"$_[0]\"";
 }
 
-# execute_sql_file(database, file, [user, pass])
+# execute_sql_file(database, file, [user, pass], [unix-user])
 # Executes some file of SQL statements, and returns the exit status and output
 sub execute_sql_file
 {
+local ($db, $file, $user, $pass, $unixuser) = @_;
 if (&is_readonly_mode()) {
        return (0, undef);
        }
-local ($db, $file, $user, $pass) = @_;
 if (!defined($user)) {
        $user = $postgres_login;
        $pass = $postgres_pass;
@@ -780,6 +780,9 @@ local $cmd = &quote_path($config{'psql'})." -f ".&quote_path($file).
 if ($postgres_sameunix && defined(getpwnam($postgres_login))) {
        $cmd = &command_as_user($postgres_login, 0, $cmd);
        }
+elsif ($unixuser && $unixuser ne 'root' && $< == 0) {
+       $cmd = &command_as_user($unixuser, 0, $cmd);
+       }
 $cmd = &command_with_login($cmd, $user, $pass);
 local $out = &backquote_logged("$cmd 2>&1");
 return ($out =~ /ERROR/i ? 1 : 0, $out);