Question

I've read the greendao documentation and didn't find any clue about a way to be warned if, for some reason, an update fails for an entity...

the update(T entity) neither returns anything nor throws any error...

so is there any way to know if the update process has failed?

thank you.

Was it helpful?

Solution

If the update doesn't work you are getting a SQLException. Since SQLException extends [RuntimeException][2] it doesn't have to be handled and thus doesn't have to be declared withthrows`.

The only reasons for updatefailure I can think of at the moment:

  • The primary key in your update-object is empty.
  • The primary key of your update-object isn't found in your db.
  • The update violates some constraints (i.e. unique).
  • The database or filesystem is corrupted.

So normally, if you are sure you won't violate constraints and if you are careful with primary key your updates won't fail.

If you are not sure you can surround your update with try-catch-block.

try {
    myEntityDao.update(myObj);
} catch (SQLException ex) {
    // handle the failure here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top