Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ITKEY_
Vim Sql Workbench
提交
0a30f28f
V
Vim Sql Workbench
项目概览
ITKEY_
/
Vim Sql Workbench
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vim Sql Workbench
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
0a30f28f
编写于
8月 15, 2015
作者:
C
Cosmin Popescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
version 3.3
上级
63b8da5a
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
1422 addition
and
1179 deletion
+1422
-1179
README.md
README.md
+52
-81
autoload/sw/autocomplete.vim
autoload/sw/autocomplete.vim
+12
-0
autoload/sw/cmdline.vim
autoload/sw/cmdline.vim
+63
-0
autoload/sw/server.vim
autoload/sw/server.vim
+7
-7
autoload/sw/sqlwindow.vim
autoload/sw/sqlwindow.vim
+9
-3
autoload/sw/variables.vim
autoload/sw/variables.vim
+11
-25
doc/sw.txt
doc/sw.txt
+0
-968
doc/tags
doc/tags
+58
-16
doc/vim-sql-workbench.txt
doc/vim-sql-workbench.txt
+1089
-0
plugin/sw.vim
plugin/sw.vim
+6
-6
resources/shortcuts_sql_results.vim
resources/shortcuts_sql_results.vim
+1
-1
resources/sqlwbserver
resources/sqlwbserver
+114
-72
未找到文件。
README.md
浏览文件 @
0a30f28f
...
...
@@ -26,18 +26,19 @@ CONTENTS:
2.
Connecting to a DBMS
3.
The database explorer
4.
The SQL Buffer
5.
Searching
6.
Exporting
7.
Sessions
8.
Variables
9.
Commands
10.
Settings
11.
Screen shots
5.
SQL commands
6.
Searching
7.
Exporting
8.
Sessions
9.
Variables
10.
Commands
11.
Settings
12.
Screen shots
Requirements
========================================
*
`Vim`
compiled with
`python`
support
ed
*
`Vim`
compiled with
`python`
support
*
`Python`
installed on the machine
*
`SQL Workbench/J`
installed on the machine
*
Optional:
[
`vim dispatch`
](
https://github.com/tpope/vim-dispatch
)
plugin
...
...
@@ -478,6 +479,29 @@ shortcut.
Alternatively, you can execute the
`WbDisplay`
command. See
[
here
](
http://www.sql-workbench.net/manual/console-mode.html
)
for more detail.
SQL commands
========================================
You can send a sql query to the DBMS from the vim command line using the
command
`SWSqlExecuteNow`
. The first parameter is the port of the server on
which to execute, and the next parameters are the sql query. Please note that
by default no results will be shown. If you want to see all that happened on
the server side, use the
`SWSqlExecuteNowLastResult`
command. This will show
you what happened with the last command sent from the vim command line.
This is useful if you want to put vim shortcuts for simple things. Like, for
example, you could have in your
`vimrc`
:
```
nnoremap <leader>t :SWSqlExecuteNow 5000 wbdisplay tab;<cr>
```
Then pressing
`<leader>t`
in normal mode, would set the display to tab for the
instance listening on port 5000.
*Note*
: This command will not be recorded in
`g:sw_last_sql_query`
. The
delimiter is the
`;`
.
Searching
========================================
...
...
@@ -600,50 +624,11 @@ By default, in `SQL Workbench`, the variables are enclosed between `$[` and
`]`
.
[
These can be
changed
](
http://www.sql-workbench.net/manual/using-variables.html#access-variable
)
.
By default, in
`VIM SQL Workbench`
the variable substitution is on. This
means, that when you send a query to the database, the plugin will search for
anything enclosed between the parameter prefix and suffix. Once a match is
found, if a value is defined with
`SWVarSet`
then the match is replaced with
this value. Please note that exactly the literal is replaced. No quotes are
added and no escaping is executed. If you want quotes, you need to add then in
the value.
If the variable is not defined using
`SWVarSet`
the plugin will ask for a
value. If you don't want this string to be replaced when the query is sent to
the database, then you can use an empty string as a value. If you want to send
to the database an empty string, then you have to set the value
`''`
.
If you set already a value for a variable, you can always change it by
executing again
`SWVarSet`
.
A variable can be unset using
`SWVarUnset`
.
If you don't want the plugin doing parameters substitution for a given buffer,
you can call
`SWVarDisable`
. You can always re-enable the parameter
substitution by calling
`SWVarEnable`
.
Example:
In your
`workbench.settings`
file:
```
workbench.sql.parameter.prefix=:
workbench.sql.parameter.suffix=
```
The sql query:
`select * from table where d = '2015-01-01 00:00:00'`
.
When launching this query, you will be asked for the value of the
`00`
variable. You can just press
`enter`
and the
`:00`
will not be replace.
The sql query:
`select * from table where name = :name`
.
When launching this query, you will be asked for the value of the
`name`
variable. If you enter
`'Cosmin Popescu'`
, the query sent to the DBMS will be
`select * from table where name = 'Cosmin Popescu'`
. Please note that if you
just enter
`Cosmin Popescu`
(notice the missing quotes), the query sent to the
DBMS will be
`select * from table where name = Cosmin Popescu`
which will
obviously return an error.
You can use
`WbVarSet`
and
`WbVarUnset`
in a sql buffer. If you want the
system to ask for a value, then you can use the
`$[?`
form of a parameter.
Please note that in
`VIM Sql Workbench`
there is no difference between
`?`
and
`&`
, since there is no way to get a list of vars in
`vimscript`
from
`SQL
Workbench/J`
Commands
========================================
...
...
@@ -719,6 +704,19 @@ call this command, the plugin will return it's source code, if the selected
word is an object in the database. Otherwise, it will return an empty result
set.
## SWSqlExecuteNow
*Parameters*
:
*
port: the port on which to execute the command
*
sql: The query to be sent to the DBMS
Executes a query against the DBMS on the indicated port.
## SWSqlExecuteNowLastResult
Shows the communication with the server for the last
`SWSqlExecuteNow`
command.
## SWSqlExport
This command will export the last executed statement. Of course, if your last
...
...
@@ -823,35 +821,6 @@ This command will restore the properties of the sql buffer following a vim
session restore. This includes the autocomplete intellisense of the buffer, if
this was active when
`mksession`
was executed.
## SWVarSet
*Parameters*
:
*
the variable name: the name of the variable to be set
*
the value: the value that you want to set for this variable
If you want to set a string enclosed between the
`SQL Workbench/J`
parameters
suffix and prefix without being substituted, then set it to an empty string.
If you want to replace a parameter with an empty string, set the value of the
variable to
`''`
.
## SWVarUnset
Unsets a variable
## SWVarDisable
Disables the replacement of the parameters in the queries sent to the DBMS.
## SWVarEnable
Enables the replacement of the parameters in the queries sent to the DBMS
(enabled by default).
## SWVarList
Lists the parameters values
## SWServerStart
*Parameters*
:
...
...
@@ -946,6 +915,8 @@ and
in a db explorer will switch between the bottom panels
*
`g:sw_autocomplete_cache_dir`
: the location where the autocomplete
information is saved. You'll need to set it on Windows to work.
*
`g:sw_switch_to_results_tab`
: If true, then switch to the results buffer
after executting a query
## Database explorer settings
...
...
autoload/sw/autocomplete.vim
浏览文件 @
0a30f28f
...
...
@@ -470,6 +470,16 @@ function! sw#autocomplete#perform(findstart, base)
endfor
return
sort
(
result
,
"sw#autocomplete#sort"
)
elseif
b:autocomplete_type
==
'wbconnect'
let
profiles
=
sw
#parse_profile_xml
()
let
result
=
[]
for
profile
in
profiles
if
profile
=~
'^'
.
a:base
call
add
(
result
,
profile
)
endif
endfor
return
result
endif
return
[]
...
...
@@ -496,6 +506,8 @@ function! s:get_sql_type(sql)
return
'proc'
elseif
sql
=~
'\v\c[\s \t\r]*delete'
return
'delete'
elseif
sql
=~
'\v\c^[\s \t\r]*wbconnect'
return
'wbconnect'
endif
return
'other'
...
...
autoload/sw/cmdline.vim
0 → 100644
浏览文件 @
0a30f28f
"============================================================================"
"
" Vim SQL Workbench/J Implementation
"
" Copyright (c) Cosmin Popescu
"
" Author: Cosmin Popescu <cosminadrianpopescu at gmail dot com>
" Version: 1.00 (2015-01-08)
" Requires: Vim 7
" License: GPL
"
" Description:
"
" Provides SQL database access to any DBMS supported by SQL Workbench/J. The
" only dependency is SQL Workbench/J. Also includes powefull intellisense
" autocomplete based on the current selected database
"
"============================================================================"
let
s:last_result
=
''
function
!
sw
#cmdline#
execute
(
wait_result
,
port
,
...)
let
sql
=
''
let
i
=
1
while
i
<=
a:0
execute
"let sql .= ' ' . a:"
.
i
let
i
=
i
+
1
endwhile
let
b:on_async_result
=
'sw#sqlwindow#check_results'
let
b:delimiter
=
';'
let
result
=
sw
#server#execute_sql
(
sql
,
a:wait_result
,
a:port
)
if
result
!=
''
call
s:process_results
(
result
)
endif
endfunction
function
!
sw
#cmdline#got_result
()
let
s:last_result
=
sw
#server#fetch_result
()
if
results
!=
''
call
s:process_results
(
result
)
endif
endfunction
function
!
s:process_results
(
result
)
let
s:last_result
=
a:result
endfunction
function
!
sw
#cmdline#show_last_result
()
let
s_below
=
&
splitbelow
set
splitbelow
execute
"split __TMP__-"
.
sw
#generate_unique_id
()
call
sw
#set_special_buffer
()
setlocal
modifiable
if
!
s_below
set
nosplitbelow
endif
let
lines
=
split
(
s:last_result
,
"\n"
)
for
line
in
lines
put
=
line
endfor
setlocal
nomodifiable
endfunction
autoload/sw/server.vim
浏览文件 @
0a30f28f
...
...
@@ -94,19 +94,19 @@ import vim
import
socket
import
re
identifier
=
vim
.
eval
(
'v:servername'
)
+
"#"
+
vim
.
eval
(
'uid'
)
cmd
=
vim
.
eval
(
'a:cmd'
)
+
"\n"
cmd
=
vim
.
eval
(
'a:cmd'
)
port
=
int
(
vim
.
eval
(
'port'
))
type
=
vim
.
eval
(
'a:type'
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
'127.0.0.1'
,
port
))
s
.
sendall
(
type
)
packet
=
''
packet
+=
type
if
vim
.
eval
(
'a:wait_result'
)
==
'0'
:
s
.
sendall
(
"!#identifier = "
+
identifier
+
"\n"
)
#end
if
s
.
sendall
(
cmd
)
if
vim
.
eval
(
'a:wait_result'
)
==
'0'
or
(
vim
.
eval
(
'a:wait_result'
)
==
'1'
and
type
!=
'RES'
and
type
!=
'DBE'
):
s
.
sendall
(
"!#end = 1\n"
)
packet
+=
"!#identifier = "
+
identifier
+
"\n"
#end
if
packet
+=
cmd
packet
=
str
(
len
(
packet
))
+
"#"
+
packet
s
.
sendall
(
packet
)
result
=
''
if
vim
.
eval
(
'a:wait_result'
)
==
'1'
:
while
1
:
...
...
autoload/sw/sqlwindow.vim
浏览文件 @
0a30f28f
...
...
@@ -444,10 +444,15 @@ function! s:process_result(result)
normal ggdd
setlocal
nomodifiable
let
b
=
sw
#find_buffer_by_unique_id
(
b:r_unique_id
)
if
b
!=
''
call
sw
#goto_window
(
b
)
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
endif
echomsg
"Command completed"
endfunction
function
!
sw
#sqlwindow#execute_sql
(
wait_result
,
sql
)
...
...
@@ -465,6 +470,7 @@ function! sw#sqlwindow#execute_sql(wait_result, sql)
let
_sql
=
w
:
auto_added1
.
'wbvardef '
.
var
.
' = '
.
value
.
"\n"
.
b:delimiter
.
"\n"
.
w
:
auto_added2
.
_sql
endif
endfor
let
_sql
=
substitute
(
_sql
,
g:parameters_pattern
,
g:sw_p_prefix
.
'\1'
.
g:sw_p_suffix
,
'g'
)
endif
endif
let
b:on_async_result
=
'sw#sqlwindow#check_results'
...
...
autoload/sw/variables.vim
浏览文件 @
0a30f28f
...
...
@@ -36,6 +36,11 @@ function! s:set_delimiters()
if
!
exists
(
'g:sw_p_suffix'
)
let
g:sw_p_suffix
=
'\]'
endif
let
g:parameters_pattern
=
g:sw_p_prefix
.
'[?&]\([a-zA-Z_].\{\-\}\)'
.
g:sw_p_suffix
if
g:sw_p_suffix
==
''
let
g:parameters_pattern
=
g:parameters_pattern
.
'\>'
endif
endif
endfunction
...
...
@@ -87,43 +92,24 @@ endfunction
function
!
sw
#variables#
get
(
key
)
call
s:init_vars
()
if
has_key
(
b:variables
,
a:key
)
return
b:variables
[
a:key
]
endif
let
value
=
input
(
'Please input the value for '
.
a:key
.
': '
)
call
sw
#variables#
set
(
a:key
,
value
)
return
value
endfunction
function
!
sw
#variables#enable
()
call
sw
#session#unset_buffer_variable
(
'no_variables'
)
endfunction
function
!
sw
#variables#disable
()
call
sw
#session#set_buffer_variable
(
'no_variables'
,
1
)
endfunction
function
!
sw
#variables#extract
(
sql
)
call
s:set_delimiters
()
let
pattern
=
g:sw_p_prefix
.
'\([a-zA-Z_].\{\-\}\)'
.
g:sw_p_suffix
if
g:sw_p_suffix
==
''
let
pattern
=
pattern
.
'\>'
endif
let
result
=
[]
let
n
=
0
let
i
=
match
(
a:sql
,
pattern
,
n
)
let
i
=
match
(
a:sql
,
g:parameters_
pattern
,
n
)
while
i
!=
-1
let
l
=
matchlist
(
a:sql
,
pattern
,
n
)
let
s
=
substitute
(
l
[
0
],
'^'
.
g:sw_p_prefix
,
''
,
'g'
)
if
g:sw_p_suffix
!=
''
let
s
=
substitute
(
s
,
g:sw_p_suffix
.
'$'
,
''
,
'g'
)
endif
let
l
=
matchlist
(
a:sql
,
g:parameters_pattern
,
n
)
let
s
=
substitute
(
l
[
0
],
'^'
.
g:sw_p_prefix
.
'?'
,
''
,
'g'
)
let
n
=
i
+
strlen
(
l
[
0
])
+
1
if
index
(
result
,
s
)
==
-1
call
add
(
result
,
s
)
if
index
(
result
,
l
[
1
]
)
==
-1
call
add
(
result
,
l
[
1
]
)
endif
let
i
=
match
(
a:sql
,
pattern
,
n
)
let
i
=
match
(
a:sql
,
g:parameters_
pattern
,
n
)
endwhile
return
result
endfunction
doc/sw.txt
已删除
100644 → 0
浏览文件 @
63b8da5a
此差异已折叠。
点击以展开。
doc/tags
浏览文件 @
0a30f28f
Example: sw.txt /*Example:*
Example: sw.txt /*Example:*
Features: sw.txt /*Features:*
NOTE: sw.txt /*NOTE:*
sw sw.txt /*sw*
sw-commands sw.txt /*sw-commands*
sw-dbexplorer sw.txt /*sw-dbexplorer*
sw-dbms-connect sw.txt /*sw-dbms-connect*
sw-exporting sw.txt /*sw-exporting*
sw-requirements sw.txt /*sw-requirements*
sw-searching sw.txt /*sw-searching*
sw-sessions sw.txt /*sw-sessions*
sw-settings sw.txt /*sw-settings*
sw-sql-buffer sw.txt /*sw-sql-buffer*
sw-variables sw.txt /*sw-variables*
vim-sql-workbench sw.txt /*vim-sql-workbench*
sql-workbench vim-sql-workbench.txt /*sql-workbench*
sql-workbench-changing-result-sets-display-mode vim-sql-workbench.txt /*sql-workbench-changing-result-sets-display-mode*
sql-workbench-commands vim-sql-workbench.txt /*sql-workbench-commands*
sql-workbench-connecting-to-dbms vim-sql-workbench.txt /*sql-workbench-connecting-to-dbms*
sql-workbench-connecting-vim-buffer vim-sql-workbench.txt /*sql-workbench-connecting-vim-buffer*
sql-workbench-creating-new-database-explorer-from-scratch vim-sql-workbench.txt /*sql-workbench-creating-new-database-explorer-from-scratch*
sql-workbench-database-explorer vim-sql-workbench.txt /*sql-workbench-database-explorer*
sql-workbench-database-explorer-settings vim-sql-workbench.txt /*sql-workbench-database-explorer-settings*
sql-workbench-execute-all-statements vim-sql-workbench.txt /*sql-workbench-execute-all-statements*
sql-workbench-execute-current-statement vim-sql-workbench.txt /*sql-workbench-execute-current-statement*
sql-workbench-execute-selected-statement vim-sql-workbench.txt /*sql-workbench-execute-selected-statement*
sql-workbench-exporting vim-sql-workbench.txt /*sql-workbench-exporting*
sql-workbench-extending-default-database-explorer vim-sql-workbench.txt /*sql-workbench-extending-default-database-explorer*
sql-workbench-general-settings vim-sql-workbench.txt /*sql-workbench-general-settings*
sql-workbench-get-an-object-definition vim-sql-workbench.txt /*sql-workbench-get-an-object-definition*
sql-workbench-intellisense vim-sql-workbench.txt /*sql-workbench-intellisense*
sql-workbench-introduction vim-sql-workbench.txt /*sql-workbench-introduction*
sql-workbench-maximum-number-of-rows. vim-sql-workbench.txt /*sql-workbench-maximum-number-of-rows.*
sql-workbench-references vim-sql-workbench.txt /*sql-workbench-references*
sql-workbench-requirements vim-sql-workbench.txt /*sql-workbench-requirements*
sql-workbench-screen-shots vim-sql-workbench.txt /*sql-workbench-screen-shots*
sql-workbench-search-data-in-tables-settings vim-sql-workbench.txt /*sql-workbench-search-data-in-tables-settings*
sql-workbench-search-object-source-settings vim-sql-workbench.txt /*sql-workbench-search-object-source-settings*
sql-workbench-searching vim-sql-workbench.txt /*sql-workbench-searching*
sql-workbench-searching-for-data-inside-tables vim-sql-workbench.txt /*sql-workbench-searching-for-data-inside-tables*
sql-workbench-searching-in-objects-source-code vim-sql-workbench.txt /*sql-workbench-searching-in-objects-source-code*
sql-workbench-sessions vim-sql-workbench.txt /*sql-workbench-sessions*
sql-workbench-settings vim-sql-workbench.txt /*sql-workbench-settings*
sql-workbench-sql-buffer vim-sql-workbench.txt /*sql-workbench-sql-buffer*
sql-workbench-sql-buffer-settings vim-sql-workbench.txt /*sql-workbench-sql-buffer-settings*
sql-workbench-sql-commands vim-sql-workbench.txt /*sql-workbench-sql-commands*
sql-workbench-starting-server-from-command-line vim-sql-workbench.txt /*sql-workbench-starting-server-from-command-line*
sql-workbench-starting-server-from-vim vim-sql-workbench.txt /*sql-workbench-starting-server-from-vim*
sql-workbench-swdbexplorer vim-sql-workbench.txt /*sql-workbench-swdbexplorer*
sql-workbench-swdbexplorerclose vim-sql-workbench.txt /*sql-workbench-swdbexplorerclose*
sql-workbench-swdbexplorerreconnect vim-sql-workbench.txt /*sql-workbench-swdbexplorerreconnect*
sql-workbench-swdbexplorerrestore vim-sql-workbench.txt /*sql-workbench-swdbexplorerrestore*
sql-workbench-swsearchdata vim-sql-workbench.txt /*sql-workbench-swsearchdata*
sql-workbench-swsearchdataadvanced vim-sql-workbench.txt /*sql-workbench-swsearchdataadvanced*
sql-workbench-swsearchdatadefaults vim-sql-workbench.txt /*sql-workbench-swsearchdatadefaults*
sql-workbench-swsearchobject vim-sql-workbench.txt /*sql-workbench-swsearchobject*
sql-workbench-swsearchobjectadvanced vim-sql-workbench.txt /*sql-workbench-swsearchobjectadvanced*
sql-workbench-swsearchobjectdefaults vim-sql-workbench.txt /*sql-workbench-swsearchobjectdefaults*
sql-workbench-swserverstart vim-sql-workbench.txt /*sql-workbench-swserverstart*
sql-workbench-swserverstop vim-sql-workbench.txt /*sql-workbench-swserverstop*
sql-workbench-swsqlautocomplete vim-sql-workbench.txt /*sql-workbench-swsqlautocomplete*
sql-workbench-swsqlbufferrestore vim-sql-workbench.txt /*sql-workbench-swsqlbufferrestore*
sql-workbench-swsqlconnecttoserver vim-sql-workbench.txt /*sql-workbench-swsqlconnecttoserver*
sql-workbench-swsqlexecuteall vim-sql-workbench.txt /*sql-workbench-swsqlexecuteall*
sql-workbench-swsqlexecutecurrent vim-sql-workbench.txt /*sql-workbench-swsqlexecutecurrent*
sql-workbench-swsqlexecutenow vim-sql-workbench.txt /*sql-workbench-swsqlexecutenow*
sql-workbench-swsqlexecutenowlastresult vim-sql-workbench.txt /*sql-workbench-swsqlexecutenowlastresult*
sql-workbench-swsqlexecuteselected vim-sql-workbench.txt /*sql-workbench-swsqlexecuteselected*
sql-workbench-swsqlexport vim-sql-workbench.txt /*sql-workbench-swsqlexport*
sql-workbench-swsqlobjectinfo vim-sql-workbench.txt /*sql-workbench-swsqlobjectinfo*
sql-workbench-swsqlobjectsource vim-sql-workbench.txt /*sql-workbench-swsqlobjectsource*
sql-workbench-swsqltogglemessages vim-sql-workbench.txt /*sql-workbench-swsqltogglemessages*
sql-workbench-variables vim-sql-workbench.txt /*sql-workbench-variables*
doc/vim-sql-workbench.txt
0 → 100644
浏览文件 @
0a30f28f
此差异已折叠。
点击以展开。
plugin/sw.vim
浏览文件 @
0a30f28f
...
...
@@ -81,6 +81,10 @@ if !exists('g:sw_sqlopen_command')
let
g:sw_sqlopen_command
=
'e'
endif
if
!
exists
(
'g:sw_switch_to_results_tab'
)
let
g:sw_switch_to_results_tab
=
0
endif
if
(!
exists
(
'g:sw_default_right_panel_type'
))
let
g:sw_default_right_panel_type
=
'txt'
endif
...
...
@@ -166,6 +170,8 @@ command! SWSqlToggleFormDisplay call sw#sqlwindow#toggle_display()
command
!
SWSqlObjectInfo
call
sw
#sqlwindow#get_object_info
()
command
!
SWSqlObjectSource
call
sw
#sqlwindow#get_object_source
()
command
!
SWSqlExport
call
sw
#sqlwindow#export_last
()
command
!
-
bang
-
nargs
=+
SWSqlExecuteNow
call
sw
#cmdline#
execute
(<
bang
>
1
,
<
f
-
args
>)
command
!
-
nargs
=
0
SWSqlExecuteNowLastResult
call
sw
#cmdline#show_last_result
()
command
!
-
bang
-
nargs
=+
SWSearchObject
call
sw
#
search
#object
(<
bang
>
1
,
<
f
-
args
>)
command
!
-
bang SWSearchObjectAdvanced
call
sw
#
search
#object
(<
bang
>
1
)
command
!
-
bang
-
nargs
=
1
SWSearchObjectDefaults
call
sw
#
search
#object_defaults
(<
bang
>
1
,
<
f
-
args
>)
...
...
@@ -177,12 +183,6 @@ command! -nargs=1 -complete=customlist,sw#autocomplete#complete_cache_name SWSql
command
!
-
nargs
=
1
-
complete
=
customlist
,
sw
#autocomplete#complete_cache_name SWSqlAutocompletePersist
call
sw
#autocomplete#persist
(<
f
-
args
>)
command
!
SWSqlBufferRestore
call
sw
#session#restore_sqlbuffer
()
command
!
-
nargs
=+
-
complete
=
customlist
,
sw
#variables#autocomplete_names SWVarSet
call
sw
#variables#
set
(<
f
-
args
>,
''
)
command
!
-
nargs
=
1
-
complete
=
customlist
,
sw
#variables#autocomplete_names SWVarUnset
call
sw
#variables#unset
(<
f
-
args
>)
command
!
-
nargs
=
0
SWVarDisable
call
sw
#variables#disable
()
command
!
-
nargs
=
0
SWVarEnable
call
sw
#variables#enable
()
command
!
-
nargs
=
0
SWVarList
call
sw
#variables#
list
()
command
!
-
nargs
=+
-
complete
=
customlist
,
sw
#autocomplete_profile SWServerStart
call
sw
#server#run
(<
f
-
args
>)
command
!
-
nargs
=
1
SWServerStop
call
sw
#server#
stop
(<
f
-
args
>)
...
...
resources/shortcuts_sql_results.vim
浏览文件 @
0a30f28f
...
...
@@ -6,5 +6,5 @@ nmap <buffer> <C-A> :SWSqlExecuteAll<cr>
nmap
<
buffer
>
<
C
-
i
>
:
SWSqlObjectInfo
<
cr
>
nmap
<
buffer
>
<
Leader
>
os
:
SWSqlObjectSource
<
cr
>
nmap
<
buffer
>
<
C
-
m
>
:
SWSqlToggleMessages
<
cr
>
nmap
<
buffer
>
<
C
-
d
>
:
SWSqlToggleFormDisplay
<
cr
>
nmap
<
buffer
>
<
Leader
>
d
:
SWSqlToggleFormDisplay
<
cr
>
resources/sqlwbserver
浏览文件 @
0a30f28f
...
...
@@ -22,9 +22,9 @@ class SQLWorkbench(object):
port
=
5000
results
=
{}
debug
=
0
threads_started
=
0
vim
=
'vim'
tmp
=
"/tmp"
clock
=
datetime
.
datetime
.
now
()
quit
=
False
lock
=
thread
.
allocate_lock
()
executing
=
thread
.
allocate_lock
()
...
...
@@ -36,6 +36,20 @@ class SQLWorkbench(object):
dbe_connections
=
{}
identifier
=
None
def
startThread
(
self
):
# if self.debug:
# print "NEW THREAD STARTED"
# #end if
self
.
threads_started
+=
1
#end def startThread
def
stopThread
(
self
):
# if self.debug:
# print "THREAD STOPPED"
# #end if
self
.
threads_started
-=
1
#end def stopThread
def
parseCustomCommand
(
self
,
command
):
if
command
[
0
]
==
'identifier'
:
self
.
identifier
=
command
[
1
]
...
...
@@ -95,7 +109,7 @@ class SQLWorkbench(object):
if
record
==
1
and
re
.
search
(
pattern1
,
line
)
==
None
and
re
.
search
(
pattern2
,
line
)
==
None
:
if
re
.
search
(
'send_to_vim'
,
line
)
==
None
:
if
i
<
len
(
lines
)
-
1
:
if
re
.
search
(
'^
\\
-
\\
-[
\\
-
\\
+
\\
s
\\
t ]+$'
,
lines
[
i
+
1
])
!=
None
or
re
.
search
(
'^----'
,
lines
[
i
+
1
])
!=
None
:
if
re
.
search
(
'^
\\
-
\\
-[
\\
-
\\
+
\\
s
\\
t ]+$'
,
lines
[
i
+
1
])
!=
None
:
to_add_results
=
True
result
+=
"--results--"
#end if
...
...
@@ -108,7 +122,9 @@ class SQLWorkbench(object):
'
\n
==============================================================================
\n
'
+
'Query returned '
+
p
.
group
(
1
)
+
' row'
+
(
's'
if
int
(
p
.
group
(
1
))
>
1
else
''
)
+
'
\n
'
)
else
:
result
=
result
+
re
.
sub
(
self
.
prompt_pattern_begin
,
''
,
line
)
+
"
\n
"
line
=
re
.
sub
(
self
.
prompt_pattern_begin
,
''
,
line
)
line
=
re
.
sub
(
"^(
\\
.
\\
.> )+"
,
''
,
line
)
result
=
result
+
line
+
"
\n
"
#end if
#end if
#end if
...
...
@@ -128,22 +144,25 @@ class SQLWorkbench(object):
#end def prepareResult
def
spawnDbeConnection
(
self
,
profile
,
conn
):
self
.
startThread
()
cmd
=
"%s -feedback=true -showProgress=false -profile=%s"
%
(
self
.
cmd
,
profile
)
pipe
=
subprocess
.
Popen
(
shlex
.
split
(
cmd
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
bufsize
=
1
)
pipe
.
stdin
.
write
(
'set maxrows = 100;
\n
'
)
conn
.
send
(
'DISCONNECT'
)
self
.
dbe_connections
[
profile
]
=
pipe
print
"OPENING DBE CONNECTION: "
+
cmd
if
self
.
debug
:
print
"OPENING DBE CONNECTION: "
+
cmd
#end if
while
1
:
with
self
.
lock
:
if
self
.
quit
:
break
#end with
time
.
sleep
(
0.3
)
#end while
pipe
.
stdin
.
write
(
"exit
\n
"
)
self
.
stopThread
(
)
#end def spawnDbeConnection
def
dbExplorer
(
self
,
conn
):
def
dbExplorer
(
self
,
conn
,
n
):
profile
=
''
char
=
''
while
char
!=
'
\n
'
:
...
...
@@ -157,11 +176,12 @@ class SQLWorkbench(object):
while
(
not
profile
in
self
.
dbe_connections
):
time
.
sleep
(
0.1
)
#end while
else
:
#end if
if
n
-
len
(
profile
)
-
4
>
0
:
pipe
=
self
.
dbe_connections
[
profile
]
data
=
conn
.
recv
(
4096
)
if
(
data
):
data
+=
"
wbvardef send_to_vim = 1
;
\n
"
data
+=
"
\n
wbvardef send_to_vim = 1;
\n
wbvardelete send_to_vim
;
\n
"
pipe
.
stdin
.
write
(
data
)
result
=
self
.
receiverDbe
(
pipe
)
conn
.
send
(
self
.
prepareResult
(
result
))
...
...
@@ -169,11 +189,8 @@ class SQLWorkbench(object):
#end if
#end def dbExplorer
def
searchResult
(
self
,
conn
):
data
=
conn
.
recv
(
4096
)
if
not
data
:
return
#end if
def
searchResult
(
self
,
conn
,
n
):
data
=
self
.
readData
(
conn
,
n
)
p
=
self
.
getCaller
(
data
)
if
p
==
None
:
return
...
...
@@ -186,42 +203,43 @@ class SQLWorkbench(object):
#end if
#end def searchResult
def
receiveData
(
self
,
conn
,
pipe
):
def
readData
(
self
,
conn
,
n
):
result
=
''
i
=
0
while
i
<
n
:
data
=
conn
.
recv
(
4096
)
if
not
data
:
break
#end if
result
+=
data
i
+=
len
(
data
)
#end while
return
result
#end def readData
def
receiveData
(
self
,
conn
,
pipe
,
n
):
with
self
.
processing
:
self
.
identifier
=
None
cont
=
True
while
1
:
data
=
conn
.
recv
(
4096
)
if
not
data
:
break
#end if
lines
=
data
.
split
(
"
\n
"
)
for
line
in
lines
:
if
re
.
search
(
'^!#'
,
line
)
!=
None
:
command
=
self
.
gotCustomCommand
(
line
)
if
command
!=
None
:
self
.
parseCustomCommand
(
command
)
if
command
[
0
]
==
'end'
:
cont
=
False
break
#end if
#end if
else
:
self
.
clock
=
datetime
.
datetime
.
now
()
if
self
.
debug
:
print
"SENT TO SERVER: "
+
line
#end if
if
line
!=
''
:
pipe
.
stdin
.
write
(
line
+
"
\n
"
)
#end if
buff
=
self
.
readData
(
conn
,
n
)
lines
=
buff
.
split
(
"
\n
"
)
for
line
in
lines
:
if
re
.
search
(
'^!#'
,
line
)
!=
None
:
command
=
self
.
gotCustomCommand
(
line
)
if
command
!=
None
:
self
.
parseCustomCommand
(
command
)
#end if
else
:
if
self
.
debug
:
print
"SENT TO SERVER: "
+
line
#end if
if
line
!=
''
:
pipe
.
stdin
.
write
(
line
+
"
\n
"
)
#end if
#end for
if
not
cont
:
break
#end if
#end
while
#end
for
with
self
.
new_loop
:
pipe
.
stdin
.
write
(
"wbvardef send_to_vim = 1;
\n
"
)
pipe
.
stdin
.
write
(
"wbvardef send_to_vim = 1;
\n
wbvardelete send_to_vim;
\n
"
)
if
self
.
identifier
==
None
:
with
self
.
executing
:
data
=
self
.
prepareResult
(
self
.
buff
)
...
...
@@ -243,22 +261,37 @@ class SQLWorkbench(object):
#end def receiveData
def
newConnection
(
self
,
conn
,
pipe
):
n
=
''
c
=
''
while
c
!=
'#'
:
c
=
conn
.
recv
(
1
)
if
c
!=
'#'
:
n
+=
c
#end if
#end while
if
(
n
!=
''
):
n
=
int
(
n
)
else
:
n
=
0
#end if
data
=
conn
.
recv
(
3
)
if
data
==
'COM'
:
self
.
receiveData
(
conn
,
pipe
)
self
.
receiveData
(
conn
,
pipe
,
n
-
3
)
elif
data
==
'RES'
:
self
.
searchResult
(
conn
)
self
.
searchResult
(
conn
,
n
-
3
)
elif
data
==
'DBE'
:
self
.
dbExplorer
(
conn
)
self
.
dbExplorer
(
conn
,
n
)
#end if
conn
.
close
()
#end def newConnection
def
monitor
(
self
,
pipe
,
port
):
self
.
startThread
()
HOST
=
'127.0.0.1'
# Symbolic name meaning all available interfaces
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
s
.
settimeout
(
3
)
try
:
s
.
bind
((
HOST
,
port
))
...
...
@@ -270,14 +303,18 @@ class SQLWorkbench(object):
#now keep talking with the client
while
1
:
#wait to accept a connection - blocking call
conn
,
addr
=
s
.
accept
()
if
self
.
debug
:
print
'Connected with '
+
addr
[
0
]
+
':'
+
str
(
addr
[
1
])
try
:
conn
,
addr
=
s
.
accept
()
except
Exception
:
conn
=
None
#end try
if
conn
!=
None
:
if
self
.
debug
:
print
'Connected with '
+
addr
[
0
]
+
':'
+
str
(
addr
[
1
])
#end if
thread
.
start_new_thread
(
self
.
newConnection
,
(
conn
,
pipe
))
#end if
thread
.
start_new_thread
(
self
.
newConnection
,
(
conn
,
pipe
))
with
self
.
lock
:
if
self
.
quit
:
break
...
...
@@ -285,10 +322,10 @@ class SQLWorkbench(object):
#end with
#end while
s
.
close
()
self
.
stopThread
()
#end def monitor
def
receiverDbe
(
self
,
pipe
):
time
=
''
line
=
''
buff
=
''
while
re
.
search
(
'using.*send_to_vim'
,
line
)
==
None
:
...
...
@@ -305,7 +342,7 @@ class SQLWorkbench(object):
def
receiver
(
self
,
pipe
):
first_prompt
=
False
record_set
=
False
time
=
''
self
.
startThread
()
while
True
:
with
self
.
new_loop
:
line
=
''
...
...
@@ -314,22 +351,20 @@ class SQLWorkbench(object):
with
self
.
executing
:
while
re
.
search
(
'send_to_vim'
,
line
)
==
None
:
line
=
pipe
.
stdout
.
readline
()
if
re
.
search
(
self
.
prompt_pattern_begin
,
line
)
!=
No
ne
:
if
not
first_prompt
:
first_prompt
=
True
self
.
buff
=
''
else
:
self
.
buff
+=
"
\n
"
+
time
+
"
\n
"
if
li
ne
:
if
re
.
search
(
self
.
prompt_pattern_begin
,
line
)
!=
None
:
if
not
first_prompt
:
first_prompt
=
True
self
.
buff
=
''
#end if
#end if
#end if
if
re
.
search
(
'^[
\\
-
\\
+]+$'
,
line
):
time
=
"SQL execution time: %.2g seconds"
%
(
datetime
.
datetime
.
now
()
-
self
.
clock
).
total_seconds
()
self
.
clock
=
datetime
.
datetime
.
now
()
#end if
self
.
buff
+=
line
if
self
.
debug
:
sys
.
stdout
.
write
(
line
)
sys
.
stdout
.
flush
()
self
.
buff
+=
line
if
self
.
debug
:
sys
.
stdout
.
write
(
line
)
sys
.
stdout
.
flush
()
#end if
else
:
break
#end if
#end while
if
self
.
identifier
!=
None
:
...
...
@@ -345,6 +380,7 @@ class SQLWorkbench(object):
if
self
.
quit
:
break
#end with
#end while
self
.
stopThread
()
#end def receiver
def
main
(
self
):
...
...
@@ -357,7 +393,9 @@ class SQLWorkbench(object):
if
(
self
.
profile
!=
None
):
cmd
+=
" -profile=%s"
%
self
.
profile
#end if
print
"OPENING: "
+
cmd
if
self
.
debug
:
print
"OPENING: "
+
cmd
#end if
pipe
=
subprocess
.
Popen
(
shlex
.
split
(
cmd
),
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
bufsize
=
1
)
thread
.
start_new_thread
(
self
.
receiver
,
(
pipe
,))
...
...
@@ -374,7 +412,11 @@ class SQLWorkbench(object):
with
self
.
lock
:
self
.
quit
=
True
#end try...except
time
.
sleep
(
0.3
)
print
"Waiting for server to stop..."
while
self
.
threads_started
>
0
:
time
.
sleep
(
0.3
)
#end while
sys
.
exit
(
0
)
#end def main
#end class SQLWorkbench
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录