summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <gkodinov@mysql.com>2006-07-04 12:10:12 +0300
committerunknown <gkodinov@mysql.com>2006-07-04 12:10:12 +0300
commite08ff11534c4ca13eea46590841fc38ec72b3462 (patch)
treec001611fa67848fb8274ad02405452540a1b33f7
parentd0412ab8e01e8410bc6b78bd33cdb844dc580a40 (diff)
downloadmariadb-git-e08ff11534c4ca13eea46590841fc38ec72b3462.tar.gz
Bug #16110: insert permitted into view col w/o default value
When compiling INSERT statements the check whether columns are provided values depends on the flag whether a field is used in that query (Field::query_id). However the check for updatability of VIEW columns (check_view_insertability()) was calling fix_fields() and thus setting the Field::query_id even for the view fields that are not referenced in the current INSERT statement. So the correct check for columns without default values ( check_that_all_fields_are_given_values() ) is assuming that all the VIEW columns were mentioned in the INSERT field list and was issuing no warnings or errors. Fixed check_view_insertability() to turn off the flag whether or not to set Field::query_id (THREAD::set_query_id) before calling fix fields and restore it when it's done. mysql-test/r/view.result: Bug #16110: insert permitted into view col w/o default value * test case mysql-test/t/view.test: Bug #16110: insert permitted into view col w/o default value * test case sql/sql_insert.cc: Bug #16110: insert permitted into view col w/o default value * avoid setting the "field used" flag for fields when checking view columns for updatability. * a missing DBUG_RETURN added.
-rw-r--r--mysql-test/r/view.result16
-rw-r--r--mysql-test/t/view.test20
-rw-r--r--sql/sql_insert.cc15
3 files changed, 48 insertions, 3 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 5bb407f4256..3cb89a995a1 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -2735,4 +2735,18 @@ m e
4 a
1 b
DROP VIEW v1;
-DROP TABLE IF EXISTS t1,t2;
+DROP TABLE t1,t2;
+CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
+CREATE VIEW v1 AS SELECT a, b FROM t1;
+INSERT INTO v1 (b) VALUES (2);
+Warnings:
+Warning 1423 Field of view 'test.v1' underlying table doesn't have a default value
+SET SQL_MODE = STRICT_ALL_TABLES;
+INSERT INTO v1 (b) VALUES (4);
+ERROR HY000: Field of view 'test.v1' underlying table doesn't have a default value
+SET SQL_MODE = '';
+SELECT * FROM t1;
+a b
+0 2
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index a1c1e9b2ad1..18ba85d3408 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2595,4 +2595,22 @@ CREATE TABLE t2 SELECT * FROM v1;
SELECT * FROM t2;
DROP VIEW v1;
-DROP TABLE IF EXISTS t1,t2;
+DROP TABLE t1,t2;
+
+#
+# Bug#16110: insert permitted into view col w/o default value
+#
+CREATE TABLE t1 (a INT NOT NULL, b INT NULL DEFAULT NULL);
+CREATE VIEW v1 AS SELECT a, b FROM t1;
+
+INSERT INTO v1 (b) VALUES (2);
+
+SET SQL_MODE = STRICT_ALL_TABLES;
+--error 1423
+INSERT INTO v1 (b) VALUES (4);
+SET SQL_MODE = '';
+
+SELECT * FROM t1;
+
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 8ffc6f53a43..26521fd65a6 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -675,6 +675,7 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
uint used_fields_buff_size= (table->s->fields + 7) / 8;
uchar *used_fields_buff= (uchar*)thd->alloc(used_fields_buff_size);
MY_BITMAP used_fields;
+ bool save_set_query_id= thd->set_query_id;
DBUG_ENTER("check_key_in_view");
if (!used_fields_buff)
@@ -687,15 +688,26 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
bitmap_clear_all(&used_fields);
view->contain_auto_increment= 0;
+ /*
+ we must not set query_id for fields as they're not
+ really used in this context
+ */
+ thd->set_query_id= 0;
/* check simplicity and prepare unique test of view */
for (trans= trans_start; trans != trans_end; trans++)
{
if (!trans->item->fixed && trans->item->fix_fields(thd, &trans->item))
- return TRUE;
+ {
+ thd->set_query_id= save_set_query_id;
+ DBUG_RETURN(TRUE);
+ }
Item_field *field;
/* simple SELECT list entry (field without expression) */
if (!(field= trans->item->filed_for_view_update()))
+ {
+ thd->set_query_id= save_set_query_id;
DBUG_RETURN(TRUE);
+ }
if (field->field->unireg_check == Field::NEXT_NUMBER)
view->contain_auto_increment= 1;
/* prepare unique test */
@@ -705,6 +717,7 @@ static bool check_view_insertability(THD * thd, TABLE_LIST *view)
*/
trans->item= field;
}
+ thd->set_query_id= save_set_query_id;
/* unique test */
for (trans= trans_start; trans != trans_end; trans++)
{