Commit c8bfc232 authored by unknown's avatar unknown

Fixed bug #2082 'mysqldump converts "inf" to NULL' and

added commands vertical_results and horisontal_results to client/mysqltest.c


client/mysqltest.c:
  added commands vertical_results and horisontal_results
mysql-test/r/insert.result:
  added test for bug #2082 'mysqldump converts "inf" to NULL'
mysql-test/t/insert.test:
  Fixed bug #2082 'mysqldump converts "inf" to NULL'
sql/field.cc:
  added test for Fixed bug #2082 'mysqldump converts "inf" to NULL'
parent e269e9c9
...@@ -128,6 +128,8 @@ static CHARSET_INFO *charset_info= &my_charset_latin1; ...@@ -128,6 +128,8 @@ static CHARSET_INFO *charset_info= &my_charset_latin1;
static int embedded_server_arg_count=0; static int embedded_server_arg_count=0;
static char *embedded_server_args[MAX_SERVER_ARGS]; static char *embedded_server_args[MAX_SERVER_ARGS];
static my_bool display_result_vertically= FALSE;
static const char *embedded_server_groups[] = { static const char *embedded_server_groups[] = {
"server", "server",
"embedded", "embedded",
...@@ -213,6 +215,7 @@ Q_REQUIRE_VERSION, ...@@ -213,6 +215,7 @@ Q_REQUIRE_VERSION,
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
Q_ENABLE_INFO, Q_DISABLE_INFO, Q_ENABLE_INFO, Q_DISABLE_INFO,
Q_EXEC, Q_DELIMITER, Q_EXEC, Q_DELIMITER,
Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORISONTAL_RESULTS,
Q_UNKNOWN, /* Unknown command. */ Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */ Q_COMMENT, /* Comments, ignored. */
...@@ -286,6 +289,8 @@ const char *command_names[]= ...@@ -286,6 +289,8 @@ const char *command_names[]=
"disable_info", "disable_info",
"exec", "exec",
"delimiter", "delimiter",
"vertical_results",
"horisontal_results",
0 0
}; };
...@@ -2110,6 +2115,7 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) ...@@ -2110,6 +2115,7 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
{ {
MYSQL_ROW row; MYSQL_ROW row;
uint num_fields= mysql_num_fields(res); uint num_fields= mysql_num_fields(res);
MYSQL_FIELD *fields= !display_result_vertically ? 0 : mysql_fetch_fields(res);
unsigned long *lengths; unsigned long *lengths;
while ((row = mysql_fetch_row(res))) while ((row = mysql_fetch_row(res)))
{ {
...@@ -2130,11 +2136,22 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) ...@@ -2130,11 +2136,22 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
val= "NULL"; val= "NULL";
len= 4; len= 4;
} }
if (i) if (!display_result_vertically)
{
if (i)
dynstr_append_mem(ds, "\t", 1);
replace_dynstr_append_mem(ds, val, len);
}
else
{
dynstr_append(ds, fields[i].name);
dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, "\t", 1);
replace_dynstr_append_mem(ds, val, len); replace_dynstr_append_mem(ds, val, len);
dynstr_append_mem(ds, "\n", 1);
}
} }
dynstr_append_mem(ds, "\n", 1); if (!display_result_vertically)
dynstr_append_mem(ds, "\n", 1);
} }
free_replace_column(); free_replace_column();
} }
...@@ -2276,16 +2293,19 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags) ...@@ -2276,16 +2293,19 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
{ {
if (res) if (res)
{ {
int num_fields= mysql_num_fields(res);
MYSQL_FIELD *fields= mysql_fetch_fields(res);
for (i = 0; i < num_fields; i++) if (!display_result_vertically)
{ {
if (i) int num_fields= mysql_num_fields(res);
dynstr_append_mem(ds, "\t", 1); MYSQL_FIELD *fields= mysql_fetch_fields(res);
dynstr_append(ds, fields[i].name); for (i = 0; i < num_fields; i++)
{
if (i)
dynstr_append_mem(ds, "\t", 1);
dynstr_append(ds, fields[i].name);
}
dynstr_append_mem(ds, "\n", 1);
} }
dynstr_append_mem(ds, "\n", 1);
append_result(ds, res); append_result(ds, res);
} }
...@@ -2557,6 +2577,9 @@ int main(int argc, char **argv) ...@@ -2557,6 +2577,9 @@ int main(int argc, char **argv)
strmake(delimiter, q->first_argument, sizeof(delimiter) - 1); strmake(delimiter, q->first_argument, sizeof(delimiter) - 1);
delimiter_length= strlen(delimiter); delimiter_length= strlen(delimiter);
break; break;
case Q_DISPLAY_VERTICAL_RESULTS: display_result_vertically= TRUE; break;
case Q_DISPLAY_HORISONTAL_RESULTS:
display_result_vertically= FALSE; break;
case Q_LET: do_let(q); break; case Q_LET: do_let(q); break;
case Q_EVAL_RESULT: eval_result = 1; break; case Q_EVAL_RESULT: eval_result = 1; break;
case Q_EVAL: case Q_EVAL:
......
This diff is collapsed.
...@@ -87,3 +87,88 @@ use mysqltest; ...@@ -87,3 +87,88 @@ use mysqltest;
create table t1 (c int); create table t1 (c int);
insert into mysqltest.t1 set mysqltest.t1.c = '1'; insert into mysqltest.t1 set mysqltest.t1.c = '1';
drop database mysqltest; drop database mysqltest;
#
# Test of wrong values for float data (bug #2082)
#
use test;
create table t1(
`number ` int auto_increment primary key,
`original_value ` varchar(50),
`f_double ` double,
`f_float ` float,
`f_double_7_2 ` double(7,2),
`f_float_4_3 ` float (4,3),
`f_double_u ` double unsigned,
`f_float_u ` float unsigned,
`f_double_15_1_u ` double(15,1) unsigned,
`f_float_3_1_u ` float (3,1) unsigned
);
set @value= "aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= "1aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= "aa1";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= "1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= "-1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= 1e+1111111111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= -1e+1111111111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= 1e+111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= -1e+111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= 1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
set @value= -1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
vertical_results;
select * from t1 where `number `=last_insert_id();
horisontal_results;
drop table t1;
...@@ -2271,13 +2271,18 @@ void Field_longlong::sql_type(String &res) const ...@@ -2271,13 +2271,18 @@ void Field_longlong::sql_type(String &res) const
int Field_float::store(const char *from,uint len,CHARSET_INFO *cs) int Field_float::store(const char *from,uint len,CHARSET_INFO *cs)
{ {
int err; int err;
Field_float::store(my_strntod(cs,(char*) from,len,(char**)NULL,&err)); char *end;
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs)) double nr= my_strntod(cs,(char*) from,len,&end,&err);
if (!err && (!current_thd->count_cuted_fields || end-from==len))
{
return Field_float::store(nr);
}
else
{ {
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED);
Field_float::store(nr);
return 1; return 1;
} }
return (err) ? 1 : 0;
} }
...@@ -2285,28 +2290,41 @@ int Field_float::store(double nr) ...@@ -2285,28 +2290,41 @@ int Field_float::store(double nr)
{ {
float j; float j;
int error= 0; int error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (isnan(nr) || unsigned_flag && nr < 0)
if (unsigned_flag && nr < 0)
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
nr=0;
error= 1;
}
if (nr < -FLT_MAX)
{ {
j= -FLT_MAX; j= 0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1; error= 1;
} }
else if (nr > FLT_MAX) else
{ {
j=FLT_MAX; double max_value;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); if (dec >= NOT_FIXED_DEC)
error= 1; {
max_value= FLT_MAX;
}
else
{
max_value= (log_10[field_length]-1)/log_10[dec];
nr= floor(nr*log_10[dec]+0.5)/log_10[dec];
}
if (nr < -max_value)
{
j= (float)-max_value;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
else if (nr > max_value)
{
j= (float)max_value;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
else
j= (float) nr;
} }
else
j= (float) nr;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
{ {
...@@ -2544,41 +2562,57 @@ void Field_float::sql_type(String &res) const ...@@ -2544,41 +2562,57 @@ void Field_float::sql_type(String &res) const
int Field_double::store(const char *from,uint len,CHARSET_INFO *cs) int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
{ {
int err; int err;
double j= my_strntod(cs,(char*) from,len,(char**)0,&err); char *end;
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs)) double nr= my_strntod(cs,(char*) from,len,&end,&err);
{ if (!err && (!current_thd->count_cuted_fields || end-from==len))
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED);
err= 1;
}
if (unsigned_flag && j < 0)
{ {
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); return Field_double::store(nr);
j=0;
err= 1;
} }
#ifdef WORDS_BIGENDIAN else
if (table->db_low_byte_first)
{ {
float8store(ptr,j); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED);
Field_double::store(nr);
return 1;
} }
else
#endif
doublestore(ptr,j);
return err;
} }
int Field_double::store(double nr) int Field_double::store(double nr)
{ {
int error= 0; int error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point if (isnan(nr) || unsigned_flag && nr < 0)
if (unsigned_flag && nr < 0)
{ {
nr= 0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE); set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
nr=0;
error= 1; error= 1;
} }
else
{
double max_value;
if (dec >= NOT_FIXED_DEC)
{
max_value= DBL_MAX;
}
else
{
max_value= (log_10[field_length]-1)/log_10[dec];
nr= floor(nr*log_10[dec]+0.5)/log_10[dec];
}
if (nr < -max_value)
{
nr= -max_value;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
else if (nr > max_value)
{
nr= max_value;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
}
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
{ {
......
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