I'm trying to create a simple favorites application, where you can keep your favorites pages (from the web for example).
Let's say I have the following data in my database
Title | URL | TAG |
-------------------------------
Hey Ho.com Site
Jo Jo.com Image
Jo Mo.com Image
Now I want to make sure, the user does not add the same page twice, so I will check if the value already exists. But I need to that the user does not add a site to the table that has already been added.
So let's say I would try to add:
Title | URL | TAG |
-------------------------------
Jo Mo.com Image
This it would return true (for "check if row exist", because an identical row already exists).
But if I would try to add:
Title | URL | TAG |
-------------------------------
Jo Go.com Image
It would return false (though the title already exists), because there is no identical row.
This is the code where I add my data to the database with:
public long createNote(String title, String url, String rn) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_URL, url);
initialValues.put(KEY_RN, rn);
return mDb.insert(DATABASE_TABLE, null, initialValues);
How can I check if a row already exists in a database?