Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with MariaDB 10.3 #291

Merged
merged 6 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ matrix:
# - perl: "5.20"
# env: DB=MariaDB VERSION=10.2.5
# mariadb_config bug: https://jira.mariadb.org/browse/MDEV-15820
# - perl: "5.20"
# env: DB=MariaDB VERSION=10.3.9
- perl: "5.20"
env: DB=MariaDB VERSION=10.3.11
- perl: "5.20"
env: CONC_DB=MySQL CONC_VERSION=6.0.0-beta
- perl: "5.20"
Expand Down Expand Up @@ -261,7 +261,17 @@ before_script:
export DBD_MYSQL_CONFIG="skip" ;
fi ;
elif [ -n "$DB" ]; then
export DBD_MYSQL_CONFIG="$SANDBOX_HOME/msb/my sql_config" ;
if [ "$DB" = "MariaDB" ]; then
mariadb_config="$SANDBOX_HOME/binary/${VERSION}/bin/mariadb_config" ;
if [ -e $mariadb_config ]; then
export DBD_MYSQL_CONFIG=$mariadb_config;
else
echo "$mariadb_config does not exist, falling back to my sql_config" ;
export DBD_MYSQL_CONFIG="$SANDBOX_HOME/msb/my sql_config" ;
fi
else
export DBD_MYSQL_CONFIG="$SANDBOX_HOME/msb/my sql_config" ;
fi
else
export DBD_MYSQL_FORCE_EMBEDDED=1 ;
fi
Expand Down
10 changes: 9 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,25 @@ sub Configure {
$str =~ s/\-L\"(.*?)\"/-L$1/sg;

# Separate libs from ldflags
# Ignore static libs like libgnutls.a as reported by MariaDB's mysql_config
if ($param eq 'libs') {
my (@libs, @ldflags);
for (split ' ', $str) {
if (/^-[Ll]/ || /^[^\-]/) { push @libs, $_ }
if (/^-[Ll]/ || /^[^\-]/) { push @libs, $_ unless /\.a$/ }
else { push @ldflags, $_ }
}
$str = "@libs";
$opt->{ldflags} = "@ldflags";
$source->{ldflags} = "mysql_config";
}

if ($command =~ /10.3/) {
# MariaDB's mysql_config/mariadb_config reports the compile time
# locations, not the install location. This results in issues for
# dbdeployer etc. where these are not the same.
my $installdir = substr(dirname($opt->{'mysql_config'}), 1, -4);
$str =~ s#usr/local/mysql#$installdir#g;
}
$opt->{$param} = $str;
$source->{$param} = "mysql_config";
return;
Expand Down
15 changes: 15 additions & 0 deletions dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4055,7 +4055,12 @@ int dbd_describe(SV* sth, imp_sth_t* imp_sth)
break;

default:
#if MYSQL_VERSION_ID > 100300
// https://jira.mariadb.org/browse/MDEV-18143
buffer->buffer_length= fields[i].max_length ? fields[i].max_length : 2;
#else
buffer->buffer_length= fields[i].max_length ? fields[i].max_length : 1;
#endif
Newz(908, fbh->data, buffer->buffer_length, char);
buffer->buffer= (char *) fbh->data;
}
Expand Down Expand Up @@ -5313,6 +5318,16 @@ int mysql_db_reconnect(SV* h)
else
imp_dbh= (imp_dbh_t*) imp_xxh;

/* reconnect a closed connection, used in do() for implicit reconnect */
if (!DBIc_has(imp_dbh, DBIcf_ACTIVE) && DBIc_has(imp_dbh, DBIcf_AutoCommit)) {
if (my_login(aTHX_ h, imp_dbh)) {
DBIc_ACTIVE_on(imp_dbh);
DBIc_set(imp_dbh, DBIcf_AutoCommit, TRUE);
return TRUE;
}
return FALSE;
}

if (mysql_errno(imp_dbh->pmysql) != CR_SERVER_GONE_ERROR &&
mysql_errno(imp_dbh->pmysql) != CR_SERVER_LOST)
/* Other error */
Expand Down
3 changes: 3 additions & 0 deletions mysql.xs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ do(dbh, statement, attr=Nullsv, ...)
MYSQL_BIND *bind= NULL;
#endif
ASYNC_CHECK_XS(dbh);
if ((!DBIc_has(imp_dbh, DBIcf_ACTIVE)) &&
(!mysql_db_reconnect(dbh)))
XSRETURN_UNDEF;
#if MYSQL_VERSION_ID >= MULTIPLE_RESULT_SET_VERSION
while (mysql_next_result(imp_dbh->pmysql)==0)
{
Expand Down
12 changes: 10 additions & 2 deletions t/15reconnect.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
if ($@) {
plan skip_all => "no database connection";
}
plan tests => 8 * 2;
plan tests => 13 * 2;

for my $mysql_server_prepare (0, 1) {
$dbh= DBI->connect("$test_dsn;mysql_server_prepare=$mysql_server_prepare;mysql_server_prepare_disable_fallback=1", $test_user, $test_password,
Expand All @@ -38,5 +38,13 @@ ok($dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");

ok($dbh->{Active}, "checking for reactivated handle");

$dbh->disconnect();
ok(!($dbh->{AutoCommit} = 0), "disabling autocommit");

ok($dbh->disconnect(), "disconnecting active handle");

ok(!$dbh->{Active}, "checking for inactive handle");

ok(!$dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");

ok(!$dbh->{Active}, "checking for reactivated handle");
}
4 changes: 4 additions & 0 deletions t/57trackgtid.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ if ($@) {
"no database connection";
}

if ($dbh->{mysql_serverversion} > 100000) {
plan skip_all => "GTID tracking is not available on MariaDB";
}

if ($dbh->{mysql_serverversion} < 50000) {
plan skip_all => "You must have MySQL version 5.0.0 and greater for this test to run";
}
Expand Down