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 min_n_lo min_n_hi\n" unless ($#ARGV == 1);
0011
0012 my ($min_n_lo, $min_n_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 my $sth = $dbh->prepare_cached($sql);
0037
0038 $sth->execute($min_n_lo, $min_n_hi);
0039
0040 print join("\t", @{$sth->{NAME}}), "\n";
0041 while (my @row = $sth->fetchrow()) {
0042 print join("\t", @row), "\n";
0043 }
0044
0045
0046
0047 sub my_connect {
0048 my %args = @_;
0049 my $db = $args{db};
0050 my $user = $args{user};
0051 my $pass = $args{pass};
0052 my $port = $args{port} || 1521;
0053 my $db_opts = $args{db_opts};
0054
0055
0056 $ENV{"ORACLE_HOME"} = '/afs/cern.ch/project/oracle/@sys/10103';
0057 $ENV{"TNS_ADMIN"} = '/afs/cern.ch/project/oracle/admin';
0058 $ENV{"NLS_LANG"} = "AMERICAN";
0059
0060
0061 my $dsn;
0062 if ($db) {
0063 $dsn = "DBI:Oracle:$db";
0064 } else {
0065 die "Oracle needs to have database defined on connection!\n";
0066 }
0067
0068 my $dbh = DBI->connect($dsn, $user, $pass, $db_opts)
0069 or die "Database connection failed, $DBI::errstr";
0070
0071 $dbh->do();
0072
0073 return $dbh;
0074 }