Questions about mysql_affected_rows
Posted by: rurouni kenshin
Date: July 24, 2016 10:05AM

Hi There,

I'm using MySQLdb as the client in my Python code. The underlying implementation of this library is based on the native mysql library. The code snippet that I concerned like this:

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)));
}

Sometimes, mysql_affected_rows returns -1, according to the MySQL official documentation, http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html, -1 indicates that the query returned an error, but actually the query is successfully executed. The result set also have the correct data.

I also tried to get the error info from the connection via MySQLdb, the underlying code looks like this,

static PyObject *
_mysql_ConnectionObject_error(
_mysql_ConnectionObject *self,
PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) return NULL;
check_connection(self);
#ifdef IS_PY3K
return PyUnicode_FromString(mysql_error(&(self->connection)));
#else
return PyString_FromString(mysql_error(&(self->connection)));
#endif
}

but there is not error returned.



My question is:

1. Is this a reasonable behavior that affected_rows returns -1, but the query is executed well?

2. Is there any other ways to get the "error" related to the -1 from mysql_affected_rows?

Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
Questions about mysql_affected_rows
1648
July 24, 2016 10:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.