Skip to content

Commit

Permalink
Merge pull request mtxr#178 from mtxr/default_connection_encoding
Browse files Browse the repository at this point in the history
Check if valid encoding, defaulting to utf-8
  • Loading branch information
tkopets authored Jan 18, 2018
2 parents 14cb7a5 + a2ef789 commit ad8d653
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions SQLToolsAPI/Connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import shutil
import shlex
import codecs
import sqlparse

from .Log import Log
from . import Utils as U
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.
Expand All @@ -28,7 +37,6 @@ class Connection(object):
username = None
password = None
encoding = None
service = None
safe_limit = None
show_query = None
rowsLimit = None
Expand All @@ -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)
Expand Down

0 comments on commit ad8d653

Please sign in to comment.