Commit 5da7c346 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-9428 NO_AUTO_VALUE_ON_ZERO is ignored when a trigger before insert is defined

Don't compare "field == table->next_number_field" because the field
can be special nullable field copy created by the trigger.
Compare field_index values instead.
parent 68910e70
......@@ -309,3 +309,16 @@ a b c
1 1 1
2 5 3
drop table t1;
set session sql_mode ='no_auto_value_on_zero';
create table t1 (id int unsigned auto_increment primary key);
insert t1 values (0);
select * from t1;
id
0
delete from t1;
create trigger t1_bi before insert on t1 for each row begin end;
insert t1 values (0);
select * from t1;
id
0
drop table t1;
......@@ -325,3 +325,17 @@ insert t1 values (9, 9, 2);
insert t1 (a,c) values (9, 3);
select * from t1;
drop table t1;
#
# MDEV-9428 NO_AUTO_VALUE_ON_ZERO is ignored when a trigger before insert is defined
#
set session sql_mode ='no_auto_value_on_zero';
create table t1 (id int unsigned auto_increment primary key);
insert t1 values (0);
select * from t1;
delete from t1;
create trigger t1_bi before insert on t1 for each row begin end;
insert t1 values (0);
select * from t1;
drop table t1;
......@@ -8962,6 +8962,9 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
Item *value;
Field *field;
bool abort_on_warning_saved= thd->abort_on_warning;
uint autoinc_index= table->next_number_field
? table->next_number_field->field_index
: ~0U;
DBUG_ENTER("fill_record");
if (!*ptr)
......@@ -8987,7 +8990,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
DBUG_ASSERT(field->table == table);
value=v++;
if (field == table->next_number_field)
if (field->field_index == autoinc_index)
table->auto_increment_field_not_null= TRUE;
if (field->vcol_info &&
value->type() != Item::DEFAULT_VALUE_ITEM &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment