1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-31 22:22:30 +03:00

BUG#22584: last_insert_id not updated after inserting a record through

a updatable view.

When there's a VIEW on a base table that have AUTO_INCREMENT column, and
this VIEW doesn't provide an access such column, after INSERT to such
VIEW LAST_INSERT_ID() did not return the value just generated.

This behaviour is intended and correct, because if the VIEW doesn't list
some columns then these columns are effectively hidden from the user,
and so any side effects of inserting default values to them.

However, there was a bug that such statement inserting into a view would
reset LAST_INSERT_ID() instead of leaving it unchanged.

This patch restores the original value of LAST_INSERT_ID() instead of
resetting it to zero.
This commit is contained in:
kroki/tomash@moonlight.intranet
2006-10-27 13:32:41 +04:00
parent 643606cac9
commit 0e0f7a0423
3 changed files with 89 additions and 2 deletions

View File

@@ -3369,8 +3369,16 @@ end_with_restore_list:
res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values,
lex->update_list, lex->value_list,
lex->duplicates, lex->ignore);
/*
If we have inserted into a VIEW, and the base table has
AUTO_INCREMENT column, but this column is not accessible through
a view, then we should restore LAST_INSERT_ID to the value it
had before the statement.
*/
if (first_table->view && !first_table->contain_auto_increment)
thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it
thd->last_insert_id= thd->current_insert_id;
break;
}
case SQLCOM_REPLACE_SELECT:
@@ -3431,8 +3439,15 @@ end_with_restore_list:
select_lex->table_list.first= (byte*) first_table;
}
/*
If we have inserted into a VIEW, and the base table has
AUTO_INCREMENT column, but this column is not accessible through
a view, then we should restore LAST_INSERT_ID to the value it
had before the statement.
*/
if (first_table->view && !first_table->contain_auto_increment)
thd->last_insert_id= 0; // do not show last insert ID if VIEW have not it
thd->last_insert_id= thd->current_insert_id;
break;
}
case SQLCOM_TRUNCATE: