Commit e9ca6861 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-4871 Temporal literals do not accept nanoseconds

parent 3462b6d3
...@@ -69,6 +69,13 @@ extern uchar days_in_month[]; ...@@ -69,6 +69,13 @@ extern uchar days_in_month[];
#define MYSQL_TIME_WARN_TRUNCATED 1 #define MYSQL_TIME_WARN_TRUNCATED 1
#define MYSQL_TIME_WARN_OUT_OF_RANGE 2 #define MYSQL_TIME_WARN_OUT_OF_RANGE 2
#define MYSQL_TIME_NOTE_TRUNCATED 16
#define MYSQL_TIME_WARN_WARNINGS (MYSQL_TIME_WARN_TRUNCATED|MYSQL_TIME_WARN_OUT_OF_RANGE)
#define MYSQL_TIME_WARN_NOTES (MYSQL_TIME_NOTE_TRUNCATED)
#define MYSQL_TIME_WARN_HAVE_WARNINGS(x) test((x) & MYSQL_TIME_WARN_WARNINGS)
#define MYSQL_TIME_WARN_HAVE_NOTES(x) test((x) & MYSQL_TIME_WARN_NOTES)
/* Limits for the TIME data type */ /* Limits for the TIME data type */
#define TIME_MAX_HOUR 838 #define TIME_MAX_HOUR 838
......
...@@ -562,7 +562,7 @@ select column_get(column_create(1, "2011-04-05 8:46:06.12345678" AS datetime(6)) ...@@ -562,7 +562,7 @@ select column_get(column_create(1, "2011-04-05 8:46:06.12345678" AS datetime(6))
column_get(column_create(1, "2011-04-05 8:46:06.12345678" AS datetime(6)), 1 as decimal(32,8)) column_get(column_create(1, "2011-04-05 8:46:06.12345678" AS datetime(6)), 1 as decimal(32,8))
20110405084606.12345600 20110405084606.12345600
Warnings: Warnings:
Warning 1292 Truncated incorrect datetime value: '2011-04-05 8:46:06.12345678' Note 1292 Truncated incorrect datetime value: '2011-04-05 8:46:06.12345678'
select column_get(column_create(1, NULL as decimal), 1 as decimal(32,10)); select column_get(column_create(1, NULL as decimal), 1 as decimal(32,10));
column_get(column_create(1, NULL as decimal), 1 as decimal(32,10)) column_get(column_create(1, NULL as decimal), 1 as decimal(32,10))
NULL NULL
......
...@@ -291,24 +291,33 @@ SELECT TIMESTAMP'2001-01-00 00:00:00.999999'; ...@@ -291,24 +291,33 @@ SELECT TIMESTAMP'2001-01-00 00:00:00.999999';
TIMESTAMP'2001-01-00 00:00:00.999999' TIMESTAMP'2001-01-00 00:00:00.999999'
2001-01-00 00:00:00.999999 2001-01-00 00:00:00.999999
SELECT TIMESTAMP'2001-00-00 00:00:00.9999999'; SELECT TIMESTAMP'2001-00-00 00:00:00.9999999';
ERROR HY000: Incorrect DATETIME value: '2001-00-00 00:00:00.9999999' TIMESTAMP'2001-00-00 00:00:00.9999999'
2001-00-00 00:00:00.999999
Warnings:
Note 1292 Truncated incorrect datetime value: '2001-00-00 00:00:00.9999999'
SELECT TIMESTAMP'2001-00-01 00:00:00.9999999'; SELECT TIMESTAMP'2001-00-01 00:00:00.9999999';
ERROR HY000: Incorrect DATETIME value: '2001-00-01 00:00:00.9999999' TIMESTAMP'2001-00-01 00:00:00.9999999'
2001-00-01 00:00:00.999999
Warnings:
Note 1292 Truncated incorrect datetime value: '2001-00-01 00:00:00.9999999'
SELECT TIMESTAMP'2001-01-00 00:00:00.9999999'; SELECT TIMESTAMP'2001-01-00 00:00:00.9999999';
ERROR HY000: Incorrect DATETIME value: '2001-01-00 00:00:00.9999999' TIMESTAMP'2001-01-00 00:00:00.9999999'
2001-01-00 00:00:00.999999
Warnings:
Note 1292 Truncated incorrect datetime value: '2001-01-00 00:00:00.9999999'
# #
# String literal with bad dates and nanoseconds to DATETIME(N) # String literal with bad dates and nanoseconds to DATETIME(N)
# #
CREATE TABLE t1 (a DATETIME(6)); CREATE TABLE t1 (a DATETIME(6));
INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
SELECT * FROM t1; SELECT * FROM t1;
a a
2001-00-00 00:00:00.999999 2001-00-00 00:00:00.999999
...@@ -318,13 +327,13 @@ DROP TABLE t1; ...@@ -318,13 +327,13 @@ DROP TABLE t1;
CREATE TABLE t1 (a DATETIME(5)); CREATE TABLE t1 (a DATETIME(5));
INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
SELECT * FROM t1; SELECT * FROM t1;
a a
2001-00-00 00:00:00.99999 2001-00-00 00:00:00.99999
...@@ -334,13 +343,13 @@ DROP TABLE t1; ...@@ -334,13 +343,13 @@ DROP TABLE t1;
CREATE TABLE t1 (a DATETIME); CREATE TABLE t1 (a DATETIME);
INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-00-01 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999'); INSERT INTO t1 VALUES ('2001-01-00 00:00:00.9999999');
Warnings: Warnings:
Warning 1265 Data truncated for column 'a' at row 1 Note 1265 Data truncated for column 'a' at row 1
SELECT * FROM t1; SELECT * FROM t1;
a a
2001-00-00 00:00:00 2001-00-00 00:00:00
...@@ -414,3 +423,54 @@ SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00'; ...@@ -414,3 +423,54 @@ SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00';
ERROR HY000: Incorrect arguments to ESCAPE ERROR HY000: Incorrect arguments to ESCAPE
SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00'; SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00';
ERROR HY000: Incorrect arguments to ESCAPE ERROR HY000: Incorrect arguments to ESCAPE
#
# MDEV-4871 Temporal literals do not accept nanoseconds
#
SELECT TIME'10:10:10.1234567';
TIME'10:10:10.1234567'
10:10:10.123456
Warnings:
Note 1292 Truncated incorrect time value: '10:10:10.1234567'
SELECT TIME('10:10:10.1234567');
TIME('10:10:10.1234567')
10:10:10.123456
Warnings:
Note 1292 Truncated incorrect time value: '10:10:10.1234567'
SELECT TIME'10:10:10.123456xyz';
ERROR HY000: Incorrect TIME value: '10:10:10.123456xyz'
SELECT TIME'10:10:10.1234567xyz';
ERROR HY000: Incorrect TIME value: '10:10:10.1234567xyz'
SELECT TIME('10:10:10.123456xyz');
TIME('10:10:10.123456xyz')
10:10:10.123456
Warnings:
Warning 1292 Truncated incorrect time value: '10:10:10.123456xyz'
SELECT TIME('10:10:10.1234567xyz');
TIME('10:10:10.1234567xyz')
10:10:10.123456
Warnings:
Warning 1292 Truncated incorrect time value: '10:10:10.1234567xyz'
SELECT TIMESTAMP'2001-01-01 10:10:10.1234567';
TIMESTAMP'2001-01-01 10:10:10.1234567'
2001-01-01 10:10:10.123456
Warnings:
Note 1292 Truncated incorrect datetime value: '2001-01-01 10:10:10.1234567'
SELECT TIMESTAMP('2001-01-01 10:10:10.1234567');
TIMESTAMP('2001-01-01 10:10:10.1234567')
2001-01-01 10:10:10.123456
Warnings:
Note 1292 Truncated incorrect datetime value: '2001-01-01 10:10:10.1234567'
SELECT TIMESTAMP'2001-01-01 10:10:10.123456xyz';
ERROR HY000: Incorrect DATETIME value: '2001-01-01 10:10:10.123456xyz'
SELECT TIMESTAMP'2001-01-01 10:10:10.1234567xyz';
ERROR HY000: Incorrect DATETIME value: '2001-01-01 10:10:10.1234567xyz'
SELECT TIMESTAMP('2001-01-01 10:10:10.123456xyz');
TIMESTAMP('2001-01-01 10:10:10.123456xyz')
2001-01-01 10:10:10.123456
Warnings:
Warning 1292 Truncated incorrect datetime value: '2001-01-01 10:10:10.123456xyz'
SELECT TIMESTAMP('2001-01-01 10:10:10.1234567xyz');
TIMESTAMP('2001-01-01 10:10:10.1234567xyz')
2001-01-01 10:10:10.123456
Warnings:
Warning 1292 Truncated incorrect datetime value: '2001-01-01 10:10:10.1234567xyz'
...@@ -627,12 +627,12 @@ SELECT CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME(6)) AS DECIMAL(30,7)) ...@@ -627,12 +627,12 @@ SELECT CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME(6)) AS DECIMAL(30,7))
CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME(6)) AS DECIMAL(30,7)) CAST(CAST('2006-08-10 10:11:12.0123450' AS DATETIME(6)) AS DECIMAL(30,7))
20060810101112.0123450 20060810101112.0123450
Warnings: Warnings:
Warning 1292 Truncated incorrect datetime value: '2006-08-10 10:11:12.0123450' Note 1292 Truncated incorrect datetime value: '2006-08-10 10:11:12.0123450'
SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME(6)) AS DECIMAL(30,7)); SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME(6)) AS DECIMAL(30,7));
CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME(6)) AS DECIMAL(30,7)) CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.0123450' AS DATETIME(6)) AS DECIMAL(30,7))
20060810101112.0123450 20060810101112.0123450
Warnings: Warnings:
Warning 1292 Truncated incorrect datetime value: '00000002006-000008-0000010 000010:0000011:00000012.0123450' Note 1292 Truncated incorrect datetime value: '00000002006-000008-0000010 000010:0000011:00000012.0123450'
SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME(6)) AS DECIMAL(30,7)); SELECT CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME(6)) AS DECIMAL(30,7));
CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME(6)) AS DECIMAL(30,7)) CAST(CAST('00000002006-000008-0000010 000010:0000011:00000012.012345' AS DATETIME(6)) AS DECIMAL(30,7))
20060810101112.0123450 20060810101112.0123450
...@@ -640,7 +640,7 @@ SELECT CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime(6)) AS DECIMAL(30,7)) ...@@ -640,7 +640,7 @@ SELECT CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime(6)) AS DECIMAL(30,7))
CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime(6)) AS DECIMAL(30,7)) CAST(CAST('2008-07-29T10:42:51.1234567' AS DateTime(6)) AS DECIMAL(30,7))
20080729104251.1234560 20080729104251.1234560
Warnings: Warnings:
Warning 1292 Truncated incorrect datetime value: '2008-07-29T10:42:51.1234567' Note 1292 Truncated incorrect datetime value: '2008-07-29T10:42:51.1234567'
# #
# Bug#59173: Failure to handle DATE(TIME) values where Year, Month or # Bug#59173: Failure to handle DATE(TIME) values where Year, Month or
# Day is ZERO # Day is ZERO
......
...@@ -155,11 +155,8 @@ EXPLAIN EXTENDED SELECT TIMESTAMP'2010-01-01 10:10:10'; ...@@ -155,11 +155,8 @@ EXPLAIN EXTENDED SELECT TIMESTAMP'2010-01-01 10:10:10';
SELECT TIMESTAMP'2001-00-00 00:00:00.999999'; SELECT TIMESTAMP'2001-00-00 00:00:00.999999';
SELECT TIMESTAMP'2001-00-01 00:00:00.999999'; SELECT TIMESTAMP'2001-00-01 00:00:00.999999';
SELECT TIMESTAMP'2001-01-00 00:00:00.999999'; SELECT TIMESTAMP'2001-01-00 00:00:00.999999';
--error ER_WRONG_VALUE
SELECT TIMESTAMP'2001-00-00 00:00:00.9999999'; SELECT TIMESTAMP'2001-00-00 00:00:00.9999999';
--error ER_WRONG_VALUE
SELECT TIMESTAMP'2001-00-01 00:00:00.9999999'; SELECT TIMESTAMP'2001-00-01 00:00:00.9999999';
--error ER_WRONG_VALUE
SELECT TIMESTAMP'2001-01-00 00:00:00.9999999'; SELECT TIMESTAMP'2001-01-00 00:00:00.9999999';
--echo # --echo #
...@@ -215,3 +212,24 @@ SELECT 'a' LIKE 'a' ESCAPE DATE'2001-01-01'; ...@@ -215,3 +212,24 @@ SELECT 'a' LIKE 'a' ESCAPE DATE'2001-01-01';
SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00'; SELECT 'a' LIKE 'a' ESCAPE TIMESTAMP'2001-01-01 00:00:00';
--error ER_WRONG_ARGUMENTS --error ER_WRONG_ARGUMENTS
SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00'; SELECT 'a' LIKE 'a' ESCAPE TIME'00:00:00';
--echo #
--echo # MDEV-4871 Temporal literals do not accept nanoseconds
--echo #
SELECT TIME'10:10:10.1234567';
SELECT TIME('10:10:10.1234567');
--error ER_WRONG_VALUE
SELECT TIME'10:10:10.123456xyz';
--error ER_WRONG_VALUE
SELECT TIME'10:10:10.1234567xyz';
SELECT TIME('10:10:10.123456xyz');
SELECT TIME('10:10:10.1234567xyz');
SELECT TIMESTAMP'2001-01-01 10:10:10.1234567';
SELECT TIMESTAMP('2001-01-01 10:10:10.1234567');
--error ER_WRONG_VALUE
SELECT TIMESTAMP'2001-01-01 10:10:10.123456xyz';
--error ER_WRONG_VALUE
SELECT TIMESTAMP'2001-01-01 10:10:10.1234567xyz';
SELECT TIMESTAMP('2001-01-01 10:10:10.123456xyz');
SELECT TIMESTAMP('2001-01-01 10:10:10.1234567xyz');
...@@ -239,7 +239,7 @@ static void get_microseconds(ulong *val, MYSQL_TIME_STATUS *status, ...@@ -239,7 +239,7 @@ static void get_microseconds(ulong *val, MYSQL_TIME_STATUS *status,
else else
*val= tmp; *val= tmp;
if (skip_digits(str, end)) if (skip_digits(str, end))
status->warnings|= MYSQL_TIME_WARN_TRUNCATED; status->warnings|= MYSQL_TIME_NOTE_TRUNCATED;
} }
......
...@@ -4593,19 +4593,25 @@ my_time_t Field_timestamp::get_timestamp(ulong *sec_part) const ...@@ -4593,19 +4593,25 @@ my_time_t Field_timestamp::get_timestamp(ulong *sec_part) const
int Field_timestamp::store_TIME_with_warning(THD *thd, MYSQL_TIME *l_time, int Field_timestamp::store_TIME_with_warning(THD *thd, MYSQL_TIME *l_time,
const ErrConv *str, const ErrConv *str,
bool was_cut, int was_cut,
bool have_smth_to_conv) bool have_smth_to_conv)
{ {
ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED;
uint error = 0; uint error = 0;
my_time_t timestamp; my_time_t timestamp;
if (was_cut || !have_smth_to_conv) if (MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut) || !have_smth_to_conv)
{ {
error= 1; error= 1;
set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, set_datetime_warning(Sql_condition::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED,
str, MYSQL_TIMESTAMP_DATETIME, 1); str, MYSQL_TIMESTAMP_DATETIME, 1);
} }
else if (MYSQL_TIME_WARN_HAVE_NOTES(was_cut))
{
error= 3;
set_datetime_warning(Sql_condition::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED,
str, MYSQL_TIMESTAMP_DATETIME, 1);
}
/* Only convert a correct date (not a zero date) */ /* Only convert a correct date (not a zero date) */
if (have_smth_to_conv && l_time->month) if (have_smth_to_conv && l_time->month)
{ {
...@@ -5138,9 +5144,10 @@ int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME *ltime, ...@@ -5138,9 +5144,10 @@ int Field_temporal_with_date::store_TIME_with_warning(MYSQL_TIME *ltime,
was_cut= MYSQL_TIME_WARN_TRUNCATED; was_cut= MYSQL_TIME_WARN_TRUNCATED;
ret= 1; ret= 1;
} }
else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && else if (!MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut) &&
mysql_type_to_time_type(type()) == MYSQL_TIMESTAMP_DATE && (MYSQL_TIME_WARN_HAVE_NOTES(was_cut) ||
(ltime->hour || ltime->minute || ltime->second || ltime->second_part)) (mysql_type_to_time_type(type()) == MYSQL_TIMESTAMP_DATE &&
(ltime->hour || ltime->minute || ltime->second || ltime->second_part))))
{ {
trunc_level= Sql_condition::WARN_LEVEL_NOTE; trunc_level= Sql_condition::WARN_LEVEL_NOTE;
was_cut|= MYSQL_TIME_WARN_TRUNCATED; was_cut|= MYSQL_TIME_WARN_TRUNCATED;
...@@ -5230,7 +5237,6 @@ int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime, ...@@ -5230,7 +5237,6 @@ int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime,
{ {
Sql_condition::enum_warning_level trunc_level= Sql_condition::WARN_LEVEL_WARN; Sql_condition::enum_warning_level trunc_level= Sql_condition::WARN_LEVEL_WARN;
int ret= 2; int ret= 2;
ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED; ASSERT_COLUMN_MARKED_FOR_WRITE_OR_COMPUTED;
if (!have_smth_to_conv) if (!have_smth_to_conv)
...@@ -5239,9 +5245,11 @@ int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime, ...@@ -5239,9 +5245,11 @@ int Field_time::store_TIME_with_warning(MYSQL_TIME *ltime,
was_cut= MYSQL_TIME_WARN_TRUNCATED; was_cut= MYSQL_TIME_WARN_TRUNCATED;
ret= 1; ret= 1;
} }
else if (!(was_cut & MYSQL_TIME_WARN_TRUNCATED) && else if (!MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut) &&
(ltime->year || ltime->month)) ((ltime->year || ltime->month) ||
MYSQL_TIME_WARN_HAVE_NOTES(was_cut)))
{ {
if (ltime->year || ltime->month)
ltime->year= ltime->month= ltime->day= 0; ltime->year= ltime->month= ltime->day= 0;
trunc_level= Sql_condition::WARN_LEVEL_NOTE; trunc_level= Sql_condition::WARN_LEVEL_NOTE;
was_cut|= MYSQL_TIME_WARN_TRUNCATED; was_cut|= MYSQL_TIME_WARN_TRUNCATED;
......
...@@ -1543,7 +1543,7 @@ class Field_temporal_with_date: public Field_temporal { ...@@ -1543,7 +1543,7 @@ class Field_temporal_with_date: public Field_temporal {
class Field_timestamp :public Field_temporal { class Field_timestamp :public Field_temporal {
protected: protected:
int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *, int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *,
bool, bool); int warnings, bool have_smth_to_conv);
public: public:
Field_timestamp(uchar *ptr_arg, uint32 len_arg, Field_timestamp(uchar *ptr_arg, uint32 len_arg,
uchar *null_ptr_arg, uchar null_bit_arg, uchar *null_ptr_arg, uchar null_bit_arg,
......
...@@ -5796,6 +5796,13 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type, ...@@ -5796,6 +5796,13 @@ create_func_cast(THD *thd, Item *a, Cast_target cast_type,
} }
static bool
have_important_literal_warnings(const MYSQL_TIME_STATUS *status)
{
return (status->warnings & ~MYSQL_TIME_NOTE_TRUNCATED) != 0;
}
/** /**
Builder for datetime literals: Builder for datetime literals:
TIME'00:00:00', DATE'2001-01-01', TIMESTAMP'2001-01-01 00:00:00'. TIME'00:00:00', DATE'2001-01-01', TIMESTAMP'2001-01-01 00:00:00'.
...@@ -5827,13 +5834,15 @@ Item *create_temporal_literal(THD *thd, ...@@ -5827,13 +5834,15 @@ Item *create_temporal_literal(THD *thd,
break; break;
case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_DATETIME:
if (!str_to_datetime(cs, str, length, &ltime, flags, &status) && if (!str_to_datetime(cs, str, length, &ltime, flags, &status) &&
ltime.time_type == MYSQL_TIMESTAMP_DATETIME && !status.warnings) ltime.time_type == MYSQL_TIMESTAMP_DATETIME &&
!have_important_literal_warnings(&status))
item= new (thd->mem_root) Item_datetime_literal(&ltime, item= new (thd->mem_root) Item_datetime_literal(&ltime,
status.precision); status.precision);
break; break;
case MYSQL_TYPE_TIME: case MYSQL_TYPE_TIME:
if (!str_to_time(cs, str, length, &ltime, 0, &status) && if (!str_to_time(cs, str, length, &ltime, 0, &status) &&
ltime.time_type == MYSQL_TIMESTAMP_TIME && !status.warnings) ltime.time_type == MYSQL_TIMESTAMP_TIME &&
!have_important_literal_warnings(&status))
item= new (thd->mem_root) Item_time_literal(&ltime, item= new (thd->mem_root) Item_time_literal(&ltime,
status.precision); status.precision);
break; break;
...@@ -5842,7 +5851,16 @@ Item *create_temporal_literal(THD *thd, ...@@ -5842,7 +5851,16 @@ Item *create_temporal_literal(THD *thd,
} }
if (item) if (item)
{
if (status.warnings) // e.g. a note on nanosecond truncation
{
ErrConvString err(str, length, cs);
make_truncated_value_warning(current_thd,
Sql_condition::time_warn_level(status.warnings),
&err, ltime.time_type, 0);
}
return item; return item;
}
if (send_error) if (send_error)
{ {
......
...@@ -46,6 +46,16 @@ class Sql_condition : public Sql_alloc ...@@ -46,6 +46,16 @@ class Sql_condition : public Sql_alloc
enum enum_warning_level enum enum_warning_level
{ WARN_LEVEL_NOTE, WARN_LEVEL_WARN, WARN_LEVEL_ERROR, WARN_LEVEL_END}; { WARN_LEVEL_NOTE, WARN_LEVEL_WARN, WARN_LEVEL_ERROR, WARN_LEVEL_END};
/**
Convert a bitmask consisting of MYSQL_TIME_{NOTE|WARN}_XXX bits
to WARN_LEVEL_XXX
*/
static enum_warning_level time_warn_level(int warnings)
{
return MYSQL_TIME_WARN_HAVE_WARNINGS(warnings) ?
WARN_LEVEL_WARN : WARN_LEVEL_NOTE;
}
/** /**
Get the MESSAGE_TEXT of this condition. Get the MESSAGE_TEXT of this condition.
@return the message text. @return the message text.
......
...@@ -311,7 +311,9 @@ str_to_datetime_with_warn(CHARSET_INFO *cs, ...@@ -311,7 +311,9 @@ str_to_datetime_with_warn(CHARSET_INFO *cs,
THD *thd= current_thd; THD *thd= current_thd;
bool ret_val= str_to_datetime(cs, str, length, l_time, flags, &status); bool ret_val= str_to_datetime(cs, str, length, l_time, flags, &status);
if (ret_val || status.warnings) if (ret_val || status.warnings)
make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN, make_truncated_value_warning(thd,
ret_val ? Sql_condition::WARN_LEVEL_WARN :
Sql_condition::time_warn_level(status.warnings),
str, length, flags & TIME_TIME_ONLY ? str, length, flags & TIME_TIME_ONLY ?
MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS);
DBUG_EXECUTE_IF("str_to_datetime_warn", DBUG_EXECUTE_IF("str_to_datetime_warn",
......
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