immobiluser
immobiluser

Reputation: 359

UPDATE SQLite, how to get numbers of affected changed rows (not the found matched rows)

Nowhere I found the solution to retrieve the numbers of affected changed rows (not the found matched rows). Each solution are "found/matched rows" only :

But i want know the real number of rows updated (whith differents values only before the update statement).

Looking on SQL "matching found rows" vs "affected rows", neither command line, neither connector PHP PDO was able to return the number of real changed rows.

To resume, with :

CREATE TABLE table_update_count ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, 'val' VARCHAR);
INSERT INTO table_update_count (val) VALUES ('AA');
INSERT INTO table_update_count (val) VALUES ('AB');
UPDATE table_update_count SET val = 'AB';

Result obtained : 2

Expected result : 1

I there a way to do that ?

I don't seem to be alone wishing this improvement...

Upvotes: 4

Views: 2669

Answers (1)

CL.
CL.

Reputation: 180020

The UPDATE statement updates two rows. That the new value happens to be identical with the old value does not matter, as far as this count is concerned.

If you do not want to count rows with the same values, you have to manually filter them out:

UPDATE table_update_count
SET val = 'AB'
WHERE val IS NOT 'AB';

Upvotes: 3

Related Questions