[Zope] Select Count problem
Jim Penny
jpenny@universal-fasteners.com
Wed, 24 Jul 2002 19:53:05 -0400
On Wed, Jul 24, 2002 at 05:44:03PM -0600, Jose Gerardo Amaya Giron wrote:
> Hello all.
>
> In a SQL Method I'm executing a select count query this way
>
> select count(*) as count from table where attrib=something
>
> now I want to get the results in a python script I try to get it with no
> success with the following
>
> SQLdata_datos_count = container.dic_datos_count(pdf_id=1)
>
> SQLdata_datos_count[0].count
>
> but I get a
>
> Error Type: TypeError
> Error Value: argument 2 to map() must be a sequence object
>
> what is the way to get the count data correctly
>
> thanks in advance
>
> Gerardo
>
in a python script, you are returned a "results" structure.
SpinWing has a HOWTO on this, and there is an older one by me (jpenny).
Short answer.
res=container.dic_datos_count(pdf_id=1)
Then len(res) is the number of rows returned by the query.
res[0][0] is the first item of the first row, etc.
res.names() is a list of names (column headers) of res.
This fragment is ofen useful.
res=container.dic_datos_count(pdf_id=1)
n2i={}
names=res.names()
for i in range(len(names)):
n2i[names[i]]=i
Then, you can select a row element using:
res[row][n2i['name']], for example,
res[0][n2i['count']
Of course, in your case, res[0][0] is much easier.
Jim Penny
>
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>