Commit 8d5bfbfa authored by bar@mysql.com's avatar bar@mysql.com

Bug#12371 executing prepared statement fails (illegal mix of collations)

item.cc:
item.h:
  Adding Item_param::safe_charset_converter,
  not to return collation mix error if
  parameter can be converted into operation
  character set.

ctype_utf8.result:
  adding test case
ctype_utf8.test:
  adding test case
parent de158e94
...@@ -993,6 +993,15 @@ select * from t1 where a like "%abc\d%"; ...@@ -993,6 +993,15 @@ select * from t1 where a like "%abc\d%";
a a
abcd abcd
drop table t1; drop table t1;
set names utf8;
create table t1 (a char(3), b varchar(10));
insert into t1 values ('bar','kostja');
prepare my_stmt from "select * from t1 where a=?";
set @a:='bar';
execute my_stmt using @a;
a b
bar kostja
drop table t1;
CREATE TABLE t1 ( CREATE TABLE t1 (
a varchar(255) NOT NULL default '', a varchar(255) NOT NULL default '',
KEY a (a) KEY a (a)
......
...@@ -831,6 +831,18 @@ select * from t1 where a like "%abc\d%"; ...@@ -831,6 +831,18 @@ select * from t1 where a like "%abc\d%";
drop table t1; drop table t1;
#
# Bug #12371 executing prepared statement fails (illegal mix of collations)
#
set names utf8;
create table t1 (a char(3), b varchar(10));
insert into t1 values ('bar','kostja');
prepare my_stmt from "select * from t1 where a=?";
set @a:='bar';
execute my_stmt using @a;
drop table t1;
# #
# Bug#9557 MyISAM utf8 table crash # Bug#9557 MyISAM utf8 table crash
# #
......
...@@ -284,6 +284,26 @@ Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs) ...@@ -284,6 +284,26 @@ Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
} }
Item *Item_param::safe_charset_converter(CHARSET_INFO *tocs)
{
if (const_item())
{
Item_string *conv;
uint conv_errors;
String tmp, cstr, *ostr= val_str(&tmp);
cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
if (conv_errors || !(conv= new Item_string(cstr.ptr(), cstr.length(),
cstr.charset(),
collation.derivation)))
return NULL;
conv->str_value.copy();
conv->str_value.shrink_to_length();
return conv;
}
return NULL;
}
bool Item_string::eq(const Item *item, bool binary_cmp) const bool Item_string::eq(const Item *item, bool binary_cmp) const
{ {
if (type() == item->type() && item->basic_const_item()) if (type() == item->type() && item->basic_const_item())
......
...@@ -617,6 +617,7 @@ public: ...@@ -617,6 +617,7 @@ public:
basic_const_item returned TRUE. basic_const_item returned TRUE.
*/ */
Item *new_item(); Item *new_item();
Item *safe_charset_converter(CHARSET_INFO *tocs);
/* /*
Implement by-value equality evaluation if parameter value Implement by-value equality evaluation if parameter value
is set and is a basic constant (integer, real or string). is set and is a basic constant (integer, real or string).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment