Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 1082 supplied

import sqlite3

database = r"files/users.db"
textfile = r"files/AlphaVList.txt"


class List:

    def getusers(f):
        return f


c = sqlite3.connect(database)

with open(textfile, "r") as openfile:
    file = openfile.read()
    # print(file)


nameList = []
addressList = []

fullAddress = file.split("\n")
fullAddress = fullAddress[1:]

userList = file.split('@')

try:
    for i in userList:
        u = i.split("\n")
        nameList.append(u[1])
        addressList.append(u[0])
except IndexError:
    pass
addressList.remove("")

c.executemany(f"INSERT INTO users (fullAddress, name, mailAddress) VALUES (?, ?, ?)", (tuple(fullAddress), tuple(nameList), tuple(addressList),))

Why am I getting this error?

The code was supposed to upload 3 lists into sql, and when I tried to insert the lists I got an error:
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 1082 supplied.
Ignore the rest of the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

When you use executemany() the second argument should be a list of rows. So it should be

[(fullAddress, name, mailAddress), (fullAddress, name, mailAddress), (fullAddress, name, mailAddress), ...]

but you’re creating

((fullAddress, fullAddress, fullAddress, ...), (name, name, name, ...), (mailAddress, mailAddress, mailAddress...)]

Use zip() to combine them in the proper way.

c.executemany(f"INSERT INTO users (fullAddress, name, mailAddress) VALUES (?, ?, ?)", 
    zip(fullAddress, nameList, addressList))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading