fixed file name
[sgn.git] / bin / delete_nd_experiment_entries.pl
blob5a322cde7d33b00d30a07622fd8702914abc7cb5
1 #!/usr/bin/perl
3 =head1 NAME
5 delete_nd_experiment_entries.pl - script to delete nd_experiment entries. used during phenotpe deletion to move the slow process of deleting nd_experiment entries to an asynchronous process
7 =head1 DESCRIPTION
9 delete_nd_experiment_entries.pl -H [database handle] -D [database name] -U [database user] -P [database password] -i [filename of tempfile with nd_experiment_ids to delete]
11 Options:
13 -H database host
14 -D database name
15 -U database user
16 -P database password
17 -i filename of tempfile with nd_experiment_ids to delete
19 =head1 AUTHOR
22 =cut
24 use strict;
25 use warnings;
26 use Getopt::Std;
27 use DBI;
28 #use CXGN::DB::InsertDBH;
30 our ($opt_H, $opt_D, $opt_U, $opt_P, $opt_i);
31 getopts('H:D:U:P:i:');
33 print STDERR "Connecting to database...\n";
34 my $dsn = 'dbi:Pg:database='.$opt_D.";host=".$opt_H.";port=5432";
35 my $dbh = DBI->connect($dsn, $opt_U, $opt_P);
37 my @nd_experiment_ids;
38 open (my $fh, "<", $opt_i ) || die ("\nERROR: the file $opt_i could not be found\n" );
39 while (my $line = <$fh>) {
40 chomp($line);
41 push @nd_experiment_ids, $line;
43 close($fh);
45 eval {
46 my $nd_experiment_ids_string = join ",", @nd_experiment_ids;
47 my $q = "DELETE FROM nd_experiment WHERE nd_experiment_id IN ($nd_experiment_ids_string)";
48 my $h = $dbh->prepare($q);
49 $h->execute();
50 print STDERR "DELETED ".scalar(@nd_experiment_ids)." Nd Experiment Entries\n";
53 if ($@) {
54 $dbh->rollback();
55 print STDERR $@;
56 } else {
57 print STDERR "Done, exiting delete_nd_experiment_entries.pl \n";