Skip to content

Commit add9678

Browse files
committed
support for mysql-connector-c
check for LIBMYSQL_VERSION, if it exists we are linking against the connector library, otherwise, use MYSQL_SERVER_VERSION as before added preprocessor variable to track connector library version
1 parent 2fd0369 commit add9678

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ext/mysql2/client.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ static ID intern_merge, intern_error_number_eql, intern_sql_state_eql;
2424
mysql_client_wrapper *wrapper; \
2525
Data_Get_Struct(self, mysql_client_wrapper, wrapper)
2626

27+
/*
28+
* compatability with mysql-connector-c, where LIBMYSQL_VERSION is the correct
29+
* variable to use, but MYSQL_SERVER_VERSION gives the correct numbers when
30+
* linking against the server itself
31+
*/
32+
#ifdef LIBMYSQL_VERSION
33+
#define MYSQL_LINK_VERSION LIBMYSQL_VERSION
34+
#else
35+
#define MYSQL_LINK_VERSION MYSQL_SERVER_VERSION
36+
#endif
37+
2738
/*
2839
* used to pass all arguments to mysql_real_connect while inside
2940
* rb_thread_blocking_region
@@ -740,14 +751,15 @@ void init_mysql2_client() {
740751
int i;
741752
int dots = 0;
742753
const char *lib = mysql_get_client_info();
743-
for (i = 0; lib[i] != 0 && MYSQL_SERVER_VERSION[i] != 0; i++) {
754+
755+
for (i = 0; lib[i] != 0 && MYSQL_LINK_VERSION[i] != 0; i++) {
744756
if (lib[i] == '.') {
745757
dots++;
746758
// we only compare MAJOR and MINOR
747759
if (dots == 2) break;
748760
}
749-
if (lib[i] != MYSQL_SERVER_VERSION[i]) {
750-
rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib);
761+
if (lib[i] != MYSQL_LINK_VERSION[i]) {
762+
rb_raise(rb_eRuntimeError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_LINK_VERSION, lib);
751763
return;
752764
}
753765
}

0 commit comments

Comments
 (0)