Cannot retrieve the latest update value from database after running the ORM Lite UpdateBuilder.update() in android

♀尐吖头ヾ 提交于 2020-01-16 20:07:02

问题


I have trouble when updating the data in android by using ORM Lite because my updated data is not affected in database immediately. After the update process, I query the data from the database but I got the old data that was the same as before I update.

So, I solved this problem by refreshing each updated object by using refresh(Object) after the update process, the problem was OK(I can access the latest updated data from data in next query).

But I am not sure is it the best way or not? If there have another ways to solve this problem, could you please tell me? Thanks.

Run the batch update by using UpdateBuilder.

try {
    Set<String> ids = accountIdSet;
    UpdateBuilder<Account, Long> updateBuilder = account.updateBuilder();
    updateBuilder.where().in(Account.ID,ids);
    updateBuilder.updateColumnValue(Account.REGISTERED, true);
    return updateBuilder.update();
} catch (SQLException e) { }
return 0;

After update process I do the query data from database by below lines.

try {
    Set<String> ids = accountIdSet;
    List<Account> result =  Account.queryBuilder().where().in(Account.ID, ids).query();
    if (result!=null) {
        for (Account acc : result) {
            Log.i(acc.getId() + ", registered = " + acc.getRegistered());
        }
        return result;
    }
} catch (SQLException e) { }
return null;

At that time I got the old value of data. For example -

1, registered = false
2, registered = false
3, registered = false

Result should be

1, registered = true
2, registered = true
3, registered = true

来源:https://stackoverflow.com/questions/27053093/cannot-retrieve-the-latest-update-value-from-database-after-running-the-orm-lite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!