#!/usr/bin/perl
-# vim:et:ts=4:
+# vim:et:ts=4:sw=4:
use strict;
use warnings;
my $confxpc = XML::LibXML::XPathContext->new($confxml);
my $osrfxml = $xmlparser->parse_file($settings_config);
-check_all_database_connections();
+my $dbh = init_database_connections();
-sub check_all_database_connections {
- print "\nChecking database connections\n";
+get_date1_records($dbh);
+
+$dbh->disconnect;
+
+sub get_date1_records {
+ my ($dbh) = @_;
+
+ # Get list of server languages
+ my $sth = $dbh->prepare("SELECT DISTINCT mrfr.record
+ FROM metabib.real_full_rec mrfr INNER JOIN biblio.record_entry bre ON mrfr.record = bre.id
+ INNER JOIN asset.call_number acn ON bre.id = acn.record
+ INNER JOIN asset.copy ac ON acn.id = ac.call_number
+ INNER JOIN actor.org_unit aou ON ac.circ_lib = aou.id
+ WHERE mrfr.record IN (SELECT record
+ FROM metabib.real_full_rec
+ WHERE tag = '008' AND substring(value, 8, 4) ~ '(^\\s*\$|^\\d{1,3}\$|[^0-9\\su]|203[1-9])')
+ AND (tag = '260' OR tag = '264') AND subfield = 'c' AND value ~ '\\d{1,4}' AND bre.deleted = false AND aou.shortname NOT IN ('MWP', 'AB', 'LB', 'ITC', 'HBCA')");
+ $sth->execute;
+ my $records = $sth->fetchall_arrayref([0]);
+ $sth->finish;
+
+ for (@$records) {
+ print $_->[0] . "\n";
+ }
+}
+
+sub init_database_connections {
+ print "\nInitializing database connection\n";
# Check database connections
my @databases = $osrfxml->findnodes('//database');
next unless $node->nodeType == XML::LibXML::XML_ELEMENT_NODE;
$osrf_xpath .= "/" . $node->nodeName;
}
- $output .= test_db_connect($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath);
+
+ my $dbh = db_connect($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath);
+
+ return $dbh;
}
}
-sub test_db_connect {
+sub db_connect {
my ($db_name, $db_host, $db_port, $db_user, $db_pw, $osrf_xpath) = @_;
my $dsn = "dbi:Pg:dbname=$db_name;host=$db_host;port=$db_port";
- my $de = undef;
- my ($dbh, $encoding, $langs);
+ my $dbh;
+
$dbh = DBI->connect($dsn, $db_user, $db_pw);
# Short-circuit if we didn't connect successfully
unless($dbh) {
- $de = "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
warn "* $osrf_xpath :: Unable to connect to database $dsn, user=$db_user, password=$db_pw\n";
- return $de;
+ return -1;
}
- $dbh->disconnect;
- print "* $osrf_xpath :: Successfully connected to database $dsn\n" unless ($de);
+ return $dbh;
}