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

Commit 51b2e24

Browse files
committed
Output in the same window. Not using temp file anymore
1 parent 51237d0 commit 51b2e24

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

SQLTools.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def checkDefaultConnection():
121121
STM.Log.debug("Invalid connection setted")
122122

123123
@staticmethod
124-
def display(content, name="SQLTools Result"):
124+
def getOutputPlace(name="SQLTools Result"):
125125
if not sublime.load_settings(STM.Const.SETTINGS_FILENAME).get('show_result_on_window'):
126126
resultContainer = STM.Window().create_output_panel(name)
127127
STM.Window().run_command("show_panel", {"panel": "output." + name})
@@ -141,10 +141,16 @@ def display(content, name="SQLTools Result"):
141141
resultContainer.settings().set("word_wrap", "false")
142142
resultContainer.set_read_only(False)
143143
resultContainer.set_syntax_file('Packages/SQL/SQL.tmLanguage')
144-
resultContainer.run_command('select_all')
145-
resultContainer.run_command('left_delete')
146-
resultContainer.run_command('append', {'characters': content})
147-
resultContainer.set_read_only(True)
144+
# resultContainer.run_command('select_all')
145+
# resultContainer.run_command('left_delete')
146+
return resultContainer
147+
148+
@staticmethod
149+
def display(content, panel=None):
150+
if not panel:
151+
panel = ST.getOutputPlace()
152+
panel.run_command('append', {'characters': content})
153+
panel.set_read_only(True)
148154

149155
@staticmethod
150156
def toBuffer(content, name="", suffix="SQLTools Saved Query"):

SQLToolsModels.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sublime, os, tempfile, threading, signal, shlex, subprocess, sys
1+
import sublime, os, threading, signal, shlex, subprocess, sys
22

33
sys.path.append(os.path.dirname(__file__))
44
if sys.version_info >= (3, 0):
@@ -259,18 +259,15 @@ def run(self):
259259
return
260260

261261
sublime.status_message(' ST: running SQL command')
262-
self.tmp = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.sql')
263-
self.tmp.write(self.query)
264-
self.tmp.close()
265-
266262
self.args = map(str, self.args)
267263
si = None
268264
if os.name == 'nt':
269265
si = subprocess.STARTUPINFO()
270266
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
271-
self.process = subprocess.Popen(self.args, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=open(self.tmp.name), env=os.environ.copy(), startupinfo=si)
272267

273-
results, errors = self.process.communicate()
268+
self.process = subprocess.Popen(self.args, stdout=subprocess.PIPE,stderr=subprocess.PIPE, stdin=subprocess.PIPE, env=os.environ.copy(), startupinfo=si)
269+
270+
results, errors = self.process.communicate(input=self.query.encode())
274271

275272
if errors:
276273
self.callback(errors.decode(self.encoding, 'replace').replace('\r', ''))
@@ -289,8 +286,6 @@ def stop(self):
289286
Log.debug("Your command is taking too long to run. Process killed")
290287
except Exception:
291288
pass
292-
if self.tmp and os.path.exists(self.tmp.name):
293-
os.unlink(self.tmp.name)
294289

295290
class Utils:
296291
@staticmethod

0 commit comments

Comments
 (0)