• unknown's avatar
    BUG#22584: last_insert_id not updated after inserting a record through · c7cd2f8d
    unknown authored
    a updatable view.
    
    When there's a VIEW on a base table that have AUTO_INCREMENT column, and
    this VIEW doesn't provide an access such column, after INSERT to such
    VIEW LAST_INSERT_ID() did not return the value just generated.
    
    This behaviour is intended and correct, because if the VIEW doesn't list
    some columns then these columns are effectively hidden from the user,
    and so any side effects of inserting default values to them.
    
    However, there was a bug that such statement inserting into a view would
    reset LAST_INSERT_ID() instead of leaving it unchanged.
    
    This patch restores the original value of LAST_INSERT_ID() instead of
    resetting it to zero.
    
    
    mysql-test/r/view.result:
      Add result for bug#22584: last_insert_id not updated after inserting
      a record through a updatable view.
    mysql-test/t/view.test:
      Add test case for bug#22584: last_insert_id not updated after inserting
      a record through a updatable view.
    sql/sql_parse.cc:
      When we have inserted into a view, and AUTO_INCREMENT column is not
      accessed from this view, instead of setting LAST_INSERT_ID to zero set
      it to the value it had before this statement was executed.
    c7cd2f8d
sql_parse.cc 223 KB