Skip to content

Commit 2c8a809

Browse files
bagyi0vim-scripts
authored andcommitted
Version 12.00
Posted by David Fishburn New Features --------- - A number of changes around the Oracle formating instructions. Support for packages when describing certain objects. These changes were provided by Sergey Khorev. - Improved the parsing of Perl strings when prompting for variables. - Made some additional changes to the variable_def_regex for how you can specify it from Vim modelines and DBSetOption. This makes it much more flexible. Bug Fixes --------- - If the word "profile" was used in a dbext profile name dbext would report the error: "dbext: Profiles cannot be nested" (Chris Cierpisz). - Corrected the regex used to find object owner names (Sergey Khorev).
1 parent 108502a commit 2c8a809

File tree

4 files changed

+155
-126
lines changed

4 files changed

+155
-126
lines changed

autoload/dbext.vim

Lines changed: 95 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
" dbext.vim - Commn Database Utility
22
" Copyright (C) 2002-7, Peter Bagyinszki, David Fishburn
33
" ---------------------------------------------------------------
4-
" Version: 11.01
4+
" Version: 12.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: 2009 Aug 27
8+
" Last Modified: 2010 Jul 15
99
" Based On: sqlplus.vim (author: Jamis Buck)
1010
" Created: 2002-05-24
1111
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
12-
" Contributors: Joerg Schoppet <joerg dot schoppet at web dot de>
13-
" Hari Krishna Dara <hari_vim at yahoo dot com>
12+
" Contributors: Joerg Schoppet
13+
" Hari Krishna Dara
1414
" Ron Aaron
1515
" Andi Stern
16+
" Sergey Khorev
1617
"
1718
" Help: :h dbext.txt
1819
"
@@ -37,7 +38,7 @@ if v:version < 700
3738
echomsg "dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
3839
finish
3940
endif
40-
let g:loaded_dbext_auto = 1101
41+
let g:loaded_dbext_auto = 1200
4142

4243
" call confirm("Loaded dbext autoload", "&Ok")
4344
" Script variable defaults, these are used internal and are never displayed
@@ -867,7 +868,7 @@ function! s:DB_getDefault(name)
867868
elseif a:name ==# "FIREBIRD_SQL_Top_sub" |return (exists("g:dbext_default_FIREBIRD_SQL_Top_sub")?g:dbext_default_FIREBIRD_SQL_Top_sub.'':'\1 FIRST @dbext_topX ')
868869
elseif a:name ==# "ORA_bin" |return (exists("g:dbext_default_ORA_bin")?g:dbext_default_ORA_bin.'':'sqlplus')
869870
elseif a:name ==# "ORA_cmd_header" |return (exists("g:dbext_default_ORA_cmd_header")?g:dbext_default_ORA_cmd_header.'':"" .
870-
\ "set pagesize 10000\n" .
871+
\ "set pagesize 50000\n" .
871872
\ "set wrap off\n" .
872873
\ "set sqlprompt \"\"\n" .
873874
\ "set linesize 10000\n" .
@@ -1391,7 +1392,6 @@ function! dbext#DB_checkModeline()
13911392
if rc > -1
13921393
call s:DB_validateBufferParameters()
13931394
endif
1394-
break
13951395
else
13961396
if( line(".") < from_bottom_line )
13971397
silent exec 'normal! '.from_bottom_line.'G'.col(".")."\<bar>"
@@ -1511,9 +1511,18 @@ function! dbext#DB_setMultipleOptions(multi_options, ...)
15111511
endif
15121512

15131513
" Special case due to regular expression syntax
1514-
if options_cs =~ 'variable_def_regex'
1514+
if options_cs =~ '\<variable_def_regex\>'
15151515
let opt_value = substitute(options_cs, 'variable_def_regex\s*=\s*', '', '')
1516-
call s:DB_set('variable_def_regex', opt_value)
1516+
if opt_value =~ '^,'
1517+
let l:variable_def_regex = s:DB_get('variable_def_regex')
1518+
" if escape(','.l:variable_def_regex, '\\/.*$^~[]') !~ escape(opt_value, '\\/.*$^~[]')
1519+
if ','.l:variable_def_regex !~ escape(opt_value, '\\/.*$^~[]')
1520+
" Append to existing values if not already present
1521+
call s:DB_set('variable_def_regex', l:variable_def_regex.opt_value)
1522+
endif
1523+
else
1524+
call s:DB_set('variable_def_regex', opt_value)
1525+
endif
15171526
else
15181527
" Convert the comma separated list into a List
15191528
let options_mv = split(options_cs, ':')
@@ -2847,11 +2856,11 @@ function! s:DB_ORA_execSql(str)
28472856
" Added quit to the end of the command to exit SQLPLUS
28482857
if output !~ s:DB_escapeStr(terminator) .
28492858
\ '['."\n".' \t]*$'
2850-
let output = output . terminator
2859+
let output = output . "\n" . terminator
28512860
endif
28522861

