In GreenDao, create a connection request using OR instead of AND

I created SQLite DB using GreenDao v2.1.0. Here is his chart (tiny part)

CONTACT can have many phone numbers. I want to do a search query: a list of all contacts whose GIVEN_NAME or FAMILY_NAME or PHONE.NUMBER contains a specific word.

For example, with these entries , if I use the word "bob", the Sponge Bob contact will be returned. If I use the word "222", the Patrick Star contact will be returned.

Since two tables are involved in the query, I resorted to solving the JOIN using this piece of code:

QueryBuilder<Contact> qb = getContactDao(context).queryBuilder(); qb.whereOr(ContactDao.Properties.Given_name.like("%" + word + "%"), ContactDao.Properties.Family_name.like("%" + word + "%")); qb.join(Phone.class, PhoneDao.Properties.Contact_id) .where(PhoneDao.Properties.Number.like("%" + word + "%")); List<Contact> contacts = qb.list(); 

This generates the following SQL:

 SELECT T."_id", T."GIVEN_NAME", T."FAMILY_NAME" FROM "CONTACT" T JOIN PHONE J1 ON T."_id"=J1."CONTACT_ID" WHERE (T."GIVEN_NAME" LIKE ? OR T."FAMILY_NAME" LIKE ?) AND J1."NUMBER" LIKE ? COLLATE LOCALIZED ASC 

The 5th line indicates a problem: the "AND" connector. I am desperately trying to replace it with "OR".

Am I missing something? Should I leave the JOIN solution? Thanks:)

+5
source share
1 answer

I have the same problem. It seems that greendao is currently not able to do this. Instead, I use queryRaw() .

+1
source

Source: https://habr.com/ru/post/1241643/


All Articles