Skip to content

Commit

Permalink
MDEV-31334: Consider dates ending in 'T' as malformed
Browse files Browse the repository at this point in the history
According to ISO 8601 standard, 'T' should be followed by the time of
day. If a date ends with only 'T', throw an error in strict mode and a
warning in other modes.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
  • Loading branch information
FarihaIS committed Jan 22, 2025
1 parent 89f5d28 commit bd2c417
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
46 changes: 39 additions & 7 deletions mysql-test/main/func_extract.result
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ EXTRACT(DAY FROM '01-02-03')
3
SELECT EXTRACT(DAY FROM '24:02:03T');
EXTRACT(DAY FROM '24:02:03T')
3
1
Warnings:
Warning 1292 Truncated incorrect time value: '24:02:03T'
SELECT EXTRACT(DAY FROM '24-02-03');
EXTRACT(DAY FROM '24-02-03')
3
Expand All @@ -380,39 +382,69 @@ EXTRACT(DAY FROM '11111')
SELECT TIME('2001-01-01T'), TIME('2001-01-01T ');
TIME('2001-01-01T') TIME('2001-01-01T ')
00:00:00 00:00:00
Warnings:
Warning 1292 Truncated incorrect date value: '2001-01-01T'
Warning 1292 Truncated incorrect date value: '2001-01-01T '
SELECT TIME('2001/01/01T'), TIME('2001/01/01T ');
TIME('2001/01/01T') TIME('2001/01/01T ')
00:00:00 00:00:00
Warnings:
Warning 1292 Truncated incorrect date value: '2001/01/01T'
Warning 1292 Truncated incorrect date value: '2001/01/01T '
SELECT TIME('2001:01:01T'), TIME('2001:01:01T ');
TIME('2001:01:01T') TIME('2001:01:01T ')
00:00:00 00:00:00
838:59:59 838:59:59
Warnings:
Warning 1292 Truncated incorrect time value: '2001:01:01T'
Warning 1292 Truncated incorrect time value: '2001:01:01T '
SELECT EXTRACT(DAY FROM '2001-01-01T'), EXTRACT(DAY FROM '2001-01-01T ');
EXTRACT(DAY FROM '2001-01-01T') EXTRACT(DAY FROM '2001-01-01T ')
1 1
Warnings:
Warning 1292 Truncated incorrect date value: '2001-01-01T'
Warning 1292 Truncated incorrect date value: '2001-01-01T '
SELECT EXTRACT(DAY FROM '2001/01/01T'), EXTRACT(DAY FROM '2001/01/01T ');
EXTRACT(DAY FROM '2001/01/01T') EXTRACT(DAY FROM '2001/01/01T ')
1 1
Warnings:
Warning 1292 Truncated incorrect date value: '2001/01/01T'
Warning 1292 Truncated incorrect date value: '2001/01/01T '
SELECT EXTRACT(DAY FROM '2001:01:01T'), EXTRACT(DAY FROM '2001:01:01T ');
EXTRACT(DAY FROM '2001:01:01T') EXTRACT(DAY FROM '2001:01:01T ')
1 1
83 83
Warnings:
Warning 1292 Truncated incorrect time value: '2001:01:01T'
Warning 1292 Truncated incorrect time value: '2001:01:01T '
SELECT TIME('2001:01:01T'), TIME('2001:01:01T ');
TIME('2001:01:01T') TIME('2001:01:01T ')
00:00:00 00:00:00
838:59:59 838:59:59
Warnings:
Warning 1292 Truncated incorrect time value: '2001:01:01T'
Warning 1292 Truncated incorrect time value: '2001:01:01T '
SELECT EXTRACT(HOUR FROM '2001-01-01T'), EXTRACT(HOUR FROM '2001-01-01T ');
EXTRACT(HOUR FROM '2001-01-01T') EXTRACT(HOUR FROM '2001-01-01T ')
0 0
Warnings:
Warning 1292 Truncated incorrect date value: '2001-01-01T'
Warning 1292 Truncated incorrect date value: '2001-01-01T '
SELECT EXTRACT(HOUR FROM '2001/01/01T'), EXTRACT(HOUR FROM '2001/01/01T ');
EXTRACT(HOUR FROM '2001/01/01T') EXTRACT(HOUR FROM '2001/01/01T ')
0 0
Warnings:
Warning 1292 Truncated incorrect date value: '2001/01/01T'
Warning 1292 Truncated incorrect date value: '2001/01/01T '
SELECT EXTRACT(HOUR FROM '2001:01:01T'), EXTRACT(HOUR FROM '2001:01:01T ');
EXTRACT(HOUR FROM '2001:01:01T') EXTRACT(HOUR FROM '2001:01:01T ')
0 0
9 9
Warnings:
Warning 1292 Truncated incorrect time value: '2001:01:01T'
Warning 1292 Truncated incorrect time value: '2001:01:01T '
# This still parses as DATE and returns NULL (without trying TIME)
SELECT EXTRACT(DAY FROM '100000:02:03T');
EXTRACT(DAY FROM '100000:02:03T')
NULL
4166
Warnings:
Warning 1292 Incorrect interval value: '100000:02:03T'
Warning 1292 Truncated incorrect time value: '100000:02:03T'
SELECT EXTRACT(DAY FROM '100000/02/03');
EXTRACT(DAY FROM '100000/02/03')
NULL
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/main/func_time.result
Original file line number Diff line number Diff line change
Expand Up @@ -6253,6 +6253,9 @@ Warning 1292 Truncated incorrect time value: '1 2 '
SELECT TIME('2001-01-01T'), TIME('2001-01-01T ');
TIME('2001-01-01T') TIME('2001-01-01T ')
00:00:00 00:00:00
Warnings:
Warning 1292 Truncated incorrect date value: '2001-01-01T'
Warning 1292 Truncated incorrect date value: '2001-01-01T '
SELECT TIME('901-01-01T1'), TIME('901-01-01T10');
TIME('901-01-01T1') TIME('901-01-01T10')
01:00:00 10:00:00
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/main/strict.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ INSERT INTO t1 VALUES ('59');
ERROR 22007: Incorrect date value: '59' for column `test`.`t1`.`col1` at row 1
set @@sql_mode='STRICT_ALL_TABLES';
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
INSERT INTO t1 VALUES('2004-01-01Q');
ERROR 22007: Incorrect date value: '2004-01-01Q' for column `test`.`t1`.`col1` at row 1
INSERT INTO t1 VALUES('2004-01-01T');
ERROR 22007: Incorrect date value: '2004-01-01T' for column `test`.`t1`.`col1` at row 1
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
INSERT INTO t1 VALUES('2004-0-30');
ERROR 22007: Incorrect date value: '2004-0-30' for column `test`.`t1`.`col1` at row 1
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/main/strict.test
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ INSERT INTO t1 VALUES ('59');
# Test the different related modes
set @@sql_mode='STRICT_ALL_TABLES';
INSERT INTO t1 VALUES('2004-01-03'),('2004-0-31');
--error 1292
INSERT INTO t1 VALUES('2004-01-01Q');
--error 1292
INSERT INTO t1 VALUES('2004-01-01T');
set @@sql_mode='STRICT_ALL_TABLES,NO_ZERO_IN_DATE';
--error 1292
INSERT INTO t1 VALUES('2004-0-30');
Expand Down
2 changes: 1 addition & 1 deletion sql-common/my_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int get_date_time_separator(uint *number_of_fields,
if (s >= end)
return 0;

if (*s == 'T')
if (*s == 'T' && s + 1 < end)
{
(*str)++;
return 0;
Expand Down

0 comments on commit bd2c417

Please sign in to comment.