From: Dobrica Pavlinusic Date: Sun, 20 Sep 2009 21:38:15 +0000 (+0000) Subject: fix offset to skip records just like SQL databases do, and not position us on it X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=01091188dac765b18d9fb9bd84cad20ee4bd3e95;p=webpac2 fix offset to skip records just like SQL databases do, and not position us on it git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1304 07558da8-63fa-0310-ba24-9fe276d99e06 --- diff --git a/lib/WebPAC/Input.pm b/lib/WebPAC/Input.pm index 94afb8b..ecc6773 100644 --- a/lib/WebPAC/Input.pm +++ b/lib/WebPAC/Input.pm @@ -137,7 +137,7 @@ This function will read whole database in memory and produce lookups. By default, C is assumed to be C. -C is optional parametar to position at some offset before reading from database. +C is optional parametar to skip records at beginning. C is optional parametar to read just C records from database @@ -264,10 +264,10 @@ sub open { my $to_rec = $size; if (my $s = $self->{offset}) { - $log->debug("skipping to MFN $s"); - $from_rec = $s; + $log->debug("offset $s records"); + $from_rec = $s + 1; } else { - $self->{offset} = $from_rec; + $self->{offset} = $from_rec - 1; } if ($self->{limit}) { @@ -277,7 +277,7 @@ sub open { } # store size for later - $self->{size} = ($to_rec - $from_rec) ? ($to_rec - $from_rec + 1) : 0; + $self->{size} = $to_rec - $from_rec + 1; my $strict_encoding = $arg->{strict_encoding} || $self->{strict_encoding}; ## FIXME should be 1 really @@ -415,7 +415,7 @@ sub fetch { $log->logconfess("it seems that you didn't load database!") unless ($self->{pos}); if ($self->{pos} == -1) { - $self->{pos} = $self->{offset}; + $self->{pos} = $self->{offset} + 1; } else { $self->{pos}++; } diff --git a/t/2-input.t b/t/2-input.t index 53ca2eb..052b586 100755 --- a/t/2-input.t +++ b/t/2-input.t @@ -94,14 +94,14 @@ sub test_start_limit($$$$) { diag "offset $s, limit: $l, expected: $e"; ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => $debug ), "open winisis"); - cmp_ok($s, '==', $size, "db size from open = $size"); + cmp_ok($s, '==', $size, "db size"); cmp_ok($input->size, '==', $e, "input->size = $e"); } test_start_limit($input, 1, 3, 3); test_start_limit($input, $size, 3, 0); -test_start_limit($input, 3, $size, $size - 2); -test_start_limit($input, 1, $size + 2, $size); +test_start_limit($input, 3, $size, $size - 3); +test_start_limit($input, 1, $size, $size - 1); ok(my $s = $input->stats, "$module stats"); diag "stats:\n$s" if ($debug);