微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 有没有办法检测mysql中的溢出?

经过一段时间试图杀死这个bug,我直接测试了SQL查询

UPDATE noticias SET
    data_destaque_ini='2013-12-03', data_destaque_fim='',
    fotoDestaque_x=-3, fotoDestaque_y=-102,
    fotoDestaque_escala=154, destacar=1
WHERE idNoticia=3

但fotoDestaque_escala保持与以前相同的值:127.嗯,这是一个“圆”数,对吗?因此,即使没有任何sql错误消息,我打开了结构,就是这样:列设置为tinyint(-127到127),并将其更改为SMALLINT解决了问题.

但是考虑到未来,我对MysqL的这种行为感到震惊:我为这个专栏传递了太大的价值,MysqL保存了可能的东西,削减了其余部分,并且没有说出任何关于 – 客户端仍处于黑暗状态!

那么,有没有办法以某种方式配置或检测溢出?如果没有,我正在考虑在我的库中进行PHP级别测试…

解决方法:

直接取自MysqL文档中的11.2.6 Out-of-Range and Overflow Handling

When MysqL stores a value in a numeric column that is outside the permissible range of the column data type, the result depends on the sql mode in effect at the time:

  • If strict sql mode is enabled, MysqL rejects the out-of-range value with an error, and the insert fails, in accordance with the sql standard.
  • If no restrictive modes are enabled, MysqL clips the value to the appropriate endpoint of the range and stores the resulting value instead.

因此,如果您想要一个错误,您需要将MysqL置于严格的sql模式.如何更改模式在5.1.7 Server SQL Modes中描述.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