Skip to content

Commit

Permalink
MDEV-6649 Different warnings for TIME and TIME(N) when @@old_mode=zer…
Browse files Browse the repository at this point in the history
…o_date_time_cast

Merging from 10.0 (pre-requisite for  MDEV-5528)
  • Loading branch information
Alexander Barkov committed Nov 3, 2014
1 parent cb37c55 commit a245543
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
13 changes: 13 additions & 0 deletions mysql-test/r/old-mode.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
9 changes: 9 additions & 0 deletions mysql-test/t/old-mode.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
33 changes: 22 additions & 11 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a245543

Please sign in to comment.