使用python中的mysql插入来对抗空值和撇号

时间:2016-12-14 17:18:01

标签: python mysql

以下代码是我正在努力解决的mysql插件。如果我可以让它接受Nones(我需要插入不同数量的空值),那么我就无法接受这些空值。目前,我似乎遇到了空值问题。

        sql = "INSERT INTO `dtdbtest`.`card` (`pack_id`,`type_id`,`shooter_id`,`gang_id`,`ts`,`code`,`number`,`quantity`,`title`,`keywords`,`text`,`flavor`,`illustrator`,`cost`,`rank`,`upkeep`,`production`,`bullets`,`influence`,`control`,`wealth`) VALUES ({},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{});"

        cur.execute(sql, [packid, typeid, shooterid, gangid, card['last-modified'], card['code'], card['number'], card['quantity'], card['title'], card['keywords'], card['text'], card['flavor'], card['illustrator'], card['cost'], card['rank'], card['upkeep'], card['production'], card['bullets'], card['influence'], card['control'], card['wealth']])
        db.commit()

这里是sql汇编的输出,列表传递给cur.execute()

    INSERT INTO `dtdbtest`.`card` (`pack_id`,`type_id`,`shooter_id`,`gang_id`,`ts`,`code`,`number`,`quantity`,`title`,`keywords`,`text`,`flavor`,`illustrator`,`cost`,`rank`,`upkeep`,`production`,`bullets`,`influence`,`control`,`wealth`) VALUES ({},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{});
    [7, 6, None, None, '2015-11-14T20:18:33+00:00', '00005', 5, 1, 'One Good Turn\\u2026', None, '<b>Noon:<\\/b> Draw a card.\r\n<b>Cheatin\\u2019 Resolution:<\\/b> Gain 3 ghost rock.', '\\u201cI sure do owe ya one, Mr. Grothe... too bad ya don\\u2019t drink.\\u201d \\u2014Clementine Lepp', 'David Hueso', 0, 6, None, None, None, None, None, None]

这是实际的错误块

         67             poop = [packid, typeid, shooterid, gangid, card['last-modified'], card['code'], card['number'], card['quantity'], card['title'], card['keywords'], card['text'], card['flavor'], card['illustrator'], card['cost'], card['rank'], card['upkeep'], card['production'], card['bullets'], card['influence'], card['control'], card['wealth']]
         68             print poop
    ---> 69             cur.execute(sql, [packid, typeid, shooterid, gangid, card['last-modified'], card['code'], card['number'], card['quantity'], card['title'], card['keywords'], card['text'], card['flavor'], card['illustrator'], card['cost'], card['rank'], card['upkeep'], card['production'], card['bullets'], card['influence'], card['control'], card['wealth']])
         70             db.commit()
         71 

    /usr/lib/python2.7/dist-packages/MySQLdb/cursors.pyc in execute(self, query, args)
        157             query = query.encode(charset)
        158         if args is not None:
    --> 159             query = query % db.literal(args)
        160         try:
        161             r = self._query(query)

    TypeError: not all arguments converted during string formatting

0 个答案:

没有答案