Extract a GET_ENCODING macro

This commit is contained in:
Lourens Naudé 2010-08-07 00:13:39 +01:00 committed by Brian Lopez
parent e250e337cf
commit 931765ee05
3 changed files with 10 additions and 7 deletions

View File

@ -239,7 +239,7 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
rb_iv_set(resultObj, "@query_options", rb_obj_dup(rb_iv_get(self, "@query_options"))); rb_iv_set(resultObj, "@query_options", rb_obj_dup(rb_iv_get(self, "@query_options")));
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_iv_set(resultObj, "@encoding", rb_iv_get(self, "@encoding")); rb_iv_set(resultObj, "@encoding", GET_ENCODING(self));
#endif #endif
return resultObj; return resultObj;
} }
@ -278,7 +278,7 @@ static VALUE rb_mysql_client_query(int argc, VALUE * argv, VALUE self) {
} }
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
// ensure the string is in the encoding the connection is expecting // ensure the string is in the encoding the connection is expecting
args.sql = rb_str_export_to_enc(args.sql, conn_enc); args.sql = rb_str_export_to_enc(args.sql, conn_enc);
#endif #endif
@ -324,7 +324,7 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
Check_Type(str, T_STRING); Check_Type(str, T_STRING);
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
// ensure the string is in the encoding the connection is expecting // ensure the string is in the encoding the connection is expecting
str = rb_str_export_to_enc(str, conn_enc); str = rb_str_export_to_enc(str, conn_enc);
#endif #endif
@ -355,7 +355,7 @@ static VALUE rb_mysql_client_info(RB_MYSQL_UNUSED VALUE self) {
VALUE version = rb_hash_new(), client_info; VALUE version = rb_hash_new(), client_info;
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
#endif #endif
rb_hash_aset(version, sym_id, LONG2NUM(mysql_get_client_version())); rb_hash_aset(version, sym_id, LONG2NUM(mysql_get_client_version()));
@ -375,7 +375,7 @@ static VALUE rb_mysql_client_server_info(VALUE self) {
VALUE version, server_info; VALUE version, server_info;
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
#endif #endif
Data_Get_Struct(self, MYSQL, client); Data_Get_Struct(self, MYSQL, client);

View File

@ -29,4 +29,7 @@
#include <client.h> #include <client.h>
#include <result.h> #include <result.h>
#define GET_ENCODING(self) \
rb_iv_get(self, "@encoding")
#endif #endif

View File

@ -64,7 +64,7 @@ static VALUE rb_mysql_result_fetch_field(VALUE self, unsigned int idx, short int
MYSQL_FIELD *field = NULL; MYSQL_FIELD *field = NULL;
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
#endif #endif
field = mysql_fetch_field_direct(wrapper->result, idx); field = mysql_fetch_field_direct(wrapper->result, idx);
@ -98,7 +98,7 @@ static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezo
void * ptr; void * ptr;
#ifdef HAVE_RUBY_ENCODING_H #ifdef HAVE_RUBY_ENCODING_H
rb_encoding *default_internal_enc = rb_default_internal_encoding(); rb_encoding *default_internal_enc = rb_default_internal_encoding();
rb_encoding *conn_enc = rb_to_encoding(rb_iv_get(self, "@encoding")); rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
#endif #endif
GetMysql2Result(self, wrapper); GetMysql2Result(self, wrapper);