I\'ve a database that I will populate with items after I parse a JSON response. How can I check if the values are already present in the database and prevent inserting again
In your example table:
When you create your table you can set your name as unique (if that is what you want unique) with the following (Using a SQLiteOpenHelper
).
String createPlayerTable = "create table " +
TIME_REPORT +
" (" +
USER_ID + " integer primary key autoincrement not null," +
CLIENT_NAME + " text not null," +
"UNIQUE("+CLIENT_NAME+")"+
");";
Then in you insert insertIntoDatabase
method use
db.insertOrThrow(TIME_REPORT, null, initialValues);
instead of
db.insert(TIME_REPORT, null, initialValues);
This may throw a SQLiteConstraintException
so you will have add a try/catch.
Hope this is what you need.