jeudi 30 avril 2015

Simulate ON DUPLICATE KEY UPDATE in SQLITE Android

I am trying to find a way to get INSERT...ON DUPLICATE KEY UPDATE from MySQL working in SQLite. The problem is that my current attempts are always failing due to the fact, that SQLite always deletes the row first and inserts it with the new values and the same primary key. When I now have a foreign key constraint ON DELETE CASCADE on this primary key in another table, the entries in the other tables always get deleted.

What I've tried:

db.insertWithOnConflict(tableName, null, values, SQLiteDatabase.CONFLICT_REPLACE);
db.replace(tableName, null, values);

Both methods first remove the entry and re-insert it.

Is there any method to prevent this kind of behaviour and just update the entry's values, except for the primary?

Aucun commentaire:

Enregistrer un commentaire