[Python-Dev] Convert from unsigned long long to PyLong
himurakenshin54 at gmail.com
Fri Jul 22 02:10:22 EDT 2016
Maybe I should not post this in the dev group, but I think it has some
relationship on the Python core.
I'm using MySQLdb as the MySQL client. Recently I got a weird problem of
this library. After looking into it, I suspect the problem may related to
the conversion from unsigned long to PyLongObject.
Here is the detail, If you are familiar with MySQLdb, the following snippet
is a way to query the data from MySQL:
connection = MySQLdb.connect(...)
cursor = connection.cursor()
if not cursor.execute(sql, values) > 0:
row = cursor.fetchone()
Sometimes the return value of execute method would be 18446744073709552000
even there is no matched data available. I checked the source code of the
library, the underlying implementation is
static PyObject *
if (!PyArg_ParseTuple(args, "")) return NULL;
And here is the official doc for mysql_affected_rows
Let me give a superficial understanding, please correct me if I were wrong.
In a 64-bit system, the mysql_affected_rows is supposed to return a number
of unsigned long, which means the range should be 0 ~ 2^64
(18446744073709551616), How could it be possible the function
PyLong_FromUnsignedLongLong return a converted value larger than 2^64,
that's what I don't understand.
Does anyone have some ideas of it?
The versions of the components I used:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev