On Sep 26, 12:23 pm, Tino Wildenhain <[EMAIL PROTECTED]> wrote:
> Hi,
>
>
>
> Bruno Desthuilliers wrote:
> > bcurtu a écrit :
> >> Hi,
>
> >> I have a BIIIIIG problem with the next query:
>
> >>         cursor.execute("""
> >>                     SELECT titem.object_id, titem.tag_id
> >>                     FROM tagging_taggeditem titem
> >>                     WHERE titem.object_id IN (%s)
> >>                 """,( eid_list))
>
> >> eid_list is suppossed to be a list of ids = [1,5,9]
>
> >> How can I make it work?
>
> > You have to build your sql statement in three stages:
>
> > # stage 0: the template
> > sql_template = """
> >     SELECT titem.object_id, titem.tag_id
> >     FROM tagging_taggeditem titem
> >     WHERE titem.object_id IN (%s)
> > """
>
> > # stage 1: build correct place_holders string for the actual number
> > # of items in eid_list
> > place_holders = ", " .join("%s" for x in xrange(len(eid_list)))
>
> Hm. either ", ".join(["%s"]*len(eid_list))
> or ", ".join("%s" for x in eid_list)
>
> should produce the same, wouldn't it? :-)
>
[snip]
Or:

    place_holders = ("%s," * len(eid_list))[ : -1]

:-)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to