diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/pyodbc.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/pyodbc.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/pyodbc.py b/lib/sqlalchemy/dialects/mysql/pyodbc.py index 69cc6487d..9cae7b714 100644 --- a/lib/sqlalchemy/dialects/mysql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mysql/pyodbc.py @@ -43,11 +43,11 @@ Pass through exact pyodbc connection string:: """ # noqa import re -import sys from .base import MySQLDialect from .base import MySQLExecutionContext from .types import TIME +from ... import exc from ... import util from ...connectors.pyodbc import PyODBCConnector from ...sql.sqltypes import Time @@ -88,13 +88,14 @@ class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect): # # If it's decided that issuing that sort of SQL leaves you SOL, then # this can prefer the driver value. - rs = connection.exec_driver_sql( - "SHOW VARIABLES LIKE 'character_set%%'" - ) - opts = {row[0]: row[1] for row in self._compat_fetchall(rs)} - for key in ("character_set_connection", "character_set"): - if opts.get(key, None): - return opts[key] + try: + value = connection.exec_driver_sql( + "select @@character_set_client" + ).scalar() + if value: + return value + except exc.DBAPIError: + pass util.warn( "Could not detect the connection character set. " @@ -121,15 +122,9 @@ class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect): # https://github.com/mkleehammer/pyodbc/wiki/Unicode pyodbc_SQL_CHAR = 1 # pyodbc.SQL_CHAR pyodbc_SQL_WCHAR = -8 # pyodbc.SQL_WCHAR - if sys.version_info.major > 2: - conn.setdecoding(pyodbc_SQL_CHAR, encoding="utf-8") - conn.setdecoding(pyodbc_SQL_WCHAR, encoding="utf-8") - conn.setencoding(encoding="utf-8") - else: - conn.setdecoding(pyodbc_SQL_CHAR, encoding="utf-8") - conn.setdecoding(pyodbc_SQL_WCHAR, encoding="utf-8") - conn.setencoding(str, encoding="utf-8") - conn.setencoding(unicode, encoding="utf-8") # noqa: F821 + conn.setdecoding(pyodbc_SQL_CHAR, encoding="utf-8") + conn.setdecoding(pyodbc_SQL_WCHAR, encoding="utf-8") + conn.setencoding(encoding="utf-8") return on_connect |