Commit 858171cb authored by bar@mysql.com's avatar bar@mysql.com

item_timefunc.cc:

  CAST now always return a well-formed character string.
parent b7824315
...@@ -2115,7 +2115,6 @@ String *Item_char_typecast::val_str(String *str) ...@@ -2115,7 +2115,6 @@ String *Item_char_typecast::val_str(String *str)
String *res; String *res;
uint32 length; uint32 length;
#if 0
if (!charset_conversion) if (!charset_conversion)
{ {
if (!(res= args[0]->val_str(str))) if (!(res= args[0]->val_str(str)))
...@@ -2125,7 +2124,6 @@ String *Item_char_typecast::val_str(String *str) ...@@ -2125,7 +2124,6 @@ String *Item_char_typecast::val_str(String *str)
} }
} }
else else
#endif
{ {
// Convert character set if differ // Convert character set if differ
uint dummy_errors; uint dummy_errors;
...@@ -2163,9 +2161,18 @@ String *Item_char_typecast::val_str(String *str) ...@@ -2163,9 +2161,18 @@ String *Item_char_typecast::val_str(String *str)
void Item_char_typecast::fix_length_and_dec() void Item_char_typecast::fix_length_and_dec()
{ {
uint32 char_length; uint32 char_length;
charset_conversion= !my_charset_same(args[0]->collation.collation, cast_cs) && /*
args[0]->collation.collation != &my_charset_bin && We always force character set conversion if cast_cs
cast_cs != &my_charset_bin; is a multi-byte character set. It garantees that the
result of CAST is a well-formed string.
For single-byte character sets we allow just to copy
from the argument. A single-byte character sets string
is always well-formed.
*/
charset_conversion= (cast_cs->mbmaxlen > 1) ||
!my_charset_same(args[0]->collation.collation, cast_cs) &&
args[0]->collation.collation != &my_charset_bin &&
cast_cs != &my_charset_bin;
collation.set(cast_cs, DERIVATION_IMPLICIT); collation.set(cast_cs, DERIVATION_IMPLICIT);
char_length= (cast_length >= 0) ? cast_length : char_length= (cast_length >= 0) ? cast_length :
args[0]->max_length/args[0]->collation.collation->mbmaxlen; args[0]->max_length/args[0]->collation.collation->mbmaxlen;
......
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