17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
22
22
#include <drizzled/function/min_max.h>
23
23
#include <drizzled/item/cmpfunc.h>
28
25
void Item_func_min_max::fix_length_and_dec()
30
27
int max_int_part=0;
54
51
agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
55
52
if (datetime_found)
57
session= getSessionPtr();
54
session= current_session;
58
55
compare_as_dates= true;
94
91
bool is_null_unused;
95
92
uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
98
/* Check if we need to stop (because of error or KILL) and stop the loop */
99
if (session->is_error())
105
94
if ((null_value= args[i]->null_value))
107
96
if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
132
121
str_res= args[min_max_idx]->val_str(str);
133
if (args[min_max_idx]->null_value)
135
// check if the call to val_str() above returns a NULL value
139
122
str_res->set_charset(collation.collation);
142
125
switch (cmp_type) {
145
int64_t nr=val_int();
148
str->set_int(nr, unsigned_flag, &my_charset_bin);
128
int64_t nr=val_int();
131
str->set_int(nr, unsigned_flag, &my_charset_bin);
152
134
case DECIMAL_RESULT:
154
my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
157
my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
136
my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
139
my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
161
142
case REAL_RESULT:
163
double nr= val_real();
166
str->set_real(nr,decimals,&my_charset_bin);
144
double nr= val_real();
146
return 0; /* purecov: inspected */
147
str->set_real(nr,decimals,&my_charset_bin);
170
150
case STRING_RESULT:
154
for (uint32_t i=0; i < arg_count ; i++)
174
for (uint32_t i=0; i < arg_count ; i++)
157
res=args[i]->val_str(str);
177
res=args[i]->val_str(str);
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)
189
if ((null_value= args[i]->null_value))
161
res2= args[i]->val_str(res == str ? &tmp_value : str);
164
int cmp= sortcmp(res,res2,collation.collation);
165
if ((cmp_sign < 0 ? cmp : -cmp) < 0)
192
res->set_charset(collation.collation);
169
if ((null_value= args[i]->null_value))
172
res->set_charset(collation.collation);
197
177
// This case should never be chosen
202
181
return 0; // Keep compiler happy