mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
bugfix: TIME_FORMAT() allowed some non-time format specifiers
it contradicted the manual and was inconsistent
This commit is contained in:
@ -558,3 +558,18 @@ SET NAMES latin1;
|
||||
#
|
||||
# End of 5.1 tests
|
||||
#
|
||||
select time_format('2001-01-01 02:02:02', '%d.%m.%Y');
|
||||
time_format('2001-01-01 02:02:02', '%d.%m.%Y')
|
||||
NULL
|
||||
select time_format('2001-01-01 02:02:02', '%d %T');
|
||||
time_format('2001-01-01 02:02:02', '%d %T')
|
||||
NULL
|
||||
select time_format('01 02:02:02', '%d %T');
|
||||
time_format('01 02:02:02', '%d %T')
|
||||
NULL
|
||||
select time_format('01 02:02:02', '%T');
|
||||
time_format('01 02:02:02', '%T')
|
||||
26:02:02
|
||||
select time_format('2001-01-01 02:02:02', '%T');
|
||||
time_format('2001-01-01 02:02:02', '%T')
|
||||
02:02:02
|
||||
|
@ -2911,16 +2911,16 @@ drop table t1;
|
||||
set sql_warnings = 0;
|
||||
# TIME_FORMAT()
|
||||
set sql_warnings = 1;
|
||||
create table t1 (a datetime, b varchar(10) as (time_format(a,"%d.%m.%Y")));
|
||||
create table t1 (a datetime, b varchar(10) as (time_format(a,"%H.%i.%S")));
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` datetime DEFAULT NULL,
|
||||
`b` varchar(10) GENERATED ALWAYS AS (time_format(`a`,'%d.%m.%Y')) VIRTUAL
|
||||
`b` varchar(10) GENERATED ALWAYS AS (time_format(`a`,'%H.%i.%S')) VIRTUAL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
insert into t1 values ('2001-01-01 02:02:02',default);
|
||||
insert into t1 values ('2001-01-01 02:03:04',default);
|
||||
select * from t1;
|
||||
a b
|
||||
2001-01-01 02:02:02 01.01.2001
|
||||
2001-01-01 02:03:04 02.03.04
|
||||
drop table t1;
|
||||
set sql_warnings = 0;
|
||||
|
@ -1204,8 +1204,8 @@ let $rows = 1;
|
||||
--source suite/vcol/inc/vcol_supported_sql_funcs.inc
|
||||
|
||||
--echo # TIME_FORMAT()
|
||||
let $cols = a datetime, b varchar(10) as (time_format(a,"%d.%m.%Y"));
|
||||
let $values1 = '2001-01-01 02:02:02',default;
|
||||
let $cols = a datetime, b varchar(10) as (time_format(a,"%H.%i.%S"));
|
||||
let $values1 = '2001-01-01 02:03:04',default;
|
||||
let $rows = 1;
|
||||
--source suite/vcol/inc/vcol_supported_sql_funcs.inc
|
||||
|
||||
|
@ -366,3 +366,12 @@ SET NAMES latin1;
|
||||
--echo #
|
||||
--echo # End of 5.1 tests
|
||||
--echo #
|
||||
|
||||
#
|
||||
# TIME_FORMAT and non-time format specifiers
|
||||
#
|
||||
select time_format('2001-01-01 02:02:02', '%d.%m.%Y');
|
||||
select time_format('2001-01-01 02:02:02', '%d %T');
|
||||
select time_format('01 02:02:02', '%d %T');
|
||||
select time_format('01 02:02:02', '%T');
|
||||
select time_format('2001-01-01 02:02:02', '%T');
|
||||
|
@ -477,14 +477,14 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
|
||||
{
|
||||
switch (*++ptr) {
|
||||
case 'M':
|
||||
if (!l_time->month)
|
||||
if (type == MYSQL_TIMESTAMP_TIME || !l_time->month)
|
||||
return 1;
|
||||
str->append(locale->month_names->type_names[l_time->month-1],
|
||||
(uint) strlen(locale->month_names->type_names[l_time->month-1]),
|
||||
system_charset_info);
|
||||
break;
|
||||
case 'b':
|
||||
if (!l_time->month)
|
||||
if (type == MYSQL_TIMESTAMP_TIME || !l_time->month)
|
||||
return 1;
|
||||
str->append(locale->ab_month_names->type_names[l_time->month-1],
|
||||
(uint) strlen(locale->ab_month_names->type_names[l_time->month-1]),
|
||||
@ -534,26 +534,38 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
|
||||
}
|
||||
break;
|
||||
case 'Y':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->year, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 4, '0');
|
||||
break;
|
||||
case 'y':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->year%100, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 2, '0');
|
||||
break;
|
||||
case 'm':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 2, '0');
|
||||
break;
|
||||
case 'c':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 1, '0');
|
||||
break;
|
||||
case 'd':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 2, '0');
|
||||
break;
|
||||
case 'e':
|
||||
if (type == MYSQL_TIMESTAMP_TIME)
|
||||
return 1;
|
||||
length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff);
|
||||
str->append_with_prefill(intbuff, length, 1, '0');
|
||||
break;
|
||||
|
Reference in New Issue
Block a user