Python Driver: ResultCursor

The ResultCursor class in the Polypheny Python Driver is a key component for handling query results. It provides a mechanism to iterate over the rows returned by a query, managing the fetching of result frames as needed. This class is typically used internally by the Cursor class and may not be directly instantiated by end-users. However, understanding its properties and methods can be useful for advanced usage and debugging.

The ResultCursor class is designed to abstract away the complexities of result set pagination and should be used in conjunction with the Cursor class for executing queries and fetching results. Direct usage of ResultCursor is generally not necessary unless implementing custom cursor behavior or extending the driver’s functionality.

Initialization

The ResultCursor class is initialized with the following parameters:

  • con: A reference to the Connection object associated with the current database session.
  • statement_id: The unique identifier of the executed statement, provided by the Polypheny database.
  • frame: The initial result frame returned by the execution of the statement.
  • fetch_size: The number of rows to fetch per network round trip. If not specified, the driver’s default fetch size is used.

Example:

result_cursor = ResultCursor(con, statement_id, frame, fetch_size)

Properties:

  • con: The Connection object through which the statement was executed.
  • statement_id: The identifier for the statement whose results are being fetched.
  • closed: A boolean flag indicating whether the cursor is closed.
  • frame: The current frame of results being processed.
  • fetch_size: The number of rows to fetch in each network round trip.
  • rows: An iterator over the rows in the current frame.

close()

Closes the cursor, releasing any resources associated with it. Once closed, the cursor is no longer usable.

Usage:

result_cursor.close()

next()

Advances the cursor to the next row. If the current frame is exhausted and more rows are available, automatically fetches the next frame.

Returns:

  • The next row as a tuple of values.

Raises:

  • StopIteration if there are no more rows.

Usage:

next_row = next(result_cursor)

nextframe()

Fetches the next frame of results from the database, updating the cursor’s state to iterate over the new frame.

Returns:

  • The first row of the new frame as a tuple of values.

Raises:

  • StopIteration if no more frames are available.

Usage:

next_frame_first_row = result_cursor.nextframe()
© Polypheny GmbH. All Rights Reserved.