1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
22
#include <drizzled/function/min_max.h>
23
23
#include <drizzled/item/cmpfunc.h>
24
#include <drizzled/session.h>
61
62
else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
62
max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals,
63
max_length= class_decimal_precision_to_length(max_int_part+decimals, decimals,
64
65
cached_field_type= agg_field_type(args, arg_count);
79
80
stored to the value pointer, if latter is provided.
82
0 If one of arguments is NULL
83
0 If one of arguments is NULL or there was a execution error
83
84
# index of the least/greatest argument
94
95
bool is_null_unused;
95
96
uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
99
/* Check if we need to stop (because of error or KILL) and stop the loop */
100
if (session->is_error())
97
106
if ((null_value= args[i]->null_value))
99
108
if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
124
133
str_res= args[min_max_idx]->val_str(str);
134
if (args[min_max_idx]->null_value)
136
// check if the call to val_str() above returns a NULL value
125
140
str_res->set_charset(collation.collation);
128
143
switch (cmp_type) {
131
int64_t nr=val_int();
134
str->set_int(nr, unsigned_flag, &my_charset_bin);
146
int64_t nr=val_int();
149
str->set_int(nr, unsigned_flag, &my_charset_bin);
137
153
case DECIMAL_RESULT:
139
my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
142
my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
155
type::Decimal dec_buf, *dec_val= val_decimal(&dec_buf);
158
class_decimal2string(dec_val, 0, str);
145
162
case REAL_RESULT:
147
double nr= val_real();
150
str->set_real(nr,decimals,&my_charset_bin);
164
double nr= val_real();
167
str->set_real(nr,decimals,&my_charset_bin);
153
171
case STRING_RESULT:
157
for (uint32_t i=0; i < arg_count ; i++)
160
res=args[i]->val_str(str);
175
for (uint32_t i=0; i < arg_count ; i++)
164
res2= args[i]->val_str(res == str ? &tmp_value : str);
167
int cmp= sortcmp(res,res2,collation.collation);
168
if ((cmp_sign < 0 ? cmp : -cmp) < 0)
178
res=args[i]->val_str(str);
182
res2= args[i]->val_str(res == str ? &tmp_value : str);
185
int cmp= sortcmp(res,res2,collation.collation);
186
if ((cmp_sign < 0 ? cmp : -cmp) < 0)
190
if ((null_value= args[i]->null_value))
172
if ((null_value= args[i]->null_value))
193
res->set_charset(collation.collation);
175
res->set_charset(collation.collation);
180
198
// This case should never be chosen
184
203
return 0; // Keep compiler happy
242
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
261
type::Decimal *Item_func_min_max::val_decimal(type::Decimal *dec)
244
263
assert(fixed == 1);
245
my_decimal tmp_buf, *tmp, *res= NULL;
264
type::Decimal tmp_buf, *tmp, *res= NULL;
247
266
if (compare_as_dates)
260
279
tmp= args[i]->val_decimal(&tmp_buf); // Zero if NULL
261
if (tmp && (my_decimal_cmp(tmp, res) * cmp_sign) < 0)
280
if (tmp && (class_decimal_cmp(tmp, res) * cmp_sign) < 0)
263
282
if (tmp == &tmp_buf)
265
284
/* Move value out of tmp_buf as this will be reused on next loop */
266
my_decimal2decimal(tmp, dec);
285
class_decimal2decimal(tmp, dec);