Commit 81194d92 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zero_date_time_cast

parent af4d469a
...@@ -101,3 +101,16 @@ Warnings: ...@@ -101,3 +101,16 @@ Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00 00:20:12' Warning 1292 Incorrect datetime value: '0000-00-00 00:20:12'
Warning 1292 Truncated incorrect datetime value: '-00:20:12' Warning 1292 Truncated incorrect datetime value: '-00:20:12'
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zero_date_time_cast
#
SET @@old_mode=zero_date_time_cast;
CREATE TABLE t1 (a TIME,b TIME(1));
INSERT INTO t1 VALUES (TIME'830:20:30',TIME'830:20:30');
SELECT TO_DAYS(a), TO_DAYS(b) FROM t1;
TO_DAYS(a) TO_DAYS(b)
NULL NULL
Warnings:
Warning 1264 Out of range value for column 'a' at row 1
Warning 1264 Out of range value for column 'b' at row 1
DROP TABLE t1;
...@@ -64,3 +64,12 @@ INSERT INTO t1 VALUES (NULL, '00:20:12'); ...@@ -64,3 +64,12 @@ INSERT INTO t1 VALUES (NULL, '00:20:12');
INSERT INTO t1 VALUES (NULL, '-00:20:12'); INSERT INTO t1 VALUES (NULL, '-00:20:12');
SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1; SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zero_date_time_cast
--echo #
SET @@old_mode=zero_date_time_cast;
CREATE TABLE t1 (a TIME,b TIME(1));
INSERT INTO t1 VALUES (TIME'830:20:30',TIME'830:20:30');
SELECT TO_DAYS(a), TO_DAYS(b) FROM t1;
DROP TABLE t1;
...@@ -5442,6 +5442,21 @@ String *Field_time::val_str(String *str, ...@@ -5442,6 +5442,21 @@ String *Field_time::val_str(String *str,
} }
bool Field_time::check_zero_in_date_with_warn(ulonglong fuzzydate)
{
if (!(fuzzydate & TIME_TIME_ONLY) && (fuzzydate & TIME_NO_ZERO_IN_DATE))
{
THD *thd= get_thd();
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_DATA_OUT_OF_RANGE,
ER(ER_WARN_DATA_OUT_OF_RANGE), field_name,
thd->get_stmt_da()->current_row_for_warning());
return true;
}
return false;
}
/** /**
@note @note
Normally we would not consider 'time' as a valid date, but we allow Normally we would not consider 'time' as a valid date, but we allow
...@@ -5451,16 +5466,8 @@ String *Field_time::val_str(String *str, ...@@ -5451,16 +5466,8 @@ String *Field_time::val_str(String *str,
bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ {
if (!(fuzzydate & TIME_TIME_ONLY) && if (check_zero_in_date_with_warn(fuzzydate))
(fuzzydate & TIME_NO_ZERO_IN_DATE)) return true;
{
THD *thd= get_thd();
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARN_DATA_OUT_OF_RANGE,
ER(ER_WARN_DATA_OUT_OF_RANGE), field_name,
thd->get_stmt_da()->current_row_for_warning());
return 1;
}
long tmp=(long) sint3korr(ptr); long tmp=(long) sint3korr(ptr);
ltime->neg=0; ltime->neg=0;
if (tmp < 0) if (tmp < 0)
...@@ -5565,6 +5572,8 @@ double Field_time_with_dec::val_real(void) ...@@ -5565,6 +5572,8 @@ double Field_time_with_dec::val_real(void)
bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ {
if (check_zero_in_date_with_warn(fuzzydate))
return true;
uint32 len= pack_length(); uint32 len= pack_length();
longlong packed= read_bigendian(ptr, len); longlong packed= read_bigendian(ptr, len);
...@@ -5578,7 +5587,7 @@ bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) ...@@ -5578,7 +5587,7 @@ bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
ltime->time_type= MYSQL_TIMESTAMP_TIME; ltime->time_type= MYSQL_TIMESTAMP_TIME;
ltime->hour+= (ltime->month*32+ltime->day)*24; ltime->hour+= (ltime->month*32+ltime->day)*24;
ltime->month= ltime->day= 0; ltime->month= ltime->day= 0;
return !(fuzzydate & TIME_TIME_ONLY) && (fuzzydate & TIME_NO_ZERO_IN_DATE); return false;
} }
...@@ -5623,6 +5632,8 @@ void Field_timef::store_TIME(MYSQL_TIME *ltime) ...@@ -5623,6 +5632,8 @@ void Field_timef::store_TIME(MYSQL_TIME *ltime)
bool Field_timef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool Field_timef::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ {
if (check_zero_in_date_with_warn(fuzzydate))
return true;
longlong tmp= my_time_packed_from_binary(ptr, dec); longlong tmp= my_time_packed_from_binary(ptr, dec);
TIME_from_longlong_time_packed(ltime, tmp); TIME_from_longlong_time_packed(ltime, tmp);
return false; return false;
......
...@@ -1885,6 +1885,7 @@ protected: ...@@ -1885,6 +1885,7 @@ protected:
virtual void store_TIME(MYSQL_TIME *ltime); virtual void store_TIME(MYSQL_TIME *ltime);
int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str, int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str,
int was_cut, int have_smth_to_conv); int was_cut, int have_smth_to_conv);
bool check_zero_in_date_with_warn(ulonglong fuzzydate);
public: public:
Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg, Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_arg,
uchar null_bit_arg, enum utype unireg_check_arg, uchar null_bit_arg, enum utype unireg_check_arg,
......
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