Commit d3d50570 authored by Tuukka Pasanen's avatar Tuukka Pasanen Committed by Daniel Black

MDEV-28376: Make sure available Perl MariaDB DBI driver is chosen

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.
parent af869493
...@@ -240,26 +240,56 @@ sub get_user_mycnf ...@@ -240,26 +240,56 @@ sub get_user_mycnf
sub connect_to_MySQL sub connect_to_MySQL
{ {
print "connect_to_MySQL\n" if $op{debug}; print "connect_to_MySQL\n" if $op{debug};
my $dsn; if(my @driverList = grep {/mariadb|mysql/i} DBI->available_drivers()) {
my $dsn;
if($mycnf{'socket'} && -S $mycnf{'socket'}) my $driver = undef;
{
$dsn = "DBI:MariaDB:mariadb_socket=$mycnf{socket}"; if(grep {/mariadb/i} @driverList)
} {
elsif($mycnf{'host'}) $driver = "DBI:MariaDB";
{ }
$dsn = "DBI:MariaDB:host=$mycnf{host}" . ($mycnf{port} ? ";port=$mycnf{port}" : ""); elsif(grep {/mysql/i} @driverList)
} {
else $driver = "DBI:mysql";
{ }
$dsn = "DBI:MariaDB:host=localhost";
} if($mycnf{'socket'} && -S $mycnf{'socket'})
{
print "connect_to_MySQL: DBI DSN: $dsn\n" if $op{debug}; if(grep {/mariadb/i} @driverList)
{
$dbh = DBI->connect($dsn, $mycnf{'user'}, $mycnf{'pass'}) or die; $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 sub collect_reports
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment