Commit 1d27b578 authored by Daniel Black's avatar Daniel Black

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
parent 810ef911
...@@ -46,7 +46,7 @@ create table t1 (version char(60)) select database(), user(), version() as 'vers ...@@ -46,7 +46,7 @@ create table t1 (version char(60)) select database(), user(), version() as 'vers
show create table t1; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`database()` varchar(34) CHARACTER SET utf8 DEFAULT NULL, `database()` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
`user()` varchar(141) CHARACTER SET utf8 DEFAULT NULL, `user()` varchar(141) CHARACTER SET utf8 DEFAULT NULL,
`version` char(60) DEFAULT NULL `version` char(60) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
...@@ -95,3 +95,21 @@ select left(concat(a,version()),1) from t1; ...@@ -95,3 +95,21 @@ select left(concat(a,version()),1) from t1;
left(concat(a,version()),1) left(concat(a,version()),1)
a a
drop table t1; drop table t1;
#
# Start of 10.2 tests
#
MDEV-27544 database() function under UNION ALL truncates results to 34 characters
SET NAMES utf8;
create database betäubungsmittelverschreibungsverordnung;
use betäubungsmittelverschreibungsverordnung;
select database() as "database" union all select database();
database
betäubungsmittelverschreibungsverordnung
betäubungsmittelverschreibungsverordnung
drop database betäubungsmittelverschreibungsverordnung;
#
# End of 10.2 tests
#
...@@ -55,3 +55,23 @@ select left(concat(a,version()),1) from t1; ...@@ -55,3 +55,23 @@ select left(concat(a,version()),1) from t1;
drop table t1; drop table t1;
# End of 4.1 tests # End of 4.1 tests
--echo #
--echo # Start of 10.2 tests
--echo #
--echo
--echo MDEV-27544 database() function under UNION ALL truncates results to 34 characters
--echo
--echo
SET NAMES utf8;
create database betäubungsmittelverschreibungsverordnung;
use betäubungsmittelverschreibungsverordnung;
select database() as "database" union all select database();
drop database betäubungsmittelverschreibungsverordnung;
--echo #
--echo # End of 10.2 tests
--echo #
...@@ -717,7 +717,7 @@ class Item_func_database :public Item_func_sysconst ...@@ -717,7 +717,7 @@ class Item_func_database :public Item_func_sysconst
String *val_str(String *); String *val_str(String *);
bool fix_length_and_dec() bool fix_length_and_dec()
{ {
max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; max_length= NAME_CHAR_LEN * system_charset_info->mbmaxlen;
maybe_null=1; maybe_null=1;
return FALSE; return FALSE;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment