I know there's an SQL command that goes like this: IF NOT EXISTS, but since Android's SQLiteDatabase class has some fine methods, I was wondering if it's possible to insert a value if it doesn't exist via a method.
Currently I'm using this to insert a String:
public long insertString(String key, String value) {
ContentValues initialValues = new ContentValues();
initialValues.put(key, value);
return db.insert(DATABASE_TABLE, null, initialValues);
}
(db is an instance of SQLiteDatabase.)
I tried the method insertOrThrow() instead of insert(), but it seems it does the same as insert(). That is, if the value is already in the row, it's inserted again so the row now has two values of the same value.