[Zope] formatting problem...

Randall F. Kern randy@spoke.net
Thu, 15 Mar 2001 08:25:57 -0800


ZMySQLDA always converts columns of MySQL type int(11) (the normal
'integer' field type) to Python Long values.  The reason this is done is
that the MySQL integer data type can hold values larger than the normal
Python integer.

Python 1.5.2 and earlier had a bug that caused a Python long to print
out with the L suffix; this bug was fixed in 2.0 (and maybe 1.6,
although I haven't tried it).

The conversion table in ZMySQLDA can be found in
lib/python/Products/ZMySQLDA/db.py, in the DB class:

    conv=3D{
        FIELD_TYPE.TIMESTAMP: _mysql_timestamp_converter,
        FIELD_TYPE.TINY: int,
        FIELD_TYPE.SHORT: int,
        FIELD_TYPE.LONG: long,
        FIELD_TYPE.FLOAT: float,
        FIELD_TYPE.DOUBLE: float,
        FIELD_TYPE.LONGLONG: long,
        FIELD_TYPE.INT24: int,
        FIELD_TYPE.YEAR: int,
        FIELD_TYPE.DATETIME: DateTime,
        FIELD_TYPE.DATE: DateTime,
        FIELD_TYPE.TIME: DateTime
        }
(from ZMySQLDA-2.0.4)


If these L's are causing you trouble, you can edit this code to show int
in place of long for the FIELD_TYPE.LONG and FIELD_TYPE.LONGLONG.

Something like this external method might also work, if you call it
before making any SQL queries:

def patch_ZMySQLDA_for_ints(self):
	from Products.ZMySQLDA.db import DB
	from _mysql import FIELD_TYPE
	DB.conv[FIELD_TYPE.LONG] =3D int
	DB.conv[FIELD_TYPE.LONGLONG] =3D int

Note that this method would have to be called at every time your server
was started, or for safety's sake before each query was run.

-Randy

> -----Original Message-----
> From: Paul Zwarts [mailto:paul.zwarts@oratrix.com]
> Sent: Thursday, March 15, 2001 8:12 AM
> To: Daniel Corr=EAa de Azevedo
> Cc: 'zope@zope.org'
> Subject: Re: [Zope] formatting problem...
>=20
>=20
> Hi Daniel,
>=20
> I have had similar problems with MySQL... What I use to get=20
> around it is to send
> it through the integer module. You'll find this also handy=20
> for converting
> strings that only contain numbers and dates to floats and=20
> yadda yadda....:
>=20
> <dtml-var "_.int(varname)">
>=20
> Anyone got a better one? Or rather, explain why MySQL=20
> translates everthing as
> long integers? Is this ALWAYS the case when defining a dbase=20
> field as INT4?
> Cheers,
> Paz
>=20
> Daniel Corr=EAa de Azevedo wrote:
>=20
> >     Hello you all.
> >     I=B4m having problem in using FMT atribute of the=20
> DTML-VAR tag in dtml
> > methods. The situation is that when I receive some integer=20
> data from a MYSQL
> > database, I get it with a L sufix. That makes it necessary=20
> to format the
> > data with <dtml-var key fmt=3D"%d">. Now, the problem is=20
> that, sometimes, I
> > need to keep on passing the data over to a few dtml=20
> methods, and when ever I
> > need to reformat the data, I get an erro message: " Ilegal=20
> argument type for
> > built-in operation.".
> >    I need to reformat because the data in the other=20
> dtml-methods in the
> > sequece may be being received from the MYSQL database.
> >    How coud I reformat the data using <dtml-var key=20
> FMT=3D"????">, even if it
> > has already been formated by <dtml-var key fmt=3D"%d">?
> >
> >    Thanks,
> >                                                        =20
> Daniel C. Azevedo
> >
> > _______________________________________________
> > 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 )
>=20
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>=20