1

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_Final\database.py    36      
    ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3,     and there are 16 supplied.
infused
  • 24,000
  • 13
  • 68
  • 78

2 Answers2

1

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])
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
-1

Its because the conn.execute requires two parameters ..Here you havnt provided the exact parameters.

See here.It solves your problem .

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26