Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for vimconfig/vim/modules/database-client.vim between version 1.6 and 1.7

version 1.6, 2004/03/08 10:55:18 version 1.7, 2004/03/12 08:13:09
Line 2 
Line 2 
 "  "
 " File:                 database-client.vim  " File:                 database-client.vim
 " Maintainer:   Lubomir Host 'rajo' <rajo AT platon.sk>  " Maintainer:   Lubomir Host 'rajo' <rajo AT platon.sk>
 " Version:              $Platon: vimconfig/vim/modules/database-client.vim,v 1.5 2004/02/29 20:01:11 rajo Exp $  " Version:              $Platon: vimconfig/vim/modules/database-client.vim,v 1.6 2004/03/08 10:55:18 rajo Exp $
 "  "
 " Copyright (c) 2003 Platon SDG, http://platon.sk/  " Copyright (c) 2003 Platon SDG, http://platon.sk/
 " Licensed under terms of GNU General Public License.  " Licensed under terms of GNU General Public License.
 " All rights reserved.  " All rights reserved.
 "  "
 " $Platon: vimconfig/vim/modules/database-client.vim,v 1.5 2004/02/29 20:01:11 rajo Exp $  " $Platon: vimconfig/vim/modules/database-client.vim,v 1.6 2004/03/08 10:55:18 rajo Exp $
 "  "
   
 " This plugin needs Perl interpreter to be enabled (+perl feature)  " This plugin needs Perl interpreter to be enabled (+perl feature)
Line 143  function! SQL_Init() " {{{
Line 143  function! SQL_Init() " {{{
   
         package main;          package main;
   
           # list of available database drivers
           @available_drivers = reverse sort DBI->available_drivers; # make "mysql" first!
   
         # return reference to array with database names          # return reference to array with database names
         sub SQL_database_list($;)          sub SQL_database_list($;)
         { # {{{          { # {{{
                 my ($dbh) = @_;                  my ($dbh) = @_;
   
                 my $sth = $dbh->prepare("SHOW DATABASES");                  my $sth = $dbh->prepare("SHOW DATABASES");
                   unless (defined $sth) {
                           VIM::Msg("Error", $dbh->errstr);
                           return;
                   }
                 $sth->execute();                  $sth->execute();
                 my @arr;                  my @arr;
   
Line 183  endfunction
Line 190  endfunction
 call SQL_Init()  call SQL_Init()
   
 " connect to database  " connect to database
 function! SQL_Connect() " {{{  " :call SQL_Connect("database_type", "server", "user", "password")
         perl << EOF  function! SQL_Connect(...) " {{{
   
   
           perl << EOF
   
         package main;          package main;
   
         # get hostname from user          my $param_count = VIM::Eval("a:0"); # number of function parameters
         $db_host = "localhost" unless (defined $db_host); # remember server name          my ($db_type, $db_host, $db_user, $db_pass);
         my ($success, $value) = VIM::Eval("inputdialog('Hostname of your database server', '$db_host')");  
         #VIM::Msg("success = $success value = $value");          if ($param_count == 0) { # {{{ check for db_type
         if ($success and $value ne '') {                  my ($success, $value) = VIM::Eval("confirm('Please, choose type of database server: ', "
                 $db_host = $value;                          . " '\&" . join("\n&", @main::available_drivers) . "\n')");
                   if ($success and $value ne '') {
                           $db_type = $main::available_drivers[--$value];
                   }
                   else {
                           return;
                   }
         }          }
         else {          else {
                 return;                  $db_type = VIM::Eval("a:1"); # get first function parameter
         }          } # }}}
           if ($param_count < 2) { # {{{ check for db_host
         # get username from user                  # get hostname from user
         $db_user = $ENV{"USER"} unless (defined $db_user); # remember username                  $db_host = "localhost" unless (defined $db_host); # remember server name
         my ($success, $value) = VIM::Eval("inputdialog('Login', '$db_user')");                  my ($success, $value) = VIM::Eval("inputdialog('Hostname of your database server: ', '$db_host')");
         if ($success and $value ne '') {                  #VIM::Msg("success = $success value = $value");
                 $db_user = $value;                  if ($success and $value ne '') {
                           $db_host = $value;
                   }
                   else {
                           return;
                   }
         }          }
         else {          else {
                 return;                  $db_host = VIM::Eval("a:2"); # get second function parameter
         }          } # }}}
           if ($param_count < 3) { # {{{ check fro db_user
         # get password from user                  # get username from user
         my ($success, $value) = VIM::Eval('inputsecret("Password: ")');                  $db_user = $ENV{"USER"} unless (defined $db_user); # remember username
         if ($success) {                  my ($success, $value) = VIM::Eval("inputdialog('Login: ', '$db_user')");
                 $db_pass = $value;                  if ($success and $value ne '') {
                           $db_user = $value;
                   }
                   else {
                           return;
                   }
         }          }
         else {          else {
                   $db_host = VIM::Eval("a:3");
           } # }}}
           if ($param_count < 4) { # {{{ check for db_pass
                   # get password from user
                   my ($success, $value) = VIM::Eval('inputsecret("Password: ")');
                   if ($success) {
                           $db_pass = $value;
                   }
                   else {
                           return;
                   }
                   }
           else {
                   $db_host = VIM::Eval("a:4");
           } # }}}
   
   
           $dbh = DBI->connect("DBI:$db_type:host=$db_host", $db_user, $db_pass,
                   { RaiseError => 0, AutoCommit => 1});
           unless (defined $dbh) {
                   VIM::Msg("Error", $DBI::errstr);
                 return;                  return;
         }          }
   
         $dbh = DBI->connect("DBI:mysql:host=$db_host", $db_user, $db_pass,  
                 { RaiseError => 0, AutoCommit => 1})  
                 or die $DBI::errstr;  
         # reconnect to database if the connection is lost          # reconnect to database if the connection is lost
         $dbh->{mysql_auto_reconnect} = 1;          if ($db_type =~ m/^mysql$/i) {
                   $dbh->{mysql_auto_reconnect} = 1;
           }
   
         my $key   = "$db_host; $db_user;";          my $key   = "$db_host; $db_user;";
         my $ext   = "";          my $ext   = "";
         my $index = 2;          my $index = 2;
