Commit 5a1b9e1d authored by unknown's avatar unknown

More use of new string->number conversion functions

parent e761be55
......@@ -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++;
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment