Commit 07e21be0 authored by bar@mysql.com's avatar bar@mysql.com

Additional 5.0 fix for

Bug#15098: CAST(column double TO signed int), wrong result
which was fixed originally in 4.1.
parent a586f5a1
...@@ -344,6 +344,9 @@ SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1; ...@@ -344,6 +344,9 @@ SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
double_val cast_val double_val cast_val
-1e+30 -9223372036854775808 -1e+30 -9223372036854775808
1e+30 9223372036854775807 1e+30 9223372036854775807
Warnings:
Warning 1292 Truncated incorrect INTEGER value: '-1e+30'
Warning 1292 Truncated incorrect INTEGER value: '1e+30'
DROP TABLE t1; DROP TABLE t1;
select cast('1.2' as decimal(3,2)); select cast('1.2' as decimal(3,2));
cast('1.2' as decimal(3,2)) cast('1.2' as decimal(3,2))
......
...@@ -4232,6 +4232,7 @@ double Field_double::val_real(void) ...@@ -4232,6 +4232,7 @@ double Field_double::val_real(void)
longlong Field_double::val_int(void) longlong Field_double::val_int(void)
{ {
double j; double j;
longlong res;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->s->db_low_byte_first) if (table->s->db_low_byte_first)
{ {
...@@ -4242,10 +4243,28 @@ longlong Field_double::val_int(void) ...@@ -4242,10 +4243,28 @@ longlong Field_double::val_int(void)
doubleget(j,ptr); doubleget(j,ptr);
/* Check whether we fit into longlong range */ /* Check whether we fit into longlong range */
if (j <= (double) LONGLONG_MIN) if (j <= (double) LONGLONG_MIN)
return (longlong) LONGLONG_MIN; {
res= (longlong) LONGLONG_MIN;
goto warn;
}
if (j >= (double) (ulonglong) LONGLONG_MAX) if (j >= (double) (ulonglong) LONGLONG_MAX)
return (longlong) LONGLONG_MAX; {
res= (longlong) LONGLONG_MAX;
goto warn;
}
return (longlong) rint(j); return (longlong) rint(j);
warn:
{
char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
String tmp(buf, sizeof(buf), &my_charset_latin1), *str;
str= val_str(&tmp, 0);
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_TRUNCATED_WRONG_VALUE,
ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
str->c_ptr());
}
return res;
} }
......
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