Questions about mysql_affected_rows

From: Tian JiaLin <himurakenshin54_at_gmail.com>
Date: Sat, 23 Jul 2016 11:10:41 -0700 (PDT)
Message-ID: <80f8c3d9-bbb3-46bd-adce-279a9ef5b1ad_at_googlegroups.com>



[Quoted] 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! Received on Sat Jul 23 2016 - 20:10:41 CEST

Original text of this message