Skip to content

Instantly share code, notes, and snippets.

@jbjornson
Created January 30, 2014 08:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbjornson/8704419 to your computer and use it in GitHub Desktop.
Save jbjornson/8704419 to your computer and use it in GitHub Desktop.
SublimeText 3 version for OracleSQL file oracle_exec.py (https://github.com/bizoo/OracleSQL)
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment