[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.7, Tue Jan 11 18:59:39 2005 UTC revision 1.12, Fri Apr 8 08:32:10 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 {          my $ok = eval {
75              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);              $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);
76          };          };
77          if (!$ok)          if (!$ok)
78          {          {
79              confess $@;              confess "Try running 'load_links' and 'load_attributes' to fix this error:\n$@";
80                #print STDERR "DBrtns.pm error: SQL $sql failed\n";
81                #return;
82          }          }
83          return $tmp;          return $tmp;
84      }      }
85      else      else
86      {      {
87          return $dbh->do($sql, undef, @bind_values);          my $rc;
88            my $ok = eval {
89                $rc = $dbh->do($sql, undef, @bind_values);
90            };
91    
92            if (!$ok)
93            {
94                confess "query failed: " . substr($sql, 0, 100) . ": $@";
95            }
96            return $rc;
97    
98    
99  #       $sth = $dbh->prepare($sql)  #       $sth = $dbh->prepare($sql)
100  #           or die "prepare failed: $DBI::errstr";  #           or die "prepare failed: $DBI::errstr";
101  #       $sth->execute()  #       $sth->execute()
# Line 125  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 224  Line 244 
244      }      }
245  }  }
246    
247    =pod
248    
249    =head1 get_inserted_id
250    
251    Return the last ID of a row inserted into an autonumber/serial-containing table.
252    
253    =cut
254    
255    sub get_inserted_id
256    {
257        my($self, $table, $sth) = @_;
258        if ($self->{_dbms} eq "Pg")
259        {
260            my $oid = $sth->{pg_oid_status};
261            my $ret = $self->SQL("select id from $table where oid = ?", undef, $oid);
262            return $ret->[0]->[0];
263        }
264        elsif ($self->{_dbms} eq "mysql")
265        {
266            my $id = $self->{_dbh}->{mysql_insertid};
267            # print "mysql got $id\n";
268            return $id;
269        }
270    }
271    
272    
273  #  #
274  # 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
275  # 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.7  
changed lines
  Added in v.1.12

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3