0
我知道,我们可以使用executemany这样:是否有可能使用映射来执行MySQLdb的executemany功能(字典)
sql = "insert into a(c1,c2,c3) values(%s,%s,%s)"
seq_of_parameters = [('a','b','c'),('a','b','c')]
cu.executemany(sql,seq_of_parameters)
我不知道为什么这不起作用:
sql = "insert into a(c1,c2,c3) values(%(c1)s,%(c2)s,%(c3)s)"
seq_of_parameters = [{'c1':'a','c2':'b','c3':'c'},{'c1':'a','c2':'b','c3':'c'}]
cu.executemany(sql,seq_of_parameters)
来自PEP249 Python数据库API规范2.0版本
.executemany(operation,seq_of_parameters)
准备数据库操作(查询或命令),然后 针对在序列seq_of_parameters中找到的所有参数序列或映射 执行它。
也许MySQLdb只是不支持它。使用元组的序列就好了 – suyugo