force string encoding to utf8 in 1.9

This commit is contained in:
Brian Lopez 2010-04-01 12:56:49 -07:00
parent d1466a10f1
commit 858523d7a9
2 changed files with 17 additions and 1 deletions

View File

@ -65,6 +65,7 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
MYSQL * client; MYSQL * client;
char * query; char * query;
unsigned long queryLen; unsigned long queryLen;
VALUE newStr;
Check_Type(str, T_STRING); Check_Type(str, T_STRING);
queryLen = RSTRING_LEN(str); queryLen = RSTRING_LEN(str);
@ -72,7 +73,11 @@ static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
GetMysql2Client(self, client); GetMysql2Client(self, client);
return rb_str_new(query, mysql_real_escape_string(client, query + queryLen, query, queryLen)); 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);
#endif
return newStr;
} }
/* Mysql2::Result */ /* Mysql2::Result */
@ -126,6 +131,9 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
key = ID2SYM(rb_intern(buf)); key = ID2SYM(rb_intern(buf));
} else { } else {
key = rb_str_new(fields[i].name, fields[i].name_length); key = rb_str_new(fields[i].name, fields[i].name_length);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(key, utf8Encoding);
#endif
} }
if (row[i]) { if (row[i]) {
VALUE val; VALUE val;
@ -182,6 +190,9 @@ static VALUE rb_mysql_result_fetch_row(int argc, VALUE * argv, VALUE self) {
case MYSQL_TYPE_GEOMETRY: // Spatial fielda case MYSQL_TYPE_GEOMETRY: // Spatial fielda
default: default:
val = rb_str_new(row[i], fieldLengths[i]); val = rb_str_new(row[i], fieldLengths[i]);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(val, utf8Encoding);
#endif
break; break;
} }
rb_hash_aset(rowHash, key, val); rb_hash_aset(rowHash, key, val);

View File

@ -5,6 +5,11 @@
#include <mysql/errmsg.h> #include <mysql/errmsg.h>
#include <mysql/mysqld_error.h> #include <mysql/mysqld_error.h>
#ifdef HAVE_RUBY_ENCODING_H
#include <ruby/encoding.h>
int utf8Encoding;
#endif
// VALUE cBigDecimal; // VALUE cBigDecimal;
// ID intern_new; // ID intern_new;