From: Brad Allen Date: Thu, 11 Mar 2010 22:24:06 +0000 (-0600) Subject: Converted mxODBC's raised Warning exceptions into normal Python warnings. X-Git-Tag: rel_0_6beta2~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96ed4865be2609d1a314d0c6ba9945ca682ef100;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Converted mxODBC's raised Warning exceptions into normal Python warnings. --- diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py index fd1a69ace3..47a5904b82 100644 --- a/lib/sqlalchemy/connectors/mxodbc.py +++ b/lib/sqlalchemy/connectors/mxodbc.py @@ -1,9 +1,11 @@ import sys import re +import warnings from sqlalchemy.connectors import Connector from mx.ODBC import InterfaceError +from mx.ODBC.Error import Warning as MxOdbcWarning class MxODBCConnector(Connector): driver='mxodbc' @@ -31,6 +33,8 @@ class MxODBCConnector(Connector): def connect(conn, rec): conn.stringformat = self.dbapi.MIXED_STRINGFORMAT conn.datetimeformat = self.dbapi.PYDATETIME_DATETIMEFORMAT + conn.errorhandler = error_handler + # Alternatives to experiment with: #conn.bindmethod = self.dbapi.BIND_USING_PYTHONTYPE #conn.bindmethod = self.dbapi.BIND_USING_SQLTYPE @@ -90,3 +94,17 @@ class MxODBCConnector(Connector): cursor.execute(statement, tuple(parameters)) except InterfaceError: cursor.executedirect(statement, tuple(parameters)) + + +def error_handler(connection, cursor, errorclass, errorvalue): + """ + Adjust mxODBC's raised Warnings to emit Python standard warnings. + """ + if issubclass(errorclass, MxOdbcWarning): + errorclass.__bases__ = (Warning,) + warnings.warn(message=str(errorvalue), + category=errorclass, + stacklevel=2) + else: + raise errorclass, errorvalue +