Skip to content

Commit

Permalink
use consistent error messaging for IGNORE
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vuvova committed Apr 20, 2016
1 parent 9e826bf commit 24ac546
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 63 deletions.
9 changes: 0 additions & 9 deletions mysql-test/r/insert_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -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`))
Expand Down
25 changes: 0 additions & 25 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 */
13 changes: 5 additions & 8 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
/*
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -1866,9 +1866,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
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:
Expand Down
24 changes: 5 additions & 19 deletions sql/sql_update.cc
Original file line number Diff line number Diff line change
Expand Up @@ -774,27 +774,22 @@ 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
do anything; otherwise...
*/
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));
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 &&
Expand Down Expand Up @@ -1974,26 +1969,21 @@ int multi_update::send_data(List<Item> &not_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
do anything; otherwise...
*/
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
{
Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit 24ac546

Please sign in to comment.