summaryrefslogtreecommitdiff
path: root/sql/set_var.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/set_var.cc')
-rw-r--r--sql/set_var.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/sql/set_var.cc b/sql/set_var.cc
index c667e2f2bcc..d00857a2bc1 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -2571,8 +2571,17 @@ bool sys_var_last_insert_id::update(THD *thd, set_var *var)
byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type,
LEX_STRING *base)
{
- thd->sys_var_tmp.long_value= (long) thd->insert_id();
- return (byte*) &thd->last_insert_id;
+ if (!thd->last_insert_id_used)
+ {
+ /*
+ As this statement reads @@LAST_INSERT_ID, set
+ THD::last_insert_id_used and remember first generated insert id
+ of the previous statement in THD::current_insert_id.
+ */
+ thd->last_insert_id_used= TRUE;
+ thd->current_insert_id= thd->last_insert_id;
+ }
+ return (byte*) &thd->current_insert_id;
}