You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by "masonkante@libero.it" <ma...@libero.it> on 2010/01/20 08:00:53 UTC
update without set element
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
Re: update without set element
Posted by Larry Meadors <la...@gmail.com>.
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
<ma...@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