Do this in Java code. Doing it in xml is kinda silly. :)

Larry


On Wed, Jan 20, 2010 at 12:00 AM, masonka...@libero.it
<masonka...@libero.it> wrote:
> Hi,
>
> I have a write a update statement with condition on every set element.
> If
> no condition are matched set part are empty, but where part is already created
> and this cause a sql error (ex.: update where id=4).
>
> I show an example about
> it:
>
>        update iord
>        <set>
>            <if test="oldVO.bank !=
> newVO.bank">
>                bank=#{newVO.bank,jdbcType=VARCHAR},
>
> </if>
>            <if test="oldVO.agency != newVO.agency">
>
> agency=#{newVO.agency,jdbcType=VARCHAR},
>            </if>
>            <if
> test="oldVO.iban != newVO.iban">
>                iban=#{newVO.iban,
> jdbcType=VARCHAR},
>            </if>
>        </set>
>        where id = #{oldVO.
> id}
>    </update>
>
> if there aren't no change in bank, agency and iban set part
> is empty and sql not correct.
> I try to solve the problem inserting in set
> statement a field that assign value to itself.
>
>
>        update iord
>
> <set>
> id=id,
>            <if test="oldVO.bank != newVO.bank">
>
> bank=#{newVO.bank,jdbcType=VARCHAR},
>            </if>
>            <if test="
> oldVO.agency != newVO.agency">
>                agency=#{newVO.agency,
> jdbcType=VARCHAR},
>            </if>
>            <if test="oldVO.iban != newVO.
> iban">
>                iban=#{newVO.iban,jdbcType=VARCHAR},
>            </if>
>
>           <if test="oldVO.id != newVO.id">
>                id=#{newVO.id,
> jdbcType=VARCHAR},
>            </if>
>        </set>
>        where id = #{oldVO.
> id}
>    </update>
>
> But if also the id are interested in change there are some
> problem.
> Any idea?
>
> thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
> For additional commands, e-mail: user-java-h...@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org

Reply via email to