I'm working with some legacy perl code, and there is a lot of checking
of $DBI::err after a ->connect call:
# DBI bug workaround
my $previous_error = $DBI::err;
my $previous_error_str = $DBI::errstr;
eval {
$dbh = DBI->connect(..., { AutoCommit => 1, RaiseError => 1,
PrintError => 0, LongReadLen => ..., LongTruncOk => 1 });
if ($dbh && ($dbh->err || $dbh->errstr) && ($dbh->err eq
$previous_error || $dbh->errstr eq $previous_error_str) {
$dbh->set_err(undef, undef);
}
};
if (!$dbh || $@ || $DBI::err) {
# something bad happened
}
Is any of this still necessary? Can I safely replace it with:
eval {
$dbh = DBI->connect(...);
};
if (!$dbh || $@) {
# something bad happened
}
It seems that at one point there were issues with $DBI::err not getting cleared.