~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/min_max.cc

  • Committer: Brian Aker
  • Date: 2010-11-30 00:29:39 UTC
  • mto: (1965.2.2 build)
  • mto: This revision was merged to the branch mainline in revision 1966.
  • Revision ID: brian@tangent.org-20101130002939-8bzz3xpa0aapbq2w
Fix sleep() so that a kill command will kill it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    stored to the value pointer, if latter is provided.
80
80
 
81
81
  RETURN
82
 
   0    If one of arguments is NULL or there was a execution error
 
82
   0    If one of arguments is NULL
83
83
   #    index of the least/greatest argument
84
84
*/
85
85
 
94
94
    bool is_null_unused;
95
95
    uint64_t res= get_datetime_value(session, &arg, 0, datetime_item,
96
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
 
 
105
97
    if ((null_value= args[i]->null_value))
106
98
      return 0;
107
99
    if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
130
122
    if (null_value)
131
123
      return 0;
132
124
    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
125
    str_res->set_charset(collation.collation);
140
126
    return str_res;
141
127
  }
142
128
  switch (cmp_type) {
143
129
  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
 
 
 
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
  }
152
137
  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
 
 
 
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
  }
161
145
  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
 
 
 
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
  }
170
153
  case STRING_RESULT:
 
154
  {
 
155
    String *res= NULL;
 
156
 
 
157
    for (uint32_t i=0; i < arg_count ; i++)
171
158
    {
172
 
      String *res= NULL;
173
 
 
174
 
      for (uint32_t i=0; i < arg_count ; i++)
 
159
      if (i == 0)
 
160
        res=args[i]->val_str(str);
 
161
      else
175
162
      {
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;
 
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
        }
191
171
      }
192
 
      res->set_charset(collation.collation);
193
 
      return res;
 
172
      if ((null_value= args[i]->null_value))
 
173
        return 0;
194
174
    }
195
 
 
 
175
    res->set_charset(collation.collation);
 
176
    return res;
 
177
  }
196
178
  case ROW_RESULT:
 
179
  default:
197
180
    // This case should never be chosen
198
181
    assert(0);
199
182
    return 0;
200
183
  }
201
 
 
202
184
  return 0;                                     // Keep compiler happy
203
185
}
204
186