So, I’m trying to do a SQLite prepared statement, something like this:
definition
c.execute('''CREATE TABLE IF NOT EXISTS tab (
_id integer PRIMARY KEY AUTOINCREMENT,
obj text NOT NULL,
val int NOT NULL
) ;''')
I want to execute the following prepared statement:
list_of_vars=['foo','bar']
statement = "SELECT * FROM tab WHERE obj IN ({0}) AND val BETWEEN ? AND ?".format(', '.join(['?' * len(list_of_vars)]))
My solution to this is quite ugly at the moment, and I’m looking for a more elegant way of doing this…
vals=list_of_vars
vals.append(0)
vals.append(100)
c.execute(statement, vals)
Any thoughts?
You can concatenate lists quite easily: