← Back to team overview

agesys-dev team mailing list archive

[Bug 1158428] [NEW] py3k: out of range error for valid bigint value

 

Public bug reported:

oursql has trouble with large integer values because the "long" type was
removed in Python 3.

CREATE TABLE `test` (
	`id` bigint(21) unsigned NOT NULL
) ENGINE=innodb DEFAULT CHARSET=utf8;

Inserting a value...

conn = oursql.connect(...)
cur = conn.cursor()
cur.execute("INSERT INTO `test` VALUES (?);", [14624773971177758359])

...results in:

Traceback (most recent call last):
  File "./test-oursql.py", line 8, in <module>
    cur.execute("INSERT INTO `test` VALUES (?);", [14624773971177758359])
  File "cursor.pyx", line 122, in oursql.Cursor.execute (oursqlx/oursql.c:17052)
  File "statement.pyx", line 405, in oursql._Statement.execute (oursqlx/oursql.c:11466)
  File "util.pyx", line 105, in oursql._do_warnings_query (oursqlx/oursql.c:4181)
oursql.CollatedWarningsError: (None, 'query caused warnings', [(<class 'oursql.Warning'>, ("Out of range value for column 'id' at row 1", 1264))])

Manually Inserting it works fine, because the value is smaller than the
maximum for bigint unsigned.

In statement.pyx, class _Statement, method execute, there's the handling
of the parameters according to type (lines 330-345 in 0.9.3) .
PyInt_Check is used for int and PyLong_Check for long. In py3k, the API
provides PyLong_Check only and PyInt_Check is mapped to it. Hence, the
handling for int applies here which does not handle unsigned values of
MYSQL_TYPE_LONGLONG.

In conclusion, every occurrence of PyInt_Check or  PyLong_Check should
be checked again. I think, Bug #686232 might also be caused by this.


Tested on Gentoo Linux ~amd64 and Ubuntu 12.04.2 LTS x86_64
mysql client/server: 5.5.29 for Linux (x86_64)
Python 3.2.3 [GCC 4.6.3]
oursql-0.9.3 (py3k)

** Affects: oursql
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Agesys
Team, which is subscribed to oursql.
https://bugs.launchpad.net/bugs/1158428

Title:
  py3k: out of range error for valid bigint value

Status in oursql:
  New

Bug description:
  oursql has trouble with large integer values because the "long" type
  was removed in Python 3.

  CREATE TABLE `test` (
  	`id` bigint(21) unsigned NOT NULL
  ) ENGINE=innodb DEFAULT CHARSET=utf8;

  Inserting a value...

  conn = oursql.connect(...)
  cur = conn.cursor()
  cur.execute("INSERT INTO `test` VALUES (?);", [14624773971177758359])

  ...results in:

  Traceback (most recent call last):
    File "./test-oursql.py", line 8, in <module>
      cur.execute("INSERT INTO `test` VALUES (?);", [14624773971177758359])
    File "cursor.pyx", line 122, in oursql.Cursor.execute (oursqlx/oursql.c:17052)
    File "statement.pyx", line 405, in oursql._Statement.execute (oursqlx/oursql.c:11466)
    File "util.pyx", line 105, in oursql._do_warnings_query (oursqlx/oursql.c:4181)
  oursql.CollatedWarningsError: (None, 'query caused warnings', [(<class 'oursql.Warning'>, ("Out of range value for column 'id' at row 1", 1264))])

  Manually Inserting it works fine, because the value is smaller than
  the maximum for bigint unsigned.

  In statement.pyx, class _Statement, method execute, there's the
  handling of the parameters according to type (lines 330-345 in 0.9.3)
  . PyInt_Check is used for int and PyLong_Check for long. In py3k, the
  API provides PyLong_Check only and PyInt_Check is mapped to it. Hence,
  the handling for int applies here which does not handle unsigned
  values of MYSQL_TYPE_LONGLONG.

  In conclusion, every occurrence of PyInt_Check or  PyLong_Check should
  be checked again. I think, Bug #686232 might also be caused by this.

  
  Tested on Gentoo Linux ~amd64 and Ubuntu 12.04.2 LTS x86_64
  mysql client/server: 5.5.29 for Linux (x86_64)
  Python 3.2.3 [GCC 4.6.3]
  oursql-0.9.3 (py3k)

To manage notifications about this bug go to:
https://bugs.launchpad.net/oursql/+bug/1158428/+subscriptions


Follow ups

References