public
Created

SublimeText 3 version for OracleSQL file oracle_exec.py (https://github.com/bizoo/OracleSQL)

  • Download Gist
oracle_exec.py
Python
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 44 45 46 47
import sublime
import re
import os.path
import os
from . import oracle_lib
from Default import exec as execmod
 
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 = self.quote("''")
else:
sqlfilter = self.quote(",".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'), self.quote(filename), sqlfilter]
 
super(OracleExecCommand, self).run(cmd, "", "^Filename: (.+)$", "^\\(.+?/([0-9]+):([0-9]+)\\) [0-9]+:[0-9]+ (.+)$", working_dir=directory, **kwargs)
 
def quote(self, str):
return '"{:s}"'.format(str)
 
def append_data(self, proc, data):
# Update the line number of output_view with the correct line number of source view
orgstr = data.decode(self.encoding)
datastr = orgstr
posoffset = 0
for re_ent in RE_ENTITIES.finditer(orgstr):
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
 
datastr = datastr[:pos[0]] + str(sourceline) + datastr[pos[1]:]
posoffset += len(str(sourceline)) - 1
 
super(OracleExecCommand, self).append_data(proc, datastr.encode(self.encoding))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.