removeFirstPrepend won't work unless dynamic has a filled prepend attribute.
----------------------------------------------------------------------------

                 Key: IBATIS-430
                 URL: https://issues.apache.org/jira/browse/IBATIS-430
             Project: iBatis for Java
          Issue Type: Bug
          Components: Documentation, SQL Maps
    Affects Versions: 2.3.0
         Environment: GNU/Linux, kernel 2.6.15, debian etch amd64 
Sun's Java 1.5 
java version "1.5.0_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_10-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_10-b03, mixed mode)
tomcat 5.5

            Reporter: Xavi Drudis Ferran
            Priority: Minor


According to documentation the attribute removeFirstPrepend="true" in a 
isPropertyAvailable element will 
avoid it's prepend value to be prepended for the first such element that 
generates content in the closest
enclosing dynamic element. 

I've been unable to get that to work unless I also add a prepend attribute to 
the dynamic element, which 
in principle I don't need. Furthermore the value of the prepend attribute in 
the dynamic element 
can't be void for the removeFirstPrepend of its children to work. (but it can 
be some whitespace characters,
which is harmless to the generated SQL). 

I don't see why this would be the intended behaviour, but if it is, then I 
think the documentation could be improved, 
I don't see there any need for a prepend attribute in the dynamic element .

Sample statement : 

<update id="updatePatientThirdLevelByCip" parameterClass="java.util.Map">
                UPDATE DOCUMENTS SET
                  <dynamic >
                    <isPropertyAvailable property="CIP" prepend="," 
removeFirstPrepend="true">
                       CIP = #CIP#
                    </isPropertyAvailable>
                    <isPropertyAvailable property="DNI" prepend="," 
removeFirstPrepend="true">
                       DNI = #DNI#
                    </isPropertyAvailable>
                   </dynamic>
                WHERE CIP IN (
                              <iterate property="CIPS" conjunction=", "> 
                                 #CIPS[]#
                              </iterate>
                         )  
        </update>

will generate, when passed CIP= A, CIPS = [B] and no DNI key at all in the 
parameter map: 

   UPDATE DOCUMENTS SET      ,
    CIP = ?               WHERE CIP IN (                                      ? 
                                )

Which has an extra comma "," after the SET keyword. I thought the dynamic 
element and removeFirstPrepend 
in the isPropertyAvailable would suffice to avoid this comma (the prepends 
value in the children).

If I change the dynamic element to read <dynamic prepend="">
it still generates the same incorrect SQL with the first prepends not remove, 
but instead if I try this : 
<update id="updatePatientThirdLevelByCip" parameterClass="java.util.Map">
                UPDATE DOCUMENTS SET
                  <dynamic prepend="    ">
                    <isPropertyAvailable property="CIP" prepend="," 
removeFirstPrepend="true">
                       CIP = #CIP#
                    </isPropertyAvailable>
                    <isPropertyAvailable property="DNI" prepend="," 
removeFirstPrepend="true">
                       DNI = #DNI#
                    </isPropertyAvailable>
                   </dynamic>
                WHERE CIP IN (
                              <iterate property="CIPS" conjunction=", "> 
                                 #CIPS[]#
                              </iterate>
                         )  
        </update>

then it generates the correct SQL : 

   UPDATE DOCUMENTS SET      
    CIP = ?               WHERE CIP IN (                                      ? 
                                )

whitouht any comma. 

Note: I haven't tried without the iterate clause later in the statement, since 
I don't see any relation to the issue. 

Thanks a lot for your useful great work, btw. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to