summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/cast.result3
-rw-r--r--sql/field.cc23
2 files changed, 24 insertions, 2 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index ae9e6748e65..d60efa083e0 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -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))
diff --git a/sql/field.cc b/sql/field.cc
index 6cd5147648f..617d34e89a8 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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;
}