diff options
-rw-r--r-- | mysql-test/r/func_str.result | 6 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 6 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 2 |
3 files changed, 14 insertions, 0 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 71a1a7539b0..85a0c2c55f9 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -742,3 +742,9 @@ WHERE a = CONV('e251273eb74a8ee3', 16, 10); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 DROP TABLE t1; +SELECT CHAR(NULL,121,83,81,'76') as my_column; +my_column +ySQL +SELECT CHAR_LENGTH(CHAR(NULL,121,83,81,'76')) as my_column; +my_column +4 diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index ffbcc1d774b..a69febef340 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -479,3 +479,9 @@ EXPLAIN WHERE a = CONV('e251273eb74a8ee3', 16, 10); DROP TABLE t1; + +# +# Bug #6317: string function CHAR, parameter is NULL, wrong result +# +SELECT CHAR(NULL,121,83,81,'76') as my_column; +SELECT CHAR_LENGTH(CHAR(NULL,121,83,81,'76')) as my_column; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9f2da0f7fa1..536ee46f4db 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1874,6 +1874,7 @@ String *Item_func_char::val_str(String *str) { int32 num=(int32) args[i]->val_int(); if (!args[i]->null_value) + { #ifdef USE_MB if (use_mb(collation.collation)) { @@ -1889,6 +1890,7 @@ b1: str->append((char)(num>>8)); } #endif str->append((char)num); + } } str->set_charset(collation.collation); str->realloc(str->length()); // Add end 0 (for Purify) |