LitePal icon indicating copy to clipboard operation
LitePal copied to clipboard

先调用Delete再save,查库是空的

Open jerry9433 opened this issue 3 years ago • 3 comments

用来存储当前登录用户的信息,所以这个表理论上是有且仅有一条数据的。 但是现在发现先delete后save,或者deleteAll后save,再去findFirst总是空的.

UserInfoDB first = LitePal.findFirst(UserInfoDB.class); if (first != null) { first.delete(); } boolean save = userInfoBean.save(); LogUtils.i("litepal",save+"---");

jerry9433 avatar Aug 16 '21 05:08 jerry9433

 public static void updateUserInfo(UserInfoDB userInfoBean) {
        UserInfoDB first = LitePal.findFirst(UserInfoDB.class);
        if (first != null) {
            first.delete();
        }
        boolean save = userInfoBean.save();
        LogUtils.i("litepal",save+"---");
    }

jerry9433 avatar Aug 16 '21 05:08 jerry9433

兄弟换个思路,不走删除的路,直接createOrUpdate这条记录,把字段替换成最新的值就行了吧

easytobreakdown avatar Aug 20 '21 02:08 easytobreakdown

同样遇到这个问题....

zhuzhutai avatar Jun 08 '23 15:06 zhuzhutai