summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc19
-rw-r--r--sql/item_func.h7
-rw-r--r--sql/sql_yacc.yy5
3 files changed, 20 insertions, 11 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 */
diff --git a/sql/item_func.h b/sql/item_func.h
index 4558c1c6f62..4142498af6c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -729,13 +729,14 @@ public:
};
-class Item_func_set_last_insert_id :public Item_int_func
+class Item_func_last_insert_id :public Item_int_func
{
public:
- Item_func_set_last_insert_id(Item *a) :Item_int_func(a) {}
+ Item_func_last_insert_id() :Item_int_func() {}
+ Item_func_last_insert_id(Item *a) :Item_int_func(a) {}
longlong val_int();
const char *func_name() const { return "last_insert_id"; }
- void fix_length_and_dec() { max_length=args[0]->max_length; }
+ void fix_length_and_dec() { if (arg_count) max_length= args[0]->max_length; }
};
class Item_func_benchmark :public Item_int_func
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 5987a69819e..1d30bb210d4 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -2750,13 +2750,12 @@ simple_expr:
}
| LAST_INSERT_ID '(' ')'
{
- $$= get_system_var(YYTHD, OPT_SESSION, "last_insert_id", 14,
- "last_insert_id()");
+ $$= new Item_func_last_insert_id();
Lex->safe_to_cache_query= 0;
}
| LAST_INSERT_ID '(' expr ')'
{
- $$= new Item_func_set_last_insert_id($3);
+ $$= new Item_func_last_insert_id($3);
Lex->safe_to_cache_query= 0;
}
| LEFT '(' expr ',' expr ')'