Android中的Sugar ORM:在SQLite中更新已保存的对象 [英] Sugar ORM in Android: update a saved object in SQLite

查看:226
本文介绍了Android中的Sugar ORM:在SQLite中更新已保存的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是不熟悉Android上使用SQLite和Sugar ORM进行应用程序开发的人,曾尝试通读Sugar ORM文档,但没有找到有关如何更新SQLite中保存的对象的任何信息.更改其属性后,我仍然可以保存该对象吗?像这样:

I'm new to app development using SQLite and Sugar ORM on Android, and have tried to read through the Sugar ORM documentation, but didn't find anything for how to update a saved object in SQLite. Can I still save the object after changing its properties? something like:

Customer myCustomer = (Customer.find(Customer.class, "id = ?", id)).get(0);
myCustomer.setName("new name");
myCustomer.setAddress("new Address");
myCustomer.save(); // is this okay for updating the object?

save()方法不会在保持旧条目不变的情况下创建另一个新对象,对吧?

the save() method won't create another new object while leaving the old entry untouched, right?

推荐答案

它将更新您的实体.在调用save()方法之后,Sugar ORM会覆盖您现有的e.g名称,并使用新名称"对其进行更新.

It will update your entity. The Sugar ORM overwriting your existing e.g Name and updated it with "new name" after the save() method call.

这篇关于Android中的Sugar ORM:在SQLite中更新已保存的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