I am looking to the fastest and the correct way to check if a record exists in the database:
public boolean Exists(String _id) {
Cursor c=db.query(TABLEN
Since you are looking for an answer from 'credible and/or official sources', here in DatabaseUtils we have a method called queryNumEntries
.
So your method could be made like this:
public boolean Exists(String _id) {
return DatabaseUtils.queryNumEntries(db, TABLENAME(), "_ID=?", new String[] {"1"}) > 0;
}
Or, for faster one:
public boolean Exists(String _id) {
return DatabaseUtils.longForQuery(db, "select count(*) from " + TABLENAME() + " where _ID=? limit 1", new String[] {"1"}) > 0;
}