Skip to content

Commit 035f7de

Browse files
bagyi0vim-scripts
authored andcommitted
Version 5.20
Posted by David Fishburn. New Features ------------ - When using DBI or DBI::ODBC null fields are now displayed as NULL instead of empty spaces (now you can distinguish between them). - When using DBI or DBI::ODBC you can specify the column separator :let g:dbext_default_dbi_column_delimiter="\t" (Jean-Christophe Clavier) - When using DBI or DBI::ODBC and you use a vertical orientation for the result set, if there are any embedded newline characters in your data this will be displayed and shifted to align with the column above. Prior to this all newlines were stripped from the output when printing to preserve standard horizontal output (Jean-Christophe Clavier).
1 parent d6dbd33 commit 035f7de

File tree

4 files changed

+80
-28
lines changed

4 files changed

+80
-28
lines changed

autoload/dbext.vim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
" dbext.vim - Commn Database Utility
22
" Copyright (C) 2002-7, Peter Bagyinszki, David Fishburn
33
" ---------------------------------------------------------------
4-
" Version: 5.11
4+
" Version: 5.20
55
" Maintainer: David Fishburn <[email protected]>
66
" Authors: Peter Bagyinszki <[email protected]>
77
" David Fishburn <[email protected]>
8-
" Last Modified: Mon 10 Sep 2007 09:34:14 AM Eastern Daylight Time
8+
" Last Modified: Sat 15 Sep 2007 11:09:57 PM Eastern Daylight Time
99
" Based On: sqlplus.vim (author: Jamis Buck)
1010
" Created: 2002-05-24
1111
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
@@ -39,7 +39,7 @@ if v:version < 700
3939
echomsg "dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
4040
finish
4141
endif
42-
let g:loaded_dbext_auto = 511
42+
let g:loaded_dbext_auto = 520
4343

4444
" call confirm("Loaded dbext autoload", "&Ok")
4545
" Script variable defaults, these are used internal and are never displayed
@@ -167,6 +167,7 @@ function! s:DB_buildLists()
167167
call add(s:config_dbi_mv, 'DBI_read_file_cmd')
168168
call add(s:config_dbi_mv, 'DBI_cmd_terminator')
169169
call add(s:config_dbi_mv, 'DBI_orientation')
170+
call add(s:config_dbi_mv, 'DBI_column_delimiter')
170171

171172
" DBI connection attributes
172173
let s:db_dbi_mv = []
@@ -855,6 +856,7 @@ function! s:DB_getDefault(name)
855856
elseif a:name ==# "DBI_read_file_cmd" |return (exists("g:dbext_default_DBI_read_file_cmd")?g:dbext_default_DBI_read_file_cmd.'':'read ')
856857
elseif a:name ==# "DBI_cmd_terminator" |return (exists("g:dbext_default_DBI_cmd_terminator")?g:dbext_default_DBI_cmd_terminator.'':';')
857858
elseif a:name ==# "DBI_orientation" |return (exists("g:dbext_default_DBI_orientation")?g:dbext_default_DBI_orientation.'':'horizontal')
859+
elseif a:name ==# "DBI_column_delimiter" |return (exists("g:dbext_default_DBI_column_delimiter")?g:dbext_default_DBI_column_delimiter.'':" ")
858860
elseif a:name ==# "DBI_table_type" |return (exists("g:dbext_default_DBI_table_type")?g:dbext_default_DBI_table_type.'':'TABLE')
859861
elseif a:name ==# "DBI_view_type" |return (exists("g:dbext_default_DBI_view_type")?g:dbext_default_DBI_view_type.'':'VIEW')
860862
elseif a:name ==# "DBI_trace_level" |return (exists("g:dbext_default_DBI_trace_level")?g:dbext_default_DBI_trace_level.'':'2')

autoload/dbext_dbi.vim

Lines changed: 49 additions & 20 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: 5.11
7+
" Version: 5.20
88
" Maintainer: David Fishburn <[email protected]>
99
" Authors: David Fishburn <[email protected]>
10-
" Last Modified: Mon 10 Sep 2007 09:35:04 AM Eastern Daylight Time
10+
" Last Modified: Sat 15 Sep 2007 11:05:29 PM Eastern Daylight Time
1111
" Created: 2007-05-24
1212
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
1313
"
@@ -120,7 +120,7 @@ if !has('perl')
120120
let g:loaded_dbext_dbi_msg = 'Vim does not have perl support enabled'
121121
finish
122122
endif
123-
let g:loaded_dbext_dbi = 511
123+
let g:loaded_dbext_dbi = 520
124124

125125
if !exists("dbext_dbi_debug")
126126
let g:dbext_dbi_debug = 0
@@ -137,8 +137,11 @@ endif
137137
if !exists("dbext_dbi_max_rows")
138138
let g:dbext_dbi_max_rows = 300
139139
endif
140+
if !exists("dbext_default_dbi_column_delimiter")
141+
let g:dbext_default_dbi_column_delimiter = " "
142+
endif
140143
if !exists("dbext_dbi_trace_level")
141-
let g:dbext_dbi_trace_level = 2
144+
let g:dbext_dbi_trace_level = 0
142145
endif
143146

