[Zope-DB] Re: Floating point errors

M.-A. Lemburg mal at egenix.com
Tue Feb 5 05:28:54 EST 2008


On 2008-02-05 08:05, siribu wrote:
> Hi,
> 
> well, it worked testing in Python using the eGenix API even without setting the 
> NLS_NUMERIC_CHARACTERS explicitly. Thus, I assume that the ODBC interface toward 
> Python should be working automatically using default settings.
> 
> - thus I am guessing that it might be Zope that does not find the right 
> environment variable. Tell me if I'm wrong.
> 
> Also, it is worth noting that I have converted to a Norwegian character set, 
> whereas in http://www.osdir.com/ml/web.zope.database/2003-01/msg00036.html they 
> are converting to a German character set. Might have something to do with 
> reproducing the error.

The only area where the locale for numbers could be important is
when converting floating point numbers to floats, e.g. in Germany
you write 3,141592655 (using "," as decimal point). In most English
speaking countries this is written as 3.141592655 (using "." as
decimal point).

The default ANSI C setting uses the dot as decimal point.

Now if some routine in the stack relies on this string to
float conversion and uses the wrong decimal point setting,
you end up with a wrong floating point value.

In any case: Thanks for sharing your findings.

Regards,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 05 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611



> -su
> 
> 
> 
> 
> 
> *On Mon Feb 4 11:34 , "M.-A. Lemburg" sent:
> 
> *
> 
>     On 2008-02-04 08:19, siribu wrote:
>     >  Hi,
>     >
>     >  I found the a solution to the problem, it cannot be done just by " Leave
>     scale 0
>     >  floats untouched ?" which I tried, but also the Oracle parameter
>     >  NLS_NUMERIC_CHARACTERS needed to be set explicitly.
>     >  See http://www.osdir.com/ml/web.zope.database/2003-01/msg00036.html.
>     <http://epost.start.no/mail/parse.pl?redirect=http://www.osdir.com/ml/web.zope.database/2003-01/msg00036.html.>
>     That solved
>     >  things for me.
>     >
>     >  Anyway, thanks Marc-Andre :-)
> 
>     You're welcome.
> 
>     Could you explain why you had to set the NLS_NUMERIC_CHARACTERS variable ?
> 
>     Is this needed for the ODBC driver to convert numbers to and from
>     strings correctly ?
> 
> 
>     >  *On Sun Feb 3 12:37 , "M.-A. Lemburg" sent:
>     >
>     >  *
>     >
>     >  On 2008-01-23 14:35, siribu wrote:
>     >  > Hi,
>     >  >
>     >  >
>     >  >
>     >  > I have got a problem:
>     >  >
>     >  >
>     >  >
>     >  > accessing an Oracle 10g database, whenever I ask for floats from a Zope
>     Z SQL
>     >  > method, they are automatically converted to integers, simply dropping the
>     >  > decimal numbers.
>     >  >
>     >  >
>     >  >
>     >  > I am using Zope 2.10.4-final with Python 2.4.4 running on a Linux2 OS.
>     >  > Furthermore, I am using UnixODBC with Easysoftâ€^(TM)s ODBC-Oracle driver
>     >  together
>     >  > with eGenix *mxODBC Zope DA*.
>     >
>     >  There's a connection option " Leave scale 0 floats untouched ?" to switch
>     >  this off.
>     >
>     >  The truncation to integers is done because some database drivers always
>     >  return numbers as floats - even integers. Zope would then display these
>     >  as floats (without additional formatting), which may not look right to
>     >  the user.
>     >
>     >  > Running iSQL on the server or even utilizing the mxODBC Zope DA driver
>     >  directly
>     >  > in Python works well without problems.
>     >  >
>     >  >
>     >  >
>     >  > The error logs for the ODBC contained no sign or errors. Neither did I get
>     >  any
>     >  > response when I ran Event Log Manager in Zope. I could not find anything
>     >  in syslog.
>     >  >
>     >  >
>     >  >
>     >  > Any clues on how to solve this?
>     >
>     >  See above: just switch on the option in the connection properties.
>     >
>     >  -
>     >  Marc-Andre Lemburg
>     >  eGenix.com
>     >
>     >  Professional Python Services directly from the Source (#1, Feb 03 2008)
>     >  > >> Python/Zope Consulting and Support ... http://www.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://www.egenix.com/>
>     >  <http://epost.start.no/mail/parse.pl\?redirect=http://www.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://epost.start.no/mail/parse.pl%3Fredirect%3Dhttp%253A%252F%252Fwww.egenix.com%252F>>
>     >  > >> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://zope.egenix.com/>
>     >  <http://epost.start.no/mail/parse.pl\?redirect=http://zope.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://epost.start.no/mail/parse.pl%3Fredirect%3Dhttp%253A%252F%252Fzope.egenix.com%252F>>
>     >  > >> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://python.egenix.com/>
>     >  <http://epost.start.no/mail/parse.pl\?redirect=http://python.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://epost.start.no/mail/parse.pl%3Fredirect%3Dhttp%253A%252F%252Fpython.egenix.com%252F>>
>     >  ________________________________________________________________________
>     >
>     >  :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
>     >
>     >
>     >  eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
>     >  D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>     >  Registered at Amtsgericht Duesseldorf: HRB 46611
>     >
>     >
>     >  -------------------------------------------------------------------------
>     >  Få din egen, gratis e-postadresse på Start.no <http://www.start.no/
>     <http://epost.start.no/mail/parse.pl?redirect=http://www.start.no/>>
>     >
> 
>     -- 
>     Marc-Andre Lemburg
>     eGenix.com
> 
>     Professional Python Services directly from the Source (#1, Feb 04 2008)
>     > >> Python/Zope Consulting and Support ... http://www.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://www.egenix.com/>
>     > >> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://zope.egenix.com/>
>     > >> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
>     <http://epost.start.no/mail/parse.pl?redirect=http://python.egenix.com/>
>     ________________________________________________________________________
> 
>     :::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::
> 
> 
>     eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>     Registered at Amtsgericht Duesseldorf: HRB 46611
> 
> 
> ------------------------------------------------------------------------- Få din 
> egen, gratis e-postadresse på Start.no



More information about the Zope-DB mailing list