Skip to content

Commit 0baa379

Browse files
committed
Add setencoding setdecoding to options
Issue #72
1 parent d1cc2d8 commit 0baa379

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ Dictionary. Current available keys are:
183183
Integer. Sets the timeout in seconds for the database query.
184184
Default value is ``0`` which disables the timeout.
185185

186+
- [setencoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setencoding) and [setdecoding](https://github.com/mkleehammer/pyodbc/wiki/Connection#setdecoding)
187+
188+
```python
189+
# Example
190+
"OPTIONS": {
191+
"setdecoding": [
192+
{"sqltype": pyodbc.SQL_CHAR, "encoding": 'utf-8'},
193+
{"sqltype": pyodbc.SQL_WCHAR, "encoding": 'utf-8'}],
194+
"setencoding": [
195+
{"encoding": "utf-8"}],
196+
...
197+
},
198+
```
199+
186200
### Backend-specific settings
187201

188202
The following project-level settings also control the behavior of the backend:

mssql/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ def get_new_connection(self, conn_params):
318318
retries = options.get('connection_retries', 5)
319319
backoff_time = options.get('connection_retry_backoff_time', 5)
320320
query_timeout = options.get('query_timeout', 0)
321+
setencoding = options.get('setencoding', None)
322+
setdecoding = options.get('setdecoding', None)
321323

322324
conn = None
323325
retry_count = 0
@@ -341,6 +343,12 @@ def get_new_connection(self, conn_params):
341343
raise
342344

343345
conn.timeout = query_timeout
346+
if setencoding:
347+
for entry in setencoding:
348+
conn.setencoding(**entry)
349+
if setdecoding:
350+
for entry in setdecoding:
351+
conn.setdecoding(**entry)
344352
return conn
345353

346354
def init_connection_state(self):

0 commit comments

Comments
 (0)