[Bio] / Clearinghouse / utils.pm Repository:
ViewVC logotype

Diff of /Clearinghouse/utils.pm

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

revision 1.7, Wed Jan 11 21:19:21 2006 UTC revision 1.8, Wed Jan 11 22:52:40 2006 UTC
# Line 30  Line 30 
30                   insert_package_location                   insert_package_location
31                   check_for_duplicates                   check_for_duplicates
32                   log                   log
33                     allocate_feature_id
34                  );                  );
35    
36  sub ch_log  sub ch_log
# Line 268  Line 269 
269    
270  }  }
271    
272    #
273    # Allocate the next feature ID for a genome.
274    #
275    sub allocate_feature_id
276    {
277        my($dbh, $genome, $type, $number) = @_;
278        get_lock($dbh, "feature", 10);
279    
280        #if this feature is not in table, insert it
281        #get the next value, then update the next value
282    
283        my $sth = $dbh->prepare(q(SELECT next_id
284                                  FROM next_feature_id
285                                  WHERE genome_id = ? and type = ?));
286        $sth->execute($genome, $type);
287        my $rows = $sth->rows;
288        if ($sth->rows == 0) {
289            my $sth1 = $dbh->prepare(q(INSERT into next_feature_id (genome_id, type, next_id)
290                                       VALUES (?, ?, ?)
291                                      )) or die $dbh->errstr;
292            $sth1->execute($genome, $type, 1); #Start all new features at 1
293            $sth->execute($genome, $type);
294        }
295    
296        my $next_id;
297        $sth->bind_columns(\$next_id);
298        $sth->fetch;
299        my $next_id1 = $next_id+$number;
300        my $sth = $dbh->prepare(q{UPDATE next_feature_id set next_id = ? where genome_id=? and type = ? });
301        if (not $sth)
302        {
303            release_lock($dbh, "feature");
304            die $dbh->errstr;
305        }
306        $sth->execute($next_id1, $genome, $type);
307        $rows = $sth->rows;
308        #print STDERR "update rows = $rows, next_id = $next_id\n";
309        release_lock($dbh, "feature");
310    
311        return $next_id;
312    }
313    
314  1;  1;

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3