Menu

problem with unsigned bigints

Help
robinsmb
2004-10-11
2012-09-19
  • robinsmb

    robinsmb - 2004-10-11

    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 ?

     
    • Andy Dustman

      Andy Dustman - 2004-10-12

      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.

       
    • robinsmb

      robinsmb - 2004-10-16

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.