Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
3e5cdfae
Commit
3e5cdfae
authored
Sep 12, 2017
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix: TIME_FORMAT() allowed some non-time format specifiers
it contradicted the manual and was inconsistent
parent
3878badd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
8 deletions
+44
-8
mysql-test/r/date_formats.result
mysql-test/r/date_formats.result
+15
-0
mysql-test/suite/vcol/r/vcol_supported_sql_funcs.result
mysql-test/suite/vcol/r/vcol_supported_sql_funcs.result
+4
-4
mysql-test/suite/vcol/t/vcol_supported_sql_funcs_main.inc
mysql-test/suite/vcol/t/vcol_supported_sql_funcs_main.inc
+2
-2
mysql-test/t/date_formats.test
mysql-test/t/date_formats.test
+9
-0
sql/item_timefunc.cc
sql/item_timefunc.cc
+14
-2
No files found.
mysql-test/r/date_formats.result
View file @
3e5cdfae
...
...
@@ -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
mysql-test/suite/vcol/r/vcol_supported_sql_funcs.result
View file @
3e5cdfae
...
...
@@ -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:0
2:02
',default);
insert into t1 values ('2001-01-01 02:0
3:04
',default);
select * from t1;
a b
2001-01-01 02:0
2:02 01.01.2001
2001-01-01 02:0
3:04 02.03.04
drop table t1;
set sql_warnings = 0;
mysql-test/suite/vcol/t/vcol_supported_sql_funcs_main.inc
View file @
3e5cdfae
...
...
@@ -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:0
2:02
'
,
default
;
let
$cols
=
a
datetime
,
b
varchar
(
10
)
as
(
time_format
(
a
,
"%
H.%i.%S
"
));
let
$values1
=
'2001-01-01 02:0
3:04
'
,
default
;
let
$rows
=
1
;
--
source
suite
/
vcol
/
inc
/
vcol_supported_sql_funcs
.
inc
mysql-test/t/date_formats.test
View file @
3e5cdfae
...
...
@@ -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'
);
sql/item_timefunc.cc
View file @
3e5cdfae
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment