summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.cc
diff options
context:
space:
mode:
authorRamil Kalimullin <ramil@mysql.com>2008-11-21 13:48:22 +0400
committerRamil Kalimullin <ramil@mysql.com>2008-11-21 13:48:22 +0400
commit39efef853ba172b07c3df3869e98d4b894192acc (patch)
treedf9c9ef1a4432ab2287adebbffb8d15e7ddc9f80 /sql/item_timefunc.cc
parent1cd8b9f700a3d20e0af43896b366cef6ef0e7d4c (diff)
downloadmariadb-git-39efef853ba172b07c3df3869e98d4b894192acc.tar.gz
Fix for bug#36772: When using UTF8, CONVERT with GROUP BY
returns truncated results Problem: performig conversion from {INT, DECIMAL, REAL} to CHAR we incorrectly set its max length in some cases that may lead to truncated results returned. Fix: properly set CONVERT({INT, DECIMAL, REAL}, CHAR) result's max length. mysql-test/r/ctype_utf8.result: Fix for bug#36772: When using UTF8, CONVERT with GROUP BY returns truncated results - test result. mysql-test/t/ctype_utf8.test: Fix for bug#36772: When using UTF8, CONVERT with GROUP BY returns truncated results - test case. sql/item_timefunc.cc: Fix for bug#36772: When using UTF8, CONVERT with GROUP BY returns truncated results - calculating Item_char_typecast::max_length use initial argument's charset mbmaxlen instead of from_cs->mbmaxlen, as from_cs may differ in some case (see comment above).
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r--sql/item_timefunc.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 0cb3c963dad..e9e92952908 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2550,6 +2550,8 @@ void Item_char_typecast::fix_length_and_dec()
and thus avoid unnecessary character set conversion.
- If the argument is not a number, then from_cs is set to
the argument's charset.
+
+ Note (TODO): we could use repertoire technique here.
*/
from_cs= (args[0]->result_type() == INT_RESULT ||
args[0]->result_type() == DECIMAL_RESULT ||
@@ -2557,12 +2559,13 @@ void Item_char_typecast::fix_length_and_dec()
(cast_cs->mbminlen == 1 ? cast_cs : &my_charset_latin1) :
args[0]->collation.collation;
charset_conversion= (cast_cs->mbmaxlen > 1) ||
- !my_charset_same(from_cs, cast_cs) &&
- from_cs != &my_charset_bin &&
- cast_cs != &my_charset_bin;
+ (!my_charset_same(from_cs, cast_cs) &&
+ from_cs != &my_charset_bin &&
+ cast_cs != &my_charset_bin);
collation.set(cast_cs, DERIVATION_IMPLICIT);
- char_length= (cast_length >= 0) ? cast_length :
- args[0]->max_length/from_cs->mbmaxlen;
+ char_length= (cast_length >= 0) ?
+ cast_length :
+ args[0]->max_length / args[0]->collation.collation->mbmaxlen;
max_length= char_length * cast_cs->mbmaxlen;
}