Installation guide
5. mxODBC Overview
Factory created Row Classes and pickle
Because of the way these row classes are dynamically created, they are by default
not pickleable.
In order to be pickleable, they would have to be saved to a module namespace, so
that pickle can recreate them at load time. Since the creation parameters depend
on the cursor state at creation time, this is not easily possible.
If you know that a cursor will use particular result set layout, you can statically
create the row class using the factory functions, register the class in a module and
then set the
cursor.row directly to the row class.
Example:
# Create a cursor with information about the result set
cursor.execute('select * from mytable')
# Create the row class
MyTableRow = RowFactory.TupleRowFactory(cursor)
# Adjust the MyTableRow class so that pickle can find the right module
# (__name__) and class name ('MyTableRow')
MyTableRow.__name__ = 'MyTableRow'
MyTableRow.__module__ = __name__
# Fetch the data using MyTableRow objects
cursor.row = MyTableRow
rows = cursor.fetchall()
The resulting rows list is pickleable, since it can find the module and class name.
Attribute Inheritance: cursor.rowfactory and
connection.rowfactory
Just like for cursor.row, the cursor.rowfactory attribute inherits its default
value from the connection on which the cursor was created. At creation time, the
cursor.rowfactory attribute is set to connection.rowfactory.
Adjusting
connection.rowfactory after the cursor was created does not have
an effect on
cursor.rowfactory. The connection attribute setting is only used
when creating the cursor.
5.10 mxODBC Subpackages
The mxODBC package is organized in subpackages, with one package per support
ODBC driver manager and in custom builds, additional subpackages for specific
drivers/databases.
See section 14 mx.ODBC Driver/Manager Packages for details on available
subpackages.
85