Tornado Documentation
http://www.v2ex.com/tornado/
Tornado on GitHub
https://github.com/facebook/tornado/
Tornado Gists
http://tornadogists.org/
INT21H
V2EX  ›  Tornado

Tornado中的MySQL语句出错问题

  •  
  •   INT21H · Jul 5, 2012 · 5009 views
    This topic created in 5094 days ago, the information mentioned may be changed or developed.
    我写了一个简单的SQL语句:
    return self.db.get("SELECT * FROM %s WHERE id = %s", get_table, int(get_id))

    然后数据库中有个表叫 blog , 其中一条 id = 1,即 get_table = 'blog', get_id = 1

    执行下来应该是
    SELECT * FROM blog WHERE id = 1

    可是报错如下:
    ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''blog' WHERE id = '1'' at line 1")

    呃,应该是字符串连接问题?这一句SQL应该没什么问题啊,急求解。。orz
    2 replies    1970-01-01 08:00:00 +08:00
    napoleonu
        1
    napoleonu  
       Jul 5, 2012   ❤️ 1
    'blog' 多了两个单引号。
    INT21H
        2
    INT21H  
    OP
       Jul 5, 2012
    @napoleonu 已经搞定了
    改成这样了。。

    "SELECT * FROM %s WHERE id = %s" % (get_table, int(get_id))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3112 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 12:19 · PVG 20:19 · LAX 05:19 · JFK 08:19
    ♥ Do have faith in what you're doing.