diff options
-rw-r--r-- | mysql-test/r/func_math.result | 19 | ||||
-rw-r--r-- | mysql-test/t/func_math.test | 11 | ||||
-rw-r--r-- | sql/item_func.cc | 7 |
3 files changed, 36 insertions, 1 deletions
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 0be170c2f26..8d4a4171e21 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -709,3 +709,22 @@ foo select 999999999999999999999999999999999999999999999999999999999999999999999999999999999 % 0.0 as foo; foo NULL +# +# Bug#12711164 - 61676: +# RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE +# +select 5 div 2; +5 div 2 +2 +select 5.0 div 2.0; +5.0 div 2.0 +2 +select 5.0 div 2; +5.0 div 2 +2 +select 5 div 2.0; +5 div 2.0 +2 +select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2; +5.9 div 2 1.23456789e3 DIV 2 1.23456789e9 DIV 2 1.23456789e19 DIV 2 +2 617 617283945 6172839450000000000 diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index b6890bdab17..a1df990fa8e 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -547,3 +547,14 @@ let $nine_81= eval select $nine_81 % 0.1 as foo; eval select $nine_81 % 0.0 as foo; + +--echo # +--echo # Bug#12711164 - 61676: +--echo # RESULT OF DIV WITH DECIMAL AND INTEGER DOES NOT MAKE SENSE +--echo # + +select 5 div 2; +select 5.0 div 2.0; +select 5.0 div 2; +select 5 div 2.0; +select 5.9 div 2, 1.23456789e3 DIV 2, 1.23456789e9 DIV 2, 1.23456789e19 DIV 2; diff --git a/sql/item_func.cc b/sql/item_func.cc index 19fc313a675..7257b411ec4 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1605,8 +1605,13 @@ longlong Item_func_int_div::val_int() return 0; } + my_decimal truncated; + const bool do_truncate= true; + if (my_decimal_round(E_DEC_FATAL_ERROR, &tmp, 0, do_truncate, &truncated)) + DBUG_ASSERT(false); + longlong res; - if (my_decimal2int(E_DEC_FATAL_ERROR, &tmp, unsigned_flag, &res) & + if (my_decimal2int(E_DEC_FATAL_ERROR, &truncated, unsigned_flag, &res) & E_DEC_OVERFLOW) raise_integer_overflow(); return res; |