summaryrefslogtreecommitdiff
path: root/sql/sql_time.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2018-09-28 14:01:17 +0400
committerAlexander Barkov <bar@mariadb.com>2018-09-28 14:01:17 +0400
commitad8e02ac452dc94d64b65cb9855b6dba97b651d4 (patch)
tree7c355aab42a911476eaa10520d1adbabb7091243 /sql/sql_time.cc
parent492998c0d80aa7d5c4804ac7792a38333e3b83dd (diff)
downloadmariadb-git-ad8e02ac452dc94d64b65cb9855b6dba97b651d4.tar.gz
MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type control to "fuzzydate"
Diffstat (limited to 'sql/sql_time.cc')
-rw-r--r--sql/sql_time.cc62
1 files changed, 33 insertions, 29 deletions
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index c3e1b7c28f4..469096ffa52 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -289,14 +289,14 @@ ulong convert_month_to_period(ulong month)
bool
-check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date,
+check_date_with_warn(THD *thd, const MYSQL_TIME *ltime, date_mode_t fuzzydate,
timestamp_type ts_type)
{
int unused;
- if (check_date(ltime, fuzzy_date, &unused))
+ if (check_date(ltime, ulonglong(fuzzydate), &unused))
{
ErrConvTime str(ltime);
- make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN,
+ make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN,
&str, ts_type, 0);
return true;
}
@@ -305,7 +305,7 @@ check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date,
bool
-adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec)
+adjust_time_range_with_warn(THD *thd, MYSQL_TIME *ltime, uint dec)
{
MYSQL_TIME copy= *ltime;
ErrConvTime str(&copy);
@@ -313,7 +313,7 @@ adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec)
if (check_time_range(ltime, dec, &warnings))
return true;
if (warnings)
- current_thd->push_warning_truncated_wrong_value("time", str.ptr());
+ thd->push_warning_truncated_wrong_value("time", str.ptr());
return false;
}
@@ -374,20 +374,20 @@ public:
/* Character set-aware version of str_to_time() */
bool Temporal::str_to_time(MYSQL_TIME_STATUS *status,
const char *str, size_t length, CHARSET_INFO *cs,
- sql_mode_t fuzzydate)
+ date_mode_t fuzzydate)
{
TemporalAsciiBuffer tmp(str, length, cs);
- return ::str_to_time(tmp.str, tmp.length, this, fuzzydate, status);
+ return ::str_to_time(tmp.str, tmp.length, this, ulonglong(fuzzydate), status);
}
/* Character set-aware version of str_to_datetime() */
bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status,
const char *str, size_t length, CHARSET_INFO *cs,
- sql_mode_t flags)
+ date_mode_t flags)
{
TemporalAsciiBuffer tmp(str, length, cs);
- return ::str_to_datetime(tmp.str, tmp.length, this, flags, status);
+ return ::str_to_datetime(tmp.str, tmp.length, this, ulonglong(flags), status);
}
@@ -400,14 +400,14 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status,
*/
bool
-str_to_datetime_with_warn(CHARSET_INFO *cs,
+str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs,
const char *str, size_t length, MYSQL_TIME *l_time,
- ulonglong flags)
+ date_mode_t flags)
{
MYSQL_TIME_STATUS status;
- THD *thd= current_thd;
TemporalAsciiBuffer tmp(str, length, cs);
- bool ret_val= str_to_datetime(tmp.str, tmp.length, l_time, flags, &status);
+ bool ret_val= str_to_datetime(tmp.str, tmp.length, l_time,
+ ulonglong(flags), &status);
if (ret_val || status.warnings)
{
const ErrConvString err(str, length, &my_charset_bin);
@@ -424,28 +424,32 @@ str_to_datetime_with_warn(CHARSET_INFO *cs,
}
-bool double_to_datetime_with_warn(double value, MYSQL_TIME *ltime,
- ulonglong fuzzydate, const char *field_name)
+bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime,
+ date_mode_t fuzzydate, const char *field_name)
{
const ErrConvDouble str(value);
- return Sec6(value).convert_to_mysql_time(ltime, fuzzydate, &str, field_name);
+ return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate,
+ &str, field_name);
}
-bool decimal_to_datetime_with_warn(const my_decimal *value, MYSQL_TIME *ltime,
- ulonglong fuzzydate, const char *field_name)
+bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value,
+ MYSQL_TIME *ltime,
+ date_mode_t fuzzydate, const char *field_name)
{
const ErrConvDecimal str(value);
- return Sec6(value).convert_to_mysql_time(ltime, fuzzydate, &str, field_name);
+ return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate,
+ &str, field_name);
}
-bool int_to_datetime_with_warn(bool neg, ulonglong value, MYSQL_TIME *ltime,
- ulonglong fuzzydate, const char *field_name)
+bool int_to_datetime_with_warn(THD *thd, bool neg, ulonglong value,
+ MYSQL_TIME *ltime,
+ date_mode_t fuzzydate, const char *field_name)
{
const ErrConvInteger str(neg ? - (longlong) value : (longlong) value, !neg);
Sec6 sec(neg, value, 0);
- return sec.convert_to_mysql_time(ltime, fuzzydate, &str, field_name);
+ return sec.convert_to_mysql_time(thd, ltime, fuzzydate, &str, field_name);
}
@@ -902,7 +906,7 @@ void make_truncated_value_warning(THD *thd,
(X)->second_part)
#define GET_PART(X, N) X % N ## LL; X/= N ## LL
-bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
+bool date_add_interval(THD *thd, MYSQL_TIME *ltime, interval_type int_type,
const INTERVAL &interval)
{
long period, sign;
@@ -1017,7 +1021,6 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
invalid_date:
{
- THD *thd= current_thd;
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_DATETIME_FUNCTION_OVERFLOW,
ER_THD(thd, ER_DATETIME_FUNCTION_OVERFLOW),
@@ -1106,7 +1109,7 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
- int l_sign, MYSQL_TIME *l_time3, ulonglong fuzzydate)
+ int l_sign, MYSQL_TIME *l_time3, date_mode_t fuzzydate)
{
ulonglong seconds;
ulong microseconds;
@@ -1323,7 +1326,7 @@ time_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to)
bool
time_to_datetime_with_warn(THD *thd,
const MYSQL_TIME *from, MYSQL_TIME *to,
- ulonglong fuzzydate)
+ date_mode_t fuzzydate)
{
int warn= 0;
DBUG_ASSERT(from->time_type == MYSQL_TIMESTAMP_TIME);
@@ -1336,7 +1339,7 @@ time_to_datetime_with_warn(THD *thd,
*/
if (time_to_datetime(thd, from, to) ||
((thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST) &&
- check_date(to, fuzzydate, &warn)))
+ check_date(to, ulonglong(fuzzydate), &warn)))
{
ErrConvTime str(from);
thd->push_warning_truncated_wrong_value("datetime", str.ptr());
@@ -1389,8 +1392,9 @@ void unpack_time(longlong packed, MYSQL_TIME *my_time,
}
-bool my_decimal::to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate,
+bool my_decimal::to_datetime_with_warn(THD *thd, MYSQL_TIME *to,
+ date_mode_t fuzzydate,
const char *field_name)
{
- return decimal_to_datetime_with_warn(this, to, fuzzydate, field_name);
+ return decimal_to_datetime_with_warn(thd, this, to, fuzzydate, field_name);
}