1. Mike Bayer
  2. sqlalchemy

Issues

Issue #2795 wontfix

Add pypyodbc support

sontek
created an issue

pypyodbc is a drop-in replacement for pyodbc that works on top of pypy:

https://code.google.com/p/pypyodbc/

It would be nice if there was support for it out of the box in SQLAlchemy so that we could switch between cpython and pypy with a swap of a connection string. Here are their docs on all that is required:

https://code.google.com/p/pypyodbc/wiki/Enable_SQLAlchemy_on_PyPy#Extend_SQLAlchemy_drivers

Comments (11)

  1. Mike Bayer repo owner

    have you tried pypyodbc? seems to be hanging for me. You can pass it to create_engine() like this:

    from sqlalchemy import create_engine
    
    import pypyodbc
    
    e = create_engine("mssql+pyodbc://scott:tiger@ms_2005", echo=True, module=pypyodbc)
    
    c = e.connect()
    
    print c.execute("select 1")
    
  2. Mike Bayer repo owner

    easy enough to add a new connector but I'd want to see this thing connect successfully for me, pyodbc is working fine for that same DSN....

  3. Mike Bayer repo owner

    OK I've gotten some pypyodbc tests to run, will need its own connector/dialect with some different options and different way of detecting server version info. pypyodbc isn't working for me with pypy at the moment but is working with cpython.

    here's the flags i need to have detected differently when its in use:

    diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py
    index 284de28..b920516 100644
    --- a/lib/sqlalchemy/connectors/pyodbc.py
    +++ b/lib/sqlalchemy/connectors/pyodbc.py
    @@ -47,7 +47,7 @@ class PyODBCConnector(Connector):
    
         @classmethod
         def dbapi(cls):
    -        return __import__('pyodbc')
    +        return __import__('pypyodbc')
    
         def create_connect_args(self, url):
             opts = url.translate_connect_args(username='user')
    @@ -138,6 +138,7 @@ class PyODBCConnector(Connector):
             else:
                 self.supports_unicode_binds = True
    
    +        self.supports_unicode_binds = False
             # run other initialization which asks for user name, etc.
             super(PyODBCConnector, self).initialize(connection)
    
    diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
    index 90fd1f3..d5fa15d 100644
    --- a/lib/sqlalchemy/dialects/mssql/base.py
    +++ b/lib/sqlalchemy/dialects/mssql/base.py
    @@ -1127,6 +1127,7 @@ class MSDialect(default.DefaultDialect):
    
         def initialize(self, connection):
             super(MSDialect, self).initialize(connection)
    +        self.server_version_info = MS_2008_VERSION
             if self.server_version_info[0](0) not in list(range(8, 17)):
                 # FreeTDS with version 4.2 seems to report here
                 # a number like "95.10.255".  Don't know what
    
  4. Log in to comment