-
Notifications
You must be signed in to change notification settings - Fork 35
/
oracle_exec.py
43 lines (35 loc) · 1.97 KB
/
oracle_exec.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sublime
import re
import os.path
import oracle_lib
execmod = __import__("exec")
RE_ENTITIES = re.compile("^\\((.+?)/(0):[0-9]+\\) ([0-9]+):[0-9]+ (.+)$", re.M)
class OracleExecCommand(execmod.ExecCommand):
def run(self, dsn="", **kwargs):
if not dsn and not kwargs.get("kill", False):
# if cmd is empty, open the command_palette with the available build list
self.window.run_command("show_overlay", {"overlay": "command_palette", "text": "Build: " + kwargs.get("prefix", "")})
else:
# Find entities declaration in source
self.entities = oracle_lib.find_entities(self.window.active_view())
# Create a string for the in of sql command
if len(self.entities) == 0:
sqlfilter = "\"''\""
else:
sqlfilter = '"' + ",".join("'%s'" % entity for entity in self.entities.keys()) + '"'
(directory, filename) = os.path.split(self.window.active_view().file_name())
cmd = ["sqlplus.exe", "-s", dsn, "@", os.path.join(sublime.packages_path(), 'OracleSQL', 'RunSQL.sql'), '"'+filename+'"', sqlfilter]
super(OracleExecCommand, self).run(cmd, "^Filename: (.+)$", "^\\(.+?/([0-9]+):([0-9]+)\\) [0-9]+:[0-9]+ (.+)$", working_dir=directory, **kwargs)
def append_data(self, proc, data):
# Update the line number of output_view with the correct line number of source view
orgdata = data
posoffset = 0
for re_ent in RE_ENTITIES.finditer(orgdata):
pos = re_ent.span(2)
pos = (pos[0] + posoffset, pos[1] + posoffset)
sourceoffset = self.entities[re_ent.group(1)]
sqlerrorline = int(re_ent.group(3))
sourceline = sqlerrorline + sourceoffset
data = data[:pos[0]] + str(sourceline) + data[pos[1]:]
posoffset += len(str(sourceline)) - 1
super(OracleExecCommand, self).append_data(proc, data)