22 #include <drizzled/function/min_max.h>
23 #include <drizzled/item/cmpfunc.h>
24 #include <drizzled/session.h>
29 void Item_func_min_max::fix_length_and_dec()
32 bool datetime_found=
false;
36 cmp_type=args[0]->result_type();
38 for (uint32_t i=0 ; i < arg_count ; i++)
40 set_if_bigger(max_length, args[i]->max_length);
41 set_if_bigger(decimals, args[i]->decimals);
42 set_if_bigger(max_int_part, args[i]->decimal_int_part());
45 cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
46 if (args[i]->result_type() != ROW_RESULT && args[i]->is_datetime())
49 if (!datetime_item || args[i]->field_type() == DRIZZLE_TYPE_DATETIME)
50 datetime_item= args[i];
53 if (cmp_type == STRING_RESULT)
55 agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
58 compare_as_dates=
true;
61 else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
62 max_length= class_decimal_precision_to_length(max_int_part+decimals, decimals,
86 uint32_t Item_func_min_max::cmp_datetimes(uint64_t *value)
89 uint32_t min_max_idx= 0;
91 for (uint32_t i=0; i < arg_count ; i++)
95 uint64_t res= get_datetime_value(&getSession(), &arg, 0, datetime_item,
99 if (getSession().is_error())
107 if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
116 if (datetime_item->field_type() == DRIZZLE_TYPE_DATE)
126 if (compare_as_dates)
129 uint32_t min_max_idx= cmp_datetimes(NULL);
132 str_res= args[min_max_idx]->
val_str(str);
139 str_res->set_charset(collation.collation);
148 str->set_int(nr, unsigned_flag, &my_charset_bin);
166 str->set_real(nr,decimals,&my_charset_bin);
174 for (uint32_t i=0; i < arg_count ; i++)
181 res2= args[i]->
val_str(res == str ? &tmp_value : str);
184 int cmp= sortcmp(res,res2,collation.collation);
185 if ((cmp_sign < 0 ? cmp : -cmp) < 0)
192 res->set_charset(collation.collation);
210 if (compare_as_dates)
213 (void)cmp_datetimes(&result);
214 return (
double)result;
216 for (uint32_t i=0; i < arg_count ; i++)
223 if (!args[i]->
null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0)
237 if (compare_as_dates)
240 (void)cmp_datetimes(&result);
241 return (int64_t)result;
243 for (uint32_t i=0; i < arg_count ; i++)
249 int64_t tmp=args[i]->
val_int();
250 if (!args[i]->
null_value && (tmp < value ? cmp_sign : -cmp_sign) > 0)
265 if (compare_as_dates)
268 (void)cmp_datetimes(&value);
269 uint64_t2decimal(value, dec);
272 for (uint32_t i=0; i < arg_count ; i++)
284 class_decimal2decimal(tmp, dec);
String * val_str(String *)
virtual int64_t val_int()=0
int class_decimal_cmp(const type::Decimal *a, const type::Decimal *b)
enum_field_types agg_field_type(Item **items, uint32_t nitems)
Aggregates field types from the array of items.
type::Decimal * val_decimal(type::Decimal *)
virtual double val_real()=0
virtual String * val_str(String *str)=0
int class_decimal2string(const type::Decimal *d, uint32_t fixed_dec, String *str)
Converting decimal to string.
virtual type::Decimal * val_decimal(type::Decimal *decimal_buffer)=0