Catch query failure

This commit is contained in:
Jamie Cameron
2009-07-02 23:24:56 +00:00
parent bd2b2424c4
commit 1726d33b86
2 changed files with 12 additions and 4 deletions

View 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);