0
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

1
  • You misunderstood the second parameter of executemany. In your case the parameter sequence has to contain tuples with 3 elements each. Commented Nov 14, 2022 at 18:20

1 Answer 1

1

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