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, Inc.
4
* Copyright (C) 2008 Sun Microsystems
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>
62
61
else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
63
max_length= class_decimal_precision_to_length(max_int_part+decimals, decimals,
62
max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals,
65
64
cached_field_type= agg_field_type(args, arg_count);
143
142
switch (cmp_type) {
146
int64_t nr=val_int();
149
str->set_int(nr, unsigned_flag, &my_charset_bin);
145
int64_t nr=val_int();
148
str->set_int(nr, unsigned_flag, &my_charset_bin);
153
151
case DECIMAL_RESULT:
155
type::Decimal dec_buf, *dec_val= val_decimal(&dec_buf);
158
class_decimal2string(dec_val, 0, str);
153
my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
156
my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
162
159
case REAL_RESULT:
164
double nr= val_real();
167
str->set_real(nr,decimals,&my_charset_bin);
161
double nr= val_real();
164
str->set_real(nr,decimals,&my_charset_bin);
171
167
case STRING_RESULT:
171
for (uint32_t i=0; i < arg_count ; i++)
175
for (uint32_t i=0; i < arg_count ; i++)
174
res=args[i]->val_str(str);
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))
178
res2= args[i]->val_str(res == str ? &tmp_value : str);
181
int cmp= sortcmp(res,res2,collation.collation);
182
if ((cmp_sign < 0 ? cmp : -cmp) < 0)
193
res->set_charset(collation.collation);
186
if ((null_value= args[i]->null_value))
189
res->set_charset(collation.collation);
198
194
// This case should never be chosen
203
198
return 0; // Keep compiler happy
261
type::Decimal *Item_func_min_max::val_decimal(type::Decimal *dec)
256
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
263
258
assert(fixed == 1);
264
type::Decimal tmp_buf, *tmp, *res= NULL;
259
my_decimal tmp_buf, *tmp, *res= NULL;
266
261
if (compare_as_dates)
279
274
tmp= args[i]->val_decimal(&tmp_buf); // Zero if NULL
280
if (tmp && (class_decimal_cmp(tmp, res) * cmp_sign) < 0)
275
if (tmp && (my_decimal_cmp(tmp, res) * cmp_sign) < 0)
282
277
if (tmp == &tmp_buf)
284
279
/* Move value out of tmp_buf as this will be reused on next loop */
285
class_decimal2decimal(tmp, dec);
280
my_decimal2decimal(tmp, dec);