Commit 608104cc authored by jan@hundin.mysql.fi's avatar jan@hundin.mysql.fi

Fixed a bug no error message for ALTER with InnoDB and AUTO_INCREMENT (Bug #7061).

parent dafb2969
......@@ -1326,7 +1326,13 @@ innobase_commit(
&innodb_dummy_stmt_trx_handle: the latter means
that the current SQL statement ended */
{
trx_t* trx;
trx_t* trx;
dict_table_t* table;
ib_longlong auto_inc_value;
ib_longlong aic_new;
char table_name[1000];
ulint db_name_len;
ulint table_name_len;
DBUG_ENTER("innobase_commit");
DBUG_PRINT("trans", ("ending transaction"));
......@@ -1361,6 +1367,41 @@ innobase_commit(
"InnoDB: but trx->conc_state != TRX_NOT_STARTED\n");
}
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
(thd->lex->create_info.used_fields & HA_CREATE_USED_AUTO) &&
(thd->lex->create_info.auto_increment_value != 0)) {
/* Query was ALTER TABLE...AUTO_INC = x; Find out a table
definition from the dictionary and get the current value
of the auto increment field. Set a new value to the
auto increment field if the new value is creater than
the current value. */
aic_new = thd->lex->create_info.auto_increment_value;
db_name_len = strlen(thd->lex->query_tables->db);
table_name_len = strlen(thd->lex->query_tables->real_name);
ut_ad((db_name_len + 1 + table_name_len) < 999);
strcpy(table_name, thd->lex->query_tables->db);
strcat(table_name, "/");
strcat(table_name, thd->lex->query_tables->real_name);
table = dict_table_get(table_name, trx);
if (table) {
auto_inc_value = dict_table_autoinc_peek(table);
if( auto_inc_value < aic_new) {
/* We have to decrease the new auto increment
value by one because this function will increase
the value given by one. */
dict_table_autoinc_update(table, aic_new - 1);
}
}
}
if (trx_handle != (void*)&innodb_dummy_stmt_trx_handle
|| (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))) {
......
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