[Tutor] MySQLdb: dropping zeroes!

Magnus Lyckå magnus at thinkware.se
Tue Apr 13 20:13:28 EDT 2004


At 07:56 2004-04-07 -0800, Tim Johnson wrote:
>   To quote the mysql manual:
>
>    "The DECIMAL type is considered a numeric type (as is its synonym,
>    NUMERIC), but such values are stored as strings."
>
>    So I thought there might be a way to override the
>    MySQLdb type conversion and get them back as strings.

The problem (which I hope will be fixed in a not too far future)
is that Python lacks a standard decimal type/class.

ADODBAPI does it the other way around, and returns DECIMAL
as strings, and that's not without problems either. For
instance, with e.g. Swedish settings in Windows, 1/2 will
be returned as '0,5', not '0.5', and float('0,5') won't make
Python happy.

Anyway, I guess you could replace "SELECT X FROM Y" with
"SELECT CAST(X AS CHAR(10)) AS X FROM Y" or something like
that.


--
Magnus Lycka (It's really Lyckå), magnus at thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language 




More information about the Tutor mailing list