mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-15406 NO_ZERO_IN_DATE erroneously affects how CAST(AS DATE) warns about fractional digit truncation
This commit is contained in:
@ -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')
|
||||
|
@ -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
|
||||
#
|
||||
|
@ -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 #
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user