package db_link_coffee;

use lib '/usr/lib/perl5/site_perl/5.005/i386-linux';

#global packages to use
use DBI;
use DBD::mysql ();

sub connect_db {
    my ($db,$usr) = @_;

#08-20-2002 DCI1
#temp redirect of cgn requests
    ($db eq 'cgn') and $db='cgn_old';

    $usr ||= 'web_cgn';


    $usr eq 'web_cgn'
	and $pwd='coffee';

$usr eq 'annotator'
    and $pwd='coffee_writer';

    my $dsn = "dbi:mysql:$db";


    # try to open the database    
    my $dbh = DBI->connect($dsn, $usr, $pwd, { RaiseError => 1})
	|| die "Can't connect to $dsn: $DBI::errstr";
    
    # Set larger max buffer size so that long sequences don't get truncated on retrieval
    my  $newsize = 20480;
    ($rc = $dbh->{LongReadLen} = $newsize) 
        || die "Error setting LongReadLen to $newsize: $DBI::errstr";
    
    return $dbh;
}

sub disconnect_db {
    my ($dbh) = @_;
    $rc = $dbh->disconnect || warn DBI::errstr;
}

return 1;
