Skip to content

Commit 9743bec

Browse files
committed
Fix mysql_get_client_version() function
MariaDB Connector/C 3.1.10 changed API of mysql_get_client_version() function. Before that release it returned client version. With that release it started returning Connector/C package version. So when compiling with MariaDB Connector/C client library, redefine mysql_get_client_version() to always returns client version via function mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) call. Driver code expects for a long time that mysql_get_client_version() call returns client version and not something different. Function mariadb_get_infov() is supported since MariaDB Connector/C 3.0+. Fixes: perl5-dbi/DBD-mysql#333
1 parent cbdd83e commit 9743bec

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Makefile.PL

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,13 @@ sub Configure {
757757
# libmysqld.a from MySQL 8.x is broken too
758758
$function .= "\n#if !defined(MARIADB_BASE_VERSION) && !defined(MARIADB_PACKAGE_VERSION)\nif (mysql_get_client_version() >= 80000) return 1;\n#endif\n";
759759
}
760-
$function .= 'return (mysql_get_client_version() == MYSQL_VERSION_ID) ? 0 : 1;';
760+
# MariaDB Connector/C 3.1.10+ has broken mysql_get_client_version() function, so use mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) instead
761+
$function .= "size_t version;\n";
762+
$function .= "#if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000\n";
763+
$function .= "if (mariadb_get_infov((void *)0, MARIADB_CLIENT_VERSION_ID, &version) != 0)\n";
764+
$function .= "#endif\n";
765+
$function .= "version = mysql_get_client_version();\n";
766+
$function .= 'return (version == MYSQL_VERSION_ID) ? 0 : 1;';
761767
# libmysqld is built using g++ rather than gcc and sometimes
762768
# we have to use libstdc++ to resolve linking problems
763769
foreach my $add_ldflags (undef, '-lstdc++') {

dbdimp.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,32 @@ PERL_STATIC_INLINE UV SvUV_nomg(pTHX_ SV *sv)
322322
#define my_bool bool
323323
#endif
324324

325+
/*
326+
* MariaDB Connector/C 3.1.10 changed API of mysql_get_client_version()
327+
* function. Before that release it returned client version. With that release
328+
* it started returning Connector/C package version.
329+
*
330+
* So when compiling with MariaDB Connector/C client library, redefine
331+
* mysql_get_client_version() to always returns client version via function
332+
* mariadb_get_infov(MARIADB_CLIENT_VERSION_ID) call.
333+
*
334+
* Driver code expects for a long time that mysql_get_client_version() call
335+
* returns client version and not something different.
336+
*
337+
* Function mariadb_get_infov() is supported since MariaDB Connector/C 3.0+.
338+
*/
339+
#if defined(MARIADB_PACKAGE_VERSION) && defined(MARIADB_PACKAGE_VERSION_ID) && MARIADB_PACKAGE_VERSION_ID >= 30000
340+
PERL_STATIC_INLINE unsigned long mariadb_get_client_version(void)
341+
{
342+
/* MARIADB_CLIENT_VERSION_ID really expects size_t type, documentation is wrong and says unsigned int. */
343+
size_t version;
344+
if (mariadb_get_infov(NULL, MARIADB_CLIENT_VERSION_ID, &version) != 0)
345+
version = mysql_get_client_version(); /* On error fallback to mysql_get_client_version() */
346+
return version;
347+
}
348+
#define mysql_get_client_version() mariadb_get_client_version()
349+
#endif
350+
325351
/* MYSQL_SECURE_AUTH became a no-op from MySQL 5.7.5 and is removed from MySQL 8.0.3 */
326352
#if defined(MARIADB_BASE_VERSION) || MYSQL_VERSION_ID <= 50704
327353
#define HAVE_SECURE_AUTH

0 commit comments

Comments
 (0)