MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
geew
V2EX  ›  MySQL

一直没注意到的一个 mysql 的问题-字符串到 int 的自动转换

  •  
  •   geew · Oct 17, 2014 · 5212 views
    This topic created in 4315 days ago, the information mentioned may be changed or developed.
    感觉好坑爹啊, 由这个引起的:




    查了下:
    http://cqjava.iteye.com/blog/1042182

    大家注意到这个问题不, 好恶心
    11 replies    2017-05-25 15:00:04 +08:00
    Livid
        1
    Livid  
    MOD
    PRO
       Oct 17, 2014
    不熟悉 torndb,但是疑问是 torndb 里不需要对输入的参数做任何 escape 处理么?
    11138
        2
    11138  
       Oct 17, 2014
    这个字符串自动转换成数字的问题,除了MySQL,还有Perl、PHP等编程都是这样啊。
    geew
        3
    geew  
    OP
       Oct 17, 2014
    @Livid 应该会做 但这里跟torndb没有关系了 就是mysql的自动转换....
    geew
        4
    geew  
    OP
       Oct 17, 2014
    @11138 还真没注意到这个 给同事看了也觉得不可思议
    Livid
        5
    Livid  
    MOD
    PRO
       Oct 17, 2014
    @geew 如果有 escape 的话,也会发生这样的转换么。
    geew
        6
    geew  
    OP
       Oct 17, 2014
    @Livid livid数据库层都用什么库呢? mysqldb? sqlalchemy? 还是其他的
    geew
        7
    geew  
    OP
       Oct 17, 2014
    @Livid %s传进去的都会处理 我做过测试了 然后传给mysql 但字符串到int的转换是mysql做的
    Livid
        8
    Livid  
    MOD
    PRO
       Oct 17, 2014
    geew
        9
    geew  
    OP
       Oct 17, 2014
    @Livid 看了torndb的源码 它基本什么也没做, 都是把参数传到mysqldb来处理的, mysqldb的处理:
    https://gist.github.com/anonymous/da0a0757bea150bc96b0

    试了下, 结果类似这样子的:
    https://gist.github.com/anonymous/7997605274392aa54020
    11138
        10
    11138  
       Oct 17, 2014
    如果是int类型,最好不要加引号,“好像”会影响效率。
    cowpea
        11
    cowpea  
       May 25, 2017
    要从一个 json 字段取数据,小于 5.7 没有 json 处理函数,0+substring(test,8) test 形如:{"id":"5641","de
    =-=在这里还是蛮有用的嘛
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5592 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 06:33 · PVG 14:33 · LAX 23:33 · JFK 02:33
    ♥ Do have faith in what you're doing.