@@ -1484,6 +1484,26 @@ _mysql_ResultObject_fetch_row(
1484
1484
return NULL ;
1485
1485
}
1486
1486
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
+
1487
1507
static char _mysql_ConnectionObject_change_user__doc__ [] =
1488
1508
"Changes the user and causes the database specified by db to\n\
1489
1509
become the default (current) database on the connection\n\
@@ -2081,6 +2101,43 @@ _mysql_ConnectionObject_use_result(
2081
2101
return result ;
2082
2102
}
2083
2103
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
+
2084
2141
static void
2085
2142
_mysql_ConnectionObject_dealloc (
2086
2143
_mysql_ConnectionObject * self )
@@ -2376,6 +2433,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
2376
2433
METH_NOARGS ,
2377
2434
_mysql_ConnectionObject_use_result__doc__
2378
2435
},
2436
+ {
2437
+ "discard_result" ,
2438
+ (PyCFunction )_mysql_ConnectionObject_discard_result ,
2439
+ METH_NOARGS ,
2440
+ _mysql_ConnectionObject_discard_result__doc__
2441
+ },
2379
2442
{NULL , NULL } /* sentinel */
2380
2443
};
2381
2444
@@ -2437,6 +2500,12 @@ static PyMethodDef _mysql_ResultObject_methods[] = {
2437
2500
METH_VARARGS | METH_KEYWORDS ,
2438
2501
_mysql_ResultObject_fetch_row__doc__
2439
2502
},
2503
+ {
2504
+ "discard" ,
2505
+ (PyCFunction )_mysql_ResultObject_discard ,
2506
+ METH_NOARGS ,
2507
+ _mysql_ResultObject_discard__doc__
2508
+ },
2440
2509
{
2441
2510
"field_flags" ,
2442
2511
(PyCFunction )_mysql_ResultObject_field_flags ,
0 commit comments