From c2a158c137ee07a146f02e5ee89ec42e486c6a37 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 3 Jun 2013 12:54:56 -0400 Subject: [PATCH] - some tweaks to try to help out mssql+pyodbc support a bit, py3k is really not happening too well (I need to stick with linux + freetds 0.91, I know) --- lib/sqlalchemy/connectors/pyodbc.py | 31 ++++++++++++++++----------- lib/sqlalchemy/dialects/mssql/base.py | 1 + setup.cfg | 1 + test/sql/test_query.py | 2 -- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 784344b824..6b4e3036da 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -16,9 +16,12 @@ class PyODBCConnector(Connector): driver = 'pyodbc' supports_sane_multi_rowcount = False - # PyODBC unicode is broken on UCS-4 builds - supports_unicode = sys.maxunicode == 65535 - supports_unicode_statements = supports_unicode + + if util.py2k: + # PyODBC unicode is broken on UCS-4 builds + supports_unicode = sys.maxunicode == 65535 + supports_unicode_statements = supports_unicode + supports_native_decimal = True default_paramstyle = 'named' @@ -121,15 +124,19 @@ class PyODBCConnector(Connector): self.freetds_driver_version = dbapi_con.getinfo( pyodbc.SQL_DRIVER_VER) - if not util.py3k: - self.supports_unicode_statements = ( - not self.freetds and not self.easysoft) - if self._user_supports_unicode_binds is not None: - self.supports_unicode_binds = self._user_supports_unicode_binds - else: - self.supports_unicode_binds = ( - not self.freetds or self.freetds_driver_version >= '0.91' - ) and not self.easysoft + self.supports_unicode_statements = ( + not util.py2k or + (not self.freetds and not self.easysoft) + ) + + if self._user_supports_unicode_binds is not None: + self.supports_unicode_binds = self._user_supports_unicode_binds + elif util.py2k: + self.supports_unicode_binds = ( + not self.freetds or self.freetds_driver_version >= '0.91' + ) and not self.easysoft + else: + self.supports_unicode_binds = True # 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 a5d789be19..3c329fe5e5 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -1172,6 +1172,7 @@ class MSDialect(default.DefaultDialect): columns = ischema.columns whereclause = self._unicode_cast(columns.c.table_name) == tablename + if owner: whereclause = sql.and_(whereclause, columns.c.table_schema == owner) diff --git a/setup.cfg b/setup.cfg index 9c53e32ad1..61c868a163 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,7 @@ pg8000=postgresql+pg8000://scott:tiger@127.0.0.1:5432/test postgresql_jython=postgresql+zxjdbc://scott:tiger@127.0.0.1:5432/test mysql_jython=mysql+zxjdbc://scott:tiger@127.0.0.1:5432/test mysql=mysql://scott:tiger@127.0.0.1:3306/test +mssql=mssql+pyodbc://scott:tiger@ms_2005 oursql=mysql+oursql://scott:tiger@127.0.0.1:3306/test pymysql=mysql+pymysql://scott:tiger@127.0.0.1:3306/test?use_unicode=0&charset=utf8 oracle=oracle://scott:tiger@127.0.0.1:1521 diff --git a/test/sql/test_query.py b/test/sql/test_query.py index 3e9045fa56..ae029b11ca 100644 --- a/test/sql/test_query.py +++ b/test/sql/test_query.py @@ -708,8 +708,6 @@ class QueryTest(fixtures.TestBase): use_labels=labels), [(3, 'a'), (2, 'b'), (1, None)]) - @testing.fails_on('mssql+pyodbc', - "pyodbc result row doesn't support slicing") def test_column_slices(self): users.insert().execute(user_id=1, user_name='john') users.insert().execute(user_id=2, user_name='jack') -- 2.47.3