提交 5024b052 编写于 作者: C Cosmin Popescu

sql workbench 4.0.1

上级 1868a2d9
......@@ -190,7 +190,7 @@ function! s:process_result_1(result, shortcut, title)
endfunction
" Change a tab{{{2
function! s:change_tab(command, shortcut, title)
function! sw#dbexplorer#change_tab(command, shortcut, title)
let result = sw#server#dbexplorer(a:command)
call s:process_result_1(result, a:shortcut, a:title)
endfunction
......@@ -277,7 +277,7 @@ endfunction
" Adds a shortcut from a tab to the current buffer{{{2
function! s:add_shortcut(tab)
execute "nnoremap <buffer> <silent> " . a:tab['shortcut'] . " :call <SID>change_tab(\"" . substitute(a:tab['command'], '"', "\\\\\"", 'g') . "\", \"" . a:tab['shortcut'] . "\", \"" . a:tab['title'] . "\")<cr>"
execute "nnoremap <buffer> <silent> " . a:tab['shortcut'] . " :call sw#dbexplorer#change_tab(\"" . substitute(a:tab['command'], '"', "\\\\\"", 'g') . "\", \"" . a:tab['shortcut'] . "\", \"" . a:tab['title'] . "\")<cr>"
return 1
endfunction
......@@ -428,7 +428,7 @@ function! sw#dbexplorer#restore_from_session(...)
call sw#session#init_section()
call sw#session#check()
call s:set_special_buffer(b:profile, connection)
call s:change_tab(b:first_tab['command'], b:first_tab['shortcut'], b:first_tab['title'])
call sw#dbexplorer#change_tab(b:first_tab['command'], b:first_tab['shortcut'], b:first_tab['title'])
endfunction
function! s:set_highlights()
......@@ -484,7 +484,7 @@ function! sw#dbexplorer#show_panel(profile, port, ...)
vertical resize 60
""call s:set_objects_buffer()
call s:iterate('s:get_first_tab')
call s:change_tab(b:first_tab['command'], b:first_tab['shortcut'], b:first_tab['title'])
call sw#dbexplorer#change_tab(b:first_tab['command'], b:first_tab['shortcut'], b:first_tab['title'])
if s_below
set splitbelow
endif
......
......@@ -163,14 +163,8 @@ function! sw#server#dbexplorer(sql)
endif
let lines = split(s, "\n")
let result = []
let rec = 1
let rec = 0
for line in lines
if line =~ '\v\c^[ \s\t\r]*$'
let rec = 0
if (len(result) > 0)
call add(result, '')
endif
endif
if rec && !(line =~ '\v^[\=]+$')
call add(result, line)
endif
......
......@@ -304,9 +304,8 @@ function! s:display_as_form(row_limits)
endfor
setlocal modifiable
normal ggdG
for line in lines
put =line
endfor
call writefile(lines, g:sw_tmp . "/row")
execute "read " . g:sw_tmp . "/row"
normal ggdd
setlocal modifiable
endfunction
......@@ -381,9 +380,8 @@ function! s:get_row_limits()
endfunction
function! s:display_resultsets()
for line in b:resultsets
put =line
endfor
call writefile(b:resultsets, g:sw_tmp . "/results")
execute "read " . g:sw_tmp . "/results"
call sw#session#set_buffer_variable('state', 'resultsets')
endfunction
......@@ -454,12 +452,7 @@ function! s:process_result(result)
normal ggdd
setlocal nomodifiable
if !g:sw_switch_to_results_tab
let b = sw#find_buffer_by_unique_id(b:r_unique_id)
if b != ''
call sw#goto_window(b)
else
wincmd t
endif
wincmd t
endif
echomsg "Command completed"
endfunction
......
......@@ -31,6 +31,6 @@ let g:SW_Tabs[':postgresql'] = [objects, procedures, triggers, schemas, row_coun
" Oracle specific panel
let oracle_dblinks = {'title': 'DB Links', 'shortcut': 'L', 'command': 'select db_link, username, created from user_db_links;', 'panels': [{'title': 'Show the host', 'shortcut': 'H', 'command': "select host from user_db_links where db_link = '%object%'"}]}
let oracle_jobs = {'title': 'User Jobs', 'shortcut': 'J', 'command': 'select job_name, job_creator, start_date, repeat_interval from user_scheduler_jobs', 'panels': [{'title': 'Job source', 'shortcut': 'S', 'command': "select job_action from user_scheduler_jobs where job_name = '%object%'", 'hide_header': 1, 'filetype': 'sql'}]}
let oracle_packages = {'title': 'Packages', 'shortcut': 'K', 'command': "select OBJECT_NAME, OBJECT_TYPE, STATUS from user_objects where object_type in ('PACKAGE');", 'panels': [{'title': 'SQL Source', 'shortcut': 'S', 'command': "wbprocsource %object%", 'filetype': 'sql'}, {'title': 'Compile', 'shortcut': 'E', 'command': 'alter package %object% compile package'}]}
let oracle_packages = {'title': 'Packages', 'shortcut': 'K', 'command': "select OBJECT_NAME, OBJECT_TYPE, STATUS from user_objects where object_type in ('PACKAGE');", 'panels': [{'title': 'SQL Source', 'shortcut': 'S', 'command': "wbprocsource %object%", 'filetype': 'sql'}, {'title': 'Compile', 'shortcut': 'E', 'command': 'alter package %object% compile package'}, {'title': 'Status', 'shortcut': 'v', 'command': "select object_name, OBJECT_TYPE, STATUS from user_objects where object_name = '%object%'"}]}
let oracle_schemas = {'title': 'Show schemas', 'shortcut': 'M', 'command': 'wblistschemas;', 'panels': [{'title': 'Select schema', 'shortcut': 'H', 'command': "alter session set current_schema = %object%;"}]}
let g:SW_Tabs[':oracle'] = [oracle_dblinks, oracle_jobs, oracle_packages, oracle_schemas]
......@@ -20,6 +20,9 @@ import subprocess
class SQLWorkbench(object):
profile = None
port = 5000
log = None
log_f = None
log_sem = thread.allocate_lock()
results = {}
debug = 0
colwidth = 120
......@@ -162,6 +165,7 @@ class SQLWorkbench(object):
if self.debug:
print "OPENING DBE CONNECTION: " + cmd
#end if
self.do_log("OPENING DBE CONNECTION: " + cmd, "spawnDbeConnection")
while 1:
with self.lock:
if self.quit: break
......@@ -180,6 +184,7 @@ class SQLWorkbench(object):
profile += char
#end if
#end while
self.do_log(profile, "dbExplorer")
if not (profile in self.dbe_connections):
thread.start_new_thread(self.spawnDbeConnection, (profile, conn))
while (not profile in self.dbe_connections):
......@@ -189,20 +194,24 @@ class SQLWorkbench(object):
if n - len(profile) - 4 > 0:
pipe = self.dbe_connections[profile]
data = conn.recv(4096)
self.do_log(data, "dbExplorer")
if (data):
data += "\nwbsetconfig send_to_vim=1;\n"
if self.debug:
print "SEND TO SERVER: " + data
#end if
pipe.stdin.write(data)
self.do_log("SEND TO SERVER: " + data, "dbExplorer#stdin.write")
result = self.receiverDbe(pipe)
conn.send(self.prepareResult(result))
self.do_log(self.prepareResult(result), "dbExplorer#send")
#end if
#end if
#end def dbExplorer
def searchResult(self, conn, n):
data = self.readData(conn, n)
self.do_log(data, "searchResult")
p = self.getCaller(data)
if p == None:
return
......@@ -211,6 +220,7 @@ class SQLWorkbench(object):
key = p.group(1) + "#" + p.group(2)
if key in self.results:
conn.send(self.prepareResult(self.results[key]))
self.do_log(self.prepareResult(self.results[key]), "searchResult#send")
del self.results[key]
#end if
#end def searchResult
......@@ -227,6 +237,7 @@ class SQLWorkbench(object):
i += len(data)
#end while
self.do_log(result, "readData")
return result
#end def readData
......@@ -245,6 +256,7 @@ class SQLWorkbench(object):
if self.debug:
print "SENT TO SERVER: " + line
#end if
self.do_log("SENT TO SERVER: " + line, "receiveData")
if line != '':
pipe.stdin.write(line + "\n")
#end if
......@@ -255,10 +267,12 @@ class SQLWorkbench(object):
if self.debug:
print "SENT TO SERVER: wbsetconfig send_to_vim=1;"
#end if
self.do_log("SENT TO SERVER: wbsetconfig send_to_vim=1;", "receiveData#stdin.write")
if self.identifier == None:
with self.executing:
data = self.prepareResult(self.buff)
conn.send(data)
self.do_log(data, "receiveData#send")
#end with
else:
with self.executing:
......@@ -274,6 +288,16 @@ class SQLWorkbench(object):
#end with
#end def receiveData
def do_log(self, what, who):
if self.log_f != None:
with self.log_sem:
self.log_f.write(who + ">>>>>>>>>>>>>>>\n")
self.log_f.write(what)
self.log_f.write("\n")
#end whith
#end if
#end def do_log
def newConnection(self, conn, pipe):
n = ''
c = ''
......@@ -283,12 +307,14 @@ class SQLWorkbench(object):
n += c
#end if
#end while
self.do_log(n, "newConnection")
if (n != ''):
n = int(n)
else:
n = 0
#end if
data = conn.recv(3)
self.do_log(data, "newConnection")
if data == 'COM':
self.receiveData(conn, pipe, n - 3)
elif data == 'RES':
......@@ -344,9 +370,11 @@ class SQLWorkbench(object):
buff = ''
while re.search(self.resultset_end_pattern, line) == None:
line = pipe.stdout.readline()
self.do_log(line, "receiverDbe#stdout.readline")
buff += line
if self.debug:
sys.stdout.write(line)
self.do_log(line, "receiverDbe#stdout.write")
sys.stdout.flush()
#end if
#end while
......@@ -410,6 +438,9 @@ class SQLWorkbench(object):
sys.exit(1)
#end if
if (self.log != None):
self.log_f = open(self.log, "w")
#end if
cmd = "%s -feedback=true -showProgress=false" % (self.cmd)
if (self.profile != None):
cmd += " -profile=%s" % profile
......@@ -465,6 +496,7 @@ if __name__ == "__main__":
parser.add_option("-c", "--command", help="The command to launch the sql workbench console", dest="cmd", default=None)
parser.add_option("-v", "--vim", help="The path to the vim executable", dest="vim", default='vim')
parser.add_option("-o", "--port", help="The port on which to send the commands", dest="port", default='5000', type = "int")
parser.add_option("-l", "--log", help = "Log file path", default = None, dest = "log")
parser.add_option("-d", "--debug", help="The debuging mode", dest="debug", default='0')
(options,args) = parser.parse_args(sys.argv[1:], obj)
obj.args = args
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册