Re: Questions about mysql_affected_rows

From: Luuk <luuk_at_invalid.lan>
Date: Mon, 25 Jul 2016 22:39:21 +0200
Message-ID: <579678f6$0$903$e4fe514c_at_news.xs4all.nl>


On 23-07-16 20:10, Tian JiaLin wrote:
> 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!
>

Question1:
Whats was the query that was sent ?

Question2:
Did you read the docs fter the word 'OR' here: http://dev.mysql.com/doc/refman/5.7/en/mysql-affected-rows.html Return values:.....
-1 indicates that the query returned an error *or* that, for a SEELCT query, mysql_affected_rows() was called prior to calling ysql_store_result() Received on Mon Jul 25 2016 - 22:39:21 CEST

Original text of this message