diff options
-rw-r--r-- | mysql-test/r/ctype_utf8.result | 9 | ||||
-rw-r--r-- | mysql-test/t/ctype_utf8.test | 12 | ||||
-rw-r--r-- | sql/item.cc | 20 | ||||
-rw-r--r-- | sql/item.h | 1 |
4 files changed, 42 insertions, 0 deletions
diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index bb3222ca98b..a98beb36ef1 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -993,6 +993,15 @@ select * from t1 where a like "%abc\d%"; a abcd 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 ( a varchar(255) NOT NULL default '', KEY a (a) diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index a09618df7c0..ede9665941a 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -832,6 +832,18 @@ 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 # CREATE TABLE t1 ( diff --git a/sql/item.cc b/sql/item.cc index 2ae56d17b07..53640c4e44a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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 { if (type() == item->type() && item->basic_const_item()) diff --git a/sql/item.h b/sql/item.h index 080b804c730..e683cda5786 100644 --- a/sql/item.h +++ b/sql/item.h @@ -618,6 +618,7 @@ public: basic_const_item returned TRUE. */ Item *new_item(); + Item *safe_charset_converter(CHARSET_INFO *tocs); /* Implement by-value equality evaluation if parameter value is set and is a basic constant (integer, real or string). |