List:Internals« Previous MessageNext Message »
From:ingo Date:February 7 2005 9:51pm
Subject:bk commit into 4.1 tree (ingo:1.2175)
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of mydev. When mydev 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://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.2175 05/02/07 22:51:52 ingo@stripped +3 -0
  Bug#7806 - insert on duplicate key and auto-update of timestamp
  Added a check if the update fields contain the timestamp field.
  In case of a match, the auto update is disabled, since an explicit
  value is present.

  sql/sql_insert.cc
    1.155 05/02/07 22:51:17 ingo@stripped +42 -0
    Bug#7806 - insert on duplicate key and auto-update of timestamp
    Added a check if the update fields contain the timestamp field.
    In case of a match, the auto update is disabled, since an explicit
    value is present. This is called from mysql_prepare_insert().

  mysql-test/t/type_timestamp.test
    1.23 05/02/07 22:51:17 ingo@stripped +13 -0
    Bug#7806 - insert on duplicate key and auto-update of timestamp
    The test case.

  mysql-test/r/type_timestamp.result
    1.25 05/02/07 22:51:17 ingo@stripped +20 -0
    Bug#7806 - insert on duplicate key and auto-update of timestamp
    The test result.

# 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:	ingo
# Host:	chilla.local
# Root:	/home/mydev/mysql-4.1-bug7806

--- 1.154/sql/sql_insert.cc	Tue Jan 25 15:08:26 2005
+++ 1.155/sql/sql_insert.cc	Mon Feb  7 22:51:17 2005
@@ -106,6 +106,47 @@
 }
 
 
+/*
+  Check update fields for the timestamp field.
+
+  SYNOPSIS
+    check_update_fields()
+    table                       table for update
+    fields                      update fields
+
+  DESCRIPTION
+    If the update fields include the timestamp field,
+    remove TIMESTAMP_AUTO_SET_ON_UPDATE from table->timestamp_field_type.
+
+  RETURN
+    0           OK
+*/
+
+int check_update_fields(TABLE *table, List<Item> &fields)
+{
+  Item *item;
+  List_iterator<Item> it(fields);
+  DBUG_ENTER("check_update_fields");
+
+  if (table->timestamp_field)
+  {
+    while ((item= it++))
+    {
+      DBUG_ASSERT(item->type() == Item::FIELD_ITEM);
+      if (!my_strcasecmp(system_charset_info, ((Item_field*) item)->field_name,
+			 table->timestamp_field->field_name))
+      {
+        table->timestamp_field_type=
+          ((table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH) ||
+           (table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_INSERT)) ?
+          TIMESTAMP_AUTO_SET_ON_INSERT : TIMESTAMP_NO_AUTO_SET;
+      }
+    }
+  }
+  DBUG_RETURN(0);
+}
+
+
 int mysql_insert(THD *thd,TABLE_LIST *table_list,
                  List<Item> &fields,
                  List<List_item> &values_list,
@@ -454,6 +495,7 @@
       setup_tables(insert_table_list) ||
       (values && setup_fields(thd, 0, insert_table_list, *values, 0, 0, 0)) ||
       (duplic == DUP_UPDATE &&
+       ! check_update_fields(table, update_fields) &&
        (setup_fields(thd, 0, insert_table_list, update_fields, 1, 0, 0) ||
         setup_fields(thd, 0, insert_table_list, update_values, 1, 0, 0))))
     DBUG_RETURN(-1);

--- 1.24/mysql-test/r/type_timestamp.result	Tue Jan 11 12:26:37 2005
+++ 1.25/mysql-test/r/type_timestamp.result	Mon Feb  7 22:51:17 2005
@@ -432,3 +432,23 @@
 )
 set sql_mode='';
 drop table t1;
+create table t1 (a int auto_increment primary key, b int, c timestamp);
+insert into t1 (a, b, c) values (1, 0, 0), (2, 0, 0), (3, 0, 0);
+select * from t1;
+a	b	c
+1	0	0000-00-00 00:00:00
+2	0	0000-00-00 00:00:00
+3	0	0000-00-00 00:00:00
+update t1 set b = 2, c = c where a = 2;
+select * from t1;
+a	b	c
+1	0	0000-00-00 00:00:00
+2	2	0000-00-00 00:00:00
+3	0	0000-00-00 00:00:00
+insert into t1 (a) values (3) on duplicate key update b = 3, c = c;
+select * from t1;
+a	b	c
+1	0	0000-00-00 00:00:00
+2	2	0000-00-00 00:00:00
+3	3	0000-00-00 00:00:00
+drop table t1;

--- 1.22/mysql-test/t/type_timestamp.test	Tue Jan 11 12:26:37 2005
+++ 1.23/mysql-test/t/type_timestamp.test	Mon Feb  7 22:51:17 2005
@@ -298,3 +298,16 @@
 # restore default mode
 set sql_mode='';
 drop table t1;
+
+#
+# Bug#7806 - 
+#
+create table t1 (a int auto_increment primary key, b int, c timestamp);
+insert into t1 (a, b, c) values (1, 0, 0), (2, 0, 0), (3, 0, 0);
+select * from t1;
+update t1 set b = 2, c = c where a = 2;
+select * from t1;
+insert into t1 (a) values (3) on duplicate key update b = 3, c = c;
+select * from t1;
+drop table t1;
+
Thread
bk commit into 4.1 tree (ingo:1.2175)ingo7 Feb