182
type::Decimal class limits 'decimal_t' type to what we need in MySQL.
187
type Decimal class limits 'decimal_t' type to what we need in MySQL.
184
189
It contains internally all necessary space needed by the instance so
185
190
no extra memory is needed. One should call fix_buffer_pointer() function
186
191
when he moves type::Decimal objects in memory.
189
class Decimal :public decimal_t
194
class Decimal : public decimal_t
196
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH];
191
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH];
197
len= DECIMAL_BUFF_LENGTH;
202
len= DECIMAL_BUFF_LENGTH;
199
204
#if !defined (HAVE_VALGRIND)
200
/* Set buffer to 'random' value to find wrong buffer usage */
201
for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++)
205
/* Set buffer to 'random' value to find wrong buffer usage */
206
for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++)
210
void fix_buffer_pointer() { buf= buffer; }
211
bool sign() const { return decimal_t::sign; }
212
void sign(bool s) { decimal_t::sign= s; }
213
uint32_t precision() const { return intg + frac; }
215
int val_int32(uint32_t mask, bool unsigned_flag, int64_t *l) const
217
type::Decimal rounded;
218
/* decimal_round can return only E_DEC_TRUNCATED */
219
decimal_round(static_cast<const decimal_t*>(this), &rounded, 0, HALF_UP);
220
return check_result(mask, (unsigned_flag ?
221
decimal2uint64_t(&rounded, reinterpret_cast<uint64_t *>(l)) :
222
decimal2int64_t(&rounded, l)));
225
int string_length() const
227
return decimal_string_size(this);
230
int val_binary(uint32_t mask, unsigned char *bin, int prec, int scale) const;
235
decimal_make_zero(static_cast<decimal_t*> (this));
242
return decimal_is_zero(static_cast<const decimal_t*>(this));
246
int store(uint32_t mask, const char *from, uint32_t length, const CHARSET_INFO * charset);
248
int store(uint32_t mask, char *str, char **end)
250
return check_result_and_overflow(mask, string2decimal(str, static_cast<decimal_t*>(this), end));
253
int store(uint32_t mask, const String *str)
255
return store(mask, str->ptr(), str->length(), str->charset());
258
int check_result_and_overflow(uint32_t mask, int result)
260
if (check_result(mask, result) & E_DEC_OVERFLOW)
263
fix_buffer_pointer();
264
max_internal_decimal(this);
215
void fix_buffer_pointer() { buf= buffer; }
216
bool sign() const { return decimal_t::sign; }
217
void sign(bool s) { decimal_t::sign= s; }
218
uint32_t precision() const { return intg + frac; }
220
int val_int32(uint32_t mask, bool unsigned_flag, int64_t *l) const
222
type::Decimal rounded;
223
/* decimal_round can return only E_DEC_TRUNCATED */
224
decimal_round(static_cast<const decimal_t*>(this), &rounded, 0, HALF_UP);
225
return check_result(mask, (unsigned_flag ?
226
decimal2uint64_t(&rounded, reinterpret_cast<uint64_t *>(l)) :
227
decimal2int64_t(&rounded, l)));
230
int string_length() const
232
return decimal_string_size(this);
235
int val_binary(uint32_t mask, unsigned char *bin, int prec, int scale) const;
240
decimal_make_zero(static_cast<decimal_t*> (this));
247
return decimal_is_zero(static_cast<const decimal_t*>(this));
251
int store(uint32_t mask, const char *from, uint32_t length, const CHARSET_INFO * charset);
253
int store(uint32_t mask, char *str, char **end)
255
return check_result_and_overflow(mask, string2decimal(str, static_cast<decimal_t*>(this), end));
258
int store(uint32_t mask, const String *str)
260
return store(mask, str->ptr(), str->length(), str->charset());
263
int check_result_and_overflow(uint32_t mask, int result)
265
if (check_result(mask, result) & E_DEC_OVERFLOW)
268
fix_buffer_pointer();
269
max_internal_decimal(this);
275
void convert(double &value) const;