ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: update without set element
Date Wed, 20 Jan 2010 12:05:46 GMT
Do this in Java code. Doing it in xml is kinda silly. :)

Larry


On Wed, Jan 20, 2010 at 12:00 AM, masonkante@libero.it
<masonkante@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-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

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


Mime
View raw message