summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/view.result77
-rw-r--r--mysql-test/t/view.test70
2 files changed, 143 insertions, 4 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 35b76a8ab4b..1560a4be208 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -477,8 +477,10 @@ drop view v1;
drop table t1;
create table t1 (a int);
create view v1 as select distinct a from t1 WITH CHECK OPTION;
-create view v2 as select distinct a from t1 WITH CASCADED CHECK OPTION;
-create view v3 as select distinct a from t1 WITH LOCAL CHECK OPTION;
+ERROR HY000: CHECK OPTION on non-updatable view
+create view v1 as select a from t1 WITH CHECK OPTION;
+create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
+create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
drop view v3 RESTRICT;
drop view v2 CASCADE;
drop view v1;
@@ -1270,3 +1272,74 @@ s1
7
drop view v1;
drop table t1;
+create table t1 (a int);
+create view v1 as select * from t1 where a < 2 with check option;
+insert into v1 values(1);
+insert into v1 values(3);
+ERROR HY000: CHECK OPTION failed
+insert ignore into v1 values (2),(3),(0);
+Warnings:
+Error 1359 CHECK OPTION failed
+Error 1359 CHECK OPTION failed
+select * from t1;
+a
+1
+0
+delete from t1;
+insert into v1 SELECT 1;
+insert into v1 SELECT 3;
+ERROR HY000: CHECK OPTION failed
+create table t2 (a int);
+insert into t2 values (2),(3),(0);
+insert ignore into v1 SELECT a from t2;
+Warnings:
+Error 1359 CHECK OPTION failed
+Error 1359 CHECK OPTION failed
+select * from t1;
+a
+1
+0
+update v1 set a=-1 where a=0;
+update v1 set a=2 where a=1;
+ERROR HY000: CHECK OPTION failed
+select * from t1;
+a
+1
+-1
+update v1 set a=0 where a=0;
+insert into t2 values (1);
+update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a;
+select * from t1;
+a
+0
+-1
+update v1 set a=a+1;
+update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
+Warnings:
+Error 1359 CHECK OPTION failed
+select * from t1;
+a
+1
+1
+drop view v1;
+drop table t1, t2;
+create table t1 (a int);
+create view v1 as select * from t1 where a < 2 with check option;
+create view v2 as select * from v1 where a > 0 with local check option;
+create view v3 as select * from v1 where a > 0 with cascaded check option;
+insert into v2 values (1);
+insert into v3 values (1);
+insert into v2 values (0);
+ERROR HY000: CHECK OPTION failed
+insert into v3 values (0);
+ERROR HY000: CHECK OPTION failed
+insert into v2 values (2);
+insert into v3 values (2);
+ERROR HY000: CHECK OPTION failed
+select * from t1;
+a
+1
+1
+2
+drop view v3,v2,v1;
+drop table t1;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 9464e291e05..87637fab826 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -392,9 +392,11 @@ drop table t1;
# syntax compatibility
#
create table t1 (a int);
+-- error 1358
create view v1 as select distinct a from t1 WITH CHECK OPTION;
-create view v2 as select distinct a from t1 WITH CASCADED CHECK OPTION;
-create view v3 as select distinct a from t1 WITH LOCAL CHECK OPTION;
+create view v1 as select a from t1 WITH CHECK OPTION;
+create view v2 as select a from t1 WITH CASCADED CHECK OPTION;
+create view v3 as select a from t1 WITH LOCAL CHECK OPTION;
drop view v3 RESTRICT;
drop view v2 CASCADE;
drop view v1;
@@ -1230,3 +1232,67 @@ insert into v1 values (1) on duplicate key update s1 = 7;
select * from t1;
drop view v1;
drop table t1;
+
+#
+# WITH CHECK OPTION insert/update test
+#
+create table t1 (a int);
+create view v1 as select * from t1 where a < 2 with check option;
+# simple insert
+insert into v1 values(1);
+-- error 1359
+insert into v1 values(3);
+# simple insert with ignore
+insert ignore into v1 values (2),(3),(0);
+select * from t1;
+# prepare data for next check
+delete from t1;
+# INSERT SELECT test
+insert into v1 SELECT 1;
+-- error 1359
+insert into v1 SELECT 3;
+# prepare data for next check
+create table t2 (a int);
+insert into t2 values (2),(3),(0);
+# INSERT SELECT with ignore test
+insert ignore into v1 SELECT a from t2;
+select * from t1;
+#simple UPDATE test
+update v1 set a=-1 where a=0;
+-- error 1359
+update v1 set a=2 where a=1;
+select * from t1;
+# prepare data for next check
+update v1 set a=0 where a=0;
+insert into t2 values (1);
+# multiupdate test
+update v1,t2 set v1.a=v1.a-1 where v1.a=t2.a;
+select * from t1;
+# prepare data for next check
+update v1 set a=a+1;
+# multiupdate with ignore test
+update ignore v1,t2 set v1.a=v1.a+1 where v1.a=t2.a;
+select * from t1;
+
+drop view v1;
+drop table t1, t2;
+
+#
+# CASCADED/LOCAL CHECK OPTION test
+#
+create table t1 (a int);
+create view v1 as select * from t1 where a < 2 with check option;
+create view v2 as select * from v1 where a > 0 with local check option;
+create view v3 as select * from v1 where a > 0 with cascaded check option;
+insert into v2 values (1);
+insert into v3 values (1);
+-- error 1359
+insert into v2 values (0);
+-- error 1359
+insert into v3 values (0);
+insert into v2 values (2);
+-- error 1359
+insert into v3 values (2);
+select * from t1;
+drop view v3,v2,v1;
+drop table t1;