I want to check whether a row of the sqlite table exists in database or not..If row exists i should call a class otherwise another class.To get this functionality i am using
public boolean Exists(int position) {
SQLiteDatabase db = (placeData).getReadableDatabase();
Cursor cursor = db.rawQuery("select * from pages where bbookid ='"+ position +"'", null);
boolean exists = (cursor.getColumnName(position)) != null;
Log.i("logs","fads");
if(exists=true)
{
getDataAndPopulate();
}
else
{
Log.i("qefw","cursors");
new LoadAllProducts().execute();
}
cursor.close();
return exists;
}
but using this code the rows are reinserting ..Could anyone suggest me the way to approach the functionality
Your equality check is failing because this expression is evaluating to
true:When you have a single equals sign, it means assignment. You are assigning
truetoexists, instead of comparingexiststotrue. The result of the assignment is the value to whichexistswas assigned (true).Try the proper equality operator instead:
See this related post for another look at this issue.