52
String *Item_real_func::val_str(String *str)
55
double nr= val_real();
57
return 0; /* purecov: inspected */
58
str->set_real(nr,decimals, &my_charset_bin);
63
my_decimal *Item_real_func::val_decimal(my_decimal *decimal_value)
66
double nr= val_real();
68
return 0; /* purecov: inspected */
69
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
74
51
void Item_func::fix_num_length_and_dec()
76
53
uint32_t fl_length= 0;
201
Check arguments here to determine result's type for a numeric
202
function of two arguments.
205
void Item_num_op::find_num_type(void)
207
assert(arg_count == 2);
208
Item_result r0= args[0]->result_type();
209
Item_result r1= args[1]->result_type();
211
if (r0 == REAL_RESULT || r1 == REAL_RESULT ||
212
r0 == STRING_RESULT || r1 ==STRING_RESULT)
215
max_length= float_length(decimals);
216
hybrid_type= REAL_RESULT;
218
else if (r0 == DECIMAL_RESULT || r1 == DECIMAL_RESULT)
220
hybrid_type= DECIMAL_RESULT;
225
assert(r0 == INT_RESULT && r1 == INT_RESULT);
227
hybrid_type=INT_RESULT;
235
173
Set result type for a numeric function of one argument
236
174
(can be also used by a numeric function of many arguments, if the result
237
175
type depends only on the first argument)
267
void Item_func_numhybrid::fix_length_and_dec()
269
fix_num_length_and_dec();
274
String *Item_func_numhybrid::val_str(String *str)
277
switch (hybrid_type) {
280
my_decimal decimal_value, *val;
281
if (!(val= decimal_op(&decimal_value)))
282
return 0; // null is set
283
my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
284
my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
289
int64_t nr= int_op();
291
return 0; /* purecov: inspected */
292
str->set_int(nr, unsigned_flag, &my_charset_bin);
297
double nr= real_op();
299
return 0; /* purecov: inspected */
300
str->set_real(nr,decimals,&my_charset_bin);
304
return str_op(&str_value);
312
double Item_func_numhybrid::val_real()
315
switch (hybrid_type) {
318
my_decimal decimal_value, *val;
320
if (!(val= decimal_op(&decimal_value)))
321
return 0.0; // null is set
322
my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
327
int64_t result= int_op();
328
return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
336
String *res= str_op(&str_value);
337
return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
338
&end_not_used, &err_not_used) : 0.0);
347
int64_t Item_func_numhybrid::val_int()
350
switch (hybrid_type) {
353
my_decimal decimal_value, *val;
354
if (!(val= decimal_op(&decimal_value)))
355
return 0; // null is set
357
my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
363
return (int64_t) rint(real_op());
368
if (!(res= str_op(&str_value)))
371
char *end= (char*) res->ptr() + res->length();
372
const CHARSET_INFO * const cs= str_value.charset();
373
return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
382
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
384
my_decimal *val= decimal_value;
386
switch (hybrid_type) {
388
val= decimal_op(decimal_value);
392
int64_t result= int_op();
393
int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
398
double result= (double)real_op();
399
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
405
if (!(res= str_op(&str_value)))
408
str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
409
res->length(), res->charset(), decimal_value);
420
205
void Item_func_signed::print(String *str, enum_query_type query_type)
422
207
str->append(STRING_WITH_LEN("cast("));