Handle the error when copying data from source to target table. @param error error code @param ignore alter ignore statement @param to target table handler @param thd Mysql Thread @param alter_ctx Runtime context for alter statement @retval false in case of error @retval true in case of skipping the row and continue alter operation */
| 12546 | @retval false in case of error |
| 12547 | @retval true in case of skipping the row and continue alter operation */ |
| 12548 | static bool |
| 12549 | copy_data_error_ignore(int &error, bool ignore, TABLE *to, |
| 12550 | THD *thd, Alter_table_ctx *alter_ctx) |
| 12551 | { |
| 12552 | if (to->file->is_fatal_error(error, HA_CHECK_DUP)) |
| 12553 | { |
| 12554 | /* Not a duplicate key error. */ |
| 12555 | to->file->print_error(error, MYF(0)); |
| 12556 | error= 1; |
| 12557 | return false; |
| 12558 | } |
| 12559 | /* Duplicate key error. */ |
| 12560 | if (unlikely(alter_ctx->fk_error_if_delete_row)) |
| 12561 | { |
| 12562 | /* We are trying to omit a row from the table which serves |
| 12563 | as parent in a foreign key. This might have broken |
| 12564 | referential integrity so emit an error. Note that we |
| 12565 | can't ignore this error even if we are |
| 12566 | executing ALTER IGNORE TABLE. IGNORE allows to skip rows, but |
| 12567 | doesn't allow to break unique or foreign key constraints, */ |
| 12568 | my_error(ER_FK_CANNOT_DELETE_PARENT, MYF(0), |
| 12569 | alter_ctx->fk_error_id, |
| 12570 | alter_ctx->fk_error_table); |
| 12571 | return false; |
| 12572 | } |
| 12573 | if (ignore) |
| 12574 | return true; |
| 12575 | /* Ordinary ALTER TABLE. Report duplicate key error. */ |
| 12576 | uint key_nr= to->file->get_dup_key(error); |
| 12577 | if (key_nr <= MAX_KEY) |
| 12578 | { |
| 12579 | const char *err_msg= ER_THD(thd, ER_DUP_ENTRY_WITH_KEY_NAME); |
| 12580 | if (key_nr == 0 && to->s->keys > 0 && |
| 12581 | (to->key_info[0].key_part[0].field->flags & |
| 12582 | AUTO_INCREMENT_FLAG)) |
| 12583 | err_msg= ER_THD(thd, ER_DUP_ENTRY_AUTOINCREMENT_CASE); |
| 12584 | print_keydup_error(to, |
| 12585 | key_nr >= to->s->keys ? NULL : |
| 12586 | &to->key_info[key_nr], |
| 12587 | err_msg, MYF(0)); |
| 12588 | } |
| 12589 | else |
| 12590 | to->file->print_error(error, MYF(0)); |
| 12591 | return false; |
| 12592 | } |
| 12593 | |
| 12594 | static int |
| 12595 | copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, |
no test coverage detected