You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Bruno Sanz <br...@gmail.com> on 2008/05/29 13:30:02 UTC
customized where
Hi
We have a customized search form . This allow tro add conditions. We would
want to be able to write one customized "where" in the query
Is there any way to "send" the where as parameter to the ibatis?
We want to create one condition that could have many "OR" and "AND"s in the
query (unknown before, evaluated at run time)
Any ideas?
thank you in advance
Bruno
Re: customized where
Posted by Jeff Butler <je...@gmail.com>.
Couple of ways to do this:
1. Build the where clause yourself and pass it as a parameter to the
statement:
Select * from foo $where_clause$
2. Use iBATIS dynamic SQL tags:
select * from foo
<dynamic prepend="where">
<isNotNull property="firstName" prepend="and">
FIRST_NAME = #firstName#
</isNotNull>
<isNotNull property="lastName" prepend="and">
LAST_NAME = #lastName#
</isNotNull>
</dynamic>
The first is open to SQL injection, the second is safer but less flexible.
You could also take a look at code generated by ibator - which demonstrates
a method of creating a very flexible where clause.
Jeff Butler
On Thu, May 29, 2008 at 6:30 AM, Bruno Sanz <br...@gmail.com>
wrote:
> Hi
>
> We have a customized search form . This allow tro add conditions. We would
> want to be able to write one customized "where" in the query
>
> Is there any way to "send" the where as parameter to the ibatis?
> We want to create one condition that could have many "OR" and "AND"s in the
> query (unknown before, evaluated at run time)
>
> Any ideas?
>
> thank you in advance
>
> Bruno
>