错误sql语句: `name` = "aa" = "bb"的语义转化

时间:2021-02-18 13:09:04   收藏:0   阅读:0

假设不小心写错了sql的条件,写成了 `name` = "aa" = "bb",总结sql的语义转化如下:

   由于 select ("aa" = "bb") 得到结果零,因此  

   update table set `name` = ("aa" = "bb"); ==>:update table set `name` = 0; 

  select * from talbe where `name` = "aa" = "bb";==> select * from talbe where (`name` = "aa") = "bb"; 

  如果 `name`跟"aa"是否相等,相等则(`name` = "aa") 得到结果值为1,否则得到结果0,而1或者0与"bb"进行比较,相当于int与string比较,因此都转换为float进行比较,隐式转换"bb"得到结果0,当(`name` = "aa") 值为0时,相当于0=0,恒等于1,于是当(`name` = "aa")为0时结果恒成立,相当于select * from talbe where 1=1;因此可以得到`name` != "aa"的结果。

参考自https://mp.weixin.qq.com/s/PgFdy4rlfCayauYFphDFTg 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!