ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: customized where
Date Thu, 29 May 2008 15:07:14 GMT
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 <brunosanzmarino@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
>

Mime
View raw message