diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/sql/field.cc b/sql/field.cc index bbb91fc534d..5356fbc773a 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1753,7 +1753,7 @@ void Field_medium::sql_type(String &res) const int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) { long tmp; - int error= 0, cuted_fields= 0; + int error= 0; char *end; tmp= cs->cset->scan(cs, from, from+len, MY_SEQ_SPACES); @@ -1781,7 +1781,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) #if SIZEOF_LONG > 4 if (unsigned_flag) { - if (tmp > UINT_MAX32) + if ((ulong) tmp > UINT_MAX32) { tmp= UINT_MAX32; error= 1; @@ -4277,27 +4277,17 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs) int Field_str::store(double nr) { - bool use_scientific_notation=TRUE; char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; uint length; - if (field_length < 32 && nr > 1) // TODO: negative numbers - { - if (ceiling == 0) - { - static double e[]= {1e1, 1e2, 1e4, 1e8, 1e16 }; - double p= 1; - for (int i= sizeof(e)/sizeof(e[0]), j= 1<<i ; j; i--, j>>= 1 ) - { - if (field_length & j) - p*= e[i]; - } - ceiling= p-1; - } - use_scientific_notation= (ceiling < nr); - } - length= (uint)sprintf(buff, "%-.*g", - use_scientific_notation ? max(0,(int)field_length-5) : field_length, - nr); + bool use_scientific_notation= TRUE; + use_scientific_notation= TRUE; +if (field_length < 32 && fabs(nr) < log_10[field_length]-1) + use_scientific_notation= FALSE; + length= (uint) my_sprintf(buff, (buff, "%-.*g", + (use_scientific_notation ? + max(0, (int)field_length-5) : + field_length), + nr)); /* +1 below is because "precision" in %g above means the max. number of significant digits, not the output width. @@ -4310,6 +4300,7 @@ int Field_str::store(double nr) return store((const char *)buff, min(length, field_length), charset()); } + int Field_string::store(longlong nr) { char buff[64]; @@ -4403,9 +4394,8 @@ char *Field_string::pack(char *to, const char *from, uint max_length) char *Field_string::pack_key(char *to, const char *from, uint max_length) { - int length=min(field_length,max_length); - uint char_length= (field_charset->mbmaxlen > 1) ? - max_length/field_charset->mbmaxlen : max_length; + uint length= min(field_length,max_length); + uint char_length= max_length/field_charset->mbmaxlen; if (length > char_length) char_length= my_charpos(field_charset, from, from+length, char_length); set_if_smaller(length, char_length); |