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

View of /Clearinghouse/utils.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Tue May 3 17:38:19 2005 UTC (14 years, 6 months ago) by olson
Branch: MAIN
Changes since 1.1: +14 -2 lines
Add page header.

#
# Clearinghouse utility functions.
#

use strict;
use base 'Exporter';

use HTML;
use Clearinghouse::ch_database;

our @EXPORT = qw(check_types
		 get_lock
		 release_lock
		 get_page_header
		);

sub get_page_header
{
    my @page_header = &HTML::compute_html_header(undef, undef,
						 header_name => 'clearinghouse.hdr',
						 tail_name => 'clearinghouse.tail',
						 no_fig_search => 1,
						 no_release_info => 1);
    return join("\n", @page_header);
}

sub check_types {
	my ($type) = @_;
	my $db = db_init();

	my $ar = $db->SQL(qq(SELECT type FROM types WHERE type = '$type'));
	return @$ar; #length = 0, if no rows
}



sub get_lock {
    my ($dbh, $name, $timeout) = @_;
    
    my $sth = $dbh->prepare(q{UPDATE locks  set lock = 1 where name = ? and lock = 0}) or die $dbh->errstr;
    my $res = $sth->execute($name);
    while  ($sth->rows == 0) {
	if ($timeout-- == 0) {
	    die "Lock timout";
	}
	sleep 1;
	my $res = $sth->execute($name);
    }
}


sub release_lock {
    my ($dbh, $name) = @_;
    
    my $sth = $dbh->prepare(q{UPDATE locks  set lock = 0 where name = ?}) or die $dbh->errstr;
    $sth->execute($name);
}



1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3