1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

5.0 version of the fix for bug #9481: mysql_insert_id() returns 0 after

insert ... select.

The 5.0 manual page for mysql_insert_id() does not mention anything
about INSERT ... SELECT, though its current behavior is incosistent
with what the manual says about the plain INSERT.

Fixed by changing the AUTO_INCREMENT and mysql_insert_id() handling
logic in INSERT ... SELECT to be consistent with the INSERT behavior,
the manual, and the changes in 5.1 introduced by WL3146:


- mysql_insert_id() now returns the first automatically generated
AUTO_INCREMENT value that was successfully inserted by INSERT ... SELECT

-  if an INSERT ... SELECT statement is executed, and no automatically
generated value is successfully inserted, mysql_insert_id() now returns
the ID of the last inserted row.


sql/sql_class.h:
  Replaced last_insert_id with autoinc_value_of_last_inserted_row to be
  consistent with 5.1 code.
sql/sql_insert.cc:
  Revised the AUTO_INCREMENT and mysql_insert_id() handling logic in
  INSERT ... SELECT to be consistent with INSERT behavior, the manual, and
  changes in 5.1 introduced by WL3146:
  
  - mysql_insert_id() now returns the first automatically generated
  AUTO_INCREMENT value that was successfully inserted;
  
  -  if an INSERT ... SELECT statement is executed, and no automatically
  generated value is successfully inserted, mysql_insert_id() now returns
  the ID of the last inserted row.
tests/mysql_client_test.c:
  Backported the test cases related to INSERT ... SELECT and
  mysql_insert_id() from WL3146 patch to 5.0.
This commit is contained in:
unknown
2007-11-26 18:36:05 +03:00
parent ac0612f559
commit 1836b73600
3 changed files with 224 additions and 9 deletions

View File

@@ -2048,7 +2048,8 @@ class select_insert :public select_result_interceptor {
TABLE_LIST *table_list;
TABLE *table;
List<Item> *fields;
ulonglong last_insert_id;
ulonglong autoinc_value_of_last_inserted_row; // not autogenerated
ulonglong autoinc_value_of_first_inserted_row; // autogenerated
COPY_INFO info;
bool insert_into_view;
bool is_bulk_insert_mode;