Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mtxr authored Jul 5, 2017
2 parents 18bca38 + e3d8418 commit 6fe8e24
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
15 changes: 11 additions & 4 deletions SQLTools.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"show_result_on_window" : false,
"clear_output" : true,
"safe_limit" : false,
"show_query" : false,
"expand_to_paragraph" : false,
"use_streams" : false, // use streams for results
/**
Expand All @@ -17,10 +16,18 @@
*/
"selectors": ["source.sql", "source.pgsql", "source.plpgsql.postgres", "source.plsql.oracle", "source.tsql"],
/**
* Possible values for autocompletion: "basic", "smart" or false (disable)
* Possible values for autocompletion: "basic", "smart", true ("smart"),
* or false (disable)
* Completion keywords case is controlled by format.keyword_case (see below)
*/
"autocompletion": "smart",
/**
* Possible values for show_query: "top", "bottom", true ("top"), or false (disable)
* When using regular output, this will determine where query details is displayed.
* In stream output mode, any option that isn't false will print query details at
* the bottom of result.
*/
"show_query": false,
/**
* If DB cli binary is not in PATH, set the full path in "cli" section.
* Note: forward slashes ("/") should be used in path. Example:
Expand All @@ -35,8 +42,8 @@
"firebird": "isql",
"sqlite" : "sqlite3"
},
"show_records" : {
"limit" : 50
"show_records": {
"limit": 50
},
"format" : {
"keyword_case" : "upper",
Expand Down
27 changes: 23 additions & 4 deletions SQLToolsAPI/Command.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self, args, env, callback, query=None, encoding='utf-8',
self.silenceErrors = silenceErrors
self.process = None

if 'show_query' not in self.options:
self.options['show_query'] = False
elif self.options['show_query'] not in ['top', 'bottom']:
self.options['show_query'] = 'top' if (isinstance(self.options['show_query'], bool)
and self.options['show_query']) else False

def run(self):
if not self.query:
return
Expand Down Expand Up @@ -61,18 +67,24 @@ def run(self):
if self.stream:
self.process.stdin.write(self.query.encode())
self.process.stdin.close()
hasWritten = False

for line in self.process.stdout:
self.callback(line.decode(self.encoding,
'replace').replace('\r', ''))
hasWritten = True

queryTimerEnd = time.time()
# we are done with the output, terminate the process
if self.process:
self.process.terminate()
else:
if hasWritten:
self.callback('\n')

if 'show_query' in self.options and self.options['show_query']:
if self.options['show_query']:
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
self.callback(formattedQueryInfo)
self.callback(formattedQueryInfo + '\n')

return

Expand All @@ -92,9 +104,16 @@ def run(self):
resultString += errors.decode(self.encoding,
'replace').replace('\r', '')

if 'show_query' in self.options and self.options['show_query']:
if self.process == None and resultString != '':
resultString += '\n'

if self.options['show_query']:
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
resultString = "{0}\n{1}".format(formattedQueryInfo, resultString)
queryPlacement = self.options['show_query']
if queryPlacement == 'top':
resultString = "{0}\n{1}".format(formattedQueryInfo, resultString)
elif queryPlacement == 'bottom':
resultString = "{0}{1}\n".format(resultString, formattedQueryInfo)

self.callback(resultString)

Expand Down
2 changes: 1 addition & 1 deletion SQLToolsAPI/Connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, name, options, settings=None, commandClass='ThreadCommand'):
self.service = options.get('service', None)

self.safe_limit = settings.get('safe_limit', None)
self.show_query = settings.get('show_query', None)
self.show_query = settings.get('show_query', False)
self.rowsLimit = settings.get('show_records', {}).get('limit', 50)
self.cli = settings.get('cli')[options['type']]

Expand Down

0 comments on commit 6fe8e24

Please sign in to comment.