[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.5, Mon Nov 1 20:20:09 2004 UTC revision 1.12, Fri Apr 8 08:32:10 2005 UTC
# Line 59  Line 59 
59  }  }
60    
61  sub SQL {  sub SQL {
62      my($self,$sql,$verbose) = @_;      my($self, $sql, $verbose, @bind_values) = @_;
63      my($dbh,$sth,$rc,$tmp);      my($dbh,$sth,$rc,$tmp);
64    
65      if ($verbose)      if ($verbose)
# 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          $tmp = $dbh->selectall_arrayref($sql);          my $ok = eval {
75                $tmp = $dbh->selectall_arrayref($sql, undef, @bind_values);
76            };
77            if (!$ok)
78            {
79                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);          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 119  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 218  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).
# Line 340  Line 392 
392      push(@opts, "--basedir=$FIG_Config::common_runtime");      push(@opts, "--basedir=$FIG_Config::common_runtime");
393      push(@opts, "--datadir=$FIG_Config::db_datadir");      push(@opts, "--datadir=$FIG_Config::db_datadir");
394      push(@opts, "--ledir=$FIG_Config::common_runtime/libexec");      push(@opts, "--ledir=$FIG_Config::common_runtime/libexec");
395        push(@opts, "--old-password");
396        push(@opts, "--max-allowed-packet=128M");
397      #      #
398      # Oddly, this doesn't seem to work. need to set the environment variable.      # Oddly, this doesn't seem to work. need to set the environment variable.
399      #      #

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.12

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3