MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_decimal2string

Function my_decimal2string

sql/my_decimal.cc:92–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90*/
91
92int 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/**

Callers 8

val_str_asciiMethod · 0.85
val_strMethod · 0.85
str_set_decimalFunction · 0.85
store_decimalMethod · 0.85
val_strMethod · 0.85
printMethod · 0.85
query_val_strMethod · 0.85

Calls 7

my_decimal_string_lengthFunction · 0.85
check_resultFunction · 0.85
decimal2stringFunction · 0.85
allocMethod · 0.45
ptrMethod · 0.45
lengthMethod · 0.45
set_charsetMethod · 0.45

Tested by

no test coverage detected