|
From: Deron M. <der...@gm...> - 2009-08-18 14:57:53
|
On Tue, Aug 18, 2009 at 10:51 AM, Deron Meranda<der...@gm...> wrote:
> items = ["A", "B", "C"]
> qitems = ", ".join( [ "@item%d" % n for n in range(len(items)) ] )
> query = "select foo from bar where baz in (" + qitems + ")
> args = dict( [ ("@item%d" % n, v) for n, v in enumerate(items) ] )
Oops, I dropped a missing quote character on the query= line above.
Oh, what the complicated-looking list comprehensions give you is
SQL which looks like:
select foo from bar where baz in (@item0, @item1, @item2)
and an argument dictionary that is like:
{'@item0': 'A', '@item1': 'B', '@item2': 'C'}
Though it will automatically handle any number of members
in the items list.
--
Deron Meranda
|