~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/min_max.cc

  • Committer: Brian Aker
  • Date: 2009-01-07 09:27:07 UTC
  • Revision ID: brian@tangent.org-20090107092707-bn67qpdllfcyh3j9
Removing dead field translator code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/min_max.h>
23
23
#include <drizzled/item/cmpfunc.h>
24
24
 
25
 
namespace drizzled
26
 
{
27
 
 
28
25
void Item_func_min_max::fix_length_and_dec()
29
26
{
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)
56
53
    {
57
 
      session= getSessionPtr();
 
54
      session= current_session;
58
55
      compare_as_dates= true;
59
56
    }
60
57
  }
79
76
    stored to the value pointer, if latter is provided.
80
77
 
81
78
  RETURN
82
 
   0    If one of arguments is NULL or there was a execution error
 
79
   0    If one of arguments is NULL
83
80
   #    index of the least/greatest argument
84
81
*/
85
82
 
91
88
  for (uint32_t i=0; i < arg_count ; i++)
92
89
  {
93
90
    Item **arg= args + i;
94
 
    bool is_null_unused;
95
 
    uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
96
 
                                     &is_null_unused);
97
 
 
98
 
    /* Check if we need to stop (because of error or KILL)  and stop the loop */
99
 
    if (session->is_error())
100
 
    {
101
 
      null_value= 1;
102
 
      return 0;
103
 
    }
104
 
 
 
91
    bool is_null;
 
92
    uint64_t res= get_datetime_value(session, &arg, 0, datetime_item, &is_null);
105
93
    if ((null_value= args[i]->null_value))
106
94
      return 0;
107
95
    if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
130
118
    if (null_value)
131
119
      return 0;
132
120
    str_res= args[min_max_idx]->val_str(str);
133
 
    if (args[min_max_idx]->null_value)
134
 
    {
135
 
      // check if the call to val_str() above returns a NULL value
136
 
      null_value= 1;
137
 
      return NULL;
138
 
    }
139
121
    str_res->set_charset(collation.collation);
140
122
    return str_res;
141
123
  }
142
124
  switch (cmp_type) {
143
125
  case INT_RESULT:
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
 
    }
151
 
 
 
126
  {
 
127
    int64_t nr=val_int();
 
128
    if (null_value)
 
129
      return 0;
 
130
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
131
    return str;
 
132
  }
152
133
  case DECIMAL_RESULT:
153
 
    {
154
 
      my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
155
 
      if (null_value)
156
 
        return 0;
157
 
      my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
158
 
      return str;
159
 
    }
160
 
 
 
134
  {
 
135
    my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
 
136
    if (null_value)
 
137
      return 0;
 
138
    my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
 
139
    return str;
 
140
  }
161
141
  case REAL_RESULT:
162
 
    {
163
 
      double nr= val_real();
164
 
      if (null_value)
165
 
        return 0;
166
 
      str->set_real(nr,decimals,&my_charset_bin);
167
 
      return str;
168
 
    }
169
 
 
 
142
  {
 
143
    double nr= val_real();
 
144
    if (null_value)
 
145
      return 0; /* purecov: inspected */
 
146
    str->set_real(nr,decimals,&my_charset_bin);
 
147
    return str;
 
148
  }
170
149
  case STRING_RESULT:
 
150
  {
 
151
    String *res= NULL;
 
152
 
 
153
    for (uint32_t i=0; i < arg_count ; i++)
171
154
    {
172
 
      String *res= NULL;
173
 
 
174
 
      for (uint32_t i=0; i < arg_count ; i++)
 
155
      if (i == 0)
 
156
        res=args[i]->val_str(str);
 
157
      else
175
158
      {
176
 
        if (i == 0)
177
 
          res=args[i]->val_str(str);
178
 
        else
179
 
        {
180
 
          String *res2;
181
 
          res2= args[i]->val_str(res == str ? &tmp_value : str);
182
 
          if (res2)
183
 
          {
184
 
            int cmp= sortcmp(res,res2,collation.collation);
185
 
            if ((cmp_sign < 0 ? cmp : -cmp) < 0)
186
 
              res=res2;
187
 
          }
188
 
        }
189
 
        if ((null_value= args[i]->null_value))
190
 
          return 0;
 
159
        String *res2;
 
160
        res2= args[i]->val_str(res == str ? &tmp_value : str);
 
161
        if (res2)
 
162
        {
 
163
          int cmp= sortcmp(res,res2,collation.collation);
 
164
          if ((cmp_sign < 0 ? cmp : -cmp) < 0)
 
165
            res=res2;
 
166
        }
191
167
      }
192
 
      res->set_charset(collation.collation);
193
 
      return res;
 
168
      if ((null_value= args[i]->null_value))
 
169
        return 0;
194
170
    }
195
 
 
 
171
    res->set_charset(collation.collation);
 
172
    return res;
 
173
  }
196
174
  case ROW_RESULT:
 
175
  default:
197
176
    // This case should never be chosen
198
177
    assert(0);
199
178
    return 0;
200
179
  }
201
 
 
202
180
  return 0;                                     // Keep compiler happy
203
181
}
204
182
 
297
275
  return res;
298
276
}
299
277
 
300
 
} /* namespace drizzled */