diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/pyodbc.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mysql/pyodbc.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/pyodbc.py b/lib/sqlalchemy/dialects/mysql/pyodbc.py index 6866c3f42..9a18b5090 100644 --- a/lib/sqlalchemy/dialects/mysql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mysql/pyodbc.py @@ -23,6 +23,7 @@ """ import re +import sys from .base import MySQLDialect from .base import MySQLExecutionContext @@ -86,5 +87,28 @@ class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect): else: return None + def on_connect(self): + super_ = super(MySQLDialect_pyodbc, self).on_connect() + + def on_connect(conn): + if super_ is not None: + super_(conn) + + # declare Unicode encoding for pyodbc as per + # 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') + + return on_connect + dialect = MySQLDialect_pyodbc |