support driver specification via entry points

Issue #2286 resolved
Mike Bayer repo owner created an issue

This would include both existing databases with just the driver coming from an entry point, as well as the database+driver coming from an entrypoint.

patch, untested:

diff -r 13897cb81bfcbf24c2e96cd22f61a7d42cff4ca8 lib/sqlalchemy/engine/url.py
--- a/lib/sqlalchemy/engine/url.py  Fri Sep 23 22:25:31 2011 -0400
+++ b/lib/sqlalchemy/engine/url.py  Fri Sep 23 22:33:28 2011 -0400
@@ -104,7 +104,14 @@

             module = __import__('sqlalchemy.dialects.%s' % (dialect, )).dialects
             module = getattr(module, dialect)
-            module = getattr(module, driver)
+            if hasattr(module, driver):
+                module = getattr(module, driver)
+            else:
+                module = self._load_entry_point()
+                if module is None:
+                    raise exc.ArgumentError(
+                        "Could not determine dialect for '%s'." % 
+                        self.drivername)

             return module.dialect
         except ImportError:
@@ -128,7 +135,7 @@
             return None

         for res in pkg_resources.iter_entry_points('sqlalchemy.dialects'):
-            if res.name == self.drivername:
+            if res.name == self.drivername.replace("+", "."):
                 return res.load()
         else:
             return None

Comments (7)

  1. Former user Account Deleted

    I think this is much better as it enabling the use of alt. driver for already supported database, not only for unsupported database. Thank you Michael.

    -Jaimy.

  2. Former user Account Deleted

    Confirmed works Michael, I try it both on CPython and Jython.

    -Jaimy.

    (sqltest) D:\Projects\sqltest\SQLAlchemy-0.7.2>python sqla_nose.py --verbose --dburi=ibm_db_sa+pyodbc://user:passwd@aa.bb.cc.dd:50000/USERDB
    D:\Projects\sqltest\lib\site-packages\nose-1.1.2-py2.6.egg\nose\plugins\manager.
    py:383: RuntimeWarning: Unable to load plugin pylons = pylons.test:PylonsPlugin:
     Beaker>=1.3dev
      RuntimeWarning)
    D:\Projects\sqltest\lib\site-packages\sqlalchemy-0.7.2-py2.6.egg\sqlalchemy\dial
    ects\access\base.py:162: SAWarning: The access dialect is not yet ported to SQLA
    lchemy 0.6/0.7
      super(AccessDialect, self).__init__(**params)
    test.aaa_profiling.test_compiler.CompileTest.test_insert ... ok
    test.aaa_profiling.test_compiler.CompileTest.test_select ... ok
    test.aaa_profiling.test_compiler.CompileTest.test_update ... ok
    test.aaa_profiling.test_compiler.CompileTest.test_update_whereclause ... ok
    ...
    
    (sqltest) D:\Projects\sqltest\SQLAlchemy-0.7.2>jython sqla_nose.py --verbose --dburi=ibm_db_sa+zxjdbc://user:passwd@aa.bb.cc.dd:50000/USERDB
    C:\Java\app\jython\Lib\site-packages\sqlalchemy-0.7.2-py2.5.egg\sqlalchemy\diale
    cts\access\base.py:162: SAWarning: The access dialect is not yet ported to SQLAl
    chemy 0.6/0.7
      super(AccessDialect, self).__init__(**params)
    test.base.test_dependency.DependencySortTest.test_find_cycle_one ... ok
    ...
    
  3. Log in to comment