You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BUG#22028117 - MYSQLCLIENT DOES NOT RETURN CORRECT
MYSQL_INSERT_ID VIA DATABASE HANDLE
DESCRIPTION
===========
mysql_insert_id() does not return correct values after
performing inserts in a table containing an AUTO_INCREMENT
field and then performing a SELECT operation.
The value of insert_id is getting reset to 0 after
performing SELECT. However, LAST_INSERT_ID() gives the
correct value.
ANALYSIS
========
An OK packet is sent from the server to the client to
signal successful completion of a command.
As of MySQL 5.7.5, OK packes are also used to indicate EOF,
as EOF packets are deprecated. The packet identifier 0x00
represents an OK packet whereas the packet identifier OxFE
represents an EOF packet. The EOF packet has valid values
for the following fields: packet header, warnings and
server status. The fields affected_rows and insert_id will
have valid values only if it was an OK packet and not for
an EOF packet. Reading the values of the above two fields
for an EOF packet will result in inconsistent values being
assigned to the connection handle.
FIX
====
The fix is to assign the affected_rows and insert_id fields
to the connection handle only if they were read from an OK
packet. In case of an EOF packet, skip the assignment and
proceed to the next valid fields. This way we can make sure
that they don't get wrongly updated in the connection
handle.
0 commit comments