[ZPT] zpt + zsql
Brent Hendricks
brentmh@ece.rice.edu
Fri, 07 Dec 2001 07:58:12 -0600
Nicola Larosa wrote:
> > The difficult part is iteration over the result set, when it becomes
> > large. There is not "dtml-in" with all of its features.
>
> Do you mean this stuff?
>
> http://dev.zope.org/Wikis/DevSite/Projects/ZPT/RepeatVariable
>
>
> > More fancy stuff, like e.g. statistics, are probably done in
>
> One thing that could be useful: only recently I discovered that a Python
> Script can refer to SQL columns *by name*, since I had seen no doc about
> it, only in mailing lists archives.
>
> You can build a dictionary of data from a SQL query, like this:
>
>
> # this returns one row only
> rows = query.sql()
>
> if not rows:
> return {}
>
> fRow = {}
> for field in rows[0].names():
> fRow[field] = rows[0][field]
>
> return fRow
You don't really have to copy the items into a new dictionary, just do
return rows[0]
-- Brent
-------------------------------------------------------------------------
"The programmer, like the poet, works only slightly removed from pure
thought-stuff. He builds his castles in the air, from air, creating
by exertion of the imagination. Few media of creation are so
flexible, so easy to polish and rework, so readily capable of
realizing grand conceptual structures."
-- Frederick Brooks, Jr., The Mythical Man Month