summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2022-01-20 09:10:44 +1100
committerDaniel Black <daniel@mariadb.org>2022-01-20 19:01:36 +1100
commit1d27b5789aaa353175f5331d3a8b104b22dd1fce (patch)
treec44151e98eaef2977eca876d9462dd5559ebcb9b
parent810ef9117a54f8dfbd362d959d46a2322f86a9d0 (diff)
downloadmariadb-git-1d27b5789aaa353175f5331d3a8b104b22dd1fce.tar.gz
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
-rw-r--r--mysql-test/r/func_system.result20
-rw-r--r--mysql-test/t/func_system.test20
-rw-r--r--sql/item_strfunc.h2
3 files changed, 40 insertions, 2 deletions
diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result
index 06fb7e44cf0..688f4a30b50 100644
--- a/mysql-test/r/func_system.result
+++ b/mysql-test/r/func_system.result
@@ -46,7 +46,7 @@ create table t1 (version char(60)) select database(), user(), version() as 'vers
show create table t1;
Table Create Table
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,
`version` char(60) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
@@ -95,3 +95,21 @@ select left(concat(a,version()),1) from t1;
left(concat(a,version()),1)
a
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
+#
diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test
index fa09e81a300..d9f2bda750a 100644
--- a/mysql-test/t/func_system.test
+++ b/mysql-test/t/func_system.test
@@ -55,3 +55,23 @@ select left(concat(a,version()),1) from t1;
drop table t1;
# 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 #
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 0bf21b63ac9..30464ddadb3 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -717,7 +717,7 @@ public:
String *val_str(String *);
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;
return FALSE;
}