Commit 3609c3a4 authored by unknown's avatar unknown

Fixed bug #25931.

View check option clauses were ignored for updates of multi-table
views when the updates could not be performed on fly and the rows
to update had to be put into temporary tables first.



mysql-test/r/view.result:
  Added a test case for bug #25931.
mysql-test/t/view.test:
  Added a test case for bug #25931.
  Adjusted another existed test case to have the correct result.
sql/sql_update.cc:
  Fixed bug #25931.
  View check option clauses were ignored for updates of multi-table
  views when the updates could not be performed on fly and the rows
  to update had to be put into temporary tables first.
  Added the required check to multi_update::do_updates to fix the problem.
parent 3a54e593
......@@ -2543,7 +2543,7 @@ create table t1(f1 int, f2 int);
create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb
.f1 and ta.f2=tb.f2;
insert into t1 values(1,1),(2,2);
create view v2 as select * from v1 where a > 1 with check option;
create view v2 as select * from v1 where a > 1 with local check option;
select * from v2;
a b
2 2
......@@ -3052,4 +3052,30 @@ mydate
2007-01-31 00:00:00
DROP VIEW v1;
DROP TABLE t1;
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1), (2);
CREATE VIEW v1 AS
SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION;
SELECT * FROM v1;
b
1
2
UPDATE v1 SET b=3;
ERROR HY000: CHECK OPTION failed 'test.v1'
SELECT * FROM v1;
b
1
2
SELECT * FROM t1;
a
1
2
SELECT * FROM t2;
b
1
2
DROP VIEW v1;
DROP TABLE t1,t2;
End of 5.0 tests.
......@@ -2385,7 +2385,7 @@ create table t1(f1 int, f2 int);
create view v1 as select ta.f1 as a, tb.f1 as b from t1 ta, t1 tb where ta.f1=tb
.f1 and ta.f2=tb.f2;
insert into t1 values(1,1),(2,2);
create view v2 as select * from v1 where a > 1 with check option;
create view v2 as select * from v1 where a > 1 with local check option;
select * from v2;
update v2 set b=3 where a=2;
select * from v2;
......@@ -3002,4 +3002,26 @@ SELECT * FROM v1 WHERE mydate BETWEEN '2007-01-01' AND '2007-01-31';
DROP VIEW v1;
DROP TABLE t1;
#
# Bug #25931: update of a multi-table view with check option
#
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
INSERT INTO t1 VALUES (1), (2);
INSERT INTO t2 VALUES (1), (2);
CREATE VIEW v1 AS
SELECT t2.b FROM t1,t2 WHERE t1.a = t2.b WITH CHECK OPTION;
SELECT * FROM v1;
--error 1369
UPDATE v1 SET b=3;
SELECT * FROM v1;
SELECT * FROM t1;
SELECT * FROM t2;
DROP VIEW v1;
DROP TABLE t1,t2;
--echo End of 5.0 tests.
......@@ -1445,6 +1445,15 @@ int multi_update::do_updates(bool from_send_error)
if (!can_compare_record || compare_record(table, thd->query_id))
{
int error;
if ((error= cur_table->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK)
{
if (error == VIEW_CHECK_SKIP)
continue;
else if (error == VIEW_CHECK_ERROR)
goto err;
}
if ((local_error=table->file->update_row(table->record[1],
table->record[0])))
{
......
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