Mysql字段int的value为0时产生的bug

查询

userId 在数据库中为int类型

select * from userinfo where userId = 0

等于

select * from userinfo where userId = ''

容易出现bug

当id为int类型,根据id批量(逻辑)删除记录时。

update userinfo set isdel = 1 where userId in('')

这里尽管没有删除,但是空字符串会被当成0来执行。会把id为0的删除掉。

解决办法就是当id不存在时不执行此语句。 

猜你喜欢

转载自www.cnblogs.com/aeolian/p/12303951.html