Commit 385ee993 authored by Alexander Barkov's avatar Alexander Barkov

A cleanup for MDEV-16852

Changing data types for:
- seconds from longlong to ulonglong
- microseconds from long to ulong
in:
- parameters of calc_time_diff()
- parameters of calc_time_from_sec()
- Members of Sec6_add

This will help to reuse the code easier:
all other functions use ulonglong+long
for seconds/microsecond, e.g.:

- number_to_time()
- number_to_datetime()
- number_to_datetime_with_warn()
- Field_temporal_with_date::store_decimal()
- my_decimal2seconds()
- Item::get_seconds()
parent 9da706fa
......@@ -758,8 +758,8 @@ bool get_next_time(const Time_zone *time_zone, my_time_t *next,
if (seconds)
{
longlong seconds_diff;
long microsec_diff;
ulonglong seconds_diff;
ulong microsec_diff;
bool negative= calc_time_diff(&local_now, &local_start, 1,
&seconds_diff, &microsec_diff);
if (!negative)
......
......@@ -2760,8 +2760,8 @@ longlong Item_func_microsecond::val_int()
longlong Item_func_timestamp_diff::val_int()
{
MYSQL_TIME ltime1, ltime2;
longlong seconds;
long microseconds;
ulonglong seconds;
ulong microseconds;
long months= 0;
int neg= 1;
THD *thd= current_thd;
......@@ -2840,21 +2840,21 @@ longlong Item_func_timestamp_diff::val_int()
case INTERVAL_MONTH:
return months*neg;
case INTERVAL_WEEK:
return seconds / SECONDS_IN_24H / 7L * neg;
return ((longlong) (seconds / SECONDS_IN_24H / 7L)) * neg;
case INTERVAL_DAY:
return seconds / SECONDS_IN_24H * neg;
return ((longlong) (seconds / SECONDS_IN_24H)) * neg;
case INTERVAL_HOUR:
return seconds/3600L*neg;
return ((longlong) (seconds / 3600L)) * neg;
case INTERVAL_MINUTE:
return seconds/60L*neg;
return ((longlong) (seconds / 60L)) * neg;
case INTERVAL_SECOND:
return seconds*neg;
return ((longlong) seconds) * neg;
case INTERVAL_MICROSECOND:
/*
In MySQL difference between any two valid datetime values
in microseconds fits into longlong.
*/
return (seconds*1000000L+microseconds)*neg;
return ((longlong) ((ulonglong) seconds * 1000000L + microseconds)) * neg;
default:
break;
}
......
......@@ -866,10 +866,10 @@ bool Log_to_csv_event_handler::
Open_tables_backup open_tables_backup;
CHARSET_INFO *client_cs= thd->variables.character_set_client;
bool save_time_zone_used;
long query_time= (long) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS);
long lock_time= (long) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS);
long query_time_micro= (long) (query_utime % 1000000);
long lock_time_micro= (long) (lock_utime % 1000000);
ulong query_time= (ulong) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS);
ulong lock_time= (ulong) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS);
ulong query_time_micro= (ulong) (query_utime % 1000000);
ulong lock_time_micro= (ulong) (lock_utime % 1000000);
DBUG_ENTER("Log_to_csv_event_handler::log_slow");
......
......@@ -549,7 +549,7 @@ void localtime_to_TIME(MYSQL_TIME *to, struct tm *from)
}
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds)
void calc_time_from_sec(MYSQL_TIME *to, ulong seconds, ulong microseconds)
{
long t_seconds;
// to->neg is not cleared, it may already be set to a useful value
......@@ -1130,7 +1130,7 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
bool
calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int l_sign, longlong *seconds_out, long *microseconds_out)
int l_sign, ulonglong *seconds_out, ulong *microseconds_out)
{
long days;
bool neg;
......@@ -1172,8 +1172,8 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
microseconds= -microseconds;
neg= 1;
}
*seconds_out= microseconds/1000000L;
*microseconds_out= (long) (microseconds%1000000L);
*seconds_out= (ulonglong) microseconds/1000000L;
*microseconds_out= (ulong) (microseconds%1000000L);
return neg;
}
......@@ -1181,8 +1181,8 @@ 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)
{
longlong seconds;
long microseconds;
ulonglong seconds;
ulong microseconds;
bzero((char *) l_time3, sizeof(*l_time3));
l_time3->neg= calc_time_diff(l_time1, l_time2, l_sign,
&seconds, &microseconds);
......@@ -1201,7 +1201,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
("invalid" means > TIME_MAX_SECOND)
*/
set_if_smaller(seconds, INT_MAX32);
calc_time_from_sec(l_time3, (long) seconds, microseconds);
calc_time_from_sec(l_time3, (ulong) seconds, microseconds);
return ((fuzzydate & TIME_NO_ZERO_DATE) && (seconds == 0) &&
(microseconds == 0));
}
......@@ -1335,8 +1335,8 @@ mix_date_and_time_complex(MYSQL_TIME *ldate, const MYSQL_TIME *ltime)
{
DBUG_ASSERT(ldate->time_type == MYSQL_TIMESTAMP_DATE ||
ldate->time_type == MYSQL_TIMESTAMP_DATETIME);
longlong seconds;
long days, useconds;
ulonglong seconds;
ulong days, useconds;
int sign= ltime->neg ? 1 : -1;
ldate->neg= calc_time_diff(ldate, ltime, sign, &seconds, &useconds);
......
......@@ -141,7 +141,7 @@ bool my_TIME_to_str(const MYSQL_TIME *ltime, String *str, uint dec);
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
const INTERVAL &interval);
bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int l_sign, longlong *seconds_out, long *microseconds_out);
int l_sign, ulonglong *seconds_out, ulong *microseconds_out);
int append_interval(String *str, interval_type int_type,
const INTERVAL &interval);
/**
......@@ -171,7 +171,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b);
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds);
void calc_time_from_sec(MYSQL_TIME *to, ulong seconds, ulong microseconds);
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
int calc_weekday(long daynr,bool sunday_first_day_of_week);
......
......@@ -217,15 +217,15 @@ class VDec2_lazy
*/
class Sec6_add
{
longlong m_sec; // number of seconds
long m_usec; // number of microseconds
ulonglong m_sec; // number of seconds
ulong m_usec; // number of microseconds
bool m_neg; // false if positive, true if negative
bool m_error; // false if the value is OK, true otherwise
void to_hh24mmssff(MYSQL_TIME *ltime, timestamp_type tstype) const
{
bzero(ltime, sizeof(*ltime));
ltime->neg= m_neg;
calc_time_from_sec(ltime, (long) (m_sec % SECONDS_IN_24H), m_usec);
calc_time_from_sec(ltime, (ulong) (m_sec % SECONDS_IN_24H), m_usec);
ltime->time_type= tstype;
}
public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment