I am using the insertWithOnConflict function in Android / SQLite to insert values ββthat potentially already exist in the database. According to Android documentation, if this value exists, the primary key will be returned:
Returns the row ID of the newly inserted row OR the primary key of the existing row if the input param 'conflictAlgorithm' = CONFLICT_IGNORE OR -1 if any error
However, when using this function, the existing primary key is not returned if the row already exists. Instead, it will automatically update the primary key and return this value, even if the data is not inserted into the string for the returned identifier.
The function call itself is relatively simple:
name_id = db.insertWithOnConflict("names", null, name_values, SQLiteDatabase.CONFLICT_IGNORE);
source share