U87
V2EX  ›  问与答

pymysql 入库 %s 占位符问题

  •  
  •   U87 · Aug 21, 2018 · 2108 views
    This topic created in 2821 days ago, the information mentioned may be changed or developed.

    sql = "INSERT INTO %s (%s) VALUES (%s)" val=(table, fields[:-1], values[:-1]) cursor.execute(sql, val) 我这边这么格式化参数对的.但是入库时报错 1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 请问是什么情况

    2 replies    2018-08-21 13:59:37 +08:00
    sujin190
        1
    sujin190  
       Aug 21, 2018
    你把一个数组直接转成字符串扔给 mysql 运行肯定挂啊
    blankme
        2
    blankme  
       Aug 21, 2018
    table name 不能直接作为变量传入
    psycopg2 的相关说明: http://initd.org/psycopg/docs/sql.html
    pymysql 应该也有相应的处理方式
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4241 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 00:07 · PVG 08:07 · LAX 17:07 · JFK 20:07
    ♥ Do have faith in what you're doing.