MySQLCursorBuffered class inherits from
After executing a query, a
MySQLCursorBuffered cursor fetches the entire
result set from the server and buffers the rows.
For queries executed using a buffered cursor, row-fetching
methods such as
return rows from the set of buffered rows. For nonbuffered
cursors, rows are not fetched from the server until a
row-fetching method is called. In this case, you must be sure to
fetch all rows of the result set before executing any other
statements on the same connection, or an
InternalError (Unread result found) exception
will be raised.
MySQLCursorBuffered can be useful in
situations where multiple queries, with small result sets, need
to be combined or computed with each other.
To create a buffered cursor, use the
argument when calling a connection's
method. Alternatively, to make all cursors created from the
connection buffered by default, use the
import mysql.connector cnx = mysql.connector.connect() # Only this particular cursor will buffer results cursor = cnx.cursor(buffered=True) # All cursors created from cnx2 will be buffered by default cnx2 = mysql.connector.connect(buffered=True)
For a practical use case, see Section 7.6.1, “Tutorial: Raise Employee's Salary Using a Buffered Cursor”.