views:

56

answers:

3

Consider this (using apsw here):

s = ["A", "B", "C"]
c.execute("SELECT foo.y FROM foo WHERE foo.x in (?)", (s, ))

This doesn't work, because a binding parameter cannot be a list. I want to bind a list of strings to ?. I know how to build the appropriate query-string manually, but I wonder if there is a way to do this with bindings.

A: 

I had this problem around 4 years ago, and then I found out it was impossible to bind lists to sql (i was using mssql server and ODBC provider, but also considered direct sql calls)
In my case i was just building the queries manually and it was efficient. In case you have a very long list of values you will have to create another table, populate it in runtime and join with it in your sql.

ULysses
A: 

Going with the multiple question marks idea by Fabian, how about

c.execute("SELECT foo.y FROM foo WHERE foo.x in (%s)" % ', '.join('?' * len(s)), s)
Marius Gedminas
I should've checked gimel's link before answering. It's the same answer.
Marius Gedminas
A: 

Since not enough people voted to close this as a duplicate, here is a link to a question that has a good answer.

Space_C0wb0y