diff --git a/SQLToolsAPI/Connection.py b/SQLToolsAPI/Connection.py index 2d780bb..9ab6656 100644 --- a/SQLToolsAPI/Connection.py +++ b/SQLToolsAPI/Connection.py @@ -1,5 +1,6 @@ import shutil import shlex +import codecs import sqlparse from .Log import Log @@ -7,6 +8,14 @@ from . import Command as C +def _encoding_exists(enc): + try: + codecs.lookup(enc) + except LookupError: + return False + return True + + class Connection(object): DB_CLI_NOT_FOUND_MESSAGE = """'{0}' could not be found. Please set the path to '{0}' binary in your SQLTools settings before continuing. @@ -28,7 +37,6 @@ class Connection(object): username = None password = None encoding = None - service = None safe_limit = None show_query = None rowsLimit = None @@ -52,7 +60,9 @@ def __init__(self, name, options, settings=None, commandClass='ThreadCommand'): self.username = options.get('username', None) self.password = options.get('password', None) self.encoding = options.get('encoding', 'utf-8') - self.service = options.get('service', None) + self.encoding = self.encoding or 'utf-8' # defaults to utf-8 + if not _encoding_exists(self.encoding): + self.encoding = 'utf-8' self.safe_limit = settings.get('safe_limit', None) self.show_query = settings.get('show_query', False)