Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs
Browse files Browse the repository at this point in the history
methane committed May 16, 2023

Unverified

No user is associated with the committer email.
1 parent 5533274 commit 38e4442
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/MySQLdb/_mysql.c
Original file line number Diff line number Diff line change
@@ -2114,18 +2114,25 @@ _mysql_ConnectionObject_discard_result(
MYSQL *conn = &(self->connection);

Py_BEGIN_ALLOW_THREADS;

MYSQL_RES *res = mysql_use_result(conn);
if (res == NULL) {
Py_BLOCK_THREADS;
return _mysql_Exception(self);
if (mysql_errno(conn) != 0) {
// fprintf(stderr, "mysql_use_result failed: %s\n", mysql_error(conn));
return _mysql_Exception(self);
}
Py_RETURN_NONE;
}

MYSQL_ROW row;
while (NULL != (row = mysql_fetch_row(res))) {
// do nothing.
}
mysql_free_result(res);
Py_END_ALLOW_THREADS;
if (mysql_errno(conn)) {
// fprintf(stderr, "mysql_free_result failed: %s\n", mysql_error(conn));
return _mysql_Exception(self);
}
Py_RETURN_NONE;
2 changes: 1 addition & 1 deletion src/MySQLdb/cursors.py
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ def _discard(self):
con = self.connection
if con is None:
return
while con.next_result():
while con.next_result() == 0: # -1 means no more data.
con.discard_result()

def close(self):

0 comments on commit 38e4442

Please sign in to comment.