| 90 | */ |
| 91 | |
| 92 | int my_decimal2string(uint mask, const my_decimal *d, |
| 93 | uint fixed_prec, uint fixed_dec, |
| 94 | char filler, String *str) |
| 95 | { |
| 96 | /* |
| 97 | Calculate the size of the string: For DECIMAL(a,b), fixed_prec==a |
| 98 | holds true iff the type is also ZEROFILL, which in turn implies |
| 99 | UNSIGNED. Hence the buffer for a ZEROFILLed value is the length |
| 100 | the user requested, plus one for a possible decimal point, plus |
| 101 | one if the user only wanted decimal places, but we force a leading |
| 102 | zero on them, plus one for the '\0' terminator. Because the type |
| 103 | is implicitly UNSIGNED, we do not need to reserve a character for |
| 104 | the sign. For all other cases, fixed_prec will be 0, and |
| 105 | my_decimal_string_length() will be called instead to calculate the |
| 106 | required size of the buffer. |
| 107 | */ |
| 108 | int length= (fixed_prec |
| 109 | ? (fixed_prec + ((fixed_prec == fixed_dec) ? 1 : 0) + 1 + 1) |
| 110 | : my_decimal_string_length(d)); |
| 111 | int result; |
| 112 | if (str->alloc(length)) |
| 113 | return check_result(mask, E_DEC_OOM); |
| 114 | result= decimal2string((decimal_t*) d, (char*) str->ptr(), |
| 115 | &length, (int)fixed_prec, fixed_dec, |
| 116 | filler); |
| 117 | str->length(length); |
| 118 | str->set_charset(&my_charset_numeric); |
| 119 | return check_result(mask, result); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /** |
no test coverage detected