two different crosbi databases searching different tables
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 13 Dec 2016 22:53:46 +0000 (23:53 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 13 Dec 2016 22:53:46 +0000 (23:53 +0100)
CROSBI.pm
server.pl
t/6-CROSBI.t

index 041bea0..b090760 100644 (file)
--- a/CROSBI.pm
+++ b/CROSBI.pm
@@ -58,10 +58,13 @@ sub search {
 
        my $tsquery = join(' & ', split(/\s+/,$query) );
 
 
        my $tsquery = join(' & ', split(/\s+/,$query) );
 
+       my $table = lc $self->{database};
+       $table =~ s/^crosbi-//g;
+
        my $sql = qq{
 
 select *
        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)
 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 $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0});
 
-       my $sth = $dbh->prepare( $sql );
-
 warn "XXX SQL = ",$sql;
 
 warn "XXX SQL = ",$sql;
 
-#-- and naslov like ?
+       my $sth = $dbh->prepare( $sql );
 
        $sth->execute(
                130, # FIXME ustanova
 
        $sth->execute(
                130, # FIXME ustanova
index 1ac9edb..91d45a1 100755 (executable)
--- a/server.pl
+++ b/server.pl
@@ -27,6 +27,8 @@ my $databases = {
        'DPLA'   => 'DPLA',
        'MKUTUP' => 'AlephTR',
        'CROSBI' => 'CROSBI',
        'DPLA'   => 'DPLA',
        'MKUTUP' => 'AlephTR',
        'CROSBI' => 'CROSBI',
+       'CROSBI-CASOPIS' => 'CROSBI',
+       'CROSBI-PREPRINT' => 'CROSBI',
 };
 
 my $max_records = 10; # XXX configure this
 };
 
 my $max_records = 10; # XXX configure this
index 42a3c47..4f2f1df 100755 (executable)
@@ -11,14 +11,19 @@ use_ok 'CROSBI';
 
 ok( my $o = CROSBI->new(), 'new' );
 
 
 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};
 
 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;
 
 }
 
        ok( my $marc = $o->next_marc, "next_marc $_" );
        diag $marc;
 
 }
+
+} # database