~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item_func.cc

code clean move Item_decimal_typecast to functions directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
}
152
152
 
153
153
 
154
 
String *Item_decimal_typecast::val_str(String *str)
155
 
{
156
 
  my_decimal tmp_buf, *tmp= val_decimal(&tmp_buf);
157
 
  if (null_value)
158
 
    return NULL;
159
 
  my_decimal2string(E_DEC_FATAL_ERROR, tmp, 0, 0, 0, str);
160
 
  return str;
161
 
}
162
 
 
163
 
 
164
 
double Item_decimal_typecast::val_real()
165
 
{
166
 
  my_decimal tmp_buf, *tmp= val_decimal(&tmp_buf);
167
 
  double res;
168
 
  if (null_value)
169
 
    return 0.0;
170
 
  my_decimal2double(E_DEC_FATAL_ERROR, tmp, &res);
171
 
  return res;
172
 
}
173
 
 
174
 
 
175
 
int64_t Item_decimal_typecast::val_int()
176
 
{
177
 
  my_decimal tmp_buf, *tmp= val_decimal(&tmp_buf);
178
 
  int64_t res;
179
 
  if (null_value)
180
 
    return 0;
181
 
  my_decimal2int(E_DEC_FATAL_ERROR, tmp, unsigned_flag, &res);
182
 
  return res;
183
 
}
184
 
 
185
 
 
186
 
my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec)
187
 
{
188
 
  my_decimal tmp_buf, *tmp= args[0]->val_decimal(&tmp_buf);
189
 
  bool sign;
190
 
  uint32_t precision;
191
 
 
192
 
  if ((null_value= args[0]->null_value))
193
 
    return NULL;
194
 
  my_decimal_round(E_DEC_FATAL_ERROR, tmp, decimals, false, dec);
195
 
  sign= dec->sign();
196
 
  if (unsigned_flag)
197
 
  {
198
 
    if (sign)
199
 
    {
200
 
      my_decimal_set_zero(dec);
201
 
      goto err;
202
 
    }
203
 
  }
204
 
  precision= my_decimal_length_to_precision(max_length,
205
 
                                            decimals, unsigned_flag);
206
 
  if (precision - decimals < (uint) my_decimal_intg(dec))
207
 
  {
208
 
    max_my_decimal(dec, precision, decimals);
209
 
    dec->sign(sign);
210
 
    goto err;
211
 
  }
212
 
  return dec;
213
 
 
214
 
err:
215
 
  push_warning_printf(current_thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
216
 
                      ER_WARN_DATA_OUT_OF_RANGE,
217
 
                      ER(ER_WARN_DATA_OUT_OF_RANGE),
218
 
                      name, 1);
219
 
  return dec;
220
 
}
221
 
 
222
 
 
223
 
void Item_decimal_typecast::print(String *str, enum_query_type query_type)
224
 
{
225
 
  char len_buf[20*3 + 1];
226
 
  char *end;
227
 
 
228
 
  uint32_t precision= my_decimal_length_to_precision(max_length, decimals,
229
 
                                                 unsigned_flag);
230
 
  str->append(STRING_WITH_LEN("cast("));
231
 
  args[0]->print(str, query_type);
232
 
  str->append(STRING_WITH_LEN(" as decimal("));
233
 
 
234
 
  end=int10_to_str(precision, len_buf,10);
235
 
  str->append(len_buf, (uint32_t) (end - len_buf));
236
 
 
237
 
  str->append(',');
238
 
 
239
 
  end=int10_to_str(decimals, len_buf,10);
240
 
  str->append(len_buf, (uint32_t) (end - len_buf));
241
 
 
242
 
  str->append(')');
243
 
  str->append(')');
244
 
}
245
 
 
246
 
 
247
154
double Item_func_plus::real_op()
248
155
{
249
156
  double value= args[0]->val_real() + args[1]->val_real();