You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Brandon Goodin (JIRA)" <ib...@incubator.apache.org> on 2005/04/08 17:01:04 UTC

[jira] Resolved: (IBATIS-95) Removal of extra OR/AND with parantheses ( ) with dynamic prepend!

     [ http://issues.apache.org/jira/browse/IBATIS-95?page=history ]
     
Brandon Goodin resolved IBATIS-95:
----------------------------------

      Assign To: Brandon Goodin
     Resolution: Fixed
    Fix Version: 2.1.0

Added new removeFirstPrepend functionality. I made sure that all is completely backwards compatible. 
I also added open and close attributes to all dynamic tags for dealing with nested bracketing. This is to avoid users from putting certain characters like "(" and ")" into the body of the dynamic tags and receiving bad sql because the tag sees content in it's body. 
The <dynamic> tag does NOT have the option to removeFirstPrepend. It will automatically remove the first prepend if it contains a prepend attribute. If it does not contain a prepend attribute then the first prepend is used. This was for backwards compatibility. 
All other dynamic tags have the removeFirstPrepend attribute. The default behavior is to NOT removeFirstPrepend. You must explicitly set removeFirstPrepend="true" for it to remove the first prepend.

--- on a technical level ---

- I added a LinkedList to the SqlContext. 
- I also added an inner class named RemoveFirstPrependMarker to the SqlContext. - - The RemoveFirstPrependMarker object is used to track the state of nested prepend removal in the LinkedList.
- I added a test method in the DynamicTest class called testComplexDynamicQuery. 
- I also added a mapped statement to the query called complexDynamicQueryByExample which makes heavy use of the new removeFirstPrepend, open and close attributes.

> Removal of extra OR/AND with parantheses ( ) with dynamic prepend!
> ------------------------------------------------------------------
>
>          Key: IBATIS-95
>          URL: http://issues.apache.org/jira/browse/IBATIS-95
>      Project: iBatis for Java
>         Type: Improvement
>   Components: SQL Maps
>  Environment: Not a issue.
>     Reporter: Erlend Bjørge
>     Assignee: Brandon Goodin
>      Fix For: 2.1.0

>
> Hi there!
> I have run into the same kind of problem as Brandon Goodin replied on:
> http://www.mail-archive.com/ibatis-user-java@incubator.apache.org/msg01403.html
> The problem is not just related to complex queries, but dealing with Dynamic prepend
> and parantheses, you will end up with a extra OR/AND you don't need in you query. 
> Simple as that.
> If you would have made the where clause by yourself, the simple solution is
> after you are finished with your  (OR .... OR ... OR) clause, just remove the 
> first OR/AND after ( and then your clause is correct. This is a simple solution,
> shouldn't it be possible with be possible with SQLMap tags too ??
> What about a new tag like ? (Hope this come out with correct linefeed :-)
> where clause bla bla ....
> <isParameterPresent>
>     AND (
>     <removeFirstPrependValue> 
>         <isNotNull prepend="OR".....> 
>         <isNotNull prepend="OR" ...> 
>         <isNotNull prepend="OR" ...> 
>     </removeFirstPrependValue>
>     )
> <isParameterPresent>
> Or similar function in the other tags like this as an extra parameter:
> where clause bla bla ....
> <isParameterPresent>
>     AND (
>   
>     <isNotNull prepend="OR" property="id"   removeFirstPrepend="true"> 
>     <isNotNull prepend="OR" property="name" removeFirstPrepend="true">
>     ) 
> <isParameterPresent>
> ??? Isn't that a nice new feature that will remove this kind of problem ?
> ---
> Thanks!
> Best regards,
> Erlend Bjørge

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira