use binary encoding on fields that have the binary flag set

This commit is contained in:
Brian Lopez 2010-04-01 14:29:20 -07:00
parent bd25b31731
commit bbf7585d09
2 changed files with 8 additions and 3 deletions

View File

@ -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
}

View File

@ -7,7 +7,7 @@
#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
int utf8Encoding;
int utf8Encoding, binaryEncoding;
#endif
// VALUE cBigDecimal;