From 63777287b8e07abefc74eae6b1fbf95255abd847 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 9 Jul 2010 09:39:41 +0400 Subject: [PATCH] Bug#54668 User variable assignments get wrong type Problem: Item_str_ascii_func::val_str() did not set charset of the returned value properly. mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result - Adding tests sql/item_strfunc.cc - Adding initialization of charset --- mysql-test/include/ctype_numconv.inc | 19 +++++++++++++++++ mysql-test/r/ctype_binary.result | 31 ++++++++++++++++++++++++++++ mysql-test/r/ctype_cp1251.result | 31 ++++++++++++++++++++++++++++ mysql-test/r/ctype_latin1.result | 31 ++++++++++++++++++++++++++++ mysql-test/r/ctype_ucs.result | 31 ++++++++++++++++++++++++++++ sql/item_strfunc.cc | 7 ++++++- 6 files changed, 149 insertions(+), 1 deletion(-) diff --git a/mysql-test/include/ctype_numconv.inc b/mysql-test/include/ctype_numconv.inc index d6bfa23017e..77913fc8c18 100644 --- a/mysql-test/include/ctype_numconv.inc +++ b/mysql-test/include/ctype_numconv.inc @@ -1606,6 +1606,25 @@ drop function f1; --echo # End of WL#2649 Number-to-string conversions --echo # +--echo # +--echo # Bug#54668 User variable assignments get wrong type +--echo # +SET @x=md5('a'); +SELECT charset(@x), collation(@x); +SET @x=old_password('a'); +SELECT charset(@x), collation(@x); +SET @x=password('a'); +SELECT charset(@x), collation(@x); +SET @x=sha('a'); +SELECT charset(@x), collation(@x); +SET @x=sha1('a'); +SELECT charset(@x), collation(@x); +SET @x=astext(point(1,2)); +SELECT charset(@x), collation(@x); +SET @x=aswkt(point(1,2)); +SELECT charset(@x), collation(@x); + + --echo # --echo # Bug#52159 returning time type from function and empty left join causes debug assertion --echo # diff --git a/mysql-test/r/ctype_binary.result b/mysql-test/r/ctype_binary.result index 4b93e6533d7..76a4d0f3cf3 100644 --- a/mysql-test/r/ctype_binary.result +++ b/mysql-test/r/ctype_binary.result @@ -2567,6 +2567,37 @@ drop function f1; # End of WL#2649 Number-to-string conversions # # +# Bug#54668 User variable assignments get wrong type +# +SET @x=md5('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=old_password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=sha('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=sha1('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=astext(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +SET @x=aswkt(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +binary binary +# # Bug#52159 returning time type from function and empty left join causes debug assertion # CREATE FUNCTION f1() RETURNS TIME RETURN 1; diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index 869a84a34c9..f93cb5f9a12 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -2649,6 +2649,37 @@ drop function f1; # End of WL#2649 Number-to-string conversions # # +# Bug#54668 User variable assignments get wrong type +# +SET @x=md5('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=old_password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=sha('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=sha1('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=astext(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +SET @x=aswkt(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +cp1251 cp1251_general_ci +# # Bug#52159 returning time type from function and empty left join causes debug assertion # CREATE FUNCTION f1() RETURNS TIME RETURN 1; diff --git a/mysql-test/r/ctype_latin1.result b/mysql-test/r/ctype_latin1.result index 8dbd09741ff..43ee365cd53 100644 --- a/mysql-test/r/ctype_latin1.result +++ b/mysql-test/r/ctype_latin1.result @@ -2977,6 +2977,37 @@ drop function f1; # End of WL#2649 Number-to-string conversions # # +# Bug#54668 User variable assignments get wrong type +# +SET @x=md5('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=old_password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=sha('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=sha1('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=astext(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +SET @x=aswkt(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +latin1 latin1_swedish_ci +# # Bug#52159 returning time type from function and empty left join causes debug assertion # CREATE FUNCTION f1() RETURNS TIME RETURN 1; diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 892e893db4d..7bb27e03acc 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -3809,6 +3809,37 @@ drop function f1; # End of WL#2649 Number-to-string conversions # # +# Bug#54668 User variable assignments get wrong type +# +SET @x=md5('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=old_password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=password('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=sha('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=sha1('a'); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=astext(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +SET @x=aswkt(point(1,2)); +SELECT charset(@x), collation(@x); +charset(@x) collation(@x) +ucs2 ucs2_general_ci +# # Bug#52159 returning time type from function and empty left join causes debug assertion # CREATE FUNCTION f1() RETURNS TIME RETURN 1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 2a9eef2298d..851d0e07a7e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -72,7 +72,12 @@ String *Item_str_ascii_func::val_str(String *str) DBUG_ASSERT(fixed == 1); if (!(collation.collation->state & MY_CS_NONASCII)) - return val_str_ascii(str); + { + String *res= val_str_ascii(str); + if (res) + res->set_charset(collation.collation); + return res; + } DBUG_ASSERT(str != &ascii_buf);