Commit c562c744 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-457 Inconsistent data truncation on datetime values with fractional...

MDEV-457 Inconsistent data truncation on datetime values with fractional seconds represented as strings with no delimiters

New implementation for str_to_datetime. Fix MDEV-457 and related issues.
parent 51392386
......@@ -1023,11 +1023,11 @@ MAKETIME(CAST(-1 AS UNSIGNED), 0, 0)
Warnings:
Note 1105 Cast to unsigned converted negative integer to it's positive complement
Warning 1292 Truncated incorrect time value: '18446744073709551615:00:00'
SELECT EXTRACT(HOUR FROM '100000:02:03');
EXTRACT(HOUR FROM '100000:02:03')
SELECT EXTRACT(HOUR FROM '10000:02:03');
EXTRACT(HOUR FROM '10000:02:03')
838
Warnings:
Warning 1292 Truncated incorrect time value: '100000:02:03'
Warning 1292 Truncated incorrect time value: '10000:02:03'
CREATE TABLE t1(f1 TIME);
INSERT INTO t1 VALUES('916:00:00 a');
Warnings:
......
......@@ -5,8 +5,8 @@ Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'd' at row 1
Warning 1264 Out of range value for column 'a' at row 2
Warning 1264 Out of range value for column 'b' at row 2
Warning 1265 Data truncated for column 'a' at row 2
Warning 1265 Data truncated for column 'b' at row 2
Warning 1265 Data truncated for column 'd' at row 2
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
SELECT * from t1;
......@@ -20,7 +20,7 @@ load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'd' at row 1
Warning 1264 Out of range value for column 'b' at row 2
Warning 1265 Data truncated for column 'b' at row 2
Warning 1265 Data truncated for column 'd' at row 2
SELECT * from t1;
a b c d
......
select cast('01:02:03 ' as time), cast('01:02:03 ' as time);
cast('01:02:03 ' as time) cast('01:02:03 ' as time)
01:02:03 00:00:00
select cast('2002-011-012' as date), cast('2002.11.12' as date), cast('2002.011.012' as date);
cast('2002-011-012' as date) cast('2002.11.12' as date) cast('2002.011.012' as date)
2002-11-12 2002-11-12 2002-11-12
select cast('2012103123595912' as datetime(6)), cast('20121031235959123' as datetime(6));
cast('2012103123595912' as datetime(6)) cast('20121031235959123' as datetime(6))
2012-10-31 23:59:59.000000 2012-10-31 23:59:59.000000
Warnings:
Warning 1292 Truncated incorrect datetime value: '2012103123595912'
Warning 1292 Truncated incorrect datetime value: '20121031235959123'
select cast(0 as date), cast('0000-00-00' as date), cast('0' as date);
cast(0 as date) cast('0000-00-00' as date) cast('0' as date)
0000-00-00 0000-00-00 NULL
Warnings:
Warning 1292 Incorrect datetime value: '0'
select extract(hour from '100000:02:03'), extract(hour from '100000:02:03 ');
extract(hour from '100000:02:03') extract(hour from '100000:02:03 ')
NULL NULL
Warnings:
Warning 1292 Truncated incorrect time value: '100000:02:03'
Warning 1292 Truncated incorrect time value: '100000:02:03 '
#
# backward compatibility craziness
#
select cast('12:00:00.12.34.56' as time);
cast('12:00:00.12.34.56' as time)
12:00:00
Warnings:
Warning 1292 Truncated incorrect time value: '12:00:00.12.34.56'
select cast('12:00:00 12.34.56' as time);
cast('12:00:00 12.34.56' as time)
12:34:56
select cast('12:00:00-12.34.56' as time);
cast('12:00:00-12.34.56' as time)
12:00:00
Warnings:
Warning 1292 Truncated incorrect time value: '12:00:00-12.34.56'
select cast('12:00:00.12.34.56' as datetime);
cast('12:00:00.12.34.56' as datetime)
2012-00-00 12:34:56
select cast('12:00:00-12.34.56' as datetime);
cast('12:00:00-12.34.56' as datetime)
2012-00-00 12:34:56
select cast('12:00:00 12.34.56' as datetime);
cast('12:00:00 12.34.56' as datetime)
2012-00-00 12:34:56
select cast('12:00:00.123456' as time);
cast('12:00:00.123456' as time)
12:00:00
......@@ -25,8 +25,8 @@ Warnings:
Warning 1265 Data truncated for column 'a' at row 1
Warning 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'd' at row 1
Warning 1264 Out of range value for column 'a' at row 2
Warning 1264 Out of range value for column 'b' at row 2
Warning 1265 Data truncated for column 'a' at row 2
Warning 1265 Data truncated for column 'b' at row 2
Warning 1265 Data truncated for column 'd' at row 2
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
select * from rewrite.t1;
......@@ -40,7 +40,7 @@ load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated
Warnings:
Warning 1265 Data truncated for column 'c' at row 1
Warning 1265 Data truncated for column 'd' at row 1
Warning 1264 Out of range value for column 'b' at row 2
Warning 1265 Data truncated for column 'b' at row 2
Warning 1265 Data truncated for column 'd' at row 2
select * from rewrite.t1;
a b c d
......
......@@ -526,7 +526,7 @@ SELECT MAKETIME(0, 0, 4294967296);
SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0);
# check if EXTRACT() handles out-of-range values correctly
SELECT EXTRACT(HOUR FROM '100000:02:03');
SELECT EXTRACT(HOUR FROM '10000:02:03');
# check if we get proper warnings if both input string truncation
# and out-of-range value occur
......
#
# MDEV-457 Inconsistent data truncation on datetime values with fractional seconds represented as strings with no delimiters
# (and other problems with str_to_datetime)
#
# first was ok, second was not
select cast('01:02:03 ' as time), cast('01:02:03 ' as time);
# first two were ok, third was not
select cast('2002-011-012' as date), cast('2002.11.12' as date), cast('2002.011.012' as date);
# only two microsecond digits were ok, third was truncated with a warning
select cast('2012103123595912' as datetime(6)), cast('20121031235959123' as datetime(6));
# zero string date was considered 'out of range'. Must be either ok or invalid format
select cast(0 as date), cast('0000-00-00' as date), cast('0' as date);
# first was ok, second was not
select extract(hour from '100000:02:03'), extract(hour from '100000:02:03 ');
--echo #
--echo # backward compatibility craziness
--echo #
select cast('12:00:00.12.34.56' as time); # was 12:00:00
select cast('12:00:00 12.34.56' as time); # was 12:34:56
select cast('12:00:00-12.34.56' as time); # was 12:00:00
select cast('12:00:00.12.34.56' as datetime);
select cast('12:00:00-12.34.56' as datetime);
select cast('12:00:00 12.34.56' as datetime);
select cast('12:00:00.123456' as time);
This diff is collapsed.
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