android - In GreenDao, build a join query with OR instead of AND -
i generated sqlite db greendao v2.1.0. here diagram (a tiny piece of it)
a contact can have many phone numbers. want make search query : list contacts given_name or family_name or phone.number contains specific word.
for example, with these entries, if use word "bob" contact sponge bob returned. if use word "222", contact patrick star returned.
since, 2 tables involved in query, resorted join solution 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 following sql :
select t."_id", t."given_name", t."family_name" "contact" t join phone j1 on t."_id"=j1."contact_id" (t."given_name" ? or t."family_name" ?) , j1."number" ? collate localized asc
the 5th line points out problem : "and" connector. desperately trying replace "or".
am missing ? shall leave join solution ? :)
i have same problem. seems greendao not able that. resorting using queryraw()
instead.
Comments
Post a Comment