From 102139ebe358dc1e561a69ce39abeea53f0f5c8b Mon Sep 17 00:00:00 2001 From: Dominik Meyer Date: Tue, 2 Jan 2024 23:36:02 +0100 Subject: [PATCH] ADD: more tests --- plugins/rcpt_mysql | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/rcpt_mysql b/plugins/rcpt_mysql index 14e067d..d7db4db 100644 --- a/plugins/rcpt_mysql +++ b/plugins/rcpt_mysql @@ -29,6 +29,7 @@ sub init { $self->createQuery(); $self->createDSN(); + $self->tryToConnect(); } sub createDSN @@ -84,6 +85,21 @@ sub createQuery $self->log(LOGDEBUG, "created query " . $self->{sqlquery}); } +sub tryToConnect +{ + my $self = shift; + + my $dbh = DBI::connect($self->{dsn}, $self->{user}, $self->{pass}); + + if ($dbh->err()) + { + $self->log(LOGERROR, "error connecting to DB: " . $dbh->errstr()); + return DECLINED; + } + + $dbh->disconnect; +} + sub prepareParams { my $self = shift; @@ -196,7 +212,7 @@ sub askDatabase } my $dsn = $self->{dsn}; - my $dbh = DBI::connect($dsn, $self->{user}, $self->{pass},{ RaiseError => 1, PrintError => 0 }); + my $dbh = DBI::connect($dsn, $self->{user}, $self->{pass}); if ($dbh->err()) {