28532862
" Added quit to the end of the command to exit SQLPLUS
2854-
let output = output . "\nquit".terminator
2863+
let output = output . "\nquit"
28552864

28562865
exe 'redir! > ' . s:dbext_tempfile
28572866
silent echo output
@@ -2872,11 +2881,11 @@ function! s:DB_ORA_execSql(str)
28722881
endfunction
28732882

28742883
function! s:DB_ORA_describeTable(table_name)
2875-
return s:DB_ORA_execSql("desc " . a:table_name)
2884+
return s:DB_ORA_execSql("set linesize 100\ndesc " . a:table_name)
28762885
endfunction
28772886

28782887
function! s:DB_ORA_describeProcedure(procedure_name)
2879-
return s:DB_ORA_execSql("desc " . a:procedure_name)
2888+
return s:DB_ORA_execSql("set linesize 100\ndesc " . a:procedure_name)
28802889
endfunction
28812890

28822891
function! s:DB_ORA_getListTable(table_prefix)
@@ -2897,16 +2906,39 @@ endfunction
28972906
function! s:DB_ORA_getListProcedure(proc_prefix)
28982907
let owner = toupper(s:DB_getObjectOwner(a:proc_prefix))
28992908
let obj_name = toupper(s:DB_getObjectName(a:proc_prefix))
2900-
let query = "select object_name, owner ".
2901-
\ " from all_objects ".
2902-
\ " where object_type IN ('PROCEDURE', 'PACKAGE', 'FUNCTION') ".
2903-
\ " and object_name LIKE '".obj_name."%' "
2904-
if strlen(owner) > 0
2905-
let query = query .
2906-
\ " and owner = '".owner."' "
2909+
let pkg_name = s:DB_getObjectOwner(obj_name)
2910+
if !empty(pkg_name)
2911+
let obj_name = s:DB_getObjectName(obj_name)
2912+
endif
2913+
2914+
if !empty(owner)
2915+
if !empty(pkg_name) " schema.package.procedure
2916+
let query = "select procedure_name object_name, owner ||'.'|| object_name owner ".
2917+
\ " from all_procedures ".
2918+
\ " where object_type = 'PACKAGE' ".
2919+
\ " and procedure_name LIKE '".obj_name."%' ".
2920+
\ " and owner = '".owner."' and object_name = '".pkg_name."'"
2921+
else " schema.procedureORpackage or package.procedure
2922+
let query = "select object_name, owner ".
2923+
\ " from all_objects ".
2924+
\ " where object_type IN ('PROCEDURE', 'PACKAGE', 'FUNCTION') ".
2925+
\ " and object_name LIKE '".obj_name."%' ".
2926+
\ " and owner = '".owner."'".
2927+
\ " UNION ALL ".
2928+
\ "select procedure_name, object_name ".
2929+
\ " from all_procedures ".
2930+
\ " where object_type = 'PACKAGE' ".
2931+
\ " and object_name = '".owner."'".
2932+
\ " and procedure_name LIKE '".obj_name."%'"
2933+
endif
2934+
else " just a name
2935+
let query = "select object_name, owner ".
2936+
\ " from all_objects ".
2937+
\ " where object_type IN ('PROCEDURE', 'PACKAGE', 'FUNCTION') " .
2938+
\ " and object_name LIKE '".obj_name."%' "
29072939
endif
2908-
let query = query .
2909-
\ " order by object_name"
2940+
2941+
let query .= " order by 1"
29102942
return s:DB_ORA_execSql( query )
29112943
endfunction
29122944

@@ -2920,8 +2952,7 @@ function! s:DB_ORA_getListView(view_prefix)
29202952
let query = query .
29212953
\ " and owner = '".owner."' "
29222954
endif
2923-
let query = query .
2924-
\ " order by view_name"
2955+
let query .= " order by view_name"
29252956
return s:DB_ORA_execSql( query )
29262957
endfunction
29272958

