Conflict resolution in Android's SQLiteDatabase Conflict resolution in Android's SQLiteDatabase android android

Conflict resolution in Android's SQLiteDatabase


You can specify a UNIQUE index in the table definition which will allow rows to be REPLACED:

CREATE TABLE mytable (  id  INTEGER PRIMARY KEY AUTOINCREMENT,  name TEXT NOT NULL,  UNIQUE (id) ON CONFLICT REPLACE)

If a row an INSERT or UPDATE statement tries to add a row with an id which already exists, the existing row is replaced with the new one.


There's a ON CONFLICT clause in SQLite that you can say INSERT INTO ... ON CONFLICT....

Read the documentation please. http://www.sqlite.org/lang_conflict.html


By default i you have unique index exception will be thrown on duplicated index insert. Common solution is check record existence before execute insert - pseudo-code:

select * from people where name = 'Smith';//if resultset is empty then perform insertinsert into people values 'Smith'