py3k: out of range error for valid bigint value

Bug #1158428 reported by Matthias Liebig on 2013-03-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oursql
Undecided
Unassigned

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 post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers