Reputation: 55
I am trying to insert a list of lists in a database but i get this error " cursor.execute('INSERT INTO Test VALUES(?, ?, ?)',list2) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 3, and there are 200 supplied." in my list of lists there are 201 lists
import sqlite3
import csv
import pandas as pd
def Load():
list1 = []
comparar = []
conexion = sqlite3.connect("Pruebas")
cursor = conexion.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Test ( "id" INT NOT NULL , "User" TEXT NOT NULL , "Followed" INT NOT NULL , PRIMARY KEY (id))')
cursor.execute("SELECT * FROM Test")
list1 = cursor.fetchall()
#print(data)
data = pd.read_csv(r'J:\\Proyectos y Trabajos\\Python\\Bot Instagram Follow\\Terminado BR\\Test.csv',delimiter=';')
tuples = [tuple(x) for x in data.values]
for i in tuples:
if i not in list1:
list1.append(i)
list2 = [list(elem) for elem in list1]
cursor.execute("DELETE FROM Test")
conexion.commit()
cursor.execute('INSERT INTO Test VALUES(?, ?, ?)',list2)
conexion.commit()
conexion.close()
Load()
Upvotes: 0
Views: 697
Reputation: 33359
Iterate over list2
and perform an insert on the values in each sub-list:
for sublist in list2:
cursor.execute('INSERT INTO Test VALUES(?, ?, ?)', sublist)
connexion.commit()
Upvotes: 1