How to convert to integer the the result of a ZSLQ method ?? I call a ZSQL method with: l=int(container.last_customer()) 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. I am digging many hours in the Documentation, and doesn't find the answer. I get this error: Zope Error Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: DatabaseResults instance has no attribute '__int__' Troubleshooting Suggestions The URL may be incorrect. The parameters passed to this resource may be incorrect. A resource that this resource relies on may be encountering an error. For more detailed information about the error, please refer to the HTML source for this page. If the error persists please contact the site maintainer. Thank you for your patience. Traceback (innermost last): File E:\Archivos de programa\zwin\lib\python\ZPublisher\Publish.py, line 223, in publish_module File E:\Archivos de programa\zwin\lib\python\ZPublisher\Publish.py, line 187, in publish File E:\Archivos de programa\zwin\lib\python\Zope\__init__.py, line 226, in zpublisher_exception_hook (Object: LockableItem) File E:\Archivos de programa\zwin\lib\python\ZPublisher\Publish.py, line 171, in publish File E:\Archivos de programa\zwin\lib\python\ZPublisher\mapply.py, line 160, in mapply (Object: start) File E:\Archivos de programa\zwin\lib\python\ZPublisher\Publish.py, line 112, in call_object (Object: start) File E:\Archivos de programa\zwin\lib\python\Shared\DC\Scripts\Bindings.py, line 324, in __call__ (Object: start) File E:\Archivos de programa\zwin\lib\python\Shared\DC\Scripts\Bindings.py, line 354, in _bindAndExec (Object: start) File E:\Archivos de programa\zwin\lib\python\Products\PythonScripts\PythonScript.py, line 363, in _exec (Object: start) (Info: ({'script': <PythonScript instance at 065706C0>, 'context': <Folder instance at 0205E010>, 'container': <Folder instance at 0205E010>, 'traverse_subpath': []}, (), {}, None)) File Script (Python), line 8, in start (Object: guarded_getattr) AttributeError: (see above) -- __o _ \<_ (_)/(_) Saludos de Julián EA4ACL -.-
On Friday 02 November 2001 11:21 am, Julián Muñoz Domínguez allegedly wrote:
How to convert to integer the the result of a ZSLQ method ??
I call a ZSQL method with: l=int(container.last_customer())
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.
I am digging many hours in the Documentation, and doesn't find the answer.
I get this error:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: DatabaseResults instance has no attribute '__int__'
It sounds like you are trying to convert the whole row or recordset to an int, which obviously won't work. You need to return just the field by itself like: I=int(container.last_customer().name_of_field) or possibly: I=int(container.last_customer()[0].name_of_field) hth, /---------------------------------------------------\ Casey Duncan, Sr. Web Developer National Legal Aid and Defender Association c.duncan@nlada.org \---------------------------------------------------/
Julián Muñoz Domínguez wrote:
How to convert to integer the the result of a ZSLQ method ??
I call a ZSQL method with: l=int(container.last_customer())
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.
I am digging many hours in the Documentation, and doesn't find the answer.
I get this error:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: DatabaseResults instance has no attribute '__int__'
Julián: A ZSQL Method like last_customer() returns a DatabaseResults object, 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 first row of the result, you can: l=int(container.last_customer()[0][0]) This gets the first field of the first row of your ZSQL Method results, and converts it to an int. I would maybe do it like this (ymmv): t = container.last_customer()[0][0] if t is not None: l = int(t) else: l = 0 -- Jim Washington
=?ISO-8859-1?Q?Juli=E1n_Mu=F1oz_Dom=EDnguez?= writes:
How to convert to integer the the result of a ZSLQ method ??
I call a ZSQL method with: l=int(container.last_customer()) This is (essentially) a *LIST* of *ROWS* representing your query result. You cannot convert it into an integer.
Use: "int(container.last_customer()[0].<fieldname>)" More details: Zope book Dieter
participants (4)
-
Casey Duncan -
Dieter Maurer -
Jim Washington -
Julián Muñoz Domínguez