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 Da...@ltx.com on 2008/06/13 15:39:47 UTC

Nested Dynamic Statements

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) 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 

Re: Nested Dynamic Statements

Posted by Nathan Maves <na...@gmail.com>.
Ignore that last one.... responded to fast that will not work

On Mon, Jun 16, 2008 at 2:53 PM, Nathan Maves <na...@gmail.com>
wrote:

> 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 <br...@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, <Da...@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" <br...@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, <*D...@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
>>>
>>>
>>
>

Re: Nested Dynamic Statements

Posted by Nathan Maves <na...@gmail.com>.
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 <br...@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, <Da...@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" <br...@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, <*D...@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
>>
>>
>

Re: Nested Dynamic Statements

Posted by Brandon Goodin <br...@gmail.com>.
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, <Da...@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" <br...@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, <*D...@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
>
>

Re: Nested Dynamic Statements

Posted by Da...@ltx.com.
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" <br...@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, <Da...@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) 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 


Re: Nested Dynamic Statements

Posted by Brandon Goodin <br...@gmail.com>.
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, <Da...@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