Skip to content

Commit c87d8d4

Browse files
bagyi0vim-scripts
authored andcommitted
Version 14.0
Posted by David Fishburn New Features --------- - Added support for using extended connection strings with Oracle and SQLPlus Fredrik Acosta). - Added a new buffer option to specify which filetype dbext should use when parsing the query. If an existing language already works as you need you can tell dbext to use it via the modeline or DBSetOption (Albie Janse van Rensburg). - Added an example of a function I use to execute blocks of stored procedures using dbext's commands. - For PostgreSQL, dbext will check for the existance of a .pgpass file. If not found, execution will abort and a warning message will be displayed. By default $HOME/.pgpass will be validated (Frank Schwach). Bug Fixes --------- - When closing or deleting buffers it was possible to loose syntax, filetype and hidden settings (Alexey Radkov). - Parsing VisualBasic and Basic variables let to errors in DB_parseVB (Albie Janse van Rensburg). - Generating a column list for an ASA database left an extra , at the end of the list. This also affected the SQLComplete plugin.
1 parent f539f2f commit c87d8d4

File tree

4 files changed

+248
-47
lines changed

4 files changed

+248
-47
lines changed

autoload/dbext.vim

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
" dbext.vim - Commn Database Utility
22
" Copyright (C) 2002-10, Peter Bagyinszki, David Fishburn
33
" ---------------------------------------------------------------
4-
" Version: 13.00
4+
" Version: 14.00
55
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
66
" Authors: Peter Bagyinszki <petike1 at dpg dot hu>
77
" David Fishburn <dfishburn dot vim at gmail dot com>
8-
" Last Modified: 2011 May 31
8+
" Last Modified: 2012 Mar 23
99
" Based On: sqlplus.vim (author: Jamis Buck)
1010
" Created: 2002-05-24
1111
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
@@ -38,7 +38,11 @@ if v:version < 700
3838
echomsg "dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
3939
finish
4040
endif
41-
let g:loaded_dbext_auto = 1300
41+
let g:loaded_dbext_auto = 1400
42+
43+
" Turn on support for line continuations when creating the script
44+
let s:cpo_save = &cpo
45+
set cpo&vim
4246

4347
" call confirm("Loaded dbext autoload", "&Ok")
4448
" Script variable defaults, these are used internal and are never displayed
@@ -169,6 +173,7 @@ function! s:DB_buildLists()
169173
call add(s:config_params_mv, 'autoclose')
170174
call add(s:config_params_mv, 'autoclose_min_lines')
171175
call add(s:config_params_mv, 'variable_remember')
176+
call add(s:config_params_mv, 'filetype')
172177

173178
" Script parameters
174179
let s:script_params_mv = []
@@ -884,6 +889,7 @@ function! s:DB_getDefault(name)
884889
elseif a:name ==# "PGSQL_cmd_terminator" |return (exists("g:dbext_default_PGSQL_cmd_terminator")?g:dbext_default_PGSQL_cmd_terminator.'':';')
885890
elseif a:name ==# "PGSQL_SQL_Top_pat" |return (exists("g:dbext_default_PGSQL_SQL_Top_pat")?g:dbext_default_PGSQL_SQL_Top_pat.'':'\(.*\)')
886891
elseif a:name ==# "PGSQL_SQL_Top_sub" |return (exists("g:dbext_default_PGSQL_SQL_Top_sub")?g:dbext_default_PGSQL_SQL_Top_sub.'':'\1 LIMIT @dbext_topX ')
892+
elseif a:name ==# "PGSQL_pgpass" |return (exists("g:dbext_default_PGSQL_pgpass")?g:dbext_default_PGSQL_pgpass.'':'$HOME/.pgpass')
887893
elseif a:name ==# "RDB_bin" |return (exists("g:dbext_default_RDB_bin")?g:dbext_default_RDB_bin.'':'mc sql$')
888894
elseif a:name ==# "RDB_cmd_header" |return (exists("g:dbext_default_RDB_cmd_header")?g:dbext_default_RDB_cmd_header.'':"".
889895
\ "set line length 10000\n" .
@@ -1125,6 +1131,10 @@ function! s:DB_resetBufferParameters(use_defaults)
11251131
call s:DB_promptForParameters()
11261132
endif
11271133

1134+
" if s:DB_get('filetype') == ''
1135+
" let s:DB_set('filetype') = &filetype
1136+
" endif
1137+
11281138
" call s:DB_validateBufferParameters()
11291139
let retval = s:DB_validateBufferParameters()
11301140

@@ -1795,7 +1805,9 @@ function! s:DB_ASA_stripHeaderFooter(result)
17951805
let stripped = substitute( stripped, '\((\)\?\(First\s\+\)\?\d\+ row\_.*', '', '' )
17961806
" Strip off trailing spaces
17971807
" let stripped = substitute( stripped, '\(\<\w\+\>\)\s*', '\1', 'g' )
1798-
let stripped = substitute( stripped, '\(\<\w\+\>\)\s*\(\n\)', '\1\2', '' )
1808+
let stripped = substitute( stripped, '\(\<\w\+\>\)\s*\(\n\)', '\1\2', 'g' )
1809+
" Strip blank lines
1810+
let stripped = substitute( stripped, '\(\n\)\(\n\)', '', 'g' )
17991811
return stripped
18001812
endfunction
18011813

@@ -2870,11 +2882,11 @@ function! s:DB_ORA_execSql(str)
28702882

28712883
let cmd = dbext_bin .
28722884
\ ' ' . dbext#DB_getWType("cmd_options") .
2873-
\ s:DB_option(' ', s:DB_get("user"), '') .
2885+
\ s:DB_option(" '", s:DB_get("user"), '') .
28742886
\ s:DB_option('/', s:DB_get("passwd"), '') .
28752887
\ s:DB_option('@', s:DB_get("srvname"), '') .
28762888
\ s:DB_option(' ', s:DB_get("extra"), '') .
2877-
\ ' @' . s:dbext_tempfile
2889+
\ '" @' . s:dbext_tempfile
28782890
let result = s:DB_runCmd(cmd, output, "")
28792891

28802892
return result
@@ -3026,7 +3038,32 @@ function! s:DB_ORA_getDictionaryView() "{{{
30263038
endfunction "}}}
30273039
"}}}
30283040
" PGSQL exec {{{
3041+
function! s:DB_PGSQL_check_pgpass()
3042+
" All defaults are specified in the DB_getDefault function.
3043+
" This contains the defaults settings for all database types
3044+
let filename = dbext#DB_getWType("pgpass")
3045+
3046+
if !filereadable(expand(filename))
3047+
call s:DB_warningMsg(
3048+
\ "dbext:PostgreSQL requires a '".
3049+
\ dbext#DB_getWType("pgpass").
3050+
\ "' file in order to authenticate. ".
3051+
\ 'This file is missing. '.
3052+
\ "The binary '".
3053+
\ dbext#DB_getWType("bin").
3054+
\ "' does not accept commandline passwords."
3055+
\ )
3056+
return -1
3057+
endif
3058+
3059+
return
3060+
endfunction
3061+
30293062
function! s:DB_PGSQL_execSql(str)
3063+
if s:DB_PGSQL_check_pgpass() == -1
3064+
return -1
3065+
endif
3066+
30303067
" All defaults are specified in the DB_getDefault function.
30313068
" This contains the defaults settings for all database types
30323069
let terminator = dbext#DB_getWType("cmd_terminator")
@@ -4973,6 +5010,10 @@ function! dbext#DB_execSql(query)
49735010
return -1
49745011
endif
49755012

5013+
" Mark the current line to return to
5014+
let curline = line(".")
5015+
let curcol = virtcol(".")
5016+
49765017
" Add query to internal history
49775018
call s:DB_historyAdd(query)
49785019

@@ -4994,14 +5035,26 @@ function! dbext#DB_execSql(query)
49945035
endif
49955036

49965037
if query != ""
4997-
return dbext#DB_execFuncTypeWCheck('execSql', query)
5038+
let rc = dbext#DB_execFuncTypeWCheck('execSql', query)
5039+
5040+
" Return to previous location
5041+
" Accounting for beginning of the line
5042+
" silent! exe 'norm! '.curline."G\<bar>".(curcol-1).(((curcol-1)> 0)?'l':'')
5043+
call cursor(curline, curcol)
5044+
5045+
return rc
49985046
else
49995047
" If the query was cancelled, close the history
50005048
" window which was opened when we added the
50015049
" query above.
50025050
call dbext#DB_windowClose(s:DB_resBufName())
50035051
endif
50045052

5053+
" Return to previous location
5054+
" Accounting for beginning of the line
5055+
" silent! exe 'norm! '.curline."G\<bar>".(curcol-1).(((curcol-1)> 0)?'l':'')
5056+
call cursor(curline, curcol)
5057+
50055058
return -1
50065059
endfunction
50075060

@@ -5086,6 +5139,10 @@ function! dbext#DB_execSqlTopX(...)
50865139
endfunction
50875140

50885141
function! dbext#DB_execRangeSql() range
5142+
" Mark the current line to return to
5143+
let curline = a:lastline
5144+
let curcol = 0
5145+
50895146
if a:firstline != a:lastline
50905147
let saveR = @"
50915148
silent! exec a:firstline.','.a:lastline.'y'
@@ -5095,7 +5152,13 @@ function! dbext#DB_execRangeSql() range
50955152
let query = getline(a:firstline)
50965153
endif
50975154

5098-
return dbext#DB_execSql(query)
5155+
let rc = dbext#DB_execSql(query)
5156+
5157+
" Return to previous location
5158+
" Accounting for beginning of the line
5159+
call cursor(curline, curcol)
5160+
5161+
return rc
50995162
endfunction
51005163

51015164
function! s:DB_getLoginScript(filename)
@@ -5814,6 +5877,13 @@ function! dbext#DB_auBufDelete(del_buf_nr) "{{{
58145877
return
58155878
endif
58165879

5880+
" Do not let current buffer and syntax highlighting go which may
5881+
" happen when current value of 'bufhidden' is 'delete', 'wipe' etc.
5882+
let cur_bufhidden = &bufhidden
5883+
let cur_syntax = &syntax
5884+
let cur_filetype = &filetype
5885+
setlocal bufhidden=
5886+
58175887
let idx = index(s:dbext_buffers_with_dict_files, del_buf)
58185888

58195889
if idx > -1 || exists('g:loaded_dbext_auto')
@@ -5839,6 +5909,13 @@ function! dbext#DB_auBufDelete(del_buf_nr) "{{{
58395909

58405910
" Switch back to the current buffer
58415911
silent! exec cur_buf.'buffer'
5912+
5913+
" Switch back value of 'bufhidden' and syntax
5914+
if !empty(cur_bufhidden)
5915+
exec "setlocal bufhidden=".cur_bufhidden
5916+
exec "setlocal syntax=".cur_syntax
5917+
exec "setlocal filetype=".cur_filetype
5918+
endif
58425919
endif
58435920
endfunction "}}}
58445921
"}}}
@@ -6597,33 +6674,41 @@ function! dbext#DB_parseQuery(query)
65976674
return a:query
65986675
endif
65996676

6600-
if &filetype == "sql"
6677+
" If the user has not overriden the filetype using DB_setOption
6678+
" then use the filetype Vim set
6679+
let l:filetype = s:DB_get('filetype')
6680+
if l:filetype == ''
6681+
call s:DB_set('filetype', &filetype)
6682+
let l:filetype = &filetype
6683+
endif
6684+
6685+
if matchstr( l:filetype, "sql" ) == "sql"
66016686
" Dont parse the SQL query, since DB_parseHostVariables
66026687
" will pickup the standard host variables for prompting.
66036688
" let query = s:DB_parseSQL(a:query)
66046689
return s:DB_parseHostVariables(a:query)
6605-
elseif &filetype == "java" ||
6606-
\ &filetype == "jsp" ||
6607-
\ &filetype == "html" ||
6608-
\ &filetype == "javascript"
6690+
elseif matchstr( l:filetype, "java" ) == "java" ||
6691+
\ matchstr( l:filetype, "jsp" ) == "jsp" ||
6692+
\ matchstr( l:filetype, "html" ) == "html" ||
6693+
\ matchstr( l:filetype, "javascript" ) == "javascript"
66096694
let query = s:DB_parseJava(a:query)
66106695
return s:DB_parseHostVariables(query)
6611-
elseif &filetype == "jproperties"
6696+
elseif matchstr( l:filetype, "jproperties" ) == "jproperties"
66126697
let query = s:DB_parseJProperties(a:query)
66136698
return s:DB_parseHostVariables(query)
6614-
elseif &filetype == "perl"
6699+
elseif matchstr( l:filetype, "perl" ) == "perl"
66156700
" The Perl parser will deal with string concatenation
66166701
let query = s:DB_parsePerl(a:query)
66176702
" Let the SQL parser handle embedded host variables
66186703
return s:DB_parseHostVariables(query)
6619-
elseif &filetype == "php"
6704+
elseif matchstr( l:filetype, "php" ) == "php"
66206705
let query = s:DB_parsePHP(a:query)
66216706
return s:DB_parseHostVariables(query)
6622-
elseif &filetype == "vim"
6707+
elseif matchstr( l:filetype, "vim" ) == "vim"
66236708
let query = s:DB_parseVim(a:query)
66246709
return s:DB_parseHostVariables(query)
6625-
elseif &filetype == "vb" ||
6626-
\ &filetype == "basic"
6710+
elseif matchstr( l:filetype, "vb" ) == "vb" ||
6711+
\ matchstr( l:filetype, "basic" ) == "basic"
66276712
let query = s:DB_parseVB(a:query)
66286713
return s:DB_parseHostVariables(query)
66296714
else
@@ -7553,7 +7638,7 @@ endfunction
75537638
function! s:DB_parseVB(query)
75547639

