In my app i track the user consumed calories ,and when iam trying to retrieve the daily needed calories counter from my sqlite data base it returned as zero , but when i debug my app line by line the initialization and update of the counter value is done correctly and it have a value " not zero" , why its returned as zero ? is there error in the way i returned it ? please help me
update code
<pre lang="java">
DBAdapter db=new DBAdapter(SaveMeal.this);
db.open();
String date = db.getDate(FormateDate());
if(date.equals("not exist"))
{
long d =db.InitializeCounters(FormateDate());
Log.e("intialize tracker counters" ,d+"inserted ?");
boolean st_result=db.UpdateNutrientsCounters(FormateDate(),Meal.MealTotalCalories,Meal.VB12_COUNTER,Meal.PROTEIN_COUNTER,
Meal.SODIUM_COUNTER,Meal.IRON_COUNTER, Meal.CHOLESTEROL_COUNTER,Meal.FAT_SAT_COUNTER,Meal.FAT_MONO_COUNTER);
if(st_result)
Log.e("NCals counter update after intialize ","done ");
else
Log.e("NCals counter update after intialize","failure ");
}
else if(date.equals(FormateDate()))
{
boolean st_result=db.UpdateNutrientsCounters(FormateDate(),Meal.MealTotalCalories,Meal.VB12_COUNTER,Meal.PROTEIN_COUNTER,
Meal.SODIUM_COUNTER,Meal.IRON_COUNTER, Meal.CHOLESTEROL_COUNTER,Meal.FAT_SAT_COUNTER,Meal.FAT_MONO_COUNTER);
if(st_result)
Log.e("NCals counter update","done ");
else
Log.e("NCals counter update","failure ");
}
db.close();
the retrieve method
public int getDNCalsCounter(String date ) throws SQLException
{
int NCals_CounterVal=0;
Cursor cursor=db.query(true,TRACKER_TABLE_NAME, new String[]{KEY_DAILY_NCALS_COUNTER}, KEY_DATE+ " = '" + date + "'", null, null, null, null,null);
if ( cursor .moveToFirst()) {
NCals_CounterVal =cursor.getInt(cursor.getColumnIndex(KEY_DAILY_NCALS_COUNTER));
}
cursor.close();
cursor.deactivate();
return NCals_CounterVal ;
}
Here where i use the retrieve method and it returns the counter as zero
remaining_cals_ToConsume_TV=(TextView)findViewById(R.id.RCTC_value);
db = new DBAdapter(this);
db.open();
NCals_counter=db.getDNCalsCounter(FormatDate());
Log.e("NCals_counter" ,NCals_counter +" ");
determined_DNcals=StaticPreferences.getDailyNeededCals(this);
Log.e("determined_DNcals" ,determined_DNcals +" ");
RCals_ToConsume=determined_DNcals-NCals_counter;
remaining_cals_ToConsume_TV.setText(RCals_ToConsume +" cal");
db.close();
FormatDate method
private String FormatDate()
{
localCalendar = Calendar.getInstance();
return new SimpleDateFormat("EEEE, d/MMM/yyyy").format(localCalendar.getTime());
}