+ Fix dbi error message

This commit is contained in:
garnier-quentin 2019-06-01 08:32:41 +02:00
parent ea50fa929c
commit 06076a9ce6

View File

@ -46,13 +46,13 @@ sub new {
} }
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "datasource:s@" => { name => 'data_source' }, 'datasource:s@' => { name => 'data_source' },
"username:s@" => { name => 'username' }, 'username:s@' => { name => 'username' },
"password:s@" => { name => 'password' }, 'password:s@' => { name => 'password' },
"connect-options:s@" => { name => 'connect_options' }, 'connect-options:s@' => { name => 'connect_options' },
"sql-errors-exit:s" => { name => 'sql_errors_exit', default => 'unknown' }, 'sql-errors-exit:s' => { name => 'sql_errors_exit', default => 'unknown' },
"timeout:i" => { name => 'timeout' }, 'timeout:i' => { name => 'timeout' },
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'DBI OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'DBI OPTIONS', once => 1);
@ -95,7 +95,7 @@ sub handle_ALRM {
$self->disconnect(); $self->disconnect();
$self->{output}->output_add(severity => $self->{sql_errors_exit}, $self->{output}->output_add(severity => $self->{sql_errors_exit},
short_msg => "Timeout"); short_msg => 'Timeout');
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
@ -146,7 +146,7 @@ sub check_options {
} }
if (!defined($self->{data_source}) || $self->{data_source} eq '') { if (!defined($self->{data_source}) || $self->{data_source} eq '') {
$self->{output}->add_option_msg(short_msg => "Need to specify data_source arguments."); $self->{output}->add_option_msg(short_msg => 'Need to specify data_source arguments.');
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
} }
if (defined($self->{connect_options}) && $self->{connect_options} ne '') { if (defined($self->{connect_options}) && $self->{connect_options} ne '') {
@ -228,7 +228,7 @@ sub connect {
alarm(0) if (defined($self->{timeout})); alarm(0) if (defined($self->{timeout}));
if (!defined($self->{instance})) { if (!defined($self->{instance})) {
my $err_msg = sprintf("Cannot connect: %s", defined($DBI::errstr) ? $DBI::errstr : "(no error string)"); my $err_msg = sprintf('Cannot connect: %s', defined($DBI::errstr) ? $DBI::errstr : '(no error string)');
if ($dontquit == 0) { if ($dontquit == 0) {
$self->{output}->add_option_msg(short_msg => $err_msg); $self->{output}->add_option_msg(short_msg => $err_msg);
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
@ -277,16 +277,16 @@ sub query {
$self->{statement_handle} = $self->{instance}->prepare($options{query}); $self->{statement_handle} = $self->{instance}->prepare($options{query});
if (!defined($self->{statement_handle})) { if (!defined($self->{statement_handle})) {
return 1 if ($continue_error == 1); return 1 if ($continue_error == 1);
$self->{output}->add_option_msg(short_msg => 'Cannot execute query: ' . $self->{instance}->errstr);
$self->disconnect(); $self->disconnect();
$self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{instance}->errstr);
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
} }
my $rv = $self->{statement_handle}->execute; my $rv = $self->{statement_handle}->execute;
if (!$rv) { if (!$rv) {
return 1 if ($continue_error == 1); return 1 if ($continue_error == 1);
$self->{output}->add_option_msg(short_msg => 'Cannot execute query: ' . $self->{statement_handle}->errstr);
$self->disconnect(); $self->disconnect();
$self->{output}->add_option_msg(short_msg => "Cannot execute query: " . $self->{statement_handle}->errstr);
$self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit}); $self->{output}->option_exit(exit_litteral => $self->{sql_errors_exit});
} }