From 5fa04aae9ec94428a68ef4f6f681564111933c11 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 1 Mar 2017 23:52:35 +0100 Subject: [PATCH] MDEV-11842 Fail to insert on a table where a field has no default has_no_default_value() should only fail the insert in the strict mode. Additionally, don't check for "all fields are given values" twice, it'll produce duplicate warnings. --- mysql-test/r/trigger_no_defaults-11698.result | 18 ++++++++++++++++++ mysql-test/t/trigger_no_defaults-11698.test | 15 +++++++++++++++ sql/sql_insert.cc | 9 +++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/trigger_no_defaults-11698.result b/mysql-test/r/trigger_no_defaults-11698.result index 40546cee41d14..936720921805a 100644 --- a/mysql-test/r/trigger_no_defaults-11698.result +++ b/mysql-test/r/trigger_no_defaults-11698.result @@ -20,3 +20,21 @@ a b 10 10 0 30 drop table t1; +set sql_mode=default; +create table t1 ( +id int(11) not null auto_increment primary key, +data1 varchar(10) not null, +data2 varchar(10) not null +); +insert into t1 (data2) values ('x'); +Warnings: +Warning 1364 Field 'data1' doesn't have a default value +create trigger test_trigger before insert on t1 for each row begin end; +insert into t1 (data2) values ('y'); +Warnings: +Warning 1364 Field 'data1' doesn't have a default value +select * from t1; +id data1 data2 +1 x +2 y +drop table t1; diff --git a/mysql-test/t/trigger_no_defaults-11698.test b/mysql-test/t/trigger_no_defaults-11698.test index fab7845ad7d3a..d7e391a8bb29c 100644 --- a/mysql-test/t/trigger_no_defaults-11698.test +++ b/mysql-test/t/trigger_no_defaults-11698.test @@ -23,3 +23,18 @@ insert t1 (b) values (20); insert t1 (b) values (30); select * from t1; drop table t1; +set sql_mode=default; + +# +# MDEV-11842 Fail to insert on a table where a field has no default +# +create table t1 ( + id int(11) not null auto_increment primary key, + data1 varchar(10) not null, + data2 varchar(10) not null +); +insert into t1 (data2) values ('x'); +create trigger test_trigger before insert on t1 for each row begin end; +insert into t1 (data2) values ('y'); +select * from t1; +drop table t1; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f4e0a6a00eb1c..4dacb875abe7b 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -325,7 +325,7 @@ static bool has_no_default_value(THD *thd, Field *field, TABLE_LIST *table_list) push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NO_DEFAULT_FOR_FIELD, ER_THD(thd, ER_NO_DEFAULT_FOR_FIELD), field->field_name); } - return true; + return thd->really_abort_on_warning(); } return false; } @@ -891,7 +891,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (fields.elements || !value_count || table_list->view != 0) { - if (check_that_all_fields_are_given_values(thd, table, table_list)) + if (table->triggers && + table->triggers->has_triggers(TRG_EVENT_INSERT, TRG_ACTION_BEFORE)) + { + /* BEFORE INSERT triggers exist, the check will be done later, per row */ + } + else if (check_that_all_fields_are_given_values(thd, table, table_list)) { error= 1; goto values_loop_end;