diff --git a/include/my_sys.h b/include/my_sys.h index 9c07fc2e923..473251f26cb 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -782,9 +782,9 @@ extern void get_defaults_files(int argc, char **argv, char **defaults, char **extra_defaults); extern int load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); -extern uint modify_defaults_file(const char *file_location, const char *option, - const char *option_value, - const char *section_name, int remove_option); +extern int modify_defaults_file(const char *file_location, const char *option, + const char *option_value, + const char *section_name, int remove_option); extern int my_search_option_files(const char *conf_file, int *argc, char ***argv, uint *args_used, Process_option_func func, void *func_ctx); diff --git a/include/mysql_com.h b/include/mysql_com.h index a49bc01da8a..c608a2e7724 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -417,9 +417,9 @@ const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); /* Some other useful functions */ my_bool my_init(void); -extern uint modify_defaults_file(const char *file_location, const char *option, - const char *option_value, - const char *section_name, int remove_option); +extern int modify_defaults_file(const char *file_location, const char *option, + const char *option_value, + const char *section_name, int remove_option); int load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); my_bool my_thread_init(void); diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result index 79be7a1923a..d7ad803b828 100644 --- a/mysql-test/r/strict.result +++ b/mysql-test/r/strict.result @@ -770,7 +770,7 @@ ERROR 22003: Out of range value adjusted for column 'col1' at row 1 INSERT INTO t1 VALUES ('-100E+1'); ERROR 22003: Out of range value adjusted for column 'col1' at row 1 INSERT INTO t1 VALUES ('-100E'); -ERROR 22003: Out of range value adjusted for column 'col1' at row 1 +ERROR HY000: Incorrect decimal value: '-100E' for column 'col1' at row 1 UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11; ERROR 22003: Out of range value adjusted for column 'col1' at row 6 UPDATE t1 SET col1 =col1 / 0 WHERE col1 > 0; @@ -782,8 +782,7 @@ ERROR HY000: Incorrect decimal value: '' for column 'col1' at row 1 INSERT INTO t1 (col1) VALUES ('a59b'); ERROR HY000: Incorrect decimal value: 'a59b' for column 'col1' at row 1 INSERT INTO t1 (col1) VALUES ('1a'); -Warnings: -Note 1265 Data truncated for column 'col1' at row 1 +ERROR HY000: Incorrect decimal value: '1a' for column 'col1' at row 1 INSERT IGNORE INTO t1 (col1) VALUES ('2a'); Warnings: Note 1265 Data truncated for column 'col1' at row 1 @@ -818,7 +817,6 @@ NULL -10.56 11.00 10.00 -1.00 2.00 NULL 99.99 diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index e775724ff54..f03f2f5a862 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -885,3 +885,9 @@ SELECT GRADE FROM t1 WHERE GRADE= 151; GRADE 151 DROP TABLE t1; +select abs(10/0); +abs(10/0) +NULL +select abs(NULL); +abs(NULL) +NULL diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test index 298653b554a..302acc9bef2 100644 --- a/mysql-test/t/strict.test +++ b/mysql-test/t/strict.test @@ -740,7 +740,7 @@ INSERT INTO t1 VALUES ('-101.55'); INSERT INTO t1 VALUES ('-1010.55'); --error 1264 INSERT INTO t1 VALUES ('-100E+1'); ---error 1264 +--error 1366 INSERT INTO t1 VALUES ('-100E'); --error 1264 UPDATE t1 SET col1 =col1 * 50000 WHERE col1 =11; @@ -754,7 +754,7 @@ INSERT INTO t1 (col1) VALUES (''); #--error 1265 --error 1366 INSERT INTO t1 (col1) VALUES ('a59b'); -#--error 1265 +--error 1366 INSERT INTO t1 (col1) VALUES ('1a'); INSERT IGNORE INTO t1 (col1) VALUES ('2a'); INSERT IGNORE INTO t1 values (1/0); diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index 78ad5ed2286..9b09c415379 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -916,3 +916,10 @@ INSERT INTO t1 (GRADE) VALUES (151),(252),(343); SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300; SELECT GRADE FROM t1 WHERE GRADE= 151; DROP TABLE t1; + +# +# Bug #10599: problem with NULL +# + +select abs(10/0); +select abs(NULL); diff --git a/mysys/default_modify.c b/mysys/default_modify.c index c0589f54132..3476b8628cf 100644 --- a/mysys/default_modify.c +++ b/mysys/default_modify.c @@ -37,9 +37,9 @@ #define NEWLINE_LEN 1 #endif -uint modify_defaults_file(const char *file_location, const char *option, - const char *option_value, - const char *section_name, int remove_option) +int modify_defaults_file(const char *file_location, const char *option, + const char *option_value, + const char *section_name, int remove_option) { FILE *cnf_file; struct stat file_stat; diff --git a/sql/field.cc b/sql/field.cc index fa94005cb3a..76de01ca8b9 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2366,9 +2366,20 @@ int Field_new_decimal::store(const char *from, uint length, my_decimal decimal_value; DBUG_ENTER("Field_new_decimal::store(char*)"); - switch ((err= str2my_decimal(E_DEC_FATAL_ERROR & - ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM), - from, length, charset, &decimal_value))) { + if ((err= str2my_decimal(E_DEC_FATAL_ERROR & + ~(E_DEC_OVERFLOW | E_DEC_BAD_NUM), + from, length, charset, &decimal_value)) && + table->in_use->abort_on_warning) + { + push_warning_printf(table->in_use, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, + ER(ER_TRUNCATED_WRONG_VALUE_FOR_FIELD), + "decimal", from, field_name, + (ulong) table->in_use->row_count); + DBUG_RETURN(err); + } + + switch (err) { case E_DEC_TRUNCATED: set_warning(MYSQL_ERROR::WARN_LEVEL_NOTE, WARN_DATA_TRUNCATED, 1); break; diff --git a/sql/item_func.cc b/sql/item_func.cc index f9a9b610e4f..89f9111101a 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1063,11 +1063,11 @@ my_decimal *Item_func_plus::decimal_op(my_decimal *decimal_value) if ((null_value= args[0]->null_value)) return 0; val2= args[1]->val_decimal(&value2); - if ((null_value= (args[1]->null_value || - my_decimal_add(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[1]->null_value || + my_decimal_add(E_DEC_FATAL_ERROR, decimal_value, val1, + val2) > 1))) + return decimal_value; + return 0; } /* @@ -1136,11 +1136,11 @@ my_decimal *Item_func_minus::decimal_op(my_decimal *decimal_value) if ((null_value= args[0]->null_value)) return 0; val2= args[1]->val_decimal(&value2); - if ((null_value= (args[1]->null_value || - my_decimal_sub(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[1]->null_value || + my_decimal_sub(E_DEC_FATAL_ERROR, decimal_value, val1, + val2) > 1))) + return decimal_value; + return 0; } @@ -1174,11 +1174,11 @@ my_decimal *Item_func_mul::decimal_op(my_decimal *decimal_value) if ((null_value= args[0]->null_value)) return 0; val2= args[1]->val_decimal(&value2); - if ((null_value= (args[1]->null_value || - my_decimal_mul(E_DEC_FATAL_ERROR, decimal_value, val1, - val2) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[1]->null_value || + my_decimal_mul(E_DEC_FATAL_ERROR, decimal_value, val1, + val2) > 1))) + return decimal_value; + return 0; } @@ -1396,8 +1396,9 @@ my_decimal *Item_func_neg::decimal_op(my_decimal *decimal_value) { my_decimal2decimal(value, decimal_value); my_decimal_neg(decimal_value); + return decimal_value; } - return decimal_value; + return 0; } @@ -1460,8 +1461,9 @@ my_decimal *Item_func_abs::decimal_op(my_decimal *decimal_value) my_decimal2decimal(value, decimal_value); if (decimal_value->sign()) my_decimal_neg(decimal_value); + return decimal_value; } - return decimal_value; + return 0; } @@ -1761,11 +1763,11 @@ double Item_func_ceiling::real_op() my_decimal *Item_func_ceiling::decimal_op(my_decimal *decimal_value) { my_decimal val, *value= args[0]->val_decimal(&val); - if ((null_value= (args[0]->null_value || - my_decimal_ceiling(E_DEC_FATAL_ERROR, value, - decimal_value) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[0]->null_value || + my_decimal_ceiling(E_DEC_FATAL_ERROR, value, + decimal_value) > 1))) + return decimal_value; + return 0; } @@ -1808,11 +1810,11 @@ double Item_func_floor::real_op() my_decimal *Item_func_floor::decimal_op(my_decimal *decimal_value) { my_decimal val, *value= args[0]->val_decimal(&val); - if ((null_value= (args[0]->null_value || - my_decimal_floor(E_DEC_FATAL_ERROR, value, - decimal_value) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[0]->null_value || + my_decimal_floor(E_DEC_FATAL_ERROR, value, + decimal_value) > 1))) + return decimal_value; + return 0; } @@ -1955,11 +1957,11 @@ my_decimal *Item_func_round::decimal_op(my_decimal *decimal_value) { decimals= min(dec, DECIMAL_MAX_SCALE); // to get correct output } - if ((null_value= (args[0]->null_value || args[1]->null_value || - my_decimal_round(E_DEC_FATAL_ERROR, value, dec, truncate, - decimal_value) > 1))) - return 0; - return decimal_value; + if (!(null_value= (args[0]->null_value || args[1]->null_value || + my_decimal_round(E_DEC_FATAL_ERROR, value, dec, truncate, + decimal_value) > 1))) + return decimal_value; + return 0; }