question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

affectedRows value is incorrect. no changedRows value in result

See original GitHub issue

Hi,

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:open
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
PhilSwift7commented, Nov 22, 2018

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.

1reaction
jimmyolocommented, Nov 12, 2018

try connection option: flags: "-FOUND_ROWS", ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Affected rows inconsistent across database engines - Drupal
When updating a database record in D7, according to the documentation UpdateQuery->execute() returned "the number of rows affected by the update ...
Read more >
UPDATE and SET trouble in nodejs (MYSQL) - Stack Overflow
I am trying to update the status on my database to value of 1 with node.js ... idk where did I go wrong,...
Read more >
Node.js with MySQL - w3resource
"changedRows" differs from "affectedRows" in that it does not count updated rows whose values were not changed. connection.query('DELETE FROM ...
Read more >
MySqlCommand.ExecuteNonQuery returns 1 for updates ...
ExecuteNonQuery() function always returns non-zero value ... false > > When true, the connection reports changed rows instead of found rows.
Read more >
Garage
However, MySQL only counts the rows whose values have effectively changed. To know if a driver returns the number of really changed rows...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found