Installation guide
5. mxODBC Overview
PostgreSQL
mxODBC defaults to forward only cursors, since the driver becomes unusable
with other settings.
IBM DB2
Just like MS SQL Server, IBM DB2 supports static cursors as well, so you can
enable these, if you need scrolling support or
.rowcount information.
There is a performance penalty of about 2x in using static cursors.
connection = mx.ODBC.Windows.DriverConnect(…)
connection.cursortype = mx.ODBC.Windows.SQL.CURSOR_STATIC
# All cursors created on connection will then default to static
# cursor type.
Note that with forward cursors, the .rowcount attribute does not always give
correct results with DB2.
5.9 Custom Cursor Row Objects and Row
Factory Functions
In some situation you may want to have mxODBC return a different Python object
type or class when fetching rows from the database, e.g. ones which offer not
only indexes based access to the row fields, but also named attribute or index
access.
mxODBC 3.3 introduced two new cursor attributes
cursor.row and
cursor.rowfactory which can be used to customize the objects returned by
mxODBC in result sets when using the
cursor.fetch*() methods.
Default is to return standard Python tuples for rows in the result, since this is the
most performant way of providing access to the data.
With the new attributes, it is possible to have mxODBC automatically return other
sequence types (e.g. lists), hybrids providing sequence/mapping/attribute access
to the columns or higher-level abstraction layer objects.
5.9.1 Cursor Row Constructor: cursor.row
In order to have mxODBC use a different row constructor than the tuple
constructor, set the
cursor.row attribute to a function or class which takes a
single parameter, the row tuple, and returns an object for the row.
81