You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrew Lindesay <ap...@lindesay.co.nz> on 2010/01/28 02:41:46 UTC

Using an Escaped LIKE Clause

Hello;

A question about escaping a LIKE qualifier;

	ExpressionFactory.likeExp(...,...)

JDBC specifies the ability to use '%' and '_' as matchers for characters and a character respectively.  It is then possible to escape use of those characters as in the following example;

	SELECT a FROM tabA WHERE a LIKE '%=_' {escape '='}

I can't easily see a means by which one can specify the "escape" clause in a SelectQuery -- can anybody shed some light on this for me.

Regards;

___
Andrew Lindesay
www.lindesay.co.nz


Re: Using an Escaped LIKE Clause

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Andrew,

By straightforward I meant from a general framework architecture  
standpoint, i.e. no changes to the processing pipeline, just extending  
what we have.

Yes, a minimal implementation would be adding escape char to  
PatternMatchNode and then tweak the QualifierTranslator to actually  
place it in the SQL. Don't remember if the syntax requires any further  
DbAdapter tweaking for various DBs.

A full implementation would also include an addition to  
ExpressionParser.jjt to allow escape char in String expressions. This  
can be hopefully copied from EJBQLParser.jjt.

Cheers,
Andrus

On Jan 28, 2010, at 10:40 AM, Andrew Lindesay wrote:

> Hi Andrus;
>
> Thanks for that -- I am fairly new to actually using Cayenne.  Are  
> you able to give me any pointers?  As a guess I think I would need  
> to add the escape character to "PatternMatchNode" and then modify  
> something around "DataObjectMatchTranslator" or  
> "QualifierTranslator" to turn that into SQL.
>
> Regards;
>
>> Lachlan is correct. Escaping is only supported in EJBQL now:
>> SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE  
>> 'X'
>> Should be more or less straightforward to add it to Expressions I  
>> guess.
>
> ___
> Andrew Lindesay
> www.lindesay.co.nz
>
>


Re: Using an Escaped LIKE Clause

Posted by Andrew Lindesay <ap...@lindesay.co.nz>.
Hi Andrus;

Thanks for that -- I am fairly new to actually using Cayenne.  Are you able to give me any pointers?  As a guess I think I would need to add the escape character to "PatternMatchNode" and then modify something around "DataObjectMatchTranslator" or "QualifierTranslator" to turn that into SQL.

Regards;

> Lachlan is correct. Escaping is only supported in EJBQL now:
>  SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE 'X'
> Should be more or less straightforward to add it to Expressions I guess.

___
Andrew Lindesay
www.lindesay.co.nz


Re: Using an Escaped LIKE Clause

Posted by Andrus Adamchik <an...@objectstyle.org>.
Lachlan is correct. Escaping is only supported in EJBQL now:

   SELECT p FROM Painting p WHERE p.paintingTitle LIKE 'X_DDDD' ESCAPE  
'X'

Should be more or less straightforward to add it to Expressions I guess.

Andrus

On Jan 28, 2010, at 4:06 AM, Lachlan Deck wrote:

> Hi Andrew,
>
> On 28/01/2010, at 12:41 PM, Andrew Lindesay wrote:
>
>> Hello;
>>
>> A question about escaping a LIKE qualifier;
>>
>> 	ExpressionFactory.likeExp(...,...)
>>
>> JDBC specifies the ability to use '%' and '_' as matchers for  
>> characters and a character respectively.  It is then possible to  
>> escape use of those characters as in the following example;
>>
>> 	SELECT a FROM tabA WHERE a LIKE '%=_' {escape '='}
>>
>> I can't easily see a means by which one can specify the "escape"  
>> clause in a SelectQuery -- can anybody shed some light on this for  
>> me.
>
> I'm sure Andrus and other committers will respond in time (being in  
> a differing timezone)... but if SelectQuery doesn't do it, you might  
> be able to do so with EJBQL.
>
> with regards,
> --
>
> Lachlan Deck
>
>
>
>


Re: Using an Escaped LIKE Clause

Posted by Lachlan Deck <la...@gmail.com>.
Hi Andrew,

On 28/01/2010, at 12:41 PM, Andrew Lindesay wrote:

> Hello;
> 
> A question about escaping a LIKE qualifier;
> 
> 	ExpressionFactory.likeExp(...,...)
> 
> JDBC specifies the ability to use '%' and '_' as matchers for characters and a character respectively.  It is then possible to escape use of those characters as in the following example;
> 
> 	SELECT a FROM tabA WHERE a LIKE '%=_' {escape '='}
> 
> I can't easily see a means by which one can specify the "escape" clause in a SelectQuery -- can anybody shed some light on this for me.

I'm sure Andrus and other committers will respond in time (being in a differing timezone)... but if SelectQuery doesn't do it, you might be able to do so with EJBQL.

with regards,
--

Lachlan Deck