Android DBFlow选择列表中列的位置?

Android DBFlow选择列表中列的位置?,android,sql,database,dbflow,Android,Sql,Database,Dbflow,我正在尝试查询我的数据库,查找列表中包含主键的所有模型。这是我的查询(idsList是一个包含整数的ArrayList): 但安卓工作室强调了where条件,称 "Cannot resolve method 'where(com.raizlabs.android.dbflow.sql.builder.Condition.In)" 条件也是如此。不被认为是条件吗?如何使用ArrayList中的primaryKey查询所有模型 我使用的是dbflow2.0。我也可以使用常规SQL查询字符串作为替代

我正在尝试查询我的数据库,查找列表中包含主键的所有模型。这是我的查询(idsList是一个包含整数的ArrayList):

但安卓工作室强调了where条件,称

"Cannot resolve method 'where(com.raizlabs.android.dbflow.sql.builder.Condition.In)"
条件也是如此。不被认为是条件吗?如何使用ArrayList中的primaryKey查询所有模型

我使用的是dbflow2.0。我也可以使用常规SQL查询字符串作为替代,但我对SQL不太精通,因此如果您可以为我的问题提供SQL查询字符串,这将是一个可能的解决方法。

查看in语句,对in语句进行建模,以便如果您的
idsList
包含
[“Test”、“Test2”、“TestN”]
那么您的代码需要是:

Condition.column(MyTable$Table.NAME).in("Test").and("Test2").and("TestN")
…因此,看起来您需要枚举数组中的每个项

常规SQL类似于:

select *
from PostModel
where ID in ('Test', 'Test2', 'TestN')

…但这仍然意味着您需要枚举数组中的每个项。

我对条件也有同样的问题。在

我是这样做的:

 Condition.In in = Condition.column(PostModel$Table.ID).in(0, idsList);
 ConditionQueryBuilder<PostModel> conditionQueryBuilder = new ConditionQueryBuilder<>(PostModel.class, in);

 List<PostModel> posts = new Select().from(PostModel.class).where(conditionQueryBuilder).queryList();

希望这有帮助。

在条件下创建一个

List<String> ids = new ArrayList<String>();

Condition.In in = Condition.column(Tree$Table.ID).in(ids.get(0));
for (i = 1; i < ids.size(); i++){
      in.and(ids.get(i));
}

long count = new Select().count().from(Tree.class)
        .where(in)
        .count();
List id=new ArrayList();
Condition.In=Condition.column(树$Table.ID).In(ID.get(0));
对于(i=1;i
DBFlow
v3.x
现在允许您将集合传递到
条件中()

List<String> ids = new ArrayList<>();

Condition.In in = Condition.column(Tree_Table.ID.getNameAlias()).in(ids);

long count = new Select().count().from(Tree.class)
        .where(in)
        .count();
List id=new ArrayList();
Condition.In In=Condition.column(Tree_Table.ID.getnamealis()).In(ID);
long count=new Select().count().from(Tree.class)
.何处
.count();

对于DBFlow 4.x上的用户,现在更容易做到:

SQLite.select()
    .from(PostModel.class)
    .where(PostModel_Table.ID.in(idsList))
    .async()
    .queryList(listener);

只需将
in(…)
关键字与
where(…)
调用中的值列表一起使用即可。

谢谢,这很奇怪,因为.in()接受多个参数。同样,它也不会对我有多大帮助,因为我的ID列表可能包含大约100个条目,谢谢您的检查!这就产生了原始SQL:
WHERE
ID`IN(0,[1,2,3,4,5]')“你整理好了吗?请发布你的答案。我没有,但我会查看你的答案。你标记的答案比我晚了一年,答案与正确答案相同。令人失望。我宁愿使用StringQuery
List<String> ids = new ArrayList<>();

Condition.In in = Condition.column(Tree_Table.ID.getNameAlias()).in(ids);

long count = new Select().count().from(Tree.class)
        .where(in)
        .count();
SQLite.select()
    .from(PostModel.class)
    .where(PostModel_Table.ID.in(idsList))
    .async()
    .queryList(listener);