~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/min_max.cc

  • Committer: Stewart Smith
  • Date: 2010-11-07 04:22:31 UTC
  • mto: (1911.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: stewart@flamingspork.com-20101107042231-ola4sl7j0qvg58tz
fix ARCHIVE storage engine calling exit (lintian warning). Was because we were linking in libinternal into libazio, which links into archive plugin. Just link libinternal into the command line utilities.

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
}
80
79
    stored to the value pointer, if latter is provided.
81
80
 
82
81
  RETURN
83
 
   0    If one of arguments is NULL or there was a execution error
 
82
   0    If one of arguments is NULL
84
83
   #    index of the least/greatest argument
85
84
*/
86
85
 
95
94
    bool is_null_unused;
96
95
    uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
97
96
                                     &is_null_unused);
98
 
 
99
 
    /* Check if we need to stop (because of error or KILL)  and stop the loop */
100
 
    if (session->is_error())
101
 
    {
102
 
      null_value= 1;
103
 
      return 0;
104
 
    }
105
 
 
106
97
    if ((null_value= args[i]->null_value))
107
98
      return 0;
108
99
    if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
131
122
    if (null_value)
132
123
      return 0;
133
124
    str_res= args[min_max_idx]->val_str(str);
134
 
    if (args[min_max_idx]->null_value)
135
 
    {
136
 
      // check if the call to val_str() above returns a NULL value
137
 
      null_value= 1;
138
 
      return NULL;
139
 
    }
140
125
    str_res->set_charset(collation.collation);
141
126
    return str_res;
142
127
  }
143
128
  switch (cmp_type) {
144
129
  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
 
 
 
130
  {
 
131
    int64_t nr=val_int();
 
132
    if (null_value)
 
133
      return 0;
 
134
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
135
    return str;
 
136
  }
153
137
  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
 
 
 
138
  {
 
139
    my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
 
140
    if (null_value)
 
141
      return 0;
 
142
    my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
 
143
    return str;
 
144
  }
162
145
  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
 
 
 
146
  {
 
147
    double nr= val_real();
 
148
    if (null_value)
 
149
      return 0;
 
150
    str->set_real(nr,decimals,&my_charset_bin);
 
151
    return str;
 
152
  }
171
153
  case STRING_RESULT:
 
154
  {
 
155
    String *res= NULL;
 
156
 
 
157
    for (uint32_t i=0; i < arg_count ; i++)
172
158
    {
173
 
      String *res= NULL;
174
 
 
175
 
      for (uint32_t i=0; i < arg_count ; i++)
 
159
      if (i == 0)
 
160
        res=args[i]->val_str(str);
 
161
      else
176
162
      {
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;
 
163
        String *res2;
 
164
        res2= args[i]->val_str(res == str ? &tmp_value : str);
 
165
        if (res2)
 
166
        {
 
167
          int cmp= sortcmp(res,res2,collation.collation);
 
168
          if ((cmp_sign < 0 ? cmp : -cmp) < 0)
 
169
            res=res2;
 
170
        }
192
171
      }
193
 
      res->set_charset(collation.collation);
194
 
      return res;
 
172
      if ((null_value= args[i]->null_value))
 
173
        return 0;
195
174
    }
196
 
 
 
175
    res->set_charset(collation.collation);
 
176
    return res;
 
177
  }
197
178
  case ROW_RESULT:
 
179
  default:
198
180
    // This case should never be chosen
199
181
    assert(0);
200
182
    return 0;
201
183
  }
202
 
 
203
184
  return 0;                                     // Keep compiler happy
204
185
}
205
186
 
258
239
}
259
240
 
260
241
 
261
 
type::Decimal *Item_func_min_max::val_decimal(type::Decimal *dec)
 
242
my_decimal *Item_func_min_max::val_decimal(my_decimal *dec)
262
243
{
263
244
  assert(fixed == 1);
264
 
  type::Decimal tmp_buf, *tmp, *res= NULL;
 
245
  my_decimal tmp_buf, *tmp, *res= NULL;
265
246
 
266
247
  if (compare_as_dates)
267
248
  {
277
258
    else
278
259
    {
279
260
      tmp= args[i]->val_decimal(&tmp_buf);      // Zero if NULL
280
 
      if (tmp && (class_decimal_cmp(tmp, res) * cmp_sign) < 0)
 
261
      if (tmp && (my_decimal_cmp(tmp, res) * cmp_sign) < 0)
281
262
      {
282
263
        if (tmp == &tmp_buf)
283
264
        {
284
265
          /* Move value out of tmp_buf as this will be reused on next loop */
285
 
          class_decimal2decimal(tmp, dec);
 
266
          my_decimal2decimal(tmp, dec);
286
267
          res= dec;
287
268
        }
288
269
        else