W
W
webe2019-03-10 01:01:27
MySQL
webe, 2019-03-10 01:01:27

How can I tell if an entry has been updated or added?

Plz tell me how to determine.
Has the entry been added or has it been updated?
In other words, how do you know if INSERT or UPDATE worked?
I make a request:
INSERT INTO ........'
ON DUPLICATE KEY UPDATE
........
https://knexjs.org
Object arrives

{  fieldCount: 0,
  affectedRows: 1,
  insertId: 56,
  serverStatus: 2,
  warningCount: 0,
  message: '',
  protocol41: true,
  changedRows: 0 }

insertId === 0 is returned if the entry already exists and we haven't replaced anything.
insertId === 57 returns if we create a new entry
insertId === 57 returns if the entry already exists but we updated the fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2019-03-10
@webe

By Affected Rows ( www.mysqltutorial.org/mysql-insert-or-update-on-du...
5c847f3d278ae407408226.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question