Adding a like parameter as the link suggests (addLike("attribute","%[%]%")) will
return any records where the field matches <anytexthere>[<anytexthere>]<anytexthere>
(i.e.  ABC[DEF]XYZ matches, ABC[XYZ does not).

The only way I have been able to get an sql query to work manually is to use a
statement similar to:
   select * from sometable where description like '%\%%' ESCAPE '\'
NOTE: finds all records where the description contains the '%' character somewhere.

The first problem with what OJB is doing when I add a like criteria, is strip
off the escape character.  They do this because they are only allowing a '*',
'\' or a '?' to be 'escaped', so they assume if you are using the '\' character at
all, it is simply removed.  Technically, they aren't really escaping anything,
they are simply allowing the *, ? and every other \ to go through as is and not
converting them to their respective % and _ characters.
What OJB doesn't do when escaping their '*' and '?' - is check to make sure the
next character is actually a '*' or '?'.
OJB also doesn't add the ESCAPE parameter that works with the like clause.  They
could check the value for the like operation for any '\' character, and simply
append " ESCAPE '\' " if they find one.

So, unless I am missing something, I think the ojb support for 'like' is close,
but not quite complete.  There are basically two characters you simply cannot
search for in a string, '%' and '_'.

Paul

-----Original Message-----
From: Jakob Braeuchi [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 19, 2004 12:56 PM
To: OJB Users List
Subject: Re: Query with criteria - like using '%' or '_'

hi paul,

check out this link:

http://nick.blogs.com/blog/2003/08/_in_sql_stateme.html

jakob

Nase, Paul R. wrote:

> Thanks Jakob,
> 
> But I want to find objects that contain the actual '%' character, I don't want to 
> search for objects using the '%' as the one or more wildcard.
> 
> The addLike("attribute","P%") will return all records starting with the letter 'P'.  
> So this query will search using the '%' as the normal sql wildcard, it won't query 
> for items that actually contain the '%' character.
> 
> Paul
> 
> -----Original Message-----
> From: Jakob Braeuchi [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 19, 2004 12:29 PM
> To: OJB Users List
> Subject: Re: Query with criteria - like using '%' or '_'
> 
> hi paul,
> 
> use addLike("your_attribute","P%")
> 
> hth
> jakob
> 
> Nase, Paul R. wrote:
> 
> 
>>I would like to perform a query where a description could have a '%' or an '_'.  Is 
>>this possible using QueryByCriteria?
>>
>>Example:
>>ID          DESCRIPTION
>>-------     --------------------
>>10000       40% Member Discount
>>10001       Online Discount
>>
>>I'd like to be able to search using a like statement similar to: "Where Description 
>>like '%\%%' ESCAPE '\'"
>>
>>The current implementation will just strip off the escape character, resulting in 
>>passing my literal '\%' being pass as a wildcard.
>>
>>Thanks in advance.
>>
>>Paul Nase
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to