Queries with and() and or()
Please what is the right way to create a query like select * from mytable where name='my' and ((age=20) or(town='berlin'))
supposing that i have a myTableBox box object created with objectbox library i have begin with this myTableBox.query().equal( MyTable_.name,"my") and i dont know how to play with and() and or() to complete this request in the right way. Good evening and good job for this very useful librabry
Also stuck with this today. In Realm, for example, there are grouping methods for query builder. Could not find anything like that in ObjectBox.
Please check the JavaDocs for QueryBuilder.and() and or()
So, in your example, it would be something like this: query.equal(name, "foo").equal(age,42).or().equal(town,"berlin")
We will work on a more intuitive API in the near future.
Thank you for this answer and you put me in the right direction. Whe i read this JavaDoc i think that i will perform it corectly. Very thank for this very useful library
2017-06-27 10:40 GMT+01:00 greenrobot [email protected]:
Please check the JavaDocs for QueryBuilder.and() http://objectbox.io/files/objectbox-java/current/io/objectbox/query/QueryBuilder.html#and-- and or() http://objectbox.io/files/objectbox-java/current/io/objectbox/query/QueryBuilder.html#or--
So, in your example, it would be something like this: query.equal(name, "foo").equal(age,42).or().equal(town,"berlin")
We will work on a more intuitive API in the near future.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/greenrobot/ObjectBox/issues/123#issuecomment-311307639, or mute the thread https://github.com/notifications/unsubscribe-auth/AIvkprZv9maaOwXAQn1R3r_416NpvA2hks5sIM4pgaJpZM4OFfxb .
--
Avec mes sincères salutations
TCHOUKEU Simplice Aimé Architecte des Systèmes d'informations tel: +237 75 38 35 76 skype: stchoukeu
Please sory to come back disturbing you again. I want to express a condition like (A and B) or (C and D) When i read the doc i notice tha a condition like A and (C or D) can be expressed like Query.A.C.or().D also (A and B) or D can be writed as Query.A.and().B.or().D
I Have express my need of (A and B) or (C and D) like Query.A.and().B.or().C.and().D
I have also cry Query.A.B.or().C.D but noting of all them seem to work.
Please can you tel me the right way of writing this?
2017-06-27 12:42 GMT+01:00 greenrobot [email protected]:
Closed #123 https://github.com/greenrobot/ObjectBox/issues/123.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/greenrobot/ObjectBox/issues/123#event-1140335247, or mute the thread https://github.com/notifications/unsubscribe-auth/AIvkpunSu802-J8PiLtilBxwvqdQgMCrks5sIOrCgaJpZM4OFfxb .
--
Avec mes sincères salutations
TCHOUKEU Simplice Aimé Architecte des Systèmes d'informations tel: +237 75 38 35 76 skype: stchoukeu
It might be that we reach the limits already. Sorry, the current implementation is rather a quick hack. We try to get something better really soon. A workaround would be to do two queries. It would look something like this:
long[] ids1 = query1.findIds();
long[] ids2 = query2.findIds();
// put id1 in a hash set and add contents of ids2
// get entities for collected ids using box.get(id)
Thank you for all. I will continu by the way you suggested to me. Please what is the raison that you choose to change the signature of or() and and() method? It will ne good that it be like the one in GreenDAO
Le 27 juin 2017 18:16, "greenrobot" [email protected] a écrit :
It might be that we reach the limits already. Sorry, the current implementation is rather a quick hack. We try to get something better really soon. A workaround would be to do two queries. It would look something like this:
long[] ids1 = query1.findIds(); long[] ids2 = query2.findIds(); // put id1 in a hash set and add contents of ids2 // get entities for collected ids using box.get(id)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/greenrobot/ObjectBox/issues/123#issuecomment-311425046, or mute the thread https://github.com/notifications/unsubscribe-auth/AIvkpqONiRUulk6lsldbN3qdyWiXFnQqks5sITjkgaJpZM4OFfxb .
The APIs are not final here and they will improve.
Any updates on improving QueryBuilder API? Is case (A and B) or (C and D) still not implementable using a single QueryBuilder?
Any update about this case (A and B) or (C and D) ?
Tracking this with #533. Please thumbs up that issue. -ut