From 2aad30394d33eef23545d717f4b92eb280c2b19d Mon Sep 17 00:00:00 2001
From: unknown <bell@sanja.is.com.ua>
Date: Thu, 21 Oct 2004 14:32:10 +0300
Subject: [PATCH] inserting single value with check option failed always get
 error (part of BUG#5995)

mysql-test/r/view.result:
  inserting single value with check option failed always get error
mysql-test/t/view.test:
  inserting single value with check option failed always get error
sql/sql_insert.cc:
  inserting single value with check option failed always get error
---
 mysql-test/r/view.result | 12 ++++++++++++
 mysql-test/t/view.test   | 15 +++++++++++++++
 sql/sql_insert.cc        |  5 ++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 2e5d7073c5..c9581598de 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -1535,3 +1535,15 @@ insert into v2 values (0);
 ERROR HY000: CHECK OPTION failed 'test.v2'
 drop view v2, v1;
 drop table t1;
+create table t1 (s1 int);
+create view v1 as select * from t1 where s1 < 5 with check option;
+insert ignore into v1 values (6);
+ERROR HY000: CHECK OPTION failed 'test.v1'
+insert ignore into v1 values (6),(3);
+Warnings:
+Error	1369	CHECK OPTION failed 'test.v1'
+select * from t1;
+s1
+3
+drop view v1;
+drop table t1;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 716ed4aa6b..282ea827c6 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -1482,3 +1482,18 @@ create view v2 as select * from v1 with cascaded check option;
 insert into v2 values (0);
 drop view v2, v1;
 drop table t1;
+
+#
+# inserting single value with check option failed always get error
+#
+create table t1 (s1 int);
+create view v1 as select * from t1 where s1 < 5 with check option;
+#single value
+-- error 1369
+insert ignore into v1 values (6);
+#several values
+insert ignore into v1 values (6),(3);
+select * from t1;
+drop view v1;
+drop table t1;
+
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 36ac56799d..2fe0d2f644 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -319,7 +319,10 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
 	break;
       }
     }
-    if ((res= table_list->view_check_option(thd, ignore_err)) ==
+    if ((res= table_list->view_check_option(thd,
+					    (values_list.elements == 1 ?
+					     0 :
+					     ignore_err))) ==
         VIEW_CHECK_SKIP)
       continue;
     else if (res == VIEW_CHECK_ERROR)
-- 
2.30.9