Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ITKEY_
Vim Sql Workbench
提交
06548141
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 搜索 >>
提交
06548141
编写于
3月 07, 2015
作者:
C
Cosmin Popescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added variables
上级
d1299d0b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
345 addition
and
15 deletion
+345
-15
README.md
README.md
+93
-4
autoload/sw.vim
autoload/sw.vim
+1
-0
autoload/sw/dbexplorer.vim
autoload/sw/dbexplorer.vim
+13
-9
autoload/sw/search.vim
autoload/sw/search.vim
+11
-2
autoload/sw/sqlwindow.vim
autoload/sw/sqlwindow.vim
+11
-0
autoload/sw/variables.vim
autoload/sw/variables.vim
+123
-0
doc/sw.txt
doc/sw.txt
+87
-0
plugin/sw.vim
plugin/sw.vim
+6
-0
未找到文件。
README.md
浏览文件 @
06548141
...
...
@@ -30,10 +30,11 @@ CONTENTS:
6.
Exporting
7.
Sessions
8.
Asynchronous
9.
Commands
19.
Settings
11.
Screen shots
12.
Missing features
9.
Variables
10.
Commands
11.
Settings
12.
Screen shots
13.
Missing features
Requirements
========================================
...
...
@@ -559,6 +560,65 @@ statement. The statement will get execute anyway.
If any of the requirements is not met, you will not receive any error message.
The plugin will silently switch to synchronous mode and work without issues.
Variables
========================================
`SQL Workbench/j`
supports user defined variables (you can have your queries
sent to the database parameterized). See
[
here
](
http://www.sql-workbench.net/manual/using-variables.html
)
.
This plugin takes advantage of that and implements a few commands to help you
use variables.
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 asking doing parameters substitution for a given
buffer, you can call
`SWVarDisable`
. You can always re-enable the parameter
switching 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.
Commands
========================================
...
...
@@ -894,6 +954,35 @@ this was active when `mksession` was executed.
This command will kill the current command being executed in asynchronous mode.
## 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
Settings
========================================
...
...
autoload/sw.vim
浏览文件 @
06548141
...
...
@@ -143,6 +143,7 @@ function! sw#check_async_result()
endfunction
function
!
sw
#got_async_result
(
unique_id
)
echomsg
"GOT ASYNC RESULT"
.
a:unique_id
call
add
(
g:sw_async_ended
,
a:unique_id
)
if
s:get_buff_unique_id
()
==
a:unique_id
if
mode
()
==
'i'
||
mode
()
==
'R'
...
...
autoload/sw/dbexplorer.vim
浏览文件 @
06548141
...
...
@@ -97,20 +97,24 @@ function! s:get_panels()
return
[
'__DBExplorer__-'
.
b:profile
,
'__SQL__-'
.
b:profile
,
'__Info__-'
.
b:profile
]
endfunction
function
!
s
:
set_values_to_all_buffers
(
keys
,
values
)
function
!
s
w
#dbexplorer#
set_values_to_all_buffers
(
keys
,
values
)
let
name
=
bufname
(
'%'
)
for
w
in
s:get_panels
()
call
sw
#goto_window
(
w
)
let
i
=
0
while
i
<
len
(
a:keys
)
execute
"let b:"
.
a:keys
[
i
]
.
" = a:values[i]"
if
(
a:keys
[
i
]
!=
'on_async_result'
)
execute
"let b:"
.
a:keys
[
i
]
.
" = a:values[i]"
else
call
sw
#set_on_async_result
(
a:values
[
i
])
endif
let
i
=
i
+
1
endwhile
endfor
call
sw
#goto_window
(
name
)
endfunction
function
!
s
:
unset_values_from_all_buffers
(
keys
)
function
!
s
w
#dbexplorer#
unset_values_from_all_buffers
(
keys
)
let
name
=
bufname
(
'%'
)
for
w
in
s:get_panels
()
call
sw
#goto_window
(
w
)
...
...
@@ -128,7 +132,7 @@ function! s:set_async_variables()
for
w
in
s:get_panels
()
call
sw
#goto_window
(
w
)
if
exists
(
'b:async_on_progress'
)
call
s
:
set_values_to_all_buffers
([
'async_on_progress'
],
[
b:async_on_progress
])
call
s
w
#dbexplorer#
set_values_to_all_buffers
([
'async_on_progress'
],
[
b:async_on_progress
])
break
endif
endfor
...
...
@@ -136,7 +140,7 @@ function! s:set_async_variables()
endfunction
function
!
s:unset_async_variables
()
call
s
:
unset_values_from_all_buffers
([
'async_on_progress'
])
call
s
w
#dbexplorer#
unset_values_from_all_buffers
([
'async_on_progress'
])
endfunction
function
!
s:process_result_1
(
result
,
shortcut
,
title
)
...
...
@@ -184,11 +188,11 @@ function! s:process_result_1(result, shortcut, title)
endfunction
function
!
s:set_tmp_variables_1
(
title
,
shortcut
)
call
s
:
set_values_to_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__title'
,
'__shortcut'
],
[
'sw#dbexplorer#on_async_result_1'
,
'sw#dbexplorer#on_async_result_1'
,
a:title
,
a:shortcut
])
call
s
w
#dbexplorer#
set_values_to_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__title'
,
'__shortcut'
],
[
'sw#dbexplorer#on_async_result_1'
,
'sw#dbexplorer#on_async_result_1'
,
a:title
,
a:shortcut
])
endfunction
function
!
s:unset_tmp_variables_1
()
call
s
:
unset_values_from_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__title'
,
'__shortcut'
])
call
s
w
#dbexplorer#
unset_values_from_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__title'
,
'__shortcut'
])
endfunction
function
!
sw
#dbexplorer#on_async_result_1
()
...
...
@@ -283,11 +287,11 @@ function! s:process_result_2(result, tab_shortcut, shortcut, cmd)
endfunction
function
!
s:set_tmp_variables_2
(
tab_shortcut
,
shortcut
,
cmd
)
call
s
:
set_values_to_all_buffers
([
'__tab_shortcut'
,
'__shortcut'
,
'__cmd'
,
'on_async_result'
,
'on_async_kill'
],
[
a:tab_shortcut
,
a:shortcut
,
a:cmd
,
'sw#dbexplorer#on_async_result_2'
,
'sw#dbexplorer#on_async_kill_2'
])
call
s
w
#dbexplorer#
set_values_to_all_buffers
([
'__tab_shortcut'
,
'__shortcut'
,
'__cmd'
,
'on_async_result'
,
'on_async_kill'
],
[
a:tab_shortcut
,
a:shortcut
,
a:cmd
,
'sw#dbexplorer#on_async_result_2'
,
'sw#dbexplorer#on_async_kill_2'
])
endfunction
function
!
s:unset_tmp_variables_2
()
call
s
:
unset_values_from_all_buffers
([
'__tab_shortcut'
,
'__shortcut'
,
'__cmd'
,
'on_async_result'
,
'on_async_kill'
])
call
s
w
#dbexplorer#
unset_values_from_all_buffers
([
'__tab_shortcut'
,
'__shortcut'
,
'__cmd'
,
'on_async_result'
,
'on_async_kill'
])
endfunction
function
!
s:change_panel
(
command
,
shortcut
,
title
,
tab_shortcut
)
...
...
autoload/sw/search.vim
浏览文件 @
06548141
...
...
@@ -217,9 +217,17 @@ function! s:asynchronious(columns, set)
let
a_name
=
s:get_resultset_name
()
endif
if
a:set
call
s:set_async_variables
(
a:columns
)
if
sw
#dbexplorer#is_db_explorer_tab
()
call
sw
#dbexplorer#set_values_to_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__columns'
],
[
'sw#search#on_async_result'
,
'sw#search#on_async_kill'
,
'a:columns'
])
else
call
s:set_async_variables
(
a:columns
)
endif
else
call
s:unset_async_variables
()
if
sw
#dbexplorer#is_db_explorer_tab
()
call
sw
#dbexplorer#unset_values_from_all_buffers
([
'on_async_result'
,
'on_async_kill'
,
'__columns'
])
else
call
s:unset_async_variables
()
endif
endif
call
sw
#goto_window
(
a_name
)
if
a:set
...
...
@@ -243,6 +251,7 @@ function! s:unset_async_variables()
endfunction
function
!
sw
#
search
#on_async_result
()
echomsg
"ASYNC SEARCH RESULT"
let
result
=
sw
#get_sql_result
(
0
)
let
columns
=
g:sw_search_default_result_columns
if
exists
(
'b:__columns'
)
...
...
autoload/sw/sqlwindow.vim
浏览文件 @
06548141
...
...
@@ -509,6 +509,17 @@ function! sw#sqlwindow#execute_sql(sql)
if
(
b:max_results
!=
0
)
let
_sql
=
w
:
auto_added1
.
'set maxrows = '
.
b:max_results
.
"\n"
.
b:delimiter
.
"\n"
.
w
:
auto_added2
.
_sql
endif
if
!
exists
(
'b:no_variables'
)
let
vars
=
sw
#variables#extract
(
_sql
)
if
len
(
vars
)
>
0
for
var
in
vars
let
value
=
sw
#variables#
get
(
var
)
if
value
!=
''
let
_sql
=
w
:
auto_added1
.
'wbvardef '
.
var
.
' = '
.
value
.
"\n"
.
b:delimiter
.
"\n"
.
w
:
auto_added2
.
_sql
endif
endfor
endif
endif
call
sw
#set_on_async_result
(
'sw#sqlwindow#on_async_result'
)
let
b:on_async_kill
=
'sw#sqlwindow#on_async_kill'
let
result
=
sw
#execute_sql
(
b:profile
,
_sql
,
0
)
...
...
autoload/sw/variables.vim
0 → 100644
浏览文件 @
06548141
"============================================================================"
"
" 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
"
"============================================================================"
function
!
s:set_delimiters
()
if
!
exists
(
'g:sw_p_suffix'
)
&&
!
exists
(
'g:sw_p_prefix'
)
let
p1
=
'\v\c^[\s \t]*workbench\.sql\.parameter\.(suffix|prefix)'
if
exists
(
'g:sw_config_dir'
)
let
lines
=
readfile
(
g:sw_config_dir
.
'workbench.settings'
)
for
line
in
lines
if
line
=~
p1
let
p2
=
p1
.
'[\s \t]*\=[\s\t ]*(.*)$'
let
type
=
substitute
(
line
,
p2
,
'\1'
,
'g'
)
execute
"let g:sw_p_"
.
type
.
" = substitute(line, p2, '\\2', 'g')"
endif
endfor
endif
if
!
exists
(
'g:sw_p_prefix'
)
let
g:sw_p_prefix
=
'$['
endif
if
!
exists
(
'g:sw_p_suffix'
)
let
g:sw_p_suffix
=
']'
endif
endif
endfunction
function
!
s:init_vars
()
if
!
exists
(
'b:variables'
)
call
sw
#session#set_buffer_variable
(
'variables'
,
{})
endif
endfunction
function
!
sw
#variables#
set
(
key
,
value
,
...)
call
s:init_vars
()
let
val
=
a:value
if
a:0
let
i
=
1
while
i
<=
a:0
execute
"let v = a:"
.
i
if
i
<
a:0
||
v
!=
''
execute
"let val = val . ' ' . a:"
.
i
endif
let
i
=
i
+
1
endwhile
endif
call
sw
#session#set_buffer_variable
(
"variables."
.
a:key
,
val
)
endfunction
function
!
sw
#variables#
list
()
call
s:init_vars
()
echo
string
(
b:variables
)
endfunction
function
!
sw
#variables#autocomplete_names
(
ArgLead
,
CmdLine
,
CursorPos
)
call
s:init_vars
()
let
words
=
split
(
'^'
.
a:CmdLine
,
'\v\s+'
)
let
result
=
[]
if
len
(
words
)
==
1
||
(
len
(
words
)
==
2
&&
!(
a:CmdLine
=~
'\v\s+$'
))
for
key
in
keys
(
b:variables
)
if
key
=~
a:ArgLead
call
add
(
result
,
key
)
endif
endfor
endif
return
result
endfunction
function
!
sw
#variables#unset
(
key
)
call
s:init_vars
()
call
sw
#session#unset_buffer_variable
(
'variables.'
.
a:key
)
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
.
'\(.\{-\}\)'
.
g:sw_p_suffix
.
'\>'
let
result
=
[]
let
n
=
0
let
i
=
match
(
a:sql
,
pattern
,
n
)
while
i
!=
-1
let
l
=
matchlist
(
a:sql
,
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
)
endif
let
i
=
match
(
a:sql
,
pattern
,
n
)
endwhile
return
result
endfunction
doc/sw.txt
浏览文件 @
06548141
...
...
@@ -31,6 +31,7 @@ CONTENTS
6. Exporting ................................................ |sw-export|
7. Sessions ............................................... |sw-sessions|
8. Asynchronous ....................................... |sw-asynchronous|
9. Variables ............................................. |sw-variables|
9. Commands ............................................... |sw-commands|
10. Settings .............................................. |sw-settings|
11. Missing features .............................. |sw-missing-features|
...
...
@@ -545,6 +546,63 @@ sent to the DBMS. This only means that once it's finished, vim will simply
ignore its output. This is not a way to stop a wrongly sent *update*
statement. The statement will get execute anyway.
==============================================================================
VARIABLES *sw-variables*
SQL Workbench/J supports user defined variables (you can have your queries
sent to the database parameterized).
This plugin takes advantage of that and implements a few commands to help you
use variables.
By default, in SQL Workbench, the variables are enclosed between $[ and
]. These can be changed.
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 asking doing parameters substitution for a given
buffer, you can call |SWVarDisable|. You can always re-enable the parameter
switching 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.
==============================================================================
COMMANDS *sw-commands*
...
...
@@ -861,6 +919,35 @@ this was active when `mksession` was executed.
This command will kill the current command being executed in asynchronous mode.
*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
==============================================================================
SETTINGS *sw-settings*
...
...
plugin/sw.vim
浏览文件 @
06548141
...
...
@@ -212,6 +212,12 @@ command! SWSqlAutocompleteWithDefault setlocal omnifunc=sw#autocomplete#perform
command
!
SWSqlBufferRestore
call
sw
#session#restore_sqlbuffer
()
command
!
-
nargs
=
0
SWKillCurrentCommand
call
sw
#kill_current_command
()
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
()
augroup
sw
autocmd
sw
BufDelete
,
BufWipeout
*
call
sw
#session#
sync
()
autocmd
sw
SessionLoadPost
*
call
sw
#session#restore
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录