ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Maves" <nathan.ma...@gmail.com>
Subject Re: Nested Dynamic Statements
Date Mon, 16 Jun 2008 20:53:49 GMT
can you not do....

<statement id="foo" resultMap="fooMap">
       select * from mytable
       <dynamic prepend="where" open="(" close=")">
                       <isNotEmpty prepend="or" property="prop1">
                               field1 = prop1
                       </isNotEmpty>
                       <isNotEmpty prepend="or" property="prop2">
                               field2 = prop2
                       </isNotEmpty>
               <isNotEmpty prepent="and" property="prop3">
                       field3 = prop3
               </isNotEmpty>
       </dynamic>
</statement>

On Mon, Jun 16, 2008 at 1:46 PM, Brandon Goodin <brandon.goodin@gmail.com>
wrote:

> Ah, I see.
>
> Unfortunately there is not short handed way around this. Your suggestions
> are the best way to get around it. I know it doesn't help a whole lot but we
> are aware of these shortcomings and looking to nullify them in iBATIS 3.
> I'll try to take a little time to look into nested dynamic tags. I can't
> think of a reason why we shouldn't allow it.
>
> Brandon
>
>
> On Mon, Jun 16, 2008 at 12:30 PM, <David_Greenberg@ltx.com> wrote:
>
>>
>> I'm not sure about other database systems, but MySQL (5) will throw an
>> error for this query:
>>
>> select * from mytable where () and field3 = prop3
>>
>> Is Ibatis smart enough to remove the "(" and ")" when the contents are
>> empty?
>>
>> One workaround is to put this in the parentheses, but this is an ugly
>> hack:
>>
>> <isEmpty property="prop1">
>>   <isEmpty property="prop2">
>>     1=1
>>   </isEmpty>
>> </isEmpty>
>>
>> Another hack would be to add a "property" to the input that indicates a
>> tautology should be added.  I am looking for something cleaner than this.
>>
>> Thank you,
>> David
>>
>>
>>  From: "Brandon Goodin" <brandon.goodin@gmail.com> To:
>> user-java@ibatis.apache.org Date: 06/16/2008 12:58 PM Subject: Re: Nested
>> Dynamic Statements
>> ------------------------------
>>
>>
>>
>> Can you please explain the reason you need the nested dynamic tag?
>>
>> Why not simply do this?...
>>
>> <statement id="foo" resultMap="fooMap">
>>       select * from mytable
>>       <dynamic prepend="where">
>>              (
>>                       <isNotEmpty prepend="or" property="prop1">
>>                               field1 = prop1
>>                       </isNotEmpty>
>>                       <isNotEmpty prepend="or" property="prop2">
>>                               field2 = prop2
>>                       </isNotEmpty>
>>               )
>>               <isNotEmpty prepent="and" property="prop3">
>>                       field3 = prop3
>>               </isNotEmpty>
>>       </dynamic>
>> </statement>
>>
>> Brandon
>>
>>
>> On Fri, Jun 13, 2008 at 8:39 AM, <*David_Greenberg@ltx.com*<David_Greenberg@ltx.com>>
>> wrote:
>>
>> Hi,
>>
>> Is it possible to nest dynamic statements in Ibatis?  Here is a simple
>> example of what I want to do:
>>
>> <statement id="foo" resultMap="fooMap">
>>       select * from mytable
>>       <dynamic prepend="where">
>>               <dynamic open="(" close=")">
>>                       <isNotEmpty prepend="or" property="prop1">
>>                               field1 = prop1
>>                       </isNotEmpty>
>>                       <isNotEmpty prepend="or" property="prop2">
>>                               field2 = prop2
>>                       </isNotEmpty>
>>               </dynamic>
>>               <isNotEmpty prepent="and" property="prop3">
>>                       field3 = prop3
>>               </isNotEmpty>
>>       </dynamic>
>> </statement>
>>
>> The XML validation against the DTD (*
>> http://ibatis.apache.org/dtd/sql-map-2.dtd*<http://ibatis.apache.org/dtd/sql-map-2.dtd>)
>> fails because of the nested dynamic element.  I know that I could make a
>> collection of these conditions and iterate over them as a hack to
>> accomplishing this, but I am wondering if the example above is supported or
>> planned to be supported in some version of Ibatis.
>>
>> Thank you,
>> David
>>
>>
>

Mime
View raw message