Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111738 > unrolled thread

Convert from unsigned long long to PyLong

Started byTian JiaLin <himurakenshin54@gmail.com>
First post2016-07-21 23:01 -0700
Last post2016-07-25 03:59 +0900
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Convert from unsigned long long to PyLong Tian JiaLin <himurakenshin54@gmail.com> - 2016-07-21 23:01 -0700
    Re: Convert from unsigned long long to PyLong MRAB <python@mrabarnett.plus.com> - 2016-07-22 15:46 +0100
    Re: Convert from unsigned long long to PyLong INADA Naoki <songofacandy@gmail.com> - 2016-07-25 03:59 +0900

#111738 — Convert from unsigned long long to PyLong

FromTian JiaLin <himurakenshin54@gmail.com>
Date2016-07-21 23:01 -0700
SubjectConvert from unsigned long long to PyLong
Message-ID<45db6d56-90a3-4e4f-958a-65ecb5da5ac6@googlegroups.com>
HI There,

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(...)

connection.autocommit(True)
try:
    cursor = connection.cursor()
    if not cursor.execute(sql, values) > 0:
            return None
    row = cursor.fetchone()
finally:
    connection.close()
return row[0] 


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 https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835,

static PyObject *
_mysql_ConnectionObject_affected_rows(
	_mysql_ConnectionObject *self,
	PyObject *args)
{
	if (!PyArg_ParseTuple(args, "")) return NULL;
	check_connection(self);
	return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection)));
}

And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html.

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:

Python: 2.7.6
MySQL 5.7.11
MySQLdb 1.2.5


Thanks

[toc] | [next] | [standalone]


#111755

FromMRAB <python@mrabarnett.plus.com>
Date2016-07-22 15:46 +0100
Message-ID<mailman.51.1469198790.22221.python-list@python.org>
In reply to#111738
On 2016-07-22 07:01, Tian JiaLin wrote:
> HI There,
>
> 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(...)
>
> connection.autocommit(True)
> try:
>     cursor = connection.cursor()
>     if not cursor.execute(sql, values) > 0:
>             return None
>     row = cursor.fetchone()
> finally:
>     connection.close()
> return row[0]
>
>
> 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 https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835,
>
> static PyObject *
> _mysql_ConnectionObject_affected_rows(
> 	_mysql_ConnectionObject *self,
> 	PyObject *args)
> {
> 	if (!PyArg_ParseTuple(args, "")) return NULL;
> 	check_connection(self);
> 	return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection)));
> }
>
> And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html.
>
> 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:
>
> Python: 2.7.6
> MySQL 5.7.11
> MySQLdb 1.2.5
>
>
The function returns an unsigned value, but it will return -1 (i.e. ~0) 
if there's an error, so check for an error with ~result == 0.

[toc] | [prev] | [next] | [standalone]


#111820

FromINADA Naoki <songofacandy@gmail.com>
Date2016-07-25 03:59 +0900
Message-ID<mailman.95.1469386781.22221.python-list@python.org>
In reply to#111738
Thank you for reporting this issue.

I'll fix it in next release of mysqlclient

(MySQL-python has not been maintained for these years.  Please use mysqlclient.
It supports Python 3.)

On Fri, Jul 22, 2016 at 3:01 PM, Tian JiaLin <himurakenshin54@gmail.com> wrote:
> HI There,
>
> 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(...)
>
> connection.autocommit(True)
> try:
>     cursor = connection.cursor()
>     if not cursor.execute(sql, values) > 0:
>             return None
>     row = cursor.fetchone()
> finally:
>     connection.close()
> return row[0]
>
>
> 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 https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c#L835,
>
> static PyObject *
> _mysql_ConnectionObject_affected_rows(
>         _mysql_ConnectionObject *self,
>         PyObject *args)
> {
>         if (!PyArg_ParseTuple(args, "")) return NULL;
>         check_connection(self);
>         return PyLong_FromUnsignedLongLong(mysql_affected_rows(&(self->connection)));
> }
>
> And here is the official doc for mysql_affected_rows http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html.
>
> 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:
>
> Python: 2.7.6
> MySQL 5.7.11
> MySQLdb 1.2.5
>
>
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
INADA Naoki  <songofacandy@gmail.com>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web