I'm using mysqldb 1.0.0. I'm getting a -ve long value when I fetch an unsigned big int whose value causes the sign bit to be set. Eg when fetching 16177514723655138844 I get -2269229350054412772. And of course -2269229350054412772 + (2**64) is the value that's in the db 161...etc., why is this happening ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Try your query in the MySQL command line client and see if you are really getting back the value you think you are. The C API returns all values as strings, and what all of the above is supposed to verify is that this string is simply passed through the Python long() function.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Python 2.3.3 (#1, May 7 2004, 10:31:40) [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
client and server MySQL are v 4.0.18. I'm using the shared libraries.
Bug was in my query. I had tried a simple select in mysqlcc 0.9.4 beta to confirm bigints came back as expected before posting here. I hadn't tried the full query. woops. I think it's because it's a multi statement query that uses server side variables to pass data accross querys. I'll go pour over the mysql docs some more. Thanks very much for your help !
My output for the tests you suggested matches yours:
>>> from MySQLdb.converters import conversions
>>> from MySQLdb.constants import FIELD_TYPE
>>> print conversions[FIELD_TYPE.LONG]
<type 'long'>
>>> print conversions[FIELD_TYPE.LONGLONG]
<type 'long'>
>>> print long("16177514723655138844")
16177514723655138844
Cheers,
Robin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using mysqldb 1.0.0. I'm getting a -ve long value when I fetch an unsigned big int whose value causes the sign bit to be set. Eg when fetching 16177514723655138844 I get -2269229350054412772. And of course -2269229350054412772 + (2**64) is the value that's in the db 161...etc., why is this happening ?
You don't say what Python and MySQL versions you are using.
Try this:
Python 2.3.4 (#1, Jul 30 2004, 09:49:24)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from MySQLdb.converters import conversions
>>> from MySQLdb.constants import FIELD_TYPE
>>> print conversions[FIELD_TYPE.LONG]
<type 'long'>
>>> print conversions[FIELD_TYPE.LONGLONG]
<type 'long'>
MySQL's BIGINT is LONGLONG the C API. You should be getting the output above.
>>> print long("16177514723655138844")
16177514723655138844
Try your query in the MySQL command line client and see if you are really getting back the value you think you are. The C API returns all values as strings, and what all of the above is supposed to verify is that this string is simply passed through the Python long() function.
Hi,
Applocgies in the delay on responding.
Python 2.3.3 (#1, May 7 2004, 10:31:40)
[GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
client and server MySQL are v 4.0.18. I'm using the shared libraries.
Bug was in my query. I had tried a simple select in mysqlcc 0.9.4 beta to confirm bigints came back as expected before posting here. I hadn't tried the full query. woops. I think it's because it's a multi statement query that uses server side variables to pass data accross querys. I'll go pour over the mysql docs some more. Thanks very much for your help !
My output for the tests you suggested matches yours:
>>> from MySQLdb.converters import conversions
>>> from MySQLdb.constants import FIELD_TYPE
>>> print conversions[FIELD_TYPE.LONG]
<type 'long'>
>>> print conversions[FIELD_TYPE.LONGLONG]
<type 'long'>
>>> print long("16177514723655138844")
16177514723655138844
Cheers,
Robin