lundi 19 octobre 2015

Python SQLite List Query with variables Multiselect

i have a working SQLite Query to query for a List of ID Numbers:

SELECT * FROM mytable WHERE id NOT IN ("1120", "1121")

returns correctly all rows without the specified id's

Now i want to do this with Python:

conn = sqlite3.connect('myDB.db')
c = conn.cursor()

temp = [("1120","1121")]
c.execute("SELECT * FROM mytable WHERE id NOT IN (?)", (temp,))
result = c.fetchall()

This is not working and returning Error binding parameter 0 - probably unsupported type.

I know SQLite only accepts specific datatypes, but is there a special python syntax to provide the tuple/list?

I have also tried using a list instead of the tuple, which does not work either. I intent to use a list of variable length, so hard-coding the list of arguments is no option.

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire