Reputation: 73916
I am trying to search my database to see if a number exists in it, return true if it does and false if not. here is my query
public boolean getPhone(String where){
Cursor cur = db.query(DATABASE_TABLE, new String [] {ID,PHONE_NUMBER},PHONE_NUMBER + "='" + where + "'",null,null,null,null);
if(cur.moveToFirst()){
do{
String test = cur.getString(cur.getColumnIndex(PHONE_NUMBER));
Log.v("ContactDB", test);
if(test.equals(where))
return true;
}while(cur.moveToNext());
}
return false;
}
when it gets to the do while loop it jumps right over it to return false without even doing it once like it should. If I take the do while loop out, the if(c.movetofirst()) tests false im guessing because that also jumps right to return false.
I just dont get why it is not working right. the database exists and has values in it
Upvotes: 0
Views: 117
Reputation: 42849
Your cur.moveToFirst() is returning false, meaning that there is no data in the cursor. As for why, I would venture to guess that your database does not contain the data that you are passing into this method. You should drop a debug in there to verify you are passing in the value that you expect.
Upvotes: 1