Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.mysql.cursor

import sql.mysql.cursor

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.mysql.cursor.* needs import sql.mysql.cursor.

Reading a MySQL result a batch at a time.

The server keeps the result and sends as many rows as each fetch asks for, so nothing but the current batch is ever held on this side. Only a prepared statement can be read this way, which is why a cursor over a statement written as text still prepares it first.

One at a time

A cursor holds the connection: the server is part way through answering, and no other command may be sent until it has finished. Running a statement on the same connection while a cursor is open raises rather than corrupting the exchange.

Classes

MySqlCursor

class sql.mysql.MySqlCursor < DriverCursor

A result being read in batches.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

sql.mysql.MySqlCursor(connection, state)

Parameters

  • connection (MySqlConnection)
  • state (dict) — The statement to fetch from, its columns, the batch size, whether there is anything to fetch at all, and whether this cursor prepared the statement and so has to release it.

MySqlCursor.columns()

sql.mysql.MySqlCursor.columns()

MySqlCursor.next_row()

sql.mysql.MySqlCursor.next_row() -> list|nil

The next row as a list of values, or nil once the result is finished.

Returns list|nil

MySqlCursor.close()

sql.mysql.MySqlCursor.close()

Releases the cursor, and the statement if this cursor prepared one. Safe to call more than once.

MySqlCursor.is_closed()

sql.mysql.MySqlCursor.is_closed() -> bool

Whether the cursor has been closed or read to the end.

Returns bool

MySqlCursor.to_string()

sql.mysql.MySqlCursor.to_string()

2026, Richard Ore and Zuri contributors