Commit 2c8aa3bb authored by unknown's avatar unknown

Allow inheriting check options if view have not WHERE clause (BUG#5988)


mysql-test/r/view.result:
  test of cascaded check option for whiew without WHERE clause
mysql-test/t/view.test:
  test of cascaded check option for whiew without WHERE clause
sql/table.cc:
  Allow inheriting check options if view have not WHERE clause
parent 55f12a29
......@@ -1528,3 +1528,10 @@ substring_index(t,':',2)
12:24
drop view v1;
drop table t1;
create table t1 (s1 tinyint);
create view v1 as select * from t1 where s1 <> 0 with local check option;
create view v2 as select * from v1 with cascaded check option;
insert into v2 values (0);
ERROR HY000: CHECK OPTION failed 'test.v2'
drop view v2, v1;
drop table t1;
......@@ -1471,3 +1471,14 @@ select substring_index(t,':',2) from t1;
select substring_index(t,':',2) from v1;
drop view v1;
drop table t1;
#
# test of cascaded check option for whiew without WHERE clause
#
create table t1 (s1 tinyint);
create view v1 as select * from t1 where s1 <> 0 with local check option;
create view v2 as select * from v1 with cascaded check option;
-- error 1369
insert into v2 values (0);
drop view v2, v1;
drop table t1;
......@@ -1586,14 +1586,16 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
field_translation= transl;
/* TODO: sort this list? Use hash for big number of fields */
if (where)
if (where ||
(effective_with_check == VIEW_CHECK_CASCADED &&
ancestor->check_option))
{
Item_arena *arena= thd->current_arena, backup;
TABLE_LIST *tbl= this;
if (arena->is_conventional())
arena= 0; // For easier test
if (!where->fixed && where->fix_fields(thd, ancestor, &where))
if (where && !where->fixed && where->fix_fields(thd, ancestor, &where))
goto err;
if (arena)
......@@ -1601,6 +1603,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
if (effective_with_check)
{
if (where)
check_option= where->copy_andor_structure(thd);
if (effective_with_check == VIEW_CHECK_CASCADED)
{
......@@ -1612,7 +1615,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
check that it is not VIEW in which we insert with INSERT SELECT
(in this case we can't add view WHERE condition to main SELECT_LEX)
*/
if (!no_where_clause)
if (where && !no_where_clause)
{
/* Go up to join tree and try to find left join */
for (; tbl; tbl= tbl->embedding)
......
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