[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.10, Sun Feb 27 14:05:58 2005 UTC revision 1.15, Wed May 11 18:43:19 2005 UTC
# Line 69  Line 69 
69    
70      $dbh  = $self->{_dbh};      $dbh  = $self->{_dbh};
71    
72      if ($sql =~ /^select/i)      if ($sql =~ /^\s*select/i)
73      {      {
74          my $ok = eval {          eval {
75              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);
76          };          };
77          if (!$ok)          if (!$tmp or $@)
78          {          {
79              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$@";
80              #print STDERR "DBrtns.pm error: SQL $sql failed\n";              #print STDERR "DBrtns.pm error: SQL $sql failed\n";
# Line 165  Line 165 
165      my $flds = $arg{flds};      my $flds = $arg{flds};
166      my $dbh  = $self->{_dbh};      my $dbh  = $self->{_dbh};
167      my $dbms = $self->{_dbms};      my $dbms = $self->{_dbms};
168      $dbh->do("CREATE TABLE $tbl ( $flds );");  
169        my $type;
170    
171        if ($arg{type})
172        {
173            $type = " engine = $arg{type} ";
174        }
175        $dbh->do("CREATE TABLE $tbl ( $flds ) $type;");
176  }  }
177    
178  sub load_table {  sub load_table {
# Line 177  Line 184 
184      my $delim    = $arg{delim};      my $delim    = $arg{delim};
185      my $dbh  = $self->{_dbh};      my $dbh  = $self->{_dbh};
186      my $dbms = $self->{_dbms};      my $dbms = $self->{_dbms};
187        my $result;
188    
189      if ($file)      if ($file)
190      {      {
191          if ($dbms eq "mysql")          if ($dbms eq "mysql")
192          {          {
193              $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");              $result = $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");
194          }          }
195          elsif ($dbms eq "Pg")          elsif ($dbms eq "Pg")
196          {          {
197              $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");              $result = $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");
198          }          }
199      }      }
200        return $result;
201  }  }
202    
203  sub create_index {  sub create_index {
# Line 244  Line 253 
253      }      }
254  }  }
255    
256    =pod
257    
258    =head1 get_inserted_id
259    
260    Return the last ID of a row inserted into an autonumber/serial-containing table.
261    
262    =cut
263    
264    sub get_inserted_id
265    {
266        my($self, $table, $sth) = @_;
267        if ($self->{_dbms} eq "Pg")
268        {
269            my $oid = $sth->{pg_oid_status};
270            my $ret = $self->SQL("select id from $table where oid = ?", undef, $oid);
271            return $ret->[0]->[0];
272        }
273        elsif ($self->{_dbms} eq "mysql")
274        {
275            my $id = $self->{_dbh}->{mysql_insertid};
276            # print "mysql got $id\n";
277            return $id;
278        }
279    }
280    
281    
282  #  #
283  # 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
284  # 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 303  Line 338 
338    
339      my $rc = system($exe,      my $rc = system($exe,
340                      "--datadir=$db_dir",                      "--datadir=$db_dir",
341                        "--basedir=$FIG_Config::common_runtime",
342                      "--user=$FIG_Config::dbuser");                      "--user=$FIG_Config::dbuser");
343      if ($rc != 0)      if ($rc != 0)
344      {      {
# Line 373  Line 409 
409      #      #
410      #push(@opts, "--port=$FIG_Config::dbport");      #push(@opts, "--port=$FIG_Config::dbport");
411    
412        if (@FIG_Config::db_server_startup_options)
413        {
414            push(@opts, @FIG_Config::db_server_startup_options)
415        }
416    
417      #      #
418      # 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
419      # try to use a system one.      # try to use a system one.
# Line 384  Line 425 
425          $exe = "mysqld_safe";          $exe = "mysqld_safe";
426      }      }
427    
428        print "Would run $exe @opts\n";
429    
430      my $pid = fork;      my $pid = fork;
431    
432      if ($pid == 0)      if ($pid == 0)

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3