@@ -2931,19 +2962,17 @@ function! s:DB_ORA_getListColumn(table_name) "{{{
29312962
let query = "select column_name ".
29322963
\ " from ALL_TAB_COLUMNS ".
29332964
\ " where table_name = '".table_name."' "
2934-
if strlen(owner) > 0
2935-
let query = query .
2936-
\ " and owner = '".owner."' "
2965+
if !empty(owner)
2966+
let query .= " and owner = '".owner."' "
29372967
endif
2938-
let query = query .
2939-
\ " order by column_id"
2968+
let query .= " order by column_id"
29402969
let result = s:DB_ORA_execSql( query )
29412970
return s:DB_ORA_stripHeaderFooter(result)
29422971
endfunction "}}}
29432972

29442973
function! s:DB_ORA_stripHeaderFooter(result) "{{{
29452974
" Strip off column headers ending with a newline
2946-
let stripped = substitute( a:result, '\_.*-\s*'."[\<C-J>]", '', '' )
2975+
let stripped = substitute( a:result, '^\_.\{-}[- ]\+\n', '', 'g' )
29472976
let g:dbext_rows_affected = matchstr(stripped, '\zs\d\+\ze\s\+row')
29482977
" Strip off query statistics
29492978
let stripped = substitute( stripped, '\d\+ rows\_.*', '', '' )
@@ -2957,6 +2986,7 @@ endfunction "}}}
29572986

29582987
function! s:DB_ORA_getDictionaryTable() "{{{
29592988
let result = s:DB_ORA_execSql(
2989+
\ "set pagesize 0\n".
29602990
\ "select ".(s:DB_get('dict_show_owner')==1?"owner||'.'||":'')."table_name" .
29612991
\ " from ALL_ALL_TABLES " .
29622992
\ " order by ".(s:DB_get('dict_show_owner')==1?"owner, ":'')."table_name "
@@ -2965,18 +2995,29 @@ function! s:DB_ORA_getDictionaryTable() "{{{
29652995
endfunction "}}}
29662996

29672997
function! s:DB_ORA_getDictionaryProcedure() "{{{
2968-
let result = s:DB_ORA_execSql(
2969-
\ "select ".(s:DB_get('dict_show_owner')==1?"owner||'.'||":'')."object_name " .
2998+
let query = "set pagesize 0\n".
2999+
\"select ".(s:DB_get('dict_show_owner')==1?"owner||'.'||":'')."object_name " .
29703000
\ " from all_objects " .
29713001
\ " where object_type IN " .
29723002
\ " ('PROCEDURE', 'PACKAGE', 'FUNCTION') " .
2973-
\ " order by ".(s:DB_get('dict_show_owner')==1?"owner, ":'')."object_name "
2974-
\ )
3003+
\ " UNION ALL " .
3004+
\ "select ".(s:DB_get('dict_show_owner')==1?"owner||'.'||object_name||'.'||":'')."procedure_name " .
3005+
\ " from all_procedures " .
3006+
\ " where object_type = 'PACKAGE' and procedure_name is not null "
3007+
if s:DB_get('dict_show_owner')==1
3008+
let query .= " UNION ALL " .
3009+
\ "select object_name||'.'||procedure_name " .
3010+
\ " from all_procedures " .
3011+
\ " where object_type = 'PACKAGE' and procedure_name is not null "
3012+
endif
3013+
let query .= " order by 1"
3014+
let result = s:DB_ORA_execSql(query)
29753015
return s:DB_ORA_stripHeaderFooter(result)
29763016
endfunction "}}}
29773017

29783018
function! s:DB_ORA_getDictionaryView() "{{{
29793019
let result = s:DB_ORA_execSql(
3020+
\ "set pagesize 0\n".
29803021
\ "select ".(s:DB_get('dict_show_owner')==1?"owner||'.'||":'')."view_name " .
29813022
\ " from ALL_VIEWS " .
29823023
\ " order by ".(s:DB_get('dict_show_owner')==1?"owner, ":'')."view_name "
@@ -3866,8 +3907,8 @@ function! s:DB_DBI_describeProcedure(procedure_name)
38663907

38673908
" The owner name can be optionally followed by a "." due to the syntax of
38683909
" some of the different databases (ASE and SQL Server)
3869-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner\.\?', owner, '')
3870-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, '')
3910+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner\.\?', owner, 'g')
3911+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, 'g')
38713912

38723913
let cmd = "perl db_query()"
38733914
exec cmd
@@ -4019,8 +4060,8 @@ function! s:DB_DBI_getListProcedure(proc_prefix)
40194060
return -1
40204061
endif
40214062

4022-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner', owner, '')
4023-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, '')
4063+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner', owner, 'g')
4064+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, 'g')
40244065

40254066
let cmd = "perl db_query()"
40264067
exec cmd
@@ -4433,8 +4474,8 @@ function! s:DB_ODBC_describeProcedure(procedure_name)
44334474

44344475
" The owner name can be optionally followed by a "." due to the syntax of
44354476
" some of the different databases (ASE and SQL Server)
4436-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner\.\?', owner, '')
4437-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, '')
4477+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner\.\?', owner, 'g')
4478+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, 'g')
44384479

44394480
let cmd = "perl db_query()"
44404481
exec cmd
@@ -4605,8 +4646,8 @@ function! s:DB_ODBC_getListProcedure(proc_prefix)
46054646
return -1
46064647
endif
46074648

4608-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner', owner, '')
4609-
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, '')
4649+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_owner', owner, 'g')
4650+
let g:dbext_dbi_sql = substitute(g:dbext_dbi_sql, 'dbext_replace_name', object, 'g')
46104651

46114652
let cmd = "perl db_query()"
46124653
exec cmd
@@ -5481,7 +5522,7 @@ function! s:DB_getObjectOwner(object) "{{{
54815522
" \("\|\[\)\? - ignore any quotes
54825523
" \. - must by followed by a .
54835524
" let owner = matchstr( a:object, '^\s*\zs.*\ze\.' )
5484-
let owner = matchstr( a:object, '^\("\|\[\)\?\zs\.\{-}\ze\("\|\]\)\?\.' )
5525+
let owner = matchstr( a:object, '^\("\|\[\)\?\zs.\{-}\ze\("\|\]\)\?\.' )
54855526
return owner
54865527
endfunction "}}}
54875528
function! s:DB_getObjectName(object) "{{{
@@ -7459,10 +7500,11 @@ function! s:DB_parsePerl(query)
74597500

74607501
" Prompt for the variables which are part of
74617502
" string concentations like this:
7462-
" "SELECT * FROM " + prefix+"product"
7463-
" "SELECT * FROM " + obj.method() +"product"
7503+
" "SELECT * FROM " + $prefix+"product"
7504+
" "SELECT * FROM " + $obj.method() +"product"
74647505
" "SELECT * FROM " . method() ."product"
7465-
let var_expr = '"\s*\(+\|\.\)\s*\(.\{-}\)\s*\(+\|\.\)\s*"'
7506+
" "SELECT * FROM product WHERE c1 = $mycol AND c2 = ".$cols[2];
7507+
let var_expr = '"\s*\(+\|\.\)\s*\(.\{-}\)\s*\(\(\(+\|\.\)\s*"\)\|;\|$\)'
74667508
" "\s* - Double quote followed any space
74677509
" \(+\|\.\) - A plus sign or period
74687510
" \s* - Any space
@@ -7472,6 +7514,12 @@ function! s:DB_parsePerl(query)
74727514
" \s*" - Any space followed by a double quote
74737515
let query = s:DB_searchReplace(query, var_expr, var_expr, 0)
74747516

7517+
" Prompt for $ variables
7518+
" "SELECT * FROM product WHERE c1 = $mycol "
7519+
let var_expr = '\(\$\w\+\)'
7520+
" \(\$\w\+\) - The variable / obj / method beginning with a $
7521+
let query = s:DB_searchReplace(query, var_expr, var_expr, 0)
7522+
74757523
return query
74767524
endfunction
74777525
"}}}
@@ -7583,7 +7631,7 @@ function! s:DB_parseProfile(value)
75837631
let no_defaults = 0
75847632
let rc = s:DB_resetBufferParameters(no_defaults)
75857633

7586-
if profile_value =~? 'profile'
7634+
if profile_value =~? '\<profile\>'
75877635
let rc = -1
75887636
call s:DB_warningMsg('dbext: Profiles cannot be nested' )
75897637
return -1

autoload/dbext_dbi.vim

Lines changed: 5 additions & 3 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: 11.01
7+
" Version: 12.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: 2009 Aug 27
10+
" Last Modified: 2010 Jul 15
1111
" Created: 2007-05-24
1212
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
1313
"
@@ -42,6 +42,8 @@
4242
" "C:\Program Files\Microsoft Visual Studio .Net 2003\Common7\Tools\vsvars32.bat"
4343
" or
4444
" "C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\vsvars32.bat"
45+
" or
46+
" "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
4547
" perl Makefile.PL
4648
" nmake
4749
" nmake test
@@ -114,7 +116,7 @@ if !has('perl')
114116
let g:loaded_dbext_dbi_msg = 'Vim does not have perl support enabled'
115117
finish
116118
endif
117-
let g:loaded_dbext_dbi = 1101
119+
let g:loaded_dbext_dbi = 1200
118120

119121
if !exists("dbext_dbi_debug")
120122
let g:dbext_dbi_debug = 0

0 commit comments

Comments
 (0)