diff options
author | Sergei Golubchik <serg@mariadb.org> | 2016-04-20 18:27:23 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-04-20 18:27:23 +0200 |
commit | 24ac546d0f16d5f56b11c068e4f187a9c4c56bd0 (patch) | |
tree | 0ce4470aa683f8109963f71760f23a6711ec05ab | |
parent | 9e826bfa36a57f10540ca6ea649cb450add48cf4 (diff) | |
download | mariadb-git-24ac546d0f16d5f56b11c068e4f187a9c4c56bd0.tar.gz |
use consistent error messaging for IGNORE
1. the same message text for INSERT and INSERT IGNORE
2. no new warnings in UPDATE IGNORE yet (big change for 5.5)
and replace a commonly used expression with a
named constant
-rw-r--r-- | mysql-test/r/insert_innodb.result | 9 | ||||
-rw-r--r-- | sql/handler.cc | 25 | ||||
-rw-r--r-- | sql/handler.h | 3 | ||||
-rw-r--r-- | sql/sql_insert.cc | 13 | ||||
-rw-r--r-- | sql/sql_update.cc | 24 |
5 files changed, 11 insertions, 63 deletions
diff --git a/mysql-test/r/insert_innodb.result b/mysql-test/r/insert_innodb.result index e7a133a8945..ffba9388ec4 100644 --- a/mysql-test/r/insert_innodb.result +++ b/mysql-test/r/insert_innodb.result @@ -11,20 +11,11 @@ INSERT INTO t2 VALUES(0); INSERT IGNORE INTO t2 VALUES(1); Warnings: Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) -Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`) UPDATE IGNORE t2 SET fld2=20 WHERE fld2=0; -Warnings: -Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`) UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0; -Warnings: -Warning 1451 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`) # Test for multi update. UPDATE IGNORE t1, t2 SET t2.fld2= t2.fld2 + 3; -Warnings: -Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`) UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3; -Warnings: -Warning 1451 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`) # Reports an error since IGNORE is not used. INSERT INTO t2 VALUES(1); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) diff --git a/sql/handler.cc b/sql/handler.cc index 1a318334ef3..d528c0aea7a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5463,28 +5463,3 @@ fl_create_iterator(enum handler_iterator_type type, } } #endif /*TRANS_LOG_MGM_EXAMPLE_CODE*/ - - -/** - Report a warning for FK constraint violation. - - @param thd Thread handle. - @param table table on which the operation is performed. - @param error handler error number. -*/ -void warn_fk_constraint_violation(THD *thd,TABLE *table, int error) -{ - String str; - switch(error) { - case HA_ERR_ROW_IS_REFERENCED: - table->file->get_error_message(error, &str); - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_ROW_IS_REFERENCED_2, str.c_ptr_safe()); - break; - case HA_ERR_NO_REFERENCED_ROW: - table->file->get_error_message(error, &str); - push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_NO_REFERENCED_ROW_2, str.c_ptr_safe()); - break; - } -} diff --git a/sql/handler.h b/sql/handler.h index 11718ba775c..3d6c8dea2bf 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -335,6 +335,7 @@ #define HA_CHECK_DUP_UNIQUE 2 #define HA_CHECK_FK_ERROR 4 #define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE) +#define HA_CHECK_ALL (~0U) enum legacy_db_type { @@ -3110,6 +3111,4 @@ inline const char *table_case_name(HA_CREATE_INFO *info, const char *name) return ((lower_case_table_names == 2 && info->alias) ? info->alias : name); } -void warn_fk_constraint_violation(THD *thd, TABLE *table, int error); - #endif /* HANDLER_INCLUDED */ diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 7e3a898b3da..c60ef6fcc6e 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1609,9 +1609,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) else table->file->insert_id_for_cur_row= insert_id_for_cur_row; bool is_duplicate_key_error; - if (table->file->is_fatal_error(error, HA_CHECK_DUP | HA_CHECK_FK_ERROR)) + if (table->file->is_fatal_error(error, HA_CHECK_ALL)) goto err; - is_duplicate_key_error= table->file->is_fatal_error(error, 0); + is_duplicate_key_error= + table->file->is_fatal_error(error, HA_CHECK_ALL & ~HA_CHECK_DUP); if (!is_duplicate_key_error) { /* @@ -1712,8 +1713,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) error != HA_ERR_RECORD_IS_THE_SAME) { if (info->ignore && - !table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + !table->file->is_fatal_error(error, HA_CHECK_ALL)) { if (!(thd->variables.old_behavior & OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE)) @@ -1845,7 +1845,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) { DEBUG_SYNC(thd, "write_row_noreplace"); if (!info->ignore || - table->file->is_fatal_error(error, HA_CHECK_DUP | HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(error, HA_CHECK_ALL)) goto err; if (!(thd->variables.old_behavior & OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE)) @@ -1866,9 +1866,6 @@ ok_or_after_trg_err: my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH); if (!table->file->has_transactions()) thd->transaction.stmt.modified_non_trans_table= TRUE; - if (info->ignore && - !table->file->is_fatal_error(error, HA_CHECK_FK_ERROR)) - warn_fk_constraint_violation(thd, table, error); DBUG_RETURN(trg_error); err: diff --git a/sql/sql_update.cc b/sql/sql_update.cc index d1b6e945b23..f134e0ba266 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -774,8 +774,7 @@ int mysql_update(THD *thd, error= 0; } else if (!ignore || - table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(error, HA_CHECK_ALL)) { /* If (ignore && error is ignorable) we don't have to @@ -783,8 +782,7 @@ int mysql_update(THD *thd, */ myf flags= 0; - if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + if (table->file->is_fatal_error(error, HA_CHECK_ALL)) flags|= ME_FATALERROR; /* Other handler errors are fatal */ prepare_record_for_error_message(error, table); @@ -792,9 +790,6 @@ int mysql_update(THD *thd, error= 1; break; } - else if (ignore && !table->file->is_fatal_error(error, - HA_CHECK_FK_ERROR)) - warn_fk_constraint_violation(thd, table, error); } if (table->triggers && @@ -1974,8 +1969,7 @@ int multi_update::send_data(List<Item> ¬_used_values) { updated--; if (!ignore || - table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(error, HA_CHECK_ALL)) { /* If (ignore && error == is ignorable) we don't have to @@ -1983,17 +1977,13 @@ int multi_update::send_data(List<Item> ¬_used_values) */ myf flags= 0; - if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + if (table->file->is_fatal_error(error, HA_CHECK_ALL)) flags|= ME_FATALERROR; /* Other handler errors are fatal */ prepare_record_for_error_message(error, table); table->file->print_error(error,MYF(flags)); DBUG_RETURN(1); } - else if (ignore && !table->file->is_fatal_error(error, - HA_CHECK_FK_ERROR)) - warn_fk_constraint_violation(thd, table, error); } else { @@ -2266,15 +2256,11 @@ int multi_update::do_updates() local_error != HA_ERR_RECORD_IS_THE_SAME) { if (!ignore || - table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(local_error, HA_CHECK_ALL)) { err_table= table; goto err; } - else if (ignore && !table->file->is_fatal_error(local_error, - HA_CHECK_FK_ERROR)) - warn_fk_constraint_violation(thd, table, local_error); } if (local_error != HA_ERR_RECORD_IS_THE_SAME) updated++; |