Commit a245543b authored by Alexander Barkov's avatar Alexander Barkov

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

Merging from 10.0 (pre-requisite for  MDEV-5528)
parent cb37c557
......@@ -101,3 +101,16 @@ Warnings:
Warning 1292 Incorrect datetime value: '0000-00-00 00:20:12'
Warning 1292 Truncated incorrect datetime value: '-00:20:12'
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');
INSERT INTO t1 VALUES (NULL, '-00:20:12');
SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM 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,
}
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
Normally we would not consider 'time' as a valid date, but we allow
......@@ -5451,16 +5466,8 @@ String *Field_time::val_str(String *str,
bool Field_time::get_date(MYSQL_TIME *ltime, 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 1;
}
if (check_zero_in_date_with_warn(fuzzydate))
return true;
long tmp=(long) sint3korr(ptr);
ltime->neg=0;
if (tmp < 0)
......@@ -5565,6 +5572,8 @@ double Field_time_with_dec::val_real(void)
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();
longlong packed= read_bigendian(ptr, len);
......@@ -5578,7 +5587,7 @@ bool Field_time_hires::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
ltime->time_type= MYSQL_TIMESTAMP_TIME;
ltime->hour+= (ltime->month*32+ltime->day)*24;
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)
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);
TIME_from_longlong_time_packed(ltime, tmp);
return false;
......
......@@ -1891,6 +1891,7 @@ class Field_time :public Field_temporal {
virtual void store_TIME(MYSQL_TIME *ltime);
int store_TIME_with_warning(MYSQL_TIME *ltime, const ErrConv *str,
int was_cut, int have_smth_to_conv);
bool check_zero_in_date_with_warn(ulonglong fuzzydate);
public:
Field_time(uchar *ptr_arg, uint length_arg, uchar *null_ptr_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