add Mysql2::Client#info and Mysql2::Client#server_info methods

This commit is contained in:
Brian Lopez 2010-04-03 12:15:16 -07:00
parent 0128ad0e13
commit b820100249
2 changed files with 27 additions and 2 deletions

View File

@ -146,6 +146,24 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
}
}
static VALUE rb_mysql_client_info(VALUE self) {
VALUE version = rb_hash_new();
rb_hash_aset(version, sym_id, LONG2FIX(mysql_get_client_version()));
rb_hash_aset(version, sym_version, rb_str_new2(mysql_get_client_info()));
return version;
}
static VALUE rb_mysql_client_server_info(VALUE self) {
MYSQL * client;
VALUE version;
GetMysql2Client(self, client);
version = rb_hash_new();
rb_hash_aset(version, sym_id, LONG2FIX(mysql_get_server_version(client)));
rb_hash_aset(version, sym_version, rb_str_new2(mysql_get_server_info(client)));
return version;
}
/* Mysql2::Result */
static VALUE rb_mysql_result_to_obj(MYSQL_RES * r) {
VALUE obj;
@ -322,6 +340,8 @@ void Init_mysql2_ext() {
rb_define_method(cMysql2Client, "initialize", rb_mysql_client_init, -1);
rb_define_method(cMysql2Client, "query", rb_mysql_client_query, 1);
rb_define_method(cMysql2Client, "escape", rb_mysql_client_escape, 1);
rb_define_method(cMysql2Client, "info", rb_mysql_client_info, 0);
rb_define_method(cMysql2Client, "server_info", rb_mysql_client_server_info, 0);
cMysql2Result = rb_define_class_under(mMysql2, "Result", rb_cObject);
rb_define_method(cMysql2Result, "each", rb_mysql_result_each, -1);
@ -340,6 +360,8 @@ void Init_mysql2_ext() {
sym_port = ID2SYM(rb_intern("port"));
sym_socket = ID2SYM(rb_intern("socket"));
sym_connect_timeout = ID2SYM(rb_intern("connect_timeout"));
sym_id = ID2SYM(rb_intern("id"));
sym_version = ID2SYM(rb_intern("version"));
#ifdef HAVE_RUBY_ENCODING_H
utf8Encoding = rb_enc_find_index("UTF-8");

View File

@ -15,17 +15,20 @@ int utf8Encoding, binaryEncoding;
/* Mysql2::Client */
#define GetMysql2Client(obj, sval) (sval = (MYSQL*)DATA_PTR(obj));
static ID sym_socket, sym_host, sym_port, sym_username, sym_password,
sym_database, sym_reconnect, sym_connect_timeout, sym_id, sym_version;
static VALUE rb_mysql_client_new(int argc, VALUE * argv, VALUE klass);
static VALUE rb_mysql_client_init(VALUE self, int argc, VALUE * argv);
static VALUE rb_mysql_client_query(VALUE self, VALUE query);
static VALUE rb_mysql_client_escape(VALUE self, VALUE str);
static VALUE rb_mysql_client_info(VALUE self);
static VALUE rb_mysql_client_server_info(VALUE self);
void rb_mysql_client_free(void * client);
/* Mysql2::Result */
#define GetMysql2Result(obj, sval) (sval = (MYSQL_RES*)DATA_PTR(obj));
VALUE cMysql2Result;
static ID sym_symbolize_keys, sym_socket, sym_host, sym_port, sym_username,
sym_password, sym_database, sym_reconnect, sym_connect_timeout;
static ID sym_symbolize_keys;
static VALUE rb_mysql_result_to_obj(MYSQL_RES * res);
static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self);
static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self);