V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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 · 2012-07-05 20:22:17 +08:00 · 4179 次点击
    这是一个创建于 4310 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我写了一个简单的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 条回复    1970-01-01 08:00:00 +08:00
    napoleonu
        1
    napoleonu  
       2012-07-05 22:28:45 +08:00   ❤️ 1
    'blog' 多了两个单引号。
    INT21H
        2
    INT21H  
    OP
       2012-07-05 22:34:44 +08:00
    @napoleonu 已经搞定了
    改成这样了。。

    "SELECT * FROM %s WHERE id = %s" % (get_table, int(get_id))
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5261 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:19 · PVG 17:19 · LAX 02:19 · JFK 05:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.