sqlite3.ProgrammingError:提供的绑定数量不正确 [英] sqlite3.ProgrammingError: Incorrect number of bindings supplied
问题描述
你能告诉我我在代码中做错了什么吗?
Could you tell me what I am doing wrong in the code?
我试图搜索这个特殊案例,但找不到答案.我还尝试使用 关于 sqlite3
,但无法让它工作.基本上,我在 inc_data
中有很多数据需要插入到 sqlite3 中.
I've tried to search for this particular case and could not find the answer. I've also tried to use example from the official docs on sqlite3
, but couldn't get it to work. Basically, I have a lot of data in inc_data
that I need to insert into sqlite3.
import sqlite3
inc_data = [[u'Period Ending', u'Dec 31, 2012', u'Dec 31, 2011', u'Dec 31, 2010'],
[u'Total Revenue\n', u'104,507,000\n', u'106,916,000\n', u'99,870,000\n'],
]
conn = sqlite3.connect("inc_data.db")
c = conn.cursor()
c.execute('''DROP TABLE inc_table''')
c.execute('''CREATE TABLE inc_table
(item text, value1 text, value2 text, value3 text)''')
c.execute('INSERT INTO inc_table VALUES (?,?,?,?)', inc_data)
conn.commit()
conn.close()
错误信息:
c.execute('INSERT INTO inc_table VALUES (?,?,?,?)', inc_data)
sqlite3.OperationalError: no such table: inc_table
非常感谢您的帮助.
推荐答案
您传入了两个项;每个参数列表.
You passed in two items; each a list of parameters.
要么使用 c.executemany()
(它确实需要一个序列序列),要么使用 inc_data
循环给 c.execute()
代码> 一组绑定值:
Either use c.executemany()
(which does expect a sequence of sequences), or loop over inc_data
to give c.execute()
one set of bind values:
# insert multiple rows; one for each entry in `inc_data`
c.executemany('INSERT INTO inc_table VALUES (?,?,?,?)', inc_data)
# or loop
for bind_values in inc_data:
c.execute('INSERT INTO inc_table VALUES (?,?,?,?)', bind_values)
这篇关于sqlite3.ProgrammingError:提供的绑定数量不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!