Installation guide

mxODBC - Python ODBC Database Interface
These mx.ODBC constants are available for the .warningformat attribute:
ERROR_WARNINGFORMAT (default)
Report warnings in the usual DB-API 2.0 way and raise a Warning
exception.
WARN_WARNINGFORMAT
Instead of raising a Warning exception, issue a
mx.ODBC.DatabaseWarning which is a Python Warning subclass and can
be filtered using the standard Python warnings module
mechanisms.
IGNORE_WARNINGFORMAT
Silently ignore the database warning.
The warning will still be added to the
.message attribute, but no further
action is taken.
10.6.2 Custom Warning Error Handler
If you need a more fine-grained approach to dealing with warnings, you can also
setup a special error handler which then overrides the behavior of the default
handler.
If you want to mask only certain
Warnings, simply set a
connection.errorhandler like the one below to disable raising exceptions for
database warnings:
# Error handler function
def myerrorhandler(connection, cursor, errorclass, errorvalue):
""" This error handler ignores (but logs) 01000 warnings issued
by the database.
"""
# Append to messages list
if cursor is not None:
cursor.messages.append((errorclass, errorvalue))
elif connection is not None:
connection.messages.append((errorclass, errorvalue))
# Ignore 01000 database warning
if (issubclass(errorclass, connection.Warning) and
errorvalue[0] == '01000'):
return
# Raise all other database errors and warnings
raise errorclass, errorvalue
# Installation of the error handler
connection.errorhandler = myerrorhandler
If you need to catch errors or warnings at connection time, you can use the
optional keyword argument
errorhandler to have the error handler installed
early enough to be able to deal with such errors or warnings:
connection = mx.ODBC.Windows.DriverConnect('DSN=test',
164