Duplicate data after manual refresh
swanhtet1992 opened this issue · 3 comments
Instead of updating just the goal scores, the whole new data are added to the database. And causing the duplication of data.
I am aware of this issue and can reproduce it. This happened to me before.
ORMLite has a method called createOrUpdate(T data)
. I added @DatabaseField(generatedId = true) public int id;
to GroupItem
and setId(id)
into the constructor.
While refreshing data, I put this item.setId(i);
before creating object. However, I don't know why I can't get the value of i
from for loop. The end result is like this after refreshing for two times.
sqlite> .schema GroupItem
CREATE TABLE `GroupItem` (`date` VARCHAR , `time` VARCHAR , `match_id` INTEGER , `stadium` VARCHAR , `groupNum` INTEGER );
sqlite> select * from GroupItem;
3.5.2014|16:00|1|YTC|1
3.5.2014|18:30|2|YTC|1
7.5.2014|16:00|3|YUSC|1
7.5.2014|16:00|4|Nawaday|1
11.5.2014|16:00|5|Aung San|1
11.5.2014|16:00|6|Tha Htone|1
3.5.2014|16:00|7|YTC|1
3.5.2014|18:30|8|YTC|1
7.5.2014|16:00|9|YUSC|1
7.5.2014|16:00|10|Nawaday|1
11.5.2014|16:00|11|Aung San|1
11.5.2014|16:00|12|Tha Htone|1
@indexer, can you reproduce my steps ?
In another work around is remove all records before inserting any data. Something this will work.
void deleteAllRecords() {
try {
mGroupItemDao.deleteAllGroupItem();
mMatchItemDao.deleteAllMatchItem();
} catch (SQLException e) {
e.printStackTrace();
}
}
And call it on Refresh action menu is clicked.
Or if you want to remove the groups by GroupNum, add this method to GroupItemDao
and call it from your fragment.
public void deleteGroupItemsByGroupNum(int groupNum) {
try {
mGroupItemDao.deleteBuilder().where().eq("groupNum", groupNum);
} catch (SQLException e) {
e.printStackTrace();
}
}
I don't know why. Whenever I try, I am still stuck at version 1.0.1