diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result index a36536b878d..897fa77185d 100644 --- a/mysql-test/r/ndb_alter_table.result +++ b/mysql-test/r/ndb_alter_table.result @@ -72,6 +72,21 @@ col6 col1 col3 fourth col4 col4_5 col5 col7 col8 1 100 3 4 5 PENDING 0000-00-00 00:00:00 1 101 3 4 5 PENDING 0000-00-00 00:00:00 2 102 4 3 5 99 PENDING EXTRA 2004-01-01 00:00:00 +delete from t1; +insert into t1 values (0,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); +SET SQL_MODE=''; +insert into t1 values (1,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); +select * from t1 order by col1; +col6 col1 col3 fourth col4 col4_5 col5 col7 col8 +0 0 4 3 5 99 PENDING EXTRA 2004-01-01 00:00:00 +1 103 4 3 5 99 PENDING EXTRA 2004-01-01 00:00:00 +alter table t1 drop column col4_5; +insert into t1 values (2,0,4,3,5,"PENDING","EXTRA",'2004-01-01 00:00:00'); +select * from t1 order by col1; +col6 col1 col3 fourth col4 col5 col7 col8 +0 0 4 3 5 PENDING EXTRA 2004-01-01 00:00:00 +1 103 4 3 5 PENDING EXTRA 2004-01-01 00:00:00 +2 104 4 3 5 PENDING EXTRA 2004-01-01 00:00:00 drop table t1; CREATE TABLE t1 ( a INT NOT NULL, diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test index 96270d94dcb..9128d0c3811 100644 --- a/mysql-test/t/ndb_alter_table.test +++ b/mysql-test/t/ndb_alter_table.test @@ -47,6 +47,14 @@ select * from t1 order by col1; insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); show table status; select * from t1 order by col1; +delete from t1; +insert into t1 values (0,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); +SET SQL_MODE=''; +insert into t1 values (1,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00'); +select * from t1 order by col1; +alter table t1 drop column col4_5; +insert into t1 values (2,0,4,3,5,"PENDING","EXTRA",'2004-01-01 00:00:00'); +select * from t1 order by col1; drop table t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 65e26346834..6d7a4ff269d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3303,6 +3303,8 @@ copy_data_between_tables(TABLE *from,TABLE *to, List all_fields; ha_rows examined_rows; bool auto_increment_field_copied= 0; + ulong old_sql_mode; + bool no_auto_on_zero; DBUG_ENTER("copy_data_between_tables"); if (!(copy= new Copy_field[to->fields])) @@ -3361,6 +3363,11 @@ 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 */ @@ -3417,6 +3424,11 @@ copy_data_between_tables(TABLE *from,TABLE *to, to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); 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