summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2014-11-03 19:05:16 +0400
committerAlexander Barkov <bar@mariadb.org>2014-11-03 19:05:16 +0400
commita245543bc8821b15409b839197d911302fb5bfb0 (patch)
tree94dfc087f1a0f6462742d2cabb42ccdfc6caef2c
parentcb37c557688e2f7f0381d02f78976a1b7d1bfd65 (diff)
downloadmariadb-git-a245543bc8821b15409b839197d911302fb5bfb0.tar.gz
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)
-rw-r--r--mysql-test/r/old-mode.result13
-rw-r--r--mysql-test/t/old-mode.test9
-rw-r--r--sql/field.cc33
-rw-r--r--sql/field.h1
4 files changed, 45 insertions, 11 deletions
diff --git a/mysql-test/r/old-mode.result b/mysql-test/r/old-mode.result
index 7f3339e7ce4..4f650c3c781 100644
--- a/mysql-test/r/old-mode.result
+++ b/mysql-test/r/old-mode.result
@@ -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;
diff --git a/mysql-test/t/old-mode.test b/mysql-test/t/old-mode.test
index 483549886db..c2a43f91ecb 100644
--- a/mysql-test/t/old-mode.test
+++ b/mysql-test/t/old-mode.test
@@ -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;
diff --git a/sql/field.cc b/sql/field.cc
index 103a8920d7e..411f793d613 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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;
diff --git a/sql/field.h b/sql/field.h
index da854968fe6..b4b94bfa712 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1891,6 +1891,7 @@ protected:
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,