The Python Cursor Class

The Cursor class represents a cursor to iterate through instances of a specified class, the result set of a find/search operation, or the result set from SQL queries. It provides the following methods:

find(cls, idx, value)
Find a database object of class cls by an index idx and key value (a DB API compliant call)
search(cls, idx, op, value)
Locate the position of a database object of class cls in an index idx and key value using the operation op (a DB API compliant call)
checkpoint()
Checkpoint the cursor; this updates the index for any updated objects previously returned by the methods first(), last(), next(), prev() or skip().
close()
Close the cursor
getAutoId()
Get the autoid of the current object
first()
Move cursor to the first position
last()
Move cursor to the last position
next()
Move cursor to the next position
prev()
Move cursor to the previous position
skip()
Move cursor to the next position without retrieving the element
reset()
Reset (rewind) the cursor
current()
Return the object to which the cursor is referring
execute(query [,args])
Execute a SQL query against the database substituting arguments args for format specifiers in the query string (a DB API compliant call)
execute_many(query, args)
Execute a SQL query against the database applying a set of parameters args (a DB API compliant call)
fetchone()
Return the next row of result set (a DB API compliant call)
fetchmany([size=cursor.arraysize])
Fetch the next set of rows from a result set optionally specifying the size of the result set (a DB API compliant call)
fetchall()
Fetch all (remaining) rows of a query result (a DB API compliant call)
rowcount
The read-only property that indicates the number of rows affected

Using a Cursor as a Context Manager

Starting with eXtremeDB version 8.4.1806, the Cursor type supports the context manager protocol. This allows automatic cleanup of the cursor when exiting the with block, even if an error occurs.

It is recommended to use the following pattern to ensure the cursor is properly closed:

    with con.cursor("Record") as cursor:
        for rec in cursor:
            printRecord(rec)

This approach guarantees that resources associated with the cursor are released reliably, without requiring an explicit close() call.