Zkontrolujte, zda řádek již v databázi existuje nebo ne, a v závislosti na této aktualizaci nebo vložte svá data:
public Long saveUser(Some values) {
long rowId;
String sql = "SELECT * FROM Data2 WHERE COLUMN_1 = ? AND COLUMN_2 = ?";
Cursor cursor = getSqLiteDatabase().rawQuery(sql, new String[]{"column_value_1" ,"column_value_2"});
if (cursor == null || !cursor.moveToFirst()) {
//Insert new
rowId = getSqLiteDatabase().insert(Data2, null, yourCV);
} else {
//Update
String clause = "COLUMN_1 = ? AND COLUMN_2 = ?";
String args[] = {"column_value_1" ,"column_value_2"};
rowId = getSqLiteDatabase().update(User.DB_KEYS.TABLE.toString(), UserSqlStorage.saveUserCV(user), clause, args);
}
closeCursor(cursor);
return rowId;
}