Skip to content

Commit

Permalink
Use simple bool/string value for show_query, for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Coteh committed Jun 20, 2017
1 parent 453569f commit 3a5a00f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
11 changes: 7 additions & 4 deletions SQLTools.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -37,10 +44,6 @@
"show_records": {
"limit": 50
},
"show_query": {
"enabled": false,
"placement": "top"
},
"format" : {
"keyword_case" : "upper",
"identifier_case" : null,
Expand Down
28 changes: 16 additions & 12 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 @@ -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

Expand All @@ -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)

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', {})
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 3a5a00f

Please sign in to comment.