summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
authorunknown <kroki/tomash@moonlight.intranet>2006-10-27 13:32:41 +0400
committerunknown <kroki/tomash@moonlight.intranet>2006-10-27 13:32:41 +0400
commit532735e6c8fa330e256149f0c0d94822596ac18c (patch)
treef7955edb63dda0461a6a2c83c233ced3454ba26c /sql/sql_parse.cc
parent8db4dc3f91dfbe03181e63ed45bdf35a5d65aeb0 (diff)
downloadmariadb-git-532735e6c8fa330e256149f0c0d94822596ac18c.tar.gz
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. mysql-test/r/view.result: Add result for bug#22584: last_insert_id not updated after inserting a record through a updatable view. mysql-test/t/view.test: Add test case for bug#22584: last_insert_id not updated after inserting a record through a updatable view. sql/sql_parse.cc: When we have inserted into a view, and AUTO_INCREMENT column is not accessed from this view, instead of setting LAST_INSERT_ID to zero set it to the value it had before this statement was executed.
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r--sql/sql_parse.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 7b5387e5e2f..d2cbd5b0008 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -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: