0

I've created this table in my database:

cur.execute("""CREATE TABLE VIDEO(ID VARCHAR(128) NOT NULL PRIMARY KEY)""")

and what my script is supposed to do is to read all the files in a folder and put the filename into the VIDEO table (the filename is the ID and primary key):

def AddVideo(video):
    con = sqlite3.connect("C:\\Users\\Francesco\\Desktop\\db\\Database.db")
    with con:
        cur = con.cursor()
        cur.execute("""PRAGMA foreign_keys=ON""")
        cur.execute("""INSERT INTO VIDEO(ID) VALUES(?)""", (video))

But I got this error:

    cur.execute("""INSERT INTO VIDEO(ID) VALUES(?)""", (video))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 26 supplied.

Now 26 is the the number of characters in the filename that I'm trying to add, all files are read from the folder with this:

for video in os.listdir(VIDEO_FOLDER):
  AddVideo(video)
2
  • Can you please check if the solution provided here helps you: [1] [1]: stackoverflow.com/questions/16856647/… Commented May 23, 2015 at 19:36
  • Was exactly this the problem, thanks! Commented May 23, 2015 at 19:54

1 Answer 1

2

If I am not mistaken, the cur.execute() function takes a tuple of parameters as its second argument. It's treating your value parameter as a tuple, which in this case is 26 characters long. To make it a tuple, just add a comma!

cur.execute("""INSERT INTO VIDEO(ID) VALUES(?)""", (video,))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.