Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
281 views
in Technique[技术] by (71.8m points)

python - Programming Error: Incorrect number of bindings supplied

Can anyone tell me where I have done wrong?

my code:

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()

The error message:

 Message    File Name   Line    Position    

 Traceback              
    <module>    C:Mpeg_editor_Finaldatabase.py    36      
    ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3,     and there are 16 supplied.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...