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

Commit a42e145

Browse files
committed
Added encoding selection support for database
1 parent 5c6fca5 commit a42e145

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2-
"connections": {},
2+
"connections": {
3+
/**
4+
* "Connection name": { // Connection name, used in menu (Display name)
5+
* "database" : "DATABASE",
6+
* "host" : "HOSTNAME",
7+
* "port" : "PORT",
8+
* "type" : "pgsql", // SGDB to use: (mysql, pgsql, oracle, vertica)
9+
* "username" : "USERNAME",
10+
* "password" : null // (if you are using postgresql, you must setup a pgpass file and set it to null)
11+
* "encoding" : null // Your DB encodings. Default: utf-8
12+
* },
13+
*/
14+
},
315
"default": null
416
}

SQLToolsModels.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def __init__(self, name, options):
9393
self.username = options['username']
9494
self.database = options['database']
9595

96+
if 'encoding' in options:
97+
self.encoding = options['encoding']
98+
9699
if 'password' in options:
97100
self.password = options['password']
98101

@@ -212,10 +215,11 @@ def formatSql(edit):
212215
View().replace(edit, region, Utils.formatSql(text))
213216

214217
class Command(threading.Thread):
215-
def __init__(self, args, callback, query=None):
218+
def __init__(self, args, callback, query=None, encoding='utf-8'):
216219
self.query = query
217220
self.process = None
218221
self.args = args
222+
self.encoding = encoding
219223
self.callback = callback
220224
threading.Thread.__init__(self)
221225

@@ -234,10 +238,10 @@ def run(self):
234238
results, errors = self.process.communicate()
235239

236240
if errors:
237-
self.callback(errors.decode('utf-8', 'replace').replace('\r', ''))
241+
self.callback(errors.decode(self.encoding, 'replace').replace('\r', ''))
238242
return
239243

240-
self.callback(results.decode('utf-8', 'replace').replace('\r', ''))
244+
self.callback(results.decode(self.encoding, 'replace').replace('\r', ''))
241245

242246
def stop(self):
243247
if not self.process:

0 commit comments

Comments
 (0)