samedi 1 août 2015

Android ContentResolver bulkInsert() resulting in duplicated records

My app downloads a database from the server to populate the local database using contentResolver.bulkInsert(). Normally, everything works fine.

However, if the app is closed partway through the initial operation and the app is restarted, I end up with duplicate records in the database. This is despite my table having an _id integer PRIMARY KEY column.

I have followed the execution with a debugger and can confirm that the call to contentResolver.bulkInsert() succeeds for the initial attempt and it also succeeds for the second attempt - but I would have expected it to fail the second time as the app would be trying to insert _id values in a unique column that already exist.

Can anyone advise why bulkInsert does not fail when asked to insert duplicate _ids and what would be a good workaround?

Aucun commentaire:

Enregistrer un commentaire