summaryrefslogtreecommitdiff
path: root/sql/sql_time.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_time.cc')
-rw-r--r--sql/sql_time.cc58
1 files changed, 38 insertions, 20 deletions
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index 6f15ada2dcd..f4612ec517e 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -214,6 +214,22 @@ ulong convert_month_to_period(ulong month)
}
+bool
+check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date,
+ timestamp_type ts_type)
+{
+ int unused;
+ if (check_date(ltime, fuzzy_date, &unused))
+ {
+ ErrConvTime str(ltime);
+ make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN,
+ &str, ts_type, 0);
+ return true;
+ }
+ return false;
+}
+
+
/*
Convert a string to 8-bit representation,
for use in str_to_time/str_to_date/str_to_date.
@@ -249,9 +265,9 @@ to_ascii(CHARSET_INFO *cs,
/* Character set-aware version of str_to_time() */
-timestamp_type
+bool
str_to_time(CHARSET_INFO *cs, const char *str,uint length,
- MYSQL_TIME *l_time, ulonglong fuzzydate, int *warning)
+ MYSQL_TIME *l_time, ulonglong fuzzydate, MYSQL_TIME_STATUS *status)
{
char cnv[32];
if ((cs->state & MY_CS_NONASCII) != 0)
@@ -259,14 +275,14 @@ str_to_time(CHARSET_INFO *cs, const char *str,uint length,
length= to_ascii(cs, str, length, cnv, sizeof(cnv));
str= cnv;
}
- return str_to_time(str, length, l_time, fuzzydate, warning);
+ return str_to_time(str, length, l_time, fuzzydate, status);
}
/* Character set-aware version of str_to_datetime() */
-timestamp_type str_to_datetime(CHARSET_INFO *cs,
- const char *str, uint length,
- MYSQL_TIME *l_time, ulonglong flags, int *was_cut)
+bool str_to_datetime(CHARSET_INFO *cs, const char *str, uint length,
+ MYSQL_TIME *l_time, ulonglong flags,
+ MYSQL_TIME_STATUS *status)
{
char cnv[32];
if ((cs->state & MY_CS_NONASCII) != 0)
@@ -274,7 +290,7 @@ timestamp_type str_to_datetime(CHARSET_INFO *cs,
length= to_ascii(cs, str, length, cnv, sizeof(cnv));
str= cnv;
}
- return str_to_datetime(str, length, l_time, flags, was_cut);
+ return str_to_datetime(str, length, l_time, flags, status);
}
@@ -286,21 +302,22 @@ timestamp_type str_to_datetime(CHARSET_INFO *cs,
See description of str_to_datetime() for more information.
*/
-timestamp_type
+bool
str_to_datetime_with_warn(CHARSET_INFO *cs,
const char *str, uint length, MYSQL_TIME *l_time,
ulonglong flags)
{
- int was_cut;
+ MYSQL_TIME_STATUS status;
THD *thd= current_thd;
- timestamp_type ts_type;
-
- ts_type= str_to_datetime(cs, str, length, l_time, flags, &was_cut);
- if (was_cut || ts_type <= MYSQL_TIMESTAMP_ERROR)
+ bool ret_val= str_to_datetime(cs, str, length, l_time, flags, &status);
+ if (ret_val || status.warnings)
make_truncated_value_warning(thd, Sql_condition::WARN_LEVEL_WARN,
str, length, flags & TIME_TIME_ONLY ?
- MYSQL_TIMESTAMP_TIME : ts_type, NullS);
- return ts_type;
+ MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS);
+ DBUG_EXECUTE_IF("str_to_datetime_warn",
+ push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
+ ER_YES, str););
+ return ret_val;
}
@@ -311,7 +328,7 @@ str_to_datetime_with_warn(CHARSET_INFO *cs,
@param nr integer part of the number to convert
@param sec_part microsecond part of the number
@param ltime converted value will be written here
- @param fuzzydate conversion flags (TIME_FUZZY_DATE, etc)
+ @param fuzzydate conversion flags (TIME_INVALID_DATE, etc)
@param str original number, as an ErrConv. For the warning
@param field_name field name or NULL if not a field. For the warning
@@ -328,6 +345,7 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part,
if (fuzzydate & TIME_TIME_ONLY)
{
+ fuzzydate= TIME_TIME_ONLY; // clear other flags
f_type= MYSQL_TYPE_TIME;
res= number_to_time(neg, nr, sec_part, ltime, &was_cut);
}
@@ -337,7 +355,7 @@ static bool number_to_time_with_warn(bool neg, ulonglong nr, ulong sec_part,
res= neg ? -1 : number_to_datetime(nr, sec_part, ltime, fuzzydate, &was_cut);
}
- if (res < 0 || (was_cut && !(fuzzydate & TIME_FUZZY_DATE)))
+ if (res < 0 || (was_cut && (fuzzydate & TIME_NO_ZERO_IN_DATE)))
{
make_truncated_value_warning(current_thd,
Sql_condition::WARN_LEVEL_WARN, str,
@@ -1012,13 +1030,13 @@ calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *s
(uint) l_time2->day);
}
- microseconds= ((longlong)days*LL(86400) +
+ microseconds= ((longlong)days*86400LL +
(longlong)(l_time1->hour*3600L +
l_time1->minute*60L +
l_time1->second) -
l_sign*(longlong)(l_time2->hour*3600L +
l_time2->minute*60L +
- l_time2->second)) * LL(1000000) +
+ l_time2->second)) * 1000000LL +
(longlong)l_time1->second_part -
l_sign*(longlong)l_time2->second_part;
@@ -1050,7 +1068,7 @@ calc_time_diff(MYSQL_TIME *l_time1, MYSQL_TIME *l_time2, int l_sign, longlong *s
*/
-int my_time_compare(MYSQL_TIME *a, MYSQL_TIME *b)
+int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b)
{
ulonglong a_t= pack_time(a);
ulonglong b_t= pack_time(b);