28
28
extern my_decimal decimal_zero;
30
30
/****************************************************************************
32
****************************************************************************/
34
Field_new_decimal::Field_new_decimal(unsigned char *ptr_arg,
36
unsigned char *null_ptr_arg,
37
unsigned char null_bit_arg,
38
enum utype unireg_check_arg,
39
const char *field_name_arg,
52
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
53
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
54
assert((precision <= DECIMAL_MAX_PRECISION) &&
55
(dec <= DECIMAL_MAX_SCALE));
56
bin_size= my_decimal_get_binary_size(precision, dec);
59
Field_new_decimal::Field_new_decimal(uint32_t len_arg,
64
:Field_num((unsigned char*) 0,
66
maybe_null_arg ? (unsigned char*) "": 0,
74
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
75
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
76
assert((precision <= DECIMAL_MAX_PRECISION) &&
77
(dec <= DECIMAL_MAX_SCALE));
78
bin_size= my_decimal_get_binary_size(precision, dec);
82
int Field_new_decimal::reset(void)
32
****************************************************************************/
34
Field_decimal::Field_decimal(unsigned char *ptr_arg,
36
unsigned char *null_ptr_arg,
37
unsigned char null_bit_arg,
38
enum utype unireg_check_arg,
39
const char *field_name_arg,
52
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
53
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
54
assert((precision <= DECIMAL_MAX_PRECISION) &&
55
(dec <= DECIMAL_MAX_SCALE));
56
bin_size= my_decimal_get_binary_size(precision, dec);
59
Field_decimal::Field_decimal(uint32_t len_arg,
64
:Field_num((unsigned char*) 0,
66
maybe_null_arg ? (unsigned char*) "": 0,
74
precision= my_decimal_length_to_precision(len_arg, dec_arg, unsigned_arg);
75
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION);
76
assert((precision <= DECIMAL_MAX_PRECISION) &&
77
(dec <= DECIMAL_MAX_SCALE));
78
bin_size= my_decimal_get_binary_size(precision, dec);
82
int Field_decimal::reset(void)
84
84
store_value(&decimal_zero);
177
177
String from_as_str;
178
178
from_as_str.copy(from, length, &my_charset_bin);
180
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
181
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
182
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
180
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_WARN,
181
ER_TRUNCATED_WRONG_VALUE_FOR_FIELD,
182
ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD),
183
183
"decimal", from_as_str.c_ptr(), field_name,
184
(uint32_t) table->in_use->row_count);
185
my_decimal_set_zero(&decimal_value);
184
(uint32_t) table->in_use->row_count);
185
my_decimal_set_zero(&decimal_value);
249
int Field_new_decimal::store_decimal(const my_decimal *decimal_value)
249
int Field_decimal::store_decimal(const my_decimal *decimal_value)
251
251
return store_value(decimal_value);
255
int Field_new_decimal::store_time(DRIZZLE_TIME *ltime,
256
enum enum_drizzle_timestamp_type )
255
int Field_decimal::store_time(DRIZZLE_TIME *ltime,
256
enum enum_drizzle_timestamp_type )
258
my_decimal decimal_value;
259
return store_value(date2my_decimal(ltime, &decimal_value));
258
my_decimal decimal_value;
259
return store_value(date2my_decimal(ltime, &decimal_value));
263
double Field_new_decimal::val_real(void)
263
double Field_decimal::val_real(void)
266
266
my_decimal decimal_value;
313
int Field_new_decimal::cmp(const unsigned char *a,const unsigned char*b)
313
int Field_decimal::cmp(const unsigned char *a,const unsigned char*b)
315
315
return memcmp(a, b, bin_size);
319
void Field_new_decimal::sort_string(unsigned char *buff,
319
void Field_decimal::sort_string(unsigned char *buff,
322
322
memcpy(buff, ptr, bin_size);
326
void Field_new_decimal::sql_type(String &str) const
326
void Field_decimal::sql_type(String &str) const
328
328
const CHARSET_INFO * const cs= str.charset();
329
329
str.length(cs->cset->snprintf(cs, (char*) str.ptr(), str.alloced_length(),
335
Save the field metadata for new decimal fields.
337
Saves the precision in the first byte and decimals() in the second
338
byte of the field metadata array at index of *metadata_ptr and
341
@param metadata_ptr First byte of field metadata
343
@returns number of bytes written to metadata_ptr
335
Save the field metadata for new decimal fields.
337
Saves the precision in the first byte and decimals() in the second
338
byte of the field metadata array at index of *metadata_ptr and
341
@param metadata_ptr First byte of field metadata
343
@returns number of bytes written to metadata_ptr
345
int Field_new_decimal::do_save_field_metadata(unsigned char *metadata_ptr)
345
int Field_decimal::do_save_field_metadata(unsigned char *metadata_ptr)
347
347
*metadata_ptr= precision;
348
348
*(metadata_ptr + 1)= decimals();
354
Returns the number of bytes field uses in row-based replication
357
This method is used in row-based replication to determine the number
358
of bytes that the field consumes in the row record format. This is
359
used to skip fields in the master that do not exist on the slave.
361
@param field_metadata Encoded size in field metadata
363
@returns The size of the field based on the field metadata.
354
Returns the number of bytes field uses in row-based replication
357
This method is used in row-based replication to determine the number
358
of bytes that the field consumes in the row record format. This is
359
used to skip fields in the master that do not exist on the slave.
361
@param field_metadata Encoded size in field metadata
363
@returns The size of the field based on the field metadata.
365
uint32_t Field_new_decimal::pack_length_from_metadata(uint32_t field_metadata)
365
uint32_t Field_decimal::pack_length_from_metadata(uint32_t field_metadata)
367
367
uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
368
368
uint32_t const source_decimal= field_metadata & 0x00ff;
369
369
uint32_t const source_size= my_decimal_get_binary_size(source_precision,
371
371
return (source_size);
376
Check to see if field size is compatible with destination.
378
This method is used in row-based replication to verify that the slave's
379
field size is less than or equal to the master's field size. The
380
encoded field metadata (from the master or source) is decoded and compared
381
to the size of this field (the slave or destination).
383
@param field_metadata Encoded size in field metadata
385
@retval 0 if this field's size is < the source field's size
386
@retval 1 if this field's size is >= the source field's size
376
Check to see if field size is compatible with destination.
378
This method is used in row-based replication to verify that the slave's
379
field size is less than or equal to the master's field size. The
380
encoded field metadata (from the master or source) is decoded and compared
381
to the size of this field (the slave or destination).
383
@param field_metadata Encoded size in field metadata
385
@retval 0 if this field's size is < the source field's size
386
@retval 1 if this field's size is >= the source field's size
388
int Field_new_decimal::compatible_field_size(uint32_t field_metadata)
388
int Field_decimal::compatible_field_size(uint32_t field_metadata)
390
390
int compatible= 0;
391
391
uint32_t const source_precision= (field_metadata >> 8U) & 0x00ff;
392
392
uint32_t const source_decimal= field_metadata & 0x00ff;
393
393
uint32_t const source_size= my_decimal_get_binary_size(source_precision,
395
395
uint32_t const destination_size= row_pack_length();
396
396
compatible= (source_size <= destination_size);
398
398
compatible= (source_precision <= precision) &&
399
(source_decimal <= decimals());
399
(source_decimal <= decimals());
400
400
return (compatible);
404
uint32_t Field_new_decimal::is_equal(CreateField *new_field_ptr)
404
uint32_t Field_decimal::is_equal(CreateField *new_field_ptr)
406
406
return ((new_field_ptr->sql_type == real_type()) &&
407
407
((new_field_ptr->flags & UNSIGNED_FLAG) ==
417
Unpack a decimal field from row data.
419
This method is used to unpack a decimal or numeric field from a master
420
whose size of the field is less than that of the slave.
422
@param to Destination of the data
423
@param from Source of the data
424
@param param_data Precision (upper) and decimal (lower) values
426
@return New pointer into memory based on from + length of the data
417
Unpack a decimal field from row data.
419
This method is used to unpack a decimal or numeric field from a master
420
whose size of the field is less than that of the slave.
422
@param to Destination of the data
423
@param from Source of the data
424
@param param_data Precision (upper) and decimal (lower) values
426
@return New pointer into memory based on from + length of the data
428
428
const unsigned char *
429
Field_new_decimal::unpack(unsigned char* to,
430
const unsigned char *from,
429
Field_decimal::unpack(unsigned char* to,
430
const unsigned char *from,
434
434
if (param_data == 0)
435
435
return Field::unpack(to, from, param_data, low_byte_first);
454
454
conv_dec.len= from_precision;
455
455
conv_dec.buf= dec_buf;
457
Note: bin2decimal does not change the length of the field. So it is
458
just the first step the resizing operation. The second step does the
459
resizing using the precision and decimals from the slave.
457
Note: bin2decimal does not change the length of the field. So it is
458
just the first step the resizing operation. The second step does the
459
resizing using the precision and decimals from the slave.
461
461
bin2decimal((unsigned char *)from, &conv_dec, from_precision, from_decimal);
462
462
decimal2bin(&conv_dec, to, precision, decimals());