summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
authorNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2016-02-10 19:57:17 +0530
committerNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2016-02-11 14:20:50 +0530
commitd9c541cb1be5b239787833d9d499067d44ea44d3 (patch)
tree18b421270670740fa3d0f3e3a82e1f82c8e89534 /sql/sql_update.cc
parent1fb6d4e6bf3dd79fffb034ca4b014930b0304e1f (diff)
downloadmariadb-git-d9c541cb1be5b239787833d9d499067d44ea44d3.tar.gz
BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN KEY
CONSTRAINT. Analysis ======= INSERT and UPDATE operations using the IGNORE keyword which causes FOREIGN KEY constraint violations reports an error despite using the IGNORE keyword. Foreign key violation errors were not ignored and reported as errors instead of warnings even when IGNORE was set. Fix === Added code to ignore the foreign key violation errors and report them as warnings when the IGNORE keyword is used.
Diffstat (limited to 'sql/sql_update.cc')
-rw-r--r--sql/sql_update.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index a29d474fbfc..64d1b3e49dc 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -735,7 +735,8 @@ int mysql_update(THD *thd,
error= 0;
}
else if (!ignore ||
- table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
+ table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
+ HA_CHECK_FK_ERROR))
{
/*
If (ignore && error is ignorable) we don't have to
@@ -743,7 +744,8 @@ int mysql_update(THD *thd,
*/
myf flags= 0;
- if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
+ if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
+ HA_CHECK_FK_ERROR))
flags|= ME_FATALERROR; /* Other handler errors are fatal */
prepare_record_for_error_message(error, table);
@@ -751,6 +753,9 @@ 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 &&
@@ -1883,7 +1888,8 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
updated--;
if (!ignore ||
- table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
+ table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
+ HA_CHECK_FK_ERROR))
{
/*
If (ignore && error == is ignorable) we don't have to
@@ -1891,13 +1897,17 @@ bool multi_update::send_data(List<Item> &not_used_values)
*/
myf flags= 0;
- if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
+ if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
+ HA_CHECK_FK_ERROR))
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
{
@@ -2138,8 +2148,12 @@ 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))
+ table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY |
+ HA_CHECK_FK_ERROR))
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++;