android - Android 中的 Sugar ORM : update a saved object in SQLite

标签 android sqlite orm crud

我是在 Android 上使用 SQLite 和 Sugar ORM 进行应用程序开发的新手,并试图通读 Sugar ORM 文档,但没有找到任何关于如何更新 SQLite 中保存的对象的信息。更改其属性后是否仍可以保存对象?像这样的东西:

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() 方法不会在保持旧条目不变的情况下创建另一个新对象,对吗?

最佳答案

您的代码应该可以毫无问题地更新该行。

From the docs - Update Entity :

Book book = Book.findById(Book.class, 1);
book.title = "updated title here"; // modify the values
book.edition = "3rd edition";
book.save(); // updates the previous entry with new values.

关于android - Android 中的 Sugar ORM : update a saved object in SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26835785/

相关文章:

python - 找出我的 sqlite 版本

python - 使用 Python 连接到远程 sqlite3 数据库

android - Crashlytics Fabric.io 已弃用

android - 开始使用/Flow 和 Mortar

sqlite - SQLite3 Pragma同步不持久

php - Laravel,在 Eloquent 语法中应用 where 之后 with

mysql - 如何在与sequ​​elize Node 的关系上使用having子句

linq - Linq到NHibernate项目状态?有贡献吗?铅?

java - 调用 putExtra 时 Activity 未完成

安卓NDK : Assertion failure: TARGET_PLATFORM is not defined