File indexing completed on 2024-04-06 12:22:51
0001
0002
0003 use warnings;
0004 use strict;
0005
0006 use DBI;
0007 use DBD::Oracle ;
0008
0009
0010 die "Usage: occupancy.pl start_run end_run min_sum_events_over_lo min_sum_events_over_hi\n" unless ($#ARGV == 3);
0011
0012 my ($start_run, $end_run, $min_sum_lo, $min_sum_hi) = @ARGV;
0013
0014 my $dbh = my_connect(db => 'ecalh4db',
0015 user => 'read01',
0016 pass => 'oraread01',
0017 db_opts => { RaiseError => 1 }
0018 );
0019
0020 my $sql =
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 ;
0039
0040 my $sth = $dbh->prepare_cached($sql);
0041
0042 $sth->execute($start_run, $end_run, $min_sum_lo, $min_sum_hi);
0043
0044 print join("\t", @{$sth->{NAME}}), "\n";
0045 while (my @row = $sth->fetchrow()) {
0046 print join("\t", @row), "\n";
0047 }
0048
0049
0050
0051 sub my_connect {
0052 my %args = @_;
0053 my $db = $args{db};
0054 my $user = $args{user};
0055 my $pass = $args{pass};
0056 my $port = $args{port} || 1521;
0057 my $db_opts = $args{db_opts};
0058
0059
0060 $ENV{"ORACLE_HOME"} = '/afs/cern.ch/project/oracle/@sys/10103';
0061 $ENV{"TNS_ADMIN"} = '/afs/cern.ch/project/oracle/admin';
0062 $ENV{"NLS_LANG"} = "AMERICAN";
0063
0064
0065 my $dsn;
0066 if ($db) {
0067 $dsn = "DBI:Oracle:$db";
0068 } else {
0069 die "Oracle needs to have database defined on connection!\n";
0070 }
0071
0072 my $dbh = DBI->connect($dsn, $user, $pass, $db_opts)
0073 or die "Database connection failed, $DBI::errstr";
0074
0075 $dbh->do();
0076
0077 return $dbh;
0078 }