affectedRows value is incorrect. no changedRows value in result
See original GitHub issueHi,
I’ve looked through all the old issues and can see that changedRows value ought to be present in the result set now. However I am not seeing it…
I’ve also noticed that affectedRows has the wrong value when doing an insert
This is my query
connection.DM.query('insert into trainServices (serviceId,depart,origin,destination,coaches)
values (?,?,?,?,?) on duplicate key update coaches = values(coaches)',
[service.serviceId,service.depart,service.origin,service.destination,JSON.stringify(coaches)])
And this is the result data when it results in an insert:
{
"fieldCount": 0,
"affectedRows": 2,
"insertId": 0,
"info": "",
"serverStatus": 2,
"warningStatus": 0
},
Here I expected affectedRows to have a value of 1 since only 1 row was inserted.
affectedRows has the expected value of 1 when the query does not contain the on duplicate key part.
This is the result when there is no change to any data Or when there is a duplicate so it does an update and there is a change to the data
{
"fieldCount": 0,
"affectedRows": 1,
"insertId": 0,
"info": "",
"serverStatus": 2,
"warningStatus": 0
},
Here I expected to see changeRows with a value of 0 when there was no data change and a value of 1 when there was, but it is not present in the result set. I also notice that info is empty.
I am using mysql2 v1.6.3 (promise mode) and my DB is an AWS RDS instance running mySQL v 5.6.41
Has changedRows support been dropped? Or is there any known issue with AWS’s mySQL implementation that is preventing mysql2 picking up the necessary query response info?
Thanks for your time
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
from mysql documentation: https://dev.mysql.com/doc/refman/8.0/en/mysql-affected-rows.html For INSERT … ON DUPLICATE KEY UPDATE statements, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values. If you specify the CLIENT_FOUND_ROWS flag, the affected-rows value is 1 (not 0) if an existing row is set to its current values.
try connection option:
flags: "-FOUND_ROWS",
?