|
From: Deron M. <der...@gm...> - 2009-08-18 14:51:16
|
On Tue, Aug 18, 2009 at 10:21 AM, <sk...@po...> wrote:
> Suppose I have this query:
>
> select foo from bar where baz in ("A", "B", "C")
>
> and want to parameterize the where clause. I've tried this:
>
> query = 'select foo from bar where baz in "@type"'
> args = {
> "@type": ("A", "B", "C"),
> }
>
> but I get a TypeError (unsupported parameter type) when I try to execute the
> query.
It's just a little more manual work on constructing your SQL. You
have to make each item in the set a separate substitution, rather
than trying to use just one substitution with a tuple.
Say you have a list or set of items you want to match. Then
try something like:
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) ] )
--
Deron Meranda
|