You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Joose Vettenranta <jo...@iki.fi> on 2005/08/23 12:33:04 UTC

how to make search

Hi,

I tried to make generic search using ojb, but didn't work how I was  
planning it to work, naturally =)

I have framework created so that class that I'm searching is passed  
to that generic search function, so only fields has to be checked.

My idea was this (pseudo code):

----
Criteria crit = new Criteria();

foreach search-field as field {
     Criteria crit2 = new Criteria();
     crit2.addLike (field, "%" + getValue(field) + "%");
     crit.addOrCriteria (crit2);
}

---
problem is that when field is integer, it transformed to:

SELECT ..... Where field like %value%;

I tried also adding ' signs to like field, but it worked ok with  
integers but not ok with strings. Is here SQL-injection possibility??

but what I want is to have "%value%".

Of course what I really want is to have some sort of check so that it  
would check
1) that field exists
2) to make Like operation to work ok with every object type.

There was some sort of OJBSearchFilter, but what I understood from  
javadoc, it's nothing to be used here.

Pointers, helps?

Thanks, Joose

--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * joose@iki.fi * +358 44 561 0270 *



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