diff options
| author | Brad Allen <bradallen137@gmail.com> | 2010-03-20 21:58:32 -0600 |
|---|---|---|
| committer | Brad Allen <bradallen137@gmail.com> | 2010-03-20 21:58:32 -0600 |
| commit | 323f1b358de19cc9cbfd45408636aa58060adf15 (patch) | |
| tree | de3acb9715f64afd2902b38bd21ae5fa0314fbc4 /lib/sqlalchemy/connectors/mxodbc.py | |
| parent | b728f2db23ab297c1fe2853ed3e5e69178ab2d0c (diff) | |
| download | sqlalchemy-323f1b358de19cc9cbfd45408636aa58060adf15.tar.gz | |
now loading mxODBC exception classes into module namespace while still avoiding module imports (hooking into dbapi class method)
Diffstat (limited to 'lib/sqlalchemy/connectors/mxodbc.py')
| -rw-r--r-- | lib/sqlalchemy/connectors/mxodbc.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py index 0c7e5ad06..ac7075209 100644 --- a/lib/sqlalchemy/connectors/mxodbc.py +++ b/lib/sqlalchemy/connectors/mxodbc.py @@ -31,6 +31,9 @@ class MxODBCConnector(Connector): @classmethod def dbapi(cls): + # this classmethod will normally be replaced by an instance + # attribute of the same name, so this is normally only called once. + cls._load_mx_exceptions() platform = sys.platform if platform == 'win32': from mx.ODBC import Windows as module @@ -43,6 +46,16 @@ class MxODBCConnector(Connector): raise ImportError, "Unrecognized platform for mxODBC import" return module + @classmethod + def _load_mx_exceptions(cls): + """ Import mxODBC exception classes into the module namespace, + as if they had been imported normally. This is done here + to avoid requiring all SQLAlchemy users to install mxODBC. + """ + global InterfaceError, ProgrammingError + from mx.ODBC import InterfaceError + from mx.ODBC import ProgrammingError + def on_connect(self): def connect(conn): conn.stringformat = self.dbapi.MIXED_STRINGFORMAT |