75557640
" Join all line continuations by removing the ending "_"
7556-
let a_query = substitute(a:query, " _[\r\n]\\+\\s*", "","")
7641+
let a_query = substitute(a:query, " _[\r\n]\\+\\s*", "","g")
75577642

75587643
" Get the string part of the vb query and remove the beginning
75597644
" and closing quotes
@@ -7603,20 +7688,7 @@ function! s:DB_parseVB(query)
76037688
" \s*[+&] - Any space and a plus sign
76047689
" \s*" - Any space followed by a double quote
76057690

7606-
" Replace all sql vars using existing buffer variables
7607-
let index = match(query, var_expr_q)
7608-
while index > -1
7609-
let var = matchstr(query, var_expr, index)
7610-
let val = s:DB_sqlvar_get(var)
7611-
" echo b:dbext_sqlvar_mv
7612-
if index == 0
7613-
let query = val.query[index+strlen(var)+2:]
7614-
else
7615-
let query = query[0:index-1].val.query[index+strlen(var)+2:]
7616-
endif
7617-
let index = match(query, var_expr, index+strlen(var))
7618-
endwhile
7619-
" let query = s:DB_searchReplace(query, var_expr, var_expr, 0)
7691+
let query = s:DB_searchReplace(query, var_expr, var_expr, 0)
76207692

76217693
"call inputdialog(query)
76227694
return query
@@ -8281,4 +8353,8 @@ endfunction
82818353
call s:DB_buildLists()
82828354

82838355
call s:DB_resetGlobalParameters()
8356+
8357+
let &cpo = s:cpo_save
8358+
unlet s:cpo_save
8359+
82848360
" vim:fdm=marker:nowrap:ts=4:expandtab:ff=unix:

autoload/dbext_dbi.vim

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
" It adds transaction support and the ability
55
" to reach any database currently supported
66
" by Perl and DBI.
7-
" Version: 13.00
7+
" Version: 14.00
88
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
99
" Authors: David Fishburn <dfishburn dot vim at gmail dot com>
10-
" Last Modified: 2010 Sep 07
10+
" Last Modified: 2012 Feb 24
1111
" Created: 2007-05-24
1212
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
1313
"
@@ -37,7 +37,15 @@
3737
" copy "%SQLANYSAMP10%\demo.db"
3838
" dbeng10 demo
3939
"
40-
" Make sure SQLANY10 is in your path before any other versions of SQL
40+
" cd %SQLANY11%\SDK\perl
41+
" copy "%SQLANYSAMP11%\demo.db"
42+
" dbeng11 demo
43+
"
44+
" cd %SQLANY12%\SDK\perl
45+
" copy "%SQLANYSAMP12%\demo.db"
46+
" dbeng12 demo
47+
"
48+
" Make sure SQLANY(10|11|12) is in your path before any other versions of SQL
4149
" Anywhere.
4250
" "C:\Program Files\Microsoft Visual Studio .Net 2003\Common7\Tools\vsvars32.bat"
4351
" or
@@ -116,7 +124,7 @@ if !has('perl')
116124
let g:loaded_dbext_dbi_msg = 'Vim does not have perl support enabled'
117125
finish
118126
endif
119-
let g:loaded_dbext_dbi = 1300
127+
let g:loaded_dbext_dbi = 1400
120128

121129
if !exists("dbext_dbi_debug")
122130
let g:dbext_dbi_debug = 0
@@ -140,8 +148,8 @@ if !exists("dbext_dbi_trace_level")
140148
let g:dbext_dbi_trace_level = 0
141149
endif
142150

143-
" See help use-cpo-save for info on the variable save_cpo
144-
let s:save_cpo = &cpo
151+
" Turn on support for line continuations when creating the script
152+
let s:cpo_save = &cpo
145153
set cpo&vim
146154

147155
function! dbext_dbi#DBI_load_perl_subs()
@@ -1689,4 +1697,7 @@ EOCore
16891697
let g:dbext_dbi_loaded_perl_subs = 1
16901698
endfunction
16911699

1700+
let &cpo = s:cpo_save
1701+
unlet s:cpo_save
1702+
16921703
" vim:fdm=marker:nowrap:ts=4:expandtab:

0 commit comments

Comments
 (0)