]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add on_connect to MySQLDialect_pyodbc
authorGord Thompson <gord@gordthompson.com>
Wed, 2 Oct 2019 10:52:22 +0000 (04:52 -0600)
committerGord Thompson <gord@gordthompson.com>
Wed, 2 Oct 2019 10:52:22 +0000 (04:52 -0600)
Fixes: #4876
lib/sqlalchemy/dialects/mysql/pyodbc.py

index e8d2034a1744ce80c0ab21c9dff69b2416a7cb56..889996b8a24205d3d89a60719a90eb53dc5cd4ba 100644 (file)
@@ -79,5 +79,18 @@ 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)
+
+            conn.setdecoding(1, encoding='utf-8')  # pyodbc.SQL_CHAR
+            conn.setdecoding(-8, encoding='utf-8')  # pyodbc.SQL_WCHAR
+            conn.setencoding(encoding='utf-8')
+
+        return on_connect
+
 
 dialect = MySQLDialect_pyodbc