Skip to content

Commit f81700a

Browse files
author
Alexander Barkov
committed
Bug#48766 SHOW CREATE FUNCTION returns extra data in return clause
Problem: SHOW CREATE FUNCTION and SELECT DTD_IDENTIFIER FROM I_S.ROUTINES returned wrong values in case of ENUM return data type and UCS2 character set. Fix: the string to collect returned data type was incorrectly set to "binary" character set, therefore UCS2 values where returned with extra '\0' characters. Setting string character set to creation_ctx->get_client_cs() in sp_find_routine(), and to system_charset_info in sp_create_routine fixes the problem. Adding tests: - the original test with Latin letters - an extra test with non-Latin letters
1 parent f327aa6 commit f81700a

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

mysql-test/r/sp-ucs2.result

+26
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,29 @@ a
1212
foo string
1313
drop function bug17615|
1414
drop table t3|
15+
SET NAMES utf8;
16+
DROP FUNCTION IF EXISTS bug48766;
17+
CREATE FUNCTION bug48766 ()
18+
RETURNS ENUM( 'w' ) CHARACTER SET ucs2
19+
RETURN 0;
20+
SHOW CREATE FUNCTION bug48766;
21+
Function sql_mode Create Function character_set_client collation_connection Database Collation
22+
bug48766 CREATE DEFINER=`root`@`localhost` FUNCTION `bug48766`() RETURNS enum('w') CHARSET ucs2
23+
RETURN 0 utf8 utf8_general_ci latin1_swedish_ci
24+
SELECT DTD_IDENTIFIER FROM INFORMATION_SCHEMA.ROUTINES
25+
WHERE ROUTINE_NAME='bug48766';
26+
DTD_IDENTIFIER
27+
enum('w') CHARSET ucs2
28+
DROP FUNCTION bug48766;
29+
CREATE FUNCTION bug48766 ()
30+
RETURNS ENUM('а','б','в','г') CHARACTER SET ucs2
31+
RETURN 0;
32+
SHOW CREATE FUNCTION bug48766;
33+
Function sql_mode Create Function character_set_client collation_connection Database Collation
34+
bug48766 CREATE DEFINER=`root`@`localhost` FUNCTION `bug48766`() RETURNS enum('а','б','в','г') CHARSET ucs2
35+
RETURN 0 utf8 utf8_general_ci latin1_swedish_ci
36+
SELECT DTD_IDENTIFIER FROM INFORMATION_SCHEMA.ROUTINES
37+
WHERE ROUTINE_NAME='bug48766';
38+
DTD_IDENTIFIER
39+
enum('а','б','в','г') CHARSET ucs2
40+
DROP FUNCTION bug48766;

mysql-test/t/sp-ucs2.test

+29
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,32 @@ drop table t3|
2626

2727

2828
delimiter ;|
29+
30+
#
31+
# Bug#48766 SHOW CREATE FUNCTION returns extra data in return clause
32+
#
33+
SET NAMES utf8;
34+
--disable_warnings
35+
DROP FUNCTION IF EXISTS bug48766;
36+
--enable_warnings
37+
#
38+
# Test that Latin letters are not prepended with extra '\0'.
39+
#
40+
CREATE FUNCTION bug48766 ()
41+
RETURNS ENUM( 'w' ) CHARACTER SET ucs2
42+
RETURN 0;
43+
SHOW CREATE FUNCTION bug48766;
44+
SELECT DTD_IDENTIFIER FROM INFORMATION_SCHEMA.ROUTINES
45+
WHERE ROUTINE_NAME='bug48766';
46+
DROP FUNCTION bug48766;
47+
#
48+
# Test non-Latin characters
49+
#
50+
CREATE FUNCTION bug48766 ()
51+
RETURNS ENUM('а','б','в','г') CHARACTER SET ucs2
52+
RETURN 0;
53+
SHOW CREATE FUNCTION bug48766;
54+
SELECT DTD_IDENTIFIER FROM INFORMATION_SCHEMA.ROUTINES
55+
WHERE ROUTINE_NAME='bug48766';
56+
57+
DROP FUNCTION bug48766;

sql/sp.cc

+2
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ sp_create_routine(THD *thd, int type, sp_head *sp)
900900
DBUG_PRINT("enter", ("type: %d name: %.*s",type, (int) sp->m_name.length,
901901
sp->m_name.str));
902902
String retstr(64);
903+
retstr.set_charset(system_charset_info);
903904

904905
DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
905906
type == TYPE_ENUM_FUNCTION);
@@ -1403,6 +1404,7 @@ sp_find_routine(THD *thd, int type, sp_name *name, sp_cache **cp,
14031404
64 -- size of "returns" column of mysql.proc.
14041405
*/
14051406
String retstr(64);
1407+
retstr.set_charset(sp->get_creation_ctx()->get_client_cs());
14061408

14071409
DBUG_PRINT("info", ("found: 0x%lx", (ulong)sp));
14081410
if (sp->m_first_free_instance)

0 commit comments

Comments
 (0)