Skip to content

Commit 76c3be0

Browse files
committed
Add Result.discard()
1 parent 60bb6ee commit 76c3be0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/MySQLdb/_mysql.c

+26
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,26 @@ _mysql_ResultObject_fetch_row(
14841484
return NULL;
14851485
}
14861486

1487+
static const char _mysql_ResultObject_discard__doc__[] =
1488+
"discard() -- Discard remaining rows in the resultset.";
1489+
1490+
static PyObject *
1491+
_mysql_ResultObject_discard(
1492+
_mysql_ResultObject *self,
1493+
PyObject *noargs)
1494+
{
1495+
check_result_connection(self);
1496+
1497+
MYSQL_ROW row;
1498+
while (NULL != (row = mysql_fetch_row(self->result))) {
1499+
// do nothing
1500+
}
1501+
if (mysql_errno(self->conn)) {
1502+
return _mysql_Exception(self->conn);
1503+
}
1504+
Py_RETURN_NONE;
1505+
}
1506+
14871507
static char _mysql_ConnectionObject_change_user__doc__[] =
14881508
"Changes the user and causes the database specified by db to\n\
14891509
become the default (current) database on the connection\n\
@@ -2473,6 +2493,12 @@ static PyMethodDef _mysql_ResultObject_methods[] = {
24732493
METH_VARARGS | METH_KEYWORDS,
24742494
_mysql_ResultObject_fetch_row__doc__
24752495
},
2496+
{
2497+
"discard",
2498+
(PyCFunction)_mysql_ResultObject_discard,
2499+
METH_NOARGS,
2500+
_mysql_ResultObject_discard__doc__
2501+
},
24762502
{
24772503
"field_flags",
24782504
(PyCFunction)_mysql_ResultObject_field_flags,

0 commit comments

Comments
 (0)