diff --git a/README.md b/README.md index de34297e..1f9b4c0e 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,20 @@ Dictionary. Current available keys are: Integer. Sets the timeout in seconds for the database query. Default value is ``0`` which disables the timeout. +- [setencoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setencoding) and [setdecoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setdecoding) + + ```python + # Example + "OPTIONS": { + "setdecoding": [ + {"sqltype": pyodbc.SQL_CHAR, "encoding": 'utf-8'}, + {"sqltype": pyodbc.SQL_WCHAR, "encoding": 'utf-8'}], + "setencoding": [ + {"encoding": "utf-8"}], + ... + }, + ``` + ### Backend-specific settings The following project-level settings also control the behavior of the backend: diff --git a/mssql/base.py b/mssql/base.py index 69f52194..1f75d4f3 100644 --- a/mssql/base.py +++ b/mssql/base.py @@ -318,6 +318,8 @@ def get_new_connection(self, conn_params): retries = options.get('connection_retries', 5) backoff_time = options.get('connection_retry_backoff_time', 5) query_timeout = options.get('query_timeout', 0) + setencoding = options.get('setencoding', None) + setdecoding = options.get('setdecoding', None) conn = None retry_count = 0 @@ -341,6 +343,12 @@ def get_new_connection(self, conn_params): raise conn.timeout = query_timeout + if setencoding: + for entry in setencoding: + conn.setencoding(**entry) + if setdecoding: + for entry in setdecoding: + conn.setdecoding(**entry) return conn def init_connection_state(self):