diff options
author | Monty <monty@mariadb.org> | 2020-08-27 12:24:32 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:27:27 +0200 |
commit | fa7d4abf164b37d0f98012ff7e906ebe7de8f1ed (patch) | |
tree | e351694a4b538ddf42f988d1d1df8f3ff1e3762d /sql/item.h | |
parent | aee84453ab6befef296afdf8e66a8e295b624c72 (diff) | |
download | mariadb-git-fa7d4abf164b37d0f98012ff7e906ebe7de8f1ed.tar.gz |
Added typedef decimal_digits_t (uint16) for number of digits in most
aspects of decimals and integers
For fields and Item's uint8 should be good enough. After
discussions with Alexander Barkov we choose uint16 (for now)
as some format functions may accept +256 digits.
The reason for this patch was to make the usage and storage of decimal
digits simlar. Before this patch decimals was stored/used as uint8,
int and uint. The lengths for numbers where also using a lot of
different types.
Changed most decimal variables and functions to use the new typedef.
squash! af7f09106b6c1dc20ae8c480bff6fd22d266b184
Use decimal_digits_t for all aspects of digits (total, precision
and scale), both for decimals and integers.
Diffstat (limited to 'sql/item.h')
-rw-r--r-- | sql/item.h | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/sql/item.h b/sql/item.h index 061cc9f2e90..22b6aa6656f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1655,19 +1655,19 @@ public: inline uint float_length(uint decimals_par) const { return decimals < FLOATING_POINT_DECIMALS ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} /* Returns total number of decimal digits */ - virtual uint decimal_precision() const + decimal_digits_t decimal_precision() const override { return type_handler()->Item_decimal_precision(this); } /* Returns the number of integer part digits only */ - inline int decimal_int_part() const - { return my_decimal_int_part(decimal_precision(), decimals); } + inline decimal_digits_t decimal_int_part() const + { return (decimal_digits_t) my_decimal_int_part(decimal_precision(), decimals); } /* Returns the number of fractional digits only. NOT_FIXED_DEC is replaced to the maximum possible number of fractional digits, taking into account the data type. */ - uint decimal_scale() const + decimal_digits_t decimal_scale() const { return type_handler()->Item_decimal_scale(this); } @@ -4267,8 +4267,8 @@ public: Item *clone_item(THD *thd) override; void print(String *str, enum_query_type query_type) override; Item *neg(THD *thd) override; - uint decimal_precision() const override - { return (uint) (max_length - MY_TEST(value < 0)); } + decimal_digits_t decimal_precision() const override + { return (decimal_digits_t) (max_length - MY_TEST(value < 0)); } Item *get_copy(THD *thd) override { return get_item_copy<Item_int>(thd, this); } }; @@ -4324,7 +4324,8 @@ public: double val_real() { return ulonglong2double((ulonglong)value); } Item *clone_item(THD *thd); Item *neg(THD *thd); - uint decimal_precision() const { return max_length; } + decimal_digits_t decimal_precision() const override + { return decimal_digits_t(max_length); } Item *get_copy(THD *thd) { return get_item_copy<Item_uint>(thd, this); } }; @@ -4380,7 +4381,8 @@ public: str->append(str_value); } Item *neg(THD *thd) override; - uint decimal_precision() const override { return decimal_value.precision(); } + decimal_digits_t decimal_precision() const override + { return decimal_value.precision(); } void set_decimal_value(my_decimal *value_par); Item *get_copy(THD *thd) override { return get_item_copy<Item_decimal>(thd, this); } @@ -4779,7 +4781,7 @@ public: Item_hex_constant(thd, str, str_length) {} const Type_handler *type_handler() const override { return &type_handler_hex_hybrid; } - uint decimal_precision() const override; + decimal_digits_t decimal_precision() const override; double val_real() override { return (double) (ulonglong) Item_hex_hybrid::val_int(); @@ -4909,7 +4911,7 @@ public: collation= DTCollation_numeric(); decimals= 0; } - Item_temporal_literal(THD *thd, uint dec_arg): + Item_temporal_literal(THD *thd, decimal_digits_t dec_arg): Item_literal(thd) { collation= DTCollation_numeric(); @@ -4997,7 +4999,7 @@ class Item_time_literal: public Item_temporal_literal protected: Time cached_time; public: - Item_time_literal(THD *thd, const Time *ltime, uint dec_arg): + Item_time_literal(THD *thd, const Time *ltime, decimal_digits_t dec_arg): Item_temporal_literal(thd, dec_arg), cached_time(*ltime) { @@ -5045,7 +5047,8 @@ protected: (null_value= cached_time.check_date_with_warn(current_thd)); } public: - Item_datetime_literal(THD *thd, const Datetime *ltime, uint dec_arg): + Item_datetime_literal(THD *thd, const Datetime *ltime, + decimal_digits_t dec_arg): Item_temporal_literal(thd, dec_arg), cached_time(*ltime) { @@ -5138,7 +5141,8 @@ class Item_datetime_literal_for_invalid_dates: public Item_datetime_literal { public: Item_datetime_literal_for_invalid_dates(THD *thd, - const Datetime *ltime, uint dec_arg) + const Datetime *ltime, + decimal_digits_t dec_arg) :Item_datetime_literal(thd, ltime, dec_arg) { maybe_null= false; |