Skip to content

upsert return wrong value when insert a row which db has #6310

Closed

Description

@salivarick

If table user has a row like below:

(id, name) = (1, 'daleoooo')

and run code like this

user.upsert({
  id: 1,
  name: 'daleoooo'
}).then(res => console.log(res))

the output will be true, which is obviously not right.
I traced the code, and found connection.query returns wrong affectRows.

BTW:
I run the sql as same as the sql sequelize generated in the code above, affected row is 0.

Thank you for your comments.

Dialect: mysql
Database version: 5.7
Sequelize version: 3.23.6

Activity

  1. janmeier commented on Aug 1, 2016

    @janmeier
    Member

    If you specify the CLIENT_FOUND_ROWS flag to mysql_real_connect() when connecting to mysqld, the affected-rows value is 1 (not 0) if an existing row is set to its current values.
    https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

    The flag is set by default by node-mysql, which means affected rows is 1 when the rows is matched, but nothing is updated.

    Can be fixed by setting flags: '-FOUND_ROWS' at createConnection. This would probably be a good idea to set by default in 4.0

  2. added
    type: bug
    dialect: mysql
    good first issue
    on Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mysqlgood first issuetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions