]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
now loading mxODBC exception classes into module namespace while still avoiding modul...
authorBrad Allen <bradallen137@gmail.com>
Sun, 21 Mar 2010 03:58:32 +0000 (21:58 -0600)
committerBrad Allen <bradallen137@gmail.com>
Sun, 21 Mar 2010 03:58:32 +0000 (21:58 -0600)
lib/sqlalchemy/connectors/mxodbc.py

index 0c7e5ad06e0ef2f46ba45be7c78955a862fbf3b4..ac7075209c1205fbc3f3fd006dff52f5a6905484 100644 (file)
@@ -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