我正在尝试将dict值插入数据库。但我有个错误。here is my dictionary。我用的是这个密码。你知道吗
`cols = filter_dict.keys()
vals = filter_dict.values()
("INSERT INTO table (%s) VALUES (%s)", [cols, vals])
`
当我只打印这个查询时("INSERT INTO table (%s) VALUES (%s)", [cols, vals])
。
我得到以下输出。
('INSERT INTO table (%s) VALUES (%s)', [['cinematography', 'name', 'producer', 'caption', 'studio', 'editing'], ['Venkat Prasad', '100% Love', 'Bunny Vasu', '', '100% Love Poster.jpg', 'Chandra Sekhar T Ramesh,Hari Prasad']])
但是当我执行这个查询时,我得到了奇怪的输出。
the manual that corresponds to your MySQL server version for the right syntax to use near \'table (("\'cinematography\'", "\'name\
为什么要执行向每列添加“\”的查询??有人能帮我吗?谢谢
反斜杠可能是由于调试器造成的。您是否在交互式提示中运行代码?你知道吗
无论如何,实际的问题是:
table
是reserved word。你应该把table
放在反记号里。你知道吗%s
和多个值。你知道吗例如:
您还需要更改
(cols, vals)
以列出各个值。你知道吗我也强烈建议你为你的桌子找一个更好的名字,最好是:
1)描述表中包含的数据类型,以及
2)不是保留字
相关问题 更多 >
编程相关推荐