diff options
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index 04fa20a8abf..46fdbd2a4a1 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -12,7 +12,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ /** @file @@ -1022,19 +1022,26 @@ void Item_decimal_typecast::print(String *str, enum_query_type query_type) } -double Item_double_typecast::val_real() +double Item_real_typecast::val_real_with_truncate(double max_value) { int error; double tmp= args[0]->val_real(); if ((null_value= args[0]->null_value)) return 0.0; - if (unlikely((error= truncate_double(&tmp, max_length, decimals, 0, - DBL_MAX)))) + if (unlikely((error= truncate_double(&tmp, max_length, decimals, + false/*unsigned_flag*/, max_value)))) { + /* + We don't want automatic escalation from a warning to an error + in this scenario: + INSERT INTO t1 (float_field) VALUES (CAST(1e100 AS FLOAT)); + The above statement should work even in the strict mode. + So let's use a note rather than a warning. + */ THD *thd= current_thd; push_warning_printf(thd, - Sql_condition::WARN_LEVEL_WARN, + Sql_condition::WARN_LEVEL_NOTE, ER_WARN_DATA_OUT_OF_RANGE, ER_THD(thd, ER_WARN_DATA_OUT_OF_RANGE), name.str, (ulong) 1); @@ -1048,14 +1055,15 @@ double Item_double_typecast::val_real() } -void Item_double_typecast::print(String *str, enum_query_type query_type) +void Item_real_typecast::print(String *str, enum_query_type query_type) { char len_buf[20*3 + 1]; char *end; str->append(STRING_WITH_LEN("cast(")); args[0]->print(str, query_type); - str->append(STRING_WITH_LEN(" as double")); + str->append(STRING_WITH_LEN(" as ")); + str->append(type_handler()->name().ptr()); if (decimals != NOT_FIXED_DEC) { str->append('('); |