Line 236  function! SQL_Connect() " {{{
Line 281  function! SQL_Connect() " {{{
         if (defined $dbh) {          if (defined $dbh) {
                 $main::connections->{$key} = {                  $main::connections->{$key} = {
                         'dbh'   => $dbh,                          'dbh'   => $dbh,
                         'desc'  => "$db_user\@$db_host$ext",                          'type'  => $db_type,
                           'desc'  => "$db_user\@$db_host$ext [$db_type]",
                         'list_databases'        => 1,                          'list_databases'        => 1,
                         'databases'     => SQL_database_list($dbh),                          'databases'     => SQL_database_list($dbh),
                 };                  };
                 $main::current_conn = $key;                  $main::current_conn = $key;
         }          }
         else {          else {
                 undef $main::connections->{$key}->{dbh};  
                 undef $main::connections->{$key}->{desc};  
                 undef $main::connections->{$key};                  undef $main::connections->{$key};
         }          }
         undef $key, $ext, $index; # cleanup          undef $key, $ext, $index; # cleanup
Line 442  endfunction
Line 486  endfunction
 " }}}  " }}}
 call SQL_CreateMenu()  call SQL_CreateMenu()
   
 function! s:CloseWindow(winnum) " {{{  
         " if window exists  
         if a:winnum >= 0  
                 execute "normal \<c-w>" . a:winnum . "w"  
                 silent! close  
         endif  
 endfunction  
 " }}}  
   
 " create windows  " create windows
 function! SQL_CreateWindows() " {{{  function! SQL_CreateWindows() " {{{
         let s:main_winnum = bufwinnr(g:SQL_main_window_title)          let s:main_winnum = bufwinnr(g:SQL_main_window_title)
Line 533  function! s:SQL_Display_Help()
Line 568  function! s:SQL_Display_Help()
         endif          endif
 endfunction  endfunction
 " }}}  " }}}
   
   " s:CloseWindow() {{{
   function! s:CloseWindow(winnum)
           " if window exists
           if a:winnum >= 0
                   execute "normal \<c-w>" . a:winnum . "w"
                   silent! close
           endif
   endfunction
   " }}}
   
 " s:SQL_Toggle_Help_Text() {{{  " s:SQL_Toggle_Help_Text() {{{
 " Toggle SQL plugin help text between the full version and the brief  " Toggle SQL plugin help text between the full version and the brief

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top