144147
" See help use-cpo-save for info on the variable save_cpo
@@ -184,9 +187,11 @@ my @result_set;
184187
my @result_col_length;
185188
my $result_max_col_width;
186189
my $max_rows = 300;
190+
my $min_col_width = 4; # First NULL
187191
my $test_inc = 0;
188192
my $conn_inc = 0;
189193
my $dbext_dbi_sql = "";
194+
my $col_sep_vert = " ";
190195
my $debug = db_is_debug();
191196

192197

@@ -252,8 +257,10 @@ sub db_vim_eval
252257
db_set_vim_var('msg', '"db_vim_print"');
253258
sub db_vim_print
254259
{
255-
my $line_nbr = shift;
256-
my $line_txt = shift;
260+
my $line_nbr = shift;
261+
my $line_txt = shift;
262+
my $printed_lines = 0;
263+
my $max_col_width = $result_max_col_width + 2;
257264

258265
if ( ! defined($line_nbr) ) {
259266
db_echo('db_vim_print invalid line number');
@@ -264,7 +271,28 @@ sub db_vim_print
264271
$line_txt = "";
265272
}
266273

267-
$main::curbuf->Append($line_nbr, $line_txt);
274+
my @lines = split("\n", $line_txt);
275+
276+
foreach my $line (@lines) {
277+
if ( $printed_lines > 0 ) {
278+
# Multiple lines will only be within the string if the
279+
# user is printing in a vertical orientation.
280+
# Therefore if the printed_lines is > 1 we know
281+
# we have split the column data and we need to prepend
282+
# blanks to line up the text with the data above.
283+
$line = (' ' x $max_col_width).$line;
284+
}
285+
$main::curbuf->Append($line_nbr, $line);
286+
$line_nbr++;
287+
$printed_lines++;
288+
}
289+
return $printed_lines;
290+
}
291+
292+
db_set_vim_var('msg', '"db_get_defaults"');
293+
sub db_get_defaults
294+
{
295+
$col_sep_vert = db_vim_eval('g:dbext_default_dbi_column_delimiter');
268296
}
269297

270298
db_set_vim_var('msg', '"db_escape"');
@@ -745,16 +773,15 @@ sub db_format_results
745773
my @table;
746774
my @headers;
747775

748-
# TODO
749-
# Check for the existence of this array first, some statements may not actually
750-
# define this array if there are no columns coming back.
751-
# mysql does this with a COMMIT statement for example
776+
# Check if the NUM_OF_FIELDS is > 0.
777+
# In mysql a COMMIT does not provide a result set.
752778
if ( $sth->{NUM_OF_FIELDS} > 0 ) {
753779
# Add the column list to the array
754780
push @headers,[ @{$sth->{NAME}} ];
755781
# Set the initial length of the columns
756782
foreach my $col_name ( @{$sth->{NAME}} ) {
757783
$temp_length = length($col_name);
784+
$temp_length = ($temp_length > $min_col_width ? $temp_length : $min_col_width);
758785
$max_col_width = ( $temp_length > $max_col_width ? $temp_length : $max_col_width );
759786
$col_length[$i] = $temp_length;
760787
$i++;
@@ -832,9 +859,8 @@ sub db_format_array()
832859
# blank padding each string.
833860
# Add an additional 3 spaces between columns.
834861
foreach my $col2 ( @{$row2} ) {
835-
$fragment = substr ((defined($col2)?$col2:"").(' ' x $result_col_length[$i]), 0, $result_col_length[$i]);
836-
# $result = $result.db_remove_newlines($fragment).' ';
837-
$col2 = db_remove_newlines($fragment);
862+
$fragment = substr ((defined($col2)?$col2:"NULL").(' ' x $result_col_length[$i]), 0, $result_col_length[$i]);
863+
$col2 = $fragment;
838864
$i++;
839865
}
840866
# Finally, escape any double quotes with a preceeding slash
@@ -872,7 +898,7 @@ sub db_print_results
872898
# Add an additional 3 spaces between columns.
873899
foreach my $col2 ( @{$row2} ) {
874900
$fragment = substr ((defined($col2)?$col2:"").(' ' x $result_col_length[$i]), 0, $result_col_length[$i]);
875-
$line .= db_remove_newlines($fragment).' ';
901+
$line .= db_remove_newlines($fragment).$col_sep_vert;
876902
$i++;
877903
}
878904
# Finally, escape any double quotes with a preceeding slash
@@ -884,7 +910,7 @@ sub db_print_results
884910
$i = 0;
885911
$line = "";
886912
while ($i < scalar(@result_col_length) ) {
887-
$line .= '-' x $result_col_length[$i].' ';
913+
$line .= '-' x $result_col_length[$i].$col_sep_vert;
888914
$i++;
889915
}
890916
db_vim_print($last_line, db_escape($line));
@@ -896,9 +922,9 @@ sub db_print_results
896922
# db_echo("db_print_results: row count:$row_count");
897923
$line = "";
898924
foreach my $col3 ( @{$row3} ) {
899-
$line .= $col3.' ';
925+
$line .= $col3.$col_sep_vert;
900926
}
901-
db_vim_print($last_line, db_escape($line));
927+
db_vim_print($last_line, db_remove_newlines(db_escape($line)));
902928
$last_line++;
903929
}
904930
} else {
@@ -918,18 +944,20 @@ sub db_print_results
918944
$i++;
919945
}
920946

947+
my $lines_printed = 0;
921948
foreach my $row4 ( @result_set ) {
922949
$row_count++;
923950
# db_echo("db_print_results: row count:$row_count");
924951
$col_nbr = 0;
925952
db_vim_print($last_line, "****** Row: $row_count ******");
926953
$last_line++;
954+
$lines_printed = 0;
927955
foreach my $col4 ( @{$row4} ) {
928956
$fragment = "";
929957
$line = "";
930958
$line .= $formatted_headers[$col_nbr].' '.$col4;
931-
db_vim_print($last_line, db_escape($line));
932-
$last_line++;
959+
$lines_printed = db_vim_print($last_line, db_escape($line));
960+
$last_line += $lines_printed;
933961
$col_nbr++;
934962
}
935963
}
@@ -1208,6 +1236,7 @@ sub db_odbc_catalogue
12081236

12091237
return 0;
12101238
}
1239+
db_get_defaults();
12111240
db_set_vim_var('msg', '"Perl subroutines ready"');
12121241
db_set_vim_var('result', '""');
12131242

doc/dbext.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*dbext.txt* For Vim version 6.0. Last change: Mon 10 Sep 2007 09:35:41 AM Eastern Daylight Time
1+
*dbext.txt* For Vim version 6.0. Last change: Sat 15 Sep 2007 11:09:13 PM Eastern Daylight Time
22

33

44
VIM REFERENCE MANUAL
@@ -7,7 +7,7 @@
77
Peter Bagyinszki <[email protected]>
88

99
Database extension plugin (dbext.vim) manual
10-
dbext.vim version 5.11
10+
dbext.vim version 5.20
1111

1212
For instructions on installing this file, type
1313
:help add-local-help
@@ -55,6 +55,22 @@ Homepage: http://vim.sourceforge.net/script.php?script_id=356
5555
==============================================================================
5656
What's New *dbext-new*
5757

58+
Version 5.20
59+
60+
New Features
61+
------------
62+
- When using DBI or DBI::ODBC null fields are now displayed as NULL
63+
instead of empty spaces (now you can distinguish between them).
64+
- When using DBI or DBI::ODBC you can specify the column separator let
65+
g:dbext_default_dbi_column_delimiter="\t" (Jean-Christophe Clavier)
66+
- When using DBI or DBI::ODBC and you use a vertical orientation for the
67+
result set, if there are any embedded newline characters in your
68+
data this will be displayed and shifted to align with the column
69+
above. Prior to this all newlines were stripped from the output
70+
when printing to preserve standard horizontal output (Jean-Christophe
71+
Clavier).
72+
73+
5874
Version 5.11
5975

6076
New Features
@@ -767,6 +783,11 @@ Version 2.00
767783
--- --------- ------------
768784
101 Michaels Devlin
769785
102 Beth Reiser
786+
dbext_default_DBI_column_delimiter
787+
< - By default, each column is separated by 2 spaces. It is often
788+
desirable to tab delimit the columns. You can specify whatever
789+
string you like by setting (NOTE: the use of the double quotes): >
790+
:let g:dbext_default_DBI_column_delimiter = "\t"
770791
<
771792
Buffer variables
772793
You can check all options for the buffer without specifying an option name

plugin/dbext.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
" Copyright (C) 2002-7, Peter Bagyinszki, David Fishburn
33
"
44
" ---------------------------------------------------------------
5-
" Version: 5.11
5+
" Version: 5.20
66
" Maintainer: David Fishburn <[email protected]>
77
" Authors: Peter Bagyinszki <[email protected]>
88
" David Fishburn <[email protected]>
9-
" Last Modified: Mon 10 Sep 2007 09:35:21 AM Eastern Daylight Time
9+
" Last Modified: Sat 15 Sep 2007 11:09:30 PM Eastern Daylight Time
1010
" Based On: sqlplus.vim (author: Jamis Buck)
1111
" Created: 2002-05-24
1212
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
@@ -39,7 +39,7 @@ if v:version < 700
3939
echomsg "dbext: Version 4.00 or higher requires Vim7. Version 3.50 can stil be used with Vim6."
4040
finish
4141
endif
42-
let g:loaded_dbext = 511
42+
let g:loaded_dbext = 520
4343

4444
" Commands {{{
4545
command! -nargs=+ DBExecSQL :call dbext#DB_execSql(<q-args>)

0 commit comments

Comments
 (0)