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" <[EMAIL PROTECTED]>
To:
[email protected]
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, <[EMAIL PROTECTED]> 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