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 <fishburn@ianywhere.com>
99" Authors: David Fishburn <fishburn@ianywhere.com>
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
122122endif
123- let g: loaded_dbext_dbi = 511
123+ let g: loaded_dbext_dbi = 520
124124
125125if ! exists (" dbext_dbi_debug" )
126126 let g: dbext_dbi_debug = 0
@@ -137,8 +137,11 @@ endif
137137if ! exists (" dbext_dbi_max_rows" )
138138 let g: dbext_dbi_max_rows = 300
139139endif
140+ if ! exists (" dbext_default_dbi_column_delimiter" )
141+ let g: dbext_default_dbi_column_delimiter = " "
142+ endif
140143if ! exists (" dbext_dbi_trace_level" )
141- let g: dbext_dbi_trace_level = 2
144+ let g: dbext_dbi_trace_level = 0
142145endif
143146
144147" See help use-cpo-save for info on the variable save_cpo
@@ -184,9 +187,11 @@ my @result_set;
184187my @r esult_col_length;
185188my $result_max_col_width ;
186189my $max_rows = 300 ;
190+ my $min_col_width = 4 ; # First NULL
187191my $test_inc = 0 ;
188192my $conn_inc = 0 ;
189193my $dbext_dbi_sql = " " ;
194+ my $col_sep_vert = " " ;
190195my $debug = db_is_debug ();
191196
192197
@@ -252,8 +257,10 @@ sub db_vim_eval
252257db_set_vim_var (' msg' , ' "db_vim_print"' );
253258sub 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 @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' );
268296}
269297
270298db_set_vim_var (' msg' , ' "db_escape"' );
@@ -745,16 +773,15 @@ sub db_format_results
745773 my @t able;
746774 my @h eaders;
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 @h eaders,[ @ {$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 (@r esult_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 ( @r esult_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 ();
12111240db_set_vim_var (' msg' , ' "Perl subroutines ready"' );
12121241db_set_vim_var (' result' , ' ""' );
12131242
0 commit comments