Browse Source

Fixed DELETE issues of view over view over table.

pull/843/head
unknown 14 years ago
parent
commit
52d4103ccc
  1. 18
      mysql-test/r/view.result
  2. 14
      mysql-test/t/view.test
  3. 5
      sql/sql_delete.cc

18
mysql-test/r/view.result

@ -3943,12 +3943,20 @@ REPLACE v1 SET a = 10;
ERROR HY000: The target table v1 of the INSERT is not insertable-into
INSERT into v1 values (20);
ERROR HY000: The target table v1 of the INSERT is not insertable-into
DELETE from v1;
ERROR HY000: The target table v1 of the DELETE is not updatable
UPDATE v3 SET b= 10;
ERROR HY000: The target table v2 of the UPDATE is not updatable
REPLACE v3 SET b= 10;
ERROR HY000: The target table v3 of the INSERT is not insertable-into
INSERT into v3(b) values (20);
ERROR HY000: The target table v3 of the INSERT is not insertable-into
DELETE from v3 where b=20;
ERROR HY000: Can not delete from join view 'test.v3'
DELETE from v3 where a=20;
ERROR HY000: Can not delete from join view 'test.v3'
DELETE v1 from v1,t1 where v1.a=t1.a;
ERROR HY000: The target table v1 of the DELETE is not updatable
UPDATE v3 SET a = 10;
REPLACE v3 SET a = 11;
INSERT INTO v3(a) values (20);
@ -3960,6 +3968,16 @@ a
10
11
20
CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2;
DELETE from v1 where a=11;
DELETE v1 from v1,t1 where v1.a=t1.a;
select * from t1;
a
1
select * from t2;
a
10
20
DROP VIEW v1,v2,v3;
DROP TABLE t1,t2;
# -----------------------------------------------------------------

14
mysql-test/t/view.test

@ -3998,11 +3998,19 @@ REPLACE v1 SET a = 10;
--error ER_NON_INSERTABLE_TABLE
INSERT into v1 values (20);
--error ER_NON_UPDATABLE_TABLE
DELETE from v1;
--error ER_NON_UPDATABLE_TABLE
UPDATE v3 SET b= 10;
--error ER_NON_INSERTABLE_TABLE
REPLACE v3 SET b= 10;
--error ER_NON_INSERTABLE_TABLE
INSERT into v3(b) values (20);
--error ER_VIEW_DELETE_MERGE_VIEW
DELETE from v3 where b=20;
--error ER_VIEW_DELETE_MERGE_VIEW
DELETE from v3 where a=20;
--error ER_NON_UPDATABLE_TABLE
DELETE v1 from v1,t1 where v1.a=t1.a;
UPDATE v3 SET a = 10;
REPLACE v3 SET a = 11;
INSERT INTO v3(a) values (20);
@ -4010,6 +4018,12 @@ INSERT INTO v3(a) values (20);
select * from t1;
select * from t2;
CREATE OR REPLACE ALGORITHM = MERGE VIEW v2 AS SELECT * FROM t2;
DELETE from v1 where a=11;
DELETE v1 from v1,t1 where v1.a=t1.a;
select * from t1;
select * from t2;
DROP VIEW v1,v2,v3;
DROP TABLE t1,t2;

5
sql/sql_delete.cc

@ -508,7 +508,8 @@ int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds)
setup_conds(thd, table_list, select_lex->leaf_tables, conds) ||
setup_ftfuncs(select_lex))
DBUG_RETURN(TRUE);
if (!table_list->updatable || check_key_in_view(thd, table_list))
if (!table_list->single_table_updatable() ||
check_key_in_view(thd, table_list))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias, "DELETE");
DBUG_RETURN(TRUE);
@ -598,7 +599,7 @@ int mysql_multi_delete_prepare(THD *thd)
DBUG_RETURN(TRUE);
}
if (!target_tbl->correspondent_table->updatable ||
if (!target_tbl->correspondent_table->single_table_updatable() ||
check_key_in_view(thd, target_tbl->correspondent_table))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0),

Loading…
Cancel
Save