Installation guide
5. mxODBC Overview
SQL.CURSOR_STATIC
The result set is made static by creating a static copy of the result set after
opening the cursor. As a result, any changes to the result set after opening
the cursor will not be visible to the client. Databases typically require
setting the cursor type to static to support backwards scrolling in the result
set via the
cursor.scroll() call. Please note that creating a static copy
can result in a significant performance degradation, esp. with MS SQL
Server and less so with IBM DB2.
SQL.CURSOR_KEYSET_DRIVEN
Keysets are sets of columns in the result set that provide unique keys to the
rows in the result set. Keyset driven cursors fix the memberships and order
of the rows in the result set using these keysets. Unlike static cursors, they
don't create a copy of the result set.
SQL.CURSOR_DYNAMIC
Dynamic cursors are the opposite of static cursors. All changes to the result
set after opening it are visible on the next fetch operation.
Please note that using cursor types other than
SQL.CURSOR_FORWARD_ONLY may
have a significant effect on the performance of fetch operations. Not all databases
support all listed cursor types.
5.8.2 Default Cursor Type
mxODBC defaults to using forward-only cursors with all databases.
11
Some databases also support other cursor types, which may be useful in certain
application settings, e.g. to make sure that the result set cannot change while
fetching it, or to enable backwards scrolling through a result set.
mxODBC therefore allows changing the cursor type on a per connection or cursor
basis using the
connection.cursortype / cursor.cursortype attributes.
You can check the currently used cursor type by inspecting the
.cursortype
attribute on a newly created connection/cursor objects:
if connection.cursortype == mx.ODBC.Windows.SQL.CURSOR_STATIC:
print "Connection uses static cursors."
elif connection.cursortype == mx.ODBC.Windows.SQL.CURSOR_FORWARD_ONLY:
print "Connection uses forward only cursors."
As with most connection attributes, the setting is inherited by the cursors created
on the connection at creation time. You can adjust the
.cursortype on a cursor
prior to executing a statement by assigning to the
cursor.cursortype attribute:
cursor.cursortype == mx.ODBC.Windows.SQL.CURSOR_STATIC
in case you need e.g. static cursor behavior for that cursor.
11
In mxODBC 3.2, mxODBC used to default to static cursors for some databases such as
MS SQL Server and IBM DB2, but this was found to cause performance problems.
79