Skip to content

Commit d974ea7

Browse files
author
Neeraj Bisht
committed
Bug#11745891 - LAST_INSERT(ID) DOES NOT SUPPORT BIGINT UNSIGNED
Problem:- using last_insert_id() on an auto_incremented bigint unsigned does not work for values which are greater than max-bigint-signed. Analysis:- last_insert_id() returns the first auto_incremented value for a column and an auto_incremented value can have only positive values. In our code, when we are initializing a last_insert_id object, we are taking it as a signed BIGINT, So when the auto_incremented value reaches greater than max signed bigint, last_insert_id gives negative result. Solution: When we are fetching the value from last_insert_id, We are setting the unsigned_flag, so that it take only unsigned BIGINT value.
2 parents 6e8d0f3 + c55dd6b commit d974ea7

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

sql/item_func.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,8 @@ longlong Item_func_last_insert_id::val_int()
40234023
thd->first_successful_insert_id_in_prev_stmt= value;
40244024
return value;
40254025
}
4026-
return thd->read_first_successful_insert_id_in_prev_stmt();
4026+
return
4027+
static_cast<longlong>(thd->read_first_successful_insert_id_in_prev_stmt());
40274028
}
40284029

40294030

sql/item_func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ class Item_func_last_insert_id :public Item_int_func
11301130
const char *func_name() const { return "last_insert_id"; }
11311131
void fix_length_and_dec()
11321132
{
1133+
unsigned_flag= TRUE;
11331134
if (arg_count)
11341135
max_length= args[0]->max_length;
11351136
}

0 commit comments

Comments
 (0)