Commit fa65771e authored by unknown's avatar unknown
Browse files

Additional 5.0 fix for

Bug#15098: CAST(column double TO signed int), wrong result
which was fixed originally in 4.1.


mysql-test/r/cast.result:
  Fixing test results
sql/field.cc:
  Adding a "truncated value" warning.
parent dfe5769a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -344,6 +344,9 @@ SELECT f1 AS double_val, CAST(f1 AS SIGNED INT) AS cast_val FROM t1;
double_val	cast_val
-1e+30	-9223372036854775808
1e+30	9223372036854775807
Warnings:
Warning	1292	Truncated incorrect INTEGER value: '-1e+30'
Warning	1292	Truncated incorrect INTEGER value: '1e+30'
DROP TABLE t1;
select cast('1.2' as decimal(3,2));
cast('1.2' as decimal(3,2))
+21 −2
Original line number Diff line number Diff line
@@ -4232,6 +4232,7 @@ double Field_double::val_real(void)
longlong Field_double::val_int(void)
{
  double j;
  longlong res;
#ifdef WORDS_BIGENDIAN
  if (table->s->db_low_byte_first)
  {
@@ -4242,10 +4243,28 @@ longlong Field_double::val_int(void)
    doubleget(j,ptr);
  /* Check whether we fit into longlong range */
  if (j <= (double) LONGLONG_MIN)
    return (longlong) LONGLONG_MIN;
  {
    res= (longlong) LONGLONG_MIN;
    goto warn;
  }
  if (j >= (double) (ulonglong) LONGLONG_MAX)
    return (longlong) LONGLONG_MAX;
  {
    res= (longlong) LONGLONG_MAX;
    goto warn;
  }
  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;
}