diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/pyodbc.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index c6368f969..a667b671e 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -64,34 +64,19 @@ as illustrated below using ``urllib.quote_plus``:: engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params) -Unicode Binds -------------- - -The current state of PyODBC on a unix backend with FreeTDS and/or -EasySoft is poor regarding unicode; different OS platforms and versions of -UnixODBC versus IODBC versus FreeTDS/EasySoft versus PyODBC itself -dramatically alter how strings are received. The PyODBC dialect attempts to -use all the information it knows to determine whether or not a Python unicode -literal can be passed directly to the PyODBC driver or not; while SQLAlchemy -can encode these to bytestrings first, some users have reported that PyODBC -mis-handles bytestrings for certain encodings and requires a Python unicode -object, while the author has observed widespread cases where a Python unicode -is completely misinterpreted by PyODBC, particularly when dealing with -the information schema tables used in table reflection, and the value -must first be encoded to a bytestring. - -It is for this reason that whether or not unicode literals for bound -parameters be sent to PyODBC can be controlled using the -``supports_unicode_binds`` parameter to ``create_engine()``. When -left at its default of ``None``, the PyODBC dialect will use its -best guess as to whether or not the driver deals with unicode literals -well. When ``False``, unicode literals will be encoded first, and when -``True`` unicode literals will be passed straight through. This is an interim -flag that hopefully should not be needed when the unicode situation stabilizes -for unix + PyODBC. - -.. versionadded:: 0.7.7 - ``supports_unicode_binds`` parameter to ``create_engine()``\ . +Driver / Unicode Support +------------------------- + +PyODBC works best with Microsoft ODBC drivers, particularly in the area +of Unicode support on both Python 2 and Python 3. + +Using the FreeTDS ODBC drivers on Linux or OSX with PyODBC is **not** +recommended; there have been historically many Unicode-related issues +in this area, including before Microsoft offered ODBC drivers for Linux +and OSX. Now that Microsoft offers drivers for all platforms, for +PyODBC support these are recommended. FreeTDS remains relevant for +non-ODBC drivers such as pymssql where it works very well. + Rowcount Support ---------------- @@ -272,11 +257,12 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect): def _get_server_version_info(self, connection): try: - raw = connection.scalar("SELECT SERVERPROPERTY('ProductVersion')") + raw = connection.scalar( + "SELECT CAST(SERVERPROPERTY('ProductVersion') AS VARCHAR)") except exc.DBAPIError: # SQL Server docs indicate this function isn't present prior to - # 2008; additionally, unknown combinations of pyodbc aren't - # able to run this query. + # 2008. Before we had the VARCHAR cast above, pyodbc would also + # fail on this query. return super(MSDialect_pyodbc, self).\ _get_server_version_info(connection) else: |