ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Poitras Christian" <Christian.Poit...@ircm.qc.ca>
Subject RE: Help required to write a query
Date Wed, 12 Apr 2006 21:10:41 GMT
Buy adding a dynamic tag, the prepend of tag <isNotNull> will be
replaced by the prepend value of the <dynamic> tag.

 

Try this.

 

<select id="searchUser" parameterClass="searchCriteria"
resultClass="searchCriteria" resultMap="userMap2">

select * from USR_BASIC_INFO    

  <dynamic prepend="where">   

   <iterate property="userlist" conjunction="or"> USR_ID=#userlist[]#   

     and(

     <isParameterPresent>     

     <isEqual property="operator" compareValue="and">      

        <dynamic prepend="">

      <isNotNull prepend="and" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull>      

       <isNotNull prepend="and" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

        </dynamic>

      </isEqual>  

     </isParameterPresent>  

         

     <isParameterPresent>    

      <isEqual property="operator" compareValue="or">


        <dynamic prepend="">


            <isNotNull prepend="or" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull> 

        <isNotNull prepend="or" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

        </dynamic>

      </isEqual> 

     </isParameterPresent>      

         ) 

    </iterate>    

   </dynamic> 

</select>

 



________________________________

From: rohini.ganapa@wipro.com [mailto:rohini.ganapa@wipro.com] 
Sent: Wednesday, 12 April 2006 00:49
To: user-java@ibatis.apache.org
Subject: Help required to write a query



Hi,

 

I am using the below code to retrieve user details from a table:


 

<select id="searchUser" parameterClass="searchCriteria"
resultClass="searchCriteria" resultMap="userMap2">

select * from USR_BASIC_INFO    

  <dynamic prepend="where">   

   <iterate property="userlist" conjunction="or"> USR_ID=#userlist[]#   

     and(

     <isParameterPresent>     

     <isEqual property="operator" compareValue="and">      

      <isNotNull prepend="and" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull>      

       <isNotNull prepend="and" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

      </isEqual>  

     </isParameterPresent>  

         

     <isParameterPresent>    

      <isEqual property="operator" compareValue="or">


        <isNotNull prepend="or" property="username"
removeFirstPrepend="true"> USR_NAME=#username# </isNotNull> 

        <isNotNull prepend="or" property="phonenumber"
removeFirstPrepend="true"> PHONE_NUMBER=#phonenumber# </isNotNull>

      </isEqual> 

     </isParameterPresent>      

         ) 

    </iterate>    

   </dynamic> 

</select>

 

But during execution, I am getting the following error, i.e "and" is
appended twice:

 

select * from USR_BASIC_INFO               where          USR_ID=?
and(
USR_NAME=?                     and PHONE_NUMBER=?
)      or USR_ID=?       and(
and USR_NAME=?                 and PHONE_NUMBER=?
)      or USR_ID=?          and(
and USR_NAME=?                 and PHONE_NUMBER=?
)      or USR_ID=?       and(
and USR_NAME=?                 and PHONE_NUMBER=?
)   .  

Can you please tell how the query is to be written?

 

Regards,

Rohini 

 


The information contained in this electronic message and any attachments
to this message are intended for the exclusive use of the addressee(s)
and may contain proprietary, confidential or privileged information. If
you are not the intended recipient, you should not disseminate,
distribute or copy this e-mail. Please notify the sender immediately and
destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient
should check this email and any attachments for the presence of viruses.
The company accepts no liability for any damage caused by any virus
transmitted by this email.

www.wipro.com
	

Mime
View raw message