From 2b4b23b231d62f30a4d34190efee8fb421e6364f Mon Sep 17 00:00:00 2001 From: Coteh Date: Fri, 16 Jun 2017 22:58:08 -0400 Subject: [PATCH 1/8] Add placement configuration of show_query --- SQLTools.sublime-settings | 5 ++++- SQLToolsAPI/Command.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index 2e11980..e578a38 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -8,7 +8,10 @@ "show_result_on_window" : false, "clear_output" : true, "safe_limit" : false, - "show_query" : false, + "show_query" : { + "enabled": false, + "placement": "top" + }, "expand_to_paragraph" : false, "use_streams" : false, // use streams for results /** diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index e5ef990..b027992 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -92,9 +92,18 @@ def run(self): resultString += errors.decode(self.encoding, 'replace').replace('\r', '') - if 'show_query' in self.options and self.options['show_query']: - formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) + if 'show_query' in self.options: + if isinstance(self.options['show_query'], dict): + if 'enabled' not in self.options['show_query'] or self.options['show_query']['enabled']: + formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + if ('placement' in self.options['show_query'] + and self.options['show_query']['placement'] == "bottom"): + resultString = "{0}\n{1}".format(resultString, formattedQueryInfo) + else: # top, by default + resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) + elif isinstance(self.options['show_query'], bool) and self.options['show_query']: + formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) self.callback(resultString) From d97073c481c10e156209405c567965d45be265a3 Mon Sep 17 00:00:00 2001 From: Coteh Date: Sat, 17 Jun 2017 14:38:47 -0400 Subject: [PATCH 2/8] Clean up and remove true/false evaluation for show_query --- SQLTools.sublime-settings | 11 +++++------ SQLToolsAPI/Command.py | 16 ++++++---------- SQLToolsAPI/Connection.py | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index e578a38..4bd5fd8 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -8,10 +8,6 @@ "show_result_on_window" : false, "clear_output" : true, "safe_limit" : false, - "show_query" : { - "enabled": false, - "placement": "top" - }, "expand_to_paragraph" : false, "use_streams" : false, // use streams for results /** @@ -38,8 +34,11 @@ "firebird": "isql", "sqlite" : "sqlite3" }, - "show_records" : { - "limit" : 50 + "show_records": { + "limit": 50 + }, + "show_query": { + "placement": "disabled" }, "format" : { "keyword_case" : "upper", diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index b027992..5a28589 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -93,17 +93,13 @@ def run(self): 'replace').replace('\r', '') if 'show_query' in self.options: - if isinstance(self.options['show_query'], dict): - if 'enabled' not in self.options['show_query'] or self.options['show_query']['enabled']: - formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - if ('placement' in self.options['show_query'] - and self.options['show_query']['placement'] == "bottom"): - resultString = "{0}\n{1}".format(resultString, formattedQueryInfo) - else: # top, by default - resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) - elif isinstance(self.options['show_query'], bool) and self.options['show_query']: + queryPlacement = self.options['show_query'].get('placement', 'disabled') + if isinstance(queryPlacement, str) and queryPlacement != 'disabled': formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) + if queryPlacement == 'top': + resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) + elif queryPlacement == 'bottom': + resultString = "{0}\n{1}".format(resultString, formattedQueryInfo) self.callback(resultString) diff --git a/SQLToolsAPI/Connection.py b/SQLToolsAPI/Connection.py index 7971ec0..2e83183 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', {}) self.rowsLimit = settings.get('show_records', {}).get('limit', 50) self.cli = settings.get('cli')[options['type']] From a61c117b5f96785759a452f631c4805296d6540a Mon Sep 17 00:00:00 2001 From: Coteh Date: Sat, 17 Jun 2017 17:29:42 -0400 Subject: [PATCH 3/8] Only use show_query's 'enabled' property in stream --- SQLTools.sublime-settings | 3 ++- SQLToolsAPI/Command.py | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index 4bd5fd8..03d811c 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -38,7 +38,8 @@ "limit": 50 }, "show_query": { - "placement": "disabled" + "enabled": true, + "placement": "top" }, "format" : { "keyword_case" : "upper", diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index 5a28589..0283da9 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -70,9 +70,10 @@ def run(self): if self.process: self.process.terminate() - if 'show_query' in self.options and self.options['show_query']: - formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - self.callback(formattedQueryInfo) + if 'show_query' in self.options: + if 'enabled' in self.options['show_query'] and self.options['show_query']['enabled']: + formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + self.callback(formattedQueryInfo + '\n') return @@ -93,13 +94,13 @@ def run(self): 'replace').replace('\r', '') if 'show_query' in self.options: - queryPlacement = self.options['show_query'].get('placement', 'disabled') - if isinstance(queryPlacement, str) and queryPlacement != 'disabled': + if 'enabled' in self.options['show_query'] and self.options['show_query']['enabled']: formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + queryPlacement = self.options['show_query'].get('placement', 'top') if queryPlacement == 'top': resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) elif queryPlacement == 'bottom': - resultString = "{0}\n{1}".format(resultString, formattedQueryInfo) + resultString = "{0}{1}\n".format(resultString, formattedQueryInfo) self.callback(resultString) From 453569f6015828209188f64c693be69571320fe5 Mon Sep 17 00:00:00 2001 From: Coteh Date: Sat, 17 Jun 2017 18:10:44 -0400 Subject: [PATCH 4/8] Change show_query default enabled setting back to false --- SQLTools.sublime-settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index 03d811c..c12b47e 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -38,7 +38,7 @@ "limit": 50 }, "show_query": { - "enabled": true, + "enabled": false, "placement": "top" }, "format" : { From 3a5a00f821544ef9274ed4d4bfef657468c74834 Mon Sep 17 00:00:00 2001 From: Coteh Date: Mon, 19 Jun 2017 22:14:55 -0400 Subject: [PATCH 5/8] Use simple bool/string value for show_query, for backwards compatibility --- SQLTools.sublime-settings | 11 +++++++---- SQLToolsAPI/Command.py | 28 ++++++++++++++++------------ SQLToolsAPI/Connection.py | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index c12b47e..753807f 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -20,6 +20,13 @@ * 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: @@ -37,10 +44,6 @@ "show_records": { "limit": 50 }, - "show_query": { - "enabled": false, - "placement": "top" - }, "format" : { "keyword_case" : "upper", "identifier_case" : null, diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index 0283da9..e1589fd 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 @@ -70,10 +76,9 @@ def run(self): if self.process: self.process.terminate() - if 'show_query' in self.options: - if 'enabled' in self.options['show_query'] and self.options['show_query']['enabled']: - formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - self.callback(formattedQueryInfo + '\n') + if self.options['show_query']: + formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + self.callback(formattedQueryInfo + '\n') return @@ -93,14 +98,13 @@ def run(self): resultString += errors.decode(self.encoding, 'replace').replace('\r', '') - if 'show_query' in self.options: - if 'enabled' in self.options['show_query'] and self.options['show_query']['enabled']: - formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) - queryPlacement = self.options['show_query'].get('placement', 'top') - if queryPlacement == 'top': - resultString = "{0}\n{1}".format(formattedQueryInfo, resultString) - elif queryPlacement == 'bottom': - resultString = "{0}{1}\n".format(resultString, formattedQueryInfo) + if self.options['show_query']: + formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) + 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 2e83183..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', {}) + self.show_query = settings.get('show_query', False) self.rowsLimit = settings.get('show_records', {}).get('limit', 50) self.cli = settings.get('cli')[options['type']] From e76e426bce19eab2c7624f0d782cebf702806776 Mon Sep 17 00:00:00 2001 From: Coteh Date: Mon, 19 Jun 2017 22:23:52 -0400 Subject: [PATCH 6/8] Tweak comment for autocompletion option to add true's default --- SQLTools.sublime-settings | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SQLTools.sublime-settings b/SQLTools.sublime-settings index 753807f..d576285 100644 --- a/SQLTools.sublime-settings +++ b/SQLTools.sublime-settings @@ -16,7 +16,8 @@ */ "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", From 4e3956408a29f0ee7664a8cbb8012bcd27bfd283 Mon Sep 17 00:00:00 2001 From: Coteh Date: Mon, 19 Jun 2017 23:24:19 -0400 Subject: [PATCH 7/8] If process was killed and there's some output, then append newline --- SQLToolsAPI/Command.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index e1589fd..ba55132 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -98,6 +98,9 @@ def run(self): resultString += errors.decode(self.encoding, 'replace').replace('\r', '') + if self.process == None and resultString != '': + resultString += '\n' + if self.options['show_query']: formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd) queryPlacement = self.options['show_query'] From 98568b6b495539efc5ad81e2b3a0592fb0ea8132 Mon Sep 17 00:00:00 2001 From: Coteh Date: Mon, 19 Jun 2017 23:34:58 -0400 Subject: [PATCH 8/8] If process was killed and stream wrote to output, then write newline --- SQLToolsAPI/Command.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SQLToolsAPI/Command.py b/SQLToolsAPI/Command.py index ba55132..8842f05 100644 --- a/SQLToolsAPI/Command.py +++ b/SQLToolsAPI/Command.py @@ -67,14 +67,20 @@ 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 self.options['show_query']: formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)