You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by Petr Kokorev <pe...@cern.ch> on 2006/02/17 17:05:08 UTC

removeFirstPrepend doesn't remove the first prepend?

Hello,


I have a simple insert query like this (I am sure that at least one of 
the properties is not empty)

<insert id="insertItem" parameterClass="item">
  INSERT INTO ITEMS_TABLE
  (
  <dynamic>
    <isNotEmpty prepend="," property="propertyOne" 
removeFirstPrepend="true">
      PROPERTY_ONE
    </isNotEmpty>
    <isNotEmpty prepend="," property="propertyTwo" 
removeFirstPrepend="true">
      PROPERTY_TWO
    </isNotEmpty>
  </dynamic>
  ,
  VALUE
  )
  VALUES
  (
  <dynamic>
    <isNotEmpty prepend="," property="propertyOne" 
removeFirstPrepend="true">
      #propertyOne#
    </isNotEmpty>
    <isNotEmpty prepend="," property="propertyTwo" 
removeFirstPrepend="true">
      #propertyTwo#
    </isNotEmpty>
  </dynamic>
  ,
  #value:NUMERIC#
  )
</insert>

The generated String for the prepared statement will be like this in the 
case of when both of the properties are not empty:

  INSERT INTO ITEMS_TABLE ( , PROPERTY_ONE , PROPERTY_TWO , VALUE ) 
VALUES ( , ? , ? , ? )

So the 1st prepend is not being removed.
I have done a workaround for it by specifying the prepend attribute for 
the <dynamic> element:

  <dynamic prepend="(">

