Skip to content

Commit 1d27b57

Browse files
committed
MDEV-27544 database() function should return 64 characters
Database names are 64 utf8 characters per the system tables that refer to them. The current database() function is returning 34 characters. The result of limiting this function results to max length of 34 became apparent when used in a UNION ALL where the results are truncated to 34 characters. For (uninvestigated) reasons, SELECT DATABASE() on its own would always return the right number of characters. Thanks Alexander Barkov for the review. Thanks dave for noticing the bug in the stackexchange post https://dba.stackexchange.com/questions/306183/why-is-my-database-name-truncated
1 parent 810ef91 commit 1d27b57

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

mysql-test/r/func_system.result

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ create table t1 (version char(60)) select database(), user(), version() as 'vers
4646
show create table t1;
4747
Table Create Table
4848
t1 CREATE TABLE `t1` (
49-
`database()` varchar(34) CHARACTER SET utf8 DEFAULT NULL,
49+
`database()` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
5050
`user()` varchar(141) CHARACTER SET utf8 DEFAULT NULL,
5151
`version` char(60) DEFAULT NULL
5252
) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -95,3 +95,21 @@ select left(concat(a,version()),1) from t1;
9595
left(concat(a,version()),1)
9696
a
9797
drop table t1;
98+
#
99+
# Start of 10.2 tests
100+
#
101+
102+
MDEV-27544 database() function under UNION ALL truncates results to 34 characters
103+
104+
105+
SET NAMES utf8;
106+
create database betäubungsmittelverschreibungsverordnung;
107+
use betäubungsmittelverschreibungsverordnung;
108+
select database() as "database" union all select database();
109+
database
110+
betäubungsmittelverschreibungsverordnung
111+
betäubungsmittelverschreibungsverordnung
112+
drop database betäubungsmittelverschreibungsverordnung;
113+
#
114+
# End of 10.2 tests
115+
#

mysql-test/t/func_system.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,23 @@ select left(concat(a,version()),1) from t1;
5555
drop table t1;
5656

5757
# End of 4.1 tests
58+
59+
--echo #
60+
--echo # Start of 10.2 tests
61+
--echo #
62+
63+
--echo
64+
--echo MDEV-27544 database() function under UNION ALL truncates results to 34 characters
65+
--echo
66+
--echo
67+
68+
SET NAMES utf8;
69+
create database betäubungsmittelverschreibungsverordnung;
70+
use betäubungsmittelverschreibungsverordnung;
71+
select database() as "database" union all select database();
72+
drop database betäubungsmittelverschreibungsverordnung;
73+
74+
75+
--echo #
76+
--echo # End of 10.2 tests
77+
--echo #

sql/item_strfunc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ class Item_func_database :public Item_func_sysconst
717717
String *val_str(String *);
718718
bool fix_length_and_dec()
719719
{
720-
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen;
720+
max_length= NAME_CHAR_LEN * system_charset_info->mbmaxlen;
721721
maybe_null=1;
722722
return FALSE;
723723
}

0 commit comments

Comments
 (0)