mirror of
https://github.com/MariaDB/server.git
synced 2025-07-14 13:41:20 +03:00
MDEV-12559 Split Item::temporal_precision() into virtual methods in Type_handler
- Adding a new virtual method Type_handler::Item_time_precision() - Adding a new virtual method Type_handler::Item_datetime_precision() - Removing Item::temporal_precision() and adding Item::time_precision() and Item::datetime_precision() instead. - Moving Item_func_convert_tz::fix_length_and_dec() from item_timefunc.cc to item_timefunc.h. It's only two lines, and we're changing it anyway. - Removing Item_temporal_typecast::fix_length_and_dec_generic(), moving this code to Type_handler::Item_{date|time|datetime}_typecast_fix_length_and_dec(). This allows to get rid of one more field_type() call. Also, in the old reduction, Item_date_typecast::fix_length_and_dec() unnecessarily called args[0]->temporal_precision(). The new reduction does not call args[0]->datetime_precision(), as DATE does not have fractional digits.
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include "sql_type.h"
|
||||
#include "sql_const.h"
|
||||
#include "sql_class.h"
|
||||
#include "sql_time.h"
|
||||
#include "item.h"
|
||||
#include "log.h"
|
||||
|
||||
@ -2689,7 +2690,11 @@ bool Type_handler_numeric::
|
||||
bool Type_handler::
|
||||
Item_time_typecast_fix_length_and_dec(Item_time_typecast *item) const
|
||||
{
|
||||
item->fix_length_and_dec_generic(MIN_TIME_WIDTH);
|
||||
uint dec= item->decimals == NOT_FIXED_DEC ?
|
||||
item->arguments()[0]->time_precision() :
|
||||
item->decimals;
|
||||
item->fix_attributes_temporal(MIN_TIME_WIDTH, dec);
|
||||
item->maybe_null= true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2697,7 +2702,8 @@ bool Type_handler::
|
||||
bool Type_handler::
|
||||
Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const
|
||||
{
|
||||
item->fix_length_and_dec_generic(MAX_DATE_WIDTH);
|
||||
item->fix_attributes_temporal(MAX_DATE_WIDTH, 0);
|
||||
item->maybe_null= true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2706,9 +2712,12 @@ bool Type_handler::
|
||||
Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *item)
|
||||
const
|
||||
{
|
||||
item->fix_length_and_dec_generic(MAX_DATETIME_WIDTH);
|
||||
uint dec= item->decimals == NOT_FIXED_DEC ?
|
||||
item->arguments()[0]->datetime_precision() :
|
||||
item->decimals;
|
||||
item->fix_attributes_temporal(MAX_DATETIME_WIDTH, dec);
|
||||
item->maybe_null= true;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -3023,3 +3032,35 @@ bool Type_handler_string_result::
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint Type_handler::Item_time_precision(Item *item) const
|
||||
{
|
||||
return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
|
||||
}
|
||||
|
||||
|
||||
uint Type_handler::Item_datetime_precision(Item *item) const
|
||||
{
|
||||
return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
|
||||
}
|
||||
|
||||
|
||||
uint Type_handler_string_result::Item_temporal_precision(Item *item,
|
||||
bool is_time) const
|
||||
{
|
||||
MYSQL_TIME ltime;
|
||||
StringBuffer<64> buf;
|
||||
String *tmp;
|
||||
MYSQL_TIME_STATUS status;
|
||||
DBUG_ASSERT(item->fixed);
|
||||
if ((tmp= item->val_str(&buf)) &&
|
||||
!(is_time ?
|
||||
str_to_time(tmp->charset(), tmp->ptr(), tmp->length(),
|
||||
<ime, TIME_TIME_ONLY, &status) :
|
||||
str_to_datetime(tmp->charset(), tmp->ptr(), tmp->length(),
|
||||
<ime, TIME_FUZZY_DATES, &status)))
|
||||
return MY_MIN(status.precision, TIME_SECOND_PART_DIGITS);
|
||||
return MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
Reference in New Issue
Block a user