[Zope] formatting tuple to feed to mysql

2005-05-09 Thread David Siedband
I'm have a tuple that I want to pass to a zSQL query to so I can based 
on items in the tuple.  I get the sequence from a zSQL query that 
selects a single field, and I'm postprocessing it with the following:

dtml-let SelectedIDs=[ai[0] for ai in queries.selectDOdocIDs().tuples()]
Which puts the sequence in brackets like this:
[211, 873, 515, 516, 589]
but mysql seems to want them in parenthesis... because when I try this
select ThemeWords.*
from DocThemes, ThemeWords
where DocThemes.DocID in dtml-var SelectedIDs
and DocThemes.ThemeID = ThemeWords.ID
I get a KeyError.
Also, is it possible to pass a list using dtml-sqlvar?
thanks
--
David


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] formatting tuple to feed to mysql

2005-05-09 Thread J Cameron Cooper
David Siedband wrote:
I'm have a tuple that I want to pass to a zSQL query to so I can based 
on items in the tuple.  I get the sequence from a zSQL query that 
selects a single field, and I'm postprocessing it with the following:

dtml-let SelectedIDs=[ai[0] for ai in 
queries.selectDOdocIDs().tuples()]

Which puts the sequence in brackets like this:
[211, 873, 515, 516, 589]
That's the standard Python representation of a list. SQL likes a 
different syntax.

but mysql seems to want them in parenthesis... because when I try this
select ThemeWords.*
from DocThemes, ThemeWords
where DocThemes.DocID in dtml-var SelectedIDs
and DocThemes.ThemeID = ThemeWords.ID
I get a KeyError.
The key error would indicate (depending on what it says: since that's 
not provided I'm just guessing) that your dtml-let does not contain the 
code above.

Also, is it possible to pass a list using dtml-sqlvar?
No. It's not that smart.
You should iterate over your list (dtml-in) to generate an SQL list::
(dtml-in SelectedIDsdtml-var sequence-item type=string,/dtml-in)
		--jcc
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )