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

Commit e3d8418

Browse files
authored
Merge pull request #116 from Coteh/dev/show_query_placement
Configure placement of show_query in non-stream output
2 parents 337ce02 + 98568b6 commit e3d8418

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

SQLTools.sublime-settings

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"show_result_on_window" : false,
99
"clear_output" : true,
1010
"safe_limit" : false,
11-
"show_query" : false,
1211
"expand_to_paragraph" : false,
1312
"use_streams" : false, // use streams for results
1413
/**
@@ -17,10 +16,18 @@
1716
*/
1817
"selectors": ["source.sql", "source.pgsql", "source.plpgsql.postgres", "source.plsql.oracle", "source.tsql"],
1918
/**
20-
* Possible values for autocompletion: "basic", "smart" or false (disable)
19+
* Possible values for autocompletion: "basic", "smart", true ("smart"),
20+
* or false (disable)
2121
* Completion keywords case is controlled by format.keyword_case (see below)
2222
*/
2323
"autocompletion": "smart",
24+
/**
25+
* Possible values for show_query: "top", "bottom", true ("top"), or false (disable)
26+
* When using regular output, this will determine where query details is displayed.
27+
* In stream output mode, any option that isn't false will print query details at
28+
* the bottom of result.
29+
*/
30+
"show_query": false,
2431
/**
2532
* If DB cli binary is not in PATH, set the full path in "cli" section.
2633
* Note: forward slashes ("/") should be used in path. Example:
@@ -35,8 +42,8 @@
3542
"firebird": "isql",
3643
"sqlite" : "sqlite3"
3744
},
38-
"show_records" : {
39-
"limit" : 50
45+
"show_records": {
46+
"limit": 50
4047
},
4148
"format" : {
4249
"keyword_case" : "upper",

SQLToolsAPI/Command.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def __init__(self, args, env, callback, query=None, encoding='utf-8',
2626
self.silenceErrors = silenceErrors
2727
self.process = None
2828

29+
if 'show_query' not in self.options:
30+
self.options['show_query'] = False
31+
elif self.options['show_query'] not in ['top', 'bottom']:
32+
self.options['show_query'] = 'top' if (isinstance(self.options['show_query'], bool)
33+
and self.options['show_query']) else False
34+
2935
def run(self):
3036
if not self.query:
3137
return
@@ -61,18 +67,24 @@ def run(self):
6167
if self.stream:
6268
self.process.stdin.write(self.query.encode())
6369
self.process.stdin.close()
70+
hasWritten = False
71+
6472
for line in self.process.stdout:
6573
self.callback(line.decode(self.encoding,
6674
'replace').replace('\r', ''))
75+
hasWritten = True
6776

6877
queryTimerEnd = time.time()
6978
# we are done with the output, terminate the process
7079
if self.process:
7180
self.process.terminate()
81+
else:
82+
if hasWritten:
83+
self.callback('\n')
7284

73-
if 'show_query' in self.options and self.options['show_query']:
85+
if self.options['show_query']:
7486
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
75-
self.callback(formattedQueryInfo)
87+
self.callback(formattedQueryInfo + '\n')
7688

7789
return
7890

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

95-
if 'show_query' in self.options and self.options['show_query']:
107+
if self.process == None and resultString != '':
108+
resultString += '\n'
109+
110+
if self.options['show_query']:
96111
formattedQueryInfo = self._formatShowQuery(self.query, queryTimerStart, queryTimerEnd)
97-
resultString = "{0}\n{1}".format(formattedQueryInfo, resultString)
112+
queryPlacement = self.options['show_query']
113+
if queryPlacement == 'top':
114+
resultString = "{0}\n{1}".format(formattedQueryInfo, resultString)
115+
elif queryPlacement == 'bottom':
116+
resultString = "{0}{1}\n".format(resultString, formattedQueryInfo)
98117

99118
self.callback(resultString)
100119

SQLToolsAPI/Connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, name, options, settings=None, commandClass='ThreadCommand'):
5555
self.service = options.get('service', None)
5656

5757
self.safe_limit = settings.get('safe_limit', None)
58-
self.show_query = settings.get('show_query', None)
58+
self.show_query = settings.get('show_query', False)
5959
self.rowsLimit = settings.get('show_records', {}).get('limit', 50)
6060
self.cli = settings.get('cli')[options['type']]
6161

0 commit comments

Comments
 (0)