From 5a1b9e1d05ec4c52e89df1adf40312a55f8b7d3f Mon Sep 17 00:00:00 2001 From: unknown <bar@bar.mysql.r18.ru> Date: Thu, 28 Nov 2002 11:33:04 +0400 Subject: [PATCH] More use of new string->number conversion functions --- sql/field.cc | 26 ++++++-------------------- sql/item_strfunc.cc | 8 ++++---- sql/item_sum.cc | 2 +- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index e0910caeea..f0f3b22f1c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -15,16 +15,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - NOTES: - Some of the number class uses the system functions strtol(), strtoll()... - To avoid patching the end \0 or copying the buffer unnecessary, all calls - to system functions are wrapped to a String object that adds the end null - if it only if it isn't there. - This adds some overhead when assigning numbers from strings but makes - everything simpler. - */ - /***************************************************************************** ** This file implements classes defined in field.h *****************************************************************************/ @@ -1592,7 +1582,6 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) } long tmp; int error= 0; - String tmp_str(from,len,default_charset_info); errno=0; if (unsigned_flag) { @@ -1603,10 +1592,10 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs) error= 1; } else - tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10); + tmp=(long) my_strntoul(cs,from,len,NULL,10); } else - tmp=strtol(tmp_str.c_ptr(),NULL,10); + tmp=my_strntol(cs,from,len,NULL,10); if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; @@ -1837,7 +1826,6 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) len--; from++; } longlong tmp; - String tmp_str(from,len,default_charset_info); int error= 0; errno=0; if (unsigned_flag) @@ -1849,10 +1837,10 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs) error= 1; } else - tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10); + tmp=(longlong) my_strntoull(cs,from,len,NULL,10); } else - tmp=strtoll(tmp_str.c_ptr(),NULL,10); + tmp=my_strntoll(cs,from,len,NULL,10); if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) { current_thd->cuted_fields++; @@ -2052,9 +2040,8 @@ void Field_longlong::sql_type(String &res) const int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) { - String tmp_str(from,len,default_charset_info); errno=0; - Field_float::store(atof(tmp_str.c_ptr())); + Field_float::store(my_strntod(cs,from,len,(char**)NULL)); if (errno || current_thd->count_cuted_fields && !test_if_real(from,len)) { current_thd->cuted_fields++; @@ -2314,10 +2301,9 @@ void Field_float::sql_type(String &res) const int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) { - String tmp_str(from,len,default_charset_info); errno=0; int error= 0; - double j= atof(tmp_str.c_ptr()); + double j= my_strntod(cs,from,len,(char**)0); if (errno || current_thd->count_cuted_fields && !test_if_real(from,len)) { current_thd->cuted_fields++; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index fc3b4da856..d7f70de58f 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -54,14 +54,14 @@ double Item_str_func::val() { String *res; res=val_str(&str_value); - return res ? atof(res->c_ptr()) : 0.0; + return res ? my_strntod(res->charset(),res->ptr(),res->length(),NULL) : 0.0; } longlong Item_str_func::val_int() { String *res; res=val_str(&str_value); - return res ? strtoll(res->c_ptr(),NULL,10) : (longlong) 0; + return res ? my_strntoll(res->charset(),res->ptr(),res->length(),NULL,10) : (longlong) 0; } @@ -1905,9 +1905,9 @@ String *Item_func_conv::val_str(String *str) } null_value=0; if (from_base < 0) - dec= strtoll(res->c_ptr(),&endptr,-from_base); + dec= my_strntoll(res->charset(),res->ptr(),res->length(),&endptr,-from_base); else - dec= (longlong) strtoull(res->c_ptr(),&endptr,from_base); + dec= (longlong) my_strntoull(res->charset(),res->ptr(),res->length(),&endptr,from_base); ptr= longlong2str(dec,ans,to_base); if (str->copy(ans,(uint32) (ptr-ans), thd_charset())) return &empty_string; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 567b5ee6ff..86c94e03ac 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -334,7 +334,7 @@ double Item_sum_hybrid::val() switch (hybrid_type) { case STRING_RESULT: String *res; res=val_str(&str_value); - return res ? atof(res->c_ptr()) : 0.0; + return res ? my_strntod(res->charset(),res->ptr(),res->length(),(char**)0) : 0.0; case INT_RESULT: if (unsigned_flag) return ulonglong2double(sum_int); -- 2.30.9