|
From: Nick E. <ne...@gm...> - 2009-08-18 15:20:00
|
But what if later you want to run the query with items = ['A', 'B', 'C',
'D']?
Then you're going to need to construct a new query because the original
query can only support 3 items., so you lose the performance gain of making
a query that takes parameters. I can't really see a better solution though.
Nick
On Tue, Aug 18, 2009 at 9:57 AM, Deron Meranda <der...@gm...>wrote:
> 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
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Python-sybase-misc mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/python-sybase-misc
>
|