+ Fix dbi error message

This commit is contained in:
garnier-quentin 2019-06-01 08:32:41 +02:00
parent 6bf3b23a0c
commit 37c165e2d8
1 changed files with 12 additions and 12 deletions

View File

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