Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit a2ef789

Browse files
committed
Check if valid encoding, defaulting to utf-8
1 parent 14cb7a5 commit a2ef789

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

SQLToolsAPI/Connection.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import shutil
22
import shlex
3+
import codecs
34
import sqlparse
45

56
from .Log import Log
67
from . import Utils as U
78
from . import Command as C
89

910

11+
def _encoding_exists(enc):
12+
try:
13+
codecs.lookup(enc)
14+
except LookupError:
15+
return False
16+
return True
17+
18+
1019
class Connection(object):
1120
DB_CLI_NOT_FOUND_MESSAGE = """'{0}' could not be found.
1221
Please set the path to '{0}' binary in your SQLTools settings before continuing.
@@ -28,7 +37,6 @@ class Connection(object):
2837
username = None
2938
password = None
3039
encoding = None
31-
service = None
3240
safe_limit = None
3341
show_query = None
3442
rowsLimit = None
@@ -52,7 +60,9 @@ def __init__(self, name, options, settings=None, commandClass='ThreadCommand'):
5260
self.username = options.get('username', None)
5361
self.password = options.get('password', None)
5462
self.encoding = options.get('encoding', 'utf-8')
55-
self.service = options.get('service', None)
63+
self.encoding = self.encoding or 'utf-8' # defaults to utf-8
64+
if not _encoding_exists(self.encoding):
65+
self.encoding = 'utf-8'
5666

5767
self.safe_limit = settings.get('safe_limit', None)
5868
self.show_query = settings.get('show_query', False)

0 commit comments

Comments
 (0)