robotoworks / mechanoid

Eclipse plugin providing a set of DSL's for the rapid development of Android apps
58 stars 26 forks source link

query with multiple OR and AND #198

Closed hannesa2 closed 11 years ago

hannesa2 commented 11 years ago

how to make a query similar to

where (col1 = 2 or col2 = 3) AND col7 = 4 

this solution is wrong, but how to make the () expression ?

SQuery res = query;
res = res.expr(Mytable.COL1, Op.EQ, 2);                            
res = res.or();
res = res.expr(Mytable.COL2, Op.EQ, 3);                             
res = res.and(); //<-- wrong, how to make the ()
res = res.expr(Mytable.COL7, Op.EQ, 4);         
fluxtah commented 11 years ago

You can nest queries for the perenthisis, the expr () methods have an overload that take another SQuery. I can post an example later.

Sent from Samsung Mobile

-------- Original message -------- From: hannesa2 notifications@github.com Date:
To: robotoworks/mechanoid mechanoid@noreply.github.com Subject: [mechanoid] query with multiple OR and AND (#198)

how to make a query similar to

where (col1 = 2 or col2 = 3) AND col7 = 4 this solution is wrong, but how to make the () expression ?

SQuery res = query; res = res.expr(Mytable.COL1, Op.EQ, 2);
res = res.or(); res = res.expr(Mytable.COL2, Op.EQ, 3);
res = res.and(); //<-- wrong, how to make the () res = res.expr(Mytable.COL7, Op.EQ, 4);
— Reply to this email directly or view it on GitHub.

hannesa2 commented 11 years ago

Thank you, I figured it out. For other one, who run into the same issue:

            firstSQuery.expr(subSQuery);