Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAndroid where with a "in" clause

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()

like image 919
Bruno da Hora Avatar asked Feb 11 '15 13:02

Bruno da Hora


2 Answers

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 + '%'});
            */
like image 104
rob123 Avatar answered Nov 14 '22 20:11

rob123


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

like image 1
mg in dg Avatar answered Nov 14 '22 22:11

mg in dg