[Zope] Howto convert ZSQL results
Jim Washington
jwashin@vt.edu
Fri, 02 Nov 2001 12:06:50 -0500
Juli=E1n Mu=F1oz Dom=EDnguez wrote:
>=20
> How to convert to integer the the result of a ZSLQ method ??
>=20
>=20
>=20
>=20
> I call a ZSQL method with:
> l=3Dint(container.last_customer())
>=20
>=20
> The field I query is has the type "VARCHAR(10) with Null"
> I am doing this query through ZODBC DA, to an Access .mdb file.
>=20
> I am digging many hours in the Documentation, and doesn't find the answ=
er.
>=20
>=20
> I get this error:
>=20
>=20
> Zope Error
>=20
> Zope has encountered an error while publishing this resour=
ce.
>=20
> Error Type: AttributeError
> Error Value: DatabaseResults instance has no attribute
> '__int__'
>=20
>
Juli=E1n:
A ZSQL Method like last_customer() returns a DatabaseResults object,=20
which has a list of records from your database.
If you are really sure that it is an integer in the first field of the=20
first row of the result, you can:
l=3Dint(container.last_customer()[0][0])
This gets the first field of the first row of your ZSQL Method results,=20
and converts it to an int.
I would maybe do it like this (ymmv):
t =3D container.last_customer()[0][0]
if t is not None:
l =3D int(t)
else:
l =3D 0
-- Jim Washington