~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/min_max.cc

modified transaction docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
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
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
21
21
 
22
22
#include <drizzled/function/min_max.h>
23
23
#include <drizzled/item/cmpfunc.h>
24
 
#include <drizzled/session.h>
25
24
 
26
25
namespace drizzled
27
26
{
60
59
    }
61
60
  }
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,
64
63
                                            unsigned_flag);
65
64
  cached_field_type= agg_field_type(args, arg_count);
66
65
}
142
141
  }
143
142
  switch (cmp_type) {
144
143
  case INT_RESULT:
145
 
    {
146
 
      int64_t nr=val_int();
147
 
      if (null_value)
148
 
        return 0;
149
 
      str->set_int(nr, unsigned_flag, &my_charset_bin);
150
 
      return str;
151
 
    }
152
 
 
 
144
  {
 
145
    int64_t nr=val_int();
 
146
    if (null_value)
 
147
      return 0;
 
148
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
149
    return str;
 
150
  }
153
151
  case DECIMAL_RESULT:
154
 
    {
155
 
      type::Decimal dec_buf, *dec_val= val_decimal(&dec_buf);
156
 
      if (null_value)
157
 
        return 0;
158
 
      class_decimal2string(dec_val, 0, str);
159
 
      return str;
160
 
    }
161
 
 
 
152
  {
 
153
    my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
 
154
    if (null_value)
 
155
      return 0;
 
156
    my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
 
157
    return str;
 
158
  }
162
159
  case REAL_RESULT:
163
 
    {
164
 
      double nr= val_real();
165
 
      if (null_value)
166
 
        return 0;
167
 
      str->set_real(nr,decimals,&my_charset_bin);
168
 
      return str;
169
 
    }
170
 
 
 
160
  {
 
161
    double nr= val_real();
 
162
    if (null_value)
 
163
      return 0;
 
164
    str->set_real(nr,decimals,&my_charset_bin);
 
165
    return str;
 
166
  }
171
167
  case STRING_RESULT:
 
168
  {
 
169
    String *res= NULL;
 
170
 
 
171
    for (uint32_t i=0; i < arg_count ; i++)
172
172
    {
173
 
      String *res= NULL;
174
 
 
175
 
      for (uint32_t i=0; i < arg_count ; i++)
 
173
      if (i == 0)
 
174
        res=args[i]->val_str(str);
 
175
      else
176
176
      {
177
 
        if (i == 0)
178
 
          res=args[i]->val_str(str);
179
 
        else
180
 
        {
181
 
          String *res2;
182
 
          res2= args[i]->val_str(res == str ? &tmp_value : str);
183
 
          if (res2)
184
 
          {
185
 
            int cmp= sortcmp(res,res2,collation.collation);
186
 
            if ((cmp_sign < 0 ? cmp : -cmp) < 0)
187
 
              res=res2;
188
 
          }
189
 
        }
190
 
        if ((null_value= args[i]->null_value))
191
 
          return 0;
 
177
        String *res2;
 
178
        res2= args[i]->val_str(res == str ? &tmp_value : str);
 
179
        if (res2)
 
180
        {
 
181
          int cmp= sortcmp(res,res2,collation.collation);
 
182
          if ((cmp_sign < 0 ? cmp : -cmp) < 0)
 
183
            res=res2;
 
184
        }
192
185
      }
193
 
      res->set_charset(collation.collation);
194
 
      return res;
 
186
      if ((null_value= args[i]->null_value))
 
187
        return 0;
195
188
    }
196
 
 
 
189
    res->set_charset(collation.collation);
 
190
    return res;
 
191
  }
197
192
  case ROW_RESULT:
 
193
  default:
198
194
    // This case should never be chosen
199
195
    assert(0);
200
196
    return 0;
201
197
  }
202
 
 
203
198
  return 0;                                     // Keep compiler happy
204
199
}
205
200
 
258
253
}
259
254
 
260
255
 
261
 
type::Decimal *Item_func_min_max::val_decimal(type::Decimal *dec)
 
256
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
262
257
{
263
258
  assert(fixed == 1);
264
 
  type::Decimal tmp_buf, *tmp, *res= NULL;
 
259
  my_decimal tmp_buf, *tmp, *res= NULL;
265
260
 
266
261
  if (compare_as_dates)
267
262
  {
277
272
    else
278
273
    {
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)
281
276
      {
282
277
        if (tmp == &tmp_buf)
283
278
        {
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);
286
281
          res= dec;
287
282
        }
288
283
        else