why it can run without exception?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

why it can run without exception?

yangyuchao2010
<sql id="baseModifyInfo">
    last_update_time = case
    <foreach collection="groupList" item="123">
        when id = #{group.id} then #{group.lastUpdateTime}
    </foreach>
    end,
    last_update_pin = case
    <foreach collection="groupList" item="group">
        when id = #{group.id} then #{group.lastUpdatePin}
    </foreach>
    end,
</sql>

<update id="deleteGroup">
    update raven_quick_reply_vender_group
    <trim prefix="set" suffixOverrides=",">
        active_flag = 0,
        <include refid="baseModifyInfo"/>
    </trim>
    <![CDATA[WHERE active_flag = 1 and vender_id=#{venderId} AND id IN]]>
    <foreach collection="groupList" item="group" open="(" separator="," close=")">
        <![CDATA[#{group.id}]]>
    </foreach>
</update>

int deleteGroup(@Param("venderId") String venderId, @Param("groupList") List<QuickReplyGroup> groupList);

when the red item's value is incorrect, it can run without any exception and the value is right in database. but if the blue item's value is incorrect, will throw exception : Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'last_update_pin' cannot be null。

the databse is mysql ,and table is defined:
CREATE TABLE `raven_quick_reply_vender_group` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT ,
  `vender_id` varchar(32) NOT NULL ,
  `group_name` varchar(20) NOT NULL ,
  `num` tinyint(4) NOT NULL COMMENT ,
  `active_flag` tinyint(8) NOT NULL DEFAULT '1' ,
  `last_update_pin` varchar(64) NOT NULL DEFAULT '' ,
  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  `create_pin` varchar(64) NOT NULL DEFAULT '' ,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `vender_id` (`vender_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 ;

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: why it can run without exception?

Guy Rouillier-2
I think the trim tag might be muddying the waters; you'll have to debug to be sure.  In the red case, your item name 123 is never referenced and "group" is undefined, so the entire case body is empty; trim likely just removes the whole thing, in which case you end up using the database default value.  In the blue case, you are using the correct item label, so the test is actually being applied.  I'm guessing you are finding group.id, but group.lastUpdatePin is null.  Both these scenarios are fixable: for red, use a correct item label, and for blue, check lastUpdatePin for null with an <IF> statement.

--
Guy Rouillier

------ Original Message ------
To: "mybatis-user" <[hidden email]>
Sent: 2/8/2018 10:24:57 PM
Subject: why it can run without exception?

<sql id="baseModifyInfo">
    last_update_time = case
    <foreach collection="groupList" item="123">
        when id = #{group.id} then #{group.lastUpdateTime}
    </foreach>
    end,
    last_update_pin = case
    <foreach collection="groupList" item="group">
        when id = #{group.id} then #{group.lastUpdatePin}
    </foreach>
    end,
</sql>

<update id="deleteGroup">
    update raven_quick_reply_vender_group
    <trim prefix="set" suffixOverrides=",">
        active_flag = 0,
        <include refid="baseModifyInfo"/>
    </trim>
    <![CDATA[WHERE active_flag = 1 and vender_id=#{venderId} AND id IN]]>
    <foreach collection="groupList" item="group" open="(" separator="," close=")">
        <![CDATA[#{group.id}]]>
    </foreach>
</update>

int deleteGroup(@Param("venderId") String venderId, @Param("groupList") List<QuickReplyGroup> groupList);

when the red item's value is incorrect, it can run without any exception and the value is right in database. but if the blue item's value is incorrect, will throw exception : Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'last_update_pin' cannot be null。

the databse is mysql ,and table is defined:
CREATE TABLE `raven_quick_reply_vender_group` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT ,
  `vender_id` varchar(32) NOT NULL ,
  `group_name` varchar(20) NOT NULL ,
  `num` tinyint(4) NOT NULL COMMENT ,
  `active_flag` tinyint(8) NOT NULL DEFAULT '1' ,
  `last_update_pin` varchar(64) NOT NULL DEFAULT '' ,
  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  `create_pin` varchar(64) NOT NULL DEFAULT '' ,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `vender_id` (`vender_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 ;

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: why it can run without exception?

yangyuchao2010
Actually, the value is not default in database but the value i deliver such as a special lastUpdateTime '2020-11-20'.

在 2018年2月9日星期五 UTC+8下午1:08:05,Guy Rouillier写道:
I think the trim tag might be muddying the waters; you'll have to debug to be sure.  In the red case, your item name 123 is never referenced and "group" is undefined, so the entire case body is empty; trim likely just removes the whole thing, in which case you end up using the database default value.  In the blue case, you are using the correct item label, so the test is actually being applied.  I'm guessing you are finding <a href="http://group.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;">group.id, but group.lastUpdatePin is null.  Both these scenarios are fixable: for red, use a correct item label, and for blue, check lastUpdatePin for null with an <IF> statement.

--
Guy Rouillier

------ Original Message ------
From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="wsEJVSWtCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">yangyuc...@...
To: "mybatis-user" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="wsEJVSWtCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybati...@...>
Sent: 2/8/2018 10:24:57 PM
Subject: why it can run without exception?

<sql id="baseModifyInfo">
    last_update_time = case
    <foreach collection="groupList" item="123">
        when id = #{group.id} then #{group.lastUpdateTime}
    </foreach>
    end,
    last_update_pin = case
    <foreach collection="groupList" item="group">
        when id = #{<a href="http://group.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;">group.id} then #{group.lastUpdatePin}
    </foreach>
    end,
</sql>

<update id="deleteGroup">
    update raven_quick_reply_vender_group
    <trim prefix="set" suffixOverrides=",">
        active_flag = 0,
        <include refid="baseModifyInfo"/>
    </trim>
    <![CDATA[WHERE active_flag = 1 and vender_id=#{venderId} AND id IN]]>
    <foreach collection="groupList" item="group" open="(" separator="," close=")">
        <![CDATA[#{<a href="http://group.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgroup.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGRaWXMJ0s8osSpAPJTAInAHA8VnA&#39;;return true;">group.id}]]>
    </foreach>
</update>

int deleteGroup(@Param("venderId") String venderId, @Param("groupList") List<QuickReplyGroup> groupList);

when the red item's value is <a href="http://www.baidu.com/link?url=_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_" style="color:rgb(51,51,51);font-family:arial" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYRbx-45y_-NJ4ICgD9cABOjI_8g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYRbx-45y_-NJ4ICgD9cABOjI_8g&#39;;return true;">incorrect, it can run without any exception and the value is right in database. but if the blue item's value is <a href="http://www.baidu.com/link?url=_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_" style="color:rgb(51,51,51);font-family:arial" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYRbx-45y_-NJ4ICgD9cABOjI_8g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D_BCNWq2822mSc0PJW6AHE4PH83NXR4XnsEcOV5uKlyhORKBZqvKMUYqmmJcXhlGYfd_C05YrxMeID0pSHC6yxL4GSqS048Aw9cmEIm8jUB_\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHYRbx-45y_-NJ4ICgD9cABOjI_8g&#39;;return true;">incorrect, will throw exception : Cause: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'last_update_pin' cannot be null。

the databse is mysql ,and table is defined:
CREATE TABLE `raven_quick_reply_vender_group` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT ,
  `vender_id` varchar(32) NOT NULL ,
  `group_name` varchar(20) NOT NULL ,
  `num` tinyint(4) NOT NULL COMMENT ,
  `active_flag` tinyint(8) NOT NULL DEFAULT '1' ,
  `last_update_pin` varchar(64) NOT NULL DEFAULT '' ,
  `last_update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  `create_pin` varchar(64) NOT NULL DEFAULT '' ,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `vender_id` (`vender_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 ;

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="wsEJVSWtCQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.