diff options
-rw-r--r-- | mysql-test/r/view.result | 16 | ||||
-rw-r--r-- | mysql-test/t/view.test | 14 | ||||
-rw-r--r-- | sql/sql_insert.cc | 3 |
3 files changed, 32 insertions, 1 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 0e3d650c571..fb36304e562 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3602,4 +3602,20 @@ DROP VIEW v1; DROP VIEW v2; DROP VIEW v3; DROP TABLE t1; +# +# Bug#29477: Not all fields of the target table were checked to have +# a default value when inserting into a view. +# +create table t1(f1 int, f2 int not null); +create view v1 as select f1 from t1; +insert into v1 values(1); +Warnings: +Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value +set @old_mode=@@sql_mode; +set @@sql_mode=traditional; +insert into v1 values(1); +ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value +set @@sql_mode=@old_mode; +drop view v1; +drop table t1; End of 5.0 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 0faa8e7a785..340a34db5a1 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3456,5 +3456,19 @@ DROP VIEW v2; DROP VIEW v3; DROP TABLE t1; +--echo # +--echo # Bug#29477: Not all fields of the target table were checked to have +--echo # a default value when inserting into a view. +--echo # +create table t1(f1 int, f2 int not null); +create view v1 as select f1 from t1; +insert into v1 values(1); +set @old_mode=@@sql_mode; +set @@sql_mode=traditional; +--error ER_NO_DEFAULT_FOR_VIEW_FIELD +insert into v1 values(1); +set @@sql_mode=@old_mode; +drop view v1; +drop table t1; --echo End of 5.0 tests. diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index cf9e93b8518..14292f1cd9d 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -630,7 +630,8 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list, if (mysql_prepare_insert(thd, table_list, table, fields, values, update_fields, update_values, duplic, &unused_conds, FALSE, - (fields.elements || !value_count), + (fields.elements || !value_count || + table_list->view != 0), !ignore && (thd->variables.sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))) |