3

我在我的 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

更新的“设置”部分支持不同类型的值:

  1. ContentValues -> 转换为 key/value 作为 is()/eq() 的 SQLOperator
  2. SQLOperator,它们作为 SET 语句的一部分组合在一起。

基于此,我尝试将 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)
4

1 回答 1

0

你需要这样称呼它:

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

从源代码的文档中都不清楚,但它应该以这种方式工作。

于 2017-09-18T11:21:44.083 回答