diff options
author | unknown <monty@mashka.mysql.fi> | 2003-06-30 13:28:36 +0300 |
---|---|---|
committer | unknown <monty@mashka.mysql.fi> | 2003-06-30 13:28:36 +0300 |
commit | 48272222a7e4013073f51825f996b2c979f29b6a (patch) | |
tree | 933b2046e69eb6088530f9f8b1d15d8919a876d5 | |
parent | d0dc9e7db36d3dc81aaecd761bed47bb63878108 (diff) | |
download | mariadb-git-48272222a7e4013073f51825f996b2c979f29b6a.tar.gz |
LAST_INSERT_ID() should not be set if we couldn't generate an auto_increment id.
mysql-test/r/auto_increment.result:
Update after auto_increment fix
mysql-test/t/auto_increment.test:
Another fix for LAST_INSERT_ID()
sql/handler.cc:
Another fix for LAST_INSERT_ID()
sql/sql_class.h:
Another fix for LAST_INSERT_ID()
-rw-r--r-- | mysql-test/r/auto_increment.result | 7 | ||||
-rw-r--r-- | mysql-test/t/auto_increment.test | 4 | ||||
-rw-r--r-- | sql/handler.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.h | 19 |
4 files changed, 29 insertions, 3 deletions
diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 5553f718799..19f8ffa84d4 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -111,11 +111,16 @@ insert into t1 set i = null; select last_insert_id(); last_insert_id() 255 +insert into t1 set i = 254; +ERROR 23000: Duplicate entry '254' for key 1 +select last_insert_id(); +last_insert_id() +255 insert into t1 set i = null; ERROR 23000: Duplicate entry '255' for key 1 select last_insert_id(); last_insert_id() -255 +0 drop table t1; create table t1 (i tinyint unsigned not null auto_increment, key (i)); insert into t1 set i = 254; diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index 63fdfded6d0..189320a8dcb 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -80,6 +80,9 @@ insert into t1 set i = 254; insert into t1 set i = null; select last_insert_id(); --error 1062 +insert into t1 set i = 254; +select last_insert_id(); +--error 1062 insert into t1 set i = null; select last_insert_id(); drop table t1; @@ -100,5 +103,6 @@ select last_insert_id(); --error 1062 insert into t1 values (NULL, 10); select last_insert_id(); + drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index 56319bcc91c..150a0d5329e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -709,6 +709,8 @@ void handler::update_auto_increment() nr=get_auto_increment(); if (!table->next_number_field->store(nr)) thd->insert_id((ulonglong) nr); + else + thd->insert_id(table->next_number_field->val_int()); auto_increment_column_changed=1; DBUG_VOID_RETURN; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 33767bc4226..22956f16c83 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -503,8 +503,23 @@ public: #ifdef SIGNAL_WITH_VIO_CLOSE Vio* active_vio; #endif - ulonglong next_insert_id,last_insert_id,current_insert_id, - limit_found_rows; + /* + next_insert_id is set on SET INSERT_ID= #. This is used as the next + generated auto_increment value in handler.cc + */ + ulonglong next_insert_id; + /* + The insert_id used for the last statement or set by SET LAST_INSERT_ID=# + or SELECT LAST_INSERT_ID(#). Used for binary log and returned by + LAST_INSERT_ID() + */ + ulonglong last_insert_id; + /* + Set to the first value that LAST_INSERT_ID() returned for the last + statement. When this is set, last_insert_id_used is set to true. + */ + ulonglong current_insert_id; + ulonglong limit_found_rows; ha_rows select_limit, offset_limit, cuted_fields, sent_row_count, examined_row_count; table_map used_tables; |