• unknown's avatar
    5.0 version of the fix for bug #9481: mysql_insert_id() returns 0 after · 1836b736
    unknown authored
    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.
    1836b736
sql_insert.cc 108 KB