(core) catch connect croack error for database plugin (#3477)
This commit is contained in:
parent
d1ea446afd
commit
acc1d9b5b9
|
@ -224,18 +224,29 @@ sub connect {
|
|||
}
|
||||
|
||||
$self->set_signal_handlers();
|
||||
alarm($self->{timeout}) if (defined($self->{timeout}));
|
||||
$self->{instance} = DBI->connect(
|
||||
"DBI:". $self->{data_source},
|
||||
$self->{username},
|
||||
$self->{password},
|
||||
{ RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} }
|
||||
);
|
||||
alarm(0) if (defined($self->{timeout}));
|
||||
my $connect_error;
|
||||
eval {
|
||||
alarm($self->{timeout}) if (defined($self->{timeout}));
|
||||
$self->{instance} = DBI->connect(
|
||||
"DBI:". $self->{data_source},
|
||||
$self->{username},
|
||||
$self->{password},
|
||||
{ RaiseError => 0, PrintError => 0, AutoCommit => 1, %{$self->{connect_options_hash}} }
|
||||
);
|
||||
alarm(0) if (defined($self->{timeout}));
|
||||
};
|
||||
if ($@) {
|
||||
$connect_error = $@;
|
||||
}
|
||||
|
||||
$self->prepare_destroy();
|
||||
|
||||
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 :
|
||||
(defined($connect_error) ? $connect_error : '(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});
|
||||
|
|
|
@ -55,6 +55,7 @@ sub connect {
|
|||
}
|
||||
}
|
||||
|
||||
my $connect_error;
|
||||
if (defined($self->{timeout})) {
|
||||
my $mask = POSIX::SigSet->new(SIGALRM);
|
||||
my $action = POSIX::SigAction->new(
|
||||
|
@ -69,14 +70,26 @@ sub connect {
|
|||
$self->connect_db2();
|
||||
};
|
||||
alarm(0);
|
||||
if ($@) {
|
||||
$connect_error = $@;
|
||||
}
|
||||
};
|
||||
sigaction(SIGALRM, $oldaction);
|
||||
} else {
|
||||
$self->connect_db2();
|
||||
eval {
|
||||
$self->connect_db2();
|
||||
};
|
||||
if ($@) {
|
||||
$connect_error = $@;
|
||||
}
|
||||
}
|
||||
|
||||
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 :
|
||||
(defined($connect_error) ? $connect_error : '(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});
|
||||
|
|
|
@ -28,7 +28,7 @@ use POSIX qw(:signal_h);
|
|||
|
||||
sub connect_oracle {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
$self->{instance} = DBI->connect(
|
||||
'DBI:' . $self->{data_source},
|
||||
$self->{username},
|
||||
|
@ -55,6 +55,7 @@ sub connect {
|
|||
}
|
||||
}
|
||||
|
||||
my $connect_error;
|
||||
if (defined($self->{timeout})) {
|
||||
my $mask = POSIX::SigSet->new(SIGALRM);
|
||||
my $action = POSIX::SigAction->new(
|
||||
|
@ -69,14 +70,26 @@ sub connect {
|
|||
$self->connect_oracle();
|
||||
};
|
||||
alarm(0);
|
||||
if ($@) {
|
||||
$connect_error = $@;
|
||||
}
|
||||
};
|
||||
sigaction(SIGALRM, $oldaction);
|
||||
} else {
|
||||
$self->connect_oracle();
|
||||
eval {
|
||||
$self->connect_oracle();
|
||||
};
|
||||
if ($@) {
|
||||
$connect_error = $@;
|
||||
}
|
||||
}
|
||||
|
||||
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 :
|
||||
(defined($connect_error) ? $connect_error : '(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});
|
||||
|
|
Loading…
Reference in New Issue