ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nilesh Bhattad" <nil...@outlinesys.com>
Subject RE: Qns abt using <isNotEmpty/> inside <select/>
Date Tue, 18 Jan 2005 16:39:55 GMT
Thanks Tim!!
 
I changed the <select/> as below and all possible conditions worked
fine. 
 
<select id="search" parameterClass="java.util.HashMap"
resultClass="java.util.HashMap">
          select ConsultantId, BlackListed, FirstName, LastName,
HomeTelephone, EmailAddress, InterviewGrade, TotalYrsOfExp from
Consultant
            <dynamic prepend=" where ">
                <isNotEmpty property="FirstName" prepend=" and
">FirstName like #FirstName#</isNotEmpty>
                <isNotEmpty property="LastName" prepend=" and ">LastName
like #LastName#</isNotEmpty>
                <isNotEmpty property="ActiveInactive" prepend=" and
">ActiveInactive like #ActiveInactive#</isNotEmpty>
            </dynamic>    
          order by FirstName, LastName
     </select>
 
iBatis rocks !!
 
~ Nilesh
 
-----Original Message-----
From: Chen, Tim [mailto:Tim.Chen@NielsenMedia.com] 
Sent: Tuesday, January 18, 2005 11:22 AM
To: ibatis-user-java@incubator.apache.org
Subject: RE: Qns abt using <isNotEmpty/> inside <select/>
 
There's a simple problem.
If you look at the docs.. there is another statement that you can use to
wrap what you have called:
 
<dynamic prepend="WHERE">
if you add that instead of your 'where' it will be okay.
-Tim
 
  _____  

From: Nilesh Bhattad [mailto:nilesh@outlinesys.com] 
Sent: Tuesday, January 18, 2005 11:02 AM
To: ibatis-user-java@incubator.apache.org
Subject: Qns abt using <isNotEmpty/> inside <select/>
Hello,
 
I'm having some trouble while using <isNotEmpty/> node inside <select/>
 
Please take a look at below select statement.
 
     <select id="search" parameterClass="java.util.HashMap"
resultClass="java.util.HashMap">
          select ConsultantId, BlackListed, FirstName, LastName,
HomeTelephone, EmailAddress, InterviewGrade, TotalYrsOfExp from
Consultant where
          <isNotEmpty property="FirstName">FirstName like
#FirstName#</isNotEmpty>
          <isNotEmpty property="LastName" prepend=" and ">LastName like
#LastName#</isNotEmpty>
          <isNotEmpty property="ActiveInactive" prepend=" and
">ActiveInactive like #ActiveInactive#</isNotEmpty>
          order by FirstName, LastName
     </select>
 
The problem with this stmt is if only ActiveInactive is keyed in, the
select stmt is resolved like below -
 
select ConsultantId, BlackListed, FirstName, LastName, HomeTelephone,
EmailAddress, InterviewGrade, TotalYrsOfExp from Consultant where
and ActiveInactive like ?           order by FirstName, LastName
 
'and' is added in the stmt which makes it invalid query. How do I adjust
the <isNotEmpty/> tags inside <select/> so that it will work for any
combination?
 
Help, please !
 
~ Nilesh

Mime
View raw message