55
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
55
precision= class_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
56
56
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
57
57
assert((precision <= DECIMAL_MAX_PRECISION) &&
58
58
(dec <= DECIMAL_MAX_SCALE));
59
bin_size= my_decimal_get_binary_size(precision, dec);
59
bin_size= class_decimal_get_binary_size(precision, dec);
62
62
Field_decimal::Field_decimal(uint32_t len_arg,
77
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
77
precision= class_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
78
78
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
79
79
assert((precision <= DECIMAL_MAX_PRECISION) &&
80
80
(dec <= DECIMAL_MAX_SCALE));
81
bin_size= my_decimal_get_binary_size(precision, dec);
81
bin_size= class_decimal_get_binary_size(precision, dec);
96
96
@param sign sign of value which caused overflow
99
void Field_decimal::set_value_on_overflow(my_decimal *decimal_value,
99
void Field_decimal::set_value_on_overflow(type::Decimal *decimal_value,
102
max_my_decimal(decimal_value, precision, decimals());
102
max_Decimal(decimal_value, precision, decimals());
104
104
decimal_value->sign(true);
114
114
If it does, stores the decimal in the buffer using binary format.
115
115
Otherwise sets maximal number that can be stored in the field.
117
@param decimal_value my_decimal
117
@param decimal_value type::Decimal
125
bool Field_decimal::store_value(const my_decimal *decimal_value)
125
bool Field_decimal::store_value(const type::Decimal *decimal_value)
127
int error= decimal_value->val_binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, ptr, precision, dec);
129
if (warn_if_overflow(my_decimal2binary(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
130
decimal_value, ptr, precision, dec)))
129
if (warn_if_overflow(error))
133
set_value_on_overflow(&buff, decimal_value->sign());
134
my_decimal2binary(E_DEC_FATAL_ERROR, &buff, ptr, precision, dec);
131
if (error != E_DEC_TRUNCATED)
134
set_value_on_overflow(&buff, decimal_value->sign());
135
buff.val_binary(E_DEC_FATAL_ERROR, ptr, precision, dec);
142
145
const CHARSET_INFO * const charset_arg)
145
my_decimal decimal_value;
148
type::Decimal decimal_value;
147
150
ASSERT_COLUMN_MARKED_FOR_WRITE;
149
if ((err= str2my_decimal(E_DEC_FATAL_ERROR &
152
if ((err= decimal_value.store(E_DEC_FATAL_ERROR &
150
153
~(E_DEC_OVERFLOW | E_DEC_BAD_NUM),
151
from, length, charset_arg,
153
table->in_use->abort_on_warning)
154
from, length, charset_arg)) &&
155
getTable()->in_use->abort_on_warning)
155
157
/* Because "from" is not NUL-terminated and we use %s in the ER() */
156
158
String from_as_str;
157
159
from_as_str.copy(from, length, &my_charset_bin);
159
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
161
push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
160
162
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
161
163
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
162
164
"decimal", from_as_str.c_ptr(), field_name,
163
(uint32_t) table->in_use->row_count);
165
(uint32_t) getTable()->in_use->row_count);
180
182
String from_as_str;
181
183
from_as_str.copy(from, length, &my_charset_bin);
183
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
185
push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
184
186
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
185
187
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
186
188
"decimal", from_as_str.c_ptr(), field_name,
187
(uint32_t) table->in_use->row_count);
188
my_decimal_set_zero(&decimal_value);
189
(uint32_t) getTable()->in_use->row_count);
190
decimal_value.set_zero();
201
Fix following when double2my_decimal when double2decimal
203
Fix following when double2_class_decimal when double2decimal
202
204
will return E_DEC_TRUNCATED always correctly
205
207
int Field_decimal::store(double nr)
207
my_decimal decimal_value;
209
type::Decimal decimal_value;
210
212
ASSERT_COLUMN_MARKED_FOR_WRITE;
212
err= double2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
214
err= double2_class_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW, nr,
216
218
if (check_overflow(err))
217
219
set_value_on_overflow(&decimal_value, decimal_value.sign());
218
220
/* Only issue a warning if store_value doesn't issue an warning */
219
table->in_use->got_warning= 0;
221
getTable()->in_use->got_warning= 0;
221
223
if (store_value(&decimal_value))
223
else if (err && !table->in_use->got_warning)
225
else if (err && !getTable()->in_use->got_warning)
224
226
err= warn_if_overflow(err);
229
231
int Field_decimal::store(int64_t nr, bool unsigned_val)
231
my_decimal decimal_value;
233
type::Decimal decimal_value;
234
236
ASSERT_COLUMN_MARKED_FOR_WRITE;
236
if ((err= int2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
238
if ((err= int2_class_decimal(E_DEC_FATAL_ERROR & ~E_DEC_OVERFLOW,
237
239
nr, unsigned_val, &decimal_value)))
239
241
if (check_overflow(err))
240
242
set_value_on_overflow(&decimal_value, decimal_value.sign());
241
243
/* Only issue a warning if store_value doesn't issue an warning */
242
table->in_use->got_warning= 0;
244
getTable()->in_use->got_warning= 0;
244
246
if (store_value(&decimal_value))
246
else if (err && !table->in_use->got_warning)
248
else if (err && not getTable()->in_use->got_warning)
247
249
err= warn_if_overflow(err);
252
int Field_decimal::store_decimal(const my_decimal *decimal_value)
254
int Field_decimal::store_decimal(const type::Decimal *decimal_value)
254
256
return store_value(decimal_value);
258
int Field_decimal::store_time(DRIZZLE_TIME *ltime,
259
enum enum_drizzle_timestamp_type )
260
int Field_decimal::store_time(type::Time *ltime,
261
my_decimal decimal_value;
262
return store_value(date2my_decimal(ltime, &decimal_value));
263
type::Decimal decimal_value;
264
return store_value(date2_class_decimal(ltime, &decimal_value));
266
268
double Field_decimal::val_real(void)
269
my_decimal decimal_value;
271
type::Decimal decimal_value;
271
273
ASSERT_COLUMN_MARKED_FOR_READ;
273
my_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
275
class_decimal2double(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), &dbl);
279
281
int64_t Field_decimal::val_int(void)
282
my_decimal decimal_value;
284
type::Decimal decimal_value;
284
286
ASSERT_COLUMN_MARKED_FOR_READ;
286
my_decimal2int(E_DEC_FATAL_ERROR, val_decimal(&decimal_value), false, &i);
288
val_decimal(&decimal_value)->val_int32(E_DEC_FATAL_ERROR, false, &i);
292
my_decimal* Field_decimal::val_decimal(my_decimal *decimal_value)
294
type::Decimal* Field_decimal::val_decimal(type::Decimal *decimal_value)
294
296
ASSERT_COLUMN_MARKED_FOR_READ;
296
binary2my_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
298
binary2_class_decimal(E_DEC_FATAL_ERROR, ptr, decimal_value,
298
300
return(decimal_value);
302
304
String *Field_decimal::val_str(String *val_buffer,
305
my_decimal decimal_value;
307
type::Decimal decimal_value;
307
309
ASSERT_COLUMN_MARKED_FOR_READ;
309
311
uint32_t fixed_precision= decimal_precision ? precision : 0;
310
my_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
312
class_decimal2string(E_DEC_FATAL_ERROR, val_decimal(&decimal_value),
311
313
fixed_precision, dec, '0', val_buffer);
312
314
return val_buffer;
351
353
uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
352
354
uint32_t const source_decimal= field_metadata & 0x00ff;
353
uint32_t const source_size= my_decimal_get_binary_size(source_precision,
355
uint32_t const source_size= class_decimal_get_binary_size(source_precision,
355
357
return (source_size);
392
394
uint32_t from_precision= (param_data & 0xff00) >> 8U;
393
395
uint32_t from_decimal= param_data & 0x00ff;
394
396
uint32_t length=pack_length();
395
uint32_t from_pack_len= my_decimal_get_binary_size(from_precision, from_decimal);
397
uint32_t from_pack_len= class_decimal_get_binary_size(from_precision, from_decimal);
396
398
uint32_t len= (param_data && (from_pack_len < length)) ?
397
399
from_pack_len : length;
398
400
if ((from_pack_len && (from_pack_len < length)) ||