62 |
If optional parametar C<limit_mfn> is set, it will read just 500 records |
If optional parametar C<limit_mfn> is set, it will read just 500 records |
63 |
from database in example above. |
from database in example above. |
64 |
|
|
65 |
Returns number of last record read into memory (size of database, really). |
Returns size of database, regardless of C<start_mfn> and C<limit_mfn> |
66 |
|
parametars, see also C<$isis->size>. |
67 |
|
|
68 |
=cut |
=cut |
69 |
|
|
79 |
$log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*')); |
$log->logdie("can't find database ",$arg->{'filename'}) unless (glob($arg->{'filename'}.'.*')); |
80 |
|
|
81 |
# store data in object |
# store data in object |
|
$self->{'isis_filename'} = $arg->{'filename'}; |
|
82 |
$self->{'isis_code_page'} = $code_page; |
$self->{'isis_code_page'} = $code_page; |
83 |
|
foreach my $v (qw/isis_filename start_mfn limit_mfn/) { |
84 |
#$self->{'isis_code_page'} = $code_page; |
$self->{$v} = $arg->{$v} if ($arg->{$v}); |
85 |
|
} |
86 |
|
|
87 |
# create Text::Iconv object |
# create Text::Iconv object |
88 |
my $cp = Text::Iconv->new($code_page,$self->{'code_page'}); |
my $cp = Text::Iconv->new($code_page,$self->{'code_page'}); |
90 |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
$log->info("reading ISIS database '",$arg->{'filename'},"'"); |
91 |
$log->debug("isis code page: $code_page"); |
$log->debug("isis code page: $code_page"); |
92 |
|
|
93 |
my ($isis_db,$maxmfn); |
my ($isis_db,$db_size); |
94 |
|
|
95 |
if ($have_openisis) { |
if ($have_openisis) { |
96 |
$log->debug("using OpenIsis perl bindings"); |
$log->debug("using OpenIsis perl bindings"); |
97 |
$isis_db = OpenIsis::open($arg->{'filename'}); |
$isis_db = OpenIsis::open($arg->{'filename'}); |
98 |
$maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; |
$db_size = OpenIsis::maxRowid( $isis_db ) || 1; |
99 |
} elsif ($have_biblio_isis) { |
} elsif ($have_biblio_isis) { |
100 |
$log->debug("using Biblio::Isis"); |
$log->debug("using Biblio::Isis"); |
101 |
use Biblio::Isis; |
use Biblio::Isis; |
108 |
return $l; |
return $l; |
109 |
}, |
}, |
110 |
); |
); |
111 |
$maxmfn = $isis_db->count; |
$db_size = $isis_db->count; |
112 |
|
|
113 |
unless ($maxmfn) { |
unless ($db_size) { |
114 |
$log->logwarn("no records in database ", $arg->{'filename'}, ", skipping..."); |
$log->logwarn("no records in database ", $arg->{'filename'}, ", skipping..."); |
115 |
return; |
return; |
116 |
} |
} |
121 |
|
|
122 |
|
|
123 |
my $startmfn = 1; |
my $startmfn = 1; |
124 |
|
my $maxmfn = $db_size; |
125 |
|
|
126 |
if (my $s = $self->{'start_mfn'}) { |
if (my $s = $self->{'start_mfn'}) { |
127 |
$log->info("skipping to MFN $s"); |
$log->info("skipping to MFN $s"); |
130 |
$self->{'start_mfn'} = $startmfn; |
$self->{'start_mfn'} = $startmfn; |
131 |
} |
} |
132 |
|
|
133 |
$maxmfn = $startmfn + $self->{limit_mfn} if ($self->{limit_mfn}); |
if ($self->{limit_mfn}) { |
134 |
|
$log->info("limiting to ",$self->{limit_mfn}," records"); |
135 |
|
$maxmfn = $startmfn + $self->{limit_mfn} - 1; |
136 |
|
$maxmfn = $db_size if ($maxmfn > $db_size); |
137 |
|
} |
138 |
|
|
139 |
|
# store size for later |
140 |
|
$self->{'size'} = ($maxmfn - $startmfn) ? ($maxmfn - $startmfn + 1) : 0; |
141 |
|
|
142 |
$log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis')); |
$log->info("processing ",($maxmfn-$startmfn)." records using ",( $have_openisis ? 'OpenIsis' : 'Biblio::Isis')); |
143 |
|
|
203 |
$log->debug("max mfn: $maxmfn"); |
$log->debug("max mfn: $maxmfn"); |
204 |
|
|
205 |
# store max mfn and return it. |
# store max mfn and return it. |
206 |
return $self->{'max_mfn'} = $maxmfn; |
$self->{'max_mfn'} = $maxmfn; |
207 |
|
|
208 |
|
return $db_size; |
209 |
} |
} |
210 |
|
|
211 |
=head2 fetch |
=head2 fetch |
271 |
|
|
272 |
print $isis->size; |
print $isis->size; |
273 |
|
|
274 |
|
Result from this function can be used to loop through all records |
275 |
|
|
276 |
|
foreach my $mfn ( 1 ... $isis->size ) { ... } |
277 |
|
|
278 |
|
because it takes into account C<start_mfn> and C<limit_mfn>. |
279 |
|
|
280 |
=cut |
=cut |
281 |
|
|
282 |
sub size { |
sub size { |
283 |
my $self = shift; |
my $self = shift; |
284 |
return $self->{'max_mfn'}; |
return $self->{'size'}; |
285 |
} |
} |
286 |
|
|
287 |
=head2 seek |
=head2 seek |