From e3af3c2127132e327ea8dd21d942ef2e09d7f4d6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 May 2007 12:44:59 +0400 Subject: Fix for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits" When storing a large number to a FLOAT or DOUBLE field with fixed length, it could be incorrectly truncated if the field's length was greater than 31. This patch also does some code cleanups to be able to reuse code which is common between Field_float::store() and Field_double::store(). include/m_string.h: Added declarations for log_10 and log_01 from strtod.c mysql-test/r/type_float.result: Added the testcase for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits" mysql-test/t/type_float.test: Added the testcase for bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits" sql/field.cc: Moved common code from Field_float::store() and Field_double:store() to Field_real::truncate() Fixed the algorithm to not truncate large input numbers if the field length is greater than 31. Fixed rounding to not depend on FLT_MAX/DBL_MAX constants. sql/field.h: Moved not_fixed member from Field_double to Field_real to allow code reuse between Field_float::store() and Field_double::store() Added truncate() method to Field_real which is used by both Field_float and Field_double sql/init.cc: log_10[] and log_01[] are now defined as statical arrays in strtod.c, no need to pre-computed them. sql/item_cmpfunc.cc: log_01[] now starts from 1e0, not from 1e-1 for consistency. sql/mysql_priv.h: Moved log_10[] and log_01[] from mysqld.cc to libmystrings. sql/mysqld.cc: Moved log_10[] and log_01[] from mysqld.cc to libmystrings. strings/strtod.c: Define and use log_10[] and log_01[] as static arrays of constants instead of values pre-computed at startup. --- sql/field.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'sql/field.h') diff --git a/sql/field.h b/sql/field.h index 47f61c1fe8b..f5b38630733 100644 --- a/sql/field.h +++ b/sql/field.h @@ -453,6 +453,7 @@ public: /* base class for float and double and decimal (old one) */ class Field_real :public Field_num { public: + my_bool not_fixed; Field_real(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, utype unireg_check_arg, @@ -460,12 +461,14 @@ public: struct st_table *table_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg) :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, - field_name_arg, table_arg, dec_arg, zero_arg, unsigned_arg) + field_name_arg, table_arg, dec_arg, zero_arg, unsigned_arg), + not_fixed(dec_arg >= NOT_FIXED_DEC) {} int store_decimal(const my_decimal *); my_decimal *val_decimal(my_decimal *); + int truncate(double *nr, double max_length); uint32 max_display_length() { return field_length; } }; @@ -758,7 +761,6 @@ public: class Field_double :public Field_real { public: - my_bool not_fixed; Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, @@ -766,21 +768,18 @@ public: uint8 dec_arg,bool zero_arg,bool unsigned_arg) :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, table_arg, - dec_arg, zero_arg, unsigned_arg), - not_fixed(dec_arg >= NOT_FIXED_DEC) + dec_arg, zero_arg, unsigned_arg) {} Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, struct st_table *table_arg, uint8 dec_arg) :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, - NONE, field_name_arg, table_arg, dec_arg, 0, 0), - not_fixed(dec_arg >= NOT_FIXED_DEC) + NONE, field_name_arg, table_arg, dec_arg, 0, 0) {} Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg, - struct st_table *table_arg, uint8 dec_arg, my_bool not_fixed_srg) + struct st_table *table_arg, uint8 dec_arg, my_bool not_fixed_arg) :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0, - NONE, field_name_arg, table_arg, dec_arg, 0, 0), - not_fixed(not_fixed_srg) - {} + NONE, field_name_arg, table_arg, dec_arg, 0, 0) + {not_fixed= not_fixed_arg; } enum_field_types type() const { return FIELD_TYPE_DOUBLE;} enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; } int store(const char *to,uint length,CHARSET_INFO *charset); -- cgit v1.2.1