mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
don't increment LAST_INSERT_ID() when incremented value cannot be stored in auto_increment column (e.g. is too big)
mysql-test/r/auto_increment.result: more tests mysql-test/t/auto_increment.test: more tests
This commit is contained in:
@ -105,3 +105,41 @@ Table Op Msg_type Msg_text
|
|||||||
test.t1 check warning Found row where the auto_increment column has the value 0
|
test.t1 check warning Found row where the auto_increment column has the value 0
|
||||||
test.t1 check status OK
|
test.t1 check status OK
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment primary key);
|
||||||
|
insert into t1 set i = 254;
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
255
|
||||||
|
insert into t1 set i = null;
|
||||||
|
Duplicate entry '255' for key 1
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
255
|
||||||
|
drop table t1;
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment, key (i));
|
||||||
|
insert into t1 set i = 254;
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
255
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
255
|
||||||
|
drop table t1;
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment primary key, b int, unique (b));
|
||||||
|
insert into t1 values (NULL, 10);
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
1
|
||||||
|
insert into t1 values (NULL, 15);
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
2
|
||||||
|
insert into t1 values (NULL, 10);
|
||||||
|
Duplicate entry '10' for key 2
|
||||||
|
select last_insert_id();
|
||||||
|
last_insert_id()
|
||||||
|
3
|
||||||
|
drop table t1;
|
||||||
|
@ -72,3 +72,33 @@ select * from t1;
|
|||||||
check table t1;
|
check table t1;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
#
|
||||||
|
# last_insert_id() madness
|
||||||
|
#
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment primary key);
|
||||||
|
insert into t1 set i = 254;
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
--error 1062
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment, key (i));
|
||||||
|
insert into t1 set i = 254;
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
insert into t1 set i = null;
|
||||||
|
select last_insert_id();
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
|
create table t1 (i tinyint unsigned not null auto_increment primary key, b int, unique (b));
|
||||||
|
insert into t1 values (NULL, 10);
|
||||||
|
select last_insert_id();
|
||||||
|
insert into t1 values (NULL, 15);
|
||||||
|
select last_insert_id();
|
||||||
|
--error 1062
|
||||||
|
insert into t1 values (NULL, 10);
|
||||||
|
select last_insert_id();
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
|
@ -660,8 +660,8 @@ void handler::update_auto_increment()
|
|||||||
thd->next_insert_id=0; // Clear after use
|
thd->next_insert_id=0; // Clear after use
|
||||||
else
|
else
|
||||||
nr=get_auto_increment();
|
nr=get_auto_increment();
|
||||||
thd->insert_id((ulonglong) nr);
|
if (!table->next_number_field->store(nr))
|
||||||
table->next_number_field->store(nr);
|
thd->insert_id((ulonglong) nr);
|
||||||
auto_increment_column_changed=1;
|
auto_increment_column_changed=1;
|
||||||
DBUG_VOID_RETURN;
|
DBUG_VOID_RETURN;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user