Commit cdce6061 authored by Alexander Barkov's avatar Alexander Barkov

Bug#45263 utf32_general_ci, bad effects around CREATE TABLE AS SELECT

Problem: Item_func_hex::val_str() returned data in ASCII format,
which did not match collation.collation pointing to my_charset_utf32_general_ci.
Fix: changing parent class of Item_func_hex to Item_str_ascii_func,
as val_str() implementation is heavily ASCII-oriented.

  mysql-test/r/ctype_utf32.result
  mysql-test/t/ctype_utf32.test
  Adding test case


  sql/item_strfunc.cc
  sql/item_strfunc.h
  - Changing parent class to Item_str_ascii_func
  - Clean-up in Item_func_hex::fix_length_and_dec()
    Using fix_char_length() instead of setting max_length directly.
parent d3b7cd3f
...@@ -1091,5 +1091,14 @@ t2 CREATE TABLE `t2` ( ...@@ -1091,5 +1091,14 @@ t2 CREATE TABLE `t2` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1, t2; DROP TABLE t1, t2;
# #
# Bug#45263 utf32_general_ci, bad effects around CREATE TABLE AS SELECT
#
SET collation_connection=utf32_general_ci;
CREATE TABLE t1 AS SELECT HEX(0x00) AS my_col;
SELECT * FROM t1;
my_col
00
DROP TABLE t1;
#
# End of 5.5 tests # End of 5.5 tests
# #
...@@ -800,6 +800,15 @@ CREATE TABLE t2 AS SELECT CONCAT(s1) FROM t1; ...@@ -800,6 +800,15 @@ CREATE TABLE t2 AS SELECT CONCAT(s1) FROM t1;
SHOW CREATE TABLE t2; SHOW CREATE TABLE t2;
DROP TABLE t1, t2; DROP TABLE t1, t2;
--echo #
--echo # Bug#45263 utf32_general_ci, bad effects around CREATE TABLE AS SELECT
--echo #
SET collation_connection=utf32_general_ci;
CREATE TABLE t1 AS SELECT HEX(0x00) AS my_col;
SELECT * FROM t1;
DROP TABLE t1;
--echo # --echo #
--echo # End of 5.5 tests --echo # End of 5.5 tests
--echo # --echo #
...@@ -3081,7 +3081,7 @@ String *Item_func_collation::val_str(String *str) ...@@ -3081,7 +3081,7 @@ String *Item_func_collation::val_str(String *str)
} }
String *Item_func_hex::val_str(String *str) String *Item_func_hex::val_str_ascii(String *str)
{ {
String *res; String *res;
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
...@@ -3120,6 +3120,7 @@ String *Item_func_hex::val_str(String *str) ...@@ -3120,6 +3120,7 @@ String *Item_func_hex::val_str(String *str)
} }
null_value=0; null_value=0;
tmp_value.length(res->length()*2); tmp_value.length(res->length()*2);
tmp_value.set_charset(&my_charset_latin1);
octet2hex((char*) tmp_value.ptr(), res->ptr(), res->length()); octet2hex((char*) tmp_value.ptr(), res->ptr(), res->length());
return &tmp_value; return &tmp_value;
......
...@@ -622,18 +622,18 @@ public: ...@@ -622,18 +622,18 @@ public:
}; };
class Item_func_hex :public Item_str_func class Item_func_hex :public Item_str_ascii_func
{ {
String tmp_value; String tmp_value;
public: public:
Item_func_hex(Item *a) :Item_str_func(a) {} Item_func_hex(Item *a) :Item_str_ascii_func(a) {}
const char *func_name() const { return "hex"; } const char *func_name() const { return "hex"; }
String *val_str(String *); String *val_str_ascii(String *);
void fix_length_and_dec() void fix_length_and_dec()
{ {
collation.set(default_charset()); collation.set(default_charset());
decimals=0; decimals=0;
max_length=args[0]->max_length*2*collation.collation->mbmaxlen; fix_char_length(args[0]->max_length * 2);
} }
}; };
......
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