RES: [Zope] formatting problem...

Daniel Corrêa de Azevedo DANIELCA@senado.gov.br
Thu, 15 Mar 2001 16:56:03 -0300


	Deer paz, my group  figured out that there is a SQL function FORMAT
that can be used to get rid of the L sufix that comes in the query result.

	    e.g:
	                 SELECT  FORMAT(int_key, 0) FROM data

	That code should result to you a query without the L sufix.

	See you,
	Daniel.

	
****************************************************************************
********************************************************


> 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={
>         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] = int
> 	DB.conv[FIELD_TYPE.LONGLONG] = 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êa de Azevedo
> > Cc: 'zope@zope.org'
> > Subject: Re: [Zope] formatting problem...
> > 
> > 
> > Hi Daniel,
> > 
> > I have had similar problems with MySQL... What I use to get 
> > around it is to send
> > it through the integer module. You'll find this also handy 
> > for converting
> > strings that only contain numbers and dates to floats and 
> > yadda yadda....:
> > 
> > <dtml-var "_.int(varname)">
> > 
> > Anyone got a better one? Or rather, explain why MySQL 
> > translates everthing as
> > long integers? Is this ALWAYS the case when defining a dbase 
> > field as INT4?
> > Cheers,
> > Paz
> > 
> > Daniel Corrêa de Azevedo wrote:
> > 
> > >     Hello you all.
> > >     I´m having problem in using FMT atribute of the 
> > DTML-VAR tag in dtml
> > > methods. The situation is that when I receive some integer 
> > data from a MYSQL
> > > database, I get it with a L sufix. That makes it necessary 
> > to format the
> > > data with <dtml-var key fmt="%d">. Now, the problem is 
> > that, sometimes, I
> > > need to keep on passing the data over to a few dtml 
> > methods, and when ever I
> > > need to reformat the data, I get an erro message: " Ilegal 
> > argument type for
> > > built-in operation.".
> > >    I need to reformat because the data in the other 
> > dtml-methods in the
> > > sequece may be being received from the MYSQL database.
> > >    How coud I reformat the data using <dtml-var key 
> > FMT="????">, even if it
> > > has already been formated by <dtml-var key fmt="%d">?
> > >
> > >    Thanks,
> > >                                                         
> > 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 )
> > 
> > 
> > _______________________________________________
> > 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 )
> >