added offset and limit [0.02]
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 2 Feb 2010 18:03:17 +0000 (18:03 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 2 Feb 2010 18:03:17 +0000 (18:03 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1325 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input/Koha.pm
t/2-input-koha.t

index 2ae718b..efdc82b 100644 (file)
@@ -15,15 +15,16 @@ WebPAC::Input::Koha - read MARC records from Koha
 
 =cut
 
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 =head1 FUNCTIONS
 
 =head2 new
 
   my $input = new WebPAC::Input::Koha(
 
 =head1 FUNCTIONS
 
 =head2 new
 
   my $input = new WebPAC::Input::Koha(
-       dsn => '',
-       filter => \&code_ref,
+       dsn    => 'dbi:mysql:database=koha',
+       user   => $ENV{KOHA_USER},
+       passwd => $ENV{KOHA_PASSWD},
   }
 
 =cut
   }
 
 =cut
@@ -36,6 +37,7 @@ sub new {
        my $arg = {@_};
 
        my $log = $self->_get_logger();
        my $arg = {@_};
 
        my $log = $self->_get_logger();
+       $log->debug( 'arg = ', dump($arg) );
 
        if ( -e $arg->{path} ) {
                $log->info("Koha marc dump ", $arg->{path}, " exists");
 
        if ( -e $arg->{path} ) {
                $log->info("Koha marc dump ", $arg->{path}, " exists");
@@ -45,7 +47,9 @@ sub new {
                $arg->{dsn}    ||= 'dbi:mysql:database=koha';
                $arg->{user}   ||= $ENV{KOHA_USER};
                $arg->{passwd} ||= $ENV{KOHA_PASSWD},
                $arg->{dsn}    ||= 'dbi:mysql:database=koha';
                $arg->{user}   ||= $ENV{KOHA_USER};
                $arg->{passwd} ||= $ENV{KOHA_PASSWD},
-               $arg->{sql}    ||= 'select biblioitemnumber as mfn, marc from biblioitems';
+               $arg->{sql}    ||= 'select biblionumber as mfn, marc from biblioitems';
+               $arg->{sql}    .= ' limit ' . $arg->{limit} if $arg->{limit};
+               $arg->{sql}    .= ' offset ' . $arg->{offset} if $arg->{offset};
 
                $log->info("opening Koha database '$arg->{dsn}'");
 
 
                $log->info("opening Koha database '$arg->{dsn}'");
 
@@ -100,7 +104,7 @@ Return number of records in database
 
 sub size {
        my $self = shift;
 
 sub size {
        my $self = shift;
-       return $self->{_koha_size};
+       return $self->{_koha_size} + $self->{offset};
 }
 
 
 }
 
 
index b278f72..0440987 100755 (executable)
@@ -3,7 +3,7 @@
 use strict;
 use lib 'lib';
 
 use strict;
 use lib 'lib';
 
-use Test::More tests => 27;
+use Test::More tests => 28;
 
 BEGIN {
 use_ok( 'WebPAC::Test' );
 
 BEGIN {
 use_ok( 'WebPAC::Test' );
@@ -19,19 +19,20 @@ ok(my $input = new WebPAC::Input(
        %LOG
 ), "new");
 
        %LOG
 ), "new");
 
+my $path = '/tmp/koha.marc';
+
 ok(my $db = $input->open(
 ok(my $db = $input->open(
-       path => '/tmp/koha.marc', # required?
+       path   => $path,
        dsn    => 'dbi:mysql:database=koha',
        user   => $ENV{KOHA_USER},
        passwd => $ENV{KOHA_PASSWD},
        dsn    => 'dbi:mysql:database=koha',
        user   => $ENV{KOHA_USER},
        passwd => $ENV{KOHA_PASSWD},
-       sql    => q{
-               select biblioitemnumber as mfn, marc from biblioitems limit 7
-       },
+       limit  => 7,
+       offset => 3,
 ), "open");
 ok(my $size = $input->size, "size");
 cmp_ok( $size, '==', 7, 'size ok' );
 
 ), "open");
 ok(my $size = $input->size, "size");
 cmp_ok( $size, '==', 7, 'size ok' );
 
-foreach my $mfn ( 1 ... $size ) {
+foreach my $mfn ( 3 + 1 ... 3 + $size ) {
        my $rec = $input->fetch;
        ok($rec, "fetch $mfn");
        cmp_ok($rec->{'000'}->[0], '==', $mfn, 'has mfn');
        my $rec = $input->fetch;
        ok($rec, "fetch $mfn");
        cmp_ok($rec->{'000'}->[0], '==', $mfn, 'has mfn');
@@ -39,3 +40,4 @@ foreach my $mfn ( 1 ... $size ) {
        diag "rec: ", dump($rec), "\n" if $debug;
 }
 
        diag "rec: ", dump($rec), "\n" if $debug;
 }
 
+ok( unlink $path, "unlink $path" );