|
This task is self-sufficient change MDEV-16991.
To make the main MDEV-16991 patch simpler, we'll move fractional second truncation from these methods:
Item_time_typecast::get_date()
|
Item_datetime_typecast::get_date()
|
inside new truncating Time and Datetime constructors.
Time(Item *item, const Options opt, uint dec)
|
:Temporal(Time(item, opt))
|
{
|
trunc(dec);
|
}
|
|
Datetime(THD *thd, Item *item, sql_mode_t flags, uint dec)
|
:Temporal_with_date(Datetime(thd, item, flags))
|
{
|
trunc(dec);
|
}
|
Later, in the main patch for MDEV-16991, all truncating Time and Datetime constructors will be fixed to choose between truncation and rounding, according to the current session options. So CAST will automatically start using proper truncation mode.
Additionally, we'll do the following changes:
As a result the get_date() implementations for the affected classes will look as simple as:
bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
|
{
|
Time *tm= new(ltime) Time(args[0], Time::Options_for_cast(),
|
MY_MIN(decimals, TIME_SECOND_PART_DIGITS));
|
return (null_value= !tm->is_valid_time());
|
}
|
|
|
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
|
{
|
fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY;
|
Date *d= new(ltime) Date(current_thd, args[0], fuzzy_date);
|
return (null_value= !d->is_valid_date());
|
}
|
|
|
bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
|
{
|
fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY;
|
Datetime *dt= new(ltime) Datetime(current_thd, args[0], fuzzy_date,
|
MY_MIN(decimals, TIME_SECOND_PART_DIGITS));
|
return (null_value= !dt->is_valid_datetime());
|
}
|
|