Share Coding

Tutorials, Problems, Stuffs …

Android DBFlow multiple condition query with ‘LIKE’ operator

In the following case, contain some features:

  1. ConditionGroup to handle multiple condition
  2. LIKE operator with “%”, means the keyword can have words in-front or after it

SQLite.select()
        .from(LockerLocationData.class)
        .innerJoin(Address.class)
        .on(LockerLocationData_Table.id.is(Address_Table.lockerId))
        .where(ConditionGroup.clause()
                .or(LockerLocationData_Table.nickname.like("%" + keywords + "%"))
                .or(Address_Table.building.like("%" + keywords + "%"))
                .or(Address_Table.street.like("%" + keywords + "%"))
                .or(Address_Table.province.like("%" + keywords + "%"))
                .or(Address_Table.town.like("%" + keywords + "%"))
                .or(Address_Table.district.like("%" + keywords + "%"))
                .or(Address_Table.room.like("%" + keywords + "%"))
                .or(Address_Table.country.like("%" + keywords + "%"))
                .or(Address_Table.city.like("%" + keywords + "%")))
        .queryList(databaseWrapper);
dbflow_version = "4.0.0-beta1"
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: