summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-09-27 16:38:14 +0400
committerAlexander Barkov <bar@mariadb.com>2018-09-27 16:38:14 +0400
commit492998c0d80aa7d5c4804ac7792a38333e3b83dd (patch)
tree376d323584d3d846bf62d5c50293181af9db9397
parent786940d7e03630d28d82bca4388c937c0d48594a (diff)
downloadmariadb-git-492998c0d80aa7d5c4804ac7792a38333e3b83dd.tar.gz
MDEV-15406 NO_ZERO_IN_DATE erroneously affects how CAST(AS DATE) warns about fractional digit truncation
-rw-r--r--mysql-test/main/func_time.result2
-rw-r--r--mysql-test/main/type_date.result26
-rw-r--r--mysql-test/main/type_date.test19
-rw-r--r--sql/sql_type.cc60
-rw-r--r--sql/sql_type.h4
5 files changed, 63 insertions, 48 deletions
diff --git a/mysql-test/main/func_time.result b/mysql-test/main/func_time.result
index 840db182fe7..cefd0e1f870 100644
--- a/mysql-test/main/func_time.result
+++ b/mysql-test/main/func_time.result
@@ -1105,7 +1105,7 @@ week(20061108), week(20061108.01), week(20061108085411.000002);
isnull(week(now() + 0)) isnull(week(now() + 0.2)) week(20061108) week(20061108.01) week(20061108085411.000002)
0 0 45 45 45
Warnings:
-Warning 1292 Truncated incorrect datetime value: '20061108.01'
+Note 1292 Truncated incorrect datetime value: '20061108.01'
End of 4.1 tests
select time_format('100:00:00', '%H %k %h %I %l');
time_format('100:00:00', '%H %k %h %I %l')
diff --git a/mysql-test/main/type_date.result b/mysql-test/main/type_date.result
index 897f42a2ec4..6d955ef698c 100644
--- a/mysql-test/main/type_date.result
+++ b/mysql-test/main/type_date.result
@@ -962,5 +962,31 @@ Warnings:
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where coalesce(<cache>(DATE'2001-01-02'),`test`.`t1`.`a`) <=> coalesce(DATE'2001-01-01',`test`.`t1`.`a`)
DROP TABLE t1;
#
+# MDEV-15406 NO_ZERO_IN_DATE erroneously affects how CAST(AS DATE) warns about fractional digit truncation
+#
+SET sql_mode='';
+CREATE TABLE t1 (a DATE);
+SELECT CAST(20061108.01 AS DATE);
+CAST(20061108.01 AS DATE)
+2006-11-08
+Warnings:
+Note 1292 Truncated incorrect datetime value: '20061108.01'
+INSERT INTO t1 VALUES (20061108.01);
+Warnings:
+Note 1265 Data truncated for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=NO_ZERO_IN_DATE;
+SELECT CAST(20061108.01 AS DATE);
+CAST(20061108.01 AS DATE)
+2006-11-08
+Warnings:
+Note 1292 Truncated incorrect datetime value: '20061108.01'
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (20061108.01);
+Warnings:
+Note 1265 Data truncated for column 'a' at row 1
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+#
# End of 10.4 tests
#
diff --git a/mysql-test/main/type_date.test b/mysql-test/main/type_date.test
index cbd6cc846aa..f1fd8b302e4 100644
--- a/mysql-test/main/type_date.test
+++ b/mysql-test/main/type_date.test
@@ -646,6 +646,25 @@ EXECUTE IMMEDIATE 'EXPLAIN EXTENDED SELECT * FROM t1 WHERE COALESCE(?,a)<=>COALE
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-15406 NO_ZERO_IN_DATE erroneously affects how CAST(AS DATE) warns about fractional digit truncation
+--echo #
+
+SET sql_mode='';
+CREATE TABLE t1 (a DATE);
+SELECT CAST(20061108.01 AS DATE);
+INSERT INTO t1 VALUES (20061108.01);
+DROP TABLE t1;
+
+SET sql_mode=NO_ZERO_IN_DATE;
+SELECT CAST(20061108.01 AS DATE);
+CREATE TABLE t1 (a DATE);
+INSERT INTO t1 VALUES (20061108.01);
+DROP TABLE t1;
+SET sql_mode=DEFAULT;
+
+
--echo #
--echo # End of 10.4 tests
--echo #
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index e3c854a227f..31a066271db 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -215,60 +215,34 @@ void Sec6::make_truncated_warning(THD *thd, const char *type_str) const
}
-bool Sec6::to_time_with_warn(MYSQL_TIME *to, const ErrConv *str,
- const char *field_name) const
-{
- int was_cut;
- bool res= to_time(to, &was_cut);
- if (res || MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut))
- current_thd->
- push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN,
- res, "time", str->ptr(),
- field_name);
- return res;
-}
-
-
-bool Sec6::to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate,
- const ErrConv *str,
- const char *field_name) const
-{
- bool res, have_warnings= false;
- int was_cut;
- res= to_datetime(to, fuzzydate, &was_cut);
- have_warnings= was_cut && (fuzzydate & TIME_NO_ZERO_IN_DATE);
- if (res || have_warnings)
- current_thd->
- push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN,
- res, "datetime", str->ptr(),
- field_name);
- return res;
-}
-
-
bool Sec6::convert_to_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate,
const ErrConv *str, const char *field_name)
const
{
+ int warn;
bool is_time= fuzzydate & TIME_TIME_ONLY;
+ const char *typestr= is_time ? "time" : "datetime";
+ bool rc= is_time ? to_time(ltime, &warn) :
+ to_datetime(ltime, fuzzydate, &warn);
if (truncated())
{
- /*
- The value was already truncated at the constructor call time,
- and a truncation warning was issued. Here we convert silently
- to avoid double warnings.
- */
+ // The value was already truncated at the constructor call time
current_thd->
push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN,
- !is_time,
- is_time ? "time" : "datetime",
+ !is_time, typestr,
str->ptr(), field_name);
- int warn;
- return is_time ? to_time(ltime, &warn) :
- to_datetime(ltime, fuzzydate, &warn);
}
- return is_time ? to_time_with_warn(ltime, str, field_name) :
- to_datetime_with_warn(ltime, fuzzydate, str, field_name);
+ else if (rc || MYSQL_TIME_WARN_HAVE_WARNINGS(warn))
+ current_thd->
+ push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN,
+ rc, typestr, str->ptr(),
+ field_name);
+ else if (MYSQL_TIME_WARN_HAVE_NOTES(warn))
+ current_thd->
+ push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_NOTE,
+ rc, typestr, str->ptr(),
+ field_name);
+ return rc;
}
diff --git a/sql/sql_type.h b/sql/sql_type.h
index 21704bf9ef0..f48d0c3af51 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -273,8 +273,6 @@ public:
{
return number_to_time(m_neg, m_sec, m_usec, to, warn);
}
- bool to_time_with_warn(MYSQL_TIME *to, const ErrConv *str,
- const char *field_name) const;
/*
Convert a number in format YYYYMMDDhhmmss.ff to
TIMESTAMP'YYYY-MM-DD hh:mm:ss.ff'
@@ -288,8 +286,6 @@ public:
}
return number_to_datetime(m_sec, m_usec, to, flags, warn) == -1;
}
- bool to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate,
- const ErrConv *str, const char *field_name) const;
// Convert elapsed seconds to TIME
bool sec_to_time(MYSQL_TIME *ltime, uint dec) const
{