Commit 3431b217 authored by unknown's avatar unknown

Bug#7806 - insert on duplicate key and auto-update of timestamp

A fix of the original patch.
Correctly clear a bit from an enum value.

parent cfac923c
...@@ -80,7 +80,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List<Item> &fields, ...@@ -80,7 +80,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List<Item> &fields,
check_grant_all_columns(thd,INSERT_ACL,table)) check_grant_all_columns(thd,INSERT_ACL,table))
return -1; return -1;
#endif #endif
*(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; clear_timestamp_auto_bits(table->timestamp_field_type,
TIMESTAMP_AUTO_SET_ON_INSERT);
} }
else else
{ // Part field list { // Part field list
...@@ -110,7 +111,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List<Item> &fields, ...@@ -110,7 +111,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List<Item> &fields,
} }
if (table->timestamp_field && // Don't set timestamp if used if (table->timestamp_field && // Don't set timestamp if used
table->timestamp_field->query_id == thd->query_id) table->timestamp_field->query_id == thd->query_id)
*(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; clear_timestamp_auto_bits(table->timestamp_field_type,
TIMESTAMP_AUTO_SET_ON_INSERT);
} }
// For the values we need select_priv // For the values we need select_priv
#ifndef NO_EMBEDDED_ACCESS_CHECKS #ifndef NO_EMBEDDED_ACCESS_CHECKS
...@@ -167,7 +169,8 @@ static int check_update_fields(THD *thd, TABLE *table, ...@@ -167,7 +169,8 @@ static int check_update_fields(THD *thd, TABLE *table,
{ {
/* Don't set timestamp column if this is modified. */ /* Don't set timestamp column if this is modified. */
if (table->timestamp_field->query_id == thd->query_id) if (table->timestamp_field->query_id == thd->query_id)
*(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_UPDATE; clear_timestamp_auto_bits(table->timestamp_field_type,
TIMESTAMP_AUTO_SET_ON_UPDATE);
else else
table->timestamp_field->query_id= timestamp_query_id; table->timestamp_field->query_id= timestamp_query_id;
} }
......
...@@ -58,18 +58,22 @@ typedef struct st_filesort_info ...@@ -58,18 +58,22 @@ typedef struct st_filesort_info
/* /*
Values in this enum are used to indicate during which operations value Values in this enum are used to indicate how a tables TIMESTAMP field
of TIMESTAMP field should be set to current timestamp. should be treated. It can be set to the current timestamp on insert or
WARNING: The values are used for bit operations. If you change the enum, update or both.
you must keep the bitwise relation of the values. For example: WARNING: The values are used for bit operations. If you change the
(int) TIMESTAMP_AUTO_SET_ON_BOTH == enum, you must keep the bitwise relation of the values. For example:
(int) TIMESTAMP_AUTO_SET_ON_BOTH must be equal to
(int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE. (int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE.
We use an enum here so that the debugger can display the value names.
*/ */
enum timestamp_auto_set_type enum timestamp_auto_set_type
{ {
TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1, TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1,
TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3 TIMESTAMP_AUTO_SET_ON_UPDATE= 2, TIMESTAMP_AUTO_SET_ON_BOTH= 3
}; };
#define clear_timestamp_auto_bits(_target_, _bits_) \
(_target_)= (enum timestamp_auto_set_type)((int)(_target_) & ~(int)(_bits_))
/* Table cache entry struct */ /* Table cache entry struct */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment