I am trying to retrieve data from my sqlite data base table which is MealFood and its contain : date time meal_type , Food_id . when i insert data its inserted successfully and i ensure that through the log but when iam trying to retrieve the data from it the cursor returns empty
create MealFood statement
private static final String MealFOOD_TABLE_CREATE= "create table IF NOT EXISTS MealFood (Date text not null , "+"Time text not null,MealType text not null,"+"Food_ID integer not null , primary key(Date,Time ,MealType,Food_ID) );" ;
retrieve method
<pre lang="java">
public Cursor getSpecificMealFoodsID(String date,String mealType) throws SQLException
{
Cursor cursor=db.query(MEALFOOD_TABLE_NAME, new String[]{KEY_MFFOODID},
KEY_MFDATE+ " = '" + date + "'"+ " "+ "and" +" "+ KEY_MFMEALTYPE+ " = '" + mealType + "'", null, null, null, null,null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
the code where i use the getSpecificMealFoodsID(String date,String mealType)
int food_id;
int [] foods_ID;
DBAdapter dbAdapter = new DBAdapter(this);
dbAdapter.open();
String selected_date= date_btn.getText().toString();
Cursor BFMeal_foods_c=dbAdapter.getSpecificMealFoodsID(selected_date,"Breakfast");
Log.e("BFM_cursor",BFMeal_foods_c.getCount()+" ");
foods_ID=new int[BFMeal_foods_c.getCount()];
int i =0;
if (BFMeal_foods_c.moveToFirst())
{
do {
food_id= BFMeal_foods_c.getInt(0);
Log.e("food_ID",food_id+" ");
foods_ID[i]=food_id;
i++;
}
while (BFMeal_foods_c.moveToNext());
}
BFMeal_foods_c.close();
BFMeal_foods_c.deactivate();
dbAdapter.close();
if the insert to the table is done successfully and i can retrieve data from the other tables in my data base , why when i tried to retrieve the data from this table the cursor returned empty ? is there problem in the retrieve method ? and in some times it give me an exception saying that there is " data base object" a cursor not closed but i closed the cursor and there is no cursor i was opened and didn't close it . why this exception occur ,since i closed the cursor ?please any body can help me
any help would be appreciated ...
thanks in advance