From 0c23f81dcb395091c7361254df419555117d0d7f Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Thu, 21 Apr 2005 21:47:58 +0200 Subject: [PATCH 1/2] C99 Portability fix --- sql/sql_insert.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index bb115b9d548..96d94127316 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -80,7 +80,7 @@ static int check_insert_fields(THD *thd, TABLE *table, List &fields, check_grant_all_columns(thd,INSERT_ACL,table)) return -1; #endif - (int) table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; + *(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; } else { // Part field list @@ -110,7 +110,7 @@ static int check_insert_fields(THD *thd, TABLE *table, List &fields, } if (table->timestamp_field && // Don't set timestamp if used table->timestamp_field->query_id == thd->query_id) - (int) table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; + *(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_INSERT; } // For the values we need select_priv #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -167,7 +167,7 @@ static int check_update_fields(THD *thd, TABLE *table, { /* Don't set timestamp column if this is modified. */ if (table->timestamp_field->query_id == thd->query_id) - (int) table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_UPDATE; + *(int*)&table->timestamp_field_type&= ~ (int) TIMESTAMP_AUTO_SET_ON_UPDATE; else table->timestamp_field->query_id= timestamp_query_id; } From 0e7f6a601f9e1d32d09a53364bd7d2388851721e Mon Sep 17 00:00:00 2001 From: "ingo@mysql.com" <> Date: Fri, 22 Apr 2005 12:30:09 +0200 Subject: [PATCH 2/2] 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. --- sql/sql_insert.cc | 9 ++++++--- sql/table.h | 16 ++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 96d94127316..7f890a583c6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -80,7 +80,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List &fields, check_grant_all_columns(thd,INSERT_ACL,table)) return -1; #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 { // Part field list @@ -110,7 +111,8 @@ static int check_insert_fields(THD *thd, TABLE *table, List &fields, } if (table->timestamp_field && // Don't set timestamp if used 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 #ifndef NO_EMBEDDED_ACCESS_CHECKS @@ -167,7 +169,8 @@ static int check_update_fields(THD *thd, TABLE *table, { /* Don't set timestamp column if this is modified. */ 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 table->timestamp_field->query_id= timestamp_query_id; } diff --git a/sql/table.h b/sql/table.h index e822d68531e..77153e5d8cd 100644 --- a/sql/table.h +++ b/sql/table.h @@ -58,18 +58,22 @@ typedef struct st_filesort_info /* - Values in this enum are used to indicate during which operations value - of TIMESTAMP field should be set to current timestamp. - WARNING: The values are used for bit operations. If you change the enum, - you must keep the bitwise relation of the values. For example: - (int) TIMESTAMP_AUTO_SET_ON_BOTH == - (int) TIMESTAMP_AUTO_SET_ON_INSERT | (int) TIMESTAMP_AUTO_SET_ON_UPDATE. + Values in this enum are used to indicate how a tables TIMESTAMP field + should be treated. It can be set to the current timestamp on insert or + update or both. + WARNING: The values are used for bit operations. If you change the + 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. + We use an enum here so that the debugger can display the value names. */ enum timestamp_auto_set_type { TIMESTAMP_NO_AUTO_SET= 0, TIMESTAMP_AUTO_SET_ON_INSERT= 1, 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 */