Monday, June 27, 2011

SQL query binding for a list using Python

From here:

l=[1,2,3,4] placeholder= '?' # Works For SQLite. placeholders= ', '.join(placeholder for dummy in l) #puts in len(l) '?' marks, separated by ', ' query= 'SELECT name FROM students WHERE id IN (%s)' % placeholders cursor.execute(query, l)

No comments:

Post a Comment