Commit 1c15d4df authored by unknown's avatar unknown

Merge vvagin@bk-internal.mysql.com:/home/bk/mysql-4.1

into eagle.mysql.r18.ru:/home/vva/work/BUG_2082/mysql-4.1

parents 755f6939 f9a59e45
......@@ -128,6 +128,8 @@ static CHARSET_INFO *charset_info= &my_charset_latin1;
static int embedded_server_arg_count=0;
static char *embedded_server_args[MAX_SERVER_ARGS];
static my_bool display_result_vertically= FALSE;
static const char *embedded_server_groups[] = {
"server",
"embedded",
......@@ -213,6 +215,8 @@ Q_REQUIRE_VERSION,
Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS,
Q_ENABLE_INFO, Q_DISABLE_INFO,
Q_EXEC, Q_DELIMITER,
Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORISONTAL_RESULTS,
Q_QUERY_VERTICAL, Q_QUERY_HORISONTAL,
Q_UNKNOWN, /* Unknown command. */
Q_COMMENT, /* Comments, ignored. */
......@@ -286,6 +290,10 @@ const char *command_names[]=
"disable_info",
"exec",
"delimiter",
"vertical_results",
"horisontal_results",
"query_vertical",
"query_horisontal",
0
};
......@@ -2110,6 +2118,7 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
{
MYSQL_ROW row;
uint num_fields= mysql_num_fields(res);
MYSQL_FIELD *fields= !display_result_vertically ? 0 : mysql_fetch_fields(res);
unsigned long *lengths;
while ((row = mysql_fetch_row(res)))
{
......@@ -2130,11 +2139,22 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
val= "NULL";
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);
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();
}
......@@ -2276,16 +2296,19 @@ int run_query(MYSQL* mysql, struct st_query* q, int flags)
{
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)
dynstr_append_mem(ds, "\t", 1);
dynstr_append(ds, fields[i].name);
int num_fields= mysql_num_fields(res);
MYSQL_FIELD *fields= mysql_fetch_fields(res);
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);
}
......@@ -2557,12 +2580,37 @@ int main(int argc, char **argv)
strmake(delimiter, q->first_argument, sizeof(delimiter) - 1);
delimiter_length= strlen(delimiter);
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_EVAL_RESULT: eval_result = 1; break;
case Q_EVAL:
if (q->query == q->query_buf)
q->query= q->first_argument;
/* fall through */
case Q_QUERY_VERTICAL:
case Q_QUERY_HORISONTAL:
{
my_bool old_display_result_vertically= display_result_vertically;
if (!q->query[q->first_word_len])
{
/* This happens when we use 'query_..' on it's own line */
q_send_flag=1;
break;
}
/* fix up query pointer if this is * first iteration for this line */
if (q->query == q->query_buf)
q->query += q->first_word_len + 1;
switch(q->type)
{
case Q_QUERY_VERTICAL: display_result_vertically= TRUE; break;
case Q_QUERY_HORISONTAL: display_result_vertically= FALSE; break;
}
error |= run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND);
display_result_vertically= old_display_result_vertically;
break;
}
case Q_QUERY:
case Q_REAP:
{
......
This diff is collapsed.
......@@ -46,6 +46,8 @@ UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (a double);
INSERT INTO t1 VALUES (-9e999999);
Warnings:
Warning 1264 Data truncated, out of range for column 'a' at row 1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT, CHARACTER_SET_CLIENT=utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
......
......@@ -87,3 +87,67 @@ use mysqltest;
create table t1 (c int);
insert into mysqltest.t1 set mysqltest.t1.c = '1';
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);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= "1aa";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= "aa1";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= "1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= "-1e+1111111111a";
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= 1e+1111111111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= -1e+1111111111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= 1e+111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= -1e+111;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= 1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
set @value= -1;
insert into t1 values(null,@value,@value,@value,@value,@value,@value,@value,@value,@value);
--query_vertical select * from t1 where `number `=last_insert_id()
drop table t1;
......@@ -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 err;
Field_float::store(my_strntod(cs,(char*) from,len,(char**)NULL,&err));
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
char *end;
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);
Field_float::store(nr);
return 1;
}
return (err) ? 1 : 0;
}
......@@ -2285,28 +2290,48 @@ int Field_float::store(double nr)
{
float j;
int error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point
if (unsigned_flag && nr < 0)
if (isnan(nr))
{
j= 0;
set_null();
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
nr=0;
error= 1;
}
if (nr < -FLT_MAX)
else if (unsigned_flag && nr < 0)
{
j= -FLT_MAX;
j= 0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
else if (nr > FLT_MAX)
else
{
j=FLT_MAX;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
double max_value;
if (dec >= NOT_FIXED_DEC)
{
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
if (table->db_low_byte_first)
{
......@@ -2544,41 +2569,64 @@ void Field_float::sql_type(String &res) const
int Field_double::store(const char *from,uint len,CHARSET_INFO *cs)
{
int err;
double j= my_strntod(cs,(char*) from,len,(char**)0,&err);
if (err || current_thd->count_cuted_fields && !test_if_real(from,len,cs))
{
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_TRUNCATED);
err= 1;
}
if (unsigned_flag && j < 0)
char *end;
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_OUT_OF_RANGE);
j=0;
err= 1;
return Field_double::store(nr);
}
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
else
{
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 error= 0;
if (dec < NOT_FIXED_DEC)
nr=floor(nr*log_10[dec]+0.5)/log_10[dec]; // To fixed point
if (unsigned_flag && nr < 0)
if (isnan(nr))
{
nr= 0;
set_null();
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
error= 1;
}
else if (unsigned_flag && nr < 0)
{
nr= 0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE);
nr=0;
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
if (table->db_low_byte_first)
{
......
......@@ -93,7 +93,7 @@ double my_strtod(const char *str, char **end)
if (neg)
result= 0.0;
else
result= DBL_MAX;
result= DBL_MAX*10;
goto done;
}
while (exp >= 100)
......@@ -113,9 +113,6 @@ double my_strtod(const char *str, char **end)
if (end)
*end = (char *)str;
if (isinf(result))
result=DBL_MAX;
return negative ? -result : result;
}
......
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