mirror of
https://github.com/MariaDB/server.git
synced 2025-07-17 12:02:09 +03:00
Preparation to charset dependant test_if_int and test_if_real
This commit is contained in:
52
sql/field.cc
52
sql/field.cc
@ -70,12 +70,14 @@ void Field_num::prepend_zeros(String *value)
|
|||||||
This is only used to give warnings in ALTER TABLE or LOAD DATA...
|
This is only used to give warnings in ALTER TABLE or LOAD DATA...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool test_if_int(const char *str,int length)
|
bool test_if_int(const char *str,int length, CHARSET_INFO *cs)
|
||||||
{
|
{
|
||||||
const char *end=str+length;
|
const char *end=str+length;
|
||||||
|
|
||||||
|
cs=system_charset_info; // QQ move test_if_int into CHARSET_INFO struct
|
||||||
|
|
||||||
// Allow start space
|
// Allow start space
|
||||||
while (str != end && my_isspace(system_charset_info,*str))
|
while (str != end && my_isspace(cs,*str))
|
||||||
str++; /* purecov: inspected */
|
str++; /* purecov: inspected */
|
||||||
if (str != end && (*str == '-' || *str == '+'))
|
if (str != end && (*str == '-' || *str == '+'))
|
||||||
str++;
|
str++;
|
||||||
@ -83,7 +85,7 @@ bool test_if_int(const char *str,int length)
|
|||||||
return 0; // Error: Empty string
|
return 0; // Error: Empty string
|
||||||
for (; str != end ; str++)
|
for (; str != end ; str++)
|
||||||
{
|
{
|
||||||
if (!my_isdigit(system_charset_info,*str))
|
if (!my_isdigit(cs,*str))
|
||||||
{
|
{
|
||||||
if (*str == '.')
|
if (*str == '.')
|
||||||
{ // Allow '.0000'
|
{ // Allow '.0000'
|
||||||
@ -91,10 +93,10 @@ bool test_if_int(const char *str,int length)
|
|||||||
if (str == end)
|
if (str == end)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!my_isspace(system_charset_info,*str))
|
if (!my_isspace(cs,*str))
|
||||||
return 0;
|
return 0;
|
||||||
for (str++ ; str != end ; str++)
|
for (str++ ; str != end ; str++)
|
||||||
if (!my_isspace(system_charset_info,*str))
|
if (!my_isspace(cs,*str))
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -103,9 +105,11 @@ bool test_if_int(const char *str,int length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool test_if_real(const char *str,int length)
|
static bool test_if_real(const char *str,int length, CHARSET_INFO *cs)
|
||||||
{
|
{
|
||||||
while (length && my_isspace(system_charset_info,*str))
|
cs=system_charset_info; // QQ move test_if_int into CHARSET_INFO struct
|
||||||
|
|
||||||
|
while (length && my_isspace(cs,*str))
|
||||||
{ // Allow start space
|
{ // Allow start space
|
||||||
length--; str++;
|
length--; str++;
|
||||||
}
|
}
|
||||||
@ -114,10 +118,10 @@ static bool test_if_real(const char *str,int length)
|
|||||||
if (*str == '+' || *str == '-')
|
if (*str == '+' || *str == '-')
|
||||||
{
|
{
|
||||||
length--; str++;
|
length--; str++;
|
||||||
if (!length || !(my_isdigit(system_charset_info,*str) || *str == '.'))
|
if (!length || !(my_isdigit(cs,*str) || *str == '.'))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
while (length && my_isdigit(system_charset_info,*str))
|
while (length && my_isdigit(cs,*str))
|
||||||
{
|
{
|
||||||
length--; str++;
|
length--; str++;
|
||||||
}
|
}
|
||||||
@ -126,7 +130,7 @@ static bool test_if_real(const char *str,int length)
|
|||||||
if (*str == '.')
|
if (*str == '.')
|
||||||
{
|
{
|
||||||
length--; str++;
|
length--; str++;
|
||||||
while (length && my_isdigit(system_charset_info,*str))
|
while (length && my_isdigit(cs,*str))
|
||||||
{
|
{
|
||||||
length--; str++;
|
length--; str++;
|
||||||
}
|
}
|
||||||
@ -136,18 +140,18 @@ static bool test_if_real(const char *str,int length)
|
|||||||
if (*str == 'E' || *str == 'e')
|
if (*str == 'E' || *str == 'e')
|
||||||
{
|
{
|
||||||
if (length < 3 || (str[1] != '+' && str[1] != '-') ||
|
if (length < 3 || (str[1] != '+' && str[1] != '-') ||
|
||||||
!my_isdigit(system_charset_info,str[2]))
|
!my_isdigit(cs,str[2]))
|
||||||
return 0;
|
return 0;
|
||||||
length-=3;
|
length-=3;
|
||||||
str+=3;
|
str+=3;
|
||||||
while (length && my_isdigit(system_charset_info,*str))
|
while (length && my_isdigit(cs,*str))
|
||||||
{
|
{
|
||||||
length--; str++;
|
length--; str++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; length ; length--, str++)
|
for (; length ; length--, str++)
|
||||||
{ // Allow end space
|
{ // Allow end space
|
||||||
if (!my_isspace(system_charset_info,*str))
|
if (!my_isspace(cs,*str))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -923,7 +927,7 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -943,7 +947,7 @@ int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1119,7 +1123,7 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1139,7 +1143,7 @@ int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1384,7 +1388,7 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1404,7 +1408,7 @@ int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1601,7 +1605,7 @@ int Field_long::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
tmp=my_strntol(cs,from,len,&end,10);
|
tmp=my_strntol(cs,from,len,&end,10);
|
||||||
if (errno ||
|
if (errno ||
|
||||||
(from+len != end && current_thd->count_cuted_fields &&
|
(from+len != end && current_thd->count_cuted_fields &&
|
||||||
!test_if_int(from,len)))
|
!test_if_int(from,len,cs)))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -1854,7 +1858,7 @@ int Field_longlong::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
tmp=my_strntoll(cs,from,len,&end,10);
|
tmp=my_strntoll(cs,from,len,&end,10);
|
||||||
if (errno ||
|
if (errno ||
|
||||||
(from+len != end && current_thd->count_cuted_fields &&
|
(from+len != end && current_thd->count_cuted_fields &&
|
||||||
!test_if_int(from,len)))
|
!test_if_int(from,len,cs)))
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
if (table->db_low_byte_first)
|
if (table->db_low_byte_first)
|
||||||
@ -2054,7 +2058,7 @@ int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
{
|
{
|
||||||
errno=0;
|
errno=0;
|
||||||
Field_float::store(my_strntod(cs,from,len,(char**)NULL));
|
Field_float::store(my_strntod(cs,from,len,(char**)NULL));
|
||||||
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len))
|
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
return 1;
|
return 1;
|
||||||
@ -2316,7 +2320,7 @@ int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
|
|||||||
errno=0;
|
errno=0;
|
||||||
int error= 0;
|
int error= 0;
|
||||||
double j= my_strntod(cs,from,len,(char**)0);
|
double j= my_strntod(cs,from,len,(char**)0);
|
||||||
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len))
|
if (errno || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
|
||||||
{
|
{
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
error= 1;
|
error= 1;
|
||||||
@ -3100,7 +3104,7 @@ int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
|
|||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (current_thd->count_cuted_fields && !test_if_int(from,len))
|
else if (current_thd->count_cuted_fields && !test_if_int(from,len,cs))
|
||||||
current_thd->cuted_fields++;
|
current_thd->cuted_fields++;
|
||||||
if (nr != 0 || len != 4)
|
if (nr != 0 || len != 4)
|
||||||
{
|
{
|
||||||
|
@ -1072,7 +1072,7 @@ bool set_field_to_null(Field *field);
|
|||||||
bool set_field_to_null_with_conversions(Field *field, bool no_conversions);
|
bool set_field_to_null_with_conversions(Field *field, bool no_conversions);
|
||||||
uint find_enum(TYPELIB *typelib,const char *x, uint length);
|
uint find_enum(TYPELIB *typelib,const char *x, uint length);
|
||||||
ulonglong find_set(TYPELIB *typelib,const char *x, uint length);
|
ulonglong find_set(TYPELIB *typelib,const char *x, uint length);
|
||||||
bool test_if_int(const char *str,int length);
|
bool test_if_int(const char *str,int length,CHARSET_INFO *cs);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The following are for the interface with the .frm file
|
The following are for the interface with the .frm file
|
||||||
|
@ -4637,7 +4637,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
|
|||||||
berkeley_lock_type=berkeley_lock_types[type-1];
|
berkeley_lock_type=berkeley_lock_types[type-1];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (test_if_int(argument,(uint) strlen(argument)))
|
if (test_if_int(argument,(uint) strlen(argument), my_charset_latin1))
|
||||||
berkeley_lock_scan_time=atoi(argument);
|
berkeley_lock_scan_time=atoi(argument);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user