Discussion:
[Modeling-users] MySQL double
Ralf Sigmund
2004-02-03 09:29:04 UTC
Permalink
Greetings!

I have recently started to use modeling for my bioinformatics work.
I like it a lot but now i ran into a small problem.
I often need to store small numbers like 1.24e-127
The MySQL datataype double stores theese correctly while float reduces
them to 0.0 which is a catastrophe for me.
So I tried to specify double as external datatayp, but the mdl-validate
fails telling me that double is not supported.
Is it possible to expand the mysql adapter to support double?
thanks
Ralf
Sebastien Bigaret
2004-02-03 11:39:12 UTC
Permalink
Hi,
Post by Ralf Sigmund
Greetings!
I have recently started to use modeling for my bioinformatics work.
I like it a lot but now i ran into a small problem.
I often need to store small numbers like 1.24e-127
The MySQL datataype double stores theese correctly while float reduces them to
0.0 which is a catastrophe for me.
So I tried to specify double as external datatayp, but the mdl-validate fails
telling me that double is not supported.
Is it possible to expand the mysql adapter to support double?
Absolutely :) Apply the attached patch and you should be able to use
MySQL's DOUBLE. Use precision=0, scale=0 for the default DOUBLE, or
precision=M, scale=D for DOUBLE(M,D). If you can report that this
works as expected, this will be in the next release.

Hope this helps,

-- Sébastien.



Index: DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py,v
retrieving revision 1.8
diff -u -r1.8 MySQLSQLExpression.py
--- DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py 15 Dec 2003 15:05:00 -0000 1.8
+++ DatabaseAdaptors/MySQLAdaptorLayer/MySQLSQLExpression.py 3 Feb 2004 13:31:02 -0000
@@ -34,7 +34,8 @@
__version__='$Revision: 1.8 $'[11:-2]

from Modeling.DatabaseAdaptors.MySQLAdaptorLayer.mysql_utils import *
-from Modeling.SQLExpression import SQLExpression, DateType, CharacterType
+from Modeling.SQLExpression import SQLExpression
+from Modeling.SQLExpression import DateType, CharacterType, NumericType
from Modeling.logging import trace, db_trace
import string

@@ -117,7 +118,8 @@
values=SQLExpression.valueTypeForExternalTypeMapping.im_func(self)
del values['timestamp']
values.update({ 'datetime': DateType,
- 'text': CharacterType })
+ 'text': CharacterType,
+ 'double': NumericType })
return values

def prepareSelectCountExpressionWithAttributes(self,
Mario Ruggier
2004-02-03 13:18:13 UTC
Permalink
Hi folks,
Post by Sebastien Bigaret
Hi,
Post by Ralf Sigmund
Greetings!
I have recently started to use modeling for my bioinformatics work.
I like it a lot but now i ran into a small problem.
I often need to store small numbers like 1.24e-127
The MySQL datataype double stores theese correctly while float
reduces them to
0.0 which is a catastrophe for me.
So I tried to specify double as external datatayp, but the
mdl-validate fails
telling me that double is not supported.
Is it possible to expand the mysql adapter to support double?
Absolutely :) Apply the attached patch and you should be able to use
MySQL's DOUBLE. Use precision=0, scale=0 for the default DOUBLE, or
precision=M, scale=D for DOUBLE(M,D). If you can report that this
works as expected, this will be in the next release.
wouldn't this be an appropriate case for using FixedPoint? As per:
<http://modeling.sourceforge.net/UserGuide/attribute-custom-type-
example.html>
Or are there other reasons, maybe performance?, for not doing so?

Cheers, mario
Post by Sebastien Bigaret
Hope this helps,
-- Sébastien.
Sebastien Bigaret
2004-02-04 03:45:11 UTC
Permalink
Mario Ruggier <***@ruggier.org> wrote:
[speaking of DOUBLE vs FLOAT in mysql, for floats like 1.24e-127]
Post by Mario Ruggier
<http://modeling.sourceforge.net/UserGuide/attribute-custom-type-
example.html>
Or are there other reasons, maybe performance?, for not doing so?
Well, probably not in this case, or you'll need a precision of 129 to
represent 1.24e-127 correctly with FixedPoint ;) FixedPoint is really
fixed, relative to zero.

The problem here was just the range of valid values on mysql side: the
minimum acceptable value for a FLOAT is +/-1.1E-38, that's why 1e-127
was rounded to 0; but with DOUBLE the min. value is +/-1.8-308.
(http://www.mysql.com/doc/en/Column_types.html)

BTW and in relation to the topic, PEP 327: Decimal Data Type was
announced a few days ago, see at:
http://groups.google.com/groups?selm=mailman.1036.1075467073.12720.python-list%40python.org
(seen on daily python today)


-- Sébastien.

Loading...