You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Thomas Fischer <Fi...@seitenbau.net> on 2004/12/22 17:30:03 UTC

Re: is this really the way to combine several or ´s ?




Hi,

Alex Hepp <he...@evamann.de> schrieb am 22.12.2004 16:42:30:

> Hi List!
>
> I tried several hours now, to get a simple or to work... I must say, that
i
> really would appreciate a bit of documentation on that.
>

contributions to the docs are always welcome ;-) . But yes, documentation
is not very good in torque nowadays, but it takes a lot of time to write
good documentation...

>
> what i want now is this:
> SELECT * FROM movii_user where (FIRST_NAME LIKE "%hello%" or LAST_NAME
LIKE
> "%hello%" OR EMAIL LIKE "%hello%" or LOGIN_NAME="%hello%") AND
IS_DELETED=0;
>
> pretty simple. now, what i did is the following:
>
> ************************
> **CODE
> ************************
> // just for demonstration i replaced a String by "hello"
> userKeyWord = "%hello%";
>
> Criteria crit = new Criteria();
> crit.add(MoviiUser.IS_DELETED,0);
>
> Criteria.Criterion a1 = crit.getNewCriterion( MoviiUserPeer.LAST_NAME,
>                                 (Object) (userKeyWord), Criteria.LIKE);
>
> Criteria.Criterion a2 = crit.getNewCriterion(MoviiUserPeer.FIRST_NAME,
>              (Object)userKeyWord, Criteria.LIKE);
>
> Criteria.Criterion a3 = crit.getNewCriterion(MoviiUserPeer.LOGIN_NAME,
>             (Object) userKeyWord, Criteria.LIKE);
>
> Criteria.Criterion a4 = crit.getNewCriterion(MoviiUserPeer.EMAIL,
>             (Object) userKeyWord,
>
> Criteria.crit.add( a1.or( a2.or(a3.or(a4)) ));
> ************************
> **CODE END
> ************************
>
> is this really the right way, or am i completely wrong? It´s working
> though, but
> in my eyes pretty uncool;)

I do not know another way to create a multiple "or". Maybe there is another
way (I am not very experienced with the operators).
What kind of code would you like to write instead ? The problem is that the
correct operator precedence must be determined, in case the operators are
different. An example : In general (condition1 or (condition2  and
condition3)) is different to ((condition1 or condition2) and condition3).
And because the precedence should be the same on any db, Torque cannot rely
on the db's natural precedence , Torque has to enforce it. On the other
hand, the user should be able to create any precedence. Both is ensured
with the criterion.or function. Maybe not cool, but it works.

>
> Would be cool, if someone could tell me, if this is realisable more
easy...
> TIA
>
> Alex Hepp

Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org