bugfix or escape method
This commit is contained in:
parent
799f9809d0
commit
2f380fd0ff
|
@ -18,8 +18,8 @@ Benchmark.bmbm do |x|
|
||||||
mysql.escape_string str
|
mysql.escape_string str
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
GC.start
|
|
||||||
mysql2 = Mysql2::Client.new
|
mysql2 = Mysql2::Client.new(:host => "localhost", :username => "root")
|
||||||
mysql2.query "USE #{database}"
|
mysql2.query "USE #{database}"
|
||||||
x.report do
|
x.report do
|
||||||
puts "Mysql2"
|
puts "Mysql2"
|
||||||
|
|
|
@ -113,19 +113,16 @@ static VALUE rb_mysql_client_query(VALUE self, VALUE sql) {
|
||||||
|
|
||||||
static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
|
static VALUE rb_mysql_client_escape(VALUE self, VALUE str) {
|
||||||
MYSQL * client;
|
MYSQL * client;
|
||||||
char * query;
|
|
||||||
unsigned long queryLen;
|
|
||||||
VALUE newStr;
|
VALUE newStr;
|
||||||
|
|
||||||
Check_Type(str, T_STRING);
|
Check_Type(str, T_STRING);
|
||||||
queryLen = RSTRING_LEN(str);
|
char escaped[(RSTRING_LEN(str)*2)+1];
|
||||||
query = RSTRING_PTR(str);
|
|
||||||
|
|
||||||
GetMysql2Client(self, client);
|
GetMysql2Client(self, client);
|
||||||
|
|
||||||
newStr = rb_str_new(query, mysql_real_escape_string(client, query + queryLen, query, queryLen));
|
newStr = rb_str_new(escaped, mysql_real_escape_string(client, escaped, RSTRING_PTR(str), RSTRING_LEN(str)));
|
||||||
#ifdef HAVE_RUBY_ENCODING_H
|
#ifdef HAVE_RUBY_ENCODING_H
|
||||||
rb_enc_associate_index(newStr, utf8Encoding);
|
rb_enc_associate_index(newStr, utf8Encoding);
|
||||||
#endif
|
#endif
|
||||||
return newStr;
|
return newStr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue