Commit c3460299 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-15702 Remove the use of STRING_ITEM from Item_func_date_format::fix_length_and_dec()

Implementing the task according to the description.
Additionally, implementing Item_func_date_format::check_arguments().
parent 068450a3
......@@ -3402,3 +3402,61 @@ CAST(LAST_DAY(TIME'00:00:00') AS TIME) AS c3;
c1 c2 c3
2018-02-28 00:00:00 00:00:00
SET TIMESTAMP=DEFAULT;
#
# MDEV-15702 Remove the use of STRING_ITEM from Item_func_date_format::fix_length_and_dec()
#
SELECT DATE_FORMAT('2001-01-01',POINT(1,1));
ERROR HY000: Illegal parameter data type geometry for operation 'date_format'
SELECT DATE_FORMAT(POINT(1,1),'10');
ERROR HY000: Illegal parameter data type geometry for operation 'date_format'
SELECT DATE_FORMAT('2001-01-01',ROW(1,1));
ERROR HY000: Illegal parameter data type row for operation 'date_format'
SELECT DATE_FORMAT(ROW(1,1),'10');
ERROR HY000: Illegal parameter data type row for operation 'date_format'
SELECT DATE_FORMAT('2001-01-01','%Y',POINT(1,1));
ERROR HY000: Illegal parameter data type geometry for operation 'date_format'
SELECT DATE_FORMAT('2001-01-01','%Y',ROW(1,1));
ERROR HY000: Illegal parameter data type row for operation 'date_format'
SELECT DATE_FORMAT('2001-01-01','%Y',@unknown_user_variable);
DATE_FORMAT('2001-01-01','%Y',@unknown_user_variable)
2001
Warnings:
Warning 1649 Unknown locale: 'NULL'
CREATE TABLE t1 AS SELECT
DATE_FORMAT('2001-01-01',NULL) AS c0,
DATE_FORMAT('2001-01-01','10') AS c1,
DATE_FORMAT('2001-01-01',10) AS c2,
DATE_FORMAT('2001-01-01',10.0) AS c3,
DATE_FORMAT('2001-01-01',10e0) AS c4,
DATE_FORMAT('2001-01-01',TIME'10:20:30') AS c5;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c0` char(0) DEFAULT NULL,
`c1` varchar(2) DEFAULT NULL,
`c2` varchar(2) DEFAULT NULL,
`c3` varchar(4) DEFAULT NULL,
`c4` varchar(2) DEFAULT NULL,
`c5` varchar(8) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
EXECUTE IMMEDIATE
"CREATE TABLE t1 AS SELECT
DATE_FORMAT('2001-01-01',?) AS c0,
DATE_FORMAT('2001-01-01',?) AS c1,
DATE_FORMAT('2001-01-01',?) AS c2,
DATE_FORMAT('2001-01-01',?) AS c3,
DATE_FORMAT('2001-01-01',?) AS c4,
DATE_FORMAT('2001-01-01',?) AS c5"
USING NULL, '10', 10, 10.0, 10e0, TIME'10:20:30';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c0` char(0) DEFAULT NULL,
`c1` varchar(2) DEFAULT NULL,
`c2` varchar(2) DEFAULT NULL,
`c3` varchar(4) DEFAULT NULL,
`c4` varchar(2) DEFAULT NULL,
`c5` varchar(100) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
......@@ -1998,3 +1998,46 @@ SELECT
CAST(CAST(LAST_DAY(TIME'00:00:00') AS DATE) AS TIME) AS c2,
CAST(LAST_DAY(TIME'00:00:00') AS TIME) AS c3;
SET TIMESTAMP=DEFAULT;
--echo #
--echo # MDEV-15702 Remove the use of STRING_ITEM from Item_func_date_format::fix_length_and_dec()
--echo #
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT('2001-01-01',POINT(1,1));
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT(POINT(1,1),'10');
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT('2001-01-01',ROW(1,1));
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT(ROW(1,1),'10');
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT('2001-01-01','%Y',POINT(1,1));
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT DATE_FORMAT('2001-01-01','%Y',ROW(1,1));
SELECT DATE_FORMAT('2001-01-01','%Y',@unknown_user_variable);
CREATE TABLE t1 AS SELECT
DATE_FORMAT('2001-01-01',NULL) AS c0,
DATE_FORMAT('2001-01-01','10') AS c1,
DATE_FORMAT('2001-01-01',10) AS c2,
DATE_FORMAT('2001-01-01',10.0) AS c3,
DATE_FORMAT('2001-01-01',10e0) AS c4,
DATE_FORMAT('2001-01-01',TIME'10:20:30') AS c5;
SHOW CREATE TABLE t1;
DROP TABLE t1;
EXECUTE IMMEDIATE
"CREATE TABLE t1 AS SELECT
DATE_FORMAT('2001-01-01',?) AS c0,
DATE_FORMAT('2001-01-01',?) AS c1,
DATE_FORMAT('2001-01-01',?) AS c2,
DATE_FORMAT('2001-01-01',?) AS c3,
DATE_FORMAT('2001-01-01',?) AS c4,
DATE_FORMAT('2001-01-01',?) AS c5"
USING NULL, '10', 10, 10.0, 10e0, TIME'10:20:30';
SHOW CREATE TABLE t1;
DROP TABLE t1;
......@@ -1859,11 +1859,12 @@ void Item_func_date_format::fix_length_and_dec()
if (!thd->variables.lc_time_names->is_ascii)
repertoire|= MY_REPERTOIRE_EXTENDED;
collation.set(cs, arg1->collation.derivation, repertoire);
if (arg1->type() == STRING_ITEM)
StringBuffer<STRING_BUFFER_USUAL_SIZE> buffer;
String *str;
if (args[1]->basic_const_item() && (str= args[1]->val_str(&buffer)))
{ // Optimize the normal case
fixed_length=1;
max_length= format_length(arg1->val_str(NULL)) *
collation.collation->mbmaxlen;
max_length= format_length(str) * collation.collation->mbmaxlen;
}
else
{
......
......@@ -847,6 +847,11 @@ class Item_func_from_days :public Item_datefunc
class Item_func_date_format :public Item_str_func
{
bool check_arguments() const
{
return args[0]->check_type_can_return_date(func_name()) ||
check_argument_types_can_return_text(1, arg_count);
}
const MY_LOCALE *locale;
int fixed_length;
String value;
......
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