From: Dobrica Pavlinusic Date: Tue, 13 Dec 2016 22:53:46 +0000 (+0100) Subject: two different crosbi databases searching different tables X-Git-Url: http://git.rot13.org/?p=Biblio-Z3950.git;a=commitdiff_plain;h=f26d4b82ad95b3975d8315a77928d3a1897090e4 two different crosbi databases searching different tables --- diff --git a/CROSBI.pm b/CROSBI.pm index 041bea0..b090760 100644 --- a/CROSBI.pm +++ b/CROSBI.pm @@ -58,10 +58,13 @@ sub search { my $tsquery = join(' & ', split(/\s+/,$query) ); + my $table = lc $self->{database}; + $table =~ s/^crosbi-//g; + my $sql = qq{ select * -from casopis +from $table inner join rad_ustanova using (id) left outer join rad_napomena using (id) left outer join rad_projekt using (id) @@ -77,11 +80,9 @@ where rad_ustanova.sifra = ? and ( my $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0}); - my $sth = $dbh->prepare( $sql ); - warn "XXX SQL = ",$sql; -#-- and naslov like ? + my $sth = $dbh->prepare( $sql ); $sth->execute( 130, # FIXME ustanova diff --git a/server.pl b/server.pl index 1ac9edb..91d45a1 100755 --- a/server.pl +++ b/server.pl @@ -27,6 +27,8 @@ my $databases = { 'DPLA' => 'DPLA', 'MKUTUP' => 'AlephTR', 'CROSBI' => 'CROSBI', + 'CROSBI-CASOPIS' => 'CROSBI', + 'CROSBI-PREPRINT' => 'CROSBI', }; my $max_records = 10; # XXX configure this diff --git a/t/6-CROSBI.t b/t/6-CROSBI.t index 42a3c47..4f2f1df 100755 --- a/t/6-CROSBI.t +++ b/t/6-CROSBI.t @@ -11,14 +11,19 @@ use_ok 'CROSBI'; ok( my $o = CROSBI->new(), 'new' ); +foreach my $database ( qw( CROSBI-CASOPIS CROSBI-PREPRINT ) ) { + diag $o->{database} = $database; + ok( my $hits = $o->search( $search ), "search: $search" ); like $hits, qr/^\d+$/, "hits: $hits"; diag "SQL", $o->{sql}; -foreach ( 1 .. 3 ) { +foreach ( 1 .. $hits ) { ok( my $marc = $o->next_marc, "next_marc $_" ); diag $marc; } + +} # database