You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Adam Greene <ag...@romulin.com> on 2003/01/09 20:34:06 UTC
Torque cannot do OR based selects
I am trying to do the following:
Criteria c2 = new Criteria();
c2.add(BuypartsPeer.MAKE,"Honda");
c2.or(BuypartsPeer.PARTYEAR, 1999);
System.err.println(c2);
try {
System.out.println("List Size : " + BuypartsPeer.doSelect(c2).size());
} catch (TorqueException e) {
}
It should print "List Size : 2" as I have one record with MAKE = Honda and
another record where PARTYEAR = 1999, instead it prints 0. When I check the
Criteria (by printing it), it doesn't do an OR, but instead does an AND. Am
I doing something wrong or is Torque broken??
Re: Torque cannot do OR based selects
Posted by Ben Walding <be...@walding.com>.
You're going about it the wrong way (albeit the fact that what you did
looks right, Torque doesn't work like that)
See bottom of http://jakarta.apache.org/turbine/torque/peers-howto.html
I think something like the following (which I haven't tested or syntax
checked) will work appropriately. Check your logs to see what SQL is
being run
Criteria crit = new Criteria();
Criteria.Criterion a1 = crit.getNewCriterion(BuypartsPeer.MAKE, "Honda", Criteria.EQUAL);
Criteria.Criterion b2 = crit.getNewCriterion(BuypartsPeer.PARTYEAR, 1999, Criteria.EQUAL);
crit.add(a1.or(b2));
Adam Greene wrote:
>I am trying to do the following:
>
>Criteria c2 = new Criteria();
>
>c2.add(BuypartsPeer.MAKE,"Honda");
>
>c2.or(BuypartsPeer.PARTYEAR, 1999);
>
>System.err.println(c2);
>
>try {
>
>System.out.println("List Size : " + BuypartsPeer.doSelect(c2).size());
>
>} catch (TorqueException e) {
>
>}
>
>It should print "List Size : 2" as I have one record with MAKE = Honda and
>another record where PARTYEAR = 1999, instead it prints 0. When I check the
>Criteria (by printing it), it doesn't do an OR, but instead does an AND. Am
>I doing something wrong or is Torque broken??
>
>
>
>--
>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>
>