Then it worked fine:

  INSERT INTO ITEMS_TABLE ( PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES 
( ? , ? , ? )

I just wonder, is it normal?
Because I find the 'prepend="("' thing a bit ugly, and I would like to 
have it like in my example.



Thanks in advance and respect

Pye

Re: removeFirstPrepend doesn't remove the first prepend?

Posted by Brandon Goodin <br...@gmail.com>.
Drop a bug in JIRA and attach a simple example that reproduces this
behavior and i'll take a look at it.

Brandon

On 2/20/06, Petr Kokorev <pe...@cern.ch> wrote:
> Brandon Goodin wrote:
>
> >The removeFirstPrepend does not work in the way you are expecting. The
> >rFP works to remove the first prepend that is produced by tags nested
> >in the body of the tag using the rFP. Als, the <dyanmic> tag should
> >automatically remove the first prepend. So, in your case you should
> >remove the rFP from the isNotEmpty tags. It should then work in the
> >manner you expect. If it does not, then we may have an issue.
> >
> >Brandon
> >
> >On 2/17/06, Petr Kokorev <pe...@cern.ch> wrote:
> >
> >
> >>Hello,
> >>
> >>
> >>I have a simple insert query like this (I am sure that at least one of
> >>the properties is not empty)
> >>
> >><insert id="insertItem" parameterClass="item">
> >>  INSERT INTO ITEMS_TABLE
> >>  (
> >>  <dynamic>
> >>    <isNotEmpty prepend="," property="propertyOne"
> >>removeFirstPrepend="true">
> >>      PROPERTY_ONE
> >>    </isNotEmpty>
> >>    <isNotEmpty prepend="," property="propertyTwo"
> >>removeFirstPrepend="true">
> >>      PROPERTY_TWO
> >>    </isNotEmpty>
> >>  </dynamic>
> >>  ,
> >>  VALUE
> >>  )
> >>  VALUES
> >>  (
> >>  <dynamic>
> >>    <isNotEmpty prepend="," property="propertyOne"
> >>removeFirstPrepend="true">
> >>      #propertyOne#
> >>    </isNotEmpty>
> >>    <isNotEmpty prepend="," property="propertyTwo"
> >>removeFirstPrepend="true">
> >>      #propertyTwo#
> >>    </isNotEmpty>
> >>  </dynamic>
> >>  ,
> >>  #value:NUMERIC#
> >>  )
> >></insert>
> >>
> >>The generated String for the prepared statement will be like this in the
> >>case of when both of the properties are not empty:
> >>
> >>  INSERT INTO ITEMS_TABLE ( , PROPERTY_ONE , PROPERTY_TWO , VALUE )
> >>VALUES ( , ? , ? , ? )
> >>
> >>So the 1st prepend is not being removed.
> >>I have done a workaround for it by specifying the prepend attribute for
> >>the <dynamic> element:
> >>
> >>  <dynamic prepend="(">
> >>
> >>Then it worked fine:
> >>
> >>  INSERT INTO ITEMS_TABLE ( PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES
> >>( ? , ? , ? )
> >>
> >>I just wonder, is it normal?
> >>Because I find the 'prepend="("' thing a bit ugly, and I would like to
> >>have it like in my example.
> >>
> >>
> >>
> >>Thanks in advance and respect
> >>
> >>Pye
> >>
> >>
> >>
> Hello again
>
>
> I tried what you have recomended, I removed all the rFP attributes from
> <isNotEmpty> tags - the result was absolutely the same as the last time.
> If you do not specify the 'prepend="..."' attribute in <dynamic> tag,
> the first prepend is not removed.
>
>
> Cheers
>
> Pye
>

Re: removeFirstPrepend doesn't remove the first prepend?

Posted by Petr Kokorev <pe...@cern.ch>.
Brandon Goodin wrote:

>The removeFirstPrepend does not work in the way you are expecting. The
>rFP works to remove the first prepend that is produced by tags nested
>in the body of the tag using the rFP. Als, the <dyanmic> tag should
>automatically remove the first prepend. So, in your case you should
>remove the rFP from the isNotEmpty tags. It should then work in the
>manner you expect. If it does not, then we may have an issue.
>
>Brandon
>
>On 2/17/06, Petr Kokorev <pe...@cern.ch> wrote:
>  
>
>>Hello,
>>
>>
>>I have a simple insert query like this (I am sure that at least one of
>>the properties is not empty)
>>
>><insert id="insertItem" parameterClass="item">
>>  INSERT INTO ITEMS_TABLE
>>  (
>>  <dynamic>
>>    <isNotEmpty prepend="," property="propertyOne"
>>removeFirstPrepend="true">
>>      PROPERTY_ONE
>>    </isNotEmpty>
>>    <isNotEmpty prepend="," property="propertyTwo"
>>removeFirstPrepend="true">
>>      PROPERTY_TWO
>>    </isNotEmpty>
>>  </dynamic>
>>  ,
>>  VALUE
>>  )
>>  VALUES
>>  (
>>  <dynamic>
>>    <isNotEmpty prepend="," property="propertyOne"
>>removeFirstPrepend="true">
>>      #propertyOne#
>>    </isNotEmpty>
>>    <isNotEmpty prepend="," property="propertyTwo"
>>removeFirstPrepend="true">
>>      #propertyTwo#
>>    </isNotEmpty>
>>  </dynamic>
>>  ,
>>  #value:NUMERIC#
>>  )
>></insert>
>>
>>The generated String for the prepared statement will be like this in the
>>case of when both of the properties are not empty:
>>
>>  INSERT INTO ITEMS_TABLE ( , PROPERTY_ONE , PROPERTY_TWO , VALUE )
>>VALUES ( , ? , ? , ? )
>>
>>So the 1st prepend is not being removed.
>>I have done a workaround for it by specifying the prepend attribute for
>>the <dynamic> element:
>>
>>  <dynamic prepend="(">
>>
>>Then it worked fine:
>>
>>  INSERT INTO ITEMS_TABLE ( PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES
>>( ? , ? , ? )
>>
>>I just wonder, is it normal?
>>Because I find the 'prepend="("' thing a bit ugly, and I would like to
>>have it like in my example.
>>
>>
>>
>>Thanks in advance and respect
>>
>>Pye
>>
>>    
>>
Hello again


I tried what you have recomended, I removed all the rFP attributes from 
<isNotEmpty> tags - the result was absolutely the same as the last time.
If you do not specify the 'prepend="..."' attribute in <dynamic> tag, 
the first prepend is not removed.


Cheers

Pye

Re: removeFirstPrepend doesn't remove the first prepend?

Posted by Brandon Goodin <br...@gmail.com>.
The removeFirstPrepend does not work in the way you are expecting. The
rFP works to remove the first prepend that is produced by tags nested
in the body of the tag using the rFP. Als, the <dyanmic> tag should
automatically remove the first prepend. So, in your case you should
remove the rFP from the isNotEmpty tags. It should then work in the
manner you expect. If it does not, then we may have an issue.

Brandon

On 2/17/06, Petr Kokorev <pe...@cern.ch> wrote:
> Hello,
>
>
> I have a simple insert query like this (I am sure that at least one of
> the properties is not empty)
>
> <insert id="insertItem" parameterClass="item">
>   INSERT INTO ITEMS_TABLE
>   (
>   <dynamic>
>     <isNotEmpty prepend="," property="propertyOne"
> removeFirstPrepend="true">
>       PROPERTY_ONE
>     </isNotEmpty>
>     <isNotEmpty prepend="," property="propertyTwo"
> removeFirstPrepend="true">
>       PROPERTY_TWO
>     </isNotEmpty>
>   </dynamic>
>   ,
>   VALUE
>   )
>   VALUES
>   (
>   <dynamic>
>     <isNotEmpty prepend="," property="propertyOne"
> removeFirstPrepend="true">
>       #propertyOne#
>     </isNotEmpty>
>     <isNotEmpty prepend="," property="propertyTwo"
> removeFirstPrepend="true">
>       #propertyTwo#
>     </isNotEmpty>
>   </dynamic>
>   ,
>   #value:NUMERIC#
>   )
> </insert>
>
> The generated String for the prepared statement will be like this in the
> case of when both of the properties are not empty:
>
>   INSERT INTO ITEMS_TABLE ( , PROPERTY_ONE , PROPERTY_TWO , VALUE )
> VALUES ( , ? , ? , ? )
>
> So the 1st prepend is not being removed.
> I have done a workaround for it by specifying the prepend attribute for
> the <dynamic> element:
>
>   <dynamic prepend="(">
>
> Then it worked fine:
>
>   INSERT INTO ITEMS_TABLE ( PROPERTY_ONE , PROPERTY_TWO , VALUE ) VALUES
> ( ? , ? , ? )
>
> I just wonder, is it normal?
> Because I find the 'prepend="("' thing a bit ugly, and I would like to
> have it like in my example.
>
>
>
> Thanks in advance and respect
>
> Pye
>