Skip to content

Commit

Permalink
detect MySQL client version at load time
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazel committed Jul 14, 2010
1 parent a06fc96 commit cf2b5f0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ext/mysql_api/mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,21 @@ static VALUE error_sqlstate(VALUE obj)

void Init_mysql_api(void)
{
int i;
int dots = 0;
const char *lib = mysql_get_client_info();
for (i = 0; lib[i] != 0 && MYSQL_SERVER_VERSION[i] != 0; i++) {
if (lib[i] == '.') {
dots++;
// we only compare MAJOR and MINOR
if (dots == 2) break;
}
if (lib[i] != MYSQL_SERVER_VERSION[i]) {
rb_raise(rb_eLoadError, "Incorrect MySQL client library version! This gem was compiled for %s but the client library is %s.", MYSQL_SERVER_VERSION, lib);
return;
}
}

cMysql = rb_define_class("Mysql", rb_cObject);
cMysqlRes = rb_define_class_under(cMysql, "Result", rb_cObject);
cMysqlField = rb_define_class_under(cMysql, "Field", rb_cObject);
Expand Down

0 comments on commit cf2b5f0

Please sign in to comment.