~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/min_max.cc

  • Committer: Brian Aker
  • Date: 2009-03-25 18:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 963.
  • Revision ID: brian@tangent.org-20090325182415-opf2720c1hidtfgk
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
old lock system).

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
 
94
91
    bool is_null_unused;
95
92
    uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
96
93
                                     &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
 
 
105
94
    if ((null_value= args[i]->null_value))
106
95
      return 0;
107
96
    if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
130
119
    if (null_value)
131
120
      return 0;
132
121
    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
122
    str_res->set_charset(collation.collation);
140
123
    return str_res;
141
124
  }
142
125
  switch (cmp_type) {
143
126
  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
 
 
 
127
  {
 
128
    int64_t nr=val_int();
 
129
    if (null_value)
 
130
      return 0;
 
131
    str->set_int(nr, unsigned_flag, &my_charset_bin);
 
132
    return str;
 
133
  }
152
134
  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
 
 
 
135
  {
 
136
    my_decimal dec_buf, *dec_val= val_decimal(&dec_buf);
 
137
    if (null_value)
 
138
      return 0;
 
139
    my_decimal2string(E_DEC_FATAL_ERROR, dec_val, 0, 0, 0, str);
 
140
    return str;
 
141
  }
161
142
  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
 
 
 
143
  {
 
144
    double nr= val_real();
 
145
    if (null_value)
 
146
      return 0; /* purecov: inspected */
 
147
    str->set_real(nr,decimals,&my_charset_bin);
 
148
    return str;
 
149
  }
170
150
  case STRING_RESULT:
 
151
  {
 
152
    String *res= NULL;
 
153
 
 
154
    for (uint32_t i=0; i < arg_count ; i++)
171
155
    {
172
 
      String *res= NULL;
173
 
 
174
 
      for (uint32_t i=0; i < arg_count ; i++)
 
156
      if (i == 0)
 
157
        res=args[i]->val_str(str);
 
158
      else
175
159
      {
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;
 
160
        String *res2;
 
161
        res2= args[i]->val_str(res == str ? &tmp_value : str);
 
162
        if (res2)
 
163
        {
 
164
          int cmp= sortcmp(res,res2,collation.collation);
 
165
          if ((cmp_sign < 0 ? cmp : -cmp) < 0)
 
166
            res=res2;
 
167
        }
191
168
      }
192
 
      res->set_charset(collation.collation);
193
 
      return res;
 
169
      if ((null_value= args[i]->null_value))
 
170
        return 0;
194
171
    }
195
 
 
 
172
    res->set_charset(collation.collation);
 
173
    return res;
 
174
  }
196
175
  case ROW_RESULT:
 
176
  default:
197
177
    // This case should never be chosen
198
178
    assert(0);
199
179
    return 0;
200
180
  }
201
 
 
202
181
  return 0;                                     // Keep compiler happy
203
182
}
204
183
 
297
276
  return res;
298
277
}
299
278
 
300
 
} /* namespace drizzled */