summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2004-03-25 17:42:13 +0100
committerunknown <pem@mysql.comhem.se>2004-03-25 17:42:13 +0100
commitdf06466976e3d9e63ed8f95e5543578b7ec572ac (patch)
treeb848643a5a893df72a10e6264bc0406b6c9ec236 /sql/item_func.cc
parentd8c5358115abb7134943a8ec9b1f2ec0fabcae26 (diff)
downloadmariadb-git-df06466976e3d9e63ed8f95e5543578b7ec572ac.tar.gz
Fixed BUG#3117: LAST_INSERT_ID() works incorrectly inside stored procedure.
This turned out to be a problem for prepared statements as well; the id was evaluated once, at parse time. mysql-test/r/auto_increment.result: Updated results after bugfix in last_insert_id(). mysql-test/r/query_cache.result: Updated results after bugfix in last_insert_id(). mysql-test/r/variables.result: Updated results after bugfix in last_insert_id(). sql/item_func.cc: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. sql/item_func.h: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. sql/sql_yacc.yy: Fixed bug in last_insert_id(); get id at each evaluation (and not in the parser). Renamed the class Item_func_set_last_insert_id too, since it's not only for setting. tests/client_test.c: Test case for last_insert_id() in prepared statements.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc19
1 files changed, 14 insertions, 5 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 5151fb2876d..9f80686e72c 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2139,13 +2139,22 @@ longlong Item_func_release_lock::val_int()
}
-longlong Item_func_set_last_insert_id::val_int()
+longlong Item_func_last_insert_id::val_int()
{
DBUG_ASSERT(fixed == 1);
- longlong value=args[0]->val_int();
- current_thd->insert_id(value);
- null_value=args[0]->null_value;
- return value;
+ if (arg_count)
+ {
+ longlong value=args[0]->val_int();
+ current_thd->insert_id(value);
+ null_value=args[0]->null_value;
+ return value;
+ }
+ else
+ {
+ Item *it= get_system_var(current_thd, OPT_SESSION, "last_insert_id", 14,
+ "last_insert_id()");
+ return it->val_int();
+ }
}
/* This function is just used to test speed of different functions */