py3k: out of range error for valid bigint value
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oursql |
New
|
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 (?);", [14624773971177
...results in:
Traceback (most recent call last):
File "./test-oursql.py", line 8, in <module>
cur.
File "cursor.pyx", line 122, in oursql.
File "statement.pyx", line 405, in oursql.
File "util.pyx", line 105, in oursql.
oursql.
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_
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)