Commit 3e5cdfae authored by Sergei Golubchik's avatar Sergei Golubchik

bugfix: TIME_FORMAT() allowed some non-time format specifiers

it contradicted the manual and was inconsistent
parent 3878badd
...@@ -558,3 +558,18 @@ SET NAMES latin1; ...@@ -558,3 +558,18 @@ SET NAMES latin1;
# #
# End of 5.1 tests # 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; ...@@ -2911,16 +2911,16 @@ drop table t1;
set sql_warnings = 0; set sql_warnings = 0;
# TIME_FORMAT() # TIME_FORMAT()
set sql_warnings = 1; 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; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
`a` datetime DEFAULT NULL, `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 ) 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; select * from t1;
a b a b
2001-01-01 02:02:02 01.01.2001 2001-01-01 02:03:04 02.03.04
drop table t1; drop table t1;
set sql_warnings = 0; set sql_warnings = 0;
...@@ -1204,8 +1204,8 @@ let $rows = 1; ...@@ -1204,8 +1204,8 @@ let $rows = 1;
--source suite/vcol/inc/vcol_supported_sql_funcs.inc --source suite/vcol/inc/vcol_supported_sql_funcs.inc
--echo # TIME_FORMAT() --echo # TIME_FORMAT()
let $cols = a datetime, b varchar(10) as (time_format(a,"%d.%m.%Y")); let $cols = a datetime, b varchar(10) as (time_format(a,"%H.%i.%S"));
let $values1 = '2001-01-01 02:02:02',default; let $values1 = '2001-01-01 02:03:04',default;
let $rows = 1; let $rows = 1;
--source suite/vcol/inc/vcol_supported_sql_funcs.inc --source suite/vcol/inc/vcol_supported_sql_funcs.inc
...@@ -366,3 +366,12 @@ SET NAMES latin1; ...@@ -366,3 +366,12 @@ SET NAMES latin1;
--echo # --echo #
--echo # End of 5.1 tests --echo # End of 5.1 tests
--echo # --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, ...@@ -477,14 +477,14 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
{ {
switch (*++ptr) { switch (*++ptr) {
case 'M': case 'M':
if (!l_time->month) if (type == MYSQL_TIMESTAMP_TIME || !l_time->month)
return 1; return 1;
str->append(locale->month_names->type_names[l_time->month-1], str->append(locale->month_names->type_names[l_time->month-1],
(uint) strlen(locale->month_names->type_names[l_time->month-1]), (uint) strlen(locale->month_names->type_names[l_time->month-1]),
system_charset_info); system_charset_info);
break; break;
case 'b': case 'b':
if (!l_time->month) if (type == MYSQL_TIMESTAMP_TIME || !l_time->month)
return 1; return 1;
str->append(locale->ab_month_names->type_names[l_time->month-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]), (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, ...@@ -534,26 +534,38 @@ static bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time,
} }
break; break;
case 'Y': case 'Y':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->year, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->year, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 4, '0'); str->append_with_prefill(intbuff, length, 4, '0');
break; break;
case 'y': case 'y':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->year%100, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->year%100, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 2, '0'); str->append_with_prefill(intbuff, length, 2, '0');
break; break;
case 'm': case 'm':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 2, '0'); str->append_with_prefill(intbuff, length, 2, '0');
break; break;
case 'c': case 'c':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->month, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 1, '0'); str->append_with_prefill(intbuff, length, 1, '0');
break; break;
case 'd': case 'd':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 2, '0'); str->append_with_prefill(intbuff, length, 2, '0');
break; break;
case 'e': case 'e':
if (type == MYSQL_TIMESTAMP_TIME)
return 1;
length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff); length= (uint) (int10_to_str(l_time->day, intbuff, 10) - intbuff);
str->append_with_prefill(intbuff, length, 1, '0'); str->append_with_prefill(intbuff, length, 1, '0');
break; break;
......
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