MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:July 4 2006 9:10am
Subject:bk commit into 5.0 tree (gkodinov:1.2197) BUG#16110
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2197 06/07/04 12:10:12 gkodinov@stripped +3 -0
  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.

  sql/sql_insert.cc
    1.193 06/07/04 12:09:56 gkodinov@stripped +14 -1
    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.

  mysql-test/t/view.test
    1.148 06/07/04 12:09:56 gkodinov@stripped +19 -1
    Bug #16110: insert permitted into view col w/o default value
      * test case

  mysql-test/r/view.result
    1.162 06/07/04 12:09:56 gkodinov@stripped +15 -1
    Bug #16110: insert permitted into view col w/o default value
      * test case

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gkodinov
# Host:	rakia.(none)
# Root:	/home/kgeorge/mysql/5.0/B16110

--- 1.192/sql/sql_insert.cc	2006-06-19 15:57:36 +03:00
+++ 1.193/sql/sql_insert.cc	2006-07-04 12:09:56 +03:00
@@ -675,6 +675,7 @@
   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 @@
   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 @@
     */
     trans->item= field;
   }
+  thd->set_query_id= save_set_query_id;
   /* unique test */
   for (trans= trans_start; trans != trans_end; trans++)
   {

--- 1.161/mysql-test/r/view.result	2006-06-01 08:55:39 +03:00
+++ 1.162/mysql-test/r/view.result	2006-07-04 12:09:56 +03:00
@@ -2735,4 +2735,18 @@
 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;

--- 1.147/mysql-test/t/view.test	2006-06-01 08:55:39 +03:00
+++ 1.148/mysql-test/t/view.test	2006-07-04 12:09:56 +03:00
@@ -2595,4 +2595,22 @@
 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;
Thread
bk commit into 5.0 tree (gkodinov:1.2197) BUG#16110kgeorge4 Jul