编程错误:提供的绑定数量不正确 [英] Programming Error: Incorrect number of bindings supplied
本文介绍了编程错误:提供的绑定数量不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我哪里做错了?
Can anyone tell me where I have done wrong?
我的代码:
import csv
import sqlite3
import os
import subprocess
import glob
#Connect to database
conn = sqlite3.connect("Mpeg_editor_Final.db")
try:
conn.execute("drop table Mpeg_editor_Final")
conn.execute("drop table edited")
conn.execute("drop table ffmpeg")
except sqlite3.OperationalError, e:
print e.message
#CREATE table in databse
conn.execute("PRAGMA foreign_keys = 1")
conn.execute("CREATE TABLE Mpeg_editor_Final (fileName VARCHAR(120), fileType VARCHAR(120), fileFolder VARCHAR(120))")
conn.execute("CREATE TABLE edited (fileName VARCHAR(120), fileType VARCHAR(120), fileFolder VARCHAR(120))")
conn.execute("CREATE TABLE ffmpeg (fileName VARCHAR(120), fileType VARCHAR(120), fileFolder VARCHAR(120))")
#mpegEditorFinal file location
mpegEditorFinal = 'C:\Mpeg_editor_Final'
#list all folders and file in Mpeg_editor_Final
mpegEditorFinaldirs = os.listdir(mpegEditorFinal)
# tell file's extensions
for i in mpegEditorFinaldirs:
mpegEditorFinalext = os.path.splitext(i)
#find current path
for x in mpegEditorFinaldirs:
mpegEditorFinalpath = os.path.dirname(x)
#To write information into the Mpeg_editor_final table
conn.executemany("INSERT INTO Mpeg_editor_Final (fileName, fileType, fileFolder) VALUES (?,?,?);", [mpegEditorFinaldirs , mpegEditorFinalext , mpegEditorFinalpath,])
conn.commit()
错误信息:
Message File Name Line Position
Traceback
<module> C:\Mpeg_editor_Final\database.py 36
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 16 supplied.
推荐答案
您已经使用了 executemany()
,但是您只为单次执行提供参数.要么进一步嵌套它们,要么使用 execute()
代替.
You've used executemany()
, but you only provide parameters for a single execution. Either nest them further, or use execute()
instead.
conn.executemany("INSERT INTO Mpeg_editor_Final (fileName, fileType, fileFolder) VALUES (?,?,?);", [[mpegEditorFinaldirs, mpegEditorFinalext, mpegEditorFinalpath]])
conn.execute("INSERT INTO Mpeg_editor_Final (fileName, fileType, fileFolder) VALUES (?,?,?);", [mpegEditorFinaldirs, mpegEditorFinalext, mpegEditorFinalpath])
这篇关于编程错误:提供的绑定数量不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文