ActiveAndroid where with a "in" clause
Asked Answered
P

3

6

I would like to know if it is possible and how I could do a where clause in ActiveAndroid with a "IN" clause.

For example, I would like do do something like this:

new Select().from(Table).where("id in ?", list).execute()

Peluso answered 11/2, 2015 at 13:29 Comment(0)
S
13

The query should work almost as is - ActiveAndroid reduces your SELECT to SQL anyway.

For example, the following LIKE query works for me:

public static List<Record> search(String searchTerm) {
    return new Select().from(Record.class)
            .where("Data LIKE ?", new String[]{'%' + searchTerm + '%'})
            .orderBy("Name ASC")
            .execute();
}

where search term is '%searchTerm%'

If you are having difficulty, you can query the DB directly, ie:

    mRecordList = SQLiteUtils.rawQuery(Record.class,
            "SELECT * from Records where Data LIKE ?",
            new String[]{'%' + searchTerm + '%'});
            */
Silicate answered 16/2, 2015 at 13:57 Comment(3)
What to do if we need to fetch records with respect to offests. Currently only the querying the DB directly is working for me.Injured
do you want to mark the answer as correct one day @SalmanKhakwani ? ;)Silicate
I would love to! But this isn't my question, dear.Injured
T
1

new Select().from(Table).where("id in (1,2)").execute()

Taxdeductible answered 17/6, 2015 at 8:8 Comment(0)
S
0

use this link for IN clause in activeandroid. Its bit difficult but check the answer given by jlhonora. it worked for me

https://github.com/pardom/ActiveAndroid/issues/392

Stemware answered 13/5, 2017 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.