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 Aaron Loucks <aa...@GardnerInc.com> on 2005/01/10 22:37:05 UTC

Force OR statement?

According to the API Docs :


or

public Criteria
<http://db.apache.org/torque/apidocs/org/apache/torque/util/Criteria.html>
or(java.lang.String column,
                   java.lang.Object value,
                   SqlEnum
<http://db.apache.org/torque/apidocs/org/apache/torque/util/SqlEnum.html>
comparison)

This method adds a new criterion to the list of criterias. If a criterion
for the requested column already exists, it is "OR"ed to the existing
criterion. If is used as follow:

 

Is there any way for force the Criteria to be OR'ed? For example I'm trying
to do something like the following:

 

 

SELECT * FROM table WHERE first_name LIKE '%queryString%' OR last_name LIKE
'%queryString%';

 

When I create the criteria by doing something like the following, it always
creates the statement with AND's rather than an OR. According to the
documentation this is correct, but this isn't the output I'm looking for. Is
there something in the API that I over looked? Or is this not possible?

 

Criteria c = new Criteria();

String queryString = "joe";

 

c.add(TablePeer.FIRST_NAME, (Object)("%" + queryString + "%"),
Criteria.LIKE);

c.or(TablePeer.LAST_NAME, (Object)("%" + queryString + "%"), Criteria.LIKE);

 

 

- Aaron

 


Re: Force OR statement?

Posted by Bill Leng <wl...@metatomix.com>.
try something like this.
                Criteria c = new Criteria();
                Criteria.Criterion fromCat = c.getNewCriterion(
                    IxConnectionPeer.FROM_CATEGORY, category, 
Criteria.EQUAL);
                Criteria.Criterion toCat = c.getNewCriterion(
                    IxConnectionPeer.TO_CATEGORY, category, Criteria.EQUAL);
                c.add(fromCat.or(toCat));


Aaron Loucks wrote:

>According to the API Docs :
>
>
>or
>
>public Criteria
><http://db.apache.org/torque/apidocs/org/apache/torque/util/Criteria.html>
>or(java.lang.String column,
>                   java.lang.Object value,
>                   SqlEnum
><http://db.apache.org/torque/apidocs/org/apache/torque/util/SqlEnum.html>
>comparison)
>
>This method adds a new criterion to the list of criterias. If a criterion
>for the requested column already exists, it is "OR"ed to the existing
>criterion. If is used as follow:
>
> 
>
>Is there any way for force the Criteria to be OR'ed? For example I'm trying
>to do something like the following:
>
> 
>
> 
>
>SELECT * FROM table WHERE first_name LIKE '%queryString%' OR last_name LIKE
>'%queryString%';
>
> 
>
>When I create the criteria by doing something like the following, it always
>creates the statement with AND's rather than an OR. According to the
>documentation this is correct, but this isn't the output I'm looking for. Is
>there something in the API that I over looked? Or is this not possible?
>
> 
>
>Criteria c = new Criteria();
>
>String queryString = "joe";
>
> 
>
>c.add(TablePeer.FIRST_NAME, (Object)("%" + queryString + "%"),
>Criteria.LIKE);
>
>c.or(TablePeer.LAST_NAME, (Object)("%" + queryString + "%"), Criteria.LIKE);
>
> 
>
> 
>
>- Aaron
>
> 
>
>
>  
>

-- 
Bill Leng
Sr. Software Engineer
Metatomix, Inc.
Tel: (901)261-8911
Fax: (901)261-8901



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