Documentation Home
MySQL Connector/Python Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 0.7Mb
PDF (A4) - 0.7Mb


10.6.1 cursor.MySQLCursorBuffered Class

TheMySQLCursorBuffered class inherits fromMySQLCursor.

After executing a query, aMySQLCursorBuffered cursor fetches the entire result set from the server and buffers the rows.

For queries executed using a buffered cursor, row-fetching methods such asfetchone() 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 anInternalError (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 thebuffered argument when calling a connection'scursor() method. Alternatively, to make all cursors created from the connection buffered by default, use thebufferedconnection argument.

Example:

import mysql.connectorcnx = mysql.connector.connect()# Only this particular cursor will buffer resultscursor = cnx.cursor(buffered=True)# All cursors created from cnx2 will be buffered by defaultcnx2 = mysql.connector.connect(buffered=True)

For a practical use case, seeSection 6.1, “Tutorial: Raise Employee's Salary Using a Buffered Cursor”.