I am trying to query my database based on a specific id.
String sql = "SELECT * FROM mash WHERE recipe_id = '" + id + "'";
Cursor data = database.rawQuery(sql, null);
If this is the first time the activity has been run, the table WILL exist along with the id column, but there will not be a record with the specific id. How can I check if that specific record exists and if it does not, add it? I have found lots of into regarding checking if a specific column exists, but nothing about checking if a specific record exists.
So far I have tried getting the id column index and checking to see if it returns -1, but it actually is returning 1 for some reason. What can I use in an if statement to verify that the id column has not yet been created?
if (cursor.moveToFirst()) {
// record exists
} else {
// record not found
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With