Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBFlow select where COLUMN in List?

I am trying to query my database for all models with primary keys in a list. This is my query (idsList is an ArrayList containing integers):

new Select().from(PostModel.class)
    .where(Condition.column(PostModel$Table.ID).in(0, idsList))
    .async().queryList(listener);

But Android Studio highlights the where condition, stating

"Cannot resolve method 'where(com.raizlabs.android.dbflow.sql.builder.Condition.In)"

So is Condition.In not considered a condition? How can I query all Models with primaryKey in an ArrayList?

I am using DBFlow 2.0. I can also use a regular SQL query String as a substitute, but I am not that versed in SQL, so if you could provide an SQL query String for my problem, that would be a possible workaround.

like image 749
A. Steenbergen Avatar asked May 12 '15 15:05

A. Steenbergen


2 Answers

DBFlow v3.x now allows you to pass a collection to Condition.in()

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();
like image 147
Austyn Mahoney Avatar answered Oct 13 '22 09:10

Austyn Mahoney


Create a In Condition:

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();
like image 6
tread Avatar answered Oct 13 '22 09:10

tread