From bbf7585d09441a95103654ef75b9331e9f86c043 Mon Sep 17 00:00:00 2001 From: Brian Lopez Date: Thu, 1 Apr 2010 14:29:20 -0700 Subject: [PATCH] use binary encoding on fields that have the binary flag set --- ext/mysql2_ext.c | 9 +++++++-- ext/mysql2_ext.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ext/mysql2_ext.c b/ext/mysql2_ext.c index 3edc776..e357181 100644 --- a/ext/mysql2_ext.c +++ b/ext/mysql2_ext.c @@ -75,7 +75,7 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) { newStr = rb_str_new(query, mysql_real_escape_string(client, query + queryLen, query, queryLen)); #ifdef HAVE_RUBY_ENCODING_H - rb_enc_associate_index(newStr, utf8Encoding); + rb_enc_associate_index(newStr, utf8Encoding); #endif return newStr; } @@ -191,7 +191,11 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) { default: val = rb_str_new(row[i], fieldLengths[i]); #ifdef HAVE_RUBY_ENCODING_H - rb_enc_associate_index(val, utf8Encoding); + if (fields[i].flags & BINARY_FLAG) { + rb_enc_associate_index(val, binaryEncoding); + } else { + rb_enc_associate_index(val, utf8Encoding); + } #endif break; } @@ -265,5 +269,6 @@ void Init_mysql2_ext() { #ifdef HAVE_RUBY_ENCODING_H utf8Encoding = rb_enc_find_index("UTF-8"); + binaryEncoding = rb_enc_find_index("binary"); #endif } \ No newline at end of file diff --git a/ext/mysql2_ext.h b/ext/mysql2_ext.h index 830c064..5c41cfd 100644 --- a/ext/mysql2_ext.h +++ b/ext/mysql2_ext.h @@ -7,7 +7,7 @@ #ifdef HAVE_RUBY_ENCODING_H #include -int utf8Encoding; +int utf8Encoding, binaryEncoding; #endif // VALUE cBigDecimal;