### Example perl DBI program to connect to BioSPICE Warehouse
### Kemal Sonmez
### Sun April 14 20:19:50 PDT 2002

# use DBI module
use  DBI;

$argCount = @ARGV;
if( $argCount != 2 ) {
	die "usage: perl $0 userid password\n"
}
my $userid = shift( @ARGV );
my $password = shift( @ARGV );

# Connect to the database.
$dbh = DBI->connect(
		    qq{dbi:Oracle:$ORACLE_SID},
		    $userid,
		    $password,
		    { PrintError => 1, RaiseError => 1, AutoCommit => 0 } )
    or die $DBI::errstr;

$dbh->{LongReadLen}=1000;

# Output description of query
print "Look up a SWISS-PROT protein by name (e.g., Zyxin).\n\n";
    
### Subquery 1
$sqlquery = "select * from Protein where name = 'Zyxin' and DataSetWID =
(select WID from DataSet where Name = 'Swiss-Prot')" ;
print"SQL query:\n$sqlquery\n";

# prepare a SQL query
my $sth = $dbh->prepare($sqlquery) 
    or die "Can't prepare SQL statement\n";

# send to ORACLE
$sth->execute 
    or die "Can't execute SQL statement\n";

# get and print the output
print"\nBioSPICE Warehouse output:\n";
while(@row = $sth->fetchrow_array() ) {
    $line = join('::',@row);
    print "$line\n";
}

# error check
warn "Data fetching terminated early by error: $DBI::errstr\n" if $DBI::err;



# Disconnect and exit
$dbh->disconnect or warn "Error disconnecting: $DBI::errstr\n";
exit;
