[Bio] / FigKernelPackages / DBrtns.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/DBrtns.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11, Thu Apr 7 17:31:59 2005 UTC revision 1.16, Tue May 17 16:04:08 2005 UTC
# Line 15  Line 15 
15      $dbname = defined($dbname) ? $dbname : $FIG_Config::db;      $dbname = defined($dbname) ? $dbname : $FIG_Config::db;
16      $dbuser = defined($dbuser) ? $dbuser : $FIG_Config::dbuser;      $dbuser = defined($dbuser) ? $dbuser : $FIG_Config::dbuser;
17      $dbpass = defined($dbpass) ? $dbpass : $FIG_Config::dbpass;      $dbpass = defined($dbpass) ? $dbpass : $FIG_Config::dbpass;
     $dbpass = defined($dbpass) ? $dbpass : $FIG_Config::dbpass;  
18      $dbport = defined($dbport) ? $dbport : $FIG_Config::dbport;      $dbport = defined($dbport) ? $dbport : $FIG_Config::dbport;
19    
20      my @opts;      my @opts;
# Line 69  Line 68 
68    
69      $dbh  = $self->{_dbh};      $dbh  = $self->{_dbh};
70    
71      if ($sql =~ /^select/i)      if ($sql =~ /^\s*select/i)
72      {      {
73          my $ok = eval {          eval {
74              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);
75          };          };
76          if (!$ok)          if (!$tmp or $@)
77          {          {
78              confess "Try running 'load_links' and 'load_attributes' to fix this error:\n$@";              confess "Try running 'load_links' and 'load_attributes' to fix this error:\n$@";
79              #print STDERR "DBrtns.pm error: SQL $sql failed\n";              #print STDERR "DBrtns.pm error: SQL $sql failed\n";
# Line 165  Line 164 
164      my $flds = $arg{flds};      my $flds = $arg{flds};
165      my $dbh  = $self->{_dbh};      my $dbh  = $self->{_dbh};
166      my $dbms = $self->{_dbms};      my $dbms = $self->{_dbms};
167      $dbh->do("CREATE TABLE $tbl ( $flds );");      my $type;
168    
169        if ($arg{type})
170        {
171            $type = " engine = $arg{type} ";
172        }
173    
174        eval {
175            $dbh->do("CREATE TABLE $tbl ( $flds ) $type;");
176        };
177        if ($@)
178        {
179            confess "create table $tbl failed: $@";
180        }
181  }  }
182    
183  sub load_table {  sub load_table {
# Line 177  Line 189 
189      my $delim    = $arg{delim};      my $delim    = $arg{delim};
190      my $dbh  = $self->{_dbh};      my $dbh  = $self->{_dbh};
191      my $dbms = $self->{_dbms};      my $dbms = $self->{_dbms};
192        my $result;
193    
194      if ($file)      if ($file)
195      {      {
196          if ($dbms eq "mysql")          if ($dbms eq "mysql")
197          {          {
198              $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");              $result = $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");
199          }          }
200          elsif ($dbms eq "Pg")          elsif ($dbms eq "Pg")
201          {          {
202              $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");              $result = $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");
203          }          }
204      }      }
205        return $result;
206  }  }
207    
208  sub create_index {  sub create_index {
# Line 269  Line 283 
283      }      }
284  }  }
285    
   
286  #  #
287  # Following are database administration routines. They create an instance of a ServerAdmin class  # Following are database administration routines. They create an instance of a ServerAdmin class
288  # for the appropriate server type (in order to eliminate the if mysql / if pg / etc stuff).  # for the appropriate server type (in order to eliminate the if mysql / if pg / etc stuff).
# Line 329  Line 342 
342    
343      my $rc = system($exe,      my $rc = system($exe,
344                      "--datadir=$db_dir",                      "--datadir=$db_dir",
345                        "--basedir=$FIG_Config::common_runtime",
346                      "--user=$FIG_Config::dbuser");                      "--user=$FIG_Config::dbuser");
347      if ($rc != 0)      if ($rc != 0)
348      {      {
# Line 378  Line 392 
392    
393  sub start_server  sub start_server
394  {  {
395      my($self) = @_;      my($self, $dont_fork) = @_;
396    
397      print "Starting mysql server\n";      print "Starting mysql server\n";
398    
# Line 399  Line 413 
413      #      #
414      #push(@opts, "--port=$FIG_Config::dbport");      #push(@opts, "--port=$FIG_Config::dbport");
415    
416        if (@FIG_Config::db_server_startup_options)
417        {
418            push(@opts, @FIG_Config::db_server_startup_options)
419        }
420    
421      #      #
422      # We are going to assume that if mysql has shipped with this release, we'll use it. Otherwise      # We are going to assume that if mysql has shipped with this release, we'll use it. Otherwise
423      # try to use a system one.      # try to use a system one.
# Line 410  Line 429 
429          $exe = "mysqld_safe";          $exe = "mysqld_safe";
430      }      }
431    
432        if ($dont_fork)
433        {
434            $ENV{MYSQL_TCP_PORT} = $FIG_Config::dbport;
435            exec $exe, @opts;
436        }
437        else
438        {
439      my $pid = fork;      my $pid = fork;
440    
441      if ($pid == 0)      if ($pid == 0)
# Line 419  Line 445 
445          $ENV{MYSQL_TCP_PORT} = $FIG_Config::dbport;          $ENV{MYSQL_TCP_PORT} = $FIG_Config::dbport;
446          exec $exe, @opts;          exec $exe, @opts;
447      }      }
   
448      print "Forked db server $pid\n";      print "Forked db server $pid\n";
449  }  }
450    
451    }
452    
453    
454  1  1

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.16

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3