Skip to content

Commit

Permalink
MDEV-28376: Make sure available Perl MariaDB DBI driver is chosen
Browse files Browse the repository at this point in the history
Commit introduces automatic detection which supported
Perl MariaDB DBI driver is available:

 * DBD::mysql
 * DBD::MariaDB

If nothing is then bail out and die

Current Detection prefers Perl DBD:MariaDB driver.

This is mainly for older Linux distros or Windows which does not
have Perl DBD:MariaDB packaged or does not want to use Perl cpan command.
  • Loading branch information
illuusio authored and grooverdan committed May 24, 2022
1 parent 99566fc commit 4435904
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions debian/additions/mariadb-report
Original file line number Diff line number Diff line change
Expand Up @@ -240,26 +240,56 @@ sub get_user_mycnf

sub connect_to_MySQL
{
print "connect_to_MySQL\n" if $op{debug};

my $dsn;

if($mycnf{'socket'} && -S $mycnf{'socket'})
{
$dsn = "DBI:MariaDB:mariadb_socket=$mycnf{socket}";
}
elsif($mycnf{'host'})
{
$dsn = "DBI:MariaDB:host=$mycnf{host}" . ($mycnf{port} ? ";port=$mycnf{port}" : "");
}
else
{
$dsn = "DBI:MariaDB:host=localhost";
}

print "connect_to_MySQL: DBI DSN: $dsn\n" if $op{debug};

$dbh = DBI->connect($dsn, $mycnf{'user'}, $mycnf{'pass'}) or die;
print "connect_to_MySQL\n" if $op{debug};

if(my @driverList = grep {/mariadb|mysql/i} DBI->available_drivers()) {
my $dsn;
my $driver = undef;

if(grep {/mariadb/i} @driverList)
{
$driver = "DBI:MariaDB";
}
elsif(grep {/mysql/i} @driverList)
{
$driver = "DBI:mysql";
}

if($mycnf{'socket'} && -S $mycnf{'socket'})
{
if(grep {/mariadb/i} @driverList)
{
$dsn = $driver . ":mariadb_socket=$mycnf{socket}";
}
elsif(grep {/mysql/i} @driverList)
{
$dsn = $driver . ":mysql_socket=$mycnf{socket}";
}
}
elsif($mycnf{'host'})
{
$dsn = $driver . ":host=$mycnf{host}" . ($mycnf{port} ? ";port=$mycnf{port}" : "");
}
else
{
$dsn = $driver . ":host=localhost";
}

print "connect_to_MySQL: DBI DSN: " . $dsn . "\n" if $op{debug};

$dbh = DBI->connect($dsn, $mycnf{'user'}, $mycnf{'pass'}) or die;
}
else
{
print STDERR "Install Perl 5.x driver: DBD:mysql or DBD:MariaDB\n";
print STDERR "currently installed Perl DBD drivers:\n";
foreach my $driver (DBI->available_drivers())
{
print STDERR " * " . $driver . "\n";
}
print STDERR "\n";
die("Exit as no MariaDB DBI driver found!\n");
}
}

sub collect_reports
Expand Down

0 comments on commit 4435904

Please sign in to comment.