wrong subfield
[migration-tools.git] / query_for_primary_matching_incumbent_record.pl
1 #!/usr/bin/perl
2 use DBI;
3 use Data::Dumper;
4
5 ################ THIS RESOURCE IS FOR PINES PRODUCTION
6 my $SOURCE_DBI_RESOURCE = "dbi:Pg:dbname=sparkle;host=10.1.0.12;port=5432";
7 my $SOURCE_DBI_USER = 'postgres';
8 my $SOURCE_DBI_PASSWD = '';
9 my $source_dbh = DBI->connect($SOURCE_DBI_RESOURCE, $SOURCE_DBI_USER, $SOURCE_DBI_PASSWD) or die("Database error: $DBI::errstr");
10 my $primary_fingerprint_tablename = "public.quitman_full_fingerprint_set";
11
12 sub fetch_record {
13
14     my $item_form = shift;
15     my $date1 = shift;
16     my $record_type = shift;
17     my $bib_lvl = shift;
18     my $title = shift;
19     my $sql = "select id from $primary_fingerprint_tablename where " . join(' AND ',
20         " item_form = ".$source_dbh->quote($item_form),
21         " substring = ".$source_dbh->quote($date1),
22         " item_type = ".$source_dbh->quote($record_type),
23         " bib_level = ".$source_dbh->quote($bib_lvl),
24         " title = ".$source_dbh->quote($title),
25     );
26     my $source_sth = $source_dbh->prepare($sql) or die("prepare error: $DBI::errstr \n[$sql]");
27     $source_sth->execute() or die("execute error: $DBI::errstr \n[$sql]");
28
29     while ( my ($id) = $source_sth->fetchrow_array ) {
30
31         print "$id\n";
32
33     }
34     $source_sth->finish();
35
36
37 }
38
39 while (my $line = <>) {
40     chomp $line;
41     my ($id,$item_form,$date1,$record_type,$bib_lvl,$title) = split(/\t/,$line);
42     if ($id eq 'id') { next; }
43     fetch_record($item_form,$date1,$record_type,$bib_lvl,$title);
44 }
45
46 $source_dbh->disconnect;
47