diff options
author | dlenev@brandersnatch.localdomain <> | 2004-10-07 13:02:39 +0400 |
---|---|---|
committer | dlenev@brandersnatch.localdomain <> | 2004-10-07 13:02:39 +0400 |
commit | 1f54900630636f502a4dbf16faefb4e132db0d3f (patch) | |
tree | fe89ee02ecc0b2b98bcca9915320aa37cb8ff4c9 /sql/sql_table.cc | |
parent | 96458f8f64641d5b974a17733af8c709b513bfe0 (diff) | |
download | mariadb-git-1f54900630636f502a4dbf16faefb4e132db0d3f.tar.gz |
Fix for bug #5915 "ALTER TABLE behaves differently when converting column
to auto_increment in 4.1".
Now we are enforcing NO_AUTO_VALUE_ON_ZERO mode during ALTER TABLE only
if we are converting one auto_increment column to another auto_increment
column (this also includes most common case when we don't do anything
with such column).
Also now when we convert some column to TIMESTAMP NOT NULL column with
ALTER TABLE we convert NULL values to current timestamp, (as we do this
in INSERT). One can still get old behavior by setting system TIMESTAMP
variable to 0.
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3d5aaf0c2ec..7505dec0ab6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3300,13 +3300,14 @@ copy_data_between_tables(TABLE *from,TABLE *to, List<Item> all_fields; ha_rows examined_rows; bool auto_increment_field_copied= 0; - ulong old_sql_mode; - bool no_auto_on_zero; + ulong save_sql_mode; DBUG_ENTER("copy_data_between_tables"); if (!(copy= new Copy_field[to->fields])) DBUG_RETURN(-1); /* purecov: inspected */ + save_sql_mode= thd->variables.sql_mode; + to->file->external_lock(thd,F_WRLCK); from->file->info(HA_STATUS_VARIABLE); to->file->start_bulk_insert(from->file->records); @@ -3320,7 +3321,17 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (def->field) { if (*ptr == to->next_number_field) + { auto_increment_field_copied= TRUE; + /* + If we are going to copy contents of one auto_increment column to + another auto_increment column it is sensible to preserve zeroes. + This condition also covers case when we are don't actually alter + auto_increment column. + */ + if (def->field == from->found_next_number_field) + thd->variables.sql_mode|= MODE_NO_AUTO_VALUE_ON_ZERO; + } (copy_end++)->set(*ptr,def->field,0); } @@ -3360,11 +3371,6 @@ copy_data_between_tables(TABLE *from,TABLE *to, goto err; } - /* Turn on NO_AUTO_VALUE_ON_ZERO if not already on */ - old_sql_mode= thd->variables.sql_mode; - if (!(no_auto_on_zero= thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)) - thd->variables.sql_mode|= MODE_NO_AUTO_VALUE_ON_ZERO; - /* Handler must be told explicitly to retrieve all columns, because this function does not set field->query_id in the columns to the current query id */ @@ -3422,10 +3428,6 @@ copy_data_between_tables(TABLE *from,TABLE *to, ha_enable_transaction(thd,TRUE); - /* Turn off NO_AUTO_VALUE_ON_ZERO if it was not already off */ - if (!no_auto_on_zero) - thd->variables.sql_mode= old_sql_mode; - /* Ensure that the new table is saved properly to disk so that we can do a rename @@ -3437,6 +3439,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (to->file->external_lock(thd,F_UNLCK)) error=1; err: + thd->variables.sql_mode= save_sql_mode; free_io_cache(from); *copied= found_count; *deleted=delete_count; |