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 Andrew B <ch...@yahoo.com> on 2007/05/03 22:04:28 UTC
optional parameters
Hello,
I am using iBATIS 2.3.0. I want to map a query for a report, that will have some optional selection criteria. If I map the query with these criteria as parameters, and then send null values for ones the user has not selected, will SQL Map leave them out of the query? Or, if not, is there a way to do this? (I want to avoid using a stored procedure if possible).
Thanks,
Andrew B
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: optional parameters
Posted by Jared Blitzstein <ma...@blitzstein.net>.
Check out "Dynamic Mapped Statements" in the documentation on page
49, specifically the isNotNull. Here is the example it lists:
<select id="dynamicGetAccountList"
resultMap="account-result" >
select * from ACCOUNT
<dynamic prepend="WHERE">
<isNotNull prepend="AND" property="firstName"
open=”(“ close=”)”>
ACC_FIRST_NAME = #firstName#
<isNotNull prepend="OR" property="lastName">
ACC_LAST_NAME = #lastName#
</isNotNull>
</isNotNull>
<isNotNull prepend="AND" property="emailAddress">
ACC_EMAIL like #emailAddress#
</isNotNull>
<isGreaterThan prepend="AND" property="id" compareValue="0">
ACC_ID = #id#
</isGreaterThan>
</dynamic>
order by ACC_LAST_NAME
</select>
On May 3, 2007, at 7:01 PM, Koka Kiknadze wrote:
> Check the <isNull> element in users quide. Think that's exactly
> what you need,
>
>
>
> On 5/4/07, Andrew B <ch...@yahoo.com> wrote:
> Hello,
>
> I am using iBATIS 2.3.0. I want to map a query for a report, that
> will have some optional selection criteria. If I map the query with
> these criteria as parameters, and then send null values for ones
> the user has not selected, will SQL Map leave them out of the
> query? Or, if not, is there a way to do this? (I want to avoid
> using a stored procedure if possible).
>
> Thanks,
>
> Andrew B
>
> Ahhh...imagining that irresistible "new car" smell?
> Check out new cars at Yahoo! Autos.
>
Re: optional parameters
Posted by Koka Kiknadze <22...@gmail.com>.
Check the <isNull> element in users quide. Think that's exactly what you
need,
On 5/4/07, Andrew B <ch...@yahoo.com> wrote:
>
> Hello,
>
> I am using iBATIS 2.3.0. I want to map a query for a report, that will
> have some optional selection criteria. If I map the query with these
> criteria as parameters, and then send null values for ones the user has not
> selected, will SQL Map leave them out of the query? Or, if not, is there a
> way to do this? (I want to avoid using a stored procedure if possible).
>
> Thanks,
>
> Andrew B
>
> ------------------------------
> Ahhh...imagining that irresistible "new car" smell?
> Check out new cars at Yahoo! Autos.<http://us.rd.yahoo.com/evt=48245/*http://autos.yahoo.com/new_cars.html;_ylc=X3oDMTE1YW1jcXJ2BF9TAzk3MTA3MDc2BHNlYwNtYWlsdGFncwRzbGsDbmV3LWNhcnM->
>