@@ -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+
14871507static char _mysql_ConnectionObject_change_user__doc__ [] =
14881508"Changes the user and causes the database specified by db to\n\
14891509become the default (current) database on the connection\n\
@@ -2081,6 +2101,43 @@ _mysql_ConnectionObject_use_result(
20812101 return result ;
20822102}
20832103
2104+ static const char _mysql_ConnectionObject_discard_result__doc__ [] =
2105+ "Discard current result set.\n\n"
2106+ "This function can be called instead of use_result() or store_result(). Non-standard." ;
2107+
2108+ static PyObject *
2109+ _mysql_ConnectionObject_discard_result (
2110+ _mysql_ConnectionObject * self ,
2111+ PyObject * noargs )
2112+ {
2113+ check_connection (self );
2114+ MYSQL * conn = & (self -> connection );
2115+
2116+ Py_BEGIN_ALLOW_THREADS ;
2117+
2118+ MYSQL_RES * res = mysql_use_result (conn );
2119+ if (res == NULL ) {
2120+ Py_BLOCK_THREADS ;
2121+ if (mysql_errno (conn ) != 0 ) {
2122+ // fprintf(stderr, "mysql_use_result failed: %s\n", mysql_error(conn));
2123+ return _mysql_Exception (self );
2124+ }
2125+ Py_RETURN_NONE ;
2126+ }
2127+
2128+ MYSQL_ROW row ;
2129+ while (NULL != (row = mysql_fetch_row (res ))) {
2130+ // do nothing.
2131+ }
2132+ mysql_free_result (res );
2133+ Py_END_ALLOW_THREADS ;
2134+ if (mysql_errno (conn )) {
2135+ // fprintf(stderr, "mysql_free_result failed: %s\n", mysql_error(conn));
2136+ return _mysql_Exception (self );
2137+ }
2138+ Py_RETURN_NONE ;
2139+ }
2140+
20842141static void
20852142_mysql_ConnectionObject_dealloc (
20862143 _mysql_ConnectionObject * self )
@@ -2376,6 +2433,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
23762433 METH_NOARGS ,
23772434 _mysql_ConnectionObject_use_result__doc__
23782435 },
2436+ {
2437+ "discard_result" ,
2438+ (PyCFunction )_mysql_ConnectionObject_discard_result ,
2439+ METH_NOARGS ,
2440+ _mysql_ConnectionObject_discard_result__doc__
2441+ },
23792442 {NULL , NULL } /* sentinel */
23802443};
23812444
@@ -2437,6 +2500,12 @@ static PyMethodDef _mysql_ResultObject_methods[] = {
24372500 METH_VARARGS | METH_KEYWORDS ,
24382501 _mysql_ResultObject_fetch_row__doc__
24392502 },
2503+ {
2504+ "discard" ,
2505+ (PyCFunction )_mysql_ResultObject_discard ,
2506+ METH_NOARGS ,
2507+ _mysql_ResultObject_discard__doc__
2508+ },
24402509 {
24412510 "field_flags" ,
24422511 (PyCFunction )_mysql_ResultObject_field_flags ,
0 commit comments