diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index 8b05ae8..ffc57c5 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -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 /** @@ -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: @@ -35,8 +42,8 @@ "firebird": "isql", "sqlite" : "sqlite3" }, - "show_records" : { - "limit" : 50 + "show_records": { + "limit": 50 }, "format" : { "keyword_case" : "upper", diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index e5ef990..8842f05 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -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 @@ -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 @@ -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) diff --git a/SQLToolsAPI/Connection.py b/SQLToolsAPI/Connection.py index 7971ec0..a2acba4 100644 --- a/SQLToolsAPI/Connection.py +++ b/SQLToolsAPI/Connection.py @@ -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']]