summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc38
1 files changed, 20 insertions, 18 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 4b376706500..50b6f4a6b68 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -232,7 +232,7 @@ Item_func::fix_fields(THD *thd, Item **ref)
}
}
fix_length_and_dec();
- if (thd->is_error()) // An error inside fix_length_and_dec occured
+ if (thd->is_error()) // An error inside fix_length_and_dec occurred
return TRUE;
fixed= 1;
return FALSE;
@@ -575,18 +575,19 @@ void Item_udf_func::fix_num_length_and_dec()
@retval False on success, true on error.
*/
-void Item_func::count_datetime_length(Item **item, uint nitems)
+void Item_func::count_datetime_length(enum_field_types field_type_arg,
+ Item **item, uint nitems)
{
unsigned_flag= 0;
decimals= 0;
- if (field_type() != MYSQL_TYPE_DATE)
+ if (field_type_arg != MYSQL_TYPE_DATE)
{
for (uint i= 0; i < nitems; i++)
set_if_bigger(decimals, item[i]->decimals);
}
set_if_smaller(decimals, TIME_SECOND_PART_DIGITS);
uint len= decimals ? (decimals + 1) : 0;
- len+= mysql_temporal_int_part_length(field_type());
+ len+= mysql_temporal_int_part_length(field_type_arg);
fix_char_length(len);
}
@@ -595,16 +596,16 @@ void Item_func::count_datetime_length(Item **item, uint nitems)
result length/precision depends on argument ones.
*/
-void Item_func::count_decimal_length()
+void Item_func::count_decimal_length(Item **item, uint nitems)
{
int max_int_part= 0;
decimals= 0;
unsigned_flag= 1;
- for (uint i=0 ; i < arg_count ; i++)
+ for (uint i=0 ; i < nitems ; i++)
{
- set_if_bigger(decimals, args[i]->decimals);
- set_if_bigger(max_int_part, args[i]->decimal_int_part());
- set_if_smaller(unsigned_flag, args[i]->unsigned_flag);
+ set_if_bigger(decimals, item[i]->decimals);
+ set_if_bigger(max_int_part, item[i]->decimal_int_part());
+ set_if_smaller(unsigned_flag, item[i]->unsigned_flag);
}
int precision= MY_MIN(max_int_part + decimals, DECIMAL_MAX_PRECISION);
fix_char_length(my_decimal_precision_to_length_no_truncation(precision,
@@ -635,19 +636,20 @@ void Item_func::count_only_length(Item **item, uint nitems)
result length/precision depends on argument ones.
*/
-void Item_func::count_real_length()
+void Item_func::count_real_length(Item **items, uint nitems)
{
uint32 length= 0;
decimals= 0;
max_length= 0;
- for (uint i=0 ; i < arg_count ; i++)
+ unsigned_flag= false;
+ for (uint i=0 ; i < nitems ; i++)
{
if (decimals != NOT_FIXED_DEC)
{
- set_if_bigger(decimals, args[i]->decimals);
- set_if_bigger(length, (args[i]->max_length - args[i]->decimals));
+ set_if_bigger(decimals, items[i]->decimals);
+ set_if_bigger(length, (items[i]->max_length - items[i]->decimals));
}
- set_if_bigger(max_length, args[i]->max_length);
+ set_if_bigger(max_length, items[i]->max_length);
}
if (decimals != NOT_FIXED_DEC)
{
@@ -676,11 +678,11 @@ bool Item_func::count_string_result_length(enum_field_types field_type_arg,
if (agg_arg_charsets_for_string_result(collation, items, nitems, 1))
return true;
if (is_temporal_type(field_type_arg))
- count_datetime_length(items, nitems);
+ count_datetime_length(field_type_arg, items, nitems);
else
{
- decimals= NOT_FIXED_DEC;
count_only_length(items, nitems);
+ decimals= max_length ? NOT_FIXED_DEC : 0;
}
return false;
}
@@ -755,7 +757,7 @@ void Item_num_op::fix_length_and_dec(void)
if (r0 == REAL_RESULT || r1 == REAL_RESULT ||
r0 == STRING_RESULT || r1 ==STRING_RESULT)
{
- count_real_length();
+ count_real_length(args, arg_count);
max_length= float_length(decimals);
set_handler_by_result_type(REAL_RESULT);
}
@@ -5613,7 +5615,7 @@ void Item_func_get_user_var::fix_length_and_dec()
/*
If the variable didn't exist it has been created as a STRING-type.
- 'm_var_entry' is NULL only if there occured an error during the call to
+ 'm_var_entry' is NULL only if there occurred an error during the call to
get_var_with_binlog.
*/
if (!error && m_var_entry)