[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.9, Sat Feb 26 23:32:45 2005 UTC revision 1.14, Thu Apr 21 17:56:29 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 138  Line 138 
138      {      {
139          $cmd = "DROP TABLE IF EXISTS $tbl;" ;          $cmd = "DROP TABLE IF EXISTS $tbl;" ;
140      }      }
141        elsif ($dbms eq "Pg")
142        {
143            if ($self->table_exists($tbl))
144            {
145                $cmd = "DROP TABLE $tbl CASCADE;" ;
146            }
147        }
148      else      else
149      {      {
150          if ($self->table_exists($tbl))          if ($self->table_exists($tbl))
# Line 170  Line 177 
177      my $delim    = $arg{delim};      my $delim    = $arg{delim};
178      my $dbh  = $self->{_dbh};      my $dbh  = $self->{_dbh};
179      my $dbms = $self->{_dbms};      my $dbms = $self->{_dbms};
180        my $result;
181    
182      if ($file)      if ($file)
183      {      {
184          if ($dbms eq "mysql")          if ($dbms eq "mysql")
185          {          {
186              $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");              $result = $dbh->do("LOAD DATA LOCAL INFILE '$file' REPLACE INTO TABLE $tbl;");
187          }          }
188          elsif ($dbms eq "Pg")          elsif ($dbms eq "Pg")
189          {          {
190              $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");              $result = $dbh->do("COPY $tbl FROM '$file' USING DELIMITERS '$delim';");
191          }          }
192      }      }
193        return $result;
194  }  }
195    
196  sub create_index {  sub create_index {
# Line 237  Line 246 
246      }      }
247  }  }
248    
249    =pod
250    
251    =head1 get_inserted_id
252    
253    Return the last ID of a row inserted into an autonumber/serial-containing table.
254    
255    =cut
256    
257    sub get_inserted_id
258    {
259        my($self, $table, $sth) = @_;
260        if ($self->{_dbms} eq "Pg")
261        {
262            my $oid = $sth->{pg_oid_status};
263            my $ret = $self->SQL("select id from $table where oid = ?", undef, $oid);
264            return $ret->[0]->[0];
265        }
266        elsif ($self->{_dbms} eq "mysql")
267        {
268            my $id = $self->{_dbh}->{mysql_insertid};
269            # print "mysql got $id\n";
270            return $id;
271        }
272    }
273    
274    
275  #  #
276  # 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
277  # 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).

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.14

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3