我在我的android项目中使用dbflow,我想知道是否有方法更新整个对象,而不是如下所示指定每一列

// Native SQL wrapper
SQLite.update(Ant.class)
  .set(Ant_Table.type.eq("other"))
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute(); // non-UI blocking

从向导那里
https://agrosner.gitbooks.io/dbflow/content/SQLiteWrapperLanguage.html
更新的“set”部分支持不同类型的值:
contentvalues->作为is()/eq()的sqloperator转换为key/value
作为set语句的一部分组合在一起的sqloperator。
基于此,我尝试将contentvalues传入set方法
// Native SQL wrapper
SQLite.update(Ant.class)
  .set(contentValues)
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute(); // non-UI blocking

我得到一个编译错误
set (com.raizlabs....SQLOperator...) in Update cannot be applied
to (android.content.ContentValues)

最佳答案

你需要这样称呼它:

SQLite.update(Ant.class)
  .set().conditionValues(contentValues)
  .where(Ant_Table.type.is("worker"))
  .and(Ant_Table.isMale.is(true))
  .async()
  .execute();

从文档中看不清楚,从源代码中看不清楚,但应该是这样工作的。

关于android - 使用DBFlow更新整个对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46077153/

10-10 11:34