Installation guide
mxODBC - Python ODBC Database Interface
Setting the value has an immediate effect on subsequent cursor.fetch*() calls.
mxODBC does not reset this attribute after the fetch operation, so the setting
persists until set to another constructor or
None.
Setting
cursor.row to None resets the row constructor to the mxODBC default of
using Python tuples.
Examples:
# Have mxODBC return lists for rows instead of tuples:
cursor.row = list
result_set = cursor.fetchall()
# Have mxODBC return tuples again:
cursor.row = None
result_set = cursor.fetchall()
# Have mxODBC return a custom object instead of tuples:
cursor.row = MyRow
result_set = cursor.fetchall()
Attribute Inheritance: cursor.row and connection.row
As with many other cursor attributes, the cursor.row attribute inherits its default
value from the connection on which the cursor was created. At creation time, the
cursor.row attribute is set to connection.row.
Adjusting
connection.row after the cursor was created does not have an effect
on
cursor.row anymore. The connection attribute setting is only used when
creating the cursor.
5.9.2 Cursor Row Factories: cursor.rowfactory
The cursor.row constructor attribute is useful for object types that don't depend
on the result set that is being returned or where you know that the result set rows
are going to have a specific layout before running the query.
On-the-fly Creation of Row Classes
In many cases, you will want to use custom row objects even for queries that
depend on external settings or where you don't want to create a specific object
class in advance.
This is where the
cursor.rowfactory attribute comes in handy. It allows you to
specify a factory function which provides the row constructor depending on the
cursor that just executed a query or statement.
When set, the row factory function
cursor.rowfactory is called with the cursor
as first parameter when calling the first
cursor.fetch*() method on the cursor
to fetch a new result set, but before actually fetching the first row.
The return value is then assigned to
cursor.row, which then results in the
cursor.row constructor to be used for fetching the rows of the result set.
82