From: Dobrica Pavlinusic Date: Tue, 2 Feb 2010 18:03:17 +0000 (+0000) Subject: added offset and limit [0.02] X-Git-Url: http://git.rot13.org/?p=webpac2;a=commitdiff_plain;h=a326fb51fd453c22ea509f860dcd272e70c4ffab added offset and limit [0.02] git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1325 07558da8-63fa-0310-ba24-9fe276d99e06 --- diff --git a/lib/WebPAC/Input/Koha.pm b/lib/WebPAC/Input/Koha.pm index 2ae718b..efdc82b 100644 --- a/lib/WebPAC/Input/Koha.pm +++ b/lib/WebPAC/Input/Koha.pm @@ -15,15 +15,16 @@ WebPAC::Input::Koha - read MARC records from Koha =cut -our $VERSION = '0.01'; +our $VERSION = '0.02'; =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 @@ -36,6 +37,7 @@ sub new { my $arg = {@_}; my $log = $self->_get_logger(); + $log->debug( 'arg = ', dump($arg) ); 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->{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}'"); @@ -100,7 +104,7 @@ Return number of records in database sub size { my $self = shift; - return $self->{_koha_size}; + return $self->{_koha_size} + $self->{offset}; } diff --git a/t/2-input-koha.t b/t/2-input-koha.t index b278f72..0440987 100755 --- a/t/2-input-koha.t +++ b/t/2-input-koha.t @@ -3,7 +3,7 @@ use strict; use lib 'lib'; -use Test::More tests => 27; +use Test::More tests => 28; BEGIN { use_ok( 'WebPAC::Test' ); @@ -19,19 +19,20 @@ ok(my $input = new WebPAC::Input( %LOG ), "new"); +my $path = '/tmp/koha.marc'; + 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}, - 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' ); -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'); @@ -39,3 +40,4 @@ foreach my $mfn ( 1 ... $size ) { diag "rec: ", dump($rec), "\n" if $debug; } +ok( unlink $path, "unlink $path" );