I’m prompting a user to add an item to an SQLiteDb. When they click add, I want to check if that item already exists… if it doesn’t then I want to insert it.
I make the call
mDbHelper.createNote(inputLine.getText().toString().trim(), mTable[i]);
Which calls…
public long createNote(String value, String table) {
ContentValues initialValues = new ContentValues();
initialValues.put(table, value);
return mDb.insert(table, null, initialValues);
}
Thats works but it doesn’t check if the item already exists, so it still inserts duplicates. So I tried
return mDb.insertWithOnConflict(table, null, initialValues, SQLiteDatabase.CONFLICT_FAIL);
However, it doesn’t appear to recognize insertWIthOnConflict or SQLiteDatabase.CONFLICT_FAIL…
How can I get this to work?
Edit: it’s 1 table, 2 rows. table name = note, rows = _id, note.
In such situation I perfrom such checking:
where