4
4
" It adds transaction support and the ability
5
5
" to reach any database currently supported
6
6
" by Perl and DBI.
7
- " Version: 5.11
7
+ " Version: 5.20
8
8
" Maintainer: David Fishburn <[email protected] >
9
9
" 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
11
11
" Created: 2007-05-24
12
12
" Homepage: http://vim.sourceforge.net/script.php?script_id=356
13
13
"
@@ -120,7 +120,7 @@ if !has('perl')
120
120
let g: loaded_dbext_dbi_msg = ' Vim does not have perl support enabled'
121
121
finish
122
122
endif
123
- let g: loaded_dbext_dbi = 511
123
+ let g: loaded_dbext_dbi = 520
124
124
125
125
if ! exists (" dbext_dbi_debug" )
126
126
let g: dbext_dbi_debug = 0
@@ -137,8 +137,11 @@ endif
137
137
if ! exists (" dbext_dbi_max_rows" )
138
138
let g: dbext_dbi_max_rows = 300
139
139
endif
140
+ if ! exists (" dbext_default_dbi_column_delimiter" )
141
+ let g: dbext_default_dbi_column_delimiter = " "
142
+ endif
140
143
if ! exists (" dbext_dbi_trace_level" )
141
- let g: dbext_dbi_trace_level = 2
144
+ let g: dbext_dbi_trace_level = 0
142
145
endif
143
146
144
147
" See help use-cpo-save for info on the variable save_cpo
@@ -184,9 +187,11 @@ my @result_set;
184
187
my @r esult_col_length;
185
188
my $result_max_col_width ;
186
189
my $max_rows = 300 ;
190
+ my $min_col_width = 4 ; # First NULL
187
191
my $test_inc = 0 ;
188
192
my $conn_inc = 0 ;
189
193
my $dbext_dbi_sql = " " ;
194
+ my $col_sep_vert = " " ;
190
195
my $debug = db_is_debug ();
191
196
192
197
@@ -252,8 +257,10 @@ sub db_vim_eval
252
257
db_set_vim_var (' msg' , ' "db_vim_print"' );
253
258
sub db_vim_print
254
259
{
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 ;
257
264
258
265
if ( ! defined ($line_nbr ) ) {
259
266
db_echo (' db_vim_print invalid line number' );
@@ -264,7 +271,28 @@ sub db_vim_print
264
271
$line_txt = " " ;
265
272
}
266
273
267
- $main ::curbuf- >Append ($line_nbr , $line_txt );
274
+ my @l ines = split (" \n " , $line_txt );
275
+
276
+ foreach my $line (@l ines) {
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' );
268
296
}
269
297
270
298
db_set_vim_var (' msg' , ' "db_escape"' );
@@ -745,16 +773,15 @@ sub db_format_results
745
773
my @t able;
746
774
my @h eaders;
747
775
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 .
752
778
if ( $sth - >{NUM_OF_FIELDS} > 0 ) {
753
779
# Add the column list to the array
754
780
push @h eaders,[ @ {$sth - >{NAME}} ];
755
781
# Set the initial length of the columns
756
782
foreach my $col_name ( @ {$sth - >{NAME}} ) {
757
783
$temp_length = length ($col_name );
784
+ $temp_length = ($temp_length > $min_col_width ? $temp_length : $min_col_width );
758
785
$max_col_width = ( $temp_length > $max_col_width ? $temp_length : $max_col_width );
759
786
$col_length [$i ] = $temp_length ;
760
787
$i ++ ;
@@ -832,9 +859,8 @@ sub db_format_array()
832
859
# blank padding each string .
833
860
# Add an additional 3 spaces between columns .
834
861
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 ;
838
864
$i ++ ;
839
865
}
840
866
# Finally, escape any double quotes with a preceeding slash
@@ -872,7 +898,7 @@ sub db_print_results
872
898
# Add an additional 3 spaces between columns .
873
899
foreach my $col2 ( @ {$row2 } ) {
874
900
$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 ;
876
902
$i ++ ;
877
903
}
878
904
# Finally, escape any double quotes with a preceeding slash
@@ -884,7 +910,7 @@ sub db_print_results
884
910
$i = 0 ;
885
911
$line = " " ;
886
912
while ($i < scalar (@r esult_col_length) ) {
887
- $line .= ' -' x $result_col_length [$i ].' ' ;
913
+ $line .= ' -' x $result_col_length [$i ].$col_sep_vert ;
888
914
$i ++ ;
889
915
}
890
916
db_vim_print ($last_line , db_escape ($line ));
@@ -896,9 +922,9 @@ sub db_print_results
896
922
# db_echo (" db_print_results: row count:$row_count" );
897
923
$line = " " ;
898
924
foreach my $col3 ( @ {$row3 } ) {
899
- $line .= $col3 .' ' ;
925
+ $line .= $col3 .$col_sep_vert ;
900
926
}
901
- db_vim_print ($last_line , db_escape ($line ));
927
+ db_vim_print ($last_line , db_remove_newlines ( db_escape ($line ) ));
902
928
$last_line ++ ;
903
929
}
904
930
} else {
@@ -918,18 +944,20 @@ sub db_print_results
918
944
$i ++ ;
919
945
}
920
946
947
+ my $lines_printed = 0 ;
921
948
foreach my $row4 ( @r esult_set ) {
922
949
$row_count ++ ;
923
950
# db_echo (" db_print_results: row count:$row_count" );
924
951
$col_nbr = 0 ;
925
952
db_vim_print ($last_line , " ****** Row: $row_count ******" );
926
953
$last_line ++ ;
954
+ $lines_printed = 0 ;
927
955
foreach my $col4 ( @ {$row4 } ) {
928
956
$fragment = " " ;
929
957
$line = " " ;
930
958
$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 ;
933
961
$col_nbr ++ ;
934
962
}
935
963
}
@@ -1208,6 +1236,7 @@ sub db_odbc_catalogue
1208
1236
1209
1237
return 0 ;
1210
1238
}
1239
+ db_get_defaults ();
1211
1240
db_set_vim_var (' msg' , ' "Perl subroutines ready"' );
1212
1241
db_set_vim_var (' result' , ' ""' );
1213
1242
0 commit comments