0

I have this table with an primary key column called idcolumn and another int column called datacolumn.

It exists already a row:

idcolumn=2
datacolumn=1

I execute this statement:

ContentValues cv = new ContentValues();
cv.put("datacolumn", 1);  
int count = db.update("mytable", cv, "idcolumn=2", null);

The result is count=1, even though no rows have been changed.

If I repeat the statement, the result is the same: count=1.

I need to know when an arbitrary update statement, really makes changes, in order to stamp a row as changed, for my sync framework.

How can it be done?

I've tried with and without transactions. The result is the same, and with Android 4.4.2.

Related questions:

Community
  • 1
  • 1
david.perez
  • 6,090
  • 4
  • 34
  • 57

1 Answers1

0

The idcolumn=2 matches one row and it is updated, regardless of whether it actually needs an update. Therefore you get 1 as updated count.

If your data hasn't changed, don't write it to the database. Track changes in your Java code, for example add a "isDirty" boolean flag to the POJO that holds the data to be written, set the object to dirty when a change is detected in a setter, and only update to disk (database) if the object is dirty.

laalto
  • 150,114
  • 66
  • 286
  • 303