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 Founaboui Haman <fh...@kommunity.net> on 2003/11/24 17:09:39 UTC
Help on building an sql criteria
Hi there,
I am looking for a way to build the following criteria in torque.
The sql:
SELECT * FROM articles WHERE any condition AND (articlename LIKE '%seachString%' OR articleNumber LIKE '%searchString%');
My problem resides in the criteria between the parenthesis. Any help with code shnippet could be appreciated.
Thank for your help
haman
Re: Help on building an sql criteria
Posted by Founaboui Haman <fh...@kommunity.net>.
Thank 1000 times Peter. Your code work fine
Have a nice day
haman
----- Original Message -----
From: "Peter Hamlen" <pe...@teachforamerica.org>
To: "Apache Torque Users List" <to...@db.apache.org>
Sent: Monday, November 24, 2003 8:21 PM
Subject: Re: Help on building an sql criteria
> One trick would be to use the Criteria.CUSTOM option:
>
> Criteria crit = new Criteria();
> crit.add(ArticlePeer.ARTICLENAME, (Object)"(article.name like
> '%"+searchString+"%' or article.number like '%"+searchString+"%')",
> Criteria.CUSTOM);
>
> Two important notes:
> 1) Be sure to cast the middle argument as an object - otherwise you'll
> get an "ambiguous method call" error
> 2) We're using a way-old version of Torque (3.0b2) so some of the
> syntax may have changed - but I don't think so.
>
> You can also do it in a more complicated fashion by using Criterions and
> explicitly joining them, but I personally don't think it's worth the
> effort.
>
> -Peter
>
>
> On Mon, 2003-11-24 at 11:09, Founaboui Haman wrote:
>
> > Hi there,
> >
> > I am looking for a way to build the following criteria in torque.
> > The sql:
> >
> > SELECT * FROM articles WHERE any condition AND (articlename LIKE
'%seachString%' OR articleNumber LIKE '%searchString%');
> >
> > My problem resides in the criteria between the parenthesis. Any help
with code shnippet could be appreciated.
> > Thank for your help
> >
> > haman
>
> Peter Hamlen (peter.hamlen@teachforamerica.org)
> Deputy Vice President, Technology
> Teach For America
> 212-279-2080 ext 170
> http://www.teachforamerica.org
>
> "One day, all children in this nation will have the opportunity to
> attain an excellent education."
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Help on building an sql criteria
Posted by Peter Hamlen <pe...@teachforamerica.org>.
One trick would be to use the Criteria.CUSTOM option:
Criteria crit = new Criteria();
crit.add(ArticlePeer.ARTICLENAME, (Object)"(article.name like
'%"+searchString+"%' or article.number like '%"+searchString+"%')",
Criteria.CUSTOM);
Two important notes:
1) Be sure to cast the middle argument as an object - otherwise you'll
get an "ambiguous method call" error
2) We're using a way-old version of Torque (3.0b2) so some of the
syntax may have changed - but I don't think so.
You can also do it in a more complicated fashion by using Criterions and
explicitly joining them, but I personally don't think it's worth the
effort.
-Peter
On Mon, 2003-11-24 at 11:09, Founaboui Haman wrote:
> Hi there,
>
> I am looking for a way to build the following criteria in torque.
> The sql:
>
> SELECT * FROM articles WHERE any condition AND (articlename LIKE '%seachString%' OR articleNumber LIKE '%searchString%');
>
> My problem resides in the criteria between the parenthesis. Any help with code shnippet could be appreciated.
> Thank for your help
>
> haman
Peter Hamlen (peter.hamlen@teachforamerica.org)
Deputy Vice President, Technology
Teach For America
212-279-2080 ext 170
http://www.teachforamerica.org
"One day, all children in this nation will have the opportunity to
attain an excellent education."