I am creating my first android app, and now struck on a weird issue
Here is the situation:
The user can enter a numeric value for any given date.
Issue:
So when user tries to give another score for the same date, as we all know the app should over write the old value and update the new value the user just gave.
So I have a update method that gets the rowId and overwrites old values by new. but what’s happening in my table is scary. When I update a numeric value for the same date say 6/6/2011. it creates another record, now I have 2 entries on same date one is old and one is new. and then when i do it to some other date say 6/7/2011(like give a value for a date and then update it) the duplicate column created for 6/6/2011 is gone and a duplicate column is created for 6/7/2011.
updateValue(...){
ContentValues args = new ContentValues();
args.put(KEY_DATESTAMP_SUBTABLE, day);
args.put(KEY_HABIT, habit);
args.put(KEY_USER_SCORE_SUBTABLE, userScore);
args.put(KEY_CALCULATED_SCORE_SUBTABLE,
calculateCompoundScore(scoringMethod, userScore, importance));
String whereClause = KEY_ROWID + "=" + rowId;
return mDb.update(SCORE_TABLE, args, whereClause, null) > 0;
}
can anybody explain me this behavior!!!!
I edited and added the code:
edited:
I found the problem, it is a dumb mistake, the rowID is the row id of a different table, so every time i delete using that it gives me wild results. It is my bad..BUt @Alex idea helped me to figure it out as for update as he said, i deleted first and then inserted, while doing this i found it is deleting some other row.
Thanks
Like gopal said, would be nice to see some code.
Regardless, couldn’t you just delete the old entry and add a completely new one into